Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Don Skidmore | 434c5e3 | 2013-01-08 05:02:28 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2013 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: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 35 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 36 | #include <linux/ip.h> |
| 37 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 38 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 39 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 40 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 41 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 42 | #include <net/checksum.h> |
| 43 | #include <net/ip6_checksum.h> |
| 44 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 45 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 46 | #include <linux/if_vlan.h> |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 47 | #include <linux/if_macvlan.h> |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 48 | #include <linux/if_bridge.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 49 | #include <linux/prefetch.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 50 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 51 | |
| 52 | #include "ixgbe.h" |
| 53 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 54 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 55 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 56 | |
| 57 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 58 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 59 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 60 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 61 | char ixgbe_default_device_descr[] = |
| 62 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 63 | #else |
| 64 | static char ixgbe_default_device_descr[] = |
| 65 | "Intel(R) 10 Gigabit Network Connection"; |
| 66 | #endif |
Don Skidmore | 93ac03b | 2013-05-15 07:34:50 +0000 | [diff] [blame] | 67 | #define DRV_VERSION "3.15.1-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 68 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 69 | static const char ixgbe_copyright[] = |
Don Skidmore | 434c5e3 | 2013-01-08 05:02:28 +0000 | [diff] [blame] | 70 | "Copyright (c) 1999-2013 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 71 | |
| 72 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 73 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 74 | [board_82599] = &ixgbe_82599_info, |
Don Skidmore | fe15e8e1 | 2010-11-16 19:27:16 -0800 | [diff] [blame] | 75 | [board_X540] = &ixgbe_X540_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 79 | * |
| 80 | * Wildcard entries (PCI_ANY_ID) should come last |
| 81 | * Last entry must be all 0s |
| 82 | * |
| 83 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 84 | * Class, Class Mask, private data (not used) } |
| 85 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 86 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 115 | {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] | 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 117 | /* required last entry */ |
| 118 | {0, } |
| 119 | }; |
| 120 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 121 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 122 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 123 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 124 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 125 | static struct notifier_block dca_notifier = { |
| 126 | .notifier_call = ixgbe_notify_dca, |
| 127 | .next = NULL, |
| 128 | .priority = 0 |
| 129 | }; |
| 130 | #endif |
| 131 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 132 | #ifdef CONFIG_PCI_IOV |
| 133 | static unsigned int max_vfs; |
| 134 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 135 | MODULE_PARM_DESC(max_vfs, |
Greg Rose | 6b42a9c | 2012-04-17 04:29:29 +0000 | [diff] [blame] | 136 | "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 137 | #endif /* CONFIG_PCI_IOV */ |
| 138 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 139 | static unsigned int allow_unsupported_sfp; |
| 140 | module_param(allow_unsupported_sfp, uint, 0); |
| 141 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 142 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 143 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 144 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 145 | static int debug = -1; |
| 146 | module_param(debug, int, 0); |
| 147 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 148 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 149 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 150 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 151 | MODULE_LICENSE("GPL"); |
| 152 | MODULE_VERSION(DRV_VERSION); |
| 153 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 154 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 155 | u32 reg, u16 *value) |
| 156 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 157 | struct pci_dev *parent_dev; |
| 158 | struct pci_bus *parent_bus; |
| 159 | |
| 160 | parent_bus = adapter->pdev->bus->parent; |
| 161 | if (!parent_bus) |
| 162 | return -1; |
| 163 | |
| 164 | parent_dev = parent_bus->self; |
| 165 | if (!parent_dev) |
| 166 | return -1; |
| 167 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 168 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 169 | return -1; |
| 170 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 171 | pcie_capability_read_word(parent_dev, reg, value); |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 176 | { |
| 177 | struct ixgbe_hw *hw = &adapter->hw; |
| 178 | u16 link_status = 0; |
| 179 | int err; |
| 180 | |
| 181 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 182 | |
| 183 | /* Get the negotiated link width and speed from PCI config space of the |
| 184 | * parent, as this device is behind a switch |
| 185 | */ |
| 186 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 187 | |
| 188 | /* assume caller will handle error case */ |
| 189 | if (err) |
| 190 | return err; |
| 191 | |
| 192 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 193 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 198 | /** |
| 199 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 200 | * @hw: hw specific details |
| 201 | * |
| 202 | * This function is used by probe to determine whether a device's PCI-Express |
| 203 | * bandwidth details should be gathered from the parent bus instead of from the |
| 204 | * device. Used to ensure that various locations all have the correct device ID |
| 205 | * checks. |
| 206 | */ |
| 207 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 208 | { |
| 209 | switch (hw->device_id) { |
| 210 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 211 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 212 | return true; |
| 213 | default: |
| 214 | return false; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 219 | int expected_gts) |
| 220 | { |
| 221 | int max_gts = 0; |
| 222 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 223 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 224 | struct pci_dev *pdev; |
| 225 | |
| 226 | /* determine whether to use the the parent device |
| 227 | */ |
| 228 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 229 | pdev = adapter->pdev->bus->parent->self; |
| 230 | else |
| 231 | pdev = adapter->pdev; |
| 232 | |
| 233 | if (pcie_get_minimum_link(pdev, &speed, &width) || |
| 234 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) { |
| 235 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | switch (speed) { |
| 240 | case PCIE_SPEED_2_5GT: |
| 241 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 242 | max_gts = 2 * width; |
| 243 | break; |
| 244 | case PCIE_SPEED_5_0GT: |
| 245 | /* 8b/10b encoding reduces max throughput by 20% */ |
| 246 | max_gts = 4 * width; |
| 247 | break; |
| 248 | case PCIE_SPEED_8_0GT: |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 249 | /* 128b/130b encoding reduces throughput by less than 2% */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 250 | max_gts = 8 * width; |
| 251 | break; |
| 252 | default: |
| 253 | e_dev_warn("Unable to determine PCI Express bandwidth.\n"); |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | e_dev_info("PCI Express bandwidth of %dGT/s available\n", |
| 258 | max_gts); |
| 259 | e_dev_info("(Speed:%s, Width: x%d, Encoding Loss:%s)\n", |
| 260 | (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 261 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 262 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 263 | "Unknown"), |
| 264 | width, |
| 265 | (speed == PCIE_SPEED_2_5GT ? "20%" : |
| 266 | speed == PCIE_SPEED_5_0GT ? "20%" : |
Jacob Keller | 9f0a433 | 2013-10-18 05:09:19 +0000 | [diff] [blame] | 267 | speed == PCIE_SPEED_8_0GT ? "<2%" : |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 268 | "Unknown")); |
| 269 | |
| 270 | if (max_gts < expected_gts) { |
| 271 | e_dev_warn("This is not sufficient for optimal performance of this card.\n"); |
| 272 | e_dev_warn("For optimal performance, at least %dGT/s of bandwidth is required.\n", |
| 273 | expected_gts); |
| 274 | e_dev_warn("A slot with more lanes and/or higher speed is suggested.\n"); |
| 275 | } |
| 276 | } |
| 277 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 278 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 279 | { |
| 280 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
| 281 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
| 282 | schedule_work(&adapter->service_task); |
| 283 | } |
| 284 | |
| 285 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 286 | { |
| 287 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 288 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 289 | /* flush memory to make sure state is correct before next watchdog */ |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 290 | smp_mb__before_clear_bit(); |
| 291 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 292 | } |
| 293 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 294 | struct ixgbe_reg_info { |
| 295 | u32 ofs; |
| 296 | char *name; |
| 297 | }; |
| 298 | |
| 299 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 300 | |
| 301 | /* General Registers */ |
| 302 | {IXGBE_CTRL, "CTRL"}, |
| 303 | {IXGBE_STATUS, "STATUS"}, |
| 304 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 305 | |
| 306 | /* Interrupt Registers */ |
| 307 | {IXGBE_EICR, "EICR"}, |
| 308 | |
| 309 | /* RX Registers */ |
| 310 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 311 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 312 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 313 | {IXGBE_RDH(0), "RDH"}, |
| 314 | {IXGBE_RDT(0), "RDT"}, |
| 315 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 316 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 317 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 318 | |
| 319 | /* TX Registers */ |
| 320 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 321 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 322 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 323 | {IXGBE_TDH(0), "TDH"}, |
| 324 | {IXGBE_TDT(0), "TDT"}, |
| 325 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 326 | |
| 327 | /* List Terminator */ |
| 328 | {} |
| 329 | }; |
| 330 | |
| 331 | |
| 332 | /* |
| 333 | * ixgbe_regdump - register printout routine |
| 334 | */ |
| 335 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 336 | { |
| 337 | int i = 0, j = 0; |
| 338 | char rname[16]; |
| 339 | u32 regs[64]; |
| 340 | |
| 341 | switch (reginfo->ofs) { |
| 342 | case IXGBE_SRRCTL(0): |
| 343 | for (i = 0; i < 64; i++) |
| 344 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 345 | break; |
| 346 | case IXGBE_DCA_RXCTRL(0): |
| 347 | for (i = 0; i < 64; i++) |
| 348 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 349 | break; |
| 350 | case IXGBE_RDLEN(0): |
| 351 | for (i = 0; i < 64; i++) |
| 352 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 353 | break; |
| 354 | case IXGBE_RDH(0): |
| 355 | for (i = 0; i < 64; i++) |
| 356 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 357 | break; |
| 358 | case IXGBE_RDT(0): |
| 359 | for (i = 0; i < 64; i++) |
| 360 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 361 | break; |
| 362 | case IXGBE_RXDCTL(0): |
| 363 | for (i = 0; i < 64; i++) |
| 364 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 365 | break; |
| 366 | case IXGBE_RDBAL(0): |
| 367 | for (i = 0; i < 64; i++) |
| 368 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 369 | break; |
| 370 | case IXGBE_RDBAH(0): |
| 371 | for (i = 0; i < 64; i++) |
| 372 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 373 | break; |
| 374 | case IXGBE_TDBAL(0): |
| 375 | for (i = 0; i < 64; i++) |
| 376 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 377 | break; |
| 378 | case IXGBE_TDBAH(0): |
| 379 | for (i = 0; i < 64; i++) |
| 380 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 381 | break; |
| 382 | case IXGBE_TDLEN(0): |
| 383 | for (i = 0; i < 64; i++) |
| 384 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 385 | break; |
| 386 | case IXGBE_TDH(0): |
| 387 | for (i = 0; i < 64; i++) |
| 388 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 389 | break; |
| 390 | case IXGBE_TDT(0): |
| 391 | for (i = 0; i < 64; i++) |
| 392 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 393 | break; |
| 394 | case IXGBE_TXDCTL(0): |
| 395 | for (i = 0; i < 64; i++) |
| 396 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 397 | break; |
| 398 | default: |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 399 | pr_info("%-15s %08x\n", reginfo->name, |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 400 | IXGBE_READ_REG(hw, reginfo->ofs)); |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | for (i = 0; i < 8; i++) { |
| 405 | 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] | 406 | pr_err("%-15s", rname); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 407 | for (j = 0; j < 8; j++) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 408 | pr_cont(" %08x", regs[i*8+j]); |
| 409 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 416 | */ |
| 417 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 418 | { |
| 419 | struct net_device *netdev = adapter->netdev; |
| 420 | struct ixgbe_hw *hw = &adapter->hw; |
| 421 | struct ixgbe_reg_info *reginfo; |
| 422 | int n = 0; |
| 423 | struct ixgbe_ring *tx_ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 424 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 425 | union ixgbe_adv_tx_desc *tx_desc; |
| 426 | struct my_u0 { u64 a; u64 b; } *u0; |
| 427 | struct ixgbe_ring *rx_ring; |
| 428 | union ixgbe_adv_rx_desc *rx_desc; |
| 429 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 430 | u32 staterr; |
| 431 | int i = 0; |
| 432 | |
| 433 | if (!netif_msg_hw(adapter)) |
| 434 | return; |
| 435 | |
| 436 | /* Print netdevice Info */ |
| 437 | if (netdev) { |
| 438 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 439 | pr_info("Device Name state " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 440 | "trans_start last_rx\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 441 | pr_info("%-15s %016lX %016lX %016lX\n", |
| 442 | netdev->name, |
| 443 | netdev->state, |
| 444 | netdev->trans_start, |
| 445 | netdev->last_rx); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /* Print Registers */ |
| 449 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 450 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 451 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 452 | reginfo->name; reginfo++) { |
| 453 | ixgbe_regdump(hw, reginfo); |
| 454 | } |
| 455 | |
| 456 | /* Print TX Ring Summary */ |
| 457 | if (!netdev || !netif_running(netdev)) |
| 458 | goto exit; |
| 459 | |
| 460 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 461 | pr_info(" %s %s %s %s\n", |
| 462 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 463 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 464 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 465 | tx_ring = adapter->tx_ring[n]; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 466 | tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean]; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 467 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 468 | n, tx_ring->next_to_use, tx_ring->next_to_clean, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 469 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 470 | dma_unmap_len(tx_buffer, len), |
| 471 | tx_buffer->next_to_watch, |
| 472 | (u64)tx_buffer->time_stamp); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /* Print TX Rings */ |
| 476 | if (!netif_msg_tx_done(adapter)) |
| 477 | goto rx_ring_summary; |
| 478 | |
| 479 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 480 | |
| 481 | /* Transmit Descriptor Formats |
| 482 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 483 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 484 | * +--------------------------------------------------------------+ |
| 485 | * 0 | Buffer Address [63:0] | |
| 486 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 487 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 488 | * +--------------------------------------------------------------+ |
| 489 | * 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] | 490 | * |
| 491 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 492 | * +--------------------------------------------------------------+ |
| 493 | * 0 | RSV [63:0] | |
| 494 | * +--------------------------------------------------------------+ |
| 495 | * 8 | RSV | STA | NXTSEQ | |
| 496 | * +--------------------------------------------------------------+ |
| 497 | * 63 36 35 32 31 0 |
| 498 | * |
| 499 | * 82599+ Advanced Transmit Descriptor |
| 500 | * +--------------------------------------------------------------+ |
| 501 | * 0 | Buffer Address [63:0] | |
| 502 | * +--------------------------------------------------------------+ |
| 503 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 504 | * +--------------------------------------------------------------+ |
| 505 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 506 | * |
| 507 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 508 | * +--------------------------------------------------------------+ |
| 509 | * 0 | RSV [63:0] | |
| 510 | * +--------------------------------------------------------------+ |
| 511 | * 8 | RSV | STA | RSV | |
| 512 | * +--------------------------------------------------------------+ |
| 513 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 514 | */ |
| 515 | |
| 516 | for (n = 0; n < adapter->num_tx_queues; n++) { |
| 517 | tx_ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 518 | pr_info("------------------------------------\n"); |
| 519 | pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index); |
| 520 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 521 | pr_info("%s%s %s %s %s %s\n", |
| 522 | "T [desc] [address 63:0 ] ", |
| 523 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 524 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 525 | |
| 526 | for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 527 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 528 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 529 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 530 | if (dma_unmap_len(tx_buffer, len) > 0) { |
| 531 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p", |
| 532 | i, |
| 533 | le64_to_cpu(u0->a), |
| 534 | le64_to_cpu(u0->b), |
| 535 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 536 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 537 | tx_buffer->next_to_watch, |
| 538 | (u64)tx_buffer->time_stamp, |
| 539 | tx_buffer->skb); |
| 540 | if (i == tx_ring->next_to_use && |
| 541 | i == tx_ring->next_to_clean) |
| 542 | pr_cont(" NTC/U\n"); |
| 543 | else if (i == tx_ring->next_to_use) |
| 544 | pr_cont(" NTU\n"); |
| 545 | else if (i == tx_ring->next_to_clean) |
| 546 | pr_cont(" NTC\n"); |
| 547 | else |
| 548 | pr_cont("\n"); |
| 549 | |
| 550 | if (netif_msg_pktdata(adapter) && |
| 551 | tx_buffer->skb) |
| 552 | print_hex_dump(KERN_INFO, "", |
| 553 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 554 | tx_buffer->skb->data, |
| 555 | dma_unmap_len(tx_buffer, len), |
| 556 | true); |
| 557 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | |
| 561 | /* Print RX Rings Summary */ |
| 562 | rx_ring_summary: |
| 563 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 564 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 565 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 566 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 567 | pr_info("%5d %5X %5X\n", |
| 568 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | /* Print RX Rings */ |
| 572 | if (!netif_msg_rx_status(adapter)) |
| 573 | goto exit; |
| 574 | |
| 575 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 576 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 577 | /* Receive Descriptor Formats |
| 578 | * |
| 579 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 580 | * 63 1 0 |
| 581 | * +-----------------------------------------------------+ |
| 582 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 583 | * +----------------------------------------------+------+ |
| 584 | * 8 | Header Buffer Address [63:1] | DD | |
| 585 | * +-----------------------------------------------------+ |
| 586 | * |
| 587 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 588 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 589 | * |
| 590 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 591 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 592 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 593 | * | Packet | IP | | | | Type | Type | |
| 594 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 595 | * +------------------------------------------------------+ |
| 596 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 597 | * +------------------------------------------------------+ |
| 598 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 599 | * |
| 600 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 601 | * 63 1 0 |
| 602 | * +-----------------------------------------------------+ |
| 603 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 604 | * +----------------------------------------------+------+ |
| 605 | * 8 | Header Buffer Address [63:1] | DD | |
| 606 | * +-----------------------------------------------------+ |
| 607 | * |
| 608 | * |
| 609 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 610 | * |
| 611 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 612 | * +------------------------------------------------------+ |
| 613 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 614 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 615 | * |/ Flow Dir Flt ID | | | | | | |
| 616 | * +------------------------------------------------------+ |
| 617 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 618 | * +------------------------------------------------------+ |
| 619 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 620 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 621 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 622 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 623 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 624 | pr_info("------------------------------------\n"); |
| 625 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 626 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 627 | pr_info("%s%s%s", |
| 628 | "R [desc] [ PktBuf A0] ", |
| 629 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 630 | "<-- Adv Rx Read format\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 631 | pr_info("%s%s%s", |
| 632 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 633 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 634 | "<-- Adv Rx Write-Back format\n"); |
| 635 | |
| 636 | for (i = 0; i < rx_ring->count; i++) { |
| 637 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 638 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 639 | u0 = (struct my_u0 *)rx_desc; |
| 640 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 641 | if (staterr & IXGBE_RXD_STAT_DD) { |
| 642 | /* Descriptor Done */ |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 643 | pr_info("RWB[0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 644 | "%016llX ---------------- %p", i, |
| 645 | le64_to_cpu(u0->a), |
| 646 | le64_to_cpu(u0->b), |
| 647 | rx_buffer_info->skb); |
| 648 | } else { |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 649 | pr_info("R [0x%03X] %016llX " |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 650 | "%016llX %016llX %p", i, |
| 651 | le64_to_cpu(u0->a), |
| 652 | le64_to_cpu(u0->b), |
| 653 | (u64)rx_buffer_info->dma, |
| 654 | rx_buffer_info->skb); |
| 655 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 656 | if (netif_msg_pktdata(adapter) && |
| 657 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 658 | print_hex_dump(KERN_INFO, "", |
| 659 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 660 | page_address(rx_buffer_info->page) + |
| 661 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 662 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
| 666 | if (i == rx_ring->next_to_use) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 667 | pr_cont(" NTU\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 668 | else if (i == rx_ring->next_to_clean) |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 669 | pr_cont(" NTC\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 670 | else |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 671 | pr_cont("\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 672 | |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | exit: |
| 677 | return; |
| 678 | } |
| 679 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 680 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 681 | { |
| 682 | u32 ctrl_ext; |
| 683 | |
| 684 | /* Let firmware take over control of h/w */ |
| 685 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 686 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 687 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 691 | { |
| 692 | u32 ctrl_ext; |
| 693 | |
| 694 | /* Let firmware know the driver has taken over */ |
| 695 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 696 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 697 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 698 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 699 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 700 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 701 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 702 | * @adapter: pointer to adapter struct |
| 703 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 704 | * @queue: queue to map the corresponding interrupt to |
| 705 | * @msix_vector: the vector to map to the corresponding queue |
| 706 | * |
| 707 | */ |
| 708 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 709 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 710 | { |
| 711 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 712 | struct ixgbe_hw *hw = &adapter->hw; |
| 713 | switch (hw->mac.type) { |
| 714 | case ixgbe_mac_82598EB: |
| 715 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 716 | if (direction == -1) |
| 717 | direction = 0; |
| 718 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 719 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 720 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 721 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 722 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 723 | break; |
| 724 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 725 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 726 | if (direction == -1) { |
| 727 | /* other causes */ |
| 728 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 729 | index = ((queue & 1) * 8); |
| 730 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 731 | ivar &= ~(0xFF << index); |
| 732 | ivar |= (msix_vector << index); |
| 733 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 734 | break; |
| 735 | } else { |
| 736 | /* tx or rx causes */ |
| 737 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 738 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 739 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 740 | ivar &= ~(0xFF << index); |
| 741 | ivar |= (msix_vector << index); |
| 742 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 743 | break; |
| 744 | } |
| 745 | default: |
| 746 | break; |
| 747 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 750 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 751 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 752 | { |
| 753 | u32 mask; |
| 754 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 755 | switch (adapter->hw.mac.type) { |
| 756 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 757 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 758 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 759 | break; |
| 760 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 761 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 762 | mask = (qmask & 0xFFFFFFFF); |
| 763 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 764 | mask = (qmask >> 32); |
| 765 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 766 | break; |
| 767 | default: |
| 768 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 772 | void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring, |
| 773 | struct ixgbe_tx_buffer *tx_buffer) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 774 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 775 | if (tx_buffer->skb) { |
| 776 | dev_kfree_skb_any(tx_buffer->skb); |
| 777 | if (dma_unmap_len(tx_buffer, len)) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 778 | dma_unmap_single(ring->dev, |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 779 | dma_unmap_addr(tx_buffer, dma), |
| 780 | dma_unmap_len(tx_buffer, len), |
| 781 | DMA_TO_DEVICE); |
| 782 | } else if (dma_unmap_len(tx_buffer, len)) { |
| 783 | dma_unmap_page(ring->dev, |
| 784 | dma_unmap_addr(tx_buffer, dma), |
| 785 | dma_unmap_len(tx_buffer, len), |
| 786 | DMA_TO_DEVICE); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 787 | } |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 788 | tx_buffer->next_to_watch = NULL; |
| 789 | tx_buffer->skb = NULL; |
| 790 | dma_unmap_len_set(tx_buffer, len, 0); |
| 791 | /* tx_buffer must be completely set up in the transmit path */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 794 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 795 | { |
| 796 | struct ixgbe_hw *hw = &adapter->hw; |
| 797 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 798 | int i; |
| 799 | u32 data; |
| 800 | |
| 801 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 802 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 803 | return; |
| 804 | |
| 805 | switch (hw->mac.type) { |
| 806 | case ixgbe_mac_82598EB: |
| 807 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 808 | break; |
| 809 | default: |
| 810 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 811 | } |
| 812 | hwstats->lxoffrxc += data; |
| 813 | |
| 814 | /* refill credits (no tx hang) if we received xoff */ |
| 815 | if (!data) |
| 816 | return; |
| 817 | |
| 818 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 819 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 820 | &adapter->tx_ring[i]->state); |
| 821 | } |
| 822 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 823 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 824 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 825 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 826 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 827 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 828 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 829 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 830 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 831 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 832 | if (adapter->ixgbe_ieee_pfc) |
| 833 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 834 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 835 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 836 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 837 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 838 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 839 | |
| 840 | /* update stats for each tc, only valid with PFC enabled */ |
| 841 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 842 | u32 pxoffrxc; |
| 843 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 844 | switch (hw->mac.type) { |
| 845 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 846 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 847 | break; |
| 848 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 849 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 850 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 851 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 852 | /* Get the TC for given UP */ |
| 853 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 854 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 855 | } |
| 856 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 857 | /* disarm tx queues that have received xoff frames */ |
| 858 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 859 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 860 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 861 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 862 | if (xoff[tc]) |
| 863 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 868 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 869 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 873 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 874 | struct ixgbe_adapter *adapter; |
| 875 | struct ixgbe_hw *hw; |
| 876 | u32 head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 877 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 878 | if (ring->l2_accel_priv) |
| 879 | adapter = ring->l2_accel_priv->real_adapter; |
| 880 | else |
| 881 | adapter = netdev_priv(ring->netdev); |
| 882 | |
| 883 | hw = &adapter->hw; |
| 884 | head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx)); |
| 885 | tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 886 | |
| 887 | if (head != tail) |
| 888 | return (head < tail) ? |
| 889 | tail - head : (tail + ring->count - head); |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 895 | { |
| 896 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 897 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 898 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
| 899 | bool ret = false; |
| 900 | |
| 901 | clear_check_for_tx_hang(tx_ring); |
| 902 | |
| 903 | /* |
| 904 | * Check for a hung queue, but be thorough. This verifies |
| 905 | * that a transmit has been completed since the previous |
| 906 | * check AND there is at least one packet pending. The |
| 907 | * ARMED bit is set to indicate a potential hang. The |
| 908 | * bit is cleared if a pause frame is received to remove |
| 909 | * false hang detection due to PFC or 802.3x frames. By |
| 910 | * requiring this to fail twice we avoid races with |
| 911 | * pfc clearing the ARMED bit and conditions where we |
| 912 | * run the check_tx_hang logic with a transmit completion |
| 913 | * pending but without time to complete it yet. |
| 914 | */ |
| 915 | if ((tx_done_old == tx_done) && tx_pending) { |
| 916 | /* make sure it is true for two checks in a row */ |
| 917 | ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 918 | &tx_ring->state); |
| 919 | } else { |
| 920 | /* update completed stats and continue */ |
| 921 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 922 | /* reset the countdown */ |
| 923 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 924 | } |
| 925 | |
| 926 | return ret; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 929 | /** |
| 930 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 931 | * @adapter: driver private struct |
| 932 | **/ |
| 933 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 934 | { |
| 935 | |
| 936 | /* Do the reset outside of interrupt context */ |
| 937 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 938 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 939 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 940 | ixgbe_service_event_schedule(adapter); |
| 941 | } |
| 942 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 943 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 944 | /** |
| 945 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 946 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 947 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 948 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 949 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 950 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 951 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 952 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 953 | struct ixgbe_tx_buffer *tx_buffer; |
| 954 | union ixgbe_adv_tx_desc *tx_desc; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 955 | unsigned int total_bytes = 0, total_packets = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 956 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 957 | unsigned int i = tx_ring->next_to_clean; |
| 958 | |
| 959 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 960 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 961 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 962 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 963 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 964 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 965 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 966 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 967 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 968 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 969 | /* if next_to_watch is not set then there is no work pending */ |
| 970 | if (!eop_desc) |
| 971 | break; |
| 972 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 973 | /* prevent any other reads prior to eop_desc */ |
Alexander Duyck | 7e63bf4 | 2013-01-08 07:00:58 +0000 | [diff] [blame] | 974 | read_barrier_depends(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 975 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 976 | /* if DD is not set pending work has not been completed */ |
| 977 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 978 | break; |
| 979 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 980 | /* clear next_to_watch to prevent false hangs */ |
| 981 | tx_buffer->next_to_watch = NULL; |
| 982 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 983 | /* update the statistics for this packet */ |
| 984 | total_bytes += tx_buffer->bytecount; |
| 985 | total_packets += tx_buffer->gso_segs; |
| 986 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 987 | /* free the skb */ |
| 988 | dev_kfree_skb_any(tx_buffer->skb); |
| 989 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 990 | /* unmap skb header data */ |
| 991 | dma_unmap_single(tx_ring->dev, |
| 992 | dma_unmap_addr(tx_buffer, dma), |
| 993 | dma_unmap_len(tx_buffer, len), |
| 994 | DMA_TO_DEVICE); |
| 995 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 996 | /* clear tx_buffer data */ |
| 997 | tx_buffer->skb = NULL; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 998 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 999 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1000 | /* unmap remaining buffers */ |
| 1001 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1002 | tx_buffer++; |
| 1003 | tx_desc++; |
| 1004 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1005 | if (unlikely(!i)) { |
| 1006 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1007 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1008 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1011 | /* unmap any remaining paged data */ |
| 1012 | if (dma_unmap_len(tx_buffer, len)) { |
| 1013 | dma_unmap_page(tx_ring->dev, |
| 1014 | dma_unmap_addr(tx_buffer, dma), |
| 1015 | dma_unmap_len(tx_buffer, len), |
| 1016 | DMA_TO_DEVICE); |
| 1017 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1018 | } |
| 1019 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1020 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1021 | /* move us one more past the eop_desc for start of next pkt */ |
| 1022 | tx_buffer++; |
| 1023 | tx_desc++; |
| 1024 | i++; |
| 1025 | if (unlikely(!i)) { |
| 1026 | i -= tx_ring->count; |
| 1027 | tx_buffer = tx_ring->tx_buffer_info; |
| 1028 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1029 | } |
| 1030 | |
| 1031 | /* issue prefetch for next Tx descriptor */ |
| 1032 | prefetch(tx_desc); |
| 1033 | |
| 1034 | /* update budget accounting */ |
| 1035 | budget--; |
| 1036 | } while (likely(budget)); |
| 1037 | |
| 1038 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1039 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1040 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1041 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1042 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1043 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1044 | q_vector->tx.total_bytes += total_bytes; |
| 1045 | q_vector->tx.total_packets += total_packets; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1046 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1047 | 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] | 1048 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1049 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1050 | e_err(drv, "Detected Tx Unit Hang\n" |
| 1051 | " Tx Queue <%d>\n" |
| 1052 | " TDH, TDT <%x>, <%x>\n" |
| 1053 | " next_to_use <%x>\n" |
| 1054 | " next_to_clean <%x>\n" |
| 1055 | "tx_buffer_info[next_to_clean]\n" |
| 1056 | " time_stamp <%lx>\n" |
| 1057 | " jiffies <%lx>\n", |
| 1058 | tx_ring->queue_index, |
| 1059 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1060 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1061 | tx_ring->next_to_use, i, |
| 1062 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1063 | |
| 1064 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 1065 | |
| 1066 | e_info(probe, |
| 1067 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1068 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1069 | |
| 1070 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1071 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1072 | |
| 1073 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1074 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1075 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1076 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1077 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1078 | total_packets, total_bytes); |
| 1079 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1080 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1081 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1082 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1083 | /* Make sure that anybody stopping the queue after this |
| 1084 | * sees the new next_to_clean. |
| 1085 | */ |
| 1086 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1087 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1088 | tx_ring->queue_index) |
| 1089 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1090 | netif_wake_subqueue(tx_ring->netdev, |
| 1091 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1092 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1093 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1094 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1095 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1096 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1099 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1100 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1101 | struct ixgbe_ring *tx_ring, |
| 1102 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1103 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1104 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1105 | u32 txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1106 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1107 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1108 | switch (hw->mac.type) { |
| 1109 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1110 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1111 | break; |
| 1112 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1113 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1114 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1115 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1116 | break; |
| 1117 | default: |
| 1118 | /* for unknown hardware do not write register */ |
| 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * We can enable relaxed ordering for reads, but not writes when |
| 1124 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1125 | * which will cause the DCA tag to be cleared. |
| 1126 | */ |
| 1127 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1128 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1129 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1130 | |
| 1131 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1132 | } |
| 1133 | |
| 1134 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1135 | struct ixgbe_ring *rx_ring, |
| 1136 | int cpu) |
| 1137 | { |
| 1138 | struct ixgbe_hw *hw = &adapter->hw; |
| 1139 | u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
| 1140 | u8 reg_idx = rx_ring->reg_idx; |
| 1141 | |
| 1142 | |
| 1143 | switch (hw->mac.type) { |
| 1144 | case ixgbe_mac_82599EB: |
| 1145 | case ixgbe_mac_X540: |
| 1146 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1147 | break; |
| 1148 | default: |
| 1149 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1150 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1151 | |
| 1152 | /* |
| 1153 | * We can enable relaxed ordering for reads, but not writes when |
| 1154 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1155 | * which will cause the DCA tag to be cleared. |
| 1156 | */ |
| 1157 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1158 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1159 | |
| 1160 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1164 | { |
| 1165 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1166 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1167 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1168 | |
| 1169 | if (q_vector->cpu == cpu) |
| 1170 | goto out_no_update; |
| 1171 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1172 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1173 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1174 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1175 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1176 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1177 | |
| 1178 | q_vector->cpu = cpu; |
| 1179 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1180 | put_cpu(); |
| 1181 | } |
| 1182 | |
| 1183 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1184 | { |
| 1185 | int i; |
| 1186 | |
| 1187 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 1188 | return; |
| 1189 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1190 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 1191 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 1192 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1193 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1194 | adapter->q_vector[i]->cpu = -1; |
| 1195 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1196 | } |
| 1197 | } |
| 1198 | |
| 1199 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1200 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1201 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1202 | unsigned long event = *(unsigned long *)data; |
| 1203 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1204 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1205 | return 0; |
| 1206 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1207 | switch (event) { |
| 1208 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1209 | /* if we're already enabled, don't do it again */ |
| 1210 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1211 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1212 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1213 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1214 | ixgbe_setup_dca(adapter); |
| 1215 | break; |
| 1216 | } |
| 1217 | /* Fall Through since DCA is disabled. */ |
| 1218 | case DCA_PROVIDER_REMOVE: |
| 1219 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1220 | dca_remove_requester(dev); |
| 1221 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 1222 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 1223 | } |
| 1224 | break; |
| 1225 | } |
| 1226 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1227 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1228 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1229 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1230 | #endif /* CONFIG_IXGBE_DCA */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1231 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1232 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1233 | struct sk_buff *skb) |
| 1234 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1235 | if (ring->netdev->features & NETIF_F_RXHASH) |
| 1236 | skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1239 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1240 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1241 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1242 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1243 | * @rx_desc: advanced rx descriptor |
| 1244 | * |
| 1245 | * Returns : true if it is FCoE pkt |
| 1246 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1247 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1248 | union ixgbe_adv_rx_desc *rx_desc) |
| 1249 | { |
| 1250 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1251 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1252 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1253 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1254 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1255 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1256 | } |
| 1257 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1258 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1259 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1260 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1261 | * @ring: structure containing ring specific data |
| 1262 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1263 | * @skb: skb currently being received and modified |
| 1264 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1265 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1266 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1267 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1268 | { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1269 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1270 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1271 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1272 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1273 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1274 | |
| 1275 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1276 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1277 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1278 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1279 | return; |
| 1280 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1281 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1282 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1283 | return; |
| 1284 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1285 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1286 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1287 | |
| 1288 | /* |
| 1289 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1290 | * checksum errors. |
| 1291 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1292 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1293 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1294 | return; |
| 1295 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1296 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1297 | return; |
| 1298 | } |
| 1299 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1300 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1301 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1304 | static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1305 | { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1306 | rx_ring->next_to_use = val; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1307 | |
| 1308 | /* update next to alloc since we have filled the ring */ |
| 1309 | rx_ring->next_to_alloc = val; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1310 | /* |
| 1311 | * Force memory writes to complete before letting h/w |
| 1312 | * know there are new descriptors to fetch. (Only |
| 1313 | * applicable for weak-ordered memory model archs, |
| 1314 | * such as IA-64). |
| 1315 | */ |
| 1316 | wmb(); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1317 | writel(val, rx_ring->tail); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1320 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1321 | struct ixgbe_rx_buffer *bi) |
| 1322 | { |
| 1323 | struct page *page = bi->page; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1324 | dma_addr_t dma = bi->dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1325 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1326 | /* since we are recycling buffers we should seldom need to alloc */ |
| 1327 | if (likely(dma)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1328 | return true; |
| 1329 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1330 | /* alloc new page for storage */ |
| 1331 | if (likely(!page)) { |
Mel Gorman | 0614002 | 2012-07-31 16:44:24 -0700 | [diff] [blame] | 1332 | page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP, |
| 1333 | bi->skb, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1334 | if (unlikely(!page)) { |
| 1335 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1336 | return false; |
| 1337 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1338 | bi->page = page; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1341 | /* map page for use */ |
| 1342 | dma = dma_map_page(rx_ring->dev, page, 0, |
| 1343 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1344 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1345 | /* |
| 1346 | * if mapping failed free memory back to system since |
| 1347 | * there isn't much point in holding memory we can't use |
| 1348 | */ |
| 1349 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1350 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1351 | bi->page = NULL; |
| 1352 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1353 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1354 | return false; |
| 1355 | } |
| 1356 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1357 | bi->dma = dma; |
Alexander Duyck | afaa945 | 2012-07-20 08:08:12 +0000 | [diff] [blame] | 1358 | bi->page_offset = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1359 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1360 | return true; |
| 1361 | } |
| 1362 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1363 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1364 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1365 | * @rx_ring: ring to place buffers on |
| 1366 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1367 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1368 | 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] | 1369 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1370 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1371 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1372 | u16 i = rx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1373 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1374 | /* nothing to do */ |
| 1375 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1376 | return; |
| 1377 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1378 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1379 | bi = &rx_ring->rx_buffer_info[i]; |
| 1380 | i -= rx_ring->count; |
| 1381 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1382 | do { |
| 1383 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1384 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1385 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1386 | /* |
| 1387 | * Refresh the desc even if buffer_addrs didn't change |
| 1388 | * because each write-back erases this info. |
| 1389 | */ |
| 1390 | 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] | 1391 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1392 | rx_desc++; |
| 1393 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1394 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1395 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1396 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1397 | bi = rx_ring->rx_buffer_info; |
| 1398 | i -= rx_ring->count; |
| 1399 | } |
| 1400 | |
| 1401 | /* clear the hdr_addr for the next_to_use descriptor */ |
| 1402 | rx_desc->read.hdr_addr = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1403 | |
| 1404 | cleaned_count--; |
| 1405 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1406 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1407 | i += rx_ring->count; |
| 1408 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1409 | if (rx_ring->next_to_use != i) |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 1410 | ixgbe_release_rx_desc(rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1413 | /** |
| 1414 | * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE |
| 1415 | * @data: pointer to the start of the headers |
| 1416 | * @max_len: total length of section to find headers in |
| 1417 | * |
| 1418 | * This function is meant to determine the length of headers that will |
| 1419 | * be recognized by hardware for LRO, GRO, and RSC offloads. The main |
| 1420 | * motivation of doing this is to only perform one pull for IPv4 TCP |
| 1421 | * packets so that we can do basic things like calculating the gso_size |
| 1422 | * based on the average data per packet. |
| 1423 | **/ |
| 1424 | static unsigned int ixgbe_get_headlen(unsigned char *data, |
| 1425 | unsigned int max_len) |
| 1426 | { |
| 1427 | union { |
| 1428 | unsigned char *network; |
| 1429 | /* l2 headers */ |
| 1430 | struct ethhdr *eth; |
| 1431 | struct vlan_hdr *vlan; |
| 1432 | /* l3 headers */ |
| 1433 | struct iphdr *ipv4; |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1434 | struct ipv6hdr *ipv6; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1435 | } hdr; |
| 1436 | __be16 protocol; |
| 1437 | u8 nexthdr = 0; /* default to not TCP */ |
| 1438 | u8 hlen; |
| 1439 | |
| 1440 | /* this should never happen, but better safe than sorry */ |
| 1441 | if (max_len < ETH_HLEN) |
| 1442 | return max_len; |
| 1443 | |
| 1444 | /* initialize network frame pointer */ |
| 1445 | hdr.network = data; |
| 1446 | |
| 1447 | /* set first protocol and move network header forward */ |
| 1448 | protocol = hdr.eth->h_proto; |
| 1449 | hdr.network += ETH_HLEN; |
| 1450 | |
| 1451 | /* handle any vlan tag if present */ |
| 1452 | if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 1453 | if ((hdr.network - data) > (max_len - VLAN_HLEN)) |
| 1454 | return max_len; |
| 1455 | |
| 1456 | protocol = hdr.vlan->h_vlan_encapsulated_proto; |
| 1457 | hdr.network += VLAN_HLEN; |
| 1458 | } |
| 1459 | |
| 1460 | /* handle L3 protocols */ |
| 1461 | if (protocol == __constant_htons(ETH_P_IP)) { |
| 1462 | if ((hdr.network - data) > (max_len - sizeof(struct iphdr))) |
| 1463 | return max_len; |
| 1464 | |
| 1465 | /* access ihl as a u8 to avoid unaligned access on ia64 */ |
| 1466 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 1467 | |
| 1468 | /* verify hlen meets minimum size requirements */ |
| 1469 | if (hlen < sizeof(struct iphdr)) |
| 1470 | return hdr.network - data; |
| 1471 | |
Alexander Duyck | ed83da1 | 2012-11-13 01:13:33 +0000 | [diff] [blame] | 1472 | /* record next protocol if header is present */ |
Alexander Duyck | 20967f4 | 2013-02-01 08:56:41 +0000 | [diff] [blame] | 1473 | if (!(hdr.ipv4->frag_off & htons(IP_OFFSET))) |
Alexander Duyck | ed83da1 | 2012-11-13 01:13:33 +0000 | [diff] [blame] | 1474 | nexthdr = hdr.ipv4->protocol; |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1475 | } else if (protocol == __constant_htons(ETH_P_IPV6)) { |
| 1476 | if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr))) |
| 1477 | return max_len; |
| 1478 | |
| 1479 | /* record next protocol */ |
| 1480 | nexthdr = hdr.ipv6->nexthdr; |
Alexander Duyck | ed83da1 | 2012-11-13 01:13:33 +0000 | [diff] [blame] | 1481 | hlen = sizeof(struct ipv6hdr); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1482 | #ifdef IXGBE_FCOE |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1483 | } else if (protocol == __constant_htons(ETH_P_FCOE)) { |
| 1484 | if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN)) |
| 1485 | return max_len; |
Alexander Duyck | ed83da1 | 2012-11-13 01:13:33 +0000 | [diff] [blame] | 1486 | hlen = FCOE_HEADER_LEN; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1487 | #endif |
| 1488 | } else { |
| 1489 | return hdr.network - data; |
| 1490 | } |
| 1491 | |
Alexander Duyck | ed83da1 | 2012-11-13 01:13:33 +0000 | [diff] [blame] | 1492 | /* relocate pointer to start of L4 header */ |
| 1493 | hdr.network += hlen; |
| 1494 | |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1495 | /* finally sort out TCP/UDP */ |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1496 | if (nexthdr == IPPROTO_TCP) { |
| 1497 | if ((hdr.network - data) > (max_len - sizeof(struct tcphdr))) |
| 1498 | return max_len; |
| 1499 | |
| 1500 | /* access doff as a u8 to avoid unaligned access on ia64 */ |
| 1501 | hlen = (hdr.network[12] & 0xF0) >> 2; |
| 1502 | |
| 1503 | /* verify hlen meets minimum size requirements */ |
| 1504 | if (hlen < sizeof(struct tcphdr)) |
| 1505 | return hdr.network - data; |
| 1506 | |
| 1507 | hdr.network += hlen; |
Alexander Duyck | a048b40 | 2012-05-24 08:26:29 +0000 | [diff] [blame] | 1508 | } else if (nexthdr == IPPROTO_UDP) { |
| 1509 | if ((hdr.network - data) > (max_len - sizeof(struct udphdr))) |
| 1510 | return max_len; |
| 1511 | |
| 1512 | hdr.network += sizeof(struct udphdr); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * If everything has gone correctly hdr.network should be the |
| 1517 | * data section of the packet and will be the end of the header. |
| 1518 | * If not then it probably represents the end of the last recognized |
| 1519 | * header. |
| 1520 | */ |
| 1521 | if ((hdr.network - data) < max_len) |
| 1522 | return hdr.network - data; |
| 1523 | else |
| 1524 | return max_len; |
| 1525 | } |
| 1526 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1527 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1528 | struct sk_buff *skb) |
| 1529 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1530 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1531 | |
| 1532 | /* set gso_size to avoid messing up TCP MSS */ |
| 1533 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1534 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1535 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1539 | struct sk_buff *skb) |
| 1540 | { |
| 1541 | /* if append_cnt is 0 then frame is not RSC */ |
| 1542 | if (!IXGBE_CB(skb)->append_cnt) |
| 1543 | return; |
| 1544 | |
| 1545 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1546 | rx_ring->rx_stats.rsc_flush++; |
| 1547 | |
| 1548 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1549 | |
| 1550 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1551 | IXGBE_CB(skb)->append_cnt = 0; |
| 1552 | } |
| 1553 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1554 | /** |
| 1555 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1556 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1557 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1558 | * @skb: pointer to current skb being populated |
| 1559 | * |
| 1560 | * This function checks the ring, descriptor, and packet information in |
| 1561 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1562 | * other fields within the skb. |
| 1563 | **/ |
| 1564 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1565 | union ixgbe_adv_rx_desc *rx_desc, |
| 1566 | struct sk_buff *skb) |
| 1567 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1568 | struct net_device *dev = rx_ring->netdev; |
| 1569 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1570 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1571 | |
| 1572 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1573 | |
| 1574 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1575 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 1576 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1577 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1578 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1579 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1580 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1581 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1585 | |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1586 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1590 | struct sk_buff *skb) |
| 1591 | { |
| 1592 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1593 | |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 1594 | if (ixgbe_qv_busy_polling(q_vector)) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 1595 | netif_receive_skb(skb); |
| 1596 | else if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1597 | napi_gro_receive(&q_vector->napi, skb); |
| 1598 | else |
| 1599 | netif_rx(skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1600 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1601 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1602 | /** |
| 1603 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1604 | * @rx_ring: Rx ring being processed |
| 1605 | * @rx_desc: Rx descriptor for current buffer |
| 1606 | * @skb: Current socket buffer containing buffer in progress |
| 1607 | * |
| 1608 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1609 | * this function exits returning false, otherwise it will place the |
| 1610 | * sk_buff in the next buffer to be chained and return true indicating |
| 1611 | * that this is in fact a non-EOP buffer. |
| 1612 | **/ |
| 1613 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1614 | union ixgbe_adv_rx_desc *rx_desc, |
| 1615 | struct sk_buff *skb) |
| 1616 | { |
| 1617 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1618 | |
| 1619 | /* fetch, update, and store next to clean */ |
| 1620 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1621 | rx_ring->next_to_clean = ntc; |
| 1622 | |
| 1623 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1624 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1625 | /* update RSC append count if present */ |
| 1626 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1627 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1628 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1629 | |
| 1630 | if (unlikely(rsc_enabled)) { |
| 1631 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1632 | |
| 1633 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1634 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1635 | |
| 1636 | /* update ntc based on RSC value */ |
| 1637 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1638 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1639 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | /* 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] | 1644 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1645 | return false; |
| 1646 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1647 | /* place skb in next buffer to be received */ |
| 1648 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1649 | rx_ring->rx_stats.non_eop_descs++; |
| 1650 | |
| 1651 | return true; |
| 1652 | } |
| 1653 | |
| 1654 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1655 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1656 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1657 | * @skb: pointer to current skb being adjusted |
| 1658 | * |
| 1659 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1660 | * main difference between this version and the original function is that |
| 1661 | * this function can make several assumptions about the state of things |
| 1662 | * that allow for significant optimizations versus the standard function. |
| 1663 | * As a result we can do things like drop a frag and maintain an accurate |
| 1664 | * truesize for the skb. |
| 1665 | */ |
| 1666 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1667 | struct sk_buff *skb) |
| 1668 | { |
| 1669 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1670 | unsigned char *va; |
| 1671 | unsigned int pull_len; |
| 1672 | |
| 1673 | /* |
| 1674 | * it is valid to use page_address instead of kmap since we are |
| 1675 | * working with pages allocated out of the lomem pool per |
| 1676 | * alloc_page(GFP_ATOMIC) |
| 1677 | */ |
| 1678 | va = skb_frag_address(frag); |
| 1679 | |
| 1680 | /* |
| 1681 | * we need the header to contain the greater of either ETH_HLEN or |
| 1682 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1683 | */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1684 | pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1685 | |
| 1686 | /* align pull length to size of long to optimize memcpy performance */ |
| 1687 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1688 | |
| 1689 | /* update all of the pointers */ |
| 1690 | skb_frag_size_sub(frag, pull_len); |
| 1691 | frag->page_offset += pull_len; |
| 1692 | skb->data_len -= pull_len; |
| 1693 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1694 | } |
| 1695 | |
| 1696 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1697 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1698 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1699 | * @skb: pointer to current skb being updated |
| 1700 | * |
| 1701 | * This function provides a basic DMA sync up for the first fragment of an |
| 1702 | * skb. The reason for doing this is that the first fragment cannot be |
| 1703 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1704 | * chain. |
| 1705 | */ |
| 1706 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1707 | struct sk_buff *skb) |
| 1708 | { |
| 1709 | /* if the page was released unmap it, else just sync our portion */ |
| 1710 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
| 1711 | dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1712 | ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE); |
| 1713 | IXGBE_CB(skb)->page_released = false; |
| 1714 | } else { |
| 1715 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1716 | |
| 1717 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1718 | IXGBE_CB(skb)->dma, |
| 1719 | frag->page_offset, |
| 1720 | ixgbe_rx_bufsz(rx_ring), |
| 1721 | DMA_FROM_DEVICE); |
| 1722 | } |
| 1723 | IXGBE_CB(skb)->dma = 0; |
| 1724 | } |
| 1725 | |
| 1726 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1727 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1728 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1729 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1730 | * @skb: pointer to current skb being fixed |
| 1731 | * |
| 1732 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1733 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1734 | * should be very rare. |
| 1735 | * |
| 1736 | * Also address the case where we are pulling data in on pages only |
| 1737 | * and as such no data is present in the skb header. |
| 1738 | * |
| 1739 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1740 | * it is large enough to qualify as a valid Ethernet frame. |
| 1741 | * |
| 1742 | * Returns true if an error was encountered and skb was freed. |
| 1743 | **/ |
| 1744 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1745 | union ixgbe_adv_rx_desc *rx_desc, |
| 1746 | struct sk_buff *skb) |
| 1747 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1748 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1749 | |
| 1750 | /* verify that the packet does not have any known errors */ |
| 1751 | if (unlikely(ixgbe_test_staterr(rx_desc, |
| 1752 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1753 | !(netdev->features & NETIF_F_RXALL))) { |
| 1754 | dev_kfree_skb_any(skb); |
| 1755 | return true; |
| 1756 | } |
| 1757 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1758 | /* place header in linear portion of buffer */ |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1759 | if (skb_is_nonlinear(skb)) |
| 1760 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1761 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1762 | #ifdef IXGBE_FCOE |
| 1763 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1764 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1765 | return false; |
| 1766 | |
| 1767 | #endif |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1768 | /* if skb_pad returns an error the skb was freed */ |
| 1769 | if (unlikely(skb->len < 60)) { |
| 1770 | int pad_len = 60 - skb->len; |
| 1771 | |
| 1772 | if (skb_pad(skb, pad_len)) |
| 1773 | return true; |
| 1774 | __skb_put(skb, pad_len); |
| 1775 | } |
| 1776 | |
| 1777 | return false; |
| 1778 | } |
| 1779 | |
| 1780 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1781 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1782 | * @rx_ring: rx descriptor ring to store buffers on |
| 1783 | * @old_buff: donor buffer to have page reused |
| 1784 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1785 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1786 | **/ |
| 1787 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1788 | struct ixgbe_rx_buffer *old_buff) |
| 1789 | { |
| 1790 | struct ixgbe_rx_buffer *new_buff; |
| 1791 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1792 | |
| 1793 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1794 | |
| 1795 | /* update, and store next to alloc */ |
| 1796 | nta++; |
| 1797 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1798 | |
| 1799 | /* transfer page from old buffer to new buffer */ |
| 1800 | new_buff->page = old_buff->page; |
| 1801 | new_buff->dma = old_buff->dma; |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1802 | new_buff->page_offset = old_buff->page_offset; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1803 | |
| 1804 | /* sync the buffer for use by the device */ |
| 1805 | dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1806 | new_buff->page_offset, |
| 1807 | ixgbe_rx_bufsz(rx_ring), |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1808 | DMA_FROM_DEVICE); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | /** |
| 1812 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1813 | * @rx_ring: rx descriptor ring to transact packets on |
| 1814 | * @rx_buffer: buffer containing page to add |
| 1815 | * @rx_desc: descriptor containing length of buffer written by hardware |
| 1816 | * @skb: sk_buff to place the data into |
| 1817 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1818 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1819 | * This is done either through a direct copy if the data in the buffer is |
| 1820 | * less than the skb header size, otherwise it will just attach the page as |
| 1821 | * a frag to the skb. |
| 1822 | * |
| 1823 | * The function will then update the page offset if necessary and return |
| 1824 | * true if the buffer can be reused by the adapter. |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1825 | **/ |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1826 | static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1827 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1828 | union ixgbe_adv_rx_desc *rx_desc, |
| 1829 | struct sk_buff *skb) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1830 | { |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1831 | struct page *page = rx_buffer->page; |
| 1832 | unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1833 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1834 | unsigned int truesize = ixgbe_rx_bufsz(rx_ring); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1835 | #else |
| 1836 | unsigned int truesize = ALIGN(size, L1_CACHE_BYTES); |
| 1837 | unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - |
| 1838 | ixgbe_rx_bufsz(rx_ring); |
| 1839 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1840 | |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1841 | if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) { |
| 1842 | unsigned char *va = page_address(page) + rx_buffer->page_offset; |
| 1843 | |
| 1844 | memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); |
| 1845 | |
| 1846 | /* we can reuse buffer as-is, just make sure it is local */ |
| 1847 | if (likely(page_to_nid(page) == numa_node_id())) |
| 1848 | return true; |
| 1849 | |
| 1850 | /* this page cannot be reused so discard it */ |
| 1851 | put_page(page); |
| 1852 | return false; |
| 1853 | } |
| 1854 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1855 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, |
| 1856 | rx_buffer->page_offset, size, truesize); |
| 1857 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1858 | /* avoid re-using remote pages */ |
| 1859 | if (unlikely(page_to_nid(page) != numa_node_id())) |
| 1860 | return false; |
| 1861 | |
| 1862 | #if (PAGE_SIZE < 8192) |
| 1863 | /* if we are only owner of page we can reuse it */ |
| 1864 | if (unlikely(page_count(page) != 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1865 | return false; |
| 1866 | |
| 1867 | /* flip page offset to other buffer */ |
| 1868 | rx_buffer->page_offset ^= truesize; |
| 1869 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1870 | /* |
| 1871 | * since we are the only owner of the page and we need to |
| 1872 | * increment it, just set the value to 2 in order to avoid |
| 1873 | * an unecessary locked operation |
| 1874 | */ |
| 1875 | atomic_set(&page->_count, 2); |
| 1876 | #else |
| 1877 | /* move offset up to the next cache line */ |
| 1878 | rx_buffer->page_offset += truesize; |
| 1879 | |
| 1880 | if (rx_buffer->page_offset > last_offset) |
| 1881 | return false; |
| 1882 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1883 | /* bump ref count on page before it is given to the stack */ |
| 1884 | get_page(page); |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1885 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1886 | |
| 1887 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1888 | } |
| 1889 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 1890 | static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring, |
| 1891 | union ixgbe_adv_rx_desc *rx_desc) |
| 1892 | { |
| 1893 | struct ixgbe_rx_buffer *rx_buffer; |
| 1894 | struct sk_buff *skb; |
| 1895 | struct page *page; |
| 1896 | |
| 1897 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
| 1898 | page = rx_buffer->page; |
| 1899 | prefetchw(page); |
| 1900 | |
| 1901 | skb = rx_buffer->skb; |
| 1902 | |
| 1903 | if (likely(!skb)) { |
| 1904 | void *page_addr = page_address(page) + |
| 1905 | rx_buffer->page_offset; |
| 1906 | |
| 1907 | /* prefetch first cache line of first page */ |
| 1908 | prefetch(page_addr); |
| 1909 | #if L1_CACHE_BYTES < 128 |
| 1910 | prefetch(page_addr + L1_CACHE_BYTES); |
| 1911 | #endif |
| 1912 | |
| 1913 | /* allocate a skb to store the frags */ |
| 1914 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 1915 | IXGBE_RX_HDR_SIZE); |
| 1916 | if (unlikely(!skb)) { |
| 1917 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1918 | return NULL; |
| 1919 | } |
| 1920 | |
| 1921 | /* |
| 1922 | * we will be copying header into skb->data in |
| 1923 | * pskb_may_pull so it is in our interest to prefetch |
| 1924 | * it now to avoid a possible cache miss |
| 1925 | */ |
| 1926 | prefetchw(skb->data); |
| 1927 | |
| 1928 | /* |
| 1929 | * Delay unmapping of the first packet. It carries the |
| 1930 | * header information, HW may still access the header |
| 1931 | * after the writeback. Only unmap it when EOP is |
| 1932 | * reached |
| 1933 | */ |
| 1934 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1935 | goto dma_sync; |
| 1936 | |
| 1937 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 1938 | } else { |
| 1939 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 1940 | ixgbe_dma_sync_frag(rx_ring, skb); |
| 1941 | |
| 1942 | dma_sync: |
| 1943 | /* we are reusing so sync this buffer for CPU use */ |
| 1944 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1945 | rx_buffer->dma, |
| 1946 | rx_buffer->page_offset, |
| 1947 | ixgbe_rx_bufsz(rx_ring), |
| 1948 | DMA_FROM_DEVICE); |
| 1949 | } |
| 1950 | |
| 1951 | /* pull page into skb */ |
| 1952 | if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) { |
| 1953 | /* hand second half of page back to the ring */ |
| 1954 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
| 1955 | } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) { |
| 1956 | /* the page has been released from the ring */ |
| 1957 | IXGBE_CB(skb)->page_released = true; |
| 1958 | } else { |
| 1959 | /* we are not reusing the buffer so unmap it */ |
| 1960 | dma_unmap_page(rx_ring->dev, rx_buffer->dma, |
| 1961 | ixgbe_rx_pg_size(rx_ring), |
| 1962 | DMA_FROM_DEVICE); |
| 1963 | } |
| 1964 | |
| 1965 | /* clear contents of buffer_info */ |
| 1966 | rx_buffer->skb = NULL; |
| 1967 | rx_buffer->dma = 0; |
| 1968 | rx_buffer->page = NULL; |
| 1969 | |
| 1970 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | /** |
| 1974 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 1975 | * @q_vector: structure containing interrupt and ring information |
| 1976 | * @rx_ring: rx descriptor ring to transact packets on |
| 1977 | * @budget: Total limit on number of packets to process |
| 1978 | * |
| 1979 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 1980 | * processing. The advantage to this is that on systems that have |
| 1981 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 1982 | * it by maintaining the mapping of the page to the syste. |
| 1983 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 1984 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1985 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 1986 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 1987 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 1988 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1989 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 1990 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 1991 | #ifdef IXGBE_FCOE |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1992 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 1993 | int ddp_bytes; |
| 1994 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1995 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1996 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1997 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1998 | do { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1999 | union ixgbe_adv_rx_desc *rx_desc; |
| 2000 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2001 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2002 | /* return some buffers to hardware, one at a time is too slow */ |
| 2003 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2004 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2005 | cleaned_count = 0; |
| 2006 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2007 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2008 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2009 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2010 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) |
| 2011 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2012 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2013 | /* |
| 2014 | * This memory barrier is needed to keep us from reading |
| 2015 | * any other fields out of the rx_desc until we know the |
| 2016 | * RXD_STAT_DD bit is set |
| 2017 | */ |
| 2018 | rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2019 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2020 | /* retrieve a buffer from the ring */ |
| 2021 | skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2022 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2023 | /* exit if we failed to retrieve a buffer */ |
| 2024 | if (!skb) |
| 2025 | break; |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2026 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2027 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2028 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2029 | /* place incomplete frames back on ring for completion */ |
| 2030 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2031 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2032 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2033 | /* verify the packet layout is correct */ |
| 2034 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2035 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2036 | |
| 2037 | /* probably a little skewed due to removing CRC */ |
| 2038 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2039 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2040 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2041 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2042 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2043 | #ifdef IXGBE_FCOE |
| 2044 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2045 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2046 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2047 | /* include DDPed FCoE data */ |
| 2048 | if (ddp_bytes > 0) { |
| 2049 | if (!mss) { |
| 2050 | mss = rx_ring->netdev->mtu - |
| 2051 | sizeof(struct fcoe_hdr) - |
| 2052 | sizeof(struct fc_frame_header) - |
| 2053 | sizeof(struct fcoe_crc_eof); |
| 2054 | if (mss > 512) |
| 2055 | mss &= ~511; |
| 2056 | } |
| 2057 | total_rx_bytes += ddp_bytes; |
| 2058 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2059 | mss); |
| 2060 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2061 | if (!ddp_bytes) { |
| 2062 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2063 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2064 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2065 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2066 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2067 | #endif /* IXGBE_FCOE */ |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 2068 | skb_mark_napi_id(skb, &q_vector->napi); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2069 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2070 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2071 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2072 | total_rx_packets++; |
| 2073 | } while (likely(total_rx_packets < budget)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2074 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2075 | u64_stats_update_begin(&rx_ring->syncp); |
| 2076 | rx_ring->stats.packets += total_rx_packets; |
| 2077 | rx_ring->stats.bytes += total_rx_bytes; |
| 2078 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2079 | q_vector->rx.total_packets += total_rx_packets; |
| 2080 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2081 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2082 | if (cleaned_count) |
| 2083 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2084 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2085 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2086 | } |
| 2087 | |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2088 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2089 | /* must be called with local_bh_disable()d */ |
| 2090 | static int ixgbe_low_latency_recv(struct napi_struct *napi) |
| 2091 | { |
| 2092 | struct ixgbe_q_vector *q_vector = |
| 2093 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2094 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2095 | struct ixgbe_ring *ring; |
| 2096 | int found = 0; |
| 2097 | |
| 2098 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2099 | return LL_FLUSH_FAILED; |
| 2100 | |
| 2101 | if (!ixgbe_qv_lock_poll(q_vector)) |
| 2102 | return LL_FLUSH_BUSY; |
| 2103 | |
| 2104 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 2105 | found = ixgbe_clean_rx_irq(q_vector, ring, 4); |
Jacob Keller | b464003 | 2013-10-01 04:33:54 -0700 | [diff] [blame] | 2106 | #ifdef BP_EXTENDED_STATS |
Eliezer Tamir | 7e15b90 | 2013-06-10 11:40:31 +0300 | [diff] [blame] | 2107 | if (found) |
| 2108 | ring->stats.cleaned += found; |
| 2109 | else |
| 2110 | ring->stats.misses++; |
| 2111 | #endif |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2112 | if (found) |
| 2113 | break; |
| 2114 | } |
| 2115 | |
| 2116 | ixgbe_qv_unlock_poll(q_vector); |
| 2117 | |
| 2118 | return found; |
| 2119 | } |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 2120 | #endif /* CONFIG_NET_RX_BUSY_POLL */ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2121 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2122 | /** |
| 2123 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2124 | * @adapter: board private structure |
| 2125 | * |
| 2126 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2127 | * interrupts. |
| 2128 | **/ |
| 2129 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2130 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2131 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2132 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2133 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2134 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2135 | /* Populate MSIX to EITR Select */ |
| 2136 | if (adapter->num_vfs > 32) { |
| 2137 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 2138 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2139 | } |
| 2140 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2141 | /* |
| 2142 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2143 | * corresponding register. |
| 2144 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2145 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2146 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2147 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2148 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2149 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2150 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2151 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2152 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2153 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2154 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2155 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2158 | switch (adapter->hw.mac.type) { |
| 2159 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2160 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2161 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2162 | break; |
| 2163 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2164 | case ixgbe_mac_X540: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2165 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2166 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2167 | default: |
| 2168 | break; |
| 2169 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2170 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2171 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2172 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2173 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2174 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2175 | IXGBE_EIMS_MAILBOX | |
| 2176 | IXGBE_EIMS_LSC); |
| 2177 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2178 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2181 | enum latency_range { |
| 2182 | lowest_latency = 0, |
| 2183 | low_latency = 1, |
| 2184 | bulk_latency = 2, |
| 2185 | latency_invalid = 255 |
| 2186 | }; |
| 2187 | |
| 2188 | /** |
| 2189 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2190 | * @q_vector: structure containing interrupt and ring information |
| 2191 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2192 | * |
| 2193 | * Stores a new ITR value based on packets and byte |
| 2194 | * counts during the last interrupt. The advantage of per interrupt |
| 2195 | * computation is faster updates and more accurate ITR for the current |
| 2196 | * traffic pattern. Constants in this function were computed |
| 2197 | * based on theoretical maximum wire speed and thresholds were set based |
| 2198 | * on testing data as well as attempting to minimize response time |
| 2199 | * while increasing bulk throughput. |
| 2200 | * this functionality is controlled by the InterruptThrottleRate module |
| 2201 | * parameter (see ixgbe_param.c) |
| 2202 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2203 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2204 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2205 | { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2206 | int bytes = ring_container->total_bytes; |
| 2207 | int packets = ring_container->total_packets; |
| 2208 | u32 timepassed_us; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2209 | u64 bytes_perint; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2210 | u8 itr_setting = ring_container->itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2211 | |
| 2212 | if (packets == 0) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2213 | return; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2214 | |
| 2215 | /* simple throttlerate management |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2216 | * 0-10MB/s lowest (100000 ints/s) |
| 2217 | * 10-20MB/s low (20000 ints/s) |
| 2218 | * 20-1249MB/s bulk (8000 ints/s) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2219 | */ |
| 2220 | /* what was last interrupt timeslice? */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2221 | timepassed_us = q_vector->itr >> 2; |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2222 | if (timepassed_us == 0) |
| 2223 | return; |
| 2224 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2225 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 2226 | |
| 2227 | switch (itr_setting) { |
| 2228 | case lowest_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2229 | if (bytes_perint > 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2230 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2231 | break; |
| 2232 | case low_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2233 | if (bytes_perint > 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2234 | itr_setting = bulk_latency; |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2235 | else if (bytes_perint <= 10) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2236 | itr_setting = lowest_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2237 | break; |
| 2238 | case bulk_latency: |
Alexander Duyck | 621bd70 | 2012-02-08 07:50:20 +0000 | [diff] [blame] | 2239 | if (bytes_perint <= 20) |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2240 | itr_setting = low_latency; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2241 | break; |
| 2242 | } |
| 2243 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2244 | /* clear work counters since we have the values we need */ |
| 2245 | ring_container->total_bytes = 0; |
| 2246 | ring_container->total_packets = 0; |
| 2247 | |
| 2248 | /* write updated itr to ring container */ |
| 2249 | ring_container->itr = itr_setting; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2250 | } |
| 2251 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2252 | /** |
| 2253 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2254 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2255 | * |
| 2256 | * This function is made to be called by ethtool and by the driver |
| 2257 | * when it needs to update EITR registers at runtime. Hardware |
| 2258 | * specific quirks/differences are taken care of here. |
| 2259 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2260 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2261 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2262 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2263 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2264 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2265 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2266 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2267 | switch (adapter->hw.mac.type) { |
| 2268 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2269 | /* must write high and low 16 bits to reset counter */ |
| 2270 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2271 | break; |
| 2272 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2273 | case ixgbe_mac_X540: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2274 | /* |
| 2275 | * set the WDIS bit to not clear the timer bits and cause an |
| 2276 | * immediate assertion of the interrupt |
| 2277 | */ |
| 2278 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2279 | break; |
| 2280 | default: |
| 2281 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2282 | } |
| 2283 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2284 | } |
| 2285 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2286 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2287 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2288 | u32 new_itr = q_vector->itr; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2289 | u8 current_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2290 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2291 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2292 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2293 | |
Alexander Duyck | 08c8833 | 2011-06-11 01:45:03 +0000 | [diff] [blame] | 2294 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2295 | |
| 2296 | switch (current_itr) { |
| 2297 | /* counts and packets in update_itr are dependent on these numbers */ |
| 2298 | case lowest_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2299 | new_itr = IXGBE_100K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2300 | break; |
| 2301 | case low_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2302 | new_itr = IXGBE_20K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2303 | break; |
| 2304 | case bulk_latency: |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2305 | new_itr = IXGBE_8K_ITR; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2306 | break; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2307 | default: |
| 2308 | break; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2309 | } |
| 2310 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2311 | if (new_itr != q_vector->itr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2312 | /* do an exponential smoothing */ |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2313 | new_itr = (10 * new_itr * q_vector->itr) / |
| 2314 | ((9 * new_itr) + q_vector->itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2315 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2316 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2317 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2318 | |
| 2319 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2320 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2321 | } |
| 2322 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2323 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2324 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2325 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2326 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2327 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2328 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2329 | struct ixgbe_hw *hw = &adapter->hw; |
| 2330 | u32 eicr = adapter->interrupt_event; |
| 2331 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2332 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2333 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2334 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2335 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) && |
| 2336 | !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
| 2337 | return; |
| 2338 | |
| 2339 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2340 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2341 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2342 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2343 | /* |
| 2344 | * Since the warning interrupt is for both ports |
| 2345 | * we don't have to check if: |
| 2346 | * - This interrupt wasn't for our port. |
| 2347 | * - We may have missed the interrupt so always have to |
| 2348 | * check if we got a LSC |
| 2349 | */ |
| 2350 | if (!(eicr & IXGBE_EICR_GPI_SDP0) && |
| 2351 | !(eicr & IXGBE_EICR_LSC)) |
| 2352 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2353 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2354 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2355 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2356 | bool link_up = false; |
| 2357 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2358 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2359 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2360 | if (link_up) |
| 2361 | return; |
| 2362 | } |
| 2363 | |
| 2364 | /* Check if this is not due to overtemp */ |
| 2365 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2366 | return; |
| 2367 | |
| 2368 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2369 | default: |
| 2370 | if (!(eicr & IXGBE_EICR_GPI_SDP0)) |
| 2371 | return; |
| 2372 | break; |
| 2373 | } |
| 2374 | e_crit(drv, |
| 2375 | "Network adapter has been stopped because it has over heated. " |
| 2376 | "Restart the computer. If the problem persists, " |
| 2377 | "power off the system and replace the adapter\n"); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2378 | |
| 2379 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2382 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2383 | { |
| 2384 | struct ixgbe_hw *hw = &adapter->hw; |
| 2385 | |
| 2386 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 2387 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2388 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2389 | /* write to clear the interrupt */ |
| 2390 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 2391 | } |
| 2392 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2393 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2394 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2395 | { |
| 2396 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2397 | return; |
| 2398 | |
| 2399 | switch (adapter->hw.mac.type) { |
| 2400 | case ixgbe_mac_82599EB: |
| 2401 | /* |
| 2402 | * Need to check link state so complete overtemp check |
| 2403 | * on service task |
| 2404 | */ |
| 2405 | if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) && |
| 2406 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2407 | adapter->interrupt_event = eicr; |
| 2408 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2409 | ixgbe_service_event_schedule(adapter); |
| 2410 | return; |
| 2411 | } |
| 2412 | return; |
| 2413 | case ixgbe_mac_X540: |
| 2414 | if (!(eicr & IXGBE_EICR_TS)) |
| 2415 | return; |
| 2416 | break; |
| 2417 | default: |
| 2418 | return; |
| 2419 | } |
| 2420 | |
| 2421 | e_crit(drv, |
| 2422 | "Network adapter has been stopped because it has over heated. " |
| 2423 | "Restart the computer. If the problem persists, " |
| 2424 | "power off the system and replace the adapter\n"); |
| 2425 | } |
| 2426 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2427 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2428 | { |
| 2429 | struct ixgbe_hw *hw = &adapter->hw; |
| 2430 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2431 | if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 2432 | /* Clear the interrupt */ |
| 2433 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2434 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2435 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 2436 | ixgbe_service_event_schedule(adapter); |
| 2437 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2440 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 2441 | /* Clear the interrupt */ |
| 2442 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2443 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2444 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2445 | ixgbe_service_event_schedule(adapter); |
| 2446 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2447 | } |
| 2448 | } |
| 2449 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2450 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2451 | { |
| 2452 | struct ixgbe_hw *hw = &adapter->hw; |
| 2453 | |
| 2454 | adapter->lsc_int++; |
| 2455 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2456 | adapter->link_check_timeout = jiffies; |
| 2457 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2458 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2459 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2460 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2464 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2465 | u64 qmask) |
| 2466 | { |
| 2467 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2468 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2469 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2470 | switch (hw->mac.type) { |
| 2471 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2472 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2473 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2474 | break; |
| 2475 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2476 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2477 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2478 | if (mask) |
| 2479 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2480 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2481 | if (mask) |
| 2482 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2483 | break; |
| 2484 | default: |
| 2485 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2486 | } |
| 2487 | /* skip the flush */ |
| 2488 | } |
| 2489 | |
| 2490 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2491 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2492 | { |
| 2493 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2494 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2495 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2496 | switch (hw->mac.type) { |
| 2497 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2498 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2499 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2500 | break; |
| 2501 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2502 | case ixgbe_mac_X540: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2503 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2504 | if (mask) |
| 2505 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2506 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2507 | if (mask) |
| 2508 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2509 | break; |
| 2510 | default: |
| 2511 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2512 | } |
| 2513 | /* skip the flush */ |
| 2514 | } |
| 2515 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2516 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2517 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2518 | * @adapter: board private structure |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2519 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2520 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2521 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2522 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2523 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2524 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2525 | /* don't reenable LSC while waiting for link */ |
| 2526 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2527 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2528 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2529 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2530 | switch (adapter->hw.mac.type) { |
| 2531 | case ixgbe_mac_82599EB: |
| 2532 | mask |= IXGBE_EIMS_GPI_SDP0; |
| 2533 | break; |
| 2534 | case ixgbe_mac_X540: |
| 2535 | mask |= IXGBE_EIMS_TS; |
| 2536 | break; |
| 2537 | default: |
| 2538 | break; |
| 2539 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2540 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 2541 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2542 | switch (adapter->hw.mac.type) { |
| 2543 | case ixgbe_mac_82599EB: |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2544 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 2545 | mask |= IXGBE_EIMS_GPI_SDP2; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 2546 | case ixgbe_mac_X540: |
| 2547 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2548 | mask |= IXGBE_EIMS_MAILBOX; |
| 2549 | break; |
| 2550 | default: |
| 2551 | break; |
| 2552 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2553 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2554 | if (adapter->hw.mac.type == ixgbe_mac_X540) |
| 2555 | mask |= IXGBE_EIMS_TIMESYNC; |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2556 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2557 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 2558 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 2559 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2560 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2561 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 2562 | if (queues) |
| 2563 | ixgbe_irq_enable_queues(adapter, ~0); |
| 2564 | if (flush) |
| 2565 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2568 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2569 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2570 | struct ixgbe_adapter *adapter = data; |
| 2571 | struct ixgbe_hw *hw = &adapter->hw; |
| 2572 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2573 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2574 | /* |
| 2575 | * Workaround for Silicon errata. Use clear-by-write instead |
| 2576 | * of clear-by-read. Reading with EICS will return the |
| 2577 | * interrupt causes without clearing, which later be done |
| 2578 | * with the write to EICR. |
| 2579 | */ |
| 2580 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 2581 | |
| 2582 | /* The lower 16bits of the EICR register are for the queue interrupts |
| 2583 | * which should be masked here in order to not accidently clear them if |
| 2584 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 2585 | * condition otherwise which results in possible performance loss |
| 2586 | * especially if the ixgbe_msix_other interrupt is triggering |
| 2587 | * consistently (as it would when PPS is turned on for the X540 device) |
| 2588 | */ |
| 2589 | eicr &= 0xFFFF0000; |
| 2590 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2591 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2592 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2593 | if (eicr & IXGBE_EICR_LSC) |
| 2594 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2595 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2596 | if (eicr & IXGBE_EICR_MAILBOX) |
| 2597 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2598 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2599 | switch (hw->mac.type) { |
| 2600 | case ixgbe_mac_82599EB: |
| 2601 | case ixgbe_mac_X540: |
| 2602 | if (eicr & IXGBE_EICR_ECC) |
| 2603 | e_info(link, "Received unrecoverable ECC Err, please " |
| 2604 | "reboot\n"); |
| 2605 | /* Handle Flow Director Full threshold interrupt */ |
| 2606 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 2607 | int reinit_count = 0; |
| 2608 | int i; |
| 2609 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2610 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 2611 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 2612 | &ring->state)) |
| 2613 | reinit_count++; |
| 2614 | } |
| 2615 | if (reinit_count) { |
| 2616 | /* no more flow director interrupts until after init */ |
| 2617 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 2618 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 2619 | ixgbe_service_event_schedule(adapter); |
| 2620 | } |
| 2621 | } |
| 2622 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2623 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2624 | break; |
| 2625 | default: |
| 2626 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2627 | } |
| 2628 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2629 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2630 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2631 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
| 2632 | ixgbe_ptp_check_pps_event(adapter, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2633 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2634 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2635 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2636 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2637 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2638 | return IRQ_HANDLED; |
| 2639 | } |
| 2640 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2641 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2642 | { |
| 2643 | struct ixgbe_q_vector *q_vector = data; |
| 2644 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2645 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2646 | |
| 2647 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 2648 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2649 | |
| 2650 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2653 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2654 | * ixgbe_poll - NAPI Rx polling callback |
| 2655 | * @napi: structure for representing this polling device |
| 2656 | * @budget: how many packets driver is allowed to clean |
| 2657 | * |
| 2658 | * This function is used for legacy and MSI, NAPI mode |
| 2659 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 2660 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2661 | { |
| 2662 | struct ixgbe_q_vector *q_vector = |
| 2663 | container_of(napi, struct ixgbe_q_vector, napi); |
| 2664 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 2665 | struct ixgbe_ring *ring; |
| 2666 | int per_ring_budget; |
| 2667 | bool clean_complete = true; |
| 2668 | |
| 2669 | #ifdef CONFIG_IXGBE_DCA |
| 2670 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 2671 | ixgbe_update_dca(q_vector); |
| 2672 | #endif |
| 2673 | |
| 2674 | ixgbe_for_each_ring(ring, q_vector->tx) |
| 2675 | clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring); |
| 2676 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2677 | if (!ixgbe_qv_lock_napi(q_vector)) |
| 2678 | return budget; |
| 2679 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2680 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 2681 | * the budget to go below 1 because we'll exit polling */ |
| 2682 | if (q_vector->rx.count > 1) |
| 2683 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 2684 | else |
| 2685 | per_ring_budget = budget; |
| 2686 | |
| 2687 | ixgbe_for_each_ring(ring, q_vector->rx) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2688 | clean_complete &= (ixgbe_clean_rx_irq(q_vector, ring, |
| 2689 | per_ring_budget) < per_ring_budget); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2690 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2691 | ixgbe_qv_unlock_napi(q_vector); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 2692 | /* If all work not completed, return budget and keep polling */ |
| 2693 | if (!clean_complete) |
| 2694 | return budget; |
| 2695 | |
| 2696 | /* all work done, exit the polling mode */ |
| 2697 | napi_complete(napi); |
| 2698 | if (adapter->rx_itr_setting & 1) |
| 2699 | ixgbe_set_itr(q_vector); |
| 2700 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2701 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 2702 | |
| 2703 | return 0; |
| 2704 | } |
| 2705 | |
| 2706 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2707 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 2708 | * @adapter: board private structure |
| 2709 | * |
| 2710 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 2711 | * interrupts from the kernel. |
| 2712 | **/ |
| 2713 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 2714 | { |
| 2715 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2716 | int vector, err; |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2717 | int ri = 0, ti = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2718 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2719 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2720 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2721 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 2722 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2723 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 2724 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2725 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2726 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2727 | } else if (q_vector->rx.ring) { |
| 2728 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2729 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 2730 | } else if (q_vector->tx.ring) { |
| 2731 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 2732 | "%s-%s-%d", netdev->name, "tx", ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 2733 | } else { |
| 2734 | /* skip this unused q_vector */ |
| 2735 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 2736 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2737 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 2738 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2739 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2740 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 2741 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2742 | goto free_queue_irqs; |
| 2743 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2744 | /* If Flow Director is enabled, set interrupt affinity */ |
| 2745 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2746 | /* assign the mask for this irq */ |
| 2747 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2748 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2749 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2750 | } |
| 2751 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2752 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2753 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2754 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2755 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2756 | goto free_queue_irqs; |
| 2757 | } |
| 2758 | |
| 2759 | return 0; |
| 2760 | |
| 2761 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 2762 | while (vector) { |
| 2763 | vector--; |
| 2764 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 2765 | NULL); |
| 2766 | free_irq(adapter->msix_entries[vector].vector, |
| 2767 | adapter->q_vector[vector]); |
| 2768 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2769 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2770 | pci_disable_msix(adapter->pdev); |
| 2771 | kfree(adapter->msix_entries); |
| 2772 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2773 | return err; |
| 2774 | } |
| 2775 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 2776 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2777 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2778 | * @irq: interrupt number |
| 2779 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2780 | **/ |
| 2781 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 2782 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2783 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2784 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2785 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2786 | u32 eicr; |
| 2787 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2788 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 2789 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 2790 | * before the read of EICR. |
| 2791 | */ |
| 2792 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 2793 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2794 | /* 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] | 2795 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2796 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2797 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2798 | /* |
| 2799 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2800 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2801 | * have disabled interrupts due to EIAM |
| 2802 | * finish the workaround of silicon errata on 82598. Unmask |
| 2803 | * the interrupt that we masked before the EICR read. |
| 2804 | */ |
| 2805 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2806 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2807 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 2808 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2809 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2810 | if (eicr & IXGBE_EICR_LSC) |
| 2811 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2812 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2813 | switch (hw->mac.type) { |
| 2814 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2815 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 2816 | /* Fall through */ |
| 2817 | case ixgbe_mac_X540: |
| 2818 | if (eicr & IXGBE_EICR_ECC) |
| 2819 | e_info(link, "Received unrecoverable ECC err, please " |
| 2820 | "reboot\n"); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2821 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2822 | break; |
| 2823 | default: |
| 2824 | break; |
| 2825 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2826 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2827 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 2828 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
| 2829 | ixgbe_ptp_check_pps_event(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2830 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 2831 | /* would disable interrupts here but EIAM disabled it */ |
| 2832 | napi_schedule(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2833 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2834 | /* |
| 2835 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 2836 | * ixgbe_poll will re-enable the queue interrupts |
| 2837 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 2838 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2839 | ixgbe_irq_enable(adapter, false, false); |
| 2840 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2841 | return IRQ_HANDLED; |
| 2842 | } |
| 2843 | |
| 2844 | /** |
| 2845 | * ixgbe_request_irq - initialize interrupts |
| 2846 | * @adapter: board private structure |
| 2847 | * |
| 2848 | * Attempts to configure interrupts using the best available |
| 2849 | * capabilities of the hardware and kernel. |
| 2850 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2851 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2852 | { |
| 2853 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2854 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2855 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2856 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2857 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2858 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2859 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2860 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 2861 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 2862 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2863 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2864 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2865 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2866 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2867 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2868 | return err; |
| 2869 | } |
| 2870 | |
| 2871 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 2872 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2873 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2874 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2875 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 2876 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2877 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2878 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2879 | |
| 2880 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 2881 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 2882 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 2883 | |
| 2884 | /* free only the irqs that were actually requested */ |
| 2885 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 2886 | continue; |
| 2887 | |
| 2888 | /* clear the affinity_mask in the IRQ descriptor */ |
| 2889 | irq_set_affinity_hint(entry->vector, NULL); |
| 2890 | |
| 2891 | free_irq(entry->vector, q_vector); |
| 2892 | } |
| 2893 | |
| 2894 | free_irq(adapter->msix_entries[vector++].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2898 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 2899 | * @adapter: board private structure |
| 2900 | **/ |
| 2901 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 2902 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2903 | switch (adapter->hw.mac.type) { |
| 2904 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2905 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2906 | break; |
| 2907 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2908 | case ixgbe_mac_X540: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 2909 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 2910 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2911 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2912 | break; |
| 2913 | default: |
| 2914 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2915 | } |
| 2916 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 2917 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2918 | int vector; |
| 2919 | |
| 2920 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 2921 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 2922 | |
| 2923 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2924 | } else { |
| 2925 | synchronize_irq(adapter->pdev->irq); |
| 2926 | } |
| 2927 | } |
| 2928 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2929 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2930 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2931 | * |
| 2932 | **/ |
| 2933 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2934 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2935 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2936 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2937 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2938 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2939 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2940 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2941 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2942 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2945 | /** |
| 2946 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 2947 | * @adapter: board private structure |
| 2948 | * @ring: structure containing ring specific data |
| 2949 | * |
| 2950 | * Configure the Tx descriptor ring after a reset. |
| 2951 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 2952 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 2953 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2954 | { |
| 2955 | struct ixgbe_hw *hw = &adapter->hw; |
| 2956 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2957 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2958 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 2959 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2960 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2961 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2962 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2963 | IXGBE_WRITE_FLUSH(hw); |
| 2964 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2965 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2966 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2967 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 2968 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 2969 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 2970 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 2971 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 2972 | ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 2973 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2974 | /* |
| 2975 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2976 | * higher than 1 when: |
| 2977 | * - ITR is 0 as it could cause false TX hangs |
| 2978 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2979 | * |
| 2980 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 2981 | * to or less than the number of on chip descriptors, which is |
| 2982 | * currently 40. |
| 2983 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2984 | #if IS_ENABLED(CONFIG_BQL) |
| 2985 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
| 2986 | #else |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2987 | if (!ring->q_vector || (ring->q_vector->itr < 8)) |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 2988 | #endif |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2989 | txdctl |= (1 << 16); /* WTHRESH = 1 */ |
| 2990 | else |
| 2991 | txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 2992 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 2993 | /* |
| 2994 | * Setting PTHRESH to 32 both improves performance |
| 2995 | * and avoids a TX hang with DFP enabled |
| 2996 | */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 2997 | txdctl |= (1 << 8) | /* HTHRESH = 1 */ |
| 2998 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 2999 | |
| 3000 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3001 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3002 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3003 | ring->atr_count = 0; |
| 3004 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3005 | } else { |
| 3006 | ring->atr_sample_rate = 0; |
| 3007 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3008 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3009 | /* initialize XPS */ |
| 3010 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3011 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3012 | |
| 3013 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3014 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3015 | &q_vector->affinity_mask, |
| 3016 | ring->queue_index); |
| 3017 | } |
| 3018 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3019 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3020 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3021 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3022 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3023 | |
| 3024 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3025 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3026 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3027 | return; |
| 3028 | |
| 3029 | /* poll to verify queue is enabled */ |
| 3030 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3031 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3032 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3033 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3034 | if (!wait_loop) |
| 3035 | e_err(drv, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3038 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3039 | { |
| 3040 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3041 | u32 rttdcs, mtqc; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3042 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3043 | |
| 3044 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3045 | return; |
| 3046 | |
| 3047 | /* disable the arbiter while setting MTQC */ |
| 3048 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3049 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3050 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3051 | |
| 3052 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3053 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3054 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3055 | if (tcs > 4) |
| 3056 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3057 | else if (tcs > 1) |
| 3058 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3059 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3060 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3061 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3062 | mtqc |= IXGBE_MTQC_64VF; |
| 3063 | } else { |
| 3064 | if (tcs > 4) |
| 3065 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3066 | else if (tcs > 1) |
| 3067 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3068 | else |
| 3069 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3070 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3071 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3072 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3073 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3074 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3075 | if (tcs) { |
| 3076 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3077 | sectx |= IXGBE_SECTX_DCB; |
| 3078 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | /* re-enable the arbiter */ |
| 3082 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3083 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3084 | } |
| 3085 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3086 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3087 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3088 | * @adapter: board private structure |
| 3089 | * |
| 3090 | * Configure the Tx unit of the MAC after a reset. |
| 3091 | **/ |
| 3092 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3093 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3094 | struct ixgbe_hw *hw = &adapter->hw; |
| 3095 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3096 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3097 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3098 | ixgbe_setup_mtqc(adapter); |
| 3099 | |
| 3100 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3101 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3102 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3103 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3104 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3105 | } |
| 3106 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3107 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3108 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3109 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3112 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3113 | struct ixgbe_ring *ring) |
| 3114 | { |
| 3115 | struct ixgbe_hw *hw = &adapter->hw; |
| 3116 | u8 reg_idx = ring->reg_idx; |
| 3117 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3118 | |
| 3119 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3120 | |
| 3121 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3122 | } |
| 3123 | |
| 3124 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3125 | struct ixgbe_ring *ring) |
| 3126 | { |
| 3127 | struct ixgbe_hw *hw = &adapter->hw; |
| 3128 | u8 reg_idx = ring->reg_idx; |
| 3129 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3130 | |
| 3131 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3132 | |
| 3133 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3134 | } |
| 3135 | |
| 3136 | #ifdef CONFIG_IXGBE_DCB |
| 3137 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3138 | #else |
| 3139 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3140 | #endif |
| 3141 | { |
| 3142 | int i; |
| 3143 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3144 | |
| 3145 | if (adapter->ixgbe_ieee_pfc) |
| 3146 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3147 | |
| 3148 | /* |
| 3149 | * We should set the drop enable bit if: |
| 3150 | * SR-IOV is enabled |
| 3151 | * or |
| 3152 | * Number of Rx queues > 1 and flow control is disabled |
| 3153 | * |
| 3154 | * This allows us to avoid head of line blocking for security |
| 3155 | * and performance reasons. |
| 3156 | */ |
| 3157 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3158 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3159 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3160 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3161 | } else { |
| 3162 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3163 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3164 | } |
| 3165 | } |
| 3166 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3167 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3168 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3169 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3170 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3171 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3172 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3173 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3174 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3175 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3176 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3177 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3178 | |
| 3179 | /* |
| 3180 | * if VMDq is not active we must program one srrctl register |
| 3181 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3182 | */ |
| 3183 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3184 | } |
| 3185 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3186 | /* configure header buffer length, needed for RSC */ |
| 3187 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3188 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3189 | /* configure the packet buffer length */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3190 | srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3191 | |
| 3192 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3193 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3194 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3195 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3198 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3199 | { |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3200 | struct ixgbe_hw *hw = &adapter->hw; |
| 3201 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3202 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 3203 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3204 | u32 mrqc = 0, reta = 0; |
| 3205 | u32 rxcsum; |
| 3206 | int i, j; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3207 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3208 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3209 | /* |
| 3210 | * Program table for at least 2 queues w/ SR-IOV so that VFs can |
| 3211 | * make full use of any rings they may have. We will use the |
| 3212 | * PSRTYPE register to control how many rings we use within the PF. |
| 3213 | */ |
| 3214 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2)) |
| 3215 | rss_i = 2; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3216 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3217 | /* Fill out hash function seeds */ |
| 3218 | for (i = 0; i < 10; i++) |
| 3219 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3220 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3221 | /* Fill out redirection table */ |
| 3222 | for (i = 0, j = 0; i < 128; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3223 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3224 | j = 0; |
| 3225 | /* reta = 4-byte sliding window of |
| 3226 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 3227 | reta = (reta << 8) | (j * 0x11); |
| 3228 | if ((i & 3) == 3) |
| 3229 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3230 | } |
| 3231 | |
| 3232 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3233 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3234 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3235 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3236 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3237 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3238 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3239 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3240 | } else { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3241 | u8 tcs = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3242 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3243 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3244 | if (tcs > 4) |
| 3245 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3246 | else if (tcs > 1) |
| 3247 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
| 3248 | else if (adapter->ring_feature[RING_F_RSS].indices == 4) |
| 3249 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3250 | else |
| 3251 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
| 3252 | } else { |
| 3253 | if (tcs > 4) |
| 3254 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3255 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3256 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3257 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3258 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3259 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3260 | } |
| 3261 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3262 | /* Perform hash on these packet types */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3263 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3264 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3265 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3266 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3267 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3268 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
| 3269 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
| 3270 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
| 3271 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
| 3272 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3273 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3274 | } |
| 3275 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3276 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3277 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 3278 | * @adapter: address of board private structure |
| 3279 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3280 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3281 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3282 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3283 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3284 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3285 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3286 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3287 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3288 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3289 | return; |
| 3290 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3291 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3292 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3293 | /* |
| 3294 | * we must limit the number of descriptors so that the |
| 3295 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3296 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3297 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3298 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3299 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3302 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3303 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 3304 | struct ixgbe_ring *ring) |
| 3305 | { |
| 3306 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3307 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3308 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3309 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3310 | |
| 3311 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3312 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3313 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3314 | return; |
| 3315 | |
| 3316 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3317 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3318 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3319 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3320 | |
| 3321 | if (!wait_loop) { |
| 3322 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 3323 | "the polling period\n", reg_idx); |
| 3324 | } |
| 3325 | } |
| 3326 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3327 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 3328 | struct ixgbe_ring *ring) |
| 3329 | { |
| 3330 | struct ixgbe_hw *hw = &adapter->hw; |
| 3331 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 3332 | u32 rxdctl; |
| 3333 | u8 reg_idx = ring->reg_idx; |
| 3334 | |
| 3335 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3336 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 3337 | |
| 3338 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 3339 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3340 | |
| 3341 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3342 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3343 | return; |
| 3344 | |
| 3345 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 3346 | do { |
| 3347 | udelay(10); |
| 3348 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 3349 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 3350 | |
| 3351 | if (!wait_loop) { |
| 3352 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 3353 | "the polling period\n", reg_idx); |
| 3354 | } |
| 3355 | } |
| 3356 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3357 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 3358 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3359 | { |
| 3360 | struct ixgbe_hw *hw = &adapter->hw; |
| 3361 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3362 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3363 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3364 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3365 | /* disable queue to avoid issues while updating state */ |
| 3366 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 3367 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3368 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3369 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 3370 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 3371 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 3372 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 3373 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 3374 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 3375 | ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3376 | |
| 3377 | ixgbe_configure_srrctl(adapter, ring); |
| 3378 | ixgbe_configure_rscctl(adapter, ring); |
| 3379 | |
| 3380 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3381 | /* |
| 3382 | * enable cache line friendly hardware writes: |
| 3383 | * PTHRESH=32 descriptors (half the internal cache), |
| 3384 | * this also removes ugly rx_no_buffer_count increment |
| 3385 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 3386 | * WTHRESH=8 burst writeback up to two cache lines |
| 3387 | */ |
| 3388 | rxdctl &= ~0x3FFFFF; |
| 3389 | rxdctl |= 0x080420; |
| 3390 | } |
| 3391 | |
| 3392 | /* enable receive descriptor ring */ |
| 3393 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 3394 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 3395 | |
| 3396 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 3397 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 3398 | } |
| 3399 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3400 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 3401 | { |
| 3402 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3403 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3404 | u16 pool; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3405 | |
| 3406 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 3407 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3408 | IXGBE_PSRTYPE_UDPHDR | |
| 3409 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3410 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3411 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3412 | |
| 3413 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3414 | return; |
| 3415 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3416 | if (rss_i > 3) |
| 3417 | psrtype |= 2 << 29; |
| 3418 | else if (rss_i > 1) |
| 3419 | psrtype |= 1 << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3420 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3421 | for_each_set_bit(pool, &adapter->fwd_bitmask, 32) |
| 3422 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3423 | } |
| 3424 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3425 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 3426 | { |
| 3427 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3428 | u32 reg_offset, vf_shift; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3429 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3430 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3431 | |
| 3432 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 3433 | return; |
| 3434 | |
| 3435 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3436 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 3437 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3438 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3439 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 3440 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3441 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3442 | vf_shift = VMDQ_P(0) % 32; |
| 3443 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3444 | |
| 3445 | /* Enable only the PF's pool for Tx/Rx */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3446 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift); |
| 3447 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
| 3448 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift); |
| 3449 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 3450 | if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB) |
| 3451 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3452 | |
| 3453 | /* 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] | 3454 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3455 | |
| 3456 | /* |
| 3457 | * Set up VF register offsets for selected VT Mode, |
| 3458 | * i.e. 32 or 64 VFs for SR-IOV |
| 3459 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 3460 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 3461 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 3462 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 3463 | break; |
| 3464 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 3465 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 3466 | break; |
| 3467 | default: |
| 3468 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 3469 | break; |
| 3470 | } |
| 3471 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3472 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 3473 | |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3474 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3475 | /* Enable MAC Anti-Spoofing */ |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 3476 | hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0), |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 3477 | adapter->num_vfs); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 3478 | /* For VFs that have spoof checking turned off */ |
| 3479 | for (i = 0; i < adapter->num_vfs; i++) { |
| 3480 | if (!adapter->vfinfo[i].spoofchk_enabled) |
| 3481 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false); |
| 3482 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3483 | } |
| 3484 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3485 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3486 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3487 | struct ixgbe_hw *hw = &adapter->hw; |
| 3488 | struct net_device *netdev = adapter->netdev; |
| 3489 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3490 | struct ixgbe_ring *rx_ring; |
| 3491 | int i; |
| 3492 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 3493 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3494 | #ifdef IXGBE_FCOE |
| 3495 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 3496 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 3497 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 3498 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 3499 | |
| 3500 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 3501 | |
| 3502 | /* adjust max frame to be at least the size of a standard frame */ |
| 3503 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 3504 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 3505 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3506 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 3507 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 3508 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 3509 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 3510 | |
| 3511 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3514 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3515 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 3516 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3517 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 3518 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3519 | /* |
| 3520 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3521 | * the Base and Length of the Rx Descriptor Ring |
| 3522 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3523 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3524 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3525 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 3526 | set_ring_rsc_enabled(rx_ring); |
| 3527 | else |
| 3528 | clear_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3529 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3532 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 3533 | { |
| 3534 | struct ixgbe_hw *hw = &adapter->hw; |
| 3535 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 3536 | |
| 3537 | switch (hw->mac.type) { |
| 3538 | case ixgbe_mac_82598EB: |
| 3539 | /* |
| 3540 | * For VMDq support of different descriptor types or |
| 3541 | * buffer sizes through the use of multiple SRRCTL |
| 3542 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 3543 | * |
| 3544 | * also, the manual doesn't mention it clearly but DCA hints |
| 3545 | * will only use queue 0's tags unless this bit is set. Side |
| 3546 | * effects of setting this bit are only that SRRCTL must be |
| 3547 | * fully programmed [0..15] |
| 3548 | */ |
| 3549 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 3550 | break; |
| 3551 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3552 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3553 | /* Disable RSC for ACK packets */ |
| 3554 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 3555 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 3556 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 3557 | /* hardware requires some bits to be set by default */ |
| 3558 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 3559 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 3560 | break; |
| 3561 | default: |
| 3562 | /* We should do nothing since we don't know this hardware */ |
| 3563 | return; |
| 3564 | } |
| 3565 | |
| 3566 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 3567 | } |
| 3568 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3569 | /** |
| 3570 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 3571 | * @adapter: board private structure |
| 3572 | * |
| 3573 | * Configure the Rx unit of the MAC after a reset. |
| 3574 | **/ |
| 3575 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 3576 | { |
| 3577 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3578 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3579 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3580 | |
| 3581 | /* disable receives while setting up the descriptors */ |
| 3582 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3583 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 3584 | |
| 3585 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3586 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3587 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 3588 | /* RSC Setup */ |
| 3589 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 3590 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 3591 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 3592 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
| 3593 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 3594 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3595 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3596 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 3597 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 3598 | /* set_rx_buffer_len must be called before ring initialization */ |
| 3599 | ixgbe_set_rx_buffer_len(adapter); |
| 3600 | |
| 3601 | /* |
| 3602 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 3603 | * the Base and Length of the Rx Descriptor Ring |
| 3604 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3605 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3606 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3607 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3608 | /* disable drop enable for 82598 parts */ |
| 3609 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3610 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 3611 | |
| 3612 | /* enable all receives */ |
| 3613 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 3614 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3617 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 3618 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3619 | { |
| 3620 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3621 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3622 | |
| 3623 | /* add VID to filter table */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3624 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3625 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3626 | |
| 3627 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3630 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 3631 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3632 | { |
| 3633 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3634 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3635 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3636 | /* remove VID from filter table */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3637 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3638 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 3639 | |
| 3640 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3643 | /** |
| 3644 | * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering |
| 3645 | * @adapter: driver data |
| 3646 | */ |
| 3647 | static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter) |
| 3648 | { |
| 3649 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3650 | u32 vlnctrl; |
| 3651 | |
| 3652 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3653 | vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); |
| 3654 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3655 | } |
| 3656 | |
| 3657 | /** |
| 3658 | * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering |
| 3659 | * @adapter: driver data |
| 3660 | */ |
| 3661 | static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter) |
| 3662 | { |
| 3663 | struct ixgbe_hw *hw = &adapter->hw; |
| 3664 | u32 vlnctrl; |
| 3665 | |
| 3666 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3667 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 3668 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 3669 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3670 | } |
| 3671 | |
| 3672 | /** |
| 3673 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 3674 | * @adapter: driver data |
| 3675 | */ |
| 3676 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 3677 | { |
| 3678 | struct ixgbe_hw *hw = &adapter->hw; |
| 3679 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3680 | int i, j; |
| 3681 | |
| 3682 | switch (hw->mac.type) { |
| 3683 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3684 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3685 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3686 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3687 | break; |
| 3688 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3689 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3690 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3691 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 3692 | |
| 3693 | if (ring->l2_accel_priv) |
| 3694 | continue; |
| 3695 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3696 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3697 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 3698 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3699 | } |
| 3700 | break; |
| 3701 | default: |
| 3702 | break; |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3707 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3708 | * @adapter: driver data |
| 3709 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3710 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3711 | { |
| 3712 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3713 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3714 | int i, j; |
| 3715 | |
| 3716 | switch (hw->mac.type) { |
| 3717 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3718 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 3719 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3720 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 3721 | break; |
| 3722 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3723 | case ixgbe_mac_X540: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3724 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3725 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 3726 | |
| 3727 | if (ring->l2_accel_priv) |
| 3728 | continue; |
| 3729 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3730 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 3731 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 3732 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 3733 | } |
| 3734 | break; |
| 3735 | default: |
| 3736 | break; |
| 3737 | } |
| 3738 | } |
| 3739 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3740 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 3741 | { |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3742 | u16 vid; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3743 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3744 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3745 | |
| 3746 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 3747 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | /** |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3751 | * ixgbe_write_uc_addr_list - write unicast addresses to RAR table |
| 3752 | * @netdev: network interface device structure |
| 3753 | * |
| 3754 | * Writes unicast address list to the RAR table. |
| 3755 | * Returns: -ENOMEM on failure/insufficient address space |
| 3756 | * 0 on no addresses written |
| 3757 | * X on writing X addresses to the RAR table |
| 3758 | **/ |
| 3759 | static int ixgbe_write_uc_addr_list(struct net_device *netdev) |
| 3760 | { |
| 3761 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3762 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 3763 | unsigned int rar_entries = hw->mac.num_rar_entries - 1; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3764 | int count = 0; |
| 3765 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3766 | /* In SR-IOV/VMDQ modes significantly less RAR entries are available */ |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 3767 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3768 | rar_entries = IXGBE_MAX_PF_MACVLANS - 1; |
| 3769 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3770 | /* return ENOMEM indicating insufficient memory for addresses */ |
| 3771 | if (netdev_uc_count(netdev) > rar_entries) |
| 3772 | return -ENOMEM; |
| 3773 | |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 3774 | if (!netdev_uc_empty(netdev)) { |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3775 | struct netdev_hw_addr *ha; |
| 3776 | /* return error if we do not support writing to RAR table */ |
| 3777 | if (!hw->mac.ops.set_rar) |
| 3778 | return -ENOMEM; |
| 3779 | |
| 3780 | netdev_for_each_uc_addr(ha, netdev) { |
| 3781 | if (!rar_entries) |
| 3782 | break; |
| 3783 | hw->mac.ops.set_rar(hw, rar_entries--, ha->addr, |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3784 | VMDQ_P(0), IXGBE_RAH_AV); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3785 | count++; |
| 3786 | } |
| 3787 | } |
| 3788 | /* write the addresses in reverse order to avoid write combining */ |
| 3789 | for (; rar_entries > 0 ; rar_entries--) |
| 3790 | hw->mac.ops.clear_rar(hw, rar_entries); |
| 3791 | |
| 3792 | return count; |
| 3793 | } |
| 3794 | |
| 3795 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3796 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3797 | * @netdev: network interface device structure |
| 3798 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 3799 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 3800 | * address list or the network interface flags are updated. This routine is |
| 3801 | * responsible for configuring the hardware for proper unicast, multicast and |
| 3802 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3803 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 3804 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3805 | { |
| 3806 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3807 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3808 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
| 3809 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3810 | |
| 3811 | /* Check for Promiscuous and All Multicast modes */ |
| 3812 | |
| 3813 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3814 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3815 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3816 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 3817 | fctrl |= IXGBE_FCTRL_BAM; |
| 3818 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 3819 | fctrl |= IXGBE_FCTRL_PMCF; |
| 3820 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3821 | /* clear the bits we are changing the status of */ |
| 3822 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 3823 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3824 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3825 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3826 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3827 | vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE); |
Greg Rose | 670224f | 2013-02-22 02:14:39 +0000 | [diff] [blame] | 3828 | /* Only disable hardware filter vlans in promiscuous mode |
| 3829 | * if SR-IOV and VMDQ are disabled - otherwise ensure |
| 3830 | * that hardware VLAN filters remain enabled. |
| 3831 | */ |
| 3832 | if (!(adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED | |
| 3833 | IXGBE_FLAG_SRIOV_ENABLED))) |
| 3834 | ixgbe_vlan_filter_disable(adapter); |
| 3835 | else |
| 3836 | ixgbe_vlan_filter_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3837 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3838 | if (netdev->flags & IFF_ALLMULTI) { |
| 3839 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3840 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 3841 | } |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 3842 | ixgbe_vlan_filter_enable(adapter); |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 3843 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | /* |
| 3847 | * Write addresses to available RAR registers, if there is not |
| 3848 | * sufficient space to store all the addresses then enable |
| 3849 | * unicast promiscuous mode |
| 3850 | */ |
| 3851 | count = ixgbe_write_uc_addr_list(netdev); |
| 3852 | if (count < 0) { |
| 3853 | fctrl |= IXGBE_FCTRL_UPE; |
| 3854 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3855 | } |
| 3856 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 3857 | /* Write addresses to the MTA, if the attempt fails |
| 3858 | * then we should just turn on promiscuous mode so |
| 3859 | * that we can at least receive multicast traffic |
| 3860 | */ |
| 3861 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 3862 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 3863 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3864 | if (adapter->num_vfs) |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3865 | ixgbe_restore_vf_multicasts(adapter); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3866 | |
| 3867 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3868 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 3869 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 3870 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 3871 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 3874 | /* This is useful for sniffing bad packets. */ |
| 3875 | if (adapter->netdev->features & NETIF_F_RXALL) { |
| 3876 | /* UPE and MPE will be handled by normal PROMISC logic |
| 3877 | * in e1000e_set_rx_mode */ |
| 3878 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 3879 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 3880 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 3881 | |
| 3882 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 3883 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 3884 | } |
| 3885 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3886 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3887 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 3888 | if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 3889 | ixgbe_vlan_strip_enable(adapter); |
| 3890 | else |
| 3891 | ixgbe_vlan_strip_disable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3894 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 3895 | { |
| 3896 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3897 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 3898 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
| 3899 | ixgbe_qv_init_lock(adapter->q_vector[q_idx]); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3900 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 3901 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 3905 | { |
| 3906 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3907 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 3908 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3909 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 3910 | while (!ixgbe_qv_disable(adapter->q_vector[q_idx])) { |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 3911 | pr_info("QV %d locked\n", q_idx); |
Jacob Keller | 27d9ce4 | 2013-09-21 05:05:44 +0000 | [diff] [blame] | 3912 | usleep_range(1000, 20000); |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 3913 | } |
| 3914 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3915 | } |
| 3916 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3917 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3918 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3919 | * ixgbe_configure_dcb - Configure DCB hardware |
| 3920 | * @adapter: ixgbe adapter struct |
| 3921 | * |
| 3922 | * This is called by the driver on open to configure the DCB hardware. |
| 3923 | * This is also called by the gennetlink interface when reconfiguring |
| 3924 | * the DCB state. |
| 3925 | */ |
| 3926 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 3927 | { |
| 3928 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307 | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 3929 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3930 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 3931 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 3932 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3933 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 3934 | return; |
| 3935 | } |
| 3936 | |
| 3937 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3938 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 3939 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3940 | #ifdef IXGBE_FCOE |
| 3941 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 3942 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 3943 | #endif |
| 3944 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 3945 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 3946 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3947 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3948 | DCB_TX_CONFIG); |
| 3949 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 3950 | DCB_RX_CONFIG); |
| 3951 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 3952 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 3953 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 3954 | adapter->ixgbe_ieee_ets, |
| 3955 | max_frame); |
| 3956 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 3957 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 3958 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 3959 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3960 | |
| 3961 | /* Enable RSS Hash per TC */ |
| 3962 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 3963 | u32 msb = 0; |
| 3964 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3965 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 3966 | while (rss_i) { |
| 3967 | msb++; |
| 3968 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3969 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 3970 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 3971 | /* write msb to all 8 TCs in one write */ |
| 3972 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 3973 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3974 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3975 | #endif |
| 3976 | |
| 3977 | /* Additional bittime to account for IXGBE framing */ |
| 3978 | #define IXGBE_ETH_FRAMING 20 |
| 3979 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3980 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3981 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 3982 | * |
| 3983 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3984 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 3985 | */ |
| 3986 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 3987 | { |
| 3988 | struct ixgbe_hw *hw = &adapter->hw; |
| 3989 | struct net_device *dev = adapter->netdev; |
| 3990 | int link, tc, kb, marker; |
| 3991 | u32 dv_id, rx_pba; |
| 3992 | |
| 3993 | /* Calculate max LAN frame size */ |
| 3994 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 3995 | |
| 3996 | #ifdef IXGBE_FCOE |
| 3997 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 3998 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 3999 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 4000 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 4001 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4002 | |
| 4003 | #endif |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4004 | /* Calculate delay value for device */ |
| 4005 | switch (hw->mac.type) { |
| 4006 | case ixgbe_mac_X540: |
| 4007 | dv_id = IXGBE_DV_X540(link, tc); |
| 4008 | break; |
| 4009 | default: |
| 4010 | dv_id = IXGBE_DV(link, tc); |
| 4011 | break; |
| 4012 | } |
| 4013 | |
| 4014 | /* Loopback switch introduces additional latency */ |
| 4015 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4016 | dv_id += IXGBE_B2BT(tc); |
| 4017 | |
| 4018 | /* Delay value is calculated in bit times convert to KB */ |
| 4019 | kb = IXGBE_BT2KB(dv_id); |
| 4020 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 4021 | |
| 4022 | marker = rx_pba - kb; |
| 4023 | |
| 4024 | /* It is possible that the packet buffer is not large enough |
| 4025 | * to provide required headroom. In this case throw an error |
| 4026 | * to user and a do the best we can. |
| 4027 | */ |
| 4028 | if (marker < 0) { |
| 4029 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 4030 | "headroom to support flow control." |
| 4031 | "Decrease MTU or number of traffic classes\n", pb); |
| 4032 | marker = tc + 1; |
| 4033 | } |
| 4034 | |
| 4035 | return marker; |
| 4036 | } |
| 4037 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4038 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4039 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 4040 | * |
| 4041 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4042 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4043 | */ |
| 4044 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter) |
| 4045 | { |
| 4046 | struct ixgbe_hw *hw = &adapter->hw; |
| 4047 | struct net_device *dev = adapter->netdev; |
| 4048 | int tc; |
| 4049 | u32 dv_id; |
| 4050 | |
| 4051 | /* Calculate max LAN frame size */ |
| 4052 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4053 | |
| 4054 | /* Calculate delay value for device */ |
| 4055 | switch (hw->mac.type) { |
| 4056 | case ixgbe_mac_X540: |
| 4057 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 4058 | break; |
| 4059 | default: |
| 4060 | dv_id = IXGBE_LOW_DV(tc); |
| 4061 | break; |
| 4062 | } |
| 4063 | |
| 4064 | /* Delay value is calculated in bit times convert to KB */ |
| 4065 | return IXGBE_BT2KB(dv_id); |
| 4066 | } |
| 4067 | |
| 4068 | /* |
| 4069 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 4070 | */ |
| 4071 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 4072 | { |
| 4073 | struct ixgbe_hw *hw = &adapter->hw; |
| 4074 | int num_tc = netdev_get_num_tc(adapter->netdev); |
| 4075 | int i; |
| 4076 | |
| 4077 | if (!num_tc) |
| 4078 | num_tc = 1; |
| 4079 | |
| 4080 | hw->fc.low_water = ixgbe_lpbthresh(adapter); |
| 4081 | |
| 4082 | for (i = 0; i < num_tc; i++) { |
| 4083 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
| 4084 | |
| 4085 | /* Low water marks must not be larger than high water marks */ |
| 4086 | if (hw->fc.low_water > hw->fc.high_water[i]) |
| 4087 | hw->fc.low_water = 0; |
| 4088 | } |
| 4089 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4090 | |
| 4091 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 4092 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4093 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4094 | int hdrm; |
| 4095 | u8 tc = netdev_get_num_tc(adapter->netdev); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4096 | |
| 4097 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 4098 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4099 | hdrm = 32 << adapter->fdir_pballoc; |
| 4100 | else |
| 4101 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4102 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 4103 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 4104 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4105 | } |
| 4106 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4107 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 4108 | { |
| 4109 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4110 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4111 | struct ixgbe_fdir_filter *filter; |
| 4112 | |
| 4113 | spin_lock(&adapter->fdir_perfect_lock); |
| 4114 | |
| 4115 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 4116 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 4117 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4118 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4119 | &adapter->fdir_filter_list, fdir_node) { |
| 4120 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 4121 | &filter->filter, |
| 4122 | filter->sw_idx, |
| 4123 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 4124 | IXGBE_FDIR_DROP_QUEUE : |
| 4125 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4129 | } |
| 4130 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4131 | static void ixgbe_macvlan_set_rx_mode(struct net_device *dev, unsigned int pool, |
| 4132 | struct ixgbe_adapter *adapter) |
| 4133 | { |
| 4134 | struct ixgbe_hw *hw = &adapter->hw; |
| 4135 | u32 vmolr; |
| 4136 | |
| 4137 | /* No unicast promiscuous support for VMDQ devices. */ |
| 4138 | vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(pool)); |
| 4139 | vmolr |= (IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE); |
| 4140 | |
| 4141 | /* clear the affected bit */ |
| 4142 | vmolr &= ~IXGBE_VMOLR_MPE; |
| 4143 | |
| 4144 | if (dev->flags & IFF_ALLMULTI) { |
| 4145 | vmolr |= IXGBE_VMOLR_MPE; |
| 4146 | } else { |
| 4147 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4148 | hw->mac.ops.update_mc_addr_list(hw, dev); |
| 4149 | } |
| 4150 | ixgbe_write_uc_addr_list(adapter->netdev); |
| 4151 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(pool), vmolr); |
| 4152 | } |
| 4153 | |
| 4154 | static void ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4155 | u8 *addr, u16 pool) |
| 4156 | { |
| 4157 | struct ixgbe_hw *hw = &adapter->hw; |
| 4158 | unsigned int entry; |
| 4159 | |
| 4160 | entry = hw->mac.num_rar_entries - pool; |
| 4161 | hw->mac.ops.set_rar(hw, entry, addr, VMDQ_P(pool), IXGBE_RAH_AV); |
| 4162 | } |
| 4163 | |
| 4164 | static void ixgbe_fwd_psrtype(struct ixgbe_fwd_adapter *vadapter) |
| 4165 | { |
| 4166 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 4167 | int rss_i = adapter->num_rx_queues_per_pool; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4168 | struct ixgbe_hw *hw = &adapter->hw; |
| 4169 | u16 pool = vadapter->pool; |
| 4170 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 4171 | IXGBE_PSRTYPE_UDPHDR | |
| 4172 | IXGBE_PSRTYPE_IPV4HDR | |
| 4173 | IXGBE_PSRTYPE_L2HDR | |
| 4174 | IXGBE_PSRTYPE_IPV6HDR; |
| 4175 | |
| 4176 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4177 | return; |
| 4178 | |
| 4179 | if (rss_i > 3) |
| 4180 | psrtype |= 2 << 29; |
| 4181 | else if (rss_i > 1) |
| 4182 | psrtype |= 1 << 29; |
| 4183 | |
| 4184 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
| 4185 | } |
| 4186 | |
| 4187 | /** |
| 4188 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 4189 | * @rx_ring: ring to free buffers from |
| 4190 | **/ |
| 4191 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 4192 | { |
| 4193 | struct device *dev = rx_ring->dev; |
| 4194 | unsigned long size; |
| 4195 | u16 i; |
| 4196 | |
| 4197 | /* ring already cleared, nothing to do */ |
| 4198 | if (!rx_ring->rx_buffer_info) |
| 4199 | return; |
| 4200 | |
| 4201 | /* Free all the Rx ring sk_buffs */ |
| 4202 | for (i = 0; i < rx_ring->count; i++) { |
| 4203 | struct ixgbe_rx_buffer *rx_buffer; |
| 4204 | |
| 4205 | rx_buffer = &rx_ring->rx_buffer_info[i]; |
| 4206 | if (rx_buffer->skb) { |
| 4207 | struct sk_buff *skb = rx_buffer->skb; |
| 4208 | if (IXGBE_CB(skb)->page_released) { |
| 4209 | dma_unmap_page(dev, |
| 4210 | IXGBE_CB(skb)->dma, |
| 4211 | ixgbe_rx_bufsz(rx_ring), |
| 4212 | DMA_FROM_DEVICE); |
| 4213 | IXGBE_CB(skb)->page_released = false; |
| 4214 | } |
| 4215 | dev_kfree_skb(skb); |
| 4216 | } |
| 4217 | rx_buffer->skb = NULL; |
| 4218 | if (rx_buffer->dma) |
| 4219 | dma_unmap_page(dev, rx_buffer->dma, |
| 4220 | ixgbe_rx_pg_size(rx_ring), |
| 4221 | DMA_FROM_DEVICE); |
| 4222 | rx_buffer->dma = 0; |
| 4223 | if (rx_buffer->page) |
| 4224 | __free_pages(rx_buffer->page, |
| 4225 | ixgbe_rx_pg_order(rx_ring)); |
| 4226 | rx_buffer->page = NULL; |
| 4227 | } |
| 4228 | |
| 4229 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4230 | memset(rx_ring->rx_buffer_info, 0, size); |
| 4231 | |
| 4232 | /* Zero out the descriptor ring */ |
| 4233 | memset(rx_ring->desc, 0, rx_ring->size); |
| 4234 | |
| 4235 | rx_ring->next_to_alloc = 0; |
| 4236 | rx_ring->next_to_clean = 0; |
| 4237 | rx_ring->next_to_use = 0; |
| 4238 | } |
| 4239 | |
| 4240 | static void ixgbe_disable_fwd_ring(struct ixgbe_fwd_adapter *vadapter, |
| 4241 | struct ixgbe_ring *rx_ring) |
| 4242 | { |
| 4243 | struct ixgbe_adapter *adapter = vadapter->real_adapter; |
| 4244 | int index = rx_ring->queue_index + vadapter->rx_base_queue; |
| 4245 | |
| 4246 | /* shutdown specific queue receive and wait for dma to settle */ |
| 4247 | ixgbe_disable_rx_queue(adapter, rx_ring); |
| 4248 | usleep_range(10000, 20000); |
| 4249 | ixgbe_irq_disable_queues(adapter, ((u64)1 << index)); |
| 4250 | ixgbe_clean_rx_ring(rx_ring); |
| 4251 | rx_ring->l2_accel_priv = NULL; |
| 4252 | } |
| 4253 | |
| 4254 | int ixgbe_fwd_ring_down(struct net_device *vdev, |
| 4255 | struct ixgbe_fwd_adapter *accel) |
| 4256 | { |
| 4257 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4258 | unsigned int rxbase = accel->rx_base_queue; |
| 4259 | unsigned int txbase = accel->tx_base_queue; |
| 4260 | int i; |
| 4261 | |
| 4262 | netif_tx_stop_all_queues(vdev); |
| 4263 | |
| 4264 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4265 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4266 | adapter->rx_ring[rxbase + i]->netdev = adapter->netdev; |
| 4267 | } |
| 4268 | |
| 4269 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4270 | adapter->tx_ring[txbase + i]->l2_accel_priv = NULL; |
| 4271 | adapter->tx_ring[txbase + i]->netdev = adapter->netdev; |
| 4272 | } |
| 4273 | |
| 4274 | |
| 4275 | return 0; |
| 4276 | } |
| 4277 | |
| 4278 | static int ixgbe_fwd_ring_up(struct net_device *vdev, |
| 4279 | struct ixgbe_fwd_adapter *accel) |
| 4280 | { |
| 4281 | struct ixgbe_adapter *adapter = accel->real_adapter; |
| 4282 | unsigned int rxbase, txbase, queues; |
| 4283 | int i, baseq, err = 0; |
| 4284 | |
| 4285 | if (!test_bit(accel->pool, &adapter->fwd_bitmask)) |
| 4286 | return 0; |
| 4287 | |
| 4288 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
| 4289 | netdev_dbg(vdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 4290 | accel->pool, adapter->num_rx_pools, |
| 4291 | baseq, baseq + adapter->num_rx_queues_per_pool, |
| 4292 | adapter->fwd_bitmask); |
| 4293 | |
| 4294 | accel->netdev = vdev; |
| 4295 | accel->rx_base_queue = rxbase = baseq; |
| 4296 | accel->tx_base_queue = txbase = baseq; |
| 4297 | |
| 4298 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 4299 | ixgbe_disable_fwd_ring(accel, adapter->rx_ring[rxbase + i]); |
| 4300 | |
| 4301 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4302 | adapter->rx_ring[rxbase + i]->netdev = vdev; |
| 4303 | adapter->rx_ring[rxbase + i]->l2_accel_priv = accel; |
| 4304 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[rxbase + i]); |
| 4305 | } |
| 4306 | |
| 4307 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 4308 | adapter->tx_ring[txbase + i]->netdev = vdev; |
| 4309 | adapter->tx_ring[txbase + i]->l2_accel_priv = accel; |
| 4310 | } |
| 4311 | |
| 4312 | queues = min_t(unsigned int, |
| 4313 | adapter->num_rx_queues_per_pool, vdev->num_tx_queues); |
| 4314 | err = netif_set_real_num_tx_queues(vdev, queues); |
| 4315 | if (err) |
| 4316 | goto fwd_queue_err; |
| 4317 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4318 | err = netif_set_real_num_rx_queues(vdev, queues); |
| 4319 | if (err) |
| 4320 | goto fwd_queue_err; |
| 4321 | |
| 4322 | if (is_valid_ether_addr(vdev->dev_addr)) |
| 4323 | ixgbe_add_mac_filter(adapter, vdev->dev_addr, accel->pool); |
| 4324 | |
| 4325 | ixgbe_fwd_psrtype(accel); |
| 4326 | ixgbe_macvlan_set_rx_mode(vdev, accel->pool, adapter); |
| 4327 | return err; |
| 4328 | fwd_queue_err: |
| 4329 | ixgbe_fwd_ring_down(vdev, accel); |
| 4330 | return err; |
| 4331 | } |
| 4332 | |
| 4333 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 4334 | { |
| 4335 | struct net_device *upper; |
| 4336 | struct list_head *iter; |
| 4337 | int err; |
| 4338 | |
| 4339 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 4340 | if (netif_is_macvlan(upper)) { |
| 4341 | struct macvlan_dev *dfwd = netdev_priv(upper); |
| 4342 | struct ixgbe_fwd_adapter *vadapter = dfwd->fwd_priv; |
| 4343 | |
| 4344 | if (dfwd->fwd_priv) { |
| 4345 | err = ixgbe_fwd_ring_up(upper, vadapter); |
| 4346 | if (err) |
| 4347 | continue; |
| 4348 | } |
| 4349 | } |
| 4350 | } |
| 4351 | } |
| 4352 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4353 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 4354 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 4355 | struct ixgbe_hw *hw = &adapter->hw; |
| 4356 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 4357 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4358 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 4359 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4360 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 4361 | /* |
| 4362 | * We must restore virtualization before VLANs or else |
| 4363 | * the VLVF registers will not be populated |
| 4364 | */ |
| 4365 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4366 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 4367 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4368 | ixgbe_restore_vlan(adapter); |
| 4369 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 4370 | switch (hw->mac.type) { |
| 4371 | case ixgbe_mac_82599EB: |
| 4372 | case ixgbe_mac_X540: |
| 4373 | hw->mac.ops.disable_rx_buff(hw); |
| 4374 | break; |
| 4375 | default: |
| 4376 | break; |
| 4377 | } |
| 4378 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4379 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 4380 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 4381 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4382 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 4383 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 4384 | adapter->fdir_pballoc); |
| 4385 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4386 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 4387 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 4388 | switch (hw->mac.type) { |
| 4389 | case ixgbe_mac_82599EB: |
| 4390 | case ixgbe_mac_X540: |
| 4391 | hw->mac.ops.enable_rx_buff(hw); |
| 4392 | break; |
| 4393 | default: |
| 4394 | break; |
| 4395 | } |
| 4396 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 4397 | #ifdef IXGBE_FCOE |
| 4398 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 4399 | ixgbe_configure_fcoe(adapter); |
| 4400 | |
| 4401 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4402 | ixgbe_configure_tx(adapter); |
| 4403 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4404 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4407 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 4408 | { |
| 4409 | switch (hw->phy.type) { |
| 4410 | case ixgbe_phy_sfp_avago: |
| 4411 | case ixgbe_phy_sfp_ftl: |
| 4412 | case ixgbe_phy_sfp_intel: |
| 4413 | case ixgbe_phy_sfp_unknown: |
Don Skidmore | ea0a04d | 2010-05-18 16:00:13 +0000 | [diff] [blame] | 4414 | case ixgbe_phy_sfp_passive_tyco: |
| 4415 | case ixgbe_phy_sfp_passive_unknown: |
| 4416 | case ixgbe_phy_sfp_active_unknown: |
| 4417 | case ixgbe_phy_sfp_ftl_active: |
Emil Tantilov | 987e1d5 | 2013-08-14 07:12:27 +0000 | [diff] [blame] | 4418 | case ixgbe_phy_qsfp_passive_unknown: |
| 4419 | case ixgbe_phy_qsfp_active_unknown: |
| 4420 | case ixgbe_phy_qsfp_intel: |
| 4421 | case ixgbe_phy_qsfp_unknown: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4422 | return true; |
Alexander Duyck | 8917b44 | 2011-07-21 00:40:51 +0000 | [diff] [blame] | 4423 | case ixgbe_phy_nl: |
| 4424 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4425 | return true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4426 | default: |
| 4427 | return false; |
| 4428 | } |
| 4429 | } |
| 4430 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4431 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4432 | * ixgbe_sfp_link_config - set up SFP+ link |
| 4433 | * @adapter: pointer to private adapter struct |
| 4434 | **/ |
| 4435 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 4436 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4437 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 4438 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4439 | * is that an SFP was inserted/removed after the reset |
| 4440 | * but before SFP detection was enabled. As such the best |
| 4441 | * solution is to just start searching as soon as we start |
| 4442 | */ |
| 4443 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 4444 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4445 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4446 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | /** |
| 4450 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4451 | * @hw: pointer to private hardware struct |
| 4452 | * |
| 4453 | * Returns 0 on success, negative on failure |
| 4454 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4455 | 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] | 4456 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 4457 | u32 speed; |
| 4458 | bool autoneg, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4459 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 4460 | |
| 4461 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 4462 | 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] | 4463 | |
| 4464 | if (ret) |
| 4465 | goto link_cfg_out; |
| 4466 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 4467 | speed = hw->phy.autoneg_advertised; |
| 4468 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 4469 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 4470 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4471 | if (ret) |
| 4472 | goto link_cfg_out; |
| 4473 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4474 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 4475 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 4476 | link_cfg_out: |
| 4477 | return ret; |
| 4478 | } |
| 4479 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4480 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4481 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4482 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4483 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4484 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4485 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4486 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 4487 | IXGBE_GPIE_OCD; |
| 4488 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4489 | /* |
| 4490 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 4491 | * this saves a register write for every interrupt |
| 4492 | */ |
| 4493 | switch (hw->mac.type) { |
| 4494 | case ixgbe_mac_82598EB: |
| 4495 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 4496 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4497 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4498 | case ixgbe_mac_X540: |
| 4499 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 4500 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 4501 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 4502 | break; |
| 4503 | } |
| 4504 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4505 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 4506 | * specifically only auto mask tx and rx interrupts */ |
| 4507 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4508 | } |
| 4509 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4510 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 4511 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 4512 | |
| 4513 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 4514 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 4515 | |
| 4516 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 4517 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 4518 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 4519 | break; |
| 4520 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 4521 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 4522 | break; |
| 4523 | default: |
| 4524 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 4525 | break; |
| 4526 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 4529 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 4530 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 4531 | switch (adapter->hw.mac.type) { |
| 4532 | case ixgbe_mac_82599EB: |
| 4533 | gpie |= IXGBE_SDP0_GPIEN; |
| 4534 | break; |
| 4535 | case ixgbe_mac_X540: |
| 4536 | gpie |= IXGBE_EIMS_TS; |
| 4537 | break; |
| 4538 | default: |
| 4539 | break; |
| 4540 | } |
| 4541 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 4542 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4543 | /* Enable fan failure interrupt */ |
| 4544 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 4545 | gpie |= IXGBE_SDP1_GPIEN; |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 4546 | |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 4547 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4548 | gpie |= IXGBE_SDP1_GPIEN; |
| 4549 | gpie |= IXGBE_SDP2_GPIEN; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 4550 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4551 | |
| 4552 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 4553 | } |
| 4554 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4555 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4556 | { |
| 4557 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4558 | struct net_device *upper; |
| 4559 | struct list_head *iter; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4560 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 4561 | u32 ctrl_ext; |
| 4562 | |
| 4563 | ixgbe_get_hw_control(adapter); |
| 4564 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4565 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4566 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 4567 | ixgbe_configure_msix(adapter); |
| 4568 | else |
| 4569 | ixgbe_configure_msi_and_legacy(adapter); |
| 4570 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 4571 | /* enable the optics for 82599 SFP+ fiber */ |
| 4572 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 4573 | hw->mac.ops.enable_tx_laser(hw); |
| 4574 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4575 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4576 | ixgbe_napi_enable_all(adapter); |
| 4577 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 4578 | if (ixgbe_is_sfp(hw)) { |
| 4579 | ixgbe_sfp_link_config(adapter); |
| 4580 | } else { |
| 4581 | err = ixgbe_non_sfp_link_config(hw); |
| 4582 | if (err) |
| 4583 | e_err(probe, "link_config FAILED %d\n", err); |
| 4584 | } |
| 4585 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4586 | /* clear any pending interrupts, may auto mask */ |
| 4587 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 4588 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4589 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4590 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4591 | * If this adapter has a fan, check to see if we had a failure |
| 4592 | * before we enabled the interrupt. |
| 4593 | */ |
| 4594 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 4595 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 4596 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 4597 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4598 | } |
| 4599 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 4600 | /* enable transmits */ |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4601 | netif_tx_start_all_queues(adapter->netdev); |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 4602 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4603 | /* enable any upper devices */ |
| 4604 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 4605 | if (netif_is_macvlan(upper)) { |
| 4606 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 4607 | |
| 4608 | if (vlan->fwd_priv) |
| 4609 | netif_tx_start_all_queues(upper); |
| 4610 | } |
| 4611 | } |
| 4612 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4613 | /* bring the link up in the watchdog, this could race with our first |
| 4614 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4615 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4616 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4617 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 4618 | |
| 4619 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 4620 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 4621 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 4622 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4625 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 4626 | { |
| 4627 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4628 | /* put off any impending NetWatchDogTimeout */ |
| 4629 | adapter->netdev->trans_start = jiffies; |
| 4630 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4631 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4632 | usleep_range(1000, 2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4633 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 4634 | /* |
| 4635 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 4636 | * back up to give the VFs time to respond to the reset. The |
| 4637 | * two second wait is based upon the watchdog timer cycle in |
| 4638 | * the VF driver. |
| 4639 | */ |
| 4640 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 4641 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4642 | ixgbe_up(adapter); |
| 4643 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 4644 | } |
| 4645 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4646 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4647 | { |
| 4648 | /* hardware has been reset, we need to reload some things */ |
| 4649 | ixgbe_configure(adapter); |
| 4650 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 4651 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 4655 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4656 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4657 | int err; |
| 4658 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4659 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 4660 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 4661 | usleep_range(1000, 2000); |
| 4662 | |
| 4663 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 4664 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 4665 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 4666 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 4667 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 4668 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4669 | switch (err) { |
| 4670 | case 0: |
| 4671 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4672 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4673 | break; |
| 4674 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4675 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4676 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4677 | case IXGBE_ERR_EEPROM_VERSION: |
| 4678 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4679 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 4680 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4681 | "your hardware. If you are experiencing problems " |
| 4682 | "please contact your Intel or hardware " |
| 4683 | "representative who provided you with this " |
| 4684 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 4685 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4686 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 4687 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 4688 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4689 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4690 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 4691 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4692 | /* reprogram the RAR[0] in case user changed it. */ |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4693 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 4694 | |
| 4695 | /* update SAN MAC vmdq pool selection */ |
| 4696 | if (hw->mac.san_mac_rar_index) |
| 4697 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4698 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 4699 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 4700 | ixgbe_ptp_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4701 | } |
| 4702 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4703 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4704 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4705 | * @tx_ring: ring to be cleaned |
| 4706 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4707 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4708 | { |
| 4709 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4710 | unsigned long size; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4711 | u16 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4712 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4713 | /* ring already cleared, nothing to do */ |
| 4714 | if (!tx_ring->tx_buffer_info) |
| 4715 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4716 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4717 | /* Free all the Tx ring sk_buffs */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4718 | for (i = 0; i < tx_ring->count; i++) { |
| 4719 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4720 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 4723 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
| 4724 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4725 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4726 | memset(tx_ring->tx_buffer_info, 0, size); |
| 4727 | |
| 4728 | /* Zero out the descriptor ring */ |
| 4729 | memset(tx_ring->desc, 0, tx_ring->size); |
| 4730 | |
| 4731 | tx_ring->next_to_use = 0; |
| 4732 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4733 | } |
| 4734 | |
| 4735 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4736 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 4737 | * @adapter: board private structure |
| 4738 | **/ |
| 4739 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 4740 | { |
| 4741 | int i; |
| 4742 | |
| 4743 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4744 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4747 | /** |
| 4748 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 4749 | * @adapter: board private structure |
| 4750 | **/ |
| 4751 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 4752 | { |
| 4753 | int i; |
| 4754 | |
| 4755 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 4756 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4757 | } |
| 4758 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4759 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 4760 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4761 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4762 | struct ixgbe_fdir_filter *filter; |
| 4763 | |
| 4764 | spin_lock(&adapter->fdir_perfect_lock); |
| 4765 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 4766 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 4767 | &adapter->fdir_filter_list, fdir_node) { |
| 4768 | hlist_del(&filter->fdir_node); |
| 4769 | kfree(filter); |
| 4770 | } |
| 4771 | adapter->fdir_filter_count = 0; |
| 4772 | |
| 4773 | spin_unlock(&adapter->fdir_perfect_lock); |
| 4774 | } |
| 4775 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4776 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 4777 | { |
| 4778 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4779 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4780 | struct net_device *upper; |
| 4781 | struct list_head *iter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4782 | u32 rxctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4783 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4784 | |
| 4785 | /* signal that we are down to the interrupt handler */ |
| 4786 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4787 | |
| 4788 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4789 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 4790 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4791 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4792 | /* disable all enabled rx queues */ |
| 4793 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4794 | /* this call also flushes the previous write */ |
| 4795 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 4796 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4797 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4798 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4799 | netif_tx_stop_all_queues(netdev); |
| 4800 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4801 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4802 | netif_carrier_off(netdev); |
| 4803 | netif_tx_disable(netdev); |
| 4804 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4805 | /* disable any upper devices */ |
| 4806 | netdev_for_each_all_upper_dev_rcu(adapter->netdev, upper, iter) { |
| 4807 | if (netif_is_macvlan(upper)) { |
| 4808 | struct macvlan_dev *vlan = netdev_priv(upper); |
| 4809 | |
| 4810 | if (vlan->fwd_priv) { |
| 4811 | netif_tx_stop_all_queues(upper); |
| 4812 | netif_carrier_off(upper); |
| 4813 | netif_tx_disable(upper); |
| 4814 | } |
| 4815 | } |
| 4816 | } |
| 4817 | |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 4818 | ixgbe_irq_disable(adapter); |
| 4819 | |
| 4820 | ixgbe_napi_disable_all(adapter); |
| 4821 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 4822 | adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT | |
| 4823 | IXGBE_FLAG2_RESET_REQUESTED); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 4824 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4825 | |
| 4826 | del_timer_sync(&adapter->service_timer); |
| 4827 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4828 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4829 | /* Clear EITR Select mapping */ |
| 4830 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 4831 | |
| 4832 | /* Mark all the VFs as inactive */ |
| 4833 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 4834 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 4835 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 4836 | /* 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] | 4837 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4838 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4839 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4840 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4843 | /* disable transmits in the hardware now that interrupts are off */ |
| 4844 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4845 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4846 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4847 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 4848 | |
| 4849 | /* Disable the Tx DMA engine on 82599 and X540 */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4850 | switch (hw->mac.type) { |
| 4851 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4852 | case ixgbe_mac_X540: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 4853 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4854 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 4855 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4856 | break; |
| 4857 | default: |
| 4858 | break; |
| 4859 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 4860 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 4861 | if (!pci_channel_offline(adapter->pdev)) |
| 4862 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4863 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 4864 | /* power down the optics for 82599 SFP+ fiber */ |
| 4865 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 4866 | hw->mac.ops.disable_tx_laser(hw); |
| 4867 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4868 | ixgbe_clean_all_tx_rings(adapter); |
| 4869 | ixgbe_clean_all_rx_rings(adapter); |
| 4870 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4871 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4872 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 4873 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 4874 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4877 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4878 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 4879 | * @netdev: network interface device structure |
| 4880 | **/ |
| 4881 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 4882 | { |
| 4883 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4884 | |
| 4885 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 4886 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4887 | } |
| 4888 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4889 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4890 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 4891 | * @adapter: board private structure to initialize |
| 4892 | * |
| 4893 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 4894 | * Fields are initialized based on PCI device information and |
| 4895 | * OS network device settings (MTU size). |
| 4896 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 4897 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4898 | { |
| 4899 | struct ixgbe_hw *hw = &adapter->hw; |
| 4900 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 4901 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 4902 | u32 fwsm; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4903 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4904 | int j; |
| 4905 | struct tc_configuration *tc; |
| 4906 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4907 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4908 | /* PCI config space info */ |
| 4909 | |
| 4910 | hw->vendor_id = pdev->vendor; |
| 4911 | hw->device_id = pdev->device; |
| 4912 | hw->revision_id = pdev->revision; |
| 4913 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 4914 | hw->subsystem_device_id = pdev->subsystem_device; |
| 4915 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 4916 | /* Set common capability flags and settings */ |
Jesse Brandeburg | 3ed69d7 | 2012-02-10 10:20:02 +0000 | [diff] [blame] | 4917 | rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 4918 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 4919 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 4920 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 4921 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 4922 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 4923 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 4924 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 4925 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
| 4926 | #ifdef CONFIG_IXGBE_DCA |
| 4927 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 4928 | #endif |
| 4929 | #ifdef IXGBE_FCOE |
| 4930 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 4931 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 4932 | #ifdef CONFIG_IXGBE_DCB |
| 4933 | /* Default traffic class to use for FCoE */ |
| 4934 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 4935 | #endif /* CONFIG_IXGBE_DCB */ |
| 4936 | #endif /* IXGBE_FCOE */ |
| 4937 | |
| 4938 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4939 | switch (hw->mac.type) { |
| 4940 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 4941 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
| 4942 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 4943 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4944 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 4945 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 4946 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4947 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 4948 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 4949 | adapter->atr_sample_rate = 0; |
| 4950 | adapter->fdir_pballoc = 0; |
| 4951 | #ifdef IXGBE_FCOE |
| 4952 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 4953 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 4954 | #ifdef CONFIG_IXGBE_DCB |
| 4955 | adapter->fcoe.up = 0; |
| 4956 | #endif /* IXGBE_DCB */ |
| 4957 | #endif /* IXGBE_FCOE */ |
| 4958 | break; |
| 4959 | case ixgbe_mac_82599EB: |
| 4960 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 4961 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4962 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4963 | case ixgbe_mac_X540: |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 4964 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM); |
| 4965 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 4966 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 4967 | break; |
| 4968 | default: |
| 4969 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4970 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4971 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 4972 | #ifdef IXGBE_FCOE |
| 4973 | /* FCoE support exists, always init the FCoE lock */ |
| 4974 | spin_lock_init(&adapter->fcoe.lock); |
| 4975 | |
| 4976 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 4977 | /* n-tuple support exists, always init our spinlock */ |
| 4978 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 4979 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4980 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 4981 | switch (hw->mac.type) { |
| 4982 | case ixgbe_mac_X540: |
| 4983 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 4984 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 4985 | break; |
| 4986 | default: |
| 4987 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 4988 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 4989 | break; |
| 4990 | } |
| 4991 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4992 | /* Configure DCB traffic classes */ |
| 4993 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 4994 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 4995 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 4996 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 4997 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 4998 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 4999 | tc->dcb_pfc = pfc_disabled; |
| 5000 | } |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 5001 | |
| 5002 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5003 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5004 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5005 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5006 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5007 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5008 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5009 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5010 | adapter->dcb_set_bitmap = 0x00; |
John Fastabend | 3032309 | 2011-03-01 05:25:35 +0000 | [diff] [blame] | 5011 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
John Fastabend | f525c6d2 | 2012-04-18 22:42:27 +0000 | [diff] [blame] | 5012 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5013 | sizeof(adapter->temp_dcb_cfg)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5014 | |
| 5015 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5016 | |
| 5017 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 5018 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 5019 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5020 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 5021 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 5022 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 5023 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5024 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 5025 | #ifdef CONFIG_PCI_IOV |
| 5026 | /* assign number of SR-IOV VFs */ |
| 5027 | if (hw->mac.type != ixgbe_mac_82598EB) |
| 5028 | adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs; |
| 5029 | |
| 5030 | #endif |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5031 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5032 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 5033 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5034 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 5035 | /* set default ring sizes */ |
| 5036 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 5037 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 5038 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5039 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 5040 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 5041 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5042 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5043 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5044 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5045 | return -EIO; |
| 5046 | } |
| 5047 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5048 | /* PF holds first pool slot */ |
| 5049 | set_bit(0, &adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5050 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 5051 | |
| 5052 | return 0; |
| 5053 | } |
| 5054 | |
| 5055 | /** |
| 5056 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5057 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5058 | * |
| 5059 | * Return 0 on success, negative on failure |
| 5060 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5061 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5062 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5063 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5064 | int orig_node = dev_to_node(dev); |
| 5065 | int numa_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5066 | int size; |
| 5067 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5068 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5069 | |
| 5070 | if (tx_ring->q_vector) |
| 5071 | numa_node = tx_ring->q_vector->numa_node; |
| 5072 | |
| 5073 | tx_ring->tx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5074 | if (!tx_ring->tx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5075 | tx_ring->tx_buffer_info = vzalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5076 | if (!tx_ring->tx_buffer_info) |
| 5077 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5078 | |
| 5079 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 5080 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5081 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5082 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5083 | set_dev_node(dev, numa_node); |
| 5084 | tx_ring->desc = dma_alloc_coherent(dev, |
| 5085 | tx_ring->size, |
| 5086 | &tx_ring->dma, |
| 5087 | GFP_KERNEL); |
| 5088 | set_dev_node(dev, orig_node); |
| 5089 | if (!tx_ring->desc) |
| 5090 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 5091 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5092 | if (!tx_ring->desc) |
| 5093 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5094 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5095 | tx_ring->next_to_use = 0; |
| 5096 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5097 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 5098 | |
| 5099 | err: |
| 5100 | vfree(tx_ring->tx_buffer_info); |
| 5101 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5102 | 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] | 5103 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
| 5106 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5107 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 5108 | * @adapter: board private structure |
| 5109 | * |
| 5110 | * If this function returns with an error, then it's possible one or |
| 5111 | * more of the rings is populated (while the rest are not). It is the |
| 5112 | * callers duty to clean those orphaned rings. |
| 5113 | * |
| 5114 | * Return 0 on success, negative on failure |
| 5115 | **/ |
| 5116 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5117 | { |
| 5118 | int i, err = 0; |
| 5119 | |
| 5120 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5121 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5122 | if (!err) |
| 5123 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5124 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5125 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5126 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5129 | return 0; |
| 5130 | err_setup_tx: |
| 5131 | /* rewind the index freeing the rings as we go */ |
| 5132 | while (i--) |
| 5133 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5134 | return err; |
| 5135 | } |
| 5136 | |
| 5137 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5138 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5139 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5140 | * |
| 5141 | * Returns 0 on success, negative on failure |
| 5142 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5143 | int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5144 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5145 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5146 | int orig_node = dev_to_node(dev); |
| 5147 | int numa_node = -1; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5148 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5149 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5150 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5151 | |
| 5152 | if (rx_ring->q_vector) |
| 5153 | numa_node = rx_ring->q_vector->numa_node; |
| 5154 | |
| 5155 | rx_ring->rx_buffer_info = vzalloc_node(size, numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 5156 | if (!rx_ring->rx_buffer_info) |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 5157 | rx_ring->rx_buffer_info = vzalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5158 | if (!rx_ring->rx_buffer_info) |
| 5159 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5160 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5161 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5162 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 5163 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5164 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 5165 | set_dev_node(dev, numa_node); |
| 5166 | rx_ring->desc = dma_alloc_coherent(dev, |
| 5167 | rx_ring->size, |
| 5168 | &rx_ring->dma, |
| 5169 | GFP_KERNEL); |
| 5170 | set_dev_node(dev, orig_node); |
| 5171 | if (!rx_ring->desc) |
| 5172 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 5173 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5174 | if (!rx_ring->desc) |
| 5175 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5176 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 5177 | rx_ring->next_to_clean = 0; |
| 5178 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5179 | |
| 5180 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5181 | err: |
| 5182 | vfree(rx_ring->rx_buffer_info); |
| 5183 | rx_ring->rx_buffer_info = NULL; |
| 5184 | 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] | 5185 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5189 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 5190 | * @adapter: board private structure |
| 5191 | * |
| 5192 | * If this function returns with an error, then it's possible one or |
| 5193 | * more of the rings is populated (while the rest are not). It is the |
| 5194 | * callers duty to clean those orphaned rings. |
| 5195 | * |
| 5196 | * Return 0 on success, negative on failure |
| 5197 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5198 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5199 | { |
| 5200 | int i, err = 0; |
| 5201 | |
| 5202 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5203 | err = ixgbe_setup_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5204 | if (!err) |
| 5205 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5206 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5207 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5208 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5209 | } |
| 5210 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5211 | #ifdef IXGBE_FCOE |
| 5212 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 5213 | if (!err) |
| 5214 | #endif |
| 5215 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5216 | err_setup_rx: |
| 5217 | /* rewind the index freeing the rings as we go */ |
| 5218 | while (i--) |
| 5219 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5220 | return err; |
| 5221 | } |
| 5222 | |
| 5223 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5224 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5225 | * @tx_ring: Tx descriptor ring for a specific queue |
| 5226 | * |
| 5227 | * Free all transmit software resources |
| 5228 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5229 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5230 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5231 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5232 | |
| 5233 | vfree(tx_ring->tx_buffer_info); |
| 5234 | tx_ring->tx_buffer_info = NULL; |
| 5235 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5236 | /* if not set, then don't free */ |
| 5237 | if (!tx_ring->desc) |
| 5238 | return; |
| 5239 | |
| 5240 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 5241 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5242 | |
| 5243 | tx_ring->desc = NULL; |
| 5244 | } |
| 5245 | |
| 5246 | /** |
| 5247 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 5248 | * @adapter: board private structure |
| 5249 | * |
| 5250 | * Free all transmit software resources |
| 5251 | **/ |
| 5252 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 5253 | { |
| 5254 | int i; |
| 5255 | |
| 5256 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5257 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5258 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5262 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5263 | * @rx_ring: ring to clean the resources from |
| 5264 | * |
| 5265 | * Free all receive software resources |
| 5266 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5267 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5268 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5269 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5270 | |
| 5271 | vfree(rx_ring->rx_buffer_info); |
| 5272 | rx_ring->rx_buffer_info = NULL; |
| 5273 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5274 | /* if not set, then don't free */ |
| 5275 | if (!rx_ring->desc) |
| 5276 | return; |
| 5277 | |
| 5278 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 5279 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5280 | |
| 5281 | rx_ring->desc = NULL; |
| 5282 | } |
| 5283 | |
| 5284 | /** |
| 5285 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 5286 | * @adapter: board private structure |
| 5287 | * |
| 5288 | * Free all receive software resources |
| 5289 | **/ |
| 5290 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 5291 | { |
| 5292 | int i; |
| 5293 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5294 | #ifdef IXGBE_FCOE |
| 5295 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 5296 | |
| 5297 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5298 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5299 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5300 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5304 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 5305 | * @netdev: network interface device structure |
| 5306 | * @new_mtu: new value for maximum frame size |
| 5307 | * |
| 5308 | * Returns 0 on success, negative on failure |
| 5309 | **/ |
| 5310 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 5311 | { |
| 5312 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5313 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5314 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 5315 | /* MTU < 68 is an error and causes problems on some kernels */ |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5316 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
| 5317 | return -EINVAL; |
| 5318 | |
| 5319 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 5320 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 5321 | * paths when MTU greater than 1500 is configured. So display a |
| 5322 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 5323 | */ |
| 5324 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 5325 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Alexander Duyck | c560451 | 2013-01-09 08:50:42 +0000 | [diff] [blame] | 5326 | (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN))) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 5327 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5328 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5329 | 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] | 5330 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5331 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5332 | netdev->mtu = new_mtu; |
| 5333 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5334 | if (netif_running(netdev)) |
| 5335 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5336 | |
| 5337 | return 0; |
| 5338 | } |
| 5339 | |
| 5340 | /** |
| 5341 | * ixgbe_open - Called when a network interface is made active |
| 5342 | * @netdev: network interface device structure |
| 5343 | * |
| 5344 | * Returns 0 on success, negative value on failure |
| 5345 | * |
| 5346 | * The open entry point is called when a network interface is made |
| 5347 | * active by the system (IFF_UP). At this point all resources needed |
| 5348 | * for transmit and receive operations are allocated, the interrupt |
| 5349 | * handler is registered with the OS, the watchdog timer is started, |
| 5350 | * and the stack is notified that the interface is ready. |
| 5351 | **/ |
| 5352 | static int ixgbe_open(struct net_device *netdev) |
| 5353 | { |
| 5354 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5355 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5356 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 5357 | /* disallow open during test */ |
| 5358 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 5359 | return -EBUSY; |
| 5360 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5361 | netif_carrier_off(netdev); |
| 5362 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5363 | /* allocate transmit descriptors */ |
| 5364 | err = ixgbe_setup_all_tx_resources(adapter); |
| 5365 | if (err) |
| 5366 | goto err_setup_tx; |
| 5367 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5368 | /* allocate receive descriptors */ |
| 5369 | err = ixgbe_setup_all_rx_resources(adapter); |
| 5370 | if (err) |
| 5371 | goto err_setup_rx; |
| 5372 | |
| 5373 | ixgbe_configure(adapter); |
| 5374 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5375 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5376 | if (err) |
| 5377 | goto err_req_irq; |
| 5378 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5379 | /* Notify the stack of the actual queue counts. */ |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5380 | if (adapter->num_rx_pools > 1) |
| 5381 | queues = adapter->num_rx_queues_per_pool; |
| 5382 | else |
| 5383 | queues = adapter->num_tx_queues; |
| 5384 | |
| 5385 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5386 | if (err) |
| 5387 | goto err_set_queues; |
| 5388 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5389 | if (adapter->num_rx_pools > 1 && |
| 5390 | adapter->num_rx_queues > IXGBE_MAX_L2A_QUEUES) |
| 5391 | queues = IXGBE_MAX_L2A_QUEUES; |
| 5392 | else |
| 5393 | queues = adapter->num_rx_queues; |
| 5394 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5395 | if (err) |
| 5396 | goto err_set_queues; |
| 5397 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5398 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5399 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5400 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5401 | |
| 5402 | return 0; |
| 5403 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5404 | err_set_queues: |
| 5405 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5406 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5407 | ixgbe_free_all_rx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5408 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 5409 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 5410 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | ixgbe_reset(adapter); |
| 5412 | |
| 5413 | return err; |
| 5414 | } |
| 5415 | |
| 5416 | /** |
| 5417 | * ixgbe_close - Disables a network interface |
| 5418 | * @netdev: network interface device structure |
| 5419 | * |
| 5420 | * Returns 0, this is not allowed to fail |
| 5421 | * |
| 5422 | * The close entry point is called when an interface is de-activated |
| 5423 | * by the OS. The hardware is still under the drivers control, but |
| 5424 | * needs to be disabled. A global MAC reset is issued to stop the |
| 5425 | * hardware, and all transmit and receive resources are freed. |
| 5426 | **/ |
| 5427 | static int ixgbe_close(struct net_device *netdev) |
| 5428 | { |
| 5429 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5430 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5431 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5432 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5433 | ixgbe_down(adapter); |
| 5434 | ixgbe_free_irq(adapter); |
| 5435 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5436 | ixgbe_fdir_filter_exit(adapter); |
| 5437 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5438 | ixgbe_free_all_tx_resources(adapter); |
| 5439 | ixgbe_free_all_rx_resources(adapter); |
| 5440 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5441 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5442 | |
| 5443 | return 0; |
| 5444 | } |
| 5445 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5446 | #ifdef CONFIG_PM |
| 5447 | static int ixgbe_resume(struct pci_dev *pdev) |
| 5448 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5449 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5450 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5451 | u32 err; |
| 5452 | |
| 5453 | pci_set_power_state(pdev, PCI_D0); |
| 5454 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 5455 | /* |
| 5456 | * pci_restore_state clears dev->state_saved so call |
| 5457 | * pci_save_state to restore it. |
| 5458 | */ |
| 5459 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5460 | |
| 5461 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5462 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5463 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5464 | return err; |
| 5465 | } |
| 5466 | pci_set_master(pdev); |
| 5467 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5468 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5469 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5470 | ixgbe_reset(adapter); |
| 5471 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5472 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 5473 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5474 | rtnl_lock(); |
| 5475 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5476 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5477 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 5478 | |
| 5479 | rtnl_unlock(); |
| 5480 | |
| 5481 | if (err) |
| 5482 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5483 | |
| 5484 | netif_device_attach(netdev); |
| 5485 | |
| 5486 | return 0; |
| 5487 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5488 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5489 | |
| 5490 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5491 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 5492 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 5493 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5494 | struct ixgbe_hw *hw = &adapter->hw; |
| 5495 | u32 ctrl, fctrl; |
| 5496 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5497 | #ifdef CONFIG_PM |
| 5498 | int retval = 0; |
| 5499 | #endif |
| 5500 | |
| 5501 | netif_device_detach(netdev); |
| 5502 | |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 5503 | rtnl_lock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5504 | if (netif_running(netdev)) { |
| 5505 | ixgbe_down(adapter); |
| 5506 | ixgbe_free_irq(adapter); |
| 5507 | ixgbe_free_all_tx_resources(adapter); |
| 5508 | ixgbe_free_all_rx_resources(adapter); |
| 5509 | } |
akepner | 499ab5c | 2013-03-13 14:54:58 +0000 | [diff] [blame] | 5510 | rtnl_unlock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5511 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 5512 | ixgbe_clear_interrupt_scheme(adapter); |
| 5513 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5514 | #ifdef CONFIG_PM |
| 5515 | retval = pci_save_state(pdev); |
| 5516 | if (retval) |
| 5517 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5518 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5519 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 5520 | if (hw->mac.ops.stop_link_on_d3) |
| 5521 | hw->mac.ops.stop_link_on_d3(hw); |
| 5522 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5523 | if (wufc) { |
| 5524 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5525 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5526 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 5527 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 5528 | hw->mac.ops.enable_tx_laser(hw); |
| 5529 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5530 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 5531 | if (wufc & IXGBE_WUFC_MC) { |
| 5532 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5533 | fctrl |= IXGBE_FCTRL_MPE; |
| 5534 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 5535 | } |
| 5536 | |
| 5537 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 5538 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 5539 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 5540 | |
| 5541 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 5542 | } else { |
| 5543 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 5544 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 5545 | } |
| 5546 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5547 | switch (hw->mac.type) { |
| 5548 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5549 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5550 | break; |
| 5551 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5552 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5553 | pci_wake_from_d3(pdev, !!wufc); |
| 5554 | break; |
| 5555 | default: |
| 5556 | break; |
| 5557 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5558 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5559 | *enable_wake = !!wufc; |
| 5560 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5561 | ixgbe_release_hw_control(adapter); |
| 5562 | |
| 5563 | pci_disable_device(pdev); |
| 5564 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5565 | return 0; |
| 5566 | } |
| 5567 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5568 | #ifdef CONFIG_PM |
| 5569 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5570 | { |
| 5571 | int retval; |
| 5572 | bool wake; |
| 5573 | |
| 5574 | retval = __ixgbe_shutdown(pdev, &wake); |
| 5575 | if (retval) |
| 5576 | return retval; |
| 5577 | |
| 5578 | if (wake) { |
| 5579 | pci_prepare_to_sleep(pdev); |
| 5580 | } else { |
| 5581 | pci_wake_from_d3(pdev, false); |
| 5582 | pci_set_power_state(pdev, PCI_D3hot); |
| 5583 | } |
| 5584 | |
| 5585 | return 0; |
| 5586 | } |
| 5587 | #endif /* CONFIG_PM */ |
| 5588 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5589 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 5590 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 5591 | bool wake; |
| 5592 | |
| 5593 | __ixgbe_shutdown(pdev, &wake); |
| 5594 | |
| 5595 | if (system_state == SYSTEM_POWER_OFF) { |
| 5596 | pci_wake_from_d3(pdev, wake); |
| 5597 | pci_set_power_state(pdev, PCI_D3hot); |
| 5598 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5602 | * ixgbe_update_stats - Update the board statistics counters. |
| 5603 | * @adapter: board private structure |
| 5604 | **/ |
| 5605 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 5606 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5607 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5608 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5609 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5610 | u64 total_mpc = 0; |
| 5611 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5612 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 5613 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5614 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5615 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 5616 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5617 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5618 | return; |
| 5619 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5620 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5621 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5622 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5623 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5624 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 5625 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 5626 | } |
| 5627 | adapter->rsc_total_count = rsc_count; |
| 5628 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 5629 | } |
| 5630 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5631 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 5632 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 5633 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
| 5634 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 5635 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5636 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5637 | bytes += rx_ring->stats.bytes; |
| 5638 | packets += rx_ring->stats.packets; |
| 5639 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 5640 | adapter->non_eop_descs = non_eop_descs; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5641 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 5642 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 5643 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 5644 | netdev->stats.rx_bytes = bytes; |
| 5645 | netdev->stats.rx_packets = packets; |
| 5646 | |
| 5647 | bytes = 0; |
| 5648 | packets = 0; |
| 5649 | /* gather some stats to the adapter struct that are per queue */ |
| 5650 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 5651 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 5652 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 5653 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 5654 | bytes += tx_ring->stats.bytes; |
| 5655 | packets += tx_ring->stats.packets; |
| 5656 | } |
| 5657 | adapter->restart_queue = restart_queue; |
| 5658 | adapter->tx_busy = tx_busy; |
| 5659 | netdev->stats.tx_bytes = bytes; |
| 5660 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5661 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5662 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5663 | |
| 5664 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5665 | for (i = 0; i < 8; i++) { |
| 5666 | /* for packet buffers not used, the register should read 0 */ |
| 5667 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 5668 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5669 | hwstats->mpc[i] += mpc; |
| 5670 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5671 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 5672 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5673 | switch (hw->mac.type) { |
| 5674 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5675 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 5676 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 5677 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5678 | hwstats->pxonrxc[i] += |
| 5679 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5680 | break; |
| 5681 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5682 | case ixgbe_mac_X540: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5683 | hwstats->pxonrxc[i] += |
| 5684 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5685 | break; |
| 5686 | default: |
| 5687 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5688 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5689 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 5690 | |
| 5691 | /*16 register reads */ |
| 5692 | for (i = 0; i < 16; i++) { |
| 5693 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 5694 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 5695 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
| 5696 | (hw->mac.type == ixgbe_mac_X540)) { |
| 5697 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 5698 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 5699 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 5700 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 5701 | } |
| 5702 | } |
| 5703 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5704 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5705 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5706 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5707 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 5708 | ixgbe_update_xoff_received(adapter); |
| 5709 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5710 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5711 | switch (hw->mac.type) { |
| 5712 | case ixgbe_mac_82598EB: |
| 5713 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5714 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 5715 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 5716 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 5717 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5718 | case ixgbe_mac_X540: |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 5719 | /* OS2BMC stats are X540 only*/ |
| 5720 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 5721 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 5722 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 5723 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
| 5724 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 5725 | for (i = 0; i < 16; i++) |
| 5726 | adapter->hw_rx_no_dma_resources += |
| 5727 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5728 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5729 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5730 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5731 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5732 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5733 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5734 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5735 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 5736 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5737 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5738 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 5739 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 5740 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 5741 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 5742 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 5743 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5744 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 5745 | if (adapter->fcoe.ddp_pool) { |
| 5746 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 5747 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 5748 | unsigned int cpu; |
| 5749 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5750 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 5751 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 5752 | noddp += ddp_pool->noddp; |
| 5753 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5754 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 5755 | hwstats->fcoe_noddp = noddp; |
| 5756 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 5757 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 5758 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5759 | break; |
| 5760 | default: |
| 5761 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5762 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5763 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5764 | hwstats->bprc += bprc; |
| 5765 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5766 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5767 | hwstats->mprc -= bprc; |
| 5768 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 5769 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 5770 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 5771 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 5772 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 5773 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 5774 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 5775 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5776 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5777 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5778 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5779 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5780 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 5781 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 5782 | /* |
| 5783 | * 82598 errata - tx of flow control packets is included in tx counters |
| 5784 | */ |
| 5785 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5786 | hwstats->gptc -= xon_off_tot; |
| 5787 | hwstats->mptc -= xon_off_tot; |
| 5788 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 5789 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 5790 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 5791 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 5792 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 5793 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 5794 | hwstats->ptc64 -= xon_off_tot; |
| 5795 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 5796 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 5797 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 5798 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 5799 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 5800 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5801 | |
| 5802 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5803 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5804 | |
| 5805 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5806 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5807 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 5808 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 5809 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5810 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5814 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5815 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5816 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5817 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5818 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5819 | struct ixgbe_hw *hw = &adapter->hw; |
| 5820 | int i; |
| 5821 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5822 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 5823 | return; |
| 5824 | |
| 5825 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 5826 | |
| 5827 | /* if interface is down do nothing */ |
| 5828 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5829 | return; |
| 5830 | |
| 5831 | /* do nothing if we are not using signature filters */ |
| 5832 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 5833 | return; |
| 5834 | |
| 5835 | adapter->fdir_overflow++; |
| 5836 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5837 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 5838 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 5839 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 5840 | &(adapter->tx_ring[i]->state)); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 5841 | /* re-enable flow director interrupts */ |
| 5842 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5843 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5844 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5845 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5846 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5847 | } |
| 5848 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5849 | /** |
| 5850 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5851 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5852 | * |
| 5853 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5854 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5855 | * 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] | 5856 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5857 | */ |
| 5858 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 5859 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5860 | struct ixgbe_hw *hw = &adapter->hw; |
| 5861 | u64 eics = 0; |
| 5862 | int i; |
| 5863 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5864 | /* If we're down or resetting, just bail */ |
| 5865 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 5866 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 5867 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5868 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5869 | /* Force detection of hung controller */ |
| 5870 | if (netif_carrier_ok(adapter->netdev)) { |
| 5871 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 5872 | set_check_for_tx_hang(adapter->tx_ring[i]); |
| 5873 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5874 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5875 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5876 | /* |
| 5877 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 5878 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5879 | * would set *both* EIMS and EICS for any bit in EIAM |
| 5880 | */ |
| 5881 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 5882 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5883 | } else { |
| 5884 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 5885 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5886 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 5887 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5888 | eics |= ((u64)1 << i); |
| 5889 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5890 | } |
| 5891 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5892 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5893 | ixgbe_irq_rearm_queues(adapter, eics); |
| 5894 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5898 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5899 | * @adapter: pointer to the device adapter structure |
| 5900 | * @link_speed: pointer to a u32 to store the link_speed |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5901 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5902 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5903 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5904 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5905 | u32 link_speed = adapter->link_speed; |
| 5906 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 5907 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5908 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5909 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 5910 | return; |
| 5911 | |
| 5912 | if (hw->mac.ops.check_link) { |
| 5913 | 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] | 5914 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5915 | /* always assume link is up, if no check link function */ |
| 5916 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 5917 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5918 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 5919 | |
| 5920 | if (adapter->ixgbe_ieee_pfc) |
| 5921 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 5922 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 5923 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 5924 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 5925 | ixgbe_set_rx_drop_en(adapter); |
| 5926 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5927 | |
| 5928 | if (link_up || |
| 5929 | time_after(jiffies, (adapter->link_check_timeout + |
| 5930 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 5931 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5932 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 5933 | IXGBE_WRITE_FLUSH(hw); |
| 5934 | } |
| 5935 | |
| 5936 | adapter->link_up = link_up; |
| 5937 | adapter->link_speed = link_speed; |
| 5938 | } |
| 5939 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 5940 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 5941 | { |
| 5942 | #ifdef CONFIG_IXGBE_DCB |
| 5943 | struct net_device *netdev = adapter->netdev; |
| 5944 | struct dcb_app app = { |
| 5945 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 5946 | .protocol = 0, |
| 5947 | }; |
| 5948 | u8 up = 0; |
| 5949 | |
| 5950 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 5951 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 5952 | |
| 5953 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 5954 | #endif |
| 5955 | } |
| 5956 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5957 | /** |
| 5958 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 5959 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5960 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 5961 | **/ |
| 5962 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 5963 | { |
| 5964 | struct net_device *netdev = adapter->netdev; |
| 5965 | struct ixgbe_hw *hw = &adapter->hw; |
| 5966 | u32 link_speed = adapter->link_speed; |
| 5967 | bool flow_rx, flow_tx; |
| 5968 | |
| 5969 | /* only continue if link was previously down */ |
| 5970 | if (netif_carrier_ok(netdev)) |
| 5971 | return; |
| 5972 | |
| 5973 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 5974 | |
| 5975 | switch (hw->mac.type) { |
| 5976 | case ixgbe_mac_82598EB: { |
| 5977 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5978 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 5979 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 5980 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 5981 | } |
| 5982 | break; |
| 5983 | case ixgbe_mac_X540: |
| 5984 | case ixgbe_mac_82599EB: { |
| 5985 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 5986 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 5987 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 5988 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 5989 | } |
| 5990 | break; |
| 5991 | default: |
| 5992 | flow_tx = false; |
| 5993 | flow_rx = false; |
| 5994 | break; |
| 5995 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 5996 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 5997 | adapter->last_rx_ptp_check = jiffies; |
| 5998 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5999 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6000 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6001 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6002 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", |
| 6003 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 6004 | "10 Gbps" : |
| 6005 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 6006 | "1 Gbps" : |
| 6007 | (link_speed == IXGBE_LINK_SPEED_100_FULL ? |
| 6008 | "100 Mbps" : |
| 6009 | "unknown speed"))), |
| 6010 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 6011 | (flow_rx ? "RX" : |
| 6012 | (flow_tx ? "TX" : "None")))); |
| 6013 | |
| 6014 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6015 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6016 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 6017 | /* update the default user priority for VFs */ |
| 6018 | ixgbe_update_default_up(adapter); |
| 6019 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6020 | /* ping all the active vfs to let them know link has changed */ |
| 6021 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6022 | } |
| 6023 | |
| 6024 | /** |
| 6025 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 6026 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6027 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6028 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 6029 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6030 | { |
| 6031 | struct net_device *netdev = adapter->netdev; |
| 6032 | struct ixgbe_hw *hw = &adapter->hw; |
| 6033 | |
| 6034 | adapter->link_up = false; |
| 6035 | adapter->link_speed = 0; |
| 6036 | |
| 6037 | /* only continue if link was up previously */ |
| 6038 | if (!netif_carrier_ok(netdev)) |
| 6039 | return; |
| 6040 | |
| 6041 | /* poll for SFP+ cable when link is down */ |
| 6042 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 6043 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 6044 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6045 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6046 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6047 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6048 | e_info(drv, "NIC Link is Down\n"); |
| 6049 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 6050 | |
| 6051 | /* ping all the active vfs to let them know link has changed */ |
| 6052 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /** |
| 6056 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6057 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6058 | **/ |
| 6059 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 6060 | { |
| 6061 | int i; |
| 6062 | int some_tx_pending = 0; |
| 6063 | |
| 6064 | if (!netif_carrier_ok(adapter->netdev)) { |
| 6065 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6066 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6067 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 6068 | some_tx_pending = 1; |
| 6069 | break; |
| 6070 | } |
| 6071 | } |
| 6072 | |
| 6073 | if (some_tx_pending) { |
| 6074 | /* We've lost link, so the controller stops DMA, |
| 6075 | * but we've got queued Tx work that's never going |
| 6076 | * to get done, so reset controller to flush Tx. |
| 6077 | * (Do the reset outside of interrupt context). |
| 6078 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 6079 | 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] | 6080 | adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6081 | } |
| 6082 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6083 | } |
| 6084 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6085 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 6086 | { |
| 6087 | u32 ssvpc; |
| 6088 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 6089 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 6090 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 6091 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6092 | return; |
| 6093 | |
| 6094 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 6095 | |
| 6096 | /* |
| 6097 | * ssvpc register is cleared on read, if zero then no |
| 6098 | * spoofed packets in the last interval. |
| 6099 | */ |
| 6100 | if (!ssvpc) |
| 6101 | return; |
| 6102 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 6103 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6104 | } |
| 6105 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6106 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6107 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6108 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6109 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6110 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6111 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6112 | /* if interface is down do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 6113 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6114 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6115 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6116 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6117 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 6118 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6119 | if (adapter->link_up) |
| 6120 | ixgbe_watchdog_link_is_up(adapter); |
| 6121 | else |
| 6122 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 6123 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 6124 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6125 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6126 | |
| 6127 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6128 | } |
| 6129 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6130 | /** |
| 6131 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6132 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6133 | **/ |
| 6134 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 6135 | { |
| 6136 | struct ixgbe_hw *hw = &adapter->hw; |
| 6137 | s32 err; |
| 6138 | |
| 6139 | /* not searching for SFP so there is nothing to do here */ |
| 6140 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 6141 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6142 | return; |
| 6143 | |
| 6144 | /* someone else is in init, wait until next service event */ |
| 6145 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6146 | return; |
| 6147 | |
| 6148 | err = hw->phy.ops.identify_sfp(hw); |
| 6149 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6150 | goto sfp_out; |
| 6151 | |
| 6152 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 6153 | /* If no cable is present, then we need to reset |
| 6154 | * the next time we find a good cable. */ |
| 6155 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6156 | } |
| 6157 | |
| 6158 | /* exit on error */ |
| 6159 | if (err) |
| 6160 | goto sfp_out; |
| 6161 | |
| 6162 | /* exit if reset not needed */ |
| 6163 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 6164 | goto sfp_out; |
| 6165 | |
| 6166 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 6167 | |
| 6168 | /* |
| 6169 | * A module may be identified correctly, but the EEPROM may not have |
| 6170 | * support for that module. setup_sfp() will fail in that case, so |
| 6171 | * we should not allow that module to load. |
| 6172 | */ |
| 6173 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 6174 | err = hw->phy.ops.reset(hw); |
| 6175 | else |
| 6176 | err = hw->mac.ops.setup_sfp(hw); |
| 6177 | |
| 6178 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 6179 | goto sfp_out; |
| 6180 | |
| 6181 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6182 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 6183 | |
| 6184 | sfp_out: |
| 6185 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6186 | |
| 6187 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 6188 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 6189 | e_dev_err("failed to initialize because an unsupported " |
| 6190 | "SFP+ module type was detected.\n"); |
| 6191 | e_dev_err("Reload the driver after installing a " |
| 6192 | "supported module.\n"); |
| 6193 | unregister_netdev(adapter->netdev); |
| 6194 | } |
| 6195 | } |
| 6196 | |
| 6197 | /** |
| 6198 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 6199 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6200 | **/ |
| 6201 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 6202 | { |
| 6203 | struct ixgbe_hw *hw = &adapter->hw; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 6204 | u32 speed; |
| 6205 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6206 | |
| 6207 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 6208 | return; |
| 6209 | |
| 6210 | /* someone else is in init, wait until next service event */ |
| 6211 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 6212 | return; |
| 6213 | |
| 6214 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 6215 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 6216 | speed = hw->phy.autoneg_advertised; |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 6217 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 6218 | hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 6219 | |
| 6220 | /* setup the highest link when no autoneg */ |
| 6221 | if (!autoneg) { |
| 6222 | if (speed & IXGBE_LINK_SPEED_10GB_FULL) |
| 6223 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 6224 | } |
| 6225 | } |
| 6226 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6227 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 6228 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6229 | |
| 6230 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 6231 | adapter->link_check_timeout = jiffies; |
| 6232 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 6233 | } |
| 6234 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6235 | #ifdef CONFIG_PCI_IOV |
| 6236 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 6237 | { |
| 6238 | int vf; |
| 6239 | struct ixgbe_hw *hw = &adapter->hw; |
| 6240 | struct net_device *netdev = adapter->netdev; |
| 6241 | u32 gpc; |
| 6242 | u32 ciaa, ciad; |
| 6243 | |
| 6244 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 6245 | if (gpc) /* If incrementing then no need for the check below */ |
| 6246 | return; |
| 6247 | /* |
| 6248 | * Check to see if a bad DMA write target from an errant or |
| 6249 | * malicious VF has caused a PCIe error. If so then we can |
| 6250 | * issue a VFLR to the offending VF(s) and then resume without |
| 6251 | * requesting a full slot reset. |
| 6252 | */ |
| 6253 | |
| 6254 | for (vf = 0; vf < adapter->num_vfs; vf++) { |
| 6255 | ciaa = (vf << 16) | 0x80000000; |
| 6256 | /* 32 bit read so align, we really want status at offset 6 */ |
| 6257 | ciaa |= PCI_COMMAND; |
| 6258 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6259 | ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599); |
| 6260 | ciaa &= 0x7FFFFFFF; |
| 6261 | /* disable debug mode asap after reading data */ |
| 6262 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6263 | /* Get the upper 16 bits which will be the PCI status reg */ |
| 6264 | ciad >>= 16; |
| 6265 | if (ciad & PCI_STATUS_REC_MASTER_ABORT) { |
| 6266 | netdev_err(netdev, "VF %d Hung DMA\n", vf); |
| 6267 | /* Issue VFLR */ |
| 6268 | ciaa = (vf << 16) | 0x80000000; |
| 6269 | ciaa |= 0xA8; |
| 6270 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6271 | ciad = 0x00008000; /* VFLR */ |
| 6272 | IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad); |
| 6273 | ciaa &= 0x7FFFFFFF; |
| 6274 | IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa); |
| 6275 | } |
| 6276 | } |
| 6277 | } |
| 6278 | |
| 6279 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6280 | /** |
| 6281 | * ixgbe_service_timer - Timer Call-back |
| 6282 | * @data: pointer to adapter cast into an unsigned long |
| 6283 | **/ |
| 6284 | static void ixgbe_service_timer(unsigned long data) |
| 6285 | { |
| 6286 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 6287 | unsigned long next_event_offset; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6288 | bool ready = true; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6289 | |
| 6290 | /* poll faster when waiting for link */ |
| 6291 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 6292 | next_event_offset = HZ / 10; |
| 6293 | else |
| 6294 | next_event_offset = HZ * 2; |
| 6295 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6296 | #ifdef CONFIG_PCI_IOV |
Alexander Duyck | 6bb78cf | 2012-02-08 07:51:22 +0000 | [diff] [blame] | 6297 | /* |
| 6298 | * don't bother with SR-IOV VF DMA hang check if there are |
| 6299 | * no VFs or the link is down |
| 6300 | */ |
| 6301 | if (!adapter->num_vfs || |
| 6302 | (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 6303 | goto normal_timer_service; |
| 6304 | |
| 6305 | /* If we have VFs allocated then we must check for DMA hangs */ |
| 6306 | ixgbe_check_for_bad_vf(adapter); |
| 6307 | next_event_offset = HZ / 50; |
| 6308 | adapter->timer_event_accumulator++; |
| 6309 | |
| 6310 | if (adapter->timer_event_accumulator >= 100) |
| 6311 | adapter->timer_event_accumulator = 0; |
| 6312 | else |
| 6313 | ready = false; |
| 6314 | |
| 6315 | normal_timer_service: |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6316 | #endif |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6317 | /* Reset the timer */ |
| 6318 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 6319 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 6320 | if (ready) |
| 6321 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6322 | } |
| 6323 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6324 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 6325 | { |
| 6326 | if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED)) |
| 6327 | return; |
| 6328 | |
| 6329 | adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED; |
| 6330 | |
| 6331 | /* If we're already down or resetting, just bail */ |
| 6332 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6333 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6334 | return; |
| 6335 | |
| 6336 | ixgbe_dump(adapter); |
| 6337 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 6338 | adapter->tx_timeout_count++; |
| 6339 | |
| 6340 | ixgbe_reinit_locked(adapter); |
| 6341 | } |
| 6342 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6343 | /** |
| 6344 | * ixgbe_service_task - manages and runs subtasks |
| 6345 | * @work: pointer to work_struct containing our data |
| 6346 | **/ |
| 6347 | static void ixgbe_service_task(struct work_struct *work) |
| 6348 | { |
| 6349 | struct ixgbe_adapter *adapter = container_of(work, |
| 6350 | struct ixgbe_adapter, |
| 6351 | service_task); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 6352 | ixgbe_reset_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6353 | ixgbe_sfp_detection_subtask(adapter); |
| 6354 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 6355 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6356 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 6357 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 6358 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 6359 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 6360 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 6361 | ixgbe_ptp_overflow_check(adapter); |
| 6362 | ixgbe_ptp_rx_hang(adapter); |
| 6363 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 6364 | |
| 6365 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6366 | } |
| 6367 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6368 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 6369 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6370 | u8 *hdr_len) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6371 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6372 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6373 | u32 vlan_macip_lens, type_tucmd; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6374 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6375 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 6376 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 6377 | return 0; |
| 6378 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6379 | if (!skb_is_gso(skb)) |
| 6380 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6381 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6382 | if (skb_header_cloned(skb)) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6383 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6384 | if (err) |
| 6385 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6386 | } |
| 6387 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6388 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 6389 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6390 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6391 | if (first->protocol == __constant_htons(ETH_P_IP)) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6392 | struct iphdr *iph = ip_hdr(skb); |
| 6393 | iph->tot_len = 0; |
| 6394 | iph->check = 0; |
| 6395 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 6396 | iph->daddr, 0, |
| 6397 | IPPROTO_TCP, |
| 6398 | 0); |
| 6399 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6400 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 6401 | IXGBE_TX_FLAGS_CSUM | |
| 6402 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6403 | } else if (skb_is_gso_v6(skb)) { |
| 6404 | ipv6_hdr(skb)->payload_len = 0; |
| 6405 | tcp_hdr(skb)->check = |
| 6406 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 6407 | &ipv6_hdr(skb)->daddr, |
| 6408 | 0, IPPROTO_TCP, 0); |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6409 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 6410 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6411 | } |
| 6412 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6413 | /* compute header lengths */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6414 | l4len = tcp_hdrlen(skb); |
| 6415 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 6416 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6417 | /* update gso size and bytecount with header size */ |
| 6418 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 6419 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 6420 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 6421 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6422 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6423 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6424 | |
| 6425 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 6426 | vlan_macip_lens = skb_network_header_len(skb); |
| 6427 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6428 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6429 | |
| 6430 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6431 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6432 | |
| 6433 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6434 | } |
| 6435 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6436 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
| 6437 | struct ixgbe_tx_buffer *first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6438 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6439 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6440 | u32 vlan_macip_lens = 0; |
| 6441 | u32 mss_l4len_idx = 0; |
| 6442 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6443 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6444 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6445 | if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) && |
| 6446 | !(first->tx_flags & IXGBE_TX_FLAGS_CC)) |
| 6447 | return; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6448 | } else { |
| 6449 | u8 l4_hdr = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6450 | switch (first->protocol) { |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6451 | case __constant_htons(ETH_P_IP): |
| 6452 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6453 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 6454 | l4_hdr = ip_hdr(skb)->protocol; |
| 6455 | break; |
| 6456 | case __constant_htons(ETH_P_IPV6): |
| 6457 | vlan_macip_lens |= skb_network_header_len(skb); |
| 6458 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 6459 | break; |
| 6460 | default: |
| 6461 | if (unlikely(net_ratelimit())) { |
| 6462 | dev_warn(tx_ring->dev, |
| 6463 | "partial checksum but proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6464 | first->protocol); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6465 | } |
| 6466 | break; |
| 6467 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6468 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6469 | switch (l4_hdr) { |
| 6470 | case IPPROTO_TCP: |
| 6471 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 6472 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 6473 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6474 | break; |
| 6475 | case IPPROTO_SCTP: |
| 6476 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 6477 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 6478 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6479 | break; |
| 6480 | case IPPROTO_UDP: |
| 6481 | mss_l4len_idx = sizeof(struct udphdr) << |
| 6482 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 6483 | break; |
| 6484 | default: |
| 6485 | if (unlikely(net_ratelimit())) { |
| 6486 | dev_warn(tx_ring->dev, |
| 6487 | "partial checksum but l4 proto=%x!\n", |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6488 | l4_hdr); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6489 | } |
| 6490 | break; |
| 6491 | } |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6492 | |
| 6493 | /* update TX checksum flag */ |
| 6494 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6495 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 6496 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6497 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6498 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6499 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6500 | |
| 6501 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, |
| 6502 | type_tucmd, mss_l4len_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6503 | } |
| 6504 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6505 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 6506 | ((_flag <= _result) ? \ |
| 6507 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 6508 | ((u32)(_input & _flag) / (_flag / _result))) |
| 6509 | |
| 6510 | 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] | 6511 | { |
| 6512 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6513 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 6514 | IXGBE_ADVTXD_DCMD_DEXT | |
| 6515 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6516 | |
| 6517 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6518 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 6519 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6520 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6521 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6522 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 6523 | IXGBE_ADVTXD_DCMD_TSE); |
| 6524 | |
| 6525 | /* set timestamp bit if present */ |
| 6526 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 6527 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6528 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 6529 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6530 | 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] | 6531 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6532 | return cmd_type; |
| 6533 | } |
| 6534 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6535 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 6536 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6537 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6538 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6539 | |
| 6540 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6541 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 6542 | IXGBE_TX_FLAGS_CSUM, |
| 6543 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6544 | |
Alexander Duyck | 93f5b3c | 2012-02-08 07:50:45 +0000 | [diff] [blame] | 6545 | /* enble IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6546 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 6547 | IXGBE_TX_FLAGS_IPV4, |
| 6548 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6549 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6550 | /* |
| 6551 | * Check Context must be set if Tx switch is enabled, which it |
| 6552 | * always is for case where virtual functions are running |
| 6553 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6554 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 6555 | IXGBE_TX_FLAGS_CC, |
| 6556 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 6557 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6558 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6559 | } |
| 6560 | |
| 6561 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 6562 | IXGBE_TXD_CMD_RS) |
| 6563 | |
| 6564 | static void ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6565 | struct ixgbe_tx_buffer *first, |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6566 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6567 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6568 | struct sk_buff *skb = first->skb; |
| 6569 | struct ixgbe_tx_buffer *tx_buffer; |
| 6570 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 6571 | struct skb_frag_struct *frag; |
| 6572 | dma_addr_t dma; |
| 6573 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6574 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6575 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6576 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6577 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6578 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 6579 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 6580 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 6581 | |
| 6582 | size = skb_headlen(skb); |
| 6583 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6584 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6585 | #ifdef IXGBE_FCOE |
| 6586 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6587 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6588 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 6589 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6590 | } else { |
| 6591 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6592 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6593 | } |
| 6594 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6595 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6596 | 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] | 6597 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 6598 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6599 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 6600 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 6601 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 6602 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6603 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 6604 | /* record length, and DMA address */ |
| 6605 | dma_unmap_len_set(tx_buffer, len, size); |
| 6606 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 6607 | |
| 6608 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 6609 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6610 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6611 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6612 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6613 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6614 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6615 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6616 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 6617 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6618 | i = 0; |
| 6619 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 6620 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6621 | |
| 6622 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 6623 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 6624 | |
| 6625 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6626 | } |
| 6627 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6628 | if (likely(!data_len)) |
| 6629 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6630 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6631 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6632 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6633 | i++; |
| 6634 | tx_desc++; |
| 6635 | if (i == tx_ring->count) { |
| 6636 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 6637 | i = 0; |
| 6638 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 6639 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6640 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6641 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6642 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6643 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6644 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6645 | #endif |
| 6646 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6647 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6648 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 6649 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6650 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6651 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6652 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6653 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6654 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6655 | cmd_type |= size | IXGBE_TXD_CMD; |
| 6656 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6657 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6658 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 6659 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6660 | /* set the timestamp */ |
| 6661 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6662 | |
| 6663 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6664 | * Force memory writes to complete before letting h/w know there |
| 6665 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 6666 | * memory model archs, such as IA-64). |
| 6667 | * |
| 6668 | * We also need this memory barrier to make certain all of the |
| 6669 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6670 | */ |
| 6671 | wmb(); |
| 6672 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6673 | /* set next_to_watch value indicating a packet is present */ |
| 6674 | first->next_to_watch = tx_desc; |
| 6675 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6676 | i++; |
| 6677 | if (i == tx_ring->count) |
| 6678 | i = 0; |
| 6679 | |
| 6680 | tx_ring->next_to_use = i; |
| 6681 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6682 | /* notify HW of packet */ |
Alexander Duyck | 84ea259 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6683 | writel(i, tx_ring->tail); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6684 | |
| 6685 | return; |
| 6686 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6687 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6688 | |
| 6689 | /* clear dma mappings for failed tx_buffer_info map */ |
| 6690 | for (;;) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 6691 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 6692 | ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer); |
| 6693 | if (tx_buffer == first) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6694 | break; |
| 6695 | if (i == 0) |
| 6696 | i = tx_ring->count; |
| 6697 | i--; |
| 6698 | } |
| 6699 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6700 | tx_ring->next_to_use = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6701 | } |
| 6702 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6703 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6704 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6705 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6706 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 6707 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 6708 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 6709 | union { |
| 6710 | unsigned char *network; |
| 6711 | struct iphdr *ipv4; |
| 6712 | struct ipv6hdr *ipv6; |
| 6713 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6714 | struct tcphdr *th; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 6715 | __be16 vlan_id; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6716 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6717 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 6718 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 6719 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6720 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6721 | /* do nothing if sampling is disabled */ |
| 6722 | if (!ring->atr_sample_rate) |
| 6723 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6724 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6725 | ring->atr_count++; |
| 6726 | |
| 6727 | /* snag network header to get L4 type and address */ |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6728 | hdr.network = skb_network_header(first->skb); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6729 | |
| 6730 | /* Currently only IPv4/IPv6 with TCP is supported */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6731 | if ((first->protocol != __constant_htons(ETH_P_IPV6) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6732 | hdr.ipv6->nexthdr != IPPROTO_TCP) && |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6733 | (first->protocol != __constant_htons(ETH_P_IP) || |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6734 | hdr.ipv4->protocol != IPPROTO_TCP)) |
| 6735 | return; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 6736 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6737 | th = tcp_hdr(first->skb); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6738 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6739 | /* skip this packet since it is invalid or the socket is closing */ |
| 6740 | if (!th || th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6741 | return; |
| 6742 | |
| 6743 | /* sample on all syn packets or once every atr sample count */ |
| 6744 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 6745 | return; |
| 6746 | |
| 6747 | /* reset sample count */ |
| 6748 | ring->atr_count = 0; |
| 6749 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6750 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6751 | |
| 6752 | /* |
| 6753 | * src and dst are inverted, think how the receiver sees them |
| 6754 | * |
| 6755 | * The input is broken into two sections, a non-compressed section |
| 6756 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 6757 | * is XORed together and stored in the compressed dword. |
| 6758 | */ |
| 6759 | input.formatted.vlan_id = vlan_id; |
| 6760 | |
| 6761 | /* |
| 6762 | * since src port and flex bytes occupy the same word XOR them together |
| 6763 | * and write the value to source port portion of compressed dword |
| 6764 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6765 | if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN)) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6766 | common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q); |
| 6767 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6768 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6769 | common.port.dst ^= th->source; |
| 6770 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6771 | if (first->protocol == __constant_htons(ETH_P_IP)) { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 6772 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 6773 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
| 6774 | } else { |
| 6775 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 6776 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 6777 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 6778 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 6779 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 6780 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 6781 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 6782 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 6783 | hdr.ipv6->daddr.s6_addr32[3]; |
| 6784 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6785 | |
| 6786 | /* 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] | 6787 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 6788 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6789 | } |
| 6790 | |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6791 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6792 | { |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6793 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6794 | /* Herbert's original patch had: |
| 6795 | * smp_mb__after_netif_stop_queue(); |
| 6796 | * but since that doesn't exist yet, just open code it. */ |
| 6797 | smp_mb(); |
| 6798 | |
| 6799 | /* We need to check again in a case another CPU has just |
| 6800 | * made room available. */ |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6801 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6802 | return -EBUSY; |
| 6803 | |
| 6804 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6805 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6806 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6807 | return 0; |
| 6808 | } |
| 6809 | |
Alexander Duyck | 82d4e46 | 2011-06-11 01:44:58 +0000 | [diff] [blame] | 6810 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6811 | { |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 6812 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6813 | return 0; |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6814 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 6815 | } |
| 6816 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 6817 | #ifdef IXGBE_FCOE |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6818 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 6819 | { |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 6820 | struct ixgbe_adapter *adapter; |
| 6821 | struct ixgbe_ring_feature *f; |
| 6822 | int txq; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6823 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 6824 | /* |
| 6825 | * only execute the code below if protocol is FCoE |
| 6826 | * or FIP and we have FCoE enabled on the adapter |
| 6827 | */ |
| 6828 | switch (vlan_get_protocol(skb)) { |
| 6829 | case __constant_htons(ETH_P_FCOE): |
| 6830 | case __constant_htons(ETH_P_FIP): |
| 6831 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 6832 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 6833 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 6834 | break; |
| 6835 | default: |
| 6836 | return __netdev_pick_tx(dev, skb); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 6837 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6838 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 6839 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 6840 | |
| 6841 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 6842 | smp_processor_id(); |
| 6843 | |
| 6844 | while (txq >= f->indices) |
| 6845 | txq -= f->indices; |
| 6846 | |
| 6847 | return txq + f->offset; |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 6848 | } |
| 6849 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 6850 | #endif |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 6851 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 6852 | struct ixgbe_adapter *adapter, |
| 6853 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6854 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6855 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 6856 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6857 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6858 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6859 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6860 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 6861 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 6862 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6863 | /* |
| 6864 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 6865 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6866 | * + 2 desc gap to keep tail from touching head, |
| 6867 | * + 1 desc for context descriptor, |
| 6868 | * otherwise try next time |
| 6869 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6870 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 6871 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 6872 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6873 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 6874 | tx_ring->tx_stats.tx_busy++; |
| 6875 | return NETDEV_TX_BUSY; |
| 6876 | } |
| 6877 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6878 | /* record the location of the first descriptor for this packet */ |
| 6879 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 6880 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 6881 | first->bytecount = skb->len; |
| 6882 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6883 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6884 | /* if we have a HW VLAN tag being added default to the HW one */ |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 6885 | if (vlan_tx_tag_present(skb)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6886 | tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 6887 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 6888 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
| 6889 | } else if (protocol == __constant_htons(ETH_P_8021Q)) { |
| 6890 | struct vlan_hdr *vhdr, _vhdr; |
| 6891 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 6892 | if (!vhdr) |
| 6893 | goto out_drop; |
| 6894 | |
| 6895 | protocol = vhdr->h_vlan_encapsulated_proto; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 6896 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 6897 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6898 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6899 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6900 | |
Jacob Keller | aa7bd46 | 2012-05-04 01:55:23 +0000 | [diff] [blame] | 6901 | skb_tx_timestamp(skb); |
| 6902 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6903 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { |
| 6904 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 6905 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 6906 | |
| 6907 | /* schedule check for Tx timestamp */ |
| 6908 | adapter->ptp_tx_skb = skb_get(skb); |
| 6909 | adapter->ptp_tx_start = jiffies; |
| 6910 | schedule_work(&adapter->ptp_tx_work); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6911 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 6912 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 6913 | #ifdef CONFIG_PCI_IOV |
| 6914 | /* |
| 6915 | * Use the l2switch_enable flag - would be false if the DMA |
| 6916 | * Tx switch had been disabled. |
| 6917 | */ |
| 6918 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 6919 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 6920 | |
| 6921 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 6922 | /* 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] | 6923 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 6924 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 6925 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6926 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 6927 | tx_flags |= (skb->priority & 0x7) << |
| 6928 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6929 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 6930 | struct vlan_ethhdr *vhdr; |
| 6931 | if (skb_header_cloned(skb) && |
| 6932 | pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) |
| 6933 | goto out_drop; |
| 6934 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 6935 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 6936 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 6937 | } else { |
| 6938 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 6939 | } |
| 6940 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 6941 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6942 | /* record initial flags and protocol */ |
| 6943 | first->tx_flags = tx_flags; |
| 6944 | first->protocol = protocol; |
| 6945 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6946 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6947 | /* setup tx offload for FCoE */ |
| 6948 | if ((protocol == __constant_htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 6949 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6950 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6951 | if (tso < 0) |
| 6952 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6953 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6954 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 6955 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6956 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6957 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6958 | tso = ixgbe_tso(tx_ring, first, &hdr_len); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6959 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6960 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6961 | else if (!tso) |
| 6962 | ixgbe_tx_csum(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6963 | |
| 6964 | /* add the ATR filter if ATR is on */ |
| 6965 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6966 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 6967 | |
| 6968 | #ifdef IXGBE_FCOE |
| 6969 | xmit_fcoe: |
| 6970 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 6971 | ixgbe_tx_map(tx_ring, first, hdr_len); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 6972 | |
| 6973 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6974 | |
| 6975 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6976 | |
| 6977 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 6978 | dev_kfree_skb_any(first->skb); |
| 6979 | first->skb = NULL; |
| 6980 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 6981 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6982 | } |
| 6983 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6984 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 6985 | struct net_device *netdev, |
| 6986 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6987 | { |
| 6988 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6989 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6990 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 6991 | /* |
| 6992 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 6993 | * in order to meet this minimum size requirement. |
| 6994 | */ |
Stephen Hemminger | f73332f | 2012-06-21 02:15:10 +0000 | [diff] [blame] | 6995 | if (unlikely(skb->len < 17)) { |
| 6996 | if (skb_pad(skb, 17 - skb->len)) |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 6997 | return NETDEV_TX_OK; |
| 6998 | skb->len = 17; |
Tushar Dave | 71a49f7 | 2012-09-14 04:24:49 +0000 | [diff] [blame] | 6999 | skb_set_tail_pointer(skb, 17); |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 7000 | } |
| 7001 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7002 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 7003 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7004 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 7005 | } |
| 7006 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7007 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 7008 | struct net_device *netdev) |
| 7009 | { |
| 7010 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 7011 | } |
| 7012 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7013 | /** |
| 7014 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 7015 | * @netdev: network interface device structure |
| 7016 | * @p: pointer to an address structure |
| 7017 | * |
| 7018 | * Returns 0 on success, negative on failure |
| 7019 | **/ |
| 7020 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 7021 | { |
| 7022 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7023 | struct ixgbe_hw *hw = &adapter->hw; |
| 7024 | struct sockaddr *addr = p; |
| 7025 | |
| 7026 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7027 | return -EADDRNOTAVAIL; |
| 7028 | |
| 7029 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 7030 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7031 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 7032 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7033 | |
| 7034 | return 0; |
| 7035 | } |
| 7036 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7037 | static int |
| 7038 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 7039 | { |
| 7040 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7041 | struct ixgbe_hw *hw = &adapter->hw; |
| 7042 | u16 value; |
| 7043 | int rc; |
| 7044 | |
| 7045 | if (prtad != hw->phy.mdio.prtad) |
| 7046 | return -EINVAL; |
| 7047 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 7048 | if (!rc) |
| 7049 | rc = value; |
| 7050 | return rc; |
| 7051 | } |
| 7052 | |
| 7053 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 7054 | u16 addr, u16 value) |
| 7055 | { |
| 7056 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7057 | struct ixgbe_hw *hw = &adapter->hw; |
| 7058 | |
| 7059 | if (prtad != hw->phy.mdio.prtad) |
| 7060 | return -EINVAL; |
| 7061 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 7062 | } |
| 7063 | |
| 7064 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 7065 | { |
| 7066 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7067 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7068 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7069 | case SIOCSHWTSTAMP: |
| 7070 | return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7071 | default: |
| 7072 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 7073 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7074 | } |
| 7075 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7076 | /** |
| 7077 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7078 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7079 | * @netdev: network interface device structure |
| 7080 | * |
| 7081 | * Returns non-zero on failure |
| 7082 | **/ |
| 7083 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 7084 | { |
| 7085 | int err = 0; |
| 7086 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7087 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7088 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7089 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7090 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7091 | 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] | 7092 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 7093 | |
| 7094 | /* update SAN MAC vmdq pool selection */ |
| 7095 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7096 | } |
| 7097 | return err; |
| 7098 | } |
| 7099 | |
| 7100 | /** |
| 7101 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 7102 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 7103 | * @netdev: network interface device structure |
| 7104 | * |
| 7105 | * Returns non-zero on failure |
| 7106 | **/ |
| 7107 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 7108 | { |
| 7109 | int err = 0; |
| 7110 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7111 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 7112 | |
| 7113 | if (is_valid_ether_addr(mac->san_addr)) { |
| 7114 | rtnl_lock(); |
| 7115 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 7116 | rtnl_unlock(); |
| 7117 | } |
| 7118 | return err; |
| 7119 | } |
| 7120 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7121 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7122 | /* |
| 7123 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 7124 | * without having to re-enable interrupts. It's not called while |
| 7125 | * the interrupt routine is executing. |
| 7126 | */ |
| 7127 | static void ixgbe_netpoll(struct net_device *netdev) |
| 7128 | { |
| 7129 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7130 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7131 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 7132 | /* if interface is down do nothing */ |
| 7133 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 7134 | return; |
| 7135 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7136 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7137 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 7138 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 7139 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 7140 | } else { |
| 7141 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 7142 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7143 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7144 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7145 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7146 | #endif |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7147 | static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev, |
| 7148 | struct rtnl_link_stats64 *stats) |
| 7149 | { |
| 7150 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7151 | int i; |
| 7152 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7153 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7154 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7155 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7156 | u64 bytes, packets; |
| 7157 | unsigned int start; |
| 7158 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7159 | if (ring) { |
| 7160 | do { |
| 7161 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7162 | packets = ring->stats.packets; |
| 7163 | bytes = ring->stats.bytes; |
| 7164 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7165 | stats->rx_packets += packets; |
| 7166 | stats->rx_bytes += bytes; |
| 7167 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7168 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 7169 | |
| 7170 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7171 | struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]); |
| 7172 | u64 bytes, packets; |
| 7173 | unsigned int start; |
| 7174 | |
| 7175 | if (ring) { |
| 7176 | do { |
| 7177 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 7178 | packets = ring->stats.packets; |
| 7179 | bytes = ring->stats.bytes; |
| 7180 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 7181 | stats->tx_packets += packets; |
| 7182 | stats->tx_bytes += bytes; |
| 7183 | } |
| 7184 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 7185 | rcu_read_unlock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7186 | /* following stats updated by ixgbe_watchdog_task() */ |
| 7187 | stats->multicast = netdev->stats.multicast; |
| 7188 | stats->rx_errors = netdev->stats.rx_errors; |
| 7189 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 7190 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 7191 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
| 7192 | return stats; |
| 7193 | } |
| 7194 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 7195 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7196 | /** |
| 7197 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 7198 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7199 | * @tc: number of traffic classes currently enabled |
| 7200 | * |
| 7201 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 7202 | * 802.1Q priority maps to a packet buffer that exists. |
| 7203 | */ |
| 7204 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 7205 | { |
| 7206 | struct ixgbe_hw *hw = &adapter->hw; |
| 7207 | u32 reg, rsave; |
| 7208 | int i; |
| 7209 | |
| 7210 | /* 82598 have a static priority to TC mapping that can not |
| 7211 | * be changed so no validation is needed. |
| 7212 | */ |
| 7213 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7214 | return; |
| 7215 | |
| 7216 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 7217 | rsave = reg; |
| 7218 | |
| 7219 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 7220 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 7221 | |
| 7222 | /* If up2tc is out of bounds default to zero */ |
| 7223 | if (up2tc > tc) |
| 7224 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 7225 | } |
| 7226 | |
| 7227 | if (reg != rsave) |
| 7228 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 7229 | |
| 7230 | return; |
| 7231 | } |
| 7232 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7233 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7234 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 7235 | * @adapter: Pointer to adapter struct |
| 7236 | * |
| 7237 | * Populate the netdev user priority to tc map |
| 7238 | */ |
| 7239 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 7240 | { |
| 7241 | struct net_device *dev = adapter->netdev; |
| 7242 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 7243 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 7244 | u8 prio; |
| 7245 | |
| 7246 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 7247 | u8 tc = 0; |
| 7248 | |
| 7249 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 7250 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 7251 | else if (ets) |
| 7252 | tc = ets->prio_tc[prio]; |
| 7253 | |
| 7254 | netdev_set_prio_tc_map(dev, prio, tc); |
| 7255 | } |
| 7256 | } |
| 7257 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7258 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7259 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7260 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7261 | * |
| 7262 | * @netdev: net device to configure |
| 7263 | * @tc: number of traffic classes to enable |
| 7264 | */ |
| 7265 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 7266 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7267 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7268 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7269 | bool pools; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7270 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7271 | /* Hardware supports up to 8 traffic classes */ |
John Fastabend | 4de2a02 | 2011-09-27 03:52:01 +0000 | [diff] [blame] | 7272 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs || |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7273 | (hw->mac.type == ixgbe_mac_82598EB && |
| 7274 | tc < MAX_TRAFFIC_CLASS)) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7275 | return -EINVAL; |
| 7276 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7277 | pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1); |
| 7278 | if (tc && pools && adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS) |
| 7279 | return -EBUSY; |
| 7280 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7281 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7282 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7283 | * hardware is not flexible enough to do this dynamically. |
| 7284 | */ |
| 7285 | if (netif_running(dev)) |
| 7286 | ixgbe_close(dev); |
| 7287 | ixgbe_clear_interrupt_scheme(adapter); |
| 7288 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7289 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7290 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7291 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7292 | ixgbe_set_prio_tc_map(adapter); |
| 7293 | |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7294 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7295 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 7296 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 7297 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7298 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 7299 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7300 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7301 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 7302 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 7303 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7304 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7305 | |
| 7306 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 7307 | |
| 7308 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 7309 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 7310 | } |
| 7311 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7312 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7313 | |
| 7314 | #endif /* CONFIG_IXGBE_DCB */ |
| 7315 | ixgbe_init_interrupt_scheme(adapter); |
| 7316 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7317 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 7318 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 7319 | |
| 7320 | return 0; |
| 7321 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7322 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 7323 | #ifdef CONFIG_PCI_IOV |
| 7324 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 7325 | { |
| 7326 | struct net_device *netdev = adapter->netdev; |
| 7327 | |
| 7328 | rtnl_lock(); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 7329 | ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev)); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 7330 | rtnl_unlock(); |
| 7331 | } |
| 7332 | |
| 7333 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7334 | void ixgbe_do_reset(struct net_device *netdev) |
| 7335 | { |
| 7336 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7337 | |
| 7338 | if (netif_running(netdev)) |
| 7339 | ixgbe_reinit_locked(adapter); |
| 7340 | else |
| 7341 | ixgbe_reset(adapter); |
| 7342 | } |
| 7343 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7344 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7345 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7346 | { |
| 7347 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 7348 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7349 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7350 | if (!(features & NETIF_F_RXCSUM)) |
| 7351 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7352 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7353 | /* Turn off LRO if not RSC capable */ |
| 7354 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 7355 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7356 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7357 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7358 | } |
| 7359 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 7360 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7361 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7362 | { |
| 7363 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7364 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7365 | bool need_reset = false; |
| 7366 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7367 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7368 | if (!(features & NETIF_F_LRO)) { |
| 7369 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7370 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7371 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 7372 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 7373 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 7374 | if (adapter->rx_itr_setting == 1 || |
| 7375 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 7376 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 7377 | need_reset = true; |
| 7378 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 7379 | e_info(probe, "rx-usecs set too low, " |
| 7380 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7381 | } |
| 7382 | } |
| 7383 | |
| 7384 | /* |
| 7385 | * Check if Flow Director n-tuple support was enabled or disabled. If |
| 7386 | * the state changed, we need to reset. |
| 7387 | */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 7388 | switch (features & NETIF_F_NTUPLE) { |
| 7389 | case NETIF_F_NTUPLE: |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7390 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 7391 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 7392 | need_reset = true; |
| 7393 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7394 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7395 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 7396 | break; |
| 7397 | default: |
| 7398 | /* turn off perfect filters, enable ATR and reset */ |
| 7399 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 7400 | need_reset = true; |
| 7401 | |
| 7402 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 7403 | |
| 7404 | /* We cannot enable ATR if SR-IOV is enabled */ |
| 7405 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 7406 | break; |
| 7407 | |
| 7408 | /* We cannot enable ATR if we have 2 or more traffic classes */ |
| 7409 | if (netdev_get_num_tc(netdev) > 1) |
| 7410 | break; |
| 7411 | |
| 7412 | /* We cannot enable ATR if RSS is disabled */ |
| 7413 | if (adapter->ring_feature[RING_F_RSS].limit <= 1) |
| 7414 | break; |
| 7415 | |
| 7416 | /* A sample rate of 0 indicates ATR disabled */ |
| 7417 | if (!adapter->atr_sample_rate) |
| 7418 | break; |
| 7419 | |
| 7420 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 7421 | break; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7422 | } |
| 7423 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7424 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
John Fastabend | 146d4cc | 2012-05-15 05:59:26 +0000 | [diff] [blame] | 7425 | ixgbe_vlan_strip_enable(adapter); |
| 7426 | else |
| 7427 | ixgbe_vlan_strip_disable(adapter); |
| 7428 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7429 | if (changed & NETIF_F_RXALL) |
| 7430 | need_reset = true; |
| 7431 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 7432 | netdev->features = features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7433 | if (need_reset) |
| 7434 | ixgbe_do_reset(netdev); |
| 7435 | |
| 7436 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7437 | } |
| 7438 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 7439 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7440 | struct net_device *dev, |
stephen hemminger | 6b6e272 | 2012-09-17 10:03:26 +0000 | [diff] [blame] | 7441 | const unsigned char *addr, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7442 | u16 flags) |
| 7443 | { |
| 7444 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 7445 | int err; |
| 7446 | |
| 7447 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
Vlad Yasevich | faaf02d | 2013-03-06 15:39:43 +0000 | [diff] [blame] | 7448 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7449 | |
John Fastabend | b1ac1ef | 2012-11-01 05:00:44 +0000 | [diff] [blame] | 7450 | /* Hardware does not support aging addresses so if a |
| 7451 | * ndm_state is given only allow permanent addresses |
| 7452 | */ |
| 7453 | if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) { |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7454 | pr_info("%s: FDB only supports static addresses\n", |
| 7455 | ixgbe_driver_name); |
| 7456 | return -EINVAL; |
| 7457 | } |
| 7458 | |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 7459 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 7460 | u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS; |
| 7461 | |
| 7462 | if (netdev_uc_count(dev) < rar_uc_entries) |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7463 | err = dev_uc_add_excl(dev, addr); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7464 | else |
John Fastabend | 9544746 | 2012-05-31 12:42:26 +0000 | [diff] [blame] | 7465 | err = -ENOMEM; |
| 7466 | } else if (is_multicast_ether_addr(addr)) { |
| 7467 | err = dev_mc_add_excl(dev, addr); |
| 7468 | } else { |
| 7469 | err = -EINVAL; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7470 | } |
| 7471 | |
| 7472 | /* Only return duplicate errors if NLM_F_EXCL is set */ |
| 7473 | if (err == -EEXIST && !(flags & NLM_F_EXCL)) |
| 7474 | err = 0; |
| 7475 | |
| 7476 | return err; |
| 7477 | } |
| 7478 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7479 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
| 7480 | struct nlmsghdr *nlh) |
| 7481 | { |
| 7482 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7483 | struct nlattr *attr, *br_spec; |
| 7484 | int rem; |
| 7485 | |
| 7486 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 7487 | return -EOPNOTSUPP; |
| 7488 | |
| 7489 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 7490 | |
| 7491 | nla_for_each_nested(attr, br_spec, rem) { |
| 7492 | __u16 mode; |
| 7493 | u32 reg = 0; |
| 7494 | |
| 7495 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 7496 | continue; |
| 7497 | |
| 7498 | mode = nla_get_u16(attr); |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 7499 | if (mode == BRIDGE_MODE_VEPA) { |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7500 | reg = 0; |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 7501 | adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB; |
| 7502 | } else if (mode == BRIDGE_MODE_VEB) { |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7503 | reg = IXGBE_PFDTXGSWC_VT_LBEN; |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 7504 | adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB; |
| 7505 | } else |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7506 | return -EINVAL; |
| 7507 | |
| 7508 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg); |
| 7509 | |
| 7510 | e_info(drv, "enabling bridge mode: %s\n", |
| 7511 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 7512 | } |
| 7513 | |
| 7514 | return 0; |
| 7515 | } |
| 7516 | |
| 7517 | 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] | 7518 | struct net_device *dev, |
| 7519 | u32 filter_mask) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7520 | { |
| 7521 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 7522 | u16 mode; |
| 7523 | |
| 7524 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 7525 | return 0; |
| 7526 | |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 7527 | if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7528 | mode = BRIDGE_MODE_VEB; |
| 7529 | else |
| 7530 | mode = BRIDGE_MODE_VEPA; |
| 7531 | |
| 7532 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode); |
| 7533 | } |
| 7534 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7535 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 7536 | { |
| 7537 | struct ixgbe_fwd_adapter *fwd_adapter = NULL; |
| 7538 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame^] | 7539 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7540 | int pool, err; |
| 7541 | |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 7542 | #ifdef CONFIG_RPS |
| 7543 | if (vdev->num_rx_queues != vdev->num_tx_queues) { |
| 7544 | netdev_info(pdev, "%s: Only supports a single queue count for TX and RX\n", |
| 7545 | vdev->name); |
| 7546 | return ERR_PTR(-EINVAL); |
| 7547 | } |
| 7548 | #endif |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7549 | /* Check for hardware restriction on number of rx/tx queues */ |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 7550 | if (vdev->num_tx_queues > IXGBE_MAX_L2A_QUEUES || |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7551 | vdev->num_tx_queues == IXGBE_BAD_L2A_QUEUE) { |
| 7552 | netdev_info(pdev, |
| 7553 | "%s: Supports RX/TX Queue counts 1,2, and 4\n", |
| 7554 | pdev->name); |
| 7555 | return ERR_PTR(-EINVAL); |
| 7556 | } |
| 7557 | |
| 7558 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 7559 | adapter->num_rx_pools > IXGBE_MAX_DCBMACVLANS - 1) || |
| 7560 | (adapter->num_rx_pools > IXGBE_MAX_MACVLANS)) |
| 7561 | return ERR_PTR(-EBUSY); |
| 7562 | |
| 7563 | fwd_adapter = kcalloc(1, sizeof(struct ixgbe_fwd_adapter), GFP_KERNEL); |
| 7564 | if (!fwd_adapter) |
| 7565 | return ERR_PTR(-ENOMEM); |
| 7566 | |
| 7567 | pool = find_first_zero_bit(&adapter->fwd_bitmask, 32); |
| 7568 | adapter->num_rx_pools++; |
| 7569 | set_bit(pool, &adapter->fwd_bitmask); |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame^] | 7570 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7571 | |
| 7572 | /* Enable VMDq flag so device will be set in VM mode */ |
| 7573 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | IXGBE_FLAG_SRIOV_ENABLED; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame^] | 7574 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 219354d | 2013-11-08 00:50:32 -0800 | [diff] [blame] | 7575 | adapter->ring_feature[RING_F_RSS].limit = vdev->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7576 | |
| 7577 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 7578 | err = ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 7579 | if (err) |
| 7580 | goto fwd_add_err; |
| 7581 | fwd_adapter->pool = pool; |
| 7582 | fwd_adapter->real_adapter = adapter; |
| 7583 | err = ixgbe_fwd_ring_up(vdev, fwd_adapter); |
| 7584 | if (err) |
| 7585 | goto fwd_add_err; |
| 7586 | netif_tx_start_all_queues(vdev); |
| 7587 | return fwd_adapter; |
| 7588 | fwd_add_err: |
| 7589 | /* unwind counter and free adapter struct */ |
| 7590 | netdev_info(pdev, |
| 7591 | "%s: dfwd hardware acceleration failed\n", vdev->name); |
| 7592 | clear_bit(pool, &adapter->fwd_bitmask); |
| 7593 | adapter->num_rx_pools--; |
| 7594 | kfree(fwd_adapter); |
| 7595 | return ERR_PTR(err); |
| 7596 | } |
| 7597 | |
| 7598 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 7599 | { |
| 7600 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 7601 | struct ixgbe_adapter *adapter = fwd_adapter->real_adapter; |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame^] | 7602 | unsigned int limit; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7603 | |
| 7604 | clear_bit(fwd_adapter->pool, &adapter->fwd_bitmask); |
| 7605 | adapter->num_rx_pools--; |
| 7606 | |
John Fastabend | 51f3773 | 2013-11-08 00:51:10 -0800 | [diff] [blame^] | 7607 | limit = find_last_bit(&adapter->fwd_bitmask, 32); |
| 7608 | adapter->ring_feature[RING_F_VMDQ].limit = limit + 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7609 | ixgbe_fwd_ring_down(fwd_adapter->netdev, fwd_adapter); |
| 7610 | ixgbe_setup_tc(pdev, netdev_get_num_tc(pdev)); |
| 7611 | netdev_dbg(pdev, "pool %i:%i queues %i:%i VSI bitmask %lx\n", |
| 7612 | fwd_adapter->pool, adapter->num_rx_pools, |
| 7613 | fwd_adapter->rx_base_queue, |
| 7614 | fwd_adapter->rx_base_queue + adapter->num_rx_queues_per_pool, |
| 7615 | adapter->fwd_bitmask); |
| 7616 | kfree(fwd_adapter); |
| 7617 | } |
| 7618 | |
| 7619 | static netdev_tx_t ixgbe_fwd_xmit(struct sk_buff *skb, |
| 7620 | struct net_device *dev, |
| 7621 | void *priv) |
| 7622 | { |
| 7623 | struct ixgbe_fwd_adapter *fwd_adapter = priv; |
| 7624 | unsigned int queue; |
| 7625 | struct ixgbe_ring *tx_ring; |
| 7626 | |
| 7627 | queue = skb->queue_mapping + fwd_adapter->tx_base_queue; |
| 7628 | tx_ring = fwd_adapter->real_adapter->tx_ring[queue]; |
| 7629 | |
| 7630 | return __ixgbe_xmit_frame(skb, dev, tx_ring); |
| 7631 | } |
| 7632 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7633 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7634 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7635 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 7636 | .ndo_start_xmit = ixgbe_xmit_frame, |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7637 | #ifdef IXGBE_FCOE |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 7638 | .ndo_select_queue = ixgbe_select_queue, |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 7639 | #endif |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7640 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7641 | .ndo_validate_addr = eth_validate_addr, |
| 7642 | .ndo_set_mac_address = ixgbe_set_mac, |
| 7643 | .ndo_change_mtu = ixgbe_change_mtu, |
| 7644 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7645 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 7646 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7647 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7648 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 7649 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
| 7650 | .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7651 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 7652 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 7653 | .ndo_get_stats64 = ixgbe_get_stats64, |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 7654 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | 24095aa | 2011-02-23 05:58:03 +0000 | [diff] [blame] | 7655 | .ndo_setup_tc = ixgbe_setup_tc, |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 7656 | #endif |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7657 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7658 | .ndo_poll_controller = ixgbe_netpoll, |
| 7659 | #endif |
Cong Wang | e0d1095 | 2013-08-01 11:10:25 +0800 | [diff] [blame] | 7660 | #ifdef CONFIG_NET_RX_BUSY_POLL |
Eliezer Tamir | 8b80cda | 2013-07-10 17:13:26 +0300 | [diff] [blame] | 7661 | .ndo_busy_poll = ixgbe_low_latency_recv, |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 7662 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7663 | #ifdef IXGBE_FCOE |
| 7664 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 7665 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7666 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 7667 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 7668 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 7669 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 7670 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 7671 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7672 | .ndo_set_features = ixgbe_set_features, |
| 7673 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 7674 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 7675 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 7676 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7677 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 7678 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
| 7679 | .ndo_dfwd_start_xmit = ixgbe_fwd_xmit, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7680 | }; |
| 7681 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7682 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 7683 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 7684 | * @adapter: adapter structure |
| 7685 | * |
| 7686 | * This function enumerates the phsyical functions co-located on a single slot, |
| 7687 | * in order to determine how many ports a device has. This is most useful in |
| 7688 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 7689 | * performance. |
| 7690 | **/ |
| 7691 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 7692 | { |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 7693 | struct list_head *entry; |
| 7694 | int physfns = 0; |
| 7695 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 7696 | /* Some cards can not use the generic count PCIe functions method, |
| 7697 | * because they are behind a parent switch, so we hardcode these with |
| 7698 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 7699 | */ |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 7700 | if (ixgbe_pcie_from_parent(&adapter->hw)) { |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 7701 | physfns = 4; |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 7702 | } else { |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 7703 | list_for_each(entry, &adapter->pdev->bus_list) { |
| 7704 | struct pci_dev *pdev = |
| 7705 | list_entry(entry, struct pci_dev, bus_list); |
| 7706 | /* don't count virtual functions */ |
| 7707 | if (!pdev->is_virtfn) |
| 7708 | physfns++; |
| 7709 | } |
| 7710 | } |
| 7711 | |
| 7712 | return physfns; |
| 7713 | } |
| 7714 | |
| 7715 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7716 | * ixgbe_wol_supported - Check whether device supports WoL |
| 7717 | * @hw: hw specific details |
| 7718 | * @device_id: the device ID |
| 7719 | * @subdev_id: the subsystem device ID |
| 7720 | * |
| 7721 | * This function is used by probe and ethtool to determine |
| 7722 | * which devices have WoL support |
| 7723 | * |
| 7724 | **/ |
| 7725 | int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 7726 | u16 subdevice_id) |
| 7727 | { |
| 7728 | struct ixgbe_hw *hw = &adapter->hw; |
| 7729 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
| 7730 | int is_wol_supported = 0; |
| 7731 | |
| 7732 | switch (device_id) { |
| 7733 | case IXGBE_DEV_ID_82599_SFP: |
| 7734 | /* Only these subdevices could supports WOL */ |
| 7735 | switch (subdevice_id) { |
| 7736 | case IXGBE_SUBDEV_ID_82599_560FLR: |
| 7737 | /* only support first port */ |
| 7738 | if (hw->bus.func != 0) |
| 7739 | break; |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 7740 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7741 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 7742 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 7743 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Jacob Keller | 979fe5f | 2013-04-03 04:41:37 +0000 | [diff] [blame] | 7744 | case IXGBE_SUBDEV_ID_82599_LOM_SFP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7745 | is_wol_supported = 1; |
| 7746 | break; |
| 7747 | } |
| 7748 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 7749 | case IXGBE_DEV_ID_82599EN_SFP: |
| 7750 | /* Only this subdevice supports WOL */ |
| 7751 | switch (subdevice_id) { |
| 7752 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
| 7753 | is_wol_supported = 1; |
| 7754 | break; |
| 7755 | } |
| 7756 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7757 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 7758 | /* All except this subdevice support WOL */ |
| 7759 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
| 7760 | is_wol_supported = 1; |
| 7761 | break; |
| 7762 | case IXGBE_DEV_ID_82599_KX4: |
| 7763 | is_wol_supported = 1; |
| 7764 | break; |
| 7765 | case IXGBE_DEV_ID_X540T: |
joshua.a.hay@intel.com | df376f0 | 2012-09-21 00:08:21 +0000 | [diff] [blame] | 7766 | case IXGBE_DEV_ID_X540T1: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 7767 | /* check eeprom to see if enabled wol */ |
| 7768 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 7769 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 7770 | (hw->bus.func == 0))) { |
| 7771 | is_wol_supported = 1; |
| 7772 | } |
| 7773 | break; |
| 7774 | } |
| 7775 | |
| 7776 | return is_wol_supported; |
| 7777 | } |
| 7778 | |
| 7779 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7780 | * ixgbe_probe - Device Initialization Routine |
| 7781 | * @pdev: PCI device information struct |
| 7782 | * @ent: entry in ixgbe_pci_tbl |
| 7783 | * |
| 7784 | * Returns 0 on success, negative on failure |
| 7785 | * |
| 7786 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 7787 | * The OS initialization, configuring of the adapter private structure, |
| 7788 | * and a hardware reset occur. |
| 7789 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 7790 | 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] | 7791 | { |
| 7792 | struct net_device *netdev; |
| 7793 | struct ixgbe_adapter *adapter = NULL; |
| 7794 | struct ixgbe_hw *hw; |
| 7795 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7796 | static int cards_found; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 7797 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 7798 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7799 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 7800 | #ifdef IXGBE_FCOE |
| 7801 | u16 device_caps; |
| 7802 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 7803 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7804 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 7805 | /* Catch broken hardware that put the wrong VF device ID in |
| 7806 | * the PCIe SR-IOV capability. |
| 7807 | */ |
| 7808 | if (pdev->is_virtfn) { |
| 7809 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 7810 | pci_name(pdev), pdev->vendor, pdev->device); |
| 7811 | return -EINVAL; |
| 7812 | } |
| 7813 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7814 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7815 | if (err) |
| 7816 | return err; |
| 7817 | |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7818 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 7819 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7820 | pci_using_dac = 1; |
| 7821 | } else { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7822 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7823 | if (err) { |
Nick Nunley | 1b50773 | 2010-04-27 13:10:27 +0000 | [diff] [blame] | 7824 | err = dma_set_coherent_mask(&pdev->dev, |
| 7825 | DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7826 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7827 | dev_err(&pdev->dev, |
| 7828 | "No usable DMA configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7829 | goto err_dma; |
| 7830 | } |
| 7831 | } |
| 7832 | pci_using_dac = 0; |
| 7833 | } |
| 7834 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 7835 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7836 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7837 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 7838 | dev_err(&pdev->dev, |
| 7839 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7840 | goto err_pci_reg; |
| 7841 | } |
| 7842 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 7843 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 7844 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7845 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 7846 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7847 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 7848 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7849 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 7850 | /* 8 TC w/ 4 queues per TC */ |
| 7851 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 7852 | #else |
| 7853 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7854 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 7855 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 7856 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 7857 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7858 | if (!netdev) { |
| 7859 | err = -ENOMEM; |
| 7860 | goto err_alloc_etherdev; |
| 7861 | } |
| 7862 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7863 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 7864 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7865 | adapter = netdev_priv(netdev); |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 7866 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7867 | |
| 7868 | adapter->netdev = netdev; |
| 7869 | adapter->pdev = pdev; |
| 7870 | hw = &adapter->hw; |
| 7871 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 7872 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7873 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 7874 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7875 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7876 | if (!hw->hw_addr) { |
| 7877 | err = -EIO; |
| 7878 | goto err_ioremap; |
| 7879 | } |
| 7880 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 7881 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7882 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7883 | netdev->watchdog_timeo = 5 * HZ; |
Don Skidmore | 9fe93af | 2010-12-03 09:33:54 +0000 | [diff] [blame] | 7884 | strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7885 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7886 | adapter->bd_number = cards_found; |
| 7887 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7888 | /* Setup hw api */ |
| 7889 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 7890 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7891 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7892 | /* EEPROM */ |
| 7893 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 7894 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 7895 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 7896 | if (!(eec & (1 << 8))) |
| 7897 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 7898 | |
| 7899 | /* PHY */ |
| 7900 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7901 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 7902 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 7903 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 7904 | hw->phy.mdio.mmds = 0; |
| 7905 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 7906 | hw->phy.mdio.dev = netdev; |
| 7907 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 7908 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 7909 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7910 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7911 | |
| 7912 | /* setup the private structure */ |
| 7913 | err = ixgbe_sw_init(adapter); |
| 7914 | if (err) |
| 7915 | goto err_sw_init; |
| 7916 | |
Don Skidmore | 0b2679d | 2013-02-21 03:00:04 +0000 | [diff] [blame] | 7917 | /* Cache if MNG FW is up so we don't have to read the REG later */ |
| 7918 | if (hw->mac.ops.mng_fw_enabled) |
| 7919 | hw->mng_fw_enabled = hw->mac.ops.mng_fw_enabled(hw); |
| 7920 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7921 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7922 | switch (adapter->hw.mac.type) { |
| 7923 | case ixgbe_mac_82599EB: |
| 7924 | case ixgbe_mac_X540: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7925 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 7926 | break; |
| 7927 | default: |
| 7928 | break; |
| 7929 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 7930 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7931 | /* |
| 7932 | * If there is a fan on this device and it has failed log the |
| 7933 | * failure. |
| 7934 | */ |
| 7935 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 7936 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 7937 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7938 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 7939 | } |
| 7940 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 7941 | if (allow_unsupported_sfp) |
| 7942 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 7943 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7944 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7945 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7946 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 7947 | hw->phy.reset_if_overtemp = false; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7948 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 7949 | hw->mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 7950 | err = 0; |
| 7951 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 7952 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 7953 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 7954 | goto err_sw_init; |
| 7955 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7956 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 7957 | goto err_sw_init; |
| 7958 | } |
| 7959 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 7960 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 7961 | /* SR-IOV not supported on the 82598 */ |
| 7962 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 7963 | goto skip_sriov; |
| 7964 | /* Mailbox */ |
| 7965 | ixgbe_init_mbx_params_pf(hw); |
| 7966 | memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops)); |
| 7967 | ixgbe_enable_sriov(adapter); |
Donald Dutile | 43dc4e0 | 2012-12-11 08:26:48 +0000 | [diff] [blame] | 7968 | pci_sriov_set_totalvfs(pdev, 63); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 7969 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 7970 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 7971 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7972 | netdev->features = NETIF_F_SG | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 7973 | NETIF_F_IP_CSUM | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7974 | NETIF_F_IPV6_CSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7975 | NETIF_F_HW_VLAN_CTAG_TX | |
| 7976 | NETIF_F_HW_VLAN_CTAG_RX | |
| 7977 | NETIF_F_HW_VLAN_CTAG_FILTER | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7978 | NETIF_F_TSO | |
| 7979 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7980 | NETIF_F_RXHASH | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 7981 | NETIF_F_RXCSUM | |
| 7982 | NETIF_F_HW_L2FW_DOFFLOAD; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7983 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7984 | netdev->hw_features = netdev->features; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7985 | |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7986 | switch (adapter->hw.mac.type) { |
| 7987 | case ixgbe_mac_82599EB: |
| 7988 | case ixgbe_mac_X540: |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7989 | netdev->features |= NETIF_F_SCTP_CSUM; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 7990 | netdev->hw_features |= NETIF_F_SCTP_CSUM | |
| 7991 | NETIF_F_NTUPLE; |
Don Skidmore | 58be766 | 2011-04-12 09:42:11 +0000 | [diff] [blame] | 7992 | break; |
| 7993 | default: |
| 7994 | break; |
| 7995 | } |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 7996 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 7997 | netdev->hw_features |= NETIF_F_RXALL; |
| 7998 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 7999 | netdev->vlan_features |= NETIF_F_TSO; |
| 8000 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 8001 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 8002 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 8003 | netdev->vlan_features |= NETIF_F_SG; |
| 8004 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 8005 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 8006 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 8007 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 8008 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 8009 | netdev->dcbnl_ops = &dcbnl_ops; |
| 8010 | #endif |
| 8011 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8012 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 8013 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8014 | unsigned int fcoe_l; |
| 8015 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8016 | if (hw->mac.ops.get_device_caps) { |
| 8017 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 8018 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 8019 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8020 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 8021 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 8022 | |
| 8023 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 8024 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 8025 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 8026 | netdev->features |= NETIF_F_FSO | |
| 8027 | NETIF_F_FCOE_CRC; |
| 8028 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 8029 | netdev->vlan_features |= NETIF_F_FSO | |
| 8030 | NETIF_F_FCOE_CRC | |
| 8031 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 8032 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8033 | #endif /* IXGBE_FCOE */ |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 8034 | if (pci_using_dac) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8035 | netdev->features |= NETIF_F_HIGHDMA; |
Yi Zou | 7b872a5 | 2010-09-22 17:57:58 +0000 | [diff] [blame] | 8036 | netdev->vlan_features |= NETIF_F_HIGHDMA; |
| 8037 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8038 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 8039 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 8040 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 8041 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 8042 | netdev->features |= NETIF_F_LRO; |
| 8043 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8044 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 8045 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8046 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8047 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 8048 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8049 | } |
| 8050 | |
| 8051 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8052 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 8053 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8054 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8055 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 8056 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8057 | } |
| 8058 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8059 | setup_timer(&adapter->service_timer, &ixgbe_service_timer, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8060 | (unsigned long) adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8061 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8062 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
| 8063 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8064 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8065 | err = ixgbe_init_interrupt_scheme(adapter); |
| 8066 | if (err) |
| 8067 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8068 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8069 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 8070 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 8071 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 8072 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 8073 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 8074 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 8075 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 8076 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 8077 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 8078 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 8079 | /* save off EEPROM version number */ |
| 8080 | hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh); |
| 8081 | hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl); |
| 8082 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 8083 | /* pick up the PCI bus settings for reporting later */ |
| 8084 | hw->mac.ops.get_bus_info(hw); |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8085 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 8086 | ixgbe_get_parent_bus_info(adapter); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 8087 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8088 | /* calculate the expected PCIe bandwidth required for optimal |
| 8089 | * performance. Note that some older parts will never have enough |
| 8090 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 8091 | * parts to ensure no warning is displayed if it can't be fixed. |
| 8092 | */ |
| 8093 | switch (hw->mac.type) { |
| 8094 | case ixgbe_mac_82598EB: |
| 8095 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 8096 | break; |
| 8097 | default: |
| 8098 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 8099 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 8100 | } |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 8101 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 8102 | |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 8103 | err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH); |
| 8104 | if (err) |
| 8105 | strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH); |
| 8106 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 8107 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 8108 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 8109 | part_str); |
| 8110 | else |
| 8111 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 8112 | hw->mac.type, hw->phy.type, part_str); |
| 8113 | |
| 8114 | e_dev_info("%pM\n", netdev->dev_addr); |
| 8115 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8116 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 8117 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 8118 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 8119 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8120 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 8121 | "Please be aware there may be issues associated " |
| 8122 | "with your hardware. If you are experiencing " |
| 8123 | "problems please contact your Intel or hardware " |
| 8124 | "representative who provided you with this " |
| 8125 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 8126 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8127 | strcpy(netdev->name, "eth%d"); |
| 8128 | err = register_netdev(netdev); |
| 8129 | if (err) |
| 8130 | goto err_register; |
| 8131 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 8132 | /* power down the optics for 82599 SFP+ fiber */ |
| 8133 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 8134 | hw->mac.ops.disable_tx_laser(hw); |
| 8135 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 8136 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 8137 | netif_carrier_off(netdev); |
| 8138 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8139 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 8140 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8141 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8142 | ixgbe_setup_dca(adapter); |
| 8143 | } |
| 8144 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 8145 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8146 | 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] | 8147 | for (i = 0; i < adapter->num_vfs; i++) |
| 8148 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 8149 | } |
| 8150 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8151 | /* firmware requires driver version to be 0xFFFFFFFF |
| 8152 | * since os does not support feature |
| 8153 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8154 | if (hw->mac.ops.set_fw_drv_ver) |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 8155 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, |
| 8156 | 0xFF); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 8157 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8158 | /* add san mac addr to netdev */ |
| 8159 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8160 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 8161 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8162 | cards_found++; |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8163 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8164 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8165 | if (ixgbe_sysfs_init(adapter)) |
| 8166 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8167 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8168 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8169 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8170 | |
Don Skidmore | 0b2679d | 2013-02-21 03:00:04 +0000 | [diff] [blame] | 8171 | /* Need link setup for MNG FW, else wait for IXGBE_UP */ |
| 8172 | if (hw->mng_fw_enabled && hw->mac.ops.setup_link) |
| 8173 | hw->mac.ops.setup_link(hw, |
| 8174 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 8175 | true); |
| 8176 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8177 | return 0; |
| 8178 | |
| 8179 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8180 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8181 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8182 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 8183 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8184 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8185 | iounmap(hw->hw_addr); |
| 8186 | err_ioremap: |
| 8187 | free_netdev(netdev); |
| 8188 | err_alloc_etherdev: |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8189 | pci_release_selected_regions(pdev, |
| 8190 | pci_select_bars(pdev, IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8191 | err_pci_reg: |
| 8192 | err_dma: |
| 8193 | pci_disable_device(pdev); |
| 8194 | return err; |
| 8195 | } |
| 8196 | |
| 8197 | /** |
| 8198 | * ixgbe_remove - Device Removal Routine |
| 8199 | * @pdev: PCI device information struct |
| 8200 | * |
| 8201 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 8202 | * that it should release a PCI device. The could be caused by a |
| 8203 | * Hot-Plug event, or because the driver is going to be removed from |
| 8204 | * memory. |
| 8205 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 8206 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8207 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8208 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8209 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8210 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8211 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8212 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8213 | set_bit(__IXGBE_DOWN, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 8214 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8215 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8216 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8217 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8218 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 8219 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 8220 | dca_remove_requester(&pdev->dev); |
| 8221 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 8222 | } |
| 8223 | |
| 8224 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8225 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8226 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 8227 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 8228 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8229 | /* remove the added san mac */ |
| 8230 | ixgbe_del_sanmac_netdev(netdev); |
| 8231 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 8232 | if (netdev->reg_state == NETREG_REGISTERED) |
| 8233 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8234 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8235 | #ifdef CONFIG_PCI_IOV |
| 8236 | /* |
| 8237 | * Only disable SR-IOV on unload if the user specified the now |
| 8238 | * deprecated max_vfs module parameter. |
| 8239 | */ |
| 8240 | if (max_vfs) |
| 8241 | ixgbe_disable_sriov(adapter); |
| 8242 | #endif |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 8243 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 8244 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8245 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8246 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 8247 | #ifdef CONFIG_DCB |
| 8248 | kfree(adapter->ixgbe_ieee_pfc); |
| 8249 | kfree(adapter->ixgbe_ieee_ets); |
| 8250 | |
| 8251 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8252 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8253 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8254 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8255 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8256 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 8257 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8258 | free_netdev(netdev); |
| 8259 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 8260 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8261 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8262 | pci_disable_device(pdev); |
| 8263 | } |
| 8264 | |
| 8265 | /** |
| 8266 | * ixgbe_io_error_detected - called when PCI error is detected |
| 8267 | * @pdev: Pointer to PCI device |
| 8268 | * @state: The current pci connection state |
| 8269 | * |
| 8270 | * This function is called after a PCI bus error affecting |
| 8271 | * this device has been detected. |
| 8272 | */ |
| 8273 | 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] | 8274 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8275 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8276 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8277 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8278 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8279 | #ifdef CONFIG_PCI_IOV |
| 8280 | struct pci_dev *bdev, *vfdev; |
| 8281 | u32 dw0, dw1, dw2, dw3; |
| 8282 | int vf, pos; |
| 8283 | u16 req_id, pf_func; |
| 8284 | |
| 8285 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 8286 | adapter->num_vfs == 0) |
| 8287 | goto skip_bad_vf_detection; |
| 8288 | |
| 8289 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 8290 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8291 | bdev = bdev->bus->self; |
| 8292 | |
| 8293 | if (!bdev) |
| 8294 | goto skip_bad_vf_detection; |
| 8295 | |
| 8296 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 8297 | if (!pos) |
| 8298 | goto skip_bad_vf_detection; |
| 8299 | |
| 8300 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0); |
| 8301 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1); |
| 8302 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2); |
| 8303 | pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3); |
| 8304 | |
| 8305 | req_id = dw1 >> 16; |
| 8306 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 8307 | if (!(req_id & 0x0080)) |
| 8308 | goto skip_bad_vf_detection; |
| 8309 | |
| 8310 | pf_func = req_id & 0x01; |
| 8311 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 8312 | unsigned int device_id; |
| 8313 | |
| 8314 | vf = (req_id & 0x7F) >> 1; |
| 8315 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 8316 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 8317 | "%8.8x\tdw3: %8.8x\n", |
| 8318 | dw0, dw1, dw2, dw3); |
| 8319 | switch (adapter->hw.mac.type) { |
| 8320 | case ixgbe_mac_82599EB: |
| 8321 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 8322 | break; |
| 8323 | case ixgbe_mac_X540: |
| 8324 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 8325 | break; |
| 8326 | default: |
| 8327 | device_id = 0; |
| 8328 | break; |
| 8329 | } |
| 8330 | |
| 8331 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 8332 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8333 | while (vfdev) { |
| 8334 | if (vfdev->devfn == (req_id & 0xFF)) |
| 8335 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 8336 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8337 | device_id, vfdev); |
| 8338 | } |
| 8339 | /* |
| 8340 | * There's a slim chance the VF could have been hot plugged, |
| 8341 | * so if it is no longer present we don't need to issue the |
| 8342 | * VFLR. Just clean up the AER in that case. |
| 8343 | */ |
| 8344 | if (vfdev) { |
| 8345 | e_dev_err("Issuing VFLR to VF %d\n", vf); |
| 8346 | pci_write_config_dword(vfdev, 0xA8, 0x00008000); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 8347 | /* Free device reference count */ |
| 8348 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8349 | } |
| 8350 | |
| 8351 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8352 | } |
| 8353 | |
| 8354 | /* |
| 8355 | * Even though the error may have occurred on the other port |
| 8356 | * we still need to increment the vf error reference count for |
| 8357 | * both ports because the I/O resume function will be called |
| 8358 | * for both of them. |
| 8359 | */ |
| 8360 | adapter->vferr_refcount++; |
| 8361 | |
| 8362 | return PCI_ERS_RESULT_RECOVERED; |
| 8363 | |
| 8364 | skip_bad_vf_detection: |
| 8365 | #endif /* CONFIG_PCI_IOV */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8366 | netif_device_detach(netdev); |
| 8367 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 8368 | if (state == pci_channel_io_perm_failure) |
| 8369 | return PCI_ERS_RESULT_DISCONNECT; |
| 8370 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8371 | if (netif_running(netdev)) |
| 8372 | ixgbe_down(adapter); |
| 8373 | pci_disable_device(pdev); |
| 8374 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8375 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8376 | return PCI_ERS_RESULT_NEED_RESET; |
| 8377 | } |
| 8378 | |
| 8379 | /** |
| 8380 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 8381 | * @pdev: Pointer to PCI device |
| 8382 | * |
| 8383 | * Restart the card from scratch, as if from a cold-boot. |
| 8384 | */ |
| 8385 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 8386 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8387 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8388 | pci_ers_result_t result; |
| 8389 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8390 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 8391 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 8392 | 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] | 8393 | result = PCI_ERS_RESULT_DISCONNECT; |
| 8394 | } else { |
| 8395 | pci_set_master(pdev); |
| 8396 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 8397 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8398 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 8399 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8400 | |
| 8401 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 8402 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8403 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8404 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8405 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8406 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 8407 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8408 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 8409 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8410 | /* non-fatal, continue */ |
| 8411 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8412 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 8413 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8414 | } |
| 8415 | |
| 8416 | /** |
| 8417 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 8418 | * @pdev: Pointer to PCI device |
| 8419 | * |
| 8420 | * This callback is called when the error recovery driver tells us that |
| 8421 | * its OK to resume normal operation. |
| 8422 | */ |
| 8423 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 8424 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 8425 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 8426 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8427 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 8428 | #ifdef CONFIG_PCI_IOV |
| 8429 | if (adapter->vferr_refcount) { |
| 8430 | e_info(drv, "Resuming after VF err\n"); |
| 8431 | adapter->vferr_refcount--; |
| 8432 | return; |
| 8433 | } |
| 8434 | |
| 8435 | #endif |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 8436 | if (netif_running(netdev)) |
| 8437 | ixgbe_up(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8438 | |
| 8439 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8440 | } |
| 8441 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 8442 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8443 | .error_detected = ixgbe_io_error_detected, |
| 8444 | .slot_reset = ixgbe_io_slot_reset, |
| 8445 | .resume = ixgbe_io_resume, |
| 8446 | }; |
| 8447 | |
| 8448 | static struct pci_driver ixgbe_driver = { |
| 8449 | .name = ixgbe_driver_name, |
| 8450 | .id_table = ixgbe_pci_tbl, |
| 8451 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 8452 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8453 | #ifdef CONFIG_PM |
| 8454 | .suspend = ixgbe_suspend, |
| 8455 | .resume = ixgbe_resume, |
| 8456 | #endif |
| 8457 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 8458 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8459 | .err_handler = &ixgbe_err_handler |
| 8460 | }; |
| 8461 | |
| 8462 | /** |
| 8463 | * ixgbe_init_module - Driver Registration Routine |
| 8464 | * |
| 8465 | * ixgbe_init_module is the first routine called when the driver is |
| 8466 | * loaded. All it does is register with the PCI subsystem. |
| 8467 | **/ |
| 8468 | static int __init ixgbe_init_module(void) |
| 8469 | { |
| 8470 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 8471 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8472 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8473 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8474 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8475 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 8476 | ret = pci_register_driver(&ixgbe_driver); |
| 8477 | if (ret) { |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 8478 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 8479 | return ret; |
| 8480 | } |
| 8481 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8482 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8483 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8484 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8485 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 8486 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8487 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8488 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8489 | module_init(ixgbe_init_module); |
| 8490 | |
| 8491 | /** |
| 8492 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 8493 | * |
| 8494 | * ixgbe_exit_module is called just before the driver is removed |
| 8495 | * from memory. |
| 8496 | **/ |
| 8497 | static void __exit ixgbe_exit_module(void) |
| 8498 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8499 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8500 | dca_unregister_notify(&dca_notifier); |
| 8501 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8502 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8503 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8504 | ixgbe_dbg_exit(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 8505 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8506 | rcu_barrier(); /* Wait for completion of call_rcu()'s */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8507 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8508 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 8509 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8510 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8511 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8512 | { |
| 8513 | int ret_val; |
| 8514 | |
| 8515 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 8516 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8517 | |
| 8518 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 8519 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 8520 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 8521 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 8522 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8523 | module_exit(ixgbe_exit_module); |
| 8524 | |
| 8525 | /* ixgbe_main.c */ |