Jeff Kirsher | 51dce24 | 2018-04-26 08:08:09 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* Copyright(c) 1999 - 2018 Intel Corporation. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3 | |
| 4 | #include <linux/types.h> |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/pci.h> |
| 7 | #include <linux/netdevice.h> |
| 8 | #include <linux/vmalloc.h> |
| 9 | #include <linux/string.h> |
| 10 | #include <linux/in.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 11 | #include <linux/interrupt.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 12 | #include <linux/ip.h> |
| 13 | #include <linux/tcp.h> |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 14 | #include <linux/sctp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 15 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 16 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 18 | #include <net/checksum.h> |
| 19 | #include <net/ip6_checksum.h> |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 20 | #include <linux/etherdevice.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 21 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 22 | #include <linux/if.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | #include <linux/if_vlan.h> |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 24 | #include <linux/if_macvlan.h> |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 25 | #include <linux/if_bridge.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 26 | #include <linux/prefetch.h> |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 27 | #include <linux/bpf.h> |
| 28 | #include <linux/bpf_trace.h> |
| 29 | #include <linux/atomic.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 30 | #include <scsi/fc/fc_fcoe.h> |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 31 | #include <net/udp_tunnel.h> |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 32 | #include <net/pkt_cls.h> |
| 33 | #include <net/tc_act/tc_gact.h> |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 34 | #include <net/tc_act/tc_mirred.h> |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 35 | #include <net/vxlan.h> |
Scott Peterson | 2a20525 | 2016-11-18 11:25:42 -0800 | [diff] [blame] | 36 | #include <net/mpls.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 37 | |
| 38 | #include "ixgbe.h" |
| 39 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 40 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 41 | #include "ixgbe_sriov.h" |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 42 | #include "ixgbe_model.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 43 | |
| 44 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 45 | static const char ixgbe_driver_string[] = |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 46 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 47 | #ifdef IXGBE_FCOE |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 48 | char ixgbe_default_device_descr[] = |
| 49 | "Intel(R) 10 Gigabit Network Connection"; |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 50 | #else |
| 51 | static char ixgbe_default_device_descr[] = |
| 52 | "Intel(R) 10 Gigabit Network Connection"; |
| 53 | #endif |
Tony Nguyen | 01ec552 | 2017-05-18 14:55:07 -0700 | [diff] [blame] | 54 | #define DRV_VERSION "5.1.0-k" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 55 | const char ixgbe_driver_version[] = DRV_VERSION; |
Don Skidmore | a52055e | 2011-02-23 09:58:39 +0000 | [diff] [blame] | 56 | static const char ixgbe_copyright[] = |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 57 | "Copyright (c) 1999-2016 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 58 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 59 | static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter"; |
| 60 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 61 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 62 | [board_82598] = &ixgbe_82598_info, |
| 63 | [board_82599] = &ixgbe_82599_info, |
| 64 | [board_X540] = &ixgbe_X540_info, |
| 65 | [board_X550] = &ixgbe_X550_info, |
| 66 | [board_X550EM_x] = &ixgbe_X550EM_x_info, |
Paul Greenwalt | 8dc963e | 2017-04-13 08:07:07 -0400 | [diff] [blame] | 67 | [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 68 | [board_x550em_a] = &ixgbe_x550em_a_info, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 69 | [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 73 | * |
| 74 | * Wildcard entries (PCI_ANY_ID) should come last |
| 75 | * Last entry must be all 0s |
| 76 | * |
| 77 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 78 | * Class, Class Mask, private data (not used) } |
| 79 | */ |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 80 | static const struct pci_device_id ixgbe_pci_tbl[] = { |
Alexander Duyck | 54239c6 | 2011-07-15 03:06:06 +0000 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 }, |
| 82 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 }, |
| 83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 }, |
| 84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 }, |
| 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 }, |
| 86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 }, |
| 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 }, |
| 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 }, |
| 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 }, |
| 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 }, |
| 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 }, |
| 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 }, |
| 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 }, |
| 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 }, |
| 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 }, |
| 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 }, |
| 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 }, |
| 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 }, |
| 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 }, |
| 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 }, |
| 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 }, |
| 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 }, |
| 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 }, |
| 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 }, |
| 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 }, |
| 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 }, |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 }, |
Emil Tantilov | 7d14528 | 2011-09-08 08:30:14 +0000 | [diff] [blame] | 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 }, |
Emil Tantilov | 9e791e4 | 2011-11-04 06:43:29 +0000 | [diff] [blame] | 109 | {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] | 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 }, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 111 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550}, |
Mark Rustad | a711ad8 | 2016-03-21 11:21:31 -0700 | [diff] [blame] | 112 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 113 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x}, |
Don Skidmore | 18e01ee | 2016-12-30 21:07:58 -0500 | [diff] [blame] | 114 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x}, |
Don Skidmore | 6a14ee0 | 2014-12-05 03:59:50 +0000 | [diff] [blame] | 115 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x}, |
Don Skidmore | deda562 | 2015-06-09 17:39:46 -0700 | [diff] [blame] | 116 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x}, |
Mark Rustad | 018d714 | 2015-08-08 16:19:19 -0700 | [diff] [blame] | 117 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x}, |
Paul Greenwalt | 8dc963e | 2017-04-13 08:07:07 -0400 | [diff] [blame] | 118 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw}, |
Mark Rustad | f572b2c | 2016-04-01 12:18:46 -0700 | [diff] [blame] | 119 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a }, |
| 120 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a }, |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 121 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a }, |
Mark Rustad | 200157c | 2016-04-01 12:18:40 -0700 | [diff] [blame] | 122 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a }, |
| 123 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a }, |
Don Skidmore | 92ed843 | 2016-08-17 20:34:40 -0400 | [diff] [blame] | 124 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a}, |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 125 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a }, |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 126 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw }, |
| 127 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 128 | /* required last entry */ |
| 129 | {0, } |
| 130 | }; |
| 131 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 132 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 133 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 134 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 135 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 136 | static struct notifier_block dca_notifier = { |
| 137 | .notifier_call = ixgbe_notify_dca, |
| 138 | .next = NULL, |
| 139 | .priority = 0 |
| 140 | }; |
| 141 | #endif |
| 142 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 143 | #ifdef CONFIG_PCI_IOV |
| 144 | static unsigned int max_vfs; |
| 145 | module_param(max_vfs, uint, 0); |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 146 | MODULE_PARM_DESC(max_vfs, |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 147 | "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)"); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 148 | #endif /* CONFIG_PCI_IOV */ |
| 149 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 150 | static unsigned int allow_unsupported_sfp; |
| 151 | module_param(allow_unsupported_sfp, uint, 0); |
| 152 | MODULE_PARM_DESC(allow_unsupported_sfp, |
| 153 | "Allow unsupported and untested SFP+ modules on 82599-based adapters"); |
| 154 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 155 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 156 | static int debug = -1; |
| 157 | module_param(debug, int, 0); |
| 158 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 159 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 160 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 161 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 162 | MODULE_LICENSE("GPL"); |
| 163 | MODULE_VERSION(DRV_VERSION); |
| 164 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 165 | static struct workqueue_struct *ixgbe_wq; |
| 166 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 167 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev); |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 168 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 169 | |
Alexander Duyck | 68ae742 | 2017-11-22 10:56:52 -0800 | [diff] [blame] | 170 | static const struct net_device_ops ixgbe_netdev_ops; |
| 171 | |
| 172 | static bool netif_is_ixgbe(struct net_device *dev) |
| 173 | { |
| 174 | return dev && (dev->netdev_ops == &ixgbe_netdev_ops); |
| 175 | } |
| 176 | |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 177 | static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter, |
| 178 | u32 reg, u16 *value) |
| 179 | { |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 180 | struct pci_dev *parent_dev; |
| 181 | struct pci_bus *parent_bus; |
| 182 | |
| 183 | parent_bus = adapter->pdev->bus->parent; |
| 184 | if (!parent_bus) |
| 185 | return -1; |
| 186 | |
| 187 | parent_dev = parent_bus->self; |
| 188 | if (!parent_dev) |
| 189 | return -1; |
| 190 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 191 | if (!pci_is_pcie(parent_dev)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 192 | return -1; |
| 193 | |
Yijing Wang | c0798ed | 2013-09-04 17:30:08 +0000 | [diff] [blame] | 194 | pcie_capability_read_word(parent_dev, reg, value); |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 195 | if (*value == IXGBE_FAILED_READ_CFG_WORD && |
| 196 | ixgbe_check_cfg_remove(&adapter->hw, parent_dev)) |
| 197 | return -1; |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter) |
| 202 | { |
| 203 | struct ixgbe_hw *hw = &adapter->hw; |
| 204 | u16 link_status = 0; |
| 205 | int err; |
| 206 | |
| 207 | hw->bus.type = ixgbe_bus_type_pci_express; |
| 208 | |
| 209 | /* Get the negotiated link width and speed from PCI config space of the |
| 210 | * parent, as this device is behind a switch |
| 211 | */ |
| 212 | err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status); |
| 213 | |
| 214 | /* assume caller will handle error case */ |
| 215 | if (err) |
| 216 | return err; |
| 217 | |
| 218 | hw->bus.width = ixgbe_convert_bus_width(link_status); |
| 219 | hw->bus.speed = ixgbe_convert_bus_speed(link_status); |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 224 | /** |
| 225 | * ixgbe_check_from_parent - Determine whether PCIe info should come from parent |
| 226 | * @hw: hw specific details |
| 227 | * |
| 228 | * This function is used by probe to determine whether a device's PCI-Express |
| 229 | * bandwidth details should be gathered from the parent bus instead of from the |
| 230 | * device. Used to ensure that various locations all have the correct device ID |
| 231 | * checks. |
| 232 | */ |
| 233 | static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw) |
| 234 | { |
| 235 | switch (hw->device_id) { |
| 236 | case IXGBE_DEV_ID_82599_SFP_SF_QP: |
Don Skidmore | 8f58332 | 2013-07-27 06:25:38 +0000 | [diff] [blame] | 237 | case IXGBE_DEV_ID_82599_QSFP_SF_QP: |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 238 | return true; |
| 239 | default: |
| 240 | return false; |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter, |
| 245 | int expected_gts) |
| 246 | { |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 247 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 248 | struct pci_dev *pdev; |
| 249 | |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 250 | /* Some devices are not connected over PCIe and thus do not negotiate |
| 251 | * speed. These devices do not have valid bus info, and thus any report |
| 252 | * we generate may not be correct. |
| 253 | */ |
| 254 | if (hw->bus.type == ixgbe_bus_type_internal) |
| 255 | return; |
| 256 | |
Jacob Keller | 56d1392 | 2015-06-10 11:44:45 -0700 | [diff] [blame] | 257 | /* determine whether to use the parent device */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 258 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
| 259 | pdev = adapter->pdev->bus->parent->self; |
| 260 | else |
| 261 | pdev = adapter->pdev; |
| 262 | |
Bjorn Helgaas | 4695ca9 | 2018-03-30 14:26:07 -0500 | [diff] [blame] | 263 | pcie_print_link_status(pdev); |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 266 | static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter) |
| 267 | { |
| 268 | if (!test_bit(__IXGBE_DOWN, &adapter->state) && |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 269 | !test_bit(__IXGBE_REMOVING, &adapter->state) && |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 270 | !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state)) |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 271 | queue_work(ixgbe_wq, &adapter->service_task); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 274 | static void ixgbe_remove_adapter(struct ixgbe_hw *hw) |
| 275 | { |
| 276 | struct ixgbe_adapter *adapter = hw->back; |
| 277 | |
| 278 | if (!hw->hw_addr) |
| 279 | return; |
| 280 | hw->hw_addr = NULL; |
| 281 | e_dev_err("Adapter removed\n"); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 282 | if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 283 | ixgbe_service_event_schedule(adapter); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 286 | static u32 ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg) |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 287 | { |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 288 | u8 __iomem *reg_addr; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 289 | u32 value; |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 290 | int i; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 291 | |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 292 | reg_addr = READ_ONCE(hw->hw_addr); |
| 293 | if (ixgbe_removed(reg_addr)) |
| 294 | return IXGBE_FAILED_READ_REG; |
| 295 | |
| 296 | /* Register read of 0xFFFFFFF can indicate the adapter has been removed, |
| 297 | * so perform several status register reads to determine if the adapter |
| 298 | * has been removed. |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 299 | */ |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 300 | for (i = 0; i < IXGBE_FAILED_READ_RETRIES; i++) { |
| 301 | value = readl(reg_addr + IXGBE_STATUS); |
| 302 | if (value != IXGBE_FAILED_READ_REG) |
| 303 | break; |
| 304 | mdelay(3); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 305 | } |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 306 | |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 307 | if (value == IXGBE_FAILED_READ_REG) |
| 308 | ixgbe_remove_adapter(hw); |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 309 | else |
| 310 | value = readl(reg_addr + reg); |
| 311 | return value; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 314 | /** |
| 315 | * ixgbe_read_reg - Read from device register |
| 316 | * @hw: hw specific details |
| 317 | * @reg: offset of register to read |
| 318 | * |
| 319 | * Returns : value read or IXGBE_FAILED_READ_REG if removed |
| 320 | * |
| 321 | * This function is used to read device registers. It checks for device |
| 322 | * removal by confirming any read that returns all ones by checking the |
| 323 | * status register value for all ones. This function avoids reading from |
| 324 | * the hardware if a removal was previously detected in which case it |
| 325 | * returns IXGBE_FAILED_READ_REG (all ones). |
| 326 | */ |
| 327 | u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 328 | { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 329 | u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr); |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 330 | u32 value; |
| 331 | |
| 332 | if (ixgbe_removed(reg_addr)) |
| 333 | return IXGBE_FAILED_READ_REG; |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 334 | if (unlikely(hw->phy.nw_mng_if_sel & |
Tony Nguyen | 48301cf | 2017-06-07 14:36:19 -0700 | [diff] [blame] | 335 | IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) { |
Mark Rustad | 2f2219b | 2016-04-07 10:43:50 -0700 | [diff] [blame] | 336 | struct ixgbe_adapter *adapter; |
| 337 | int i; |
| 338 | |
| 339 | for (i = 0; i < 200; ++i) { |
| 340 | value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY); |
| 341 | if (likely(!value)) |
| 342 | goto writes_completed; |
| 343 | if (value == IXGBE_FAILED_READ_REG) { |
| 344 | ixgbe_remove_adapter(hw); |
| 345 | return IXGBE_FAILED_READ_REG; |
| 346 | } |
| 347 | udelay(5); |
| 348 | } |
| 349 | |
| 350 | adapter = hw->back; |
| 351 | e_warn(hw, "register writes incomplete %08x\n", value); |
| 352 | } |
| 353 | |
| 354 | writes_completed: |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 355 | value = readl(reg_addr + reg); |
| 356 | if (unlikely(value == IXGBE_FAILED_READ_REG)) |
Paul Greenwalt | 1aa3784 | 2018-03-12 09:22:55 -0400 | [diff] [blame] | 357 | value = ixgbe_check_remove(hw, reg); |
Mark Rustad | f8e2472 | 2014-03-18 07:03:40 +0000 | [diff] [blame] | 358 | return value; |
| 359 | } |
| 360 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 361 | static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev) |
| 362 | { |
| 363 | u16 value; |
| 364 | |
| 365 | pci_read_config_word(pdev, PCI_VENDOR_ID, &value); |
| 366 | if (value == IXGBE_FAILED_READ_CFG_WORD) { |
| 367 | ixgbe_remove_adapter(hw); |
| 368 | return true; |
| 369 | } |
| 370 | return false; |
| 371 | } |
| 372 | |
| 373 | u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg) |
| 374 | { |
| 375 | struct ixgbe_adapter *adapter = hw->back; |
| 376 | u16 value; |
| 377 | |
| 378 | if (ixgbe_removed(hw->hw_addr)) |
| 379 | return IXGBE_FAILED_READ_CFG_WORD; |
| 380 | pci_read_config_word(adapter->pdev, reg, &value); |
| 381 | if (value == IXGBE_FAILED_READ_CFG_WORD && |
| 382 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 383 | return IXGBE_FAILED_READ_CFG_WORD; |
| 384 | return value; |
| 385 | } |
| 386 | |
| 387 | #ifdef CONFIG_PCI_IOV |
| 388 | static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg) |
| 389 | { |
| 390 | struct ixgbe_adapter *adapter = hw->back; |
| 391 | u32 value; |
| 392 | |
| 393 | if (ixgbe_removed(hw->hw_addr)) |
| 394 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 395 | pci_read_config_dword(adapter->pdev, reg, &value); |
| 396 | if (value == IXGBE_FAILED_READ_CFG_DWORD && |
| 397 | ixgbe_check_cfg_remove(hw, adapter->pdev)) |
| 398 | return IXGBE_FAILED_READ_CFG_DWORD; |
| 399 | return value; |
| 400 | } |
| 401 | #endif /* CONFIG_PCI_IOV */ |
| 402 | |
Jacob Keller | ed19231 | 2014-02-22 01:23:53 +0000 | [diff] [blame] | 403 | void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value) |
| 404 | { |
| 405 | struct ixgbe_adapter *adapter = hw->back; |
| 406 | |
| 407 | if (ixgbe_removed(hw->hw_addr)) |
| 408 | return; |
| 409 | pci_write_config_word(adapter->pdev, reg, value); |
| 410 | } |
| 411 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 412 | static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter) |
| 413 | { |
| 414 | BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state)); |
| 415 | |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 416 | /* flush memory to make sure state is correct before next watchdog */ |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 417 | smp_mb__before_atomic(); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 418 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
| 419 | } |
| 420 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 421 | struct ixgbe_reg_info { |
| 422 | u32 ofs; |
| 423 | char *name; |
| 424 | }; |
| 425 | |
| 426 | static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = { |
| 427 | |
| 428 | /* General Registers */ |
| 429 | {IXGBE_CTRL, "CTRL"}, |
| 430 | {IXGBE_STATUS, "STATUS"}, |
| 431 | {IXGBE_CTRL_EXT, "CTRL_EXT"}, |
| 432 | |
| 433 | /* Interrupt Registers */ |
| 434 | {IXGBE_EICR, "EICR"}, |
| 435 | |
| 436 | /* RX Registers */ |
| 437 | {IXGBE_SRRCTL(0), "SRRCTL"}, |
| 438 | {IXGBE_DCA_RXCTRL(0), "DRXCTL"}, |
| 439 | {IXGBE_RDLEN(0), "RDLEN"}, |
| 440 | {IXGBE_RDH(0), "RDH"}, |
| 441 | {IXGBE_RDT(0), "RDT"}, |
| 442 | {IXGBE_RXDCTL(0), "RXDCTL"}, |
| 443 | {IXGBE_RDBAL(0), "RDBAL"}, |
| 444 | {IXGBE_RDBAH(0), "RDBAH"}, |
| 445 | |
| 446 | /* TX Registers */ |
| 447 | {IXGBE_TDBAL(0), "TDBAL"}, |
| 448 | {IXGBE_TDBAH(0), "TDBAH"}, |
| 449 | {IXGBE_TDLEN(0), "TDLEN"}, |
| 450 | {IXGBE_TDH(0), "TDH"}, |
| 451 | {IXGBE_TDT(0), "TDT"}, |
| 452 | {IXGBE_TXDCTL(0), "TXDCTL"}, |
| 453 | |
| 454 | /* List Terminator */ |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 455 | { .name = NULL } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 456 | }; |
| 457 | |
| 458 | |
| 459 | /* |
| 460 | * ixgbe_regdump - register printout routine |
| 461 | */ |
| 462 | static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo) |
| 463 | { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 464 | int i; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 465 | char rname[16]; |
| 466 | u32 regs[64]; |
| 467 | |
| 468 | switch (reginfo->ofs) { |
| 469 | case IXGBE_SRRCTL(0): |
| 470 | for (i = 0; i < 64; i++) |
| 471 | regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i)); |
| 472 | break; |
| 473 | case IXGBE_DCA_RXCTRL(0): |
| 474 | for (i = 0; i < 64; i++) |
| 475 | regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i)); |
| 476 | break; |
| 477 | case IXGBE_RDLEN(0): |
| 478 | for (i = 0; i < 64; i++) |
| 479 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i)); |
| 480 | break; |
| 481 | case IXGBE_RDH(0): |
| 482 | for (i = 0; i < 64; i++) |
| 483 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i)); |
| 484 | break; |
| 485 | case IXGBE_RDT(0): |
| 486 | for (i = 0; i < 64; i++) |
| 487 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i)); |
| 488 | break; |
| 489 | case IXGBE_RXDCTL(0): |
| 490 | for (i = 0; i < 64; i++) |
| 491 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); |
| 492 | break; |
| 493 | case IXGBE_RDBAL(0): |
| 494 | for (i = 0; i < 64; i++) |
| 495 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i)); |
| 496 | break; |
| 497 | case IXGBE_RDBAH(0): |
| 498 | for (i = 0; i < 64; i++) |
| 499 | regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i)); |
| 500 | break; |
| 501 | case IXGBE_TDBAL(0): |
| 502 | for (i = 0; i < 64; i++) |
| 503 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i)); |
| 504 | break; |
| 505 | case IXGBE_TDBAH(0): |
| 506 | for (i = 0; i < 64; i++) |
| 507 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i)); |
| 508 | break; |
| 509 | case IXGBE_TDLEN(0): |
| 510 | for (i = 0; i < 64; i++) |
| 511 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i)); |
| 512 | break; |
| 513 | case IXGBE_TDH(0): |
| 514 | for (i = 0; i < 64; i++) |
| 515 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i)); |
| 516 | break; |
| 517 | case IXGBE_TDT(0): |
| 518 | for (i = 0; i < 64; i++) |
| 519 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i)); |
| 520 | break; |
| 521 | case IXGBE_TXDCTL(0): |
| 522 | for (i = 0; i < 64; i++) |
| 523 | regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); |
| 524 | break; |
| 525 | default: |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 526 | pr_info("%-15s %08x\n", |
| 527 | reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs)); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 528 | return; |
| 529 | } |
| 530 | |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 531 | i = 0; |
| 532 | while (i < 64) { |
| 533 | int j; |
| 534 | char buf[9 * 8 + 1]; |
| 535 | char *p = buf; |
| 536 | |
| 537 | snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 538 | for (j = 0; j < 8; j++) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 539 | p += sprintf(p, " %08x", regs[i++]); |
| 540 | pr_err("%-15s%s\n", rname, buf); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | } |
| 544 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 545 | static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n) |
| 546 | { |
| 547 | struct ixgbe_tx_buffer *tx_buffer; |
| 548 | |
| 549 | tx_buffer = &ring->tx_buffer_info[ring->next_to_clean]; |
| 550 | pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n", |
| 551 | n, ring->next_to_use, ring->next_to_clean, |
| 552 | (u64)dma_unmap_addr(tx_buffer, dma), |
| 553 | dma_unmap_len(tx_buffer, len), |
| 554 | tx_buffer->next_to_watch, |
| 555 | (u64)tx_buffer->time_stamp); |
| 556 | } |
| 557 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 558 | /* |
| 559 | * ixgbe_dump - Print registers, tx-rings and rx-rings |
| 560 | */ |
| 561 | static void ixgbe_dump(struct ixgbe_adapter *adapter) |
| 562 | { |
| 563 | struct net_device *netdev = adapter->netdev; |
| 564 | struct ixgbe_hw *hw = &adapter->hw; |
| 565 | struct ixgbe_reg_info *reginfo; |
| 566 | int n = 0; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 567 | struct ixgbe_ring *ring; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 568 | struct ixgbe_tx_buffer *tx_buffer; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 569 | union ixgbe_adv_tx_desc *tx_desc; |
| 570 | struct my_u0 { u64 a; u64 b; } *u0; |
| 571 | struct ixgbe_ring *rx_ring; |
| 572 | union ixgbe_adv_rx_desc *rx_desc; |
| 573 | struct ixgbe_rx_buffer *rx_buffer_info; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 574 | int i = 0; |
| 575 | |
| 576 | if (!netif_msg_hw(adapter)) |
| 577 | return; |
| 578 | |
| 579 | /* Print netdevice Info */ |
| 580 | if (netdev) { |
| 581 | dev_info(&adapter->pdev->dev, "Net device Info\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 582 | pr_info("Device Name state " |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 583 | "trans_start\n"); |
| 584 | pr_info("%-15s %016lX %016lX\n", |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 585 | netdev->name, |
| 586 | netdev->state, |
Tobias Klauser | 4a7c972 | 2017-01-18 17:45:01 +0100 | [diff] [blame] | 587 | dev_trans_start(netdev)); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /* Print Registers */ |
| 591 | dev_info(&adapter->pdev->dev, "Register Dump\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 592 | pr_info(" Register Name Value\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 593 | for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl; |
| 594 | reginfo->name; reginfo++) { |
| 595 | ixgbe_regdump(hw, reginfo); |
| 596 | } |
| 597 | |
| 598 | /* Print TX Ring Summary */ |
| 599 | if (!netdev || !netif_running(netdev)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 600 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 601 | |
| 602 | dev_info(&adapter->pdev->dev, "TX Rings Summary\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 603 | pr_info(" %s %s %s %s\n", |
| 604 | "Queue [NTU] [NTC] [bi(ntc)->dma ]", |
| 605 | "leng", "ntw", "timestamp"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 606 | for (n = 0; n < adapter->num_tx_queues; n++) { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 607 | ring = adapter->tx_ring[n]; |
| 608 | ixgbe_print_buffer(ring, n); |
| 609 | } |
| 610 | |
| 611 | for (n = 0; n < adapter->num_xdp_queues; n++) { |
| 612 | ring = adapter->xdp_ring[n]; |
| 613 | ixgbe_print_buffer(ring, n); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /* Print TX Rings */ |
| 617 | if (!netif_msg_tx_done(adapter)) |
| 618 | goto rx_ring_summary; |
| 619 | |
| 620 | dev_info(&adapter->pdev->dev, "TX Rings Dump\n"); |
| 621 | |
| 622 | /* Transmit Descriptor Formats |
| 623 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 624 | * 82598 Advanced Transmit Descriptor |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 625 | * +--------------------------------------------------------------+ |
| 626 | * 0 | Buffer Address [63:0] | |
| 627 | * +--------------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 628 | * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 629 | * +--------------------------------------------------------------+ |
| 630 | * 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] | 631 | * |
| 632 | * 82598 Advanced Transmit Descriptor (Write-Back Format) |
| 633 | * +--------------------------------------------------------------+ |
| 634 | * 0 | RSV [63:0] | |
| 635 | * +--------------------------------------------------------------+ |
| 636 | * 8 | RSV | STA | NXTSEQ | |
| 637 | * +--------------------------------------------------------------+ |
| 638 | * 63 36 35 32 31 0 |
| 639 | * |
| 640 | * 82599+ Advanced Transmit Descriptor |
| 641 | * +--------------------------------------------------------------+ |
| 642 | * 0 | Buffer Address [63:0] | |
| 643 | * +--------------------------------------------------------------+ |
| 644 | * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN | |
| 645 | * +--------------------------------------------------------------+ |
| 646 | * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0 |
| 647 | * |
| 648 | * 82599+ Advanced Transmit Descriptor (Write-Back Format) |
| 649 | * +--------------------------------------------------------------+ |
| 650 | * 0 | RSV [63:0] | |
| 651 | * +--------------------------------------------------------------+ |
| 652 | * 8 | RSV | STA | RSV | |
| 653 | * +--------------------------------------------------------------+ |
| 654 | * 63 36 35 32 31 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 655 | */ |
| 656 | |
| 657 | for (n = 0; n < adapter->num_tx_queues; n++) { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 658 | ring = adapter->tx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 659 | pr_info("------------------------------------\n"); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 660 | pr_info("TX QUEUE INDEX = %d\n", ring->queue_index); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 661 | pr_info("------------------------------------\n"); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 662 | pr_info("%s%s %s %s %s %s\n", |
| 663 | "T [desc] [address 63:0 ] ", |
| 664 | "[PlPOIdStDDt Ln] [bi->dma ] ", |
| 665 | "leng", "ntw", "timestamp", "bi->skb"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 666 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 667 | for (i = 0; ring->desc && (i < ring->count); i++) { |
| 668 | tx_desc = IXGBE_TX_DESC(ring, i); |
| 669 | tx_buffer = &ring->tx_buffer_info[i]; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 670 | u0 = (struct my_u0 *)tx_desc; |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 671 | if (dma_unmap_len(tx_buffer, len) > 0) { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 672 | const char *ring_desc; |
| 673 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 674 | if (i == ring->next_to_use && |
| 675 | i == ring->next_to_clean) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 676 | ring_desc = " NTC/U"; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 677 | else if (i == ring->next_to_use) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 678 | ring_desc = " NTU"; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 679 | else if (i == ring->next_to_clean) |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 680 | ring_desc = " NTC"; |
| 681 | else |
| 682 | ring_desc = ""; |
| 683 | pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 684 | i, |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 685 | le64_to_cpu((__force __le64)u0->a), |
| 686 | le64_to_cpu((__force __le64)u0->b), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 687 | (u64)dma_unmap_addr(tx_buffer, dma), |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 688 | dma_unmap_len(tx_buffer, len), |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 689 | tx_buffer->next_to_watch, |
| 690 | (u64)tx_buffer->time_stamp, |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 691 | tx_buffer->skb, |
| 692 | ring_desc); |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 693 | |
| 694 | if (netif_msg_pktdata(adapter) && |
| 695 | tx_buffer->skb) |
| 696 | print_hex_dump(KERN_INFO, "", |
| 697 | DUMP_PREFIX_ADDRESS, 16, 1, |
| 698 | tx_buffer->skb->data, |
| 699 | dma_unmap_len(tx_buffer, len), |
| 700 | true); |
| 701 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
| 705 | /* Print RX Rings Summary */ |
| 706 | rx_ring_summary: |
| 707 | dev_info(&adapter->pdev->dev, "RX Rings Summary\n"); |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 708 | pr_info("Queue [NTU] [NTC]\n"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 709 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 710 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 711 | pr_info("%5d %5X %5X\n", |
| 712 | n, rx_ring->next_to_use, rx_ring->next_to_clean); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | /* Print RX Rings */ |
| 716 | if (!netif_msg_rx_status(adapter)) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 717 | return; |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 718 | |
| 719 | dev_info(&adapter->pdev->dev, "RX Rings Dump\n"); |
| 720 | |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 721 | /* Receive Descriptor Formats |
| 722 | * |
| 723 | * 82598 Advanced Receive Descriptor (Read) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 724 | * 63 1 0 |
| 725 | * +-----------------------------------------------------+ |
| 726 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 727 | * +----------------------------------------------+------+ |
| 728 | * 8 | Header Buffer Address [63:1] | DD | |
| 729 | * +-----------------------------------------------------+ |
| 730 | * |
| 731 | * |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 732 | * 82598 Advanced Receive Descriptor (Write-Back) Format |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 733 | * |
| 734 | * 63 48 47 32 31 30 21 20 16 15 4 3 0 |
| 735 | * +------------------------------------------------------+ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 736 | * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS | |
| 737 | * | Packet | IP | | | | Type | Type | |
| 738 | * | Checksum | Ident | | | | | | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 739 | * +------------------------------------------------------+ |
| 740 | * 8 | VLAN Tag | Length | Extended Error | Extended Status | |
| 741 | * +------------------------------------------------------+ |
| 742 | * 63 48 47 32 31 20 19 0 |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 743 | * |
| 744 | * 82599+ Advanced Receive Descriptor (Read) Format |
| 745 | * 63 1 0 |
| 746 | * +-----------------------------------------------------+ |
| 747 | * 0 | Packet Buffer Address [63:1] |A0/NSE| |
| 748 | * +----------------------------------------------+------+ |
| 749 | * 8 | Header Buffer Address [63:1] | DD | |
| 750 | * +-----------------------------------------------------+ |
| 751 | * |
| 752 | * |
| 753 | * 82599+ Advanced Receive Descriptor (Write-Back) Format |
| 754 | * |
| 755 | * 63 48 47 32 31 30 21 20 17 16 4 3 0 |
| 756 | * +------------------------------------------------------+ |
| 757 | * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS | |
| 758 | * |/ RTT / PCoE_PARAM | | | CNT | Type | Type | |
| 759 | * |/ Flow Dir Flt ID | | | | | | |
| 760 | * +------------------------------------------------------+ |
| 761 | * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP | |
| 762 | * +------------------------------------------------------+ |
| 763 | * 63 48 47 32 31 20 19 0 |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 764 | */ |
Josh Hay | 39ac868 | 2012-09-26 05:59:36 +0000 | [diff] [blame] | 765 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 766 | for (n = 0; n < adapter->num_rx_queues; n++) { |
| 767 | rx_ring = adapter->rx_ring[n]; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 768 | pr_info("------------------------------------\n"); |
| 769 | pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index); |
| 770 | pr_info("------------------------------------\n"); |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 771 | pr_info("%s%s%s\n", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 772 | "R [desc] [ PktBuf A0] ", |
| 773 | "[ HeadBuf DD] [bi->dma ] [bi->skb ] ", |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 774 | "<-- Adv Rx Read format"); |
| 775 | pr_info("%s%s%s\n", |
Josh Hay | 8ad88e3 | 2012-09-26 05:59:41 +0000 | [diff] [blame] | 776 | "RWB[desc] [PcsmIpSHl PtRs] ", |
| 777 | "[vl er S cks ln] ---------------- [bi->skb ] ", |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 778 | "<-- Adv Rx Write-Back format"); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 779 | |
| 780 | for (i = 0; i < rx_ring->count; i++) { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 781 | const char *ring_desc; |
| 782 | |
| 783 | if (i == rx_ring->next_to_use) |
| 784 | ring_desc = " NTU"; |
| 785 | else if (i == rx_ring->next_to_clean) |
| 786 | ring_desc = " NTC"; |
| 787 | else |
| 788 | ring_desc = ""; |
| 789 | |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 790 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 791 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 792 | u0 = (struct my_u0 *)rx_desc; |
Alexander Duyck | 18a8cc9 | 2017-03-02 15:01:36 -0800 | [diff] [blame] | 793 | if (rx_desc->wb.upper.length) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 794 | /* Descriptor Done */ |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 795 | pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n", |
| 796 | i, |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 797 | le64_to_cpu((__force __le64)u0->a), |
| 798 | le64_to_cpu((__force __le64)u0->b), |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 799 | rx_buffer_info->skb, |
| 800 | ring_desc); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 801 | } else { |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 802 | pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n", |
| 803 | i, |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 804 | le64_to_cpu((__force __le64)u0->a), |
| 805 | le64_to_cpu((__force __le64)u0->b), |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 806 | (u64)rx_buffer_info->dma, |
Joe Perches | 332f235 | 2017-01-03 07:28:11 -0800 | [diff] [blame] | 807 | rx_buffer_info->skb, |
| 808 | ring_desc); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 809 | |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 810 | if (netif_msg_pktdata(adapter) && |
| 811 | rx_buffer_info->dma) { |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 812 | print_hex_dump(KERN_INFO, "", |
| 813 | DUMP_PREFIX_ADDRESS, 16, 1, |
Emil Tantilov | 9c50c03 | 2012-07-26 01:21:24 +0000 | [diff] [blame] | 814 | page_address(rx_buffer_info->page) + |
| 815 | rx_buffer_info->page_offset, |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 816 | ixgbe_rx_bufsz(rx_ring), true); |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 817 | } |
| 818 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 819 | } |
| 820 | } |
Taku Izumi | dcd79ae | 2010-04-27 14:39:53 +0000 | [diff] [blame] | 821 | } |
| 822 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 823 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 824 | { |
| 825 | u32 ctrl_ext; |
| 826 | |
| 827 | /* Let firmware take over control of h/w */ |
| 828 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 829 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 830 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 834 | { |
| 835 | u32 ctrl_ext; |
| 836 | |
| 837 | /* Let firmware know the driver has taken over */ |
| 838 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 839 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 840 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 841 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 842 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 843 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 844 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 845 | * @adapter: pointer to adapter struct |
| 846 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 847 | * @queue: queue to map the corresponding interrupt to |
| 848 | * @msix_vector: the vector to map to the corresponding queue |
| 849 | * |
| 850 | */ |
| 851 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 852 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 853 | { |
| 854 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 855 | struct ixgbe_hw *hw = &adapter->hw; |
| 856 | switch (hw->mac.type) { |
| 857 | case ixgbe_mac_82598EB: |
| 858 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 859 | if (direction == -1) |
| 860 | direction = 0; |
| 861 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 862 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 863 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 864 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 865 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 866 | break; |
| 867 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 868 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 869 | case ixgbe_mac_X550: |
| 870 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 871 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 872 | if (direction == -1) { |
| 873 | /* other causes */ |
| 874 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 875 | index = ((queue & 1) * 8); |
| 876 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 877 | ivar &= ~(0xFF << index); |
| 878 | ivar |= (msix_vector << index); |
| 879 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 880 | break; |
| 881 | } else { |
| 882 | /* tx or rx causes */ |
| 883 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 884 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 885 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 886 | ivar &= ~(0xFF << index); |
| 887 | ivar |= (msix_vector << index); |
| 888 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 889 | break; |
| 890 | } |
| 891 | default: |
| 892 | break; |
| 893 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 894 | } |
| 895 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 896 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 897 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 898 | { |
| 899 | u32 mask; |
| 900 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 901 | switch (adapter->hw.mac.type) { |
| 902 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 903 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 904 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 905 | break; |
| 906 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 907 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 908 | case ixgbe_mac_X550: |
| 909 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 910 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 911 | mask = (qmask & 0xFFFFFFFF); |
| 912 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 913 | mask = (qmask >> 32); |
| 914 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 915 | break; |
| 916 | default: |
| 917 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 921 | static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter) |
| 922 | { |
| 923 | struct ixgbe_hw *hw = &adapter->hw; |
| 924 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
| 925 | int i; |
| 926 | u32 data; |
| 927 | |
| 928 | if ((hw->fc.current_mode != ixgbe_fc_full) && |
| 929 | (hw->fc.current_mode != ixgbe_fc_rx_pause)) |
| 930 | return; |
| 931 | |
| 932 | switch (hw->mac.type) { |
| 933 | case ixgbe_mac_82598EB: |
| 934 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 935 | break; |
| 936 | default: |
| 937 | data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 938 | } |
| 939 | hwstats->lxoffrxc += data; |
| 940 | |
| 941 | /* refill credits (no tx hang) if we received xoff */ |
| 942 | if (!data) |
| 943 | return; |
| 944 | |
| 945 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 946 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 947 | &adapter->tx_ring[i]->state); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 948 | |
| 949 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 950 | clear_bit(__IXGBE_HANG_CHECK_ARMED, |
| 951 | &adapter->xdp_ring[i]->state); |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 952 | } |
| 953 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 954 | static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 955 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 956 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 957 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 958 | u32 xoff[8] = {0}; |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 959 | u8 tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 960 | int i; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 961 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 962 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 963 | if (adapter->ixgbe_ieee_pfc) |
| 964 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 965 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 966 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) { |
| 967 | ixgbe_update_xoff_rx_lfc(adapter); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 968 | return; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 969 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 970 | |
| 971 | /* update stats for each tc, only valid with PFC enabled */ |
| 972 | for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) { |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 973 | u32 pxoffrxc; |
| 974 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 975 | switch (hw->mac.type) { |
| 976 | case ixgbe_mac_82598EB: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 977 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 978 | break; |
| 979 | default: |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 980 | pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 981 | } |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 982 | hwstats->pxoffrxc[i] += pxoffrxc; |
| 983 | /* Get the TC for given UP */ |
| 984 | tc = netdev_get_prio_tc_map(adapter->netdev, i); |
| 985 | xoff[tc] += pxoffrxc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 986 | } |
| 987 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 988 | /* disarm tx queues that have received xoff frames */ |
| 989 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 990 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 991 | |
Parikh, Neerav | 2afaa00 | 2012-09-27 12:02:22 +0000 | [diff] [blame] | 992 | tc = tx_ring->dcb_tc; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 993 | if (xoff[tc]) |
| 994 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
| 995 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 996 | |
| 997 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 998 | struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i]; |
| 999 | |
| 1000 | tc = xdp_ring->dcb_tc; |
| 1001 | if (xoff[tc]) |
| 1002 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state); |
| 1003 | } |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring) |
| 1007 | { |
Alexander Duyck | 7d7ce68 | 2012-02-08 07:50:51 +0000 | [diff] [blame] | 1008 | return ring->stats.packets; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring) |
| 1012 | { |
Alexander Duyck | 1489542 | 2017-11-22 10:56:46 -0800 | [diff] [blame] | 1013 | unsigned int head, tail; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1014 | |
Alexander Duyck | 1489542 | 2017-11-22 10:56:46 -0800 | [diff] [blame] | 1015 | head = ring->next_to_clean; |
| 1016 | tail = ring->next_to_use; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 1017 | |
Alexander Duyck | 1489542 | 2017-11-22 10:56:46 -0800 | [diff] [blame] | 1018 | return ((head <= tail) ? tail : tail + ring->count) - head; |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring) |
| 1022 | { |
| 1023 | u32 tx_done = ixgbe_get_tx_completed(tx_ring); |
| 1024 | u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 1025 | u32 tx_pending = ixgbe_get_tx_pending(tx_ring); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1026 | |
| 1027 | clear_check_for_tx_hang(tx_ring); |
| 1028 | |
| 1029 | /* |
| 1030 | * Check for a hung queue, but be thorough. This verifies |
| 1031 | * that a transmit has been completed since the previous |
| 1032 | * check AND there is at least one packet pending. The |
| 1033 | * ARMED bit is set to indicate a potential hang. The |
| 1034 | * bit is cleared if a pause frame is received to remove |
| 1035 | * false hang detection due to PFC or 802.3x frames. By |
| 1036 | * requiring this to fail twice we avoid races with |
| 1037 | * pfc clearing the ARMED bit and conditions where we |
| 1038 | * run the check_tx_hang logic with a transmit completion |
| 1039 | * pending but without time to complete it yet. |
| 1040 | */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1041 | if (tx_done_old == tx_done && tx_pending) |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1042 | /* make sure it is true for two checks in a row */ |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1043 | return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED, |
| 1044 | &tx_ring->state); |
| 1045 | /* update completed stats and continue */ |
| 1046 | tx_ring->tx_stats.tx_done_old = tx_done; |
| 1047 | /* reset the countdown */ |
| 1048 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1049 | |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 1050 | return false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1053 | /** |
| 1054 | * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout |
| 1055 | * @adapter: driver private struct |
| 1056 | **/ |
| 1057 | static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter) |
| 1058 | { |
| 1059 | |
| 1060 | /* Do the reset outside of interrupt context */ |
| 1061 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 1062 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 1063 | e_warn(drv, "initiating reset due to tx timeout\n"); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1064 | ixgbe_service_event_schedule(adapter); |
| 1065 | } |
| 1066 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1067 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1068 | /** |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1069 | * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 1070 | * @netdev: network interface device structure |
| 1071 | * @queue_index: Tx queue to set |
| 1072 | * @maxrate: desired maximum transmit bitrate |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 1073 | **/ |
| 1074 | static int ixgbe_tx_maxrate(struct net_device *netdev, |
| 1075 | int queue_index, u32 maxrate) |
| 1076 | { |
| 1077 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1078 | struct ixgbe_hw *hw = &adapter->hw; |
| 1079 | u32 bcnrc_val = ixgbe_link_mbps(adapter); |
| 1080 | |
| 1081 | if (!maxrate) |
| 1082 | return 0; |
| 1083 | |
| 1084 | /* Calculate the rate factor values to set */ |
| 1085 | bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT; |
| 1086 | bcnrc_val /= maxrate; |
| 1087 | |
| 1088 | /* clear everything but the rate factor */ |
| 1089 | bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK | |
| 1090 | IXGBE_RTTBCNRC_RF_DEC_MASK; |
| 1091 | |
| 1092 | /* enable the rate scheduler */ |
| 1093 | bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA; |
| 1094 | |
| 1095 | IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index); |
| 1096 | IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val); |
| 1097 | |
| 1098 | return 0; |
| 1099 | } |
| 1100 | |
| 1101 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1102 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1103 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1104 | * @tx_ring: tx ring to clean |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 1105 | * @napi_budget: Used to determine if we are in netpoll |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1106 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1107 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesper Dangaard Brouer | a3a8749 | 2016-02-08 13:15:09 +0100 | [diff] [blame] | 1108 | struct ixgbe_ring *tx_ring, int napi_budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1109 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1110 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1111 | struct ixgbe_tx_buffer *tx_buffer; |
| 1112 | union ixgbe_adv_tx_desc *tx_desc; |
Shannon Nelson | a8a43fd | 2017-12-19 16:00:01 -0800 | [diff] [blame] | 1113 | unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0; |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1114 | unsigned int budget = q_vector->tx.work_limit; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1115 | unsigned int i = tx_ring->next_to_clean; |
| 1116 | |
| 1117 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1118 | return true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1119 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1120 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1121 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1122 | i -= tx_ring->count; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1123 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1124 | do { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1125 | union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1126 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1127 | /* if next_to_watch is not set then there is no work pending */ |
| 1128 | if (!eop_desc) |
| 1129 | break; |
| 1130 | |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1131 | /* prevent any other reads prior to eop_desc */ |
Brian King | 0a9a17e | 2017-11-17 11:05:43 -0600 | [diff] [blame] | 1132 | smp_rmb(); |
Alexander Duyck | 7f83a9e | 2012-02-08 07:49:23 +0000 | [diff] [blame] | 1133 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1134 | /* if DD is not set pending work has not been completed */ |
| 1135 | if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 1136 | break; |
| 1137 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1138 | /* clear next_to_watch to prevent false hangs */ |
| 1139 | tx_buffer->next_to_watch = NULL; |
| 1140 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1141 | /* update the statistics for this packet */ |
| 1142 | total_bytes += tx_buffer->bytecount; |
| 1143 | total_packets += tx_buffer->gso_segs; |
Shannon Nelson | a8a43fd | 2017-12-19 16:00:01 -0800 | [diff] [blame] | 1144 | if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC) |
| 1145 | total_ipsec++; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 1146 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1147 | /* free the skb */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1148 | if (ring_is_xdp(tx_ring)) |
Jesper Dangaard Brouer | 0399309 | 2018-04-17 16:46:32 +0200 | [diff] [blame] | 1149 | xdp_return_frame(tx_buffer->xdpf); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1150 | else |
| 1151 | napi_consume_skb(tx_buffer->skb, napi_budget); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1152 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1153 | /* unmap skb header data */ |
| 1154 | dma_unmap_single(tx_ring->dev, |
| 1155 | dma_unmap_addr(tx_buffer, dma), |
| 1156 | dma_unmap_len(tx_buffer, len), |
| 1157 | DMA_TO_DEVICE); |
| 1158 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1159 | /* clear tx_buffer data */ |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1160 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 1161 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1162 | /* unmap remaining buffers */ |
| 1163 | while (tx_desc != eop_desc) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1164 | tx_buffer++; |
| 1165 | tx_desc++; |
| 1166 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1167 | if (unlikely(!i)) { |
| 1168 | i -= tx_ring->count; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1169 | tx_buffer = tx_ring->tx_buffer_info; |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1170 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1173 | /* unmap any remaining paged data */ |
| 1174 | if (dma_unmap_len(tx_buffer, len)) { |
| 1175 | dma_unmap_page(tx_ring->dev, |
| 1176 | dma_unmap_addr(tx_buffer, dma), |
| 1177 | dma_unmap_len(tx_buffer, len), |
| 1178 | DMA_TO_DEVICE); |
| 1179 | dma_unmap_len_set(tx_buffer, len, 0); |
| 1180 | } |
| 1181 | } |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1182 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1183 | /* move us one more past the eop_desc for start of next pkt */ |
| 1184 | tx_buffer++; |
| 1185 | tx_desc++; |
| 1186 | i++; |
| 1187 | if (unlikely(!i)) { |
| 1188 | i -= tx_ring->count; |
| 1189 | tx_buffer = tx_ring->tx_buffer_info; |
| 1190 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 1191 | } |
| 1192 | |
| 1193 | /* issue prefetch for next Tx descriptor */ |
| 1194 | prefetch(tx_desc); |
| 1195 | |
| 1196 | /* update budget accounting */ |
| 1197 | budget--; |
| 1198 | } while (likely(budget)); |
| 1199 | |
| 1200 | i += tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1201 | tx_ring->next_to_clean = i; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1202 | u64_stats_update_begin(&tx_ring->syncp); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1203 | tx_ring->stats.bytes += total_bytes; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1204 | tx_ring->stats.packets += total_packets; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1205 | u64_stats_update_end(&tx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 1206 | q_vector->tx.total_bytes += total_bytes; |
| 1207 | q_vector->tx.total_packets += total_packets; |
Shannon Nelson | a8a43fd | 2017-12-19 16:00:01 -0800 | [diff] [blame] | 1208 | adapter->tx_ipsec += total_ipsec; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1209 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1210 | 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] | 1211 | /* schedule immediate reset if we believe we hung */ |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1212 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1213 | e_err(drv, "Detected Tx Unit Hang %s\n" |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1214 | " Tx Queue <%d>\n" |
| 1215 | " TDH, TDT <%x>, <%x>\n" |
| 1216 | " next_to_use <%x>\n" |
| 1217 | " next_to_clean <%x>\n" |
| 1218 | "tx_buffer_info[next_to_clean]\n" |
| 1219 | " time_stamp <%lx>\n" |
| 1220 | " jiffies <%lx>\n", |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1221 | ring_is_xdp(tx_ring) ? "(XDP)" : "", |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1222 | tx_ring->queue_index, |
| 1223 | IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)), |
| 1224 | IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)), |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 1225 | tx_ring->next_to_use, i, |
| 1226 | tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1227 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1228 | if (!ring_is_xdp(tx_ring)) |
| 1229 | netif_stop_subqueue(tx_ring->netdev, |
| 1230 | tx_ring->queue_index); |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 1231 | |
| 1232 | e_info(probe, |
| 1233 | "tx hang %d detected on queue %d, resetting adapter\n", |
| 1234 | adapter->tx_timeout_count + 1, tx_ring->queue_index); |
| 1235 | |
| 1236 | /* schedule immediate reset if we believe we hung */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 1237 | ixgbe_tx_timeout_reset(adapter); |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1238 | |
| 1239 | /* the adapter is about to reset, no point in enabling stuff */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1240 | return true; |
Alexander Duyck | b953799 | 2010-11-16 19:26:58 -0800 | [diff] [blame] | 1241 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1242 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 1243 | if (ring_is_xdp(tx_ring)) |
| 1244 | return !!budget; |
| 1245 | |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 1246 | netdev_tx_completed_queue(txring_txq(tx_ring), |
| 1247 | total_packets, total_bytes); |
| 1248 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1249 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | 30065e6 | 2011-07-15 03:05:14 +0000 | [diff] [blame] | 1250 | if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 1251 | (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1252 | /* Make sure that anybody stopping the queue after this |
| 1253 | * sees the new next_to_clean. |
| 1254 | */ |
| 1255 | smp_mb(); |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 1256 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 1257 | tx_ring->queue_index) |
| 1258 | && !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1259 | netif_wake_subqueue(tx_ring->netdev, |
| 1260 | tx_ring->queue_index); |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 1261 | ++tx_ring->tx_stats.restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 1262 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 1263 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1264 | |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 1265 | return !!budget; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1266 | } |
| 1267 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1268 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1269 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1270 | struct ixgbe_ring *tx_ring, |
| 1271 | int cpu) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1272 | { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1273 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1274 | u32 txctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1275 | u16 reg_offset; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1276 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1277 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1278 | txctrl = dca3_get_tag(tx_ring->dev, cpu); |
| 1279 | |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1280 | switch (hw->mac.type) { |
| 1281 | case ixgbe_mac_82598EB: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1282 | reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1283 | break; |
| 1284 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 1285 | case ixgbe_mac_X540: |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1286 | reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx); |
| 1287 | txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599; |
| 1288 | break; |
| 1289 | default: |
| 1290 | /* for unknown hardware do not write register */ |
| 1291 | return; |
| 1292 | } |
| 1293 | |
| 1294 | /* |
| 1295 | * We can enable relaxed ordering for reads, but not writes when |
| 1296 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1297 | * which will cause the DCA tag to be cleared. |
| 1298 | */ |
| 1299 | txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1300 | IXGBE_DCA_TXCTRL_DATA_RRO_EN | |
| 1301 | IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 1302 | |
| 1303 | IXGBE_WRITE_REG(hw, reg_offset, txctrl); |
| 1304 | } |
| 1305 | |
| 1306 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
| 1307 | struct ixgbe_ring *rx_ring, |
| 1308 | int cpu) |
| 1309 | { |
| 1310 | struct ixgbe_hw *hw = &adapter->hw; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1311 | u32 rxctrl = 0; |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1312 | u8 reg_idx = rx_ring->reg_idx; |
| 1313 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1314 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1315 | rxctrl = dca3_get_tag(rx_ring->dev, cpu); |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1316 | |
| 1317 | switch (hw->mac.type) { |
| 1318 | case ixgbe_mac_82599EB: |
| 1319 | case ixgbe_mac_X540: |
| 1320 | rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1321 | break; |
| 1322 | default: |
| 1323 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1324 | } |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1325 | |
| 1326 | /* |
| 1327 | * We can enable relaxed ordering for reads, but not writes when |
| 1328 | * DCA is enabled. This is due to a known issue in some chipsets |
| 1329 | * which will cause the DCA tag to be cleared. |
| 1330 | */ |
| 1331 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1332 | IXGBE_DCA_RXCTRL_DATA_DCA_EN | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1333 | IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 1334 | |
| 1335 | IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector) |
| 1339 | { |
| 1340 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1341 | struct ixgbe_ring *ring; |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1342 | int cpu = get_cpu(); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1343 | |
| 1344 | if (q_vector->cpu == cpu) |
| 1345 | goto out_no_update; |
| 1346 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1347 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1348 | ixgbe_update_tx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1349 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 1350 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 1351 | ixgbe_update_rx_dca(adapter, ring, cpu); |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1352 | |
| 1353 | q_vector->cpu = cpu; |
| 1354 | out_no_update: |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1355 | put_cpu(); |
| 1356 | } |
| 1357 | |
| 1358 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 1359 | { |
| 1360 | int i; |
| 1361 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1362 | /* always use CB2 mode, difference is masked in the CB driver */ |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1363 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1364 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1365 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
| 1366 | else |
| 1367 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1368 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 1369 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 1370 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1371 | adapter->q_vector[i]->cpu = -1; |
| 1372 | ixgbe_update_dca(adapter->q_vector[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 1377 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 1378 | struct ixgbe_adapter *adapter = dev_get_drvdata(dev); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1379 | unsigned long event = *(unsigned long *)data; |
| 1380 | |
Don Skidmore | 2a72c31 | 2011-07-20 02:27:05 +0000 | [diff] [blame] | 1381 | if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE)) |
Alexander Duyck | 33cf09c | 2010-11-16 19:26:55 -0800 | [diff] [blame] | 1382 | return 0; |
| 1383 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1384 | switch (event) { |
| 1385 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1386 | /* if we're already enabled, don't do it again */ |
| 1387 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1388 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1389 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 1390 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1391 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1392 | IXGBE_DCA_CTRL_DCA_MODE_CB2); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1393 | break; |
| 1394 | } |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 1395 | /* fall through - DCA is disabled. */ |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1396 | case DCA_PROVIDER_REMOVE: |
| 1397 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 1398 | dca_remove_requester(dev); |
| 1399 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 1400 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 1401 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1402 | } |
| 1403 | break; |
| 1404 | } |
| 1405 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 1406 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1407 | } |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1408 | |
Alexander Duyck | bdda1a6 | 2012-02-08 07:50:14 +0000 | [diff] [blame] | 1409 | #endif /* CONFIG_IXGBE_DCA */ |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1410 | |
| 1411 | #define IXGBE_RSS_L4_TYPES_MASK \ |
| 1412 | ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 1413 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 1414 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 1415 | (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 1416 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1417 | static inline void ixgbe_rx_hash(struct ixgbe_ring *ring, |
| 1418 | union ixgbe_adv_rx_desc *rx_desc, |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1419 | struct sk_buff *skb) |
| 1420 | { |
Fan Du | 7edda4b8 | 2015-04-29 10:57:39 +0800 | [diff] [blame] | 1421 | u16 rss_type; |
| 1422 | |
| 1423 | if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 1424 | return; |
| 1425 | |
| 1426 | rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 1427 | IXGBE_RXDADV_RSSTYPE_MASK; |
| 1428 | |
| 1429 | if (!rss_type) |
| 1430 | return; |
| 1431 | |
| 1432 | skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 1433 | (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 1434 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
Emil Tantilov | 67a74ee | 2011-04-23 04:50:40 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1437 | #ifdef IXGBE_FCOE |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1438 | /** |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1439 | * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1440 | * @ring: structure containing ring specific data |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1441 | * @rx_desc: advanced rx descriptor |
| 1442 | * |
| 1443 | * Returns : true if it is FCoE pkt |
| 1444 | */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1445 | static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring, |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1446 | union ixgbe_adv_rx_desc *rx_desc) |
| 1447 | { |
| 1448 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 1449 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1450 | return test_bit(__IXGBE_RX_FCOE, &ring->state) && |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1451 | ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) == |
| 1452 | (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE << |
| 1453 | IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT))); |
| 1454 | } |
| 1455 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1456 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | ff886df | 2011-06-11 01:45:13 +0000 | [diff] [blame] | 1457 | /** |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1458 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1459 | * @ring: structure containing ring specific data |
| 1460 | * @rx_desc: current Rx descriptor being processed |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1461 | * @skb: skb currently being received and modified |
| 1462 | **/ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1463 | static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1464 | union ixgbe_adv_rx_desc *rx_desc, |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1465 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1466 | { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1467 | __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1468 | bool encap_pkt = false; |
| 1469 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1470 | skb_checksum_none_assert(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1471 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 1472 | /* Rx csum disabled */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1473 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1474 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1475 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 1476 | /* check for VXLAN and Geneve packets */ |
| 1477 | if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) { |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1478 | encap_pkt = true; |
| 1479 | skb->encapsulation = 1; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1482 | /* if IP and error */ |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1483 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 1484 | ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1485 | ring->rx_stats.csum_err++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1486 | return; |
| 1487 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1488 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1489 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1490 | return; |
| 1491 | |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 1492 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1493 | /* |
| 1494 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 1495 | * checksum errors. |
| 1496 | */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1497 | if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) && |
| 1498 | test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state)) |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 1499 | return; |
| 1500 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1501 | ring->rx_stats.csum_err++; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1502 | return; |
| 1503 | } |
| 1504 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1505 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 1506 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1507 | if (encap_pkt) { |
| 1508 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS)) |
| 1509 | return; |
| 1510 | |
| 1511 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) { |
Mark Rustad | d469251 | 2015-12-04 11:26:43 -0800 | [diff] [blame] | 1512 | skb->ip_summed = CHECKSUM_NONE; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 1513 | return; |
| 1514 | } |
| 1515 | /* If we checked the outer header let the stack know */ |
| 1516 | skb->csum_level = 1; |
| 1517 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1518 | } |
| 1519 | |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1520 | static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring) |
| 1521 | { |
| 1522 | return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0; |
| 1523 | } |
| 1524 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1525 | static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring, |
| 1526 | struct ixgbe_rx_buffer *bi) |
| 1527 | { |
| 1528 | struct page *page = bi->page; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1529 | dma_addr_t dma; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1530 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1531 | /* since we are recycling buffers we should seldom need to alloc */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1532 | if (likely(page)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1533 | return true; |
| 1534 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1535 | /* alloc new page for storage */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1536 | page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring)); |
| 1537 | if (unlikely(!page)) { |
| 1538 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1539 | return false; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1542 | /* map page for use */ |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1543 | dma = dma_map_page_attrs(rx_ring->dev, page, 0, |
| 1544 | ixgbe_rx_pg_size(rx_ring), |
| 1545 | DMA_FROM_DEVICE, |
| 1546 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1547 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1548 | /* |
| 1549 | * if mapping failed free memory back to system since |
| 1550 | * there isn't much point in holding memory we can't use |
| 1551 | */ |
| 1552 | if (dma_mapping_error(rx_ring->dev, dma)) { |
Alexander Duyck | dd411ec | 2012-04-06 04:24:50 +0000 | [diff] [blame] | 1553 | __free_pages(page, ixgbe_rx_pg_order(rx_ring)); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1554 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1555 | rx_ring->rx_stats.alloc_rx_page_failed++; |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1559 | bi->dma = dma; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1560 | bi->page = page; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 1561 | bi->page_offset = ixgbe_rx_offset(rx_ring); |
Björn Töpel | ed93a39 | 2018-03-22 10:02:36 +0100 | [diff] [blame] | 1562 | page_ref_add(page, USHRT_MAX - 1); |
| 1563 | bi->pagecnt_bias = USHRT_MAX; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 1564 | rx_ring->rx_stats.alloc_rx_page++; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1565 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1566 | return true; |
| 1567 | } |
| 1568 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1569 | /** |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1570 | * ixgbe_alloc_rx_buffers - Replace used receive buffers |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1571 | * @rx_ring: ring to place buffers on |
| 1572 | * @cleaned_count: number of buffers to replace |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1573 | **/ |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1574 | 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] | 1575 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1576 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1577 | struct ixgbe_rx_buffer *bi; |
Alexander Duyck | d5f398e | 2010-11-16 19:26:48 -0800 | [diff] [blame] | 1578 | u16 i = rx_ring->next_to_use; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1579 | u16 bufsz; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1580 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1581 | /* nothing to do */ |
| 1582 | if (!cleaned_count) |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 1583 | return; |
| 1584 | |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1585 | rx_desc = IXGBE_RX_DESC(rx_ring, i); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1586 | bi = &rx_ring->rx_buffer_info[i]; |
| 1587 | i -= rx_ring->count; |
| 1588 | |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1589 | bufsz = ixgbe_rx_bufsz(rx_ring); |
| 1590 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1591 | do { |
| 1592 | if (!ixgbe_alloc_mapped_page(rx_ring, bi)) |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1593 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1594 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1595 | /* sync the buffer for use by the device */ |
| 1596 | dma_sync_single_range_for_device(rx_ring->dev, bi->dma, |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 1597 | bi->page_offset, bufsz, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1598 | DMA_FROM_DEVICE); |
| 1599 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1600 | /* |
| 1601 | * Refresh the desc even if buffer_addrs didn't change |
| 1602 | * because each write-back erases this info. |
| 1603 | */ |
| 1604 | 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] | 1605 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1606 | rx_desc++; |
| 1607 | bi++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1608 | i++; |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1609 | if (unlikely(!i)) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 1610 | rx_desc = IXGBE_RX_DESC(rx_ring, 0); |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1611 | bi = rx_ring->rx_buffer_info; |
| 1612 | i -= rx_ring->count; |
| 1613 | } |
| 1614 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 1615 | /* clear the length for the next_to_use descriptor */ |
| 1616 | rx_desc->wb.upper.length = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1617 | |
| 1618 | cleaned_count--; |
| 1619 | } while (cleaned_count); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1620 | |
Alexander Duyck | f990b79 | 2012-01-31 02:59:34 +0000 | [diff] [blame] | 1621 | i += rx_ring->count; |
| 1622 | |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 1623 | if (rx_ring->next_to_use != i) { |
| 1624 | rx_ring->next_to_use = i; |
| 1625 | |
| 1626 | /* update next to alloc since we have filled the ring */ |
| 1627 | rx_ring->next_to_alloc = i; |
| 1628 | |
| 1629 | /* Force memory writes to complete before letting h/w |
| 1630 | * know there are new descriptors to fetch. (Only |
| 1631 | * applicable for weak-ordered memory model archs, |
| 1632 | * such as IA-64). |
| 1633 | */ |
| 1634 | wmb(); |
| 1635 | writel(i, rx_ring->tail); |
| 1636 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1639 | static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring, |
| 1640 | struct sk_buff *skb) |
| 1641 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1642 | u16 hdr_len = skb_headlen(skb); |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1643 | |
| 1644 | /* set gso_size to avoid messing up TCP MSS */ |
| 1645 | skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len), |
| 1646 | IXGBE_CB(skb)->append_cnt); |
Alexander Duyck | 96be80a | 2013-02-12 09:45:44 +0000 | [diff] [blame] | 1647 | skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; |
Alexander Duyck | 1d2024f | 2012-01-31 02:59:29 +0000 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring, |
| 1651 | struct sk_buff *skb) |
| 1652 | { |
| 1653 | /* if append_cnt is 0 then frame is not RSC */ |
| 1654 | if (!IXGBE_CB(skb)->append_cnt) |
| 1655 | return; |
| 1656 | |
| 1657 | rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt; |
| 1658 | rx_ring->rx_stats.rsc_flush++; |
| 1659 | |
| 1660 | ixgbe_set_rsc_gso_size(rx_ring, skb); |
| 1661 | |
| 1662 | /* gso_size is computed using append_cnt so always clear it last */ |
| 1663 | IXGBE_CB(skb)->append_cnt = 0; |
| 1664 | } |
| 1665 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1666 | /** |
| 1667 | * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor |
| 1668 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1669 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1670 | * @skb: pointer to current skb being populated |
| 1671 | * |
| 1672 | * This function checks the ring, descriptor, and packet information in |
| 1673 | * order to populate the hash, checksum, VLAN, timestamp, protocol, and |
| 1674 | * other fields within the skb. |
| 1675 | **/ |
| 1676 | static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring, |
| 1677 | union ixgbe_adv_rx_desc *rx_desc, |
| 1678 | struct sk_buff *skb) |
| 1679 | { |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1680 | struct net_device *dev = rx_ring->netdev; |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1681 | u32 flags = rx_ring->q_vector->adapter->flags; |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1682 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1683 | ixgbe_update_rsc_stats(rx_ring, skb); |
| 1684 | |
| 1685 | ixgbe_rx_hash(rx_ring, rx_desc, skb); |
| 1686 | |
| 1687 | ixgbe_rx_checksum(rx_ring, rx_desc, skb); |
| 1688 | |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 1689 | if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED)) |
| 1690 | ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 1691 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1692 | if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) && |
John Fastabend | 43e95f1 | 2012-05-15 06:12:17 +0000 | [diff] [blame] | 1693 | ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1694 | u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1695 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1696 | } |
| 1697 | |
Shannon Nelson | 9210319 | 2017-12-19 15:59:59 -0800 | [diff] [blame] | 1698 | if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP)) |
| 1699 | ixgbe_ipsec_rx(rx_ring, rx_desc, skb); |
| 1700 | |
Alexander Duyck | 58918df | 2017-11-22 10:57:17 -0800 | [diff] [blame] | 1701 | /* record Rx queue, or update MACVLAN statistics */ |
| 1702 | if (netif_is_ixgbe(dev)) |
| 1703 | skb_record_rx_queue(skb, rx_ring->queue_index); |
| 1704 | else |
| 1705 | macvlan_count_rx(netdev_priv(dev), skb->len + ETH_HLEN, true, |
Alexander Duyck | 8d80ac4 | 2018-04-03 17:16:14 -0400 | [diff] [blame] | 1706 | false); |
| 1707 | |
| 1708 | skb->protocol = eth_type_trans(skb, dev); |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector, |
| 1712 | struct sk_buff *skb) |
| 1713 | { |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 1714 | napi_gro_receive(&q_vector->napi, skb); |
Alexander Duyck | aa80175 | 2010-11-16 19:27:02 -0800 | [diff] [blame] | 1715 | } |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 1716 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1717 | /** |
| 1718 | * ixgbe_is_non_eop - process handling of non-EOP buffers |
| 1719 | * @rx_ring: Rx ring being processed |
| 1720 | * @rx_desc: Rx descriptor for current buffer |
| 1721 | * @skb: Current socket buffer containing buffer in progress |
| 1722 | * |
| 1723 | * This function updates next to clean. If the buffer is an EOP buffer |
| 1724 | * this function exits returning false, otherwise it will place the |
| 1725 | * sk_buff in the next buffer to be chained and return true indicating |
| 1726 | * that this is in fact a non-EOP buffer. |
| 1727 | **/ |
| 1728 | static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring, |
| 1729 | union ixgbe_adv_rx_desc *rx_desc, |
| 1730 | struct sk_buff *skb) |
| 1731 | { |
| 1732 | u32 ntc = rx_ring->next_to_clean + 1; |
| 1733 | |
| 1734 | /* fetch, update, and store next to clean */ |
| 1735 | ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 1736 | rx_ring->next_to_clean = ntc; |
| 1737 | |
| 1738 | prefetch(IXGBE_RX_DESC(rx_ring, ntc)); |
| 1739 | |
Alexander Duyck | 5a02cbd | 2012-07-20 08:08:51 +0000 | [diff] [blame] | 1740 | /* update RSC append count if present */ |
| 1741 | if (ring_is_rsc_enabled(rx_ring)) { |
| 1742 | __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data & |
| 1743 | cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK); |
| 1744 | |
| 1745 | if (unlikely(rsc_enabled)) { |
| 1746 | u32 rsc_cnt = le32_to_cpu(rsc_enabled); |
| 1747 | |
| 1748 | rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT; |
| 1749 | IXGBE_CB(skb)->append_cnt += rsc_cnt - 1; |
| 1750 | |
| 1751 | /* update ntc based on RSC value */ |
| 1752 | ntc = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 1753 | ntc &= IXGBE_RXDADV_NEXTP_MASK; |
| 1754 | ntc >>= IXGBE_RXDADV_NEXTP_SHIFT; |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | /* 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] | 1759 | if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 1760 | return false; |
| 1761 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1762 | /* place skb in next buffer to be received */ |
| 1763 | rx_ring->rx_buffer_info[ntc].skb = skb; |
| 1764 | rx_ring->rx_stats.non_eop_descs++; |
| 1765 | |
| 1766 | return true; |
| 1767 | } |
| 1768 | |
| 1769 | /** |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1770 | * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail |
| 1771 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1772 | * @skb: pointer to current skb being adjusted |
| 1773 | * |
| 1774 | * This function is an ixgbe specific version of __pskb_pull_tail. The |
| 1775 | * main difference between this version and the original function is that |
| 1776 | * this function can make several assumptions about the state of things |
| 1777 | * that allow for significant optimizations versus the standard function. |
| 1778 | * As a result we can do things like drop a frag and maintain an accurate |
| 1779 | * truesize for the skb. |
| 1780 | */ |
| 1781 | static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring, |
| 1782 | struct sk_buff *skb) |
| 1783 | { |
| 1784 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1785 | unsigned char *va; |
| 1786 | unsigned int pull_len; |
| 1787 | |
| 1788 | /* |
| 1789 | * it is valid to use page_address instead of kmap since we are |
| 1790 | * working with pages allocated out of the lomem pool per |
| 1791 | * alloc_page(GFP_ATOMIC) |
| 1792 | */ |
| 1793 | va = skb_frag_address(frag); |
| 1794 | |
| 1795 | /* |
| 1796 | * we need the header to contain the greater of either ETH_HLEN or |
| 1797 | * 60 bytes if the skb->len is less than 60 for skb_pad. |
| 1798 | */ |
Alexander Duyck | 8496e338 | 2014-09-05 19:22:18 -0400 | [diff] [blame] | 1799 | pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE); |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1800 | |
| 1801 | /* align pull length to size of long to optimize memcpy performance */ |
| 1802 | skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long))); |
| 1803 | |
| 1804 | /* update all of the pointers */ |
| 1805 | skb_frag_size_sub(frag, pull_len); |
| 1806 | frag->page_offset += pull_len; |
| 1807 | skb->data_len -= pull_len; |
| 1808 | skb->tail += pull_len; |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | /** |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1812 | * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB |
| 1813 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1814 | * @skb: pointer to current skb being updated |
| 1815 | * |
| 1816 | * This function provides a basic DMA sync up for the first fragment of an |
| 1817 | * skb. The reason for doing this is that the first fragment cannot be |
| 1818 | * unmapped until we have reached the end of packet descriptor for a buffer |
| 1819 | * chain. |
| 1820 | */ |
| 1821 | static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring, |
| 1822 | struct sk_buff *skb) |
| 1823 | { |
| 1824 | /* if the page was released unmap it, else just sync our portion */ |
| 1825 | if (unlikely(IXGBE_CB(skb)->page_released)) { |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 1826 | dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma, |
| 1827 | ixgbe_rx_pg_size(rx_ring), |
| 1828 | DMA_FROM_DEVICE, |
| 1829 | IXGBE_RX_DMA_ATTR); |
Emil Tantilov | 0c5661e | 2018-02-23 12:39:41 -0800 | [diff] [blame] | 1830 | } else if (ring_uses_build_skb(rx_ring)) { |
| 1831 | unsigned long offset = (unsigned long)(skb->data) & ~PAGE_MASK; |
| 1832 | |
| 1833 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1834 | IXGBE_CB(skb)->dma, |
| 1835 | offset, |
| 1836 | skb_headlen(skb), |
| 1837 | DMA_FROM_DEVICE); |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1838 | } else { |
| 1839 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; |
| 1840 | |
| 1841 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 1842 | IXGBE_CB(skb)->dma, |
| 1843 | frag->page_offset, |
Alexander Duyck | f215af8 | 2017-01-17 08:35:44 -0800 | [diff] [blame] | 1844 | skb_frag_size(frag), |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1845 | DMA_FROM_DEVICE); |
| 1846 | } |
Alexander Duyck | 42073d9 | 2012-07-20 08:08:28 +0000 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1850 | * ixgbe_cleanup_headers - Correct corrupted or empty headers |
| 1851 | * @rx_ring: rx descriptor ring packet is being transacted on |
| 1852 | * @rx_desc: pointer to the EOP Rx descriptor |
| 1853 | * @skb: pointer to current skb being fixed |
| 1854 | * |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 1855 | * Check if the skb is valid in the XDP case it will be an error pointer. |
| 1856 | * Return true in this case to abort processing and advance to next |
| 1857 | * descriptor. |
| 1858 | * |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1859 | * Check for corrupted packet headers caused by senders on the local L2 |
| 1860 | * embedded NIC switch not setting up their Tx Descriptors right. These |
| 1861 | * should be very rare. |
| 1862 | * |
| 1863 | * Also address the case where we are pulling data in on pages only |
| 1864 | * and as such no data is present in the skb header. |
| 1865 | * |
| 1866 | * In addition if skb is not at least 60 bytes we need to pad it so that |
| 1867 | * it is large enough to qualify as a valid Ethernet frame. |
| 1868 | * |
| 1869 | * Returns true if an error was encountered and skb was freed. |
| 1870 | **/ |
| 1871 | static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring, |
| 1872 | union ixgbe_adv_rx_desc *rx_desc, |
| 1873 | struct sk_buff *skb) |
| 1874 | { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1875 | struct net_device *netdev = rx_ring->netdev; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1876 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 1877 | /* XDP packets use error pointer so abort at this point */ |
| 1878 | if (IS_ERR(skb)) |
| 1879 | return true; |
| 1880 | |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 1881 | /* Verify netdev is present, and that packet does not have any |
| 1882 | * errors that would be unacceptable to the netdev. |
| 1883 | */ |
| 1884 | if (!netdev || |
| 1885 | (unlikely(ixgbe_test_staterr(rx_desc, |
| 1886 | IXGBE_RXDADV_ERR_FRAME_ERR_MASK) && |
| 1887 | !(netdev->features & NETIF_F_RXALL)))) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1888 | dev_kfree_skb_any(skb); |
| 1889 | return true; |
| 1890 | } |
| 1891 | |
Alexander Duyck | 19861ce | 2012-07-20 08:08:33 +0000 | [diff] [blame] | 1892 | /* place header in linear portion of buffer */ |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 1893 | if (!skb_headlen(skb)) |
Alexander Duyck | cf3fe7a | 2012-07-20 08:08:39 +0000 | [diff] [blame] | 1894 | ixgbe_pull_tail(rx_ring, skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1895 | |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 1896 | #ifdef IXGBE_FCOE |
| 1897 | /* do not attempt to pad FCoE Frames as this will disrupt DDP */ |
| 1898 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) |
| 1899 | return false; |
| 1900 | |
| 1901 | #endif |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 1902 | /* if eth_skb_pad returns an error the skb was freed */ |
| 1903 | if (eth_skb_pad(skb)) |
| 1904 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1905 | |
| 1906 | return false; |
| 1907 | } |
| 1908 | |
| 1909 | /** |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1910 | * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring |
| 1911 | * @rx_ring: rx descriptor ring to store buffers on |
| 1912 | * @old_buff: donor buffer to have page reused |
| 1913 | * |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1914 | * Synchronizes page for reuse by the adapter |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1915 | **/ |
| 1916 | static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring, |
| 1917 | struct ixgbe_rx_buffer *old_buff) |
| 1918 | { |
| 1919 | struct ixgbe_rx_buffer *new_buff; |
| 1920 | u16 nta = rx_ring->next_to_alloc; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1921 | |
| 1922 | new_buff = &rx_ring->rx_buffer_info[nta]; |
| 1923 | |
| 1924 | /* update, and store next to alloc */ |
| 1925 | nta++; |
| 1926 | rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 1927 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1928 | /* Transfer page from old buffer to new buffer. |
| 1929 | * Move each member individually to avoid possible store |
| 1930 | * forwarding stalls and unnecessary copy of skb. |
| 1931 | */ |
| 1932 | new_buff->dma = old_buff->dma; |
| 1933 | new_buff->page = old_buff->page; |
| 1934 | new_buff->page_offset = old_buff->page_offset; |
| 1935 | new_buff->pagecnt_bias = old_buff->pagecnt_bias; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1938 | static inline bool ixgbe_page_is_reserved(struct page *page) |
| 1939 | { |
Michal Hocko | 2f064f3 | 2015-08-21 14:11:51 -0700 | [diff] [blame] | 1940 | return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1943 | static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1944 | { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1945 | unsigned int pagecnt_bias = rx_buffer->pagecnt_bias; |
| 1946 | struct page *page = rx_buffer->page; |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1947 | |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1948 | /* avoid re-using remote pages */ |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1949 | if (unlikely(ixgbe_page_is_reserved(page))) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1950 | return false; |
| 1951 | |
| 1952 | #if (PAGE_SIZE < 8192) |
| 1953 | /* if we are only owner of page we can reuse it */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1954 | if (unlikely((page_ref_count(page) - pagecnt_bias) > 1)) |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1955 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1956 | #else |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1957 | /* The last offset is a bit aggressive in that we assume the |
| 1958 | * worst case of FCoE being enabled and using a 3K buffer. |
| 1959 | * However this should have minimal impact as the 1K extra is |
| 1960 | * still less than one buffer in size. |
| 1961 | */ |
| 1962 | #define IXGBE_LAST_OFFSET \ |
| 1963 | (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K) |
| 1964 | if (rx_buffer->page_offset > IXGBE_LAST_OFFSET) |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1965 | return false; |
Alexander Duyck | 09816fb | 2012-07-20 08:08:23 +0000 | [diff] [blame] | 1966 | #endif |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1967 | |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1968 | /* If we have drained the page fragment pool we need to update |
| 1969 | * the pagecnt_bias and page count so that we fully restock the |
| 1970 | * number of references the driver holds. |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1971 | */ |
Björn Töpel | ed93a39 | 2018-03-22 10:02:36 +0100 | [diff] [blame] | 1972 | if (unlikely(pagecnt_bias == 1)) { |
| 1973 | page_ref_add(page, USHRT_MAX - 1); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 1974 | rx_buffer->pagecnt_bias = USHRT_MAX; |
| 1975 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 1976 | |
Alexander Duyck | 0549ae2 | 2012-07-20 08:08:18 +0000 | [diff] [blame] | 1977 | return true; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1980 | /** |
| 1981 | * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 1982 | * @rx_ring: rx descriptor ring to transact packets on |
| 1983 | * @rx_buffer: buffer containing page to add |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1984 | * @skb: sk_buff to place the data into |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 1985 | * @size: size of data in rx_buffer |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1986 | * |
| 1987 | * This function will add the data contained in rx_buffer->page to the skb. |
| 1988 | * This is done either through a direct copy if the data in the buffer is |
| 1989 | * less than the skb header size, otherwise it will just attach the page as |
| 1990 | * a frag to the skb. |
| 1991 | * |
| 1992 | * The function will then update the page offset if necessary and return |
| 1993 | * true if the buffer can be reused by the adapter. |
| 1994 | **/ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1995 | static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1996 | struct ixgbe_rx_buffer *rx_buffer, |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 1997 | struct sk_buff *skb, |
| 1998 | unsigned int size) |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 1999 | { |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2000 | #if (PAGE_SIZE < 8192) |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 2001 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2002 | #else |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 2003 | unsigned int truesize = ring_uses_build_skb(rx_ring) ? |
| 2004 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) : |
| 2005 | SKB_DATA_ALIGN(size); |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2006 | #endif |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2007 | skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2008 | rx_buffer->page_offset, size, truesize); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2009 | #if (PAGE_SIZE < 8192) |
| 2010 | rx_buffer->page_offset ^= truesize; |
| 2011 | #else |
| 2012 | rx_buffer->page_offset += truesize; |
| 2013 | #endif |
Alexander Duyck | af43da0 | 2017-01-17 08:35:34 -0800 | [diff] [blame] | 2014 | } |
| 2015 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2016 | static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2017 | union ixgbe_adv_rx_desc *rx_desc, |
| 2018 | struct sk_buff **skb, |
| 2019 | const unsigned int size) |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2020 | { |
| 2021 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2022 | |
| 2023 | rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2024 | prefetchw(rx_buffer->page); |
| 2025 | *skb = rx_buffer->skb; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2026 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2027 | /* Delay unmapping of the first packet. It carries the header |
| 2028 | * information, HW may still access the header after the writeback. |
| 2029 | * Only unmap it when EOP is reached |
| 2030 | */ |
| 2031 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) { |
| 2032 | if (!*skb) |
| 2033 | goto skip_sync; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2034 | } else { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2035 | if (*skb) |
| 2036 | ixgbe_dma_sync_frag(rx_ring, *skb); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2037 | } |
| 2038 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2039 | /* we are reusing so sync this buffer for CPU use */ |
| 2040 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2041 | rx_buffer->dma, |
| 2042 | rx_buffer->page_offset, |
| 2043 | size, |
| 2044 | DMA_FROM_DEVICE); |
| 2045 | skip_sync: |
| 2046 | rx_buffer->pagecnt_bias--; |
| 2047 | |
| 2048 | return rx_buffer; |
| 2049 | } |
| 2050 | |
| 2051 | static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring, |
| 2052 | struct ixgbe_rx_buffer *rx_buffer, |
| 2053 | struct sk_buff *skb) |
| 2054 | { |
| 2055 | if (ixgbe_can_reuse_rx_page(rx_buffer)) { |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2056 | /* hand second half of page back to the ring */ |
| 2057 | ixgbe_reuse_rx_page(rx_ring, rx_buffer); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2058 | } else { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2059 | if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) { |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2060 | /* the page has been released from the ring */ |
| 2061 | IXGBE_CB(skb)->page_released = true; |
| 2062 | } else { |
| 2063 | /* we are not reusing the buffer so unmap it */ |
| 2064 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
| 2065 | ixgbe_rx_pg_size(rx_ring), |
| 2066 | DMA_FROM_DEVICE, |
| 2067 | IXGBE_RX_DMA_ATTR); |
| 2068 | } |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2069 | __page_frag_cache_drain(rx_buffer->page, |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 2070 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2071 | } |
| 2072 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2073 | /* clear contents of rx_buffer */ |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2074 | rx_buffer->page = NULL; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2075 | rx_buffer->skb = NULL; |
| 2076 | } |
| 2077 | |
| 2078 | static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring, |
| 2079 | struct ixgbe_rx_buffer *rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2080 | struct xdp_buff *xdp, |
| 2081 | union ixgbe_adv_rx_desc *rx_desc) |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2082 | { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2083 | unsigned int size = xdp->data_end - xdp->data; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2084 | #if (PAGE_SIZE < 8192) |
| 2085 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2086 | #else |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2087 | unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end - |
| 2088 | xdp->data_hard_start); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2089 | #endif |
| 2090 | struct sk_buff *skb; |
| 2091 | |
| 2092 | /* prefetch first cache line of first page */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2093 | prefetch(xdp->data); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2094 | #if L1_CACHE_BYTES < 128 |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2095 | prefetch(xdp->data + L1_CACHE_BYTES); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2096 | #endif |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2097 | /* Note, we get here by enabling legacy-rx via: |
| 2098 | * |
| 2099 | * ethtool --set-priv-flags <dev> legacy-rx on |
| 2100 | * |
| 2101 | * In this mode, we currently get 0 extra XDP headroom as |
| 2102 | * opposed to having legacy-rx off, where we process XDP |
| 2103 | * packets going to stack via ixgbe_build_skb(). The latter |
| 2104 | * provides us currently with 192 bytes of headroom. |
| 2105 | * |
| 2106 | * For ixgbe_construct_skb() mode it means that the |
| 2107 | * xdp->data_meta will always point to xdp->data, since |
| 2108 | * the helper cannot expand the head. Should this ever |
| 2109 | * change in future for legacy-rx mode on, then lets also |
| 2110 | * add xdp->data_meta handling here. |
| 2111 | */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2112 | |
| 2113 | /* allocate a skb to store the frags */ |
| 2114 | skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE); |
| 2115 | if (unlikely(!skb)) |
| 2116 | return NULL; |
| 2117 | |
| 2118 | if (size > IXGBE_RX_HDR_SIZE) { |
| 2119 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2120 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2121 | |
| 2122 | skb_add_rx_frag(skb, 0, rx_buffer->page, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2123 | xdp->data - page_address(rx_buffer->page), |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2124 | size, truesize); |
| 2125 | #if (PAGE_SIZE < 8192) |
| 2126 | rx_buffer->page_offset ^= truesize; |
| 2127 | #else |
| 2128 | rx_buffer->page_offset += truesize; |
| 2129 | #endif |
| 2130 | } else { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2131 | memcpy(__skb_put(skb, size), |
| 2132 | xdp->data, ALIGN(size, sizeof(long))); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2133 | rx_buffer->pagecnt_bias++; |
| 2134 | } |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2135 | |
| 2136 | return skb; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2139 | static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring, |
| 2140 | struct ixgbe_rx_buffer *rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2141 | struct xdp_buff *xdp, |
| 2142 | union ixgbe_adv_rx_desc *rx_desc) |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2143 | { |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2144 | unsigned int metasize = xdp->data - xdp->data_meta; |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2145 | #if (PAGE_SIZE < 8192) |
| 2146 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2147 | #else |
| 2148 | unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2149 | SKB_DATA_ALIGN(xdp->data_end - |
| 2150 | xdp->data_hard_start); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2151 | #endif |
| 2152 | struct sk_buff *skb; |
| 2153 | |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2154 | /* Prefetch first cache line of first page. If xdp->data_meta |
| 2155 | * is unused, this points extactly as xdp->data, otherwise we |
| 2156 | * likely have a consumer accessing first few bytes of meta |
| 2157 | * data, and then actual data. |
| 2158 | */ |
| 2159 | prefetch(xdp->data_meta); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2160 | #if L1_CACHE_BYTES < 128 |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2161 | prefetch(xdp->data_meta + L1_CACHE_BYTES); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2162 | #endif |
| 2163 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2164 | /* build an skb to around the page buffer */ |
| 2165 | skb = build_skb(xdp->data_hard_start, truesize); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2166 | if (unlikely(!skb)) |
| 2167 | return NULL; |
| 2168 | |
| 2169 | /* update pointers within the skb to store the data */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2170 | skb_reserve(skb, xdp->data - xdp->data_hard_start); |
| 2171 | __skb_put(skb, xdp->data_end - xdp->data); |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2172 | if (metasize) |
| 2173 | skb_metadata_set(skb, metasize); |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2174 | |
| 2175 | /* record DMA address if this is the start of a chain of buffers */ |
| 2176 | if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) |
| 2177 | IXGBE_CB(skb)->dma = rx_buffer->dma; |
| 2178 | |
| 2179 | /* update buffer offset */ |
| 2180 | #if (PAGE_SIZE < 8192) |
| 2181 | rx_buffer->page_offset ^= truesize; |
| 2182 | #else |
| 2183 | rx_buffer->page_offset += truesize; |
| 2184 | #endif |
| 2185 | |
| 2186 | return skb; |
| 2187 | } |
| 2188 | |
Jesper Dangaard Brouer | ad088ec | 2018-06-26 17:39:48 +0200 | [diff] [blame] | 2189 | #define IXGBE_XDP_PASS 0 |
| 2190 | #define IXGBE_XDP_CONSUMED BIT(0) |
| 2191 | #define IXGBE_XDP_TX BIT(1) |
| 2192 | #define IXGBE_XDP_REDIR BIT(2) |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2193 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2194 | static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter, |
Jesper Dangaard Brouer | 44fa2db | 2018-04-17 16:46:37 +0200 | [diff] [blame] | 2195 | struct xdp_frame *xdpf); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2196 | |
| 2197 | static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter, |
| 2198 | struct ixgbe_ring *rx_ring, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2199 | struct xdp_buff *xdp) |
| 2200 | { |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 2201 | int err, result = IXGBE_XDP_PASS; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2202 | struct bpf_prog *xdp_prog; |
Jesper Dangaard Brouer | 44fa2db | 2018-04-17 16:46:37 +0200 | [diff] [blame] | 2203 | struct xdp_frame *xdpf; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2204 | u32 act; |
| 2205 | |
| 2206 | rcu_read_lock(); |
| 2207 | xdp_prog = READ_ONCE(rx_ring->xdp_prog); |
| 2208 | |
| 2209 | if (!xdp_prog) |
| 2210 | goto xdp_out; |
| 2211 | |
Jesper Dangaard Brouer | 44fa2db | 2018-04-17 16:46:37 +0200 | [diff] [blame] | 2212 | prefetchw(xdp->data_hard_start); /* xdp_frame write */ |
| 2213 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2214 | act = bpf_prog_run_xdp(xdp_prog, xdp); |
| 2215 | switch (act) { |
| 2216 | case XDP_PASS: |
| 2217 | break; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2218 | case XDP_TX: |
Jesper Dangaard Brouer | 44fa2db | 2018-04-17 16:46:37 +0200 | [diff] [blame] | 2219 | xdpf = convert_to_xdp_frame(xdp); |
| 2220 | if (unlikely(!xdpf)) { |
| 2221 | result = IXGBE_XDP_CONSUMED; |
| 2222 | break; |
| 2223 | } |
| 2224 | result = ixgbe_xmit_xdp_ring(adapter, xdpf); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2225 | break; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 2226 | case XDP_REDIRECT: |
John Fastabend | 5acaee0 | 2017-07-17 09:28:35 -0700 | [diff] [blame] | 2227 | err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog); |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 2228 | if (!err) |
Jesper Dangaard Brouer | ad088ec | 2018-06-26 17:39:48 +0200 | [diff] [blame] | 2229 | result = IXGBE_XDP_REDIR; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 2230 | else |
| 2231 | result = IXGBE_XDP_CONSUMED; |
| 2232 | break; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2233 | default: |
| 2234 | bpf_warn_invalid_xdp_action(act); |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 2235 | /* fallthrough */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2236 | case XDP_ABORTED: |
| 2237 | trace_xdp_exception(rx_ring->netdev, xdp_prog, act); |
| 2238 | /* fallthrough -- handle aborts by dropping packet */ |
| 2239 | case XDP_DROP: |
| 2240 | result = IXGBE_XDP_CONSUMED; |
| 2241 | break; |
| 2242 | } |
| 2243 | xdp_out: |
| 2244 | rcu_read_unlock(); |
| 2245 | return ERR_PTR(-result); |
| 2246 | } |
| 2247 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2248 | static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring, |
| 2249 | struct ixgbe_rx_buffer *rx_buffer, |
| 2250 | unsigned int size) |
| 2251 | { |
| 2252 | #if (PAGE_SIZE < 8192) |
| 2253 | unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2; |
| 2254 | |
| 2255 | rx_buffer->page_offset ^= truesize; |
| 2256 | #else |
| 2257 | unsigned int truesize = ring_uses_build_skb(rx_ring) ? |
| 2258 | SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) : |
| 2259 | SKB_DATA_ALIGN(size); |
| 2260 | |
| 2261 | rx_buffer->page_offset += truesize; |
| 2262 | #endif |
| 2263 | } |
| 2264 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2265 | /** |
| 2266 | * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf |
| 2267 | * @q_vector: structure containing interrupt and ring information |
| 2268 | * @rx_ring: rx descriptor ring to transact packets on |
| 2269 | * @budget: Total limit on number of packets to process |
| 2270 | * |
| 2271 | * This function provides a "bounce buffer" approach to Rx interrupt |
| 2272 | * processing. The advantage to this is that on systems that have |
| 2273 | * expensive overhead for IOMMU access this provides a means of avoiding |
| 2274 | * it by maintaining the mapping of the page to the syste. |
| 2275 | * |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2276 | * Returns amount of work completed |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2277 | **/ |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2278 | static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2279 | struct ixgbe_ring *rx_ring, |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2280 | const int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2281 | { |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2282 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2283 | struct ixgbe_adapter *adapter = q_vector->adapter; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2284 | #ifdef IXGBE_FCOE |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2285 | int ddp_bytes; |
| 2286 | unsigned int mss = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2287 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2288 | u16 cleaned_count = ixgbe_desc_unused(rx_ring); |
Jesper Dangaard Brouer | ad088ec | 2018-06-26 17:39:48 +0200 | [diff] [blame] | 2289 | unsigned int xdp_xmit = 0; |
Jesper Dangaard Brouer | 99ffc5a | 2018-01-03 11:25:29 +0100 | [diff] [blame] | 2290 | struct xdp_buff xdp; |
| 2291 | |
| 2292 | xdp.rxq = &rx_ring->xdp_rxq; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2293 | |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2294 | while (likely(total_rx_packets < budget)) { |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2295 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2296 | struct ixgbe_rx_buffer *rx_buffer; |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2297 | struct sk_buff *skb; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2298 | unsigned int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2299 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2300 | /* return some buffers to hardware, one at a time is too slow */ |
| 2301 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 2302 | ixgbe_alloc_rx_buffers(rx_ring, cleaned_count); |
| 2303 | cleaned_count = 0; |
| 2304 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2305 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2306 | rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean); |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2307 | size = le16_to_cpu(rx_desc->wb.upper.length); |
| 2308 | if (!size) |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2309 | break; |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2310 | |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2311 | /* This memory barrier is needed to keep us from reading |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2312 | * any other fields out of the rx_desc until we know the |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2313 | * descriptor has been written back |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2314 | */ |
Alexander Duyck | 124b74c | 2014-12-11 15:02:28 -0800 | [diff] [blame] | 2315 | dma_rmb(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2316 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2317 | rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size); |
| 2318 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2319 | /* retrieve a buffer from the ring */ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2320 | if (!skb) { |
| 2321 | xdp.data = page_address(rx_buffer->page) + |
| 2322 | rx_buffer->page_offset; |
Daniel Borkmann | 366a88f | 2017-09-25 02:25:55 +0200 | [diff] [blame] | 2323 | xdp.data_meta = xdp.data; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2324 | xdp.data_hard_start = xdp.data - |
| 2325 | ixgbe_rx_offset(rx_ring); |
| 2326 | xdp.data_end = xdp.data + size; |
| 2327 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2328 | skb = ixgbe_run_xdp(adapter, rx_ring, &xdp); |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | if (IS_ERR(skb)) { |
Jesper Dangaard Brouer | ad088ec | 2018-06-26 17:39:48 +0200 | [diff] [blame] | 2332 | unsigned int xdp_res = -PTR_ERR(skb); |
| 2333 | |
| 2334 | if (xdp_res & (IXGBE_XDP_TX | IXGBE_XDP_REDIR)) { |
| 2335 | xdp_xmit |= xdp_res; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2336 | ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size); |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2337 | } else { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 2338 | rx_buffer->pagecnt_bias++; |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2339 | } |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2340 | total_rx_packets++; |
| 2341 | total_rx_bytes += size; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2342 | } else if (skb) { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2343 | ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size); |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2344 | } else if (ring_uses_build_skb(rx_ring)) { |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 2345 | skb = ixgbe_build_skb(rx_ring, rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2346 | &xdp, rx_desc); |
| 2347 | } else { |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2348 | skb = ixgbe_construct_skb(rx_ring, rx_buffer, |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 2349 | &xdp, rx_desc); |
| 2350 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2351 | |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2352 | /* exit if we failed to retrieve a buffer */ |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2353 | if (!skb) { |
| 2354 | rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 2355 | rx_buffer->pagecnt_bias++; |
Alexander Duyck | 18806c9 | 2012-07-20 08:08:44 +0000 | [diff] [blame] | 2356 | break; |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2357 | } |
Alexander Duyck | 4c1975d | 2012-01-31 02:59:23 +0000 | [diff] [blame] | 2358 | |
Alexander Duyck | 3fd21876 | 2017-01-17 08:36:45 -0800 | [diff] [blame] | 2359 | ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2360 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2361 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2362 | /* place incomplete frames back on ring for completion */ |
| 2363 | if (ixgbe_is_non_eop(rx_ring, rx_desc, skb)) |
| 2364 | continue; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2365 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2366 | /* verify the packet layout is correct */ |
| 2367 | if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb)) |
| 2368 | continue; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2369 | |
| 2370 | /* probably a little skewed due to removing CRC */ |
| 2371 | total_rx_bytes += skb->len; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 2372 | |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2373 | /* populate checksum, timestamp, VLAN, and protocol */ |
| 2374 | ixgbe_process_skb_fields(rx_ring, rx_desc, skb); |
| 2375 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2376 | #ifdef IXGBE_FCOE |
| 2377 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Alexander Duyck | 57efd44 | 2012-06-25 21:54:46 +0000 | [diff] [blame] | 2378 | if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) { |
Alexander Duyck | f56e0cb | 2012-01-31 02:59:39 +0000 | [diff] [blame] | 2379 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
Mark Rustad | 4ffdf91 | 2012-07-18 06:05:50 +0000 | [diff] [blame] | 2380 | /* include DDPed FCoE data */ |
| 2381 | if (ddp_bytes > 0) { |
| 2382 | if (!mss) { |
| 2383 | mss = rx_ring->netdev->mtu - |
| 2384 | sizeof(struct fcoe_hdr) - |
| 2385 | sizeof(struct fc_frame_header) - |
| 2386 | sizeof(struct fcoe_crc_eof); |
| 2387 | if (mss > 512) |
| 2388 | mss &= ~511; |
| 2389 | } |
| 2390 | total_rx_bytes += ddp_bytes; |
| 2391 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, |
| 2392 | mss); |
| 2393 | } |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2394 | if (!ddp_bytes) { |
| 2395 | dev_kfree_skb_any(skb); |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2396 | continue; |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 2397 | } |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 2398 | } |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2399 | |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 2400 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 2401 | ixgbe_rx_skb(q_vector, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2402 | |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 2403 | /* update budget accounting */ |
Alexander Duyck | f4de00e | 2012-09-25 00:29:37 +0000 | [diff] [blame] | 2404 | total_rx_packets++; |
Eric W. Biederman | fdabfc8a | 2014-03-14 18:00:41 -0700 | [diff] [blame] | 2405 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2406 | |
Jesper Dangaard Brouer | ad088ec | 2018-06-26 17:39:48 +0200 | [diff] [blame] | 2407 | if (xdp_xmit & IXGBE_XDP_REDIR) |
| 2408 | xdp_do_flush_map(); |
| 2409 | |
| 2410 | if (xdp_xmit & IXGBE_XDP_TX) { |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 2411 | struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()]; |
| 2412 | |
| 2413 | /* Force memory writes to complete before letting h/w |
| 2414 | * know there are new descriptors to fetch. |
| 2415 | */ |
| 2416 | wmb(); |
| 2417 | writel(ring->next_to_use, ring->tail); |
| 2418 | } |
| 2419 | |
Alexander Duyck | c267fc1 | 2010-11-16 19:27:00 -0800 | [diff] [blame] | 2420 | u64_stats_update_begin(&rx_ring->syncp); |
| 2421 | rx_ring->stats.packets += total_rx_packets; |
| 2422 | rx_ring->stats.bytes += total_rx_bytes; |
| 2423 | u64_stats_update_end(&rx_ring->syncp); |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2424 | q_vector->rx.total_packets += total_rx_packets; |
| 2425 | q_vector->rx.total_bytes += total_rx_bytes; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 2426 | |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 2427 | return total_rx_packets; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2430 | /** |
| 2431 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 2432 | * @adapter: board private structure |
| 2433 | * |
| 2434 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 2435 | * interrupts. |
| 2436 | **/ |
| 2437 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 2438 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2439 | struct ixgbe_q_vector *q_vector; |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2440 | int v_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2441 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2442 | |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2443 | /* Populate MSIX to EITR Select */ |
| 2444 | if (adapter->num_vfs > 32) { |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 2445 | u32 eitrsel = BIT(adapter->num_vfs - 32) - 1; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 2446 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 2447 | } |
| 2448 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 2449 | /* |
| 2450 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2451 | * corresponding register. |
| 2452 | */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 2453 | for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2454 | struct ixgbe_ring *ring; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2455 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2456 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2457 | ixgbe_for_each_ring(ring, q_vector->rx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2458 | ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2459 | |
Alexander Duyck | a557928 | 2012-02-08 07:50:04 +0000 | [diff] [blame] | 2460 | ixgbe_for_each_ring(ring, q_vector->tx) |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 2461 | ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2462 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2463 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2466 | switch (adapter->hw.mac.type) { |
| 2467 | case ixgbe_mac_82598EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2468 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2469 | v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2470 | break; |
| 2471 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2472 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2473 | case ixgbe_mac_X550: |
| 2474 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2475 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2476 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2477 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2478 | default: |
| 2479 | break; |
| 2480 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2481 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2482 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 2483 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2484 | mask = IXGBE_EIMS_ENABLE_MASK; |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2485 | mask &= ~(IXGBE_EIMS_OTHER | |
| 2486 | IXGBE_EIMS_MAILBOX | |
| 2487 | IXGBE_EIMS_LSC); |
| 2488 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2489 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2490 | } |
| 2491 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2492 | /** |
| 2493 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2494 | * @q_vector: structure containing interrupt and ring information |
| 2495 | * @ring_container: structure containing ring performance data |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2496 | * |
| 2497 | * Stores a new ITR value based on packets and byte |
| 2498 | * counts during the last interrupt. The advantage of per interrupt |
| 2499 | * computation is faster updates and more accurate ITR for the current |
| 2500 | * traffic pattern. Constants in this function were computed |
| 2501 | * based on theoretical maximum wire speed and thresholds were set based |
| 2502 | * on testing data as well as attempting to minimize response time |
| 2503 | * while increasing bulk throughput. |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2504 | **/ |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2505 | static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector, |
| 2506 | struct ixgbe_ring_container *ring_container) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2507 | { |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2508 | unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS | |
| 2509 | IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2510 | unsigned int avg_wire_size, packets, bytes; |
| 2511 | unsigned long next_update = jiffies; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2512 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2513 | /* If we don't have any rings just leave ourselves set for maximum |
| 2514 | * possible latency so we take ourselves out of the equation. |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2515 | */ |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2516 | if (!ring_container->ring) |
Don Skidmore | bdbeefe | 2013-03-02 07:17:37 +0000 | [diff] [blame] | 2517 | return; |
| 2518 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2519 | /* If we didn't update within up to 1 - 2 jiffies we can assume |
| 2520 | * that either packets are coming in so slow there hasn't been |
| 2521 | * any work, or that there is so much work that NAPI is dealing |
| 2522 | * with interrupt moderation and we don't need to do anything. |
| 2523 | */ |
| 2524 | if (time_after(next_update, ring_container->next_update)) |
| 2525 | goto clear_counts; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2526 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2527 | packets = ring_container->total_packets; |
| 2528 | |
| 2529 | /* We have no packets to actually measure against. This means |
| 2530 | * either one of the other queues on this vector is active or |
| 2531 | * we are a Tx queue doing TSO with too high of an interrupt rate. |
| 2532 | * |
| 2533 | * When this occurs just tick up our delay by the minimum value |
| 2534 | * and hope that this extra delay will prevent us from being called |
| 2535 | * without any work on our queue. |
| 2536 | */ |
| 2537 | if (!packets) { |
| 2538 | itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC; |
| 2539 | if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS) |
| 2540 | itr = IXGBE_ITR_ADAPTIVE_MAX_USECS; |
| 2541 | itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2542 | goto clear_counts; |
| 2543 | } |
| 2544 | |
| 2545 | bytes = ring_container->total_bytes; |
| 2546 | |
| 2547 | /* If packets are less than 4 or bytes are less than 9000 assume |
| 2548 | * insufficient data to use bulk rate limiting approach. We are |
| 2549 | * likely latency driven. |
| 2550 | */ |
| 2551 | if (packets < 4 && bytes < 9000) { |
| 2552 | itr = IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2553 | goto adjust_by_size; |
| 2554 | } |
| 2555 | |
| 2556 | /* Between 4 and 48 we can assume that our current interrupt delay |
| 2557 | * is only slightly too low. As such we should increase it by a small |
| 2558 | * fixed amount. |
| 2559 | */ |
| 2560 | if (packets < 48) { |
| 2561 | itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC; |
| 2562 | if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS) |
| 2563 | itr = IXGBE_ITR_ADAPTIVE_MAX_USECS; |
| 2564 | goto clear_counts; |
| 2565 | } |
| 2566 | |
| 2567 | /* Between 48 and 96 is our "goldilocks" zone where we are working |
| 2568 | * out "just right". Just report that our current ITR is good for us. |
| 2569 | */ |
| 2570 | if (packets < 96) { |
| 2571 | itr = q_vector->itr >> 2; |
| 2572 | goto clear_counts; |
| 2573 | } |
| 2574 | |
| 2575 | /* If packet count is 96 or greater we are likely looking at a slight |
| 2576 | * overrun of the delay we want. Try halving our delay to see if that |
| 2577 | * will cut the number of packets in half per interrupt. |
| 2578 | */ |
| 2579 | if (packets < 256) { |
| 2580 | itr = q_vector->itr >> 3; |
| 2581 | if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS) |
| 2582 | itr = IXGBE_ITR_ADAPTIVE_MIN_USECS; |
| 2583 | goto clear_counts; |
| 2584 | } |
| 2585 | |
| 2586 | /* The paths below assume we are dealing with a bulk ITR since number |
| 2587 | * of packets is 256 or greater. We are just going to have to compute |
| 2588 | * a value and try to bring the count under control, though for smaller |
| 2589 | * packet sizes there isn't much we can do as NAPI polling will likely |
| 2590 | * be kicking in sooner rather than later. |
| 2591 | */ |
| 2592 | itr = IXGBE_ITR_ADAPTIVE_BULK; |
| 2593 | |
| 2594 | adjust_by_size: |
| 2595 | /* If packet counts are 256 or greater we can assume we have a gross |
| 2596 | * overestimation of what the rate should be. Instead of trying to fine |
| 2597 | * tune it just use the formula below to try and dial in an exact value |
| 2598 | * give the current packet size of the frame. |
| 2599 | */ |
| 2600 | avg_wire_size = bytes / packets; |
| 2601 | |
| 2602 | /* The following is a crude approximation of: |
| 2603 | * wmem_default / (size + overhead) = desired_pkts_per_int |
| 2604 | * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate |
| 2605 | * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value |
| 2606 | * |
| 2607 | * Assuming wmem_default is 212992 and overhead is 640 bytes per |
| 2608 | * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the |
| 2609 | * formula down to |
| 2610 | * |
| 2611 | * (170 * (size + 24)) / (size + 640) = ITR |
| 2612 | * |
| 2613 | * We first do some math on the packet size and then finally bitshift |
| 2614 | * by 8 after rounding up. We also have to account for PCIe link speed |
| 2615 | * difference as ITR scales based on this. |
| 2616 | */ |
| 2617 | if (avg_wire_size <= 60) { |
| 2618 | /* Start at 50k ints/sec */ |
| 2619 | avg_wire_size = 5120; |
| 2620 | } else if (avg_wire_size <= 316) { |
| 2621 | /* 50K ints/sec to 16K ints/sec */ |
| 2622 | avg_wire_size *= 40; |
| 2623 | avg_wire_size += 2720; |
| 2624 | } else if (avg_wire_size <= 1084) { |
| 2625 | /* 16K ints/sec to 9.2K ints/sec */ |
| 2626 | avg_wire_size *= 15; |
| 2627 | avg_wire_size += 11452; |
| 2628 | } else if (avg_wire_size <= 1980) { |
| 2629 | /* 9.2K ints/sec to 8K ints/sec */ |
| 2630 | avg_wire_size *= 5; |
| 2631 | avg_wire_size += 22420; |
| 2632 | } else { |
| 2633 | /* plateau at a limit of 8K ints/sec */ |
| 2634 | avg_wire_size = 32256; |
| 2635 | } |
| 2636 | |
| 2637 | /* If we are in low latency mode half our delay which doubles the rate |
| 2638 | * to somewhere between 100K to 16K ints/sec |
| 2639 | */ |
| 2640 | if (itr & IXGBE_ITR_ADAPTIVE_LATENCY) |
| 2641 | avg_wire_size >>= 1; |
| 2642 | |
| 2643 | /* Resultant value is 256 times larger than it needs to be. This |
| 2644 | * gives us room to adjust the value as needed to either increase |
| 2645 | * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc. |
| 2646 | * |
| 2647 | * Use addition as we have already recorded the new latency flag |
| 2648 | * for the ITR value. |
| 2649 | */ |
| 2650 | switch (q_vector->adapter->link_speed) { |
| 2651 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 2652 | case IXGBE_LINK_SPEED_100_FULL: |
| 2653 | default: |
| 2654 | itr += DIV_ROUND_UP(avg_wire_size, |
| 2655 | IXGBE_ITR_ADAPTIVE_MIN_INC * 256) * |
| 2656 | IXGBE_ITR_ADAPTIVE_MIN_INC; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2657 | break; |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2658 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 2659 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 2660 | case IXGBE_LINK_SPEED_10_FULL: |
| 2661 | itr += DIV_ROUND_UP(avg_wire_size, |
| 2662 | IXGBE_ITR_ADAPTIVE_MIN_INC * 64) * |
| 2663 | IXGBE_ITR_ADAPTIVE_MIN_INC; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2664 | break; |
| 2665 | } |
| 2666 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2667 | clear_counts: |
| 2668 | /* write back value */ |
| 2669 | ring_container->itr = itr; |
| 2670 | |
| 2671 | /* next update should occur within next jiffy */ |
| 2672 | ring_container->next_update = next_update + 1; |
| 2673 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2674 | ring_container->total_bytes = 0; |
| 2675 | ring_container->total_packets = 0; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2676 | } |
| 2677 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2678 | /** |
| 2679 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2680 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2681 | * |
| 2682 | * This function is made to be called by ethtool and by the driver |
| 2683 | * when it needs to update EITR registers at runtime. Hardware |
| 2684 | * specific quirks/differences are taken care of here. |
| 2685 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2686 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2687 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2688 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2689 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2690 | int v_idx = q_vector->v_idx; |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2691 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2692 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2693 | switch (adapter->hw.mac.type) { |
| 2694 | case ixgbe_mac_82598EB: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2695 | /* must write high and low 16 bits to reset counter */ |
| 2696 | itr_reg |= (itr_reg << 16); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2697 | break; |
| 2698 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2699 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2700 | case ixgbe_mac_X550: |
| 2701 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2702 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2703 | /* |
| 2704 | * set the WDIS bit to not clear the timer bits and cause an |
| 2705 | * immediate assertion of the interrupt |
| 2706 | */ |
| 2707 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2708 | break; |
| 2709 | default: |
| 2710 | break; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2711 | } |
| 2712 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 2713 | } |
| 2714 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2715 | static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2716 | { |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2717 | u32 new_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2718 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2719 | ixgbe_update_itr(q_vector, &q_vector->tx); |
| 2720 | ixgbe_update_itr(q_vector, &q_vector->rx); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2721 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2722 | /* use the smallest value of new ITR delay calculations */ |
| 2723 | new_itr = min(q_vector->rx.itr, q_vector->tx.itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2724 | |
Alexander Duyck | b4ded83 | 2017-09-25 14:55:36 -0700 | [diff] [blame] | 2725 | /* Clear latency flag if set, shift into correct position */ |
| 2726 | new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY; |
| 2727 | new_itr <<= 2; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2728 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 2729 | if (new_itr != q_vector->itr) { |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 2730 | /* save the algorithm value here */ |
Alexander Duyck | 5d967eb | 2012-02-08 07:49:43 +0000 | [diff] [blame] | 2731 | q_vector->itr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2732 | |
| 2733 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2734 | } |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2735 | } |
| 2736 | |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2737 | /** |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 2738 | * ixgbe_check_overtemp_subtask - check for over temperature |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2739 | * @adapter: pointer to adapter |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2740 | **/ |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2741 | static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter) |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2742 | { |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2743 | struct ixgbe_hw *hw = &adapter->hw; |
| 2744 | u32 eicr = adapter->interrupt_event; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2745 | s32 rc; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2746 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2747 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2748 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2749 | |
Mark Rustad | 22cb4ff | 2017-04-25 13:55:25 -0700 | [diff] [blame] | 2750 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT)) |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2751 | return; |
| 2752 | |
| 2753 | adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2754 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2755 | switch (hw->device_id) { |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2756 | case IXGBE_DEV_ID_82599_T3_LOM: |
| 2757 | /* |
| 2758 | * Since the warning interrupt is for both ports |
| 2759 | * we don't have to check if: |
| 2760 | * - This interrupt wasn't for our port. |
| 2761 | * - We may have missed the interrupt so always have to |
| 2762 | * check if we got a LSC |
| 2763 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2764 | if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) && |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2765 | !(eicr & IXGBE_EICR_LSC)) |
| 2766 | return; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2767 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2768 | if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2769 | u32 speed; |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2770 | bool link_up = false; |
| 2771 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 2772 | hw->mac.ops.check_link(hw, &speed, &link_up, false); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2773 | |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2774 | if (link_up) |
| 2775 | return; |
| 2776 | } |
| 2777 | |
| 2778 | /* Check if this is not due to overtemp */ |
| 2779 | if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP) |
| 2780 | return; |
| 2781 | |
| 2782 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2783 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 2784 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 2785 | rc = hw->phy.ops.check_overtemp(hw); |
| 2786 | if (rc != IXGBE_ERR_OVERTEMP) |
| 2787 | return; |
| 2788 | break; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2789 | default: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 2790 | if (adapter->hw.mac.type >= ixgbe_mac_X540) |
| 2791 | return; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2792 | if (!(eicr & IXGBE_EICR_GPI_SDP0(hw))) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 2793 | return; |
| 2794 | break; |
| 2795 | } |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2796 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 2797 | |
| 2798 | adapter->interrupt_event = 0; |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 2799 | } |
| 2800 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2801 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 2802 | { |
| 2803 | struct ixgbe_hw *hw = &adapter->hw; |
| 2804 | |
| 2805 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2806 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 2807 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2808 | /* write to clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2809 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2810 | } |
| 2811 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2812 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2813 | static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2814 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2815 | struct ixgbe_hw *hw = &adapter->hw; |
| 2816 | |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2817 | if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)) |
| 2818 | return; |
| 2819 | |
| 2820 | switch (adapter->hw.mac.type) { |
| 2821 | case ixgbe_mac_82599EB: |
| 2822 | /* |
| 2823 | * Need to check link state so complete overtemp check |
| 2824 | * on service task |
| 2825 | */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2826 | if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) || |
| 2827 | (eicr & IXGBE_EICR_LSC)) && |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2828 | (!test_bit(__IXGBE_DOWN, &adapter->state))) { |
| 2829 | adapter->interrupt_event = eicr; |
| 2830 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2831 | ixgbe_service_event_schedule(adapter); |
| 2832 | return; |
| 2833 | } |
| 2834 | return; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 2835 | case ixgbe_mac_x550em_a: |
| 2836 | if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) { |
| 2837 | adapter->interrupt_event = eicr; |
| 2838 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT; |
| 2839 | ixgbe_service_event_schedule(adapter); |
| 2840 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, |
| 2841 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2842 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR, |
| 2843 | IXGBE_EICR_GPI_SDP0_X550EM_a); |
| 2844 | } |
| 2845 | return; |
| 2846 | case ixgbe_mac_X550: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2847 | case ixgbe_mac_X540: |
| 2848 | if (!(eicr & IXGBE_EICR_TS)) |
| 2849 | return; |
| 2850 | break; |
| 2851 | default: |
| 2852 | return; |
| 2853 | } |
| 2854 | |
Don Skidmore | f44e751 | 2015-06-09 16:36:23 -0700 | [diff] [blame] | 2855 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2858 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2859 | { |
| 2860 | switch (hw->mac.type) { |
| 2861 | case ixgbe_mac_82598EB: |
| 2862 | if (hw->phy.type == ixgbe_phy_nl) |
| 2863 | return true; |
| 2864 | return false; |
| 2865 | case ixgbe_mac_82599EB: |
| 2866 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2867 | case ixgbe_mac_x550em_a: |
Don Skidmore | 45788d2 | 2015-06-09 16:59:04 -0700 | [diff] [blame] | 2868 | switch (hw->mac.ops.get_media_type(hw)) { |
| 2869 | case ixgbe_media_type_fiber: |
| 2870 | case ixgbe_media_type_fiber_qsfp: |
| 2871 | return true; |
| 2872 | default: |
| 2873 | return false; |
| 2874 | } |
| 2875 | default: |
| 2876 | return false; |
| 2877 | } |
| 2878 | } |
| 2879 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2880 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 2881 | { |
| 2882 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2883 | u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2884 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2885 | if (!ixgbe_is_sfp(hw)) |
| 2886 | return; |
| 2887 | |
| 2888 | /* Later MAC's use different SDP */ |
| 2889 | if (hw->mac.type >= ixgbe_mac_X540) |
| 2890 | eicr_mask = IXGBE_EICR_GPI_SDP0_X540; |
| 2891 | |
| 2892 | if (eicr & eicr_mask) { |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2893 | /* Clear the interrupt */ |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2894 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2895 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2896 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 2897 | adapter->sfp_poll_time = 0; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2898 | ixgbe_service_event_schedule(adapter); |
| 2899 | } |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 2900 | } |
| 2901 | |
Don Skidmore | 4ccc650 | 2015-09-02 13:47:54 -0700 | [diff] [blame] | 2902 | if (adapter->hw.mac.type == ixgbe_mac_82599EB && |
| 2903 | (eicr & IXGBE_EICR_GPI_SDP1(hw))) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2904 | /* Clear the interrupt */ |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2905 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw)); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 2906 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2907 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 2908 | ixgbe_service_event_schedule(adapter); |
| 2909 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2910 | } |
| 2911 | } |
| 2912 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2913 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 2914 | { |
| 2915 | struct ixgbe_hw *hw = &adapter->hw; |
| 2916 | |
| 2917 | adapter->lsc_int++; |
| 2918 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2919 | adapter->link_check_timeout = jiffies; |
| 2920 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 2921 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 2922 | IXGBE_WRITE_FLUSH(hw); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 2923 | ixgbe_service_event_schedule(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2924 | } |
| 2925 | } |
| 2926 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2927 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 2928 | u64 qmask) |
| 2929 | { |
| 2930 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2931 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2932 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2933 | switch (hw->mac.type) { |
| 2934 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2935 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2936 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask); |
| 2937 | break; |
| 2938 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2939 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2940 | case ixgbe_mac_X550: |
| 2941 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2942 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2943 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2944 | if (mask) |
| 2945 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2946 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2947 | if (mask) |
| 2948 | IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask); |
| 2949 | break; |
| 2950 | default: |
| 2951 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2952 | } |
| 2953 | /* skip the flush */ |
| 2954 | } |
| 2955 | |
| 2956 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 2957 | u64 qmask) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2958 | { |
| 2959 | u32 mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2960 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2961 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2962 | switch (hw->mac.type) { |
| 2963 | case ixgbe_mac_82598EB: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2964 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2965 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask); |
| 2966 | break; |
| 2967 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 2968 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 2969 | case ixgbe_mac_X550: |
| 2970 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 2971 | case ixgbe_mac_x550em_a: |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2972 | mask = (qmask & 0xFFFFFFFF); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2973 | if (mask) |
| 2974 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2975 | mask = (qmask >> 32); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 2976 | if (mask) |
| 2977 | IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask); |
| 2978 | break; |
| 2979 | default: |
| 2980 | break; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2981 | } |
| 2982 | /* skip the flush */ |
| 2983 | } |
| 2984 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2985 | /** |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2986 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 2987 | * @adapter: board private structure |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 2988 | * @queues: enable irqs for queues |
| 2989 | * @flush: flush register write |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2990 | **/ |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2991 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues, |
| 2992 | bool flush) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2993 | { |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 2994 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2995 | u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 2996 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 2997 | /* don't reenable LSC while waiting for link */ |
| 2998 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 2999 | mask &= ~IXGBE_EIMS_LSC; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3000 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3001 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3002 | switch (adapter->hw.mac.type) { |
| 3003 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 3004 | mask |= IXGBE_EIMS_GPI_SDP0(hw); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3005 | break; |
| 3006 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3007 | case ixgbe_mac_X550: |
| 3008 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3009 | case ixgbe_mac_x550em_a: |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3010 | mask |= IXGBE_EIMS_TS; |
| 3011 | break; |
| 3012 | default: |
| 3013 | break; |
| 3014 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3015 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 3016 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3017 | switch (adapter->hw.mac.type) { |
| 3018 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 3019 | mask |= IXGBE_EIMS_GPI_SDP1(hw); |
| 3020 | mask |= IXGBE_EIMS_GPI_SDP2(hw); |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3021 | /* fall through */ |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 3022 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3023 | case ixgbe_mac_X550: |
| 3024 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3025 | case ixgbe_mac_x550em_a: |
| 3026 | if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP || |
Mark Rustad | 2d40cd1 | 2016-04-01 12:18:35 -0700 | [diff] [blame] | 3027 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3028 | adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N) |
Mark Rustad | cbd45ec | 2015-08-08 16:17:51 -0700 | [diff] [blame] | 3029 | mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 3030 | if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t) |
| 3031 | mask |= IXGBE_EICR_GPI_SDP0_X540; |
Don Skidmore | 858bc08 | 2011-08-04 09:28:30 +0000 | [diff] [blame] | 3032 | mask |= IXGBE_EIMS_ECC; |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3033 | mask |= IXGBE_EIMS_MAILBOX; |
| 3034 | break; |
| 3035 | default: |
| 3036 | break; |
| 3037 | } |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3038 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3039 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) && |
| 3040 | !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 3041 | mask |= IXGBE_EIMS_FLOW_DIR; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3042 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3043 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 3044 | if (queues) |
| 3045 | ixgbe_irq_enable_queues(adapter, ~0); |
| 3046 | if (flush) |
| 3047 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3050 | static irqreturn_t ixgbe_msix_other(int irq, void *data) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3051 | { |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3052 | struct ixgbe_adapter *adapter = data; |
| 3053 | struct ixgbe_hw *hw = &adapter->hw; |
| 3054 | u32 eicr; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3055 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3056 | /* |
| 3057 | * Workaround for Silicon errata. Use clear-by-write instead |
| 3058 | * of clear-by-read. Reading with EICS will return the |
| 3059 | * interrupt causes without clearing, which later be done |
| 3060 | * with the write to EICR. |
| 3061 | */ |
| 3062 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 3063 | |
| 3064 | /* The lower 16bits of the EICR register are for the queue interrupts |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 3065 | * which should be masked here in order to not accidentally clear them if |
Jacob Keller | d87d830 | 2013-03-02 07:51:42 +0000 | [diff] [blame] | 3066 | * the bits are high when ixgbe_msix_other is called. There is a race |
| 3067 | * condition otherwise which results in possible performance loss |
| 3068 | * especially if the ixgbe_msix_other interrupt is triggering |
| 3069 | * consistently (as it would when PPS is turned on for the X540 device) |
| 3070 | */ |
| 3071 | eicr &= 0xFFFF0000; |
| 3072 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3073 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3074 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3075 | if (eicr & IXGBE_EICR_LSC) |
| 3076 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3077 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3078 | if (eicr & IXGBE_EICR_MAILBOX) |
| 3079 | ixgbe_msg_task(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3080 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3081 | switch (hw->mac.type) { |
| 3082 | case ixgbe_mac_82599EB: |
| 3083 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3084 | case ixgbe_mac_X550: |
| 3085 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3086 | case ixgbe_mac_x550em_a: |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 3087 | if (hw->phy.type == ixgbe_phy_x550em_ext_t && |
| 3088 | (eicr & IXGBE_EICR_GPI_SDP0_X540)) { |
| 3089 | adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT; |
| 3090 | ixgbe_service_event_schedule(adapter); |
| 3091 | IXGBE_WRITE_REG(hw, IXGBE_EICR, |
| 3092 | IXGBE_EICR_GPI_SDP0_X540); |
| 3093 | } |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3094 | if (eicr & IXGBE_EICR_ECC) { |
| 3095 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 3096 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3097 | ixgbe_service_event_schedule(adapter); |
| 3098 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3099 | } |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3100 | /* Handle Flow Director Full threshold interrupt */ |
| 3101 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 3102 | int reinit_count = 0; |
| 3103 | int i; |
| 3104 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3105 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 3106 | if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 3107 | &ring->state)) |
| 3108 | reinit_count++; |
| 3109 | } |
| 3110 | if (reinit_count) { |
| 3111 | /* no more flow director interrupts until after init */ |
| 3112 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR); |
| 3113 | adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 3114 | ixgbe_service_event_schedule(adapter); |
| 3115 | } |
| 3116 | } |
| 3117 | ixgbe_check_sfp_event(adapter, eicr); |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3118 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3119 | break; |
| 3120 | default: |
| 3121 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3124 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3125 | |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3126 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3127 | ixgbe_ptp_check_pps_event(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3128 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3129 | /* re-enable the original interrupt state, no lsc, no queues */ |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 3130 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3131 | ixgbe_irq_enable(adapter, false, false); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3132 | |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3133 | return IRQ_HANDLED; |
| 3134 | } |
| 3135 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3136 | static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3137 | { |
| 3138 | struct ixgbe_q_vector *q_vector = data; |
| 3139 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3140 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3141 | |
| 3142 | if (q_vector->rx.ring || q_vector->tx.ring) |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3143 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3144 | |
| 3145 | return IRQ_HANDLED; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3146 | } |
| 3147 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3148 | /** |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3149 | * ixgbe_poll - NAPI Rx polling callback |
| 3150 | * @napi: structure for representing this polling device |
| 3151 | * @budget: how many packets driver is allowed to clean |
| 3152 | * |
| 3153 | * This function is used for legacy and MSI, NAPI mode |
| 3154 | **/ |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 3155 | int ixgbe_poll(struct napi_struct *napi, int budget) |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3156 | { |
| 3157 | struct ixgbe_q_vector *q_vector = |
| 3158 | container_of(napi, struct ixgbe_q_vector, napi); |
| 3159 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 3160 | struct ixgbe_ring *ring; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3161 | int per_ring_budget, work_done = 0; |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3162 | bool clean_complete = true; |
| 3163 | |
| 3164 | #ifdef CONFIG_IXGBE_DCA |
| 3165 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 3166 | ixgbe_update_dca(q_vector); |
| 3167 | #endif |
| 3168 | |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 3169 | ixgbe_for_each_ring(ring, q_vector->tx) { |
| 3170 | if (!ixgbe_clean_tx_irq(q_vector, ring, budget)) |
| 3171 | clean_complete = false; |
| 3172 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3173 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 3174 | /* Exit if we are called by netpoll */ |
| 3175 | if (budget <= 0) |
Eliezer Tamir | 5a85e73 | 2013-06-10 11:40:20 +0300 | [diff] [blame] | 3176 | return budget; |
| 3177 | |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3178 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 3179 | * the budget to go below 1 because we'll exit polling */ |
| 3180 | if (q_vector->rx.count > 1) |
| 3181 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 3182 | else |
| 3183 | per_ring_budget = budget; |
| 3184 | |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3185 | ixgbe_for_each_ring(ring, q_vector->rx) { |
| 3186 | int cleaned = ixgbe_clean_rx_irq(q_vector, ring, |
| 3187 | per_ring_budget); |
| 3188 | |
| 3189 | work_done += cleaned; |
Alexander Duyck | 8220bbc | 2016-03-07 09:30:09 -0800 | [diff] [blame] | 3190 | if (cleaned >= per_ring_budget) |
| 3191 | clean_complete = false; |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3192 | } |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3193 | |
| 3194 | /* If all work not completed, return budget and keep polling */ |
| 3195 | if (!clean_complete) |
| 3196 | return budget; |
| 3197 | |
| 3198 | /* all work done, exit the polling mode */ |
Jesse Brandeburg | 32b3e08 | 2015-09-24 16:35:47 -0700 | [diff] [blame] | 3199 | napi_complete_done(napi, work_done); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3200 | if (adapter->rx_itr_setting & 1) |
| 3201 | ixgbe_set_itr(q_vector); |
| 3202 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3203 | ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx)); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3204 | |
Paolo Abeni | 4b732cd | 2016-06-15 15:37:59 +0200 | [diff] [blame] | 3205 | return min(work_done, budget - 1); |
Alexander Duyck | eb01b97 | 2012-02-08 07:51:27 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
| 3208 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3209 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 3210 | * @adapter: board private structure |
| 3211 | * |
| 3212 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 3213 | * interrupts from the kernel. |
| 3214 | **/ |
| 3215 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 3216 | { |
| 3217 | struct net_device *netdev = adapter->netdev; |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3218 | unsigned int ri = 0, ti = 0; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3219 | int vector, err; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3220 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3221 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 3222 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3223 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 3224 | |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3225 | if (q_vector->tx.ring && q_vector->rx.ring) { |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3226 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 3227 | "%s-TxRx-%u", netdev->name, ri++); |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 3228 | ti++; |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3229 | } else if (q_vector->rx.ring) { |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3230 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 3231 | "%s-rx-%u", netdev->name, ri++); |
Alexander Duyck | 4ff7fb1 | 2011-08-31 00:01:11 +0000 | [diff] [blame] | 3232 | } else if (q_vector->tx.ring) { |
Tony Nguyen | e61e4c8 | 2017-05-12 11:38:07 -0700 | [diff] [blame] | 3233 | snprintf(q_vector->name, sizeof(q_vector->name), |
| 3234 | "%s-tx-%u", netdev->name, ti++); |
Alexander Duyck | d0759eb | 2010-11-16 19:27:09 -0800 | [diff] [blame] | 3235 | } else { |
| 3236 | /* skip this unused q_vector */ |
| 3237 | continue; |
Alexander Duyck | 32aa77a | 2010-11-16 19:26:59 -0800 | [diff] [blame] | 3238 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3239 | err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0, |
| 3240 | q_vector->name, q_vector); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3241 | if (err) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3242 | e_err(probe, "request_irq failed for MSIX interrupt " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 3243 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3244 | goto free_queue_irqs; |
| 3245 | } |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3246 | /* If Flow Director is enabled, set interrupt affinity */ |
| 3247 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 3248 | /* assign the mask for this irq */ |
| 3249 | irq_set_affinity_hint(entry->vector, |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3250 | &q_vector->affinity_mask); |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3251 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3252 | } |
| 3253 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3254 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | 2c4af69 | 2011-07-15 07:29:55 +0000 | [diff] [blame] | 3255 | ixgbe_msix_other, 0, netdev->name, adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3256 | if (err) { |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3257 | e_err(probe, "request_irq for msix_other failed: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3258 | goto free_queue_irqs; |
| 3259 | } |
| 3260 | |
| 3261 | return 0; |
| 3262 | |
| 3263 | free_queue_irqs: |
Alexander Duyck | 207867f | 2011-07-15 03:05:37 +0000 | [diff] [blame] | 3264 | while (vector) { |
| 3265 | vector--; |
| 3266 | irq_set_affinity_hint(adapter->msix_entries[vector].vector, |
| 3267 | NULL); |
| 3268 | free_irq(adapter->msix_entries[vector].vector, |
| 3269 | adapter->q_vector[vector]); |
| 3270 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3271 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3272 | pci_disable_msix(adapter->pdev); |
| 3273 | kfree(adapter->msix_entries); |
| 3274 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3275 | return err; |
| 3276 | } |
| 3277 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 3278 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3279 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3280 | * @irq: interrupt number |
| 3281 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3282 | **/ |
| 3283 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 3284 | { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3285 | struct ixgbe_adapter *adapter = data; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3286 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3287 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3288 | u32 eicr; |
| 3289 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3290 | /* |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 3291 | * Workaround for silicon errata #26 on 82598. Mask the interrupt |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 3292 | * before the read of EICR. |
| 3293 | */ |
| 3294 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 3295 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3296 | /* 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] | 3297 | * therefore no explicit interrupt disable is necessary */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3298 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3299 | if (!eicr) { |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3300 | /* |
| 3301 | * shared interrupt alert! |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3302 | * make sure interrupts are enabled because the read will |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3303 | * have disabled interrupts due to EIAM |
| 3304 | * finish the workaround of silicon errata on 82598. Unmask |
| 3305 | * the interrupt that we masked before the EICR read. |
| 3306 | */ |
| 3307 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3308 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3309 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 3310 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3311 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3312 | if (eicr & IXGBE_EICR_LSC) |
| 3313 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3314 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3315 | switch (hw->mac.type) { |
| 3316 | case ixgbe_mac_82599EB: |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3317 | ixgbe_check_sfp_event(adapter, eicr); |
Don Skidmore | 0ccb974 | 2011-08-04 02:07:48 +0000 | [diff] [blame] | 3318 | /* Fall through */ |
| 3319 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3320 | case ixgbe_mac_X550: |
| 3321 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3322 | case ixgbe_mac_x550em_a: |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3323 | if (eicr & IXGBE_EICR_ECC) { |
| 3324 | e_info(link, "Received ECC Err, initiating reset\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 3325 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Don Skidmore | d773ce2 | 2014-02-25 17:58:53 -0800 | [diff] [blame] | 3326 | ixgbe_service_event_schedule(adapter); |
| 3327 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC); |
| 3328 | } |
Jacob Keller | 4f51bf7 | 2011-08-20 04:49:45 +0000 | [diff] [blame] | 3329 | ixgbe_check_overtemp_event(adapter, eicr); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3330 | break; |
| 3331 | default: |
| 3332 | break; |
| 3333 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3334 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3335 | ixgbe_check_fan_failure(adapter, eicr); |
Jacob Keller | db0677f | 2012-08-24 07:46:54 +0000 | [diff] [blame] | 3336 | if (unlikely(eicr & IXGBE_EICR_TIMESYNC)) |
Mark Rustad | a9763f3 | 2015-10-27 09:58:07 -0700 | [diff] [blame] | 3337 | ixgbe_ptp_check_pps_event(adapter); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 3338 | |
Alexander Duyck | b9f6ed2 | 2012-02-08 07:49:54 +0000 | [diff] [blame] | 3339 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | ef2662b | 2015-09-29 15:19:43 -0700 | [diff] [blame] | 3340 | napi_schedule_irqoff(&q_vector->napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3341 | |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3342 | /* |
| 3343 | * re-enable link(maybe) and non-queue interrupts, no flush. |
| 3344 | * ixgbe_poll will re-enable the queue interrupts |
| 3345 | */ |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 3346 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 3347 | ixgbe_irq_enable(adapter, false, false); |
| 3348 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3349 | return IRQ_HANDLED; |
| 3350 | } |
| 3351 | |
| 3352 | /** |
| 3353 | * ixgbe_request_irq - initialize interrupts |
| 3354 | * @adapter: board private structure |
| 3355 | * |
| 3356 | * Attempts to configure interrupts using the best available |
| 3357 | * capabilities of the hardware and kernel. |
| 3358 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3359 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3360 | { |
| 3361 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3362 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3363 | |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3364 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3365 | err = ixgbe_request_msix_irqs(adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3366 | else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3367 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3368 | netdev->name, adapter); |
Alexander Duyck | 4cc6df2 | 2011-07-15 03:05:51 +0000 | [diff] [blame] | 3369 | else |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3370 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3371 | netdev->name, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3372 | |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 3373 | if (err) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3374 | e_err(probe, "request_irq failed, Error %d\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3375 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3376 | return err; |
| 3377 | } |
| 3378 | |
| 3379 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 3380 | { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3381 | int vector; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3382 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3383 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | a65151ba2 | 2011-05-27 05:31:32 +0000 | [diff] [blame] | 3384 | free_irq(adapter->pdev->irq, adapter); |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3385 | return; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3386 | } |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3387 | |
Mark Rustad | 1fa7125 | 2016-09-28 15:36:38 -0700 | [diff] [blame] | 3388 | if (!adapter->msix_entries) |
| 3389 | return; |
| 3390 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3391 | for (vector = 0; vector < adapter->num_q_vectors; vector++) { |
| 3392 | struct ixgbe_q_vector *q_vector = adapter->q_vector[vector]; |
| 3393 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 3394 | |
| 3395 | /* free only the irqs that were actually requested */ |
| 3396 | if (!q_vector->rx.ring && !q_vector->tx.ring) |
| 3397 | continue; |
| 3398 | |
| 3399 | /* clear the affinity_mask in the IRQ descriptor */ |
| 3400 | irq_set_affinity_hint(entry->vector, NULL); |
| 3401 | |
| 3402 | free_irq(entry->vector, q_vector); |
| 3403 | } |
| 3404 | |
Babu Moger | 90c6f87 | 2016-06-18 17:40:47 -0700 | [diff] [blame] | 3405 | free_irq(adapter->msix_entries[vector].vector, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3409 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 3410 | * @adapter: board private structure |
| 3411 | **/ |
| 3412 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 3413 | { |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3414 | switch (adapter->hw.mac.type) { |
| 3415 | case ixgbe_mac_82598EB: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3416 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3417 | break; |
| 3418 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 3419 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 3420 | case ixgbe_mac_X550: |
| 3421 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 3422 | case ixgbe_mac_x550em_a: |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3423 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 3424 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3425 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3426 | break; |
| 3427 | default: |
| 3428 | break; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3429 | } |
| 3430 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 3431 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 3432 | int vector; |
| 3433 | |
| 3434 | for (vector = 0; vector < adapter->num_q_vectors; vector++) |
| 3435 | synchronize_irq(adapter->msix_entries[vector].vector); |
| 3436 | |
| 3437 | synchronize_irq(adapter->msix_entries[vector++].vector); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3438 | } else { |
| 3439 | synchronize_irq(adapter->pdev->irq); |
| 3440 | } |
| 3441 | } |
| 3442 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 3443 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3444 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 3445 | * @adapter: board private structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3446 | * |
| 3447 | **/ |
| 3448 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 3449 | { |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3450 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3451 | |
Emil Tantilov | d5bf4f6 | 2011-08-31 00:01:16 +0000 | [diff] [blame] | 3452 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3453 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3454 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 3455 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3456 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 3457 | e_info(hw, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3458 | } |
| 3459 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3460 | /** |
| 3461 | * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset |
| 3462 | * @adapter: board private structure |
| 3463 | * @ring: structure containing ring specific data |
| 3464 | * |
| 3465 | * Configure the Tx descriptor ring after a reset. |
| 3466 | **/ |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 3467 | void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter, |
| 3468 | struct ixgbe_ring *ring) |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3469 | { |
| 3470 | struct ixgbe_hw *hw = &adapter->hw; |
| 3471 | u64 tdba = ring->dma; |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3472 | int wait_loop = 10; |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3473 | u32 txdctl = IXGBE_TXDCTL_ENABLE; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3474 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3475 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3476 | /* disable queue to avoid issues while updating state */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3477 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3478 | IXGBE_WRITE_FLUSH(hw); |
| 3479 | |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3480 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3481 | (tdba & DMA_BIT_MASK(32))); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3482 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32)); |
| 3483 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx), |
| 3484 | ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 3485 | IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0); |
| 3486 | IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 3487 | ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3488 | |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3489 | /* |
| 3490 | * set WTHRESH to encourage burst writeback, it should not be set |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3491 | * higher than 1 when: |
| 3492 | * - ITR is 0 as it could cause false TX hangs |
| 3493 | * - ITR is set to > 100k int/sec and BQL is enabled |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3494 | * |
| 3495 | * In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 3496 | * to or less than the number of on chip descriptors, which is |
| 3497 | * currently 40. |
| 3498 | */ |
Emil Tantilov | 67da097 | 2013-01-25 06:19:20 +0000 | [diff] [blame] | 3499 | if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR)) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3500 | txdctl |= 1u << 16; /* WTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3501 | else |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3502 | txdctl |= 8u << 16; /* WTHRESH = 8 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3503 | |
Alexander Duyck | e954b37 | 2012-02-08 07:49:38 +0000 | [diff] [blame] | 3504 | /* |
| 3505 | * Setting PTHRESH to 32 both improves performance |
| 3506 | * and avoids a TX hang with DFP enabled |
| 3507 | */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 3508 | txdctl |= (1u << 8) | /* HTHRESH = 1 */ |
Alexander Duyck | b88c6de | 2011-07-15 03:06:12 +0000 | [diff] [blame] | 3509 | 32; /* PTHRESH = 32 */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3510 | |
| 3511 | /* reinitialize flowdirector state */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 3512 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 3513 | ring->atr_sample_rate = adapter->atr_sample_rate; |
| 3514 | ring->atr_count = 0; |
| 3515 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state); |
| 3516 | } else { |
| 3517 | ring->atr_sample_rate = 0; |
| 3518 | } |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3519 | |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3520 | /* initialize XPS */ |
| 3521 | if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) { |
| 3522 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 3523 | |
| 3524 | if (q_vector) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 3525 | netif_set_xps_queue(ring->netdev, |
Alexander Duyck | fd786b7 | 2013-01-12 06:33:31 +0000 | [diff] [blame] | 3526 | &q_vector->affinity_mask, |
| 3527 | ring->queue_index); |
| 3528 | } |
| 3529 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 3530 | clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state); |
| 3531 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 3532 | /* reinitialize tx_buffer_info */ |
| 3533 | memset(ring->tx_buffer_info, 0, |
| 3534 | sizeof(struct ixgbe_tx_buffer) * ring->count); |
| 3535 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3536 | /* enable queue */ |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3537 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl); |
| 3538 | |
| 3539 | /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 3540 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 3541 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 3542 | return; |
| 3543 | |
| 3544 | /* poll to verify queue is enabled */ |
| 3545 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 3546 | usleep_range(1000, 2000); |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3547 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx)); |
| 3548 | } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 3549 | if (!wait_loop) |
Emil Tantilov | a55defd | 2016-07-29 10:30:06 -0700 | [diff] [blame] | 3550 | hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx); |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3553 | static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter) |
| 3554 | { |
| 3555 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3556 | u32 rttdcs, mtqc; |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 3557 | u8 tcs = adapter->hw_tcs; |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3558 | |
| 3559 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3560 | return; |
| 3561 | |
| 3562 | /* disable the arbiter while setting MTQC */ |
| 3563 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 3564 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 3565 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3566 | |
| 3567 | /* set transmit pool layout */ |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3568 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3569 | mtqc = IXGBE_MTQC_VT_ENA; |
| 3570 | if (tcs > 4) |
| 3571 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3572 | else if (tcs > 1) |
| 3573 | mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3574 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3575 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3576 | mtqc |= IXGBE_MTQC_32VF; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3577 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3578 | mtqc |= IXGBE_MTQC_64VF; |
| 3579 | } else { |
| 3580 | if (tcs > 4) |
| 3581 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ; |
| 3582 | else if (tcs > 1) |
| 3583 | mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ; |
| 3584 | else |
| 3585 | mtqc = IXGBE_MTQC_64Q_1PB; |
| 3586 | } |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3587 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3588 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3589 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3590 | /* Enable Security TX Buffer IFG for multiple pb */ |
| 3591 | if (tcs) { |
| 3592 | u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG); |
| 3593 | sectx |= IXGBE_SECTX_DCB; |
| 3594 | IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx); |
Alexander Duyck | 120ff94 | 2010-08-19 13:34:50 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | /* re-enable the arbiter */ |
| 3598 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 3599 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 3600 | } |
| 3601 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3602 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3603 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3604 | * @adapter: board private structure |
| 3605 | * |
| 3606 | * Configure the Tx unit of the MAC after a reset. |
| 3607 | **/ |
| 3608 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 3609 | { |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3610 | struct ixgbe_hw *hw = &adapter->hw; |
| 3611 | u32 dmatxctl; |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3612 | u32 i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3613 | |
Alexander Duyck | 2f1860b | 2010-08-19 13:39:43 +0000 | [diff] [blame] | 3614 | ixgbe_setup_mtqc(adapter); |
| 3615 | |
| 3616 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 3617 | /* DMATXCTL.EN must be before Tx queues are enabled */ |
| 3618 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 3619 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 3620 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 3621 | } |
| 3622 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3623 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
Alexander Duyck | 43e69bf | 2010-08-19 13:35:12 +0000 | [diff] [blame] | 3624 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3625 | ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 3626 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 3627 | ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 3630 | static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter, |
| 3631 | struct ixgbe_ring *ring) |
| 3632 | { |
| 3633 | struct ixgbe_hw *hw = &adapter->hw; |
| 3634 | u8 reg_idx = ring->reg_idx; |
| 3635 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3636 | |
| 3637 | srrctl |= IXGBE_SRRCTL_DROP_EN; |
| 3638 | |
| 3639 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3640 | } |
| 3641 | |
| 3642 | static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter, |
| 3643 | struct ixgbe_ring *ring) |
| 3644 | { |
| 3645 | struct ixgbe_hw *hw = &adapter->hw; |
| 3646 | u8 reg_idx = ring->reg_idx; |
| 3647 | u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx)); |
| 3648 | |
| 3649 | srrctl &= ~IXGBE_SRRCTL_DROP_EN; |
| 3650 | |
| 3651 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
| 3652 | } |
| 3653 | |
| 3654 | #ifdef CONFIG_IXGBE_DCB |
| 3655 | void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3656 | #else |
| 3657 | static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter) |
| 3658 | #endif |
| 3659 | { |
| 3660 | int i; |
| 3661 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
| 3662 | |
| 3663 | if (adapter->ixgbe_ieee_pfc) |
| 3664 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 3665 | |
| 3666 | /* |
| 3667 | * We should set the drop enable bit if: |
| 3668 | * SR-IOV is enabled |
| 3669 | * or |
| 3670 | * Number of Rx queues > 1 and flow control is disabled |
| 3671 | * |
| 3672 | * This allows us to avoid head of line blocking for security |
| 3673 | * and performance reasons. |
| 3674 | */ |
| 3675 | if (adapter->num_vfs || (adapter->num_rx_queues > 1 && |
| 3676 | !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) { |
| 3677 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3678 | ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3679 | } else { |
| 3680 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3681 | ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]); |
| 3682 | } |
| 3683 | } |
| 3684 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3685 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3686 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 3687 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 3688 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3689 | { |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3690 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3691 | u32 srrctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3692 | u8 reg_idx = rx_ring->reg_idx; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3693 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3694 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3695 | u16 mask = adapter->ring_feature[RING_F_RSS].mask; |
| 3696 | |
| 3697 | /* |
| 3698 | * if VMDq is not active we must program one srrctl register |
| 3699 | * per RSS queue since we have enabled RDRXCTL.MVMEN |
| 3700 | */ |
| 3701 | reg_idx &= mask; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3704 | /* configure header buffer length, needed for RSC */ |
| 3705 | srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3706 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3707 | /* configure the packet buffer length */ |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 3708 | if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state)) |
| 3709 | srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 3710 | else |
| 3711 | srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3712 | |
| 3713 | /* configure descriptor type */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3714 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3715 | |
Alexander Duyck | 45e9baa | 2012-05-05 05:30:59 +0000 | [diff] [blame] | 3716 | IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 3717 | } |
| 3718 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3719 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3720 | * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3721 | * @adapter: device handle |
| 3722 | * |
| 3723 | * - 82598/82599/X540: 128 |
| 3724 | * - X550(non-SRIOV mode): 512 |
| 3725 | * - X550(SRIOV mode): 64 |
| 3726 | */ |
Vlad Zolotarov | 7f276ef | 2015-03-30 21:18:58 +0300 | [diff] [blame] | 3727 | u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3728 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3729 | if (adapter->hw.mac.type < ixgbe_mac_X550) |
| 3730 | return 128; |
| 3731 | else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3732 | return 64; |
| 3733 | else |
| 3734 | return 512; |
| 3735 | } |
| 3736 | |
| 3737 | /** |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3738 | * ixgbe_store_key - Write the RSS key to HW |
| 3739 | * @adapter: device handle |
| 3740 | * |
| 3741 | * Write the RSS key stored in adapter.rss_key to HW. |
| 3742 | */ |
| 3743 | void ixgbe_store_key(struct ixgbe_adapter *adapter) |
| 3744 | { |
| 3745 | struct ixgbe_hw *hw = &adapter->hw; |
| 3746 | int i; |
| 3747 | |
| 3748 | for (i = 0; i < 10; i++) |
| 3749 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]); |
| 3750 | } |
| 3751 | |
| 3752 | /** |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 3753 | * ixgbe_init_rss_key - Initialize adapter RSS key |
| 3754 | * @adapter: device handle |
| 3755 | * |
| 3756 | * Allocates and initializes the RSS key if it is not allocated. |
| 3757 | **/ |
| 3758 | static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter) |
| 3759 | { |
| 3760 | u32 *rss_key; |
| 3761 | |
| 3762 | if (!adapter->rss_key) { |
| 3763 | rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL); |
| 3764 | if (unlikely(!rss_key)) |
| 3765 | return -ENOMEM; |
| 3766 | |
| 3767 | netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE); |
| 3768 | adapter->rss_key = rss_key; |
| 3769 | } |
| 3770 | |
| 3771 | return 0; |
| 3772 | } |
| 3773 | |
| 3774 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3775 | * ixgbe_store_reta - Write the RETA table to HW |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3776 | * @adapter: device handle |
| 3777 | * |
| 3778 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3779 | */ |
Tom Barbette | 1c7cf07 | 2015-06-26 15:40:18 +0200 | [diff] [blame] | 3780 | void ixgbe_store_reta(struct ixgbe_adapter *adapter) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3781 | { |
| 3782 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3783 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3784 | u32 reta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3785 | u32 indices_multi; |
| 3786 | u8 *indir_tbl = adapter->rss_indir_tbl; |
John Fastabend | 86b4db3 | 2011-04-26 07:26:19 +0000 | [diff] [blame] | 3787 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3788 | /* Fill out the redirection table as follows: |
| 3789 | * - 82598: 8 bit wide entries containing pair of 4 bit RSS |
| 3790 | * indices. |
| 3791 | * - 82599/X540: 8 bit wide entries containing 4 bit RSS index |
| 3792 | * - X550: 8 bit wide entries containing 6 bit RSS index |
| 3793 | */ |
| 3794 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 3795 | indices_multi = 0x11; |
| 3796 | else |
| 3797 | indices_multi = 0x1; |
| 3798 | |
| 3799 | /* Write redirection table to HW */ |
| 3800 | for (i = 0; i < reta_entries; i++) { |
| 3801 | reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8; |
| 3802 | if ((i & 3) == 3) { |
| 3803 | if (i < 128) |
| 3804 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
| 3805 | else |
| 3806 | IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32), |
| 3807 | reta); |
| 3808 | reta = 0; |
| 3809 | } |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | /** |
Jean Sacren | a897a2a | 2015-09-19 05:08:44 -0600 | [diff] [blame] | 3814 | * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode) |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3815 | * @adapter: device handle |
| 3816 | * |
| 3817 | * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW. |
| 3818 | */ |
| 3819 | static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter) |
| 3820 | { |
| 3821 | u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3822 | struct ixgbe_hw *hw = &adapter->hw; |
| 3823 | u32 vfreta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3824 | |
| 3825 | /* Write redirection table to HW */ |
| 3826 | for (i = 0; i < reta_entries; i++) { |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 3827 | u16 pool = adapter->num_rx_pools; |
| 3828 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3829 | vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8; |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 3830 | if ((i & 3) != 3) |
| 3831 | continue; |
| 3832 | |
| 3833 | while (pool--) |
| 3834 | IXGBE_WRITE_REG(hw, |
| 3835 | IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)), |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3836 | vfreta); |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 3837 | vfreta = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3838 | } |
| 3839 | } |
| 3840 | |
| 3841 | static void ixgbe_setup_reta(struct ixgbe_adapter *adapter) |
| 3842 | { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3843 | u32 i, j; |
| 3844 | u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter); |
| 3845 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 3846 | |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3847 | /* Program table for at least 4 queues w/ SR-IOV so that VFs can |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3848 | * make full use of any rings they may have. We will use the |
| 3849 | * PSRTYPE register to control how many rings we use within the PF. |
| 3850 | */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3851 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4)) |
| 3852 | rss_i = 4; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3853 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3854 | /* Fill out hash function seeds */ |
Paolo Abeni | d3aa9c9 | 2016-12-15 15:20:34 +0100 | [diff] [blame] | 3855 | ixgbe_store_key(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3856 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3857 | /* Fill out redirection table */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3858 | memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl)); |
| 3859 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3860 | for (i = 0, j = 0; i < reta_entries; i++, j++) { |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3861 | if (j == rss_i) |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3862 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3863 | |
| 3864 | adapter->rss_indir_tbl[i] = j; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3865 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3866 | |
| 3867 | ixgbe_store_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3868 | } |
| 3869 | |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3870 | static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter) |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3871 | { |
| 3872 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3873 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3874 | int i, j; |
| 3875 | |
| 3876 | /* Fill out hash function seeds */ |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 3877 | for (i = 0; i < 10; i++) { |
| 3878 | u16 pool = adapter->num_rx_pools; |
| 3879 | |
| 3880 | while (pool--) |
| 3881 | IXGBE_WRITE_REG(hw, |
| 3882 | IXGBE_PFVFRSSRK(i, VMDQ_P(pool)), |
| 3883 | *(adapter->rss_key + i)); |
| 3884 | } |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3885 | |
| 3886 | /* Fill out the redirection table */ |
| 3887 | for (i = 0, j = 0; i < 64; i++, j++) { |
| 3888 | if (j == rss_i) |
| 3889 | j = 0; |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3890 | |
| 3891 | adapter->rss_indir_tbl[i] = j; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3892 | } |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3893 | |
| 3894 | ixgbe_store_vfreta(adapter); |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 3898 | { |
| 3899 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3900 | u32 mrqc = 0, rss_field = 0, vfmrqc = 0; |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3901 | u32 rxcsum; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3902 | |
| 3903 | /* Disable indicating checksum in descriptor, enables RSS hash */ |
| 3904 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 3905 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 3906 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
| 3907 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3908 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 3909 | if (adapter->ring_feature[RING_F_RSS].mask) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3910 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3911 | } else { |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 3912 | u8 tcs = adapter->hw_tcs; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3913 | |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3914 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 3915 | if (tcs > 4) |
| 3916 | mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */ |
| 3917 | else if (tcs > 1) |
| 3918 | mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */ |
Alexander Duyck | e24fcf2 | 2016-09-07 20:28:24 -0700 | [diff] [blame] | 3919 | else if (adapter->ring_feature[RING_F_VMDQ].mask == |
| 3920 | IXGBE_82599_VMDQ_4Q_MASK) |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3921 | mrqc = IXGBE_MRQC_VMDQRSS32EN; |
| 3922 | else |
| 3923 | mrqc = IXGBE_MRQC_VMDQRSS64EN; |
Emil Tantilov | e6b41c8 | 2017-04-25 11:31:06 -0700 | [diff] [blame] | 3924 | |
| 3925 | /* Enable L3/L4 for Tx Switched packets */ |
| 3926 | mrqc |= IXGBE_MRQC_L3L4TXSWEN; |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3927 | } else { |
| 3928 | if (tcs > 4) |
| 3929 | mrqc = IXGBE_MRQC_RTRSS8TCEN; |
| 3930 | else if (tcs > 1) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3931 | mrqc = IXGBE_MRQC_RTRSS4TCEN; |
| 3932 | else |
Alexander Duyck | 671c0ad | 2012-05-18 06:34:02 +0000 | [diff] [blame] | 3933 | mrqc = IXGBE_MRQC_RSSEN; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 3934 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3935 | } |
| 3936 | |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3937 | /* Perform hash on these packet types */ |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3938 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 | |
| 3939 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP | |
| 3940 | IXGBE_MRQC_RSS_FIELD_IPV6 | |
| 3941 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP; |
Alexander Duyck | 05abb12 | 2010-08-19 13:35:41 +0000 | [diff] [blame] | 3942 | |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3943 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3944 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3945 | if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP) |
Don Skidmore | d1b849b | 2014-11-09 06:42:57 +0000 | [diff] [blame] | 3946 | rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Alexander Duyck | ef6afc0 | 2012-02-08 07:51:53 +0000 | [diff] [blame] | 3947 | |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3948 | if ((hw->mac.type >= ixgbe_mac_X550) && |
| 3949 | (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) { |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 3950 | u16 pool = adapter->num_rx_pools; |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3951 | |
| 3952 | /* Enable VF RSS mode */ |
| 3953 | mrqc |= IXGBE_MRQC_MULTIPLE_RSS; |
| 3954 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3955 | |
| 3956 | /* Setup RSS through the VF registers */ |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3957 | ixgbe_setup_vfreta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3958 | vfmrqc = IXGBE_MRQC_RSSEN; |
| 3959 | vfmrqc |= rss_field; |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 3960 | |
| 3961 | while (pool--) |
| 3962 | IXGBE_WRITE_REG(hw, |
| 3963 | IXGBE_PFVFMRQC(VMDQ_P(pool)), |
| 3964 | vfmrqc); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3965 | } else { |
Vlad Zolotarov | dfaf891 | 2015-03-30 21:18:57 +0300 | [diff] [blame] | 3966 | ixgbe_setup_reta(adapter); |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 3967 | mrqc |= rss_field; |
| 3968 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
| 3969 | } |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3970 | } |
| 3971 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3972 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3973 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 3974 | * @adapter: address of board private structure |
| 3975 | * @ring: structure containing ring specific data |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3976 | **/ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 3977 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3978 | struct ixgbe_ring *ring) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3979 | { |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3980 | struct ixgbe_hw *hw = &adapter->hw; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3981 | u32 rscctrl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 3982 | u8 reg_idx = ring->reg_idx; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3983 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 3984 | if (!ring_is_rsc_enabled(ring)) |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3985 | return; |
| 3986 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3987 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx)); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3988 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 3989 | /* |
| 3990 | * we must limit the number of descriptors so that the |
| 3991 | * total size of max desc * buf_len is not greater |
Alexander Duyck | 642c680 | 2011-11-10 09:09:17 +0000 | [diff] [blame] | 3992 | * than 65536 |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3993 | */ |
Alexander Duyck | f800326 | 2012-03-03 02:35:52 +0000 | [diff] [blame] | 3994 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 3995 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 3996 | } |
| 3997 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 3998 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 3999 | static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 4000 | struct ixgbe_ring *ring) |
| 4001 | { |
| 4002 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4003 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 4004 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4005 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4006 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 4007 | if (ixgbe_removed(hw->hw_addr)) |
| 4008 | return; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4009 | /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */ |
| 4010 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 4011 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 4012 | return; |
| 4013 | |
| 4014 | do { |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 4015 | usleep_range(1000, 2000); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4016 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 4017 | } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 4018 | |
| 4019 | if (!wait_loop) { |
| 4020 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within " |
| 4021 | "the polling period\n", reg_idx); |
| 4022 | } |
| 4023 | } |
| 4024 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4025 | void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter, |
| 4026 | struct ixgbe_ring *ring) |
| 4027 | { |
| 4028 | struct ixgbe_hw *hw = &adapter->hw; |
| 4029 | int wait_loop = IXGBE_MAX_RX_DESC_POLL; |
| 4030 | u32 rxdctl; |
| 4031 | u8 reg_idx = ring->reg_idx; |
| 4032 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 4033 | if (ixgbe_removed(hw->hw_addr)) |
| 4034 | return; |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4035 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 4036 | rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 4037 | |
| 4038 | /* write value back with RXDCTL.ENABLE bit cleared */ |
| 4039 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 4040 | |
| 4041 | if (hw->mac.type == ixgbe_mac_82598EB && |
| 4042 | !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP)) |
| 4043 | return; |
| 4044 | |
| 4045 | /* the hardware may take up to 100us to really disable the rx queue */ |
| 4046 | do { |
| 4047 | udelay(10); |
| 4048 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
| 4049 | } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 4050 | |
| 4051 | if (!wait_loop) { |
| 4052 | e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within " |
| 4053 | "the polling period\n", reg_idx); |
| 4054 | } |
| 4055 | } |
| 4056 | |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 4057 | void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter, |
| 4058 | struct ixgbe_ring *ring) |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4059 | { |
| 4060 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 4061 | union ixgbe_adv_rx_desc *rx_desc; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4062 | u64 rdba = ring->dma; |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4063 | u32 rxdctl; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 4064 | u8 reg_idx = ring->reg_idx; |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4065 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4066 | /* disable queue to avoid issues while updating state */ |
| 4067 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx)); |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 4068 | ixgbe_disable_rx_queue(adapter, ring); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4069 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4070 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32))); |
| 4071 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32)); |
| 4072 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx), |
| 4073 | ring->count * sizeof(union ixgbe_adv_rx_desc)); |
Neerav Parikh | 8b75451 | 2015-12-08 22:13:58 -0800 | [diff] [blame] | 4074 | /* Force flushing of IXGBE_RDLEN to prevent MDD */ |
| 4075 | IXGBE_WRITE_FLUSH(hw); |
| 4076 | |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4077 | IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0); |
| 4078 | IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 4079 | ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4080 | |
| 4081 | ixgbe_configure_srrctl(adapter, ring); |
| 4082 | ixgbe_configure_rscctl(adapter, ring); |
| 4083 | |
| 4084 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 4085 | /* |
| 4086 | * enable cache line friendly hardware writes: |
| 4087 | * PTHRESH=32 descriptors (half the internal cache), |
| 4088 | * this also removes ugly rx_no_buffer_count increment |
| 4089 | * HTHRESH=4 descriptors (to minimize latency on fetch) |
| 4090 | * WTHRESH=8 burst writeback up to two cache lines |
| 4091 | */ |
| 4092 | rxdctl &= ~0x3FFFFF; |
| 4093 | rxdctl |= 0x080420; |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4094 | #if (PAGE_SIZE < 8192) |
Emil Tantilov | 2bafa8f | 2018-01-12 14:02:56 -0800 | [diff] [blame] | 4095 | /* RXDCTL.RLPML does not work on 82599 */ |
| 4096 | } else if (hw->mac.type != ixgbe_mac_82599EB) { |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4097 | rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK | |
| 4098 | IXGBE_RXDCTL_RLPML_EN); |
| 4099 | |
Emil Tantilov | 2bafa8f | 2018-01-12 14:02:56 -0800 | [diff] [blame] | 4100 | /* Limit the maximum frame size so we don't overrun the skb. |
| 4101 | * This can happen in SRIOV mode when the MTU of the VF is |
| 4102 | * higher than the MTU of the PF. |
| 4103 | */ |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4104 | if (ring_uses_build_skb(ring) && |
| 4105 | !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state)) |
Alexander Duyck | 541ea69 | 2017-03-02 15:01:05 -0800 | [diff] [blame] | 4106 | rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB | |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4107 | IXGBE_RXDCTL_RLPML_EN; |
| 4108 | #endif |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 4111 | /* initialize rx_buffer_info */ |
| 4112 | memset(ring->rx_buffer_info, 0, |
| 4113 | sizeof(struct ixgbe_rx_buffer) * ring->count); |
| 4114 | |
Alexander Duyck | c3630cc | 2017-01-17 08:36:28 -0800 | [diff] [blame] | 4115 | /* initialize Rx descriptor 0 */ |
| 4116 | rx_desc = IXGBE_RX_DESC(ring, 0); |
| 4117 | rx_desc->wb.upper.length = 0; |
| 4118 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4119 | /* enable receive descriptor ring */ |
| 4120 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
| 4121 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl); |
| 4122 | |
| 4123 | ixgbe_rx_desc_queue_enable(adapter, ring); |
Alexander Duyck | 7d4987d | 2011-05-27 05:31:37 +0000 | [diff] [blame] | 4124 | ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring)); |
Alexander Duyck | acd3717 | 2010-08-19 13:36:05 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4127 | static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter) |
| 4128 | { |
| 4129 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 4130 | int rss_i = adapter->ring_feature[RING_F_RSS].indices; |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 4131 | u16 pool = adapter->num_rx_pools; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4132 | |
| 4133 | /* PSRTYPE must be initialized in non 82598 adapters */ |
| 4134 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4135 | IXGBE_PSRTYPE_UDPHDR | |
| 4136 | IXGBE_PSRTYPE_IPV4HDR | |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4137 | IXGBE_PSRTYPE_L2HDR | |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 4138 | IXGBE_PSRTYPE_IPV6HDR; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4139 | |
| 4140 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4141 | return; |
| 4142 | |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 4143 | if (rss_i > 3) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4144 | psrtype |= 2u << 29; |
Alexander Duyck | fbe7ca7 | 2012-07-14 05:42:36 +0000 | [diff] [blame] | 4145 | else if (rss_i > 1) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4146 | psrtype |= 1u << 29; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4147 | |
Alexander Duyck | 2af62c5 | 2017-11-22 10:56:28 -0800 | [diff] [blame] | 4148 | while (pool--) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4149 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype); |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4150 | } |
| 4151 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4152 | static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) |
| 4153 | { |
| 4154 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 81d4e91 | 2018-04-03 17:16:09 -0400 | [diff] [blame] | 4155 | u16 pool = adapter->num_rx_pools; |
| 4156 | u32 reg_offset, vf_shift, vmolr; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4157 | u32 gcr_ext, vmdctl; |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 4158 | int i; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4159 | |
| 4160 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 4161 | return; |
| 4162 | |
| 4163 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4164 | vmdctl |= IXGBE_VMD_CTL_VMDQ_EN; |
| 4165 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4166 | vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT; |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4167 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 4168 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4169 | |
Alexander Duyck | 81d4e91 | 2018-04-03 17:16:09 -0400 | [diff] [blame] | 4170 | /* accept untagged packets until a vlan tag is |
| 4171 | * specifically set for the VMDQ queue/pool |
| 4172 | */ |
| 4173 | vmolr = IXGBE_VMOLR_AUPE; |
| 4174 | while (pool--) |
| 4175 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(pool)), vmolr); |
| 4176 | |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4177 | vf_shift = VMDQ_P(0) % 32; |
| 4178 | reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0; |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4179 | |
| 4180 | /* Enable only the PF's pool for Tx/Rx */ |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 4181 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4182 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1); |
Emil Tantilov | 11f2b49 | 2016-05-04 15:01:27 -0700 | [diff] [blame] | 4183 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift)); |
Alexander Duyck | 435b19f | 2012-05-18 06:34:08 +0000 | [diff] [blame] | 4184 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1); |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 4185 | if (adapter->bridge_mode == BRIDGE_MODE_VEB) |
Greg Rose | 9b73598 | 2012-11-08 02:41:35 +0000 | [diff] [blame] | 4186 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4187 | |
| 4188 | /* 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] | 4189 | hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0)); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4190 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4191 | /* clear VLAN promisc flag so VFTA will be updated if necessary */ |
| 4192 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4193 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4194 | /* |
| 4195 | * Set up VF register offsets for selected VT Mode, |
| 4196 | * i.e. 32 or 64 VFs for SR-IOV |
| 4197 | */ |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 4198 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 4199 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 4200 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_16; |
| 4201 | break; |
| 4202 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 4203 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_32; |
| 4204 | break; |
| 4205 | default: |
| 4206 | gcr_ext = IXGBE_GCR_EXT_VT_MODE_64; |
| 4207 | break; |
| 4208 | } |
| 4209 | |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4210 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext); |
| 4211 | |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 4212 | for (i = 0; i < adapter->num_vfs; i++) { |
Emil Tantilov | 77f192a | 2016-03-18 16:11:14 -0700 | [diff] [blame] | 4213 | /* configure spoof checking */ |
| 4214 | ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, |
| 4215 | adapter->vfinfo[i].spoofchk_enabled); |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 4216 | |
| 4217 | /* Enable/Disable RSS query feature */ |
| 4218 | ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i, |
| 4219 | adapter->vfinfo[i].rss_query_enabled); |
Greg Rose | de4c7f6 | 2011-09-29 05:57:33 +0000 | [diff] [blame] | 4220 | } |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4223 | static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4224 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4225 | struct ixgbe_hw *hw = &adapter->hw; |
| 4226 | struct net_device *netdev = adapter->netdev; |
| 4227 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4228 | struct ixgbe_ring *rx_ring; |
| 4229 | int i; |
| 4230 | u32 mhadd, hlreg0; |
Alexander Duyck | 4865452 | 2010-08-19 13:36:27 +0000 | [diff] [blame] | 4231 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4232 | #ifdef IXGBE_FCOE |
| 4233 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 4234 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 4235 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 4236 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 4237 | |
| 4238 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 4239 | |
| 4240 | /* adjust max frame to be at least the size of a standard frame */ |
| 4241 | if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN)) |
| 4242 | max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN); |
| 4243 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4244 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
| 4245 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 4246 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 4247 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 4248 | |
| 4249 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4250 | } |
| 4251 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4252 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4253 | /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */ |
| 4254 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4255 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 4256 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 4257 | /* |
| 4258 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 4259 | * the Base and Length of the Rx Descriptor Ring |
| 4260 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4261 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4262 | rx_ring = adapter->rx_ring[i]; |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 4263 | |
| 4264 | clear_ring_rsc_enabled(rx_ring); |
| 4265 | clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4266 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 4267 | |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 4268 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 4269 | set_ring_rsc_enabled(rx_ring); |
Alexander Duyck | 4f4542b | 2017-01-17 08:36:14 -0800 | [diff] [blame] | 4270 | |
| 4271 | if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state)) |
| 4272 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4273 | |
Alexander Duyck | 6f42922 | 2017-01-17 08:37:13 -0800 | [diff] [blame] | 4274 | clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4275 | if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY) |
| 4276 | continue; |
| 4277 | |
| 4278 | set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state); |
| 4279 | |
| 4280 | #if (PAGE_SIZE < 8192) |
| 4281 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
| 4282 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 4283 | |
Alexander Duyck | 541ea69 | 2017-03-02 15:01:05 -0800 | [diff] [blame] | 4284 | if (IXGBE_2K_TOO_SMALL_WITH_PADDING || |
| 4285 | (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN))) |
Alexander Duyck | 2de6aa3 | 2017-01-17 08:36:54 -0800 | [diff] [blame] | 4286 | set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state); |
| 4287 | #endif |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4288 | } |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4289 | } |
| 4290 | |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4291 | static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter) |
| 4292 | { |
| 4293 | struct ixgbe_hw *hw = &adapter->hw; |
| 4294 | u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 4295 | |
| 4296 | switch (hw->mac.type) { |
| 4297 | case ixgbe_mac_82598EB: |
| 4298 | /* |
| 4299 | * For VMDq support of different descriptor types or |
| 4300 | * buffer sizes through the use of multiple SRRCTL |
| 4301 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 4302 | * |
| 4303 | * also, the manual doesn't mention it clearly but DCA hints |
| 4304 | * will only use queue 0's tags unless this bit is set. Side |
| 4305 | * effects of setting this bit are only that SRRCTL must be |
| 4306 | * fully programmed [0..15] |
| 4307 | */ |
| 4308 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 4309 | break; |
Mark Rustad | 052a1a7 | 2015-08-08 16:19:04 -0700 | [diff] [blame] | 4310 | case ixgbe_mac_X550: |
| 4311 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4312 | case ixgbe_mac_x550em_a: |
Mark Rustad | f961dda | 2015-08-08 16:19:09 -0700 | [diff] [blame] | 4313 | if (adapter->num_vfs) |
| 4314 | rdrxctl |= IXGBE_RDRXCTL_PSP; |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 4315 | /* fall through */ |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4316 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4317 | case ixgbe_mac_X540: |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4318 | /* Disable RSC for ACK packets */ |
| 4319 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 4320 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 4321 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
| 4322 | /* hardware requires some bits to be set by default */ |
| 4323 | rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX); |
| 4324 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 4325 | break; |
| 4326 | default: |
| 4327 | /* We should do nothing since we don't know this hardware */ |
| 4328 | return; |
| 4329 | } |
| 4330 | |
| 4331 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 4332 | } |
| 4333 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4334 | /** |
| 4335 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
| 4336 | * @adapter: board private structure |
| 4337 | * |
| 4338 | * Configure the Rx unit of the MAC after a reset. |
| 4339 | **/ |
| 4340 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 4341 | { |
| 4342 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4343 | int i; |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4344 | u32 rxctrl, rfctl; |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4345 | |
| 4346 | /* disable receives while setting up the descriptors */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4347 | hw->mac.ops.disable_rx(hw); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4348 | |
| 4349 | ixgbe_setup_psrtype(adapter); |
Alexander Duyck | 7367096 | 2010-08-19 13:38:34 +0000 | [diff] [blame] | 4350 | ixgbe_setup_rdrxctl(adapter); |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4351 | |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4352 | /* RSC Setup */ |
| 4353 | rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL); |
| 4354 | rfctl &= ~IXGBE_RFCTL_RSC_DIS; |
| 4355 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) |
| 4356 | rfctl |= IXGBE_RFCTL_RSC_DIS; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4357 | |
| 4358 | /* disable NFS filtering */ |
| 4359 | rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS); |
Jacob Keller | 6dcc28b | 2013-07-17 02:53:23 +0000 | [diff] [blame] | 4360 | IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl); |
| 4361 | |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4362 | /* Program registers for the distribution of queues */ |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4363 | ixgbe_setup_mrqc(adapter); |
Alexander Duyck | f5b4a52 | 2010-08-19 13:38:57 +0000 | [diff] [blame] | 4364 | |
Alexander Duyck | 477de6e | 2010-08-19 13:38:11 +0000 | [diff] [blame] | 4365 | /* set_rx_buffer_len must be called before ring initialization */ |
| 4366 | ixgbe_set_rx_buffer_len(adapter); |
| 4367 | |
| 4368 | /* |
| 4369 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 4370 | * the Base and Length of the Rx Descriptor Ring |
| 4371 | */ |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4372 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4373 | ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4374 | |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 4375 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
Alexander Duyck | 9e10e04 | 2010-08-19 13:40:06 +0000 | [diff] [blame] | 4376 | /* disable drop enable for 82598 parts */ |
| 4377 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4378 | rxctrl |= IXGBE_RXCTRL_DMBYPS; |
| 4379 | |
| 4380 | /* enable all receives */ |
| 4381 | rxctrl |= IXGBE_RXCTRL_RXEN; |
| 4382 | hw->mac.ops.enable_rx_dma(hw, rxctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4383 | } |
| 4384 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4385 | static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, |
| 4386 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4387 | { |
| 4388 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4389 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4390 | |
| 4391 | /* add VID to filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4392 | if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4393 | hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid); |
| 4394 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4395 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4396 | |
| 4397 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4398 | } |
| 4399 | |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4400 | static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan) |
| 4401 | { |
| 4402 | u32 vlvf; |
| 4403 | int idx; |
| 4404 | |
| 4405 | /* short cut the special case */ |
| 4406 | if (vlan == 0) |
| 4407 | return 0; |
| 4408 | |
| 4409 | /* Search for the vlan id in the VLVF entries */ |
| 4410 | for (idx = IXGBE_VLVF_ENTRIES; --idx;) { |
| 4411 | vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx)); |
| 4412 | if ((vlvf & VLAN_VID_MASK) == vlan) |
| 4413 | break; |
| 4414 | } |
| 4415 | |
| 4416 | return idx; |
| 4417 | } |
| 4418 | |
| 4419 | void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid) |
| 4420 | { |
| 4421 | struct ixgbe_hw *hw = &adapter->hw; |
| 4422 | u32 bits, word; |
| 4423 | int idx; |
| 4424 | |
| 4425 | idx = ixgbe_find_vlvf_entry(hw, vid); |
| 4426 | if (!idx) |
| 4427 | return; |
| 4428 | |
| 4429 | /* See if any other pools are set for this VLAN filter |
| 4430 | * entry other than the PF. |
| 4431 | */ |
| 4432 | word = idx * 2 + (VMDQ_P(0) / 32); |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4433 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4434 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4435 | |
| 4436 | /* Disable the filter so this falls into the default pool. */ |
| 4437 | if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) { |
| 4438 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4439 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0); |
| 4440 | IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0); |
| 4441 | } |
| 4442 | } |
| 4443 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4444 | static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, |
| 4445 | __be16 proto, u16 vid) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4446 | { |
| 4447 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4448 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4449 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4450 | /* remove VID from filter table */ |
Alexander Duyck | 18be4fc | 2016-01-06 22:48:44 -0800 | [diff] [blame] | 4451 | if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
Alexander Duyck | e1d0a2a | 2015-11-02 17:10:19 -0800 | [diff] [blame] | 4452 | hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true); |
| 4453 | |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4454 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 4455 | |
| 4456 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4457 | } |
| 4458 | |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4459 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4460 | * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping |
| 4461 | * @adapter: driver data |
| 4462 | */ |
| 4463 | static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter) |
| 4464 | { |
| 4465 | struct ixgbe_hw *hw = &adapter->hw; |
| 4466 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4467 | int i, j; |
| 4468 | |
| 4469 | switch (hw->mac.type) { |
| 4470 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4471 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4472 | vlnctrl &= ~IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4473 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4474 | break; |
| 4475 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4476 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4477 | case ixgbe_mac_X550: |
| 4478 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4479 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4480 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4481 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4482 | |
Alexander Duyck | 68ae742 | 2017-11-22 10:56:52 -0800 | [diff] [blame] | 4483 | if (!netif_is_ixgbe(ring->netdev)) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4484 | continue; |
Alexander Duyck | 68ae742 | 2017-11-22 10:56:52 -0800 | [diff] [blame] | 4485 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4486 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4487 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4488 | vlnctrl &= ~IXGBE_RXDCTL_VME; |
| 4489 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4490 | } |
| 4491 | break; |
| 4492 | default: |
| 4493 | break; |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | /** |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4498 | * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4499 | * @adapter: driver data |
| 4500 | */ |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4501 | static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4502 | { |
| 4503 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4504 | u32 vlnctrl; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4505 | int i, j; |
| 4506 | |
| 4507 | switch (hw->mac.type) { |
| 4508 | case ixgbe_mac_82598EB: |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4509 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4510 | vlnctrl |= IXGBE_VLNCTRL_VME; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4511 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4512 | break; |
| 4513 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 4514 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 4515 | case ixgbe_mac_X550: |
| 4516 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 4517 | case ixgbe_mac_x550em_a: |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4518 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4519 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 4520 | |
Alexander Duyck | 68ae742 | 2017-11-22 10:56:52 -0800 | [diff] [blame] | 4521 | if (!netif_is_ixgbe(ring->netdev)) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4522 | continue; |
Alexander Duyck | 68ae742 | 2017-11-22 10:56:52 -0800 | [diff] [blame] | 4523 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 4524 | j = ring->reg_idx; |
Jesse Brandeburg | 5f6c018 | 2010-04-14 16:04:23 -0700 | [diff] [blame] | 4525 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 4526 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 4527 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 4528 | } |
| 4529 | break; |
| 4530 | default: |
| 4531 | break; |
| 4532 | } |
| 4533 | } |
| 4534 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4535 | static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter) |
| 4536 | { |
| 4537 | struct ixgbe_hw *hw = &adapter->hw; |
| 4538 | u32 vlnctrl, i; |
| 4539 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4540 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4541 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4542 | if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) { |
| 4543 | /* For VMDq and SR-IOV we must leave VLAN filtering enabled */ |
| 4544 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4545 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4546 | } else { |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4547 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4548 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4549 | return; |
| 4550 | } |
| 4551 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4552 | /* Nothing to do for 82598 */ |
| 4553 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4554 | return; |
| 4555 | |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4556 | /* We are already in VLAN promisc, nothing to do */ |
| 4557 | if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC) |
| 4558 | return; |
| 4559 | |
| 4560 | /* Set flag so we don't redo unnecessary work */ |
| 4561 | adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC; |
| 4562 | |
| 4563 | /* Add PF to all active pools */ |
| 4564 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4565 | u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32); |
| 4566 | u32 vlvfb = IXGBE_READ_REG(hw, reg_offset); |
| 4567 | |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4568 | vlvfb |= BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4569 | IXGBE_WRITE_REG(hw, reg_offset, vlvfb); |
| 4570 | } |
| 4571 | |
| 4572 | /* Set all bits in the VLAN filter table array */ |
| 4573 | for (i = hw->mac.vft_size; i--;) |
| 4574 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U); |
| 4575 | } |
| 4576 | |
| 4577 | #define VFTA_BLOCK_SIZE 8 |
| 4578 | static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset) |
| 4579 | { |
| 4580 | struct ixgbe_hw *hw = &adapter->hw; |
| 4581 | u32 vfta[VFTA_BLOCK_SIZE] = { 0 }; |
| 4582 | u32 vid_start = vfta_offset * 32; |
| 4583 | u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32); |
| 4584 | u32 i, vid, word, bits; |
| 4585 | |
| 4586 | for (i = IXGBE_VLVF_ENTRIES; --i;) { |
| 4587 | u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i)); |
| 4588 | |
| 4589 | /* pull VLAN ID from VLVF */ |
| 4590 | vid = vlvf & VLAN_VID_MASK; |
| 4591 | |
| 4592 | /* only concern outselves with a certain range */ |
| 4593 | if (vid < vid_start || vid >= vid_end) |
| 4594 | continue; |
| 4595 | |
| 4596 | if (vlvf) { |
| 4597 | /* record VLAN ID in VFTA */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4598 | vfta[(vid - vid_start) / 32] |= BIT(vid % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4599 | |
| 4600 | /* if PF is part of this then continue */ |
| 4601 | if (test_bit(vid, adapter->active_vlans)) |
| 4602 | continue; |
| 4603 | } |
| 4604 | |
| 4605 | /* remove PF from the pool */ |
| 4606 | word = i * 2 + VMDQ_P(0) / 32; |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 4607 | bits = ~BIT(VMDQ_P(0) % 32); |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4608 | bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word)); |
| 4609 | IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits); |
| 4610 | } |
| 4611 | |
| 4612 | /* extract values from active_vlans and write back to VFTA */ |
| 4613 | for (i = VFTA_BLOCK_SIZE; i--;) { |
| 4614 | vid = (vfta_offset + i) * 32; |
| 4615 | word = vid / BITS_PER_LONG; |
| 4616 | bits = vid % BITS_PER_LONG; |
| 4617 | |
| 4618 | vfta[i] |= adapter->active_vlans[word] >> bits; |
| 4619 | |
| 4620 | IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]); |
| 4621 | } |
| 4622 | } |
| 4623 | |
| 4624 | static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter) |
| 4625 | { |
| 4626 | struct ixgbe_hw *hw = &adapter->hw; |
| 4627 | u32 vlnctrl, i; |
| 4628 | |
Alexander Duyck | f60439b | 2016-08-11 14:51:56 -0700 | [diff] [blame] | 4629 | /* Set VLAN filtering to enabled */ |
| 4630 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
| 4631 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 4632 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 4633 | |
Emil Tantilov | 691e412 | 2016-08-22 16:17:46 -0700 | [diff] [blame] | 4634 | if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) || |
| 4635 | hw->mac.type == ixgbe_mac_82598EB) |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4636 | return; |
Alexander Duyck | 1636956 | 2015-11-02 17:10:13 -0800 | [diff] [blame] | 4637 | |
| 4638 | /* We are not in VLAN promisc, nothing to do */ |
| 4639 | if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)) |
| 4640 | return; |
| 4641 | |
| 4642 | /* Set flag so we don't redo unnecessary work */ |
| 4643 | adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC; |
| 4644 | |
| 4645 | for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE) |
| 4646 | ixgbe_scrub_vfta(adapter, i); |
| 4647 | } |
| 4648 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4649 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 4650 | { |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4651 | u16 vid = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4652 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4653 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4654 | |
Alexander Duyck | 06bb1c3 | 2016-01-06 22:48:50 -0800 | [diff] [blame] | 4655 | for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID) |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 4656 | ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | /** |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4660 | * ixgbe_write_mc_addr_list - write multicast addresses to MTA |
| 4661 | * @netdev: network interface device structure |
| 4662 | * |
| 4663 | * Writes multicast address list to the MTA hash table. |
| 4664 | * Returns: -ENOMEM on failure |
| 4665 | * 0 on no addresses written |
| 4666 | * X on writing X addresses to MTA |
| 4667 | **/ |
| 4668 | static int ixgbe_write_mc_addr_list(struct net_device *netdev) |
| 4669 | { |
| 4670 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4671 | struct ixgbe_hw *hw = &adapter->hw; |
| 4672 | |
| 4673 | if (!netif_running(netdev)) |
| 4674 | return 0; |
| 4675 | |
| 4676 | if (hw->mac.ops.update_mc_addr_list) |
| 4677 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 4678 | else |
| 4679 | return -ENOMEM; |
| 4680 | |
| 4681 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4682 | ixgbe_restore_vf_multicasts(adapter); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4683 | #endif |
| 4684 | |
| 4685 | return netdev_mc_count(netdev); |
| 4686 | } |
| 4687 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4688 | #ifdef CONFIG_PCI_IOV |
| 4689 | void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4690 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4691 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4692 | struct ixgbe_hw *hw = &adapter->hw; |
| 4693 | int i; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4694 | |
| 4695 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4696 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4697 | |
| 4698 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4699 | hw->mac.ops.set_rar(hw, i, |
| 4700 | mac_table->addr, |
| 4701 | mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4702 | IXGBE_RAH_AV); |
| 4703 | else |
| 4704 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4705 | } |
| 4706 | } |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4707 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4708 | #endif |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4709 | static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter) |
| 4710 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4711 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4712 | struct ixgbe_hw *hw = &adapter->hw; |
| 4713 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4714 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4715 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4716 | if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED)) |
| 4717 | continue; |
| 4718 | |
| 4719 | mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED; |
| 4720 | |
| 4721 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
| 4722 | hw->mac.ops.set_rar(hw, i, |
| 4723 | mac_table->addr, |
| 4724 | mac_table->pool, |
| 4725 | IXGBE_RAH_AV); |
| 4726 | else |
| 4727 | hw->mac.ops.clear_rar(hw, i); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4728 | } |
| 4729 | } |
| 4730 | |
| 4731 | static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter) |
| 4732 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4733 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4734 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4735 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4736 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4737 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4738 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4739 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4740 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4741 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4742 | ixgbe_sync_mac_table(adapter); |
| 4743 | } |
| 4744 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4745 | static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4746 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4747 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4748 | struct ixgbe_hw *hw = &adapter->hw; |
| 4749 | int i, count = 0; |
| 4750 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4751 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4752 | /* do not count default RAR as available */ |
| 4753 | if (mac_table->state & IXGBE_MAC_STATE_DEFAULT) |
| 4754 | continue; |
| 4755 | |
| 4756 | /* only count unused and addresses that belong to us */ |
| 4757 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) { |
| 4758 | if (mac_table->pool != pool) |
| 4759 | continue; |
| 4760 | } |
| 4761 | |
| 4762 | count++; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4763 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4764 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4765 | return count; |
| 4766 | } |
| 4767 | |
| 4768 | /* this function destroys the first RAR entry */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4769 | static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4770 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4771 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4772 | struct ixgbe_hw *hw = &adapter->hw; |
| 4773 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4774 | memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN); |
| 4775 | mac_table->pool = VMDQ_P(0); |
| 4776 | |
| 4777 | mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE; |
| 4778 | |
| 4779 | hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool, |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4780 | IXGBE_RAH_AV); |
| 4781 | } |
| 4782 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4783 | int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter, |
| 4784 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4785 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4786 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4787 | struct ixgbe_hw *hw = &adapter->hw; |
| 4788 | int i; |
| 4789 | |
| 4790 | if (is_zero_ether_addr(addr)) |
| 4791 | return -EINVAL; |
| 4792 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4793 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4794 | if (mac_table->state & IXGBE_MAC_STATE_IN_USE) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4795 | continue; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4796 | |
| 4797 | ether_addr_copy(mac_table->addr, addr); |
| 4798 | mac_table->pool = pool; |
| 4799 | |
| 4800 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED | |
| 4801 | IXGBE_MAC_STATE_IN_USE; |
| 4802 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4803 | ixgbe_sync_mac_table(adapter); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4804 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4805 | return i; |
| 4806 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4807 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4808 | return -ENOMEM; |
| 4809 | } |
| 4810 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4811 | int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter, |
| 4812 | const u8 *addr, u16 pool) |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4813 | { |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4814 | struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0]; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4815 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4816 | int i; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4817 | |
| 4818 | if (is_zero_ether_addr(addr)) |
| 4819 | return -EINVAL; |
| 4820 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4821 | /* search table for addr, if found clear IN_USE flag and sync */ |
| 4822 | for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) { |
| 4823 | /* we can only delete an entry if it is in use */ |
| 4824 | if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE)) |
| 4825 | continue; |
| 4826 | /* we only care about entries that belong to the given pool */ |
| 4827 | if (mac_table->pool != pool) |
| 4828 | continue; |
| 4829 | /* we only care about a specific MAC address */ |
| 4830 | if (!ether_addr_equal(addr, mac_table->addr)) |
| 4831 | continue; |
| 4832 | |
| 4833 | mac_table->state |= IXGBE_MAC_STATE_MODIFIED; |
| 4834 | mac_table->state &= ~IXGBE_MAC_STATE_IN_USE; |
| 4835 | |
| 4836 | ixgbe_sync_mac_table(adapter); |
| 4837 | |
| 4838 | return 0; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4839 | } |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 4840 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 4841 | return -ENOMEM; |
| 4842 | } |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 4843 | |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4844 | static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr) |
| 4845 | { |
| 4846 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4847 | int ret; |
| 4848 | |
| 4849 | ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4850 | |
| 4851 | return min_t(int, ret, 0); |
| 4852 | } |
| 4853 | |
| 4854 | static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr) |
| 4855 | { |
| 4856 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4857 | |
| 4858 | ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0)); |
| 4859 | |
| 4860 | return 0; |
| 4861 | } |
| 4862 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4863 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4864 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4865 | * @netdev: network interface device structure |
| 4866 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 4867 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 4868 | * address list or the network interface flags are updated. This routine is |
| 4869 | * responsible for configuring the hardware for proper unicast, multicast and |
| 4870 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4871 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 4872 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4873 | { |
| 4874 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4875 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4876 | u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4877 | netdev_features_t features = netdev->features; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4878 | int count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4879 | |
| 4880 | /* Check for Promiscuous and All Multicast modes */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4881 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4882 | |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4883 | /* set all bits that we expect to always be set */ |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4884 | fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */ |
Alexander Duyck | f5dc442 | 2010-08-19 13:36:49 +0000 | [diff] [blame] | 4885 | fctrl |= IXGBE_FCTRL_BAM; |
| 4886 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
| 4887 | fctrl |= IXGBE_FCTRL_PMCF; |
| 4888 | |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4889 | /* clear the bits we are changing the status of */ |
| 4890 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4891 | if (netdev->flags & IFF_PROMISC) { |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4892 | hw->addr_ctrl.user_set_promisc = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4893 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4894 | vmolr |= IXGBE_VMOLR_MPE; |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4895 | features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4896 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4897 | if (netdev->flags & IFF_ALLMULTI) { |
| 4898 | fctrl |= IXGBE_FCTRL_MPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4899 | vmolr |= IXGBE_VMOLR_MPE; |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 4900 | } |
Emil Tantilov | e433ea1 | 2010-05-13 17:33:00 +0000 | [diff] [blame] | 4901 | hw->addr_ctrl.user_set_promisc = false; |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4902 | } |
| 4903 | |
| 4904 | /* |
| 4905 | * Write addresses to available RAR registers, if there is not |
| 4906 | * sufficient space to store all the addresses then enable |
| 4907 | * unicast promiscuous mode |
| 4908 | */ |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 4909 | if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) { |
John Fastabend | 9dcb373 | 2012-04-15 06:44:25 +0000 | [diff] [blame] | 4910 | fctrl |= IXGBE_FCTRL_UPE; |
| 4911 | vmolr |= IXGBE_VMOLR_ROPE; |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
Emil Tantilov | cf78959 | 2013-10-26 08:13:20 +0000 | [diff] [blame] | 4914 | /* Write addresses to the MTA, if the attempt fails |
| 4915 | * then we should just turn on promiscuous mode so |
| 4916 | * that we can at least receive multicast traffic |
| 4917 | */ |
Jacob Keller | b335e75 | 2014-03-25 07:45:27 +0000 | [diff] [blame] | 4918 | count = ixgbe_write_mc_addr_list(netdev); |
| 4919 | if (count < 0) { |
| 4920 | fctrl |= IXGBE_FCTRL_MPE; |
| 4921 | vmolr |= IXGBE_VMOLR_MPE; |
| 4922 | } else if (count) { |
| 4923 | vmolr |= IXGBE_VMOLR_ROMPE; |
| 4924 | } |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4925 | |
| 4926 | if (hw->mac.type != ixgbe_mac_82598EB) { |
| 4927 | vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) & |
Alexander Duyck | 2850062 | 2010-06-15 09:25:48 +0000 | [diff] [blame] | 4928 | ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE | |
| 4929 | IXGBE_VMOLR_ROPE); |
Alexander Duyck | 1d9c0bf | 2012-05-05 05:32:21 +0000 | [diff] [blame] | 4930 | IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4931 | } |
| 4932 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4933 | /* This is useful for sniffing bad packets. */ |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4934 | if (features & NETIF_F_RXALL) { |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 4935 | /* UPE and MPE will be handled by normal PROMISC logic |
| 4936 | * in e1000e_set_rx_mode */ |
| 4937 | fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */ |
| 4938 | IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */ |
| 4939 | IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */ |
| 4940 | |
| 4941 | fctrl &= ~(IXGBE_FCTRL_DPF); |
| 4942 | /* NOTE: VLAN filtering is disabled by setting PROMISC */ |
| 4943 | } |
| 4944 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4945 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4946 | |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4947 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 4948 | ixgbe_vlan_strip_enable(adapter); |
| 4949 | else |
| 4950 | ixgbe_vlan_strip_disable(adapter); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 4951 | |
| 4952 | if (features & NETIF_F_HW_VLAN_CTAG_FILTER) |
| 4953 | ixgbe_vlan_promisc_disable(adapter); |
| 4954 | else |
| 4955 | ixgbe_vlan_promisc_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4956 | } |
| 4957 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4958 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 4959 | { |
| 4960 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4961 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4962 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4963 | napi_enable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 4967 | { |
| 4968 | int q_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4969 | |
Eric Dumazet | 3ffc1af | 2017-02-02 16:26:39 -0800 | [diff] [blame] | 4970 | for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++) |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 4971 | napi_disable(&adapter->q_vector[q_idx]->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4972 | } |
| 4973 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4974 | static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4975 | { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4976 | struct ixgbe_hw *hw = &adapter->hw; |
| 4977 | u32 vxlanctrl; |
| 4978 | |
| 4979 | if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE | |
| 4980 | IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))) |
| 4981 | return; |
| 4982 | |
Sabrina Dubroca | a39221c | 2017-07-03 13:02:55 +0200 | [diff] [blame] | 4983 | vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4984 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl); |
| 4985 | |
| 4986 | if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4987 | adapter->vxlan_port = 0; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 4988 | |
| 4989 | if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK) |
| 4990 | adapter->geneve_port = 0; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 4991 | } |
| 4992 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4993 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 4994 | /** |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4995 | * ixgbe_configure_dcb - Configure DCB hardware |
| 4996 | * @adapter: ixgbe adapter struct |
| 4997 | * |
| 4998 | * This is called by the driver on open to configure the DCB hardware. |
| 4999 | * This is also called by the gennetlink interface when reconfiguring |
| 5000 | * the DCB state. |
| 5001 | */ |
| 5002 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 5003 | { |
| 5004 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 9806307a | 2010-10-28 00:59:57 +0000 | [diff] [blame] | 5005 | int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5006 | |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5007 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) { |
| 5008 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 5009 | netif_set_gso_max_size(adapter->netdev, 65536); |
| 5010 | return; |
| 5011 | } |
| 5012 | |
| 5013 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 5014 | netif_set_gso_max_size(adapter->netdev, 32768); |
| 5015 | |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 5016 | #ifdef IXGBE_FCOE |
| 5017 | if (adapter->netdev->features & NETIF_F_FCOE_MTU) |
| 5018 | max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); |
| 5019 | #endif |
| 5020 | |
Alexander Duyck | 01fa7d9 | 2010-11-16 19:26:53 -0800 | [diff] [blame] | 5021 | /* reconfigure the hardware */ |
John Fastabend | 6f70f6a | 2011-04-26 07:26:25 +0000 | [diff] [blame] | 5022 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) { |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 5023 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 5024 | DCB_TX_CONFIG); |
| 5025 | ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, |
| 5026 | DCB_RX_CONFIG); |
| 5027 | ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); |
John Fastabend | b120818 | 2011-10-15 05:00:10 +0000 | [diff] [blame] | 5028 | } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) { |
| 5029 | ixgbe_dcb_hw_ets(&adapter->hw, |
| 5030 | adapter->ixgbe_ieee_ets, |
| 5031 | max_frame); |
| 5032 | ixgbe_dcb_hw_pfc_config(&adapter->hw, |
| 5033 | adapter->ixgbe_ieee_pfc->pfc_en, |
| 5034 | adapter->ixgbe_ieee_ets->prio_tc); |
John Fastabend | c27931d | 2011-02-23 05:58:25 +0000 | [diff] [blame] | 5035 | } |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5036 | |
| 5037 | /* Enable RSS Hash per TC */ |
| 5038 | if (hw->mac.type != ixgbe_mac_82598EB) { |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 5039 | u32 msb = 0; |
| 5040 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5041 | |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 5042 | while (rss_i) { |
| 5043 | msb++; |
| 5044 | rss_i >>= 1; |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5045 | } |
Alexander Duyck | d411a93 | 2012-06-30 00:14:01 +0000 | [diff] [blame] | 5046 | |
Alexander Duyck | 4ae6373 | 2012-06-22 06:46:33 +0000 | [diff] [blame] | 5047 | /* write msb to all 8 TCs in one write */ |
| 5048 | IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111); |
John Fastabend | 8187cd4 | 2011-02-23 05:58:08 +0000 | [diff] [blame] | 5049 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5050 | } |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5051 | #endif |
| 5052 | |
| 5053 | /* Additional bittime to account for IXGBE framing */ |
| 5054 | #define IXGBE_ETH_FRAMING 20 |
| 5055 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5056 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5057 | * ixgbe_hpbthresh - calculate high water mark for flow control |
| 5058 | * |
| 5059 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5060 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5061 | */ |
| 5062 | static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb) |
| 5063 | { |
| 5064 | struct ixgbe_hw *hw = &adapter->hw; |
| 5065 | struct net_device *dev = adapter->netdev; |
| 5066 | int link, tc, kb, marker; |
| 5067 | u32 dv_id, rx_pba; |
| 5068 | |
| 5069 | /* Calculate max LAN frame size */ |
| 5070 | tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING; |
| 5071 | |
| 5072 | #ifdef IXGBE_FCOE |
| 5073 | /* FCoE traffic class uses FCOE jumbo frames */ |
Alexander Duyck | 800bd60 | 2012-06-02 00:11:02 +0000 | [diff] [blame] | 5074 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 5075 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 5076 | (pb == ixgbe_fcoe_get_tc(adapter))) |
| 5077 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5078 | #endif |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5079 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5080 | /* Calculate delay value for device */ |
| 5081 | switch (hw->mac.type) { |
| 5082 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5083 | case ixgbe_mac_X550: |
| 5084 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5085 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5086 | dv_id = IXGBE_DV_X540(link, tc); |
| 5087 | break; |
| 5088 | default: |
| 5089 | dv_id = IXGBE_DV(link, tc); |
| 5090 | break; |
| 5091 | } |
| 5092 | |
| 5093 | /* Loopback switch introduces additional latency */ |
| 5094 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5095 | dv_id += IXGBE_B2BT(tc); |
| 5096 | |
| 5097 | /* Delay value is calculated in bit times convert to KB */ |
| 5098 | kb = IXGBE_BT2KB(dv_id); |
| 5099 | rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10; |
| 5100 | |
| 5101 | marker = rx_pba - kb; |
| 5102 | |
| 5103 | /* It is possible that the packet buffer is not large enough |
| 5104 | * to provide required headroom. In this case throw an error |
| 5105 | * to user and a do the best we can. |
| 5106 | */ |
| 5107 | if (marker < 0) { |
| 5108 | e_warn(drv, "Packet Buffer(%i) can not provide enough" |
| 5109 | "headroom to support flow control." |
| 5110 | "Decrease MTU or number of traffic classes\n", pb); |
| 5111 | marker = tc + 1; |
| 5112 | } |
| 5113 | |
| 5114 | return marker; |
| 5115 | } |
| 5116 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5117 | /** |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5118 | * ixgbe_lpbthresh - calculate low water mark for for flow control |
| 5119 | * |
| 5120 | * @adapter: board private structure to calculate for |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 5121 | * @pb: packet buffer to calculate |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5122 | */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5123 | static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb) |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5124 | { |
| 5125 | struct ixgbe_hw *hw = &adapter->hw; |
| 5126 | struct net_device *dev = adapter->netdev; |
| 5127 | int tc; |
| 5128 | u32 dv_id; |
| 5129 | |
| 5130 | /* Calculate max LAN frame size */ |
| 5131 | tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 5132 | |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5133 | #ifdef IXGBE_FCOE |
| 5134 | /* FCoE traffic class uses FCOE jumbo frames */ |
| 5135 | if ((dev->features & NETIF_F_FCOE_MTU) && |
| 5136 | (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 5137 | (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up))) |
| 5138 | tc = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 5139 | #endif |
| 5140 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5141 | /* Calculate delay value for device */ |
| 5142 | switch (hw->mac.type) { |
| 5143 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5144 | case ixgbe_mac_X550: |
| 5145 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5146 | case ixgbe_mac_x550em_a: |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5147 | dv_id = IXGBE_LOW_DV_X540(tc); |
| 5148 | break; |
| 5149 | default: |
| 5150 | dv_id = IXGBE_LOW_DV(tc); |
| 5151 | break; |
| 5152 | } |
| 5153 | |
| 5154 | /* Delay value is calculated in bit times convert to KB */ |
| 5155 | return IXGBE_BT2KB(dv_id); |
| 5156 | } |
| 5157 | |
| 5158 | /* |
| 5159 | * ixgbe_pbthresh_setup - calculate and setup high low water marks |
| 5160 | */ |
| 5161 | static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter) |
| 5162 | { |
| 5163 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 5164 | int num_tc = adapter->hw_tcs; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5165 | int i; |
| 5166 | |
| 5167 | if (!num_tc) |
| 5168 | num_tc = 1; |
| 5169 | |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5170 | for (i = 0; i < num_tc; i++) { |
| 5171 | hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i); |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5172 | hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5173 | |
| 5174 | /* Low water marks must not be larger than high water marks */ |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5175 | if (hw->fc.low_water[i] > hw->fc.high_water[i]) |
| 5176 | hw->fc.low_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5177 | } |
Jacob Keller | e577662 | 2014-04-05 02:35:52 +0000 | [diff] [blame] | 5178 | |
| 5179 | for (; i < MAX_TRAFFIC_CLASS; i++) |
| 5180 | hw->fc.high_water[i] = 0; |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5181 | } |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5182 | |
| 5183 | static void ixgbe_configure_pb(struct ixgbe_adapter *adapter) |
| 5184 | { |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5185 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 5186 | int hdrm; |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 5187 | u8 tc = adapter->hw_tcs; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5188 | |
| 5189 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5190 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 5191 | hdrm = 32 << adapter->fdir_pballoc; |
| 5192 | else |
| 5193 | hdrm = 0; |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5194 | |
Alexander Duyck | f7e1027 | 2011-07-21 00:40:35 +0000 | [diff] [blame] | 5195 | hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL); |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 5196 | ixgbe_pbthresh_setup(adapter); |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5197 | } |
| 5198 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5199 | static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter) |
| 5200 | { |
| 5201 | struct ixgbe_hw *hw = &adapter->hw; |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5202 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5203 | struct ixgbe_fdir_filter *filter; |
| 5204 | |
| 5205 | spin_lock(&adapter->fdir_perfect_lock); |
| 5206 | |
| 5207 | if (!hlist_empty(&adapter->fdir_filter_list)) |
| 5208 | ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask); |
| 5209 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5210 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5211 | &adapter->fdir_filter_list, fdir_node) { |
| 5212 | ixgbe_fdir_write_perfect_filter_82599(hw, |
Alexander Duyck | 1f4d518 | 2011-05-14 01:16:02 +0000 | [diff] [blame] | 5213 | &filter->filter, |
| 5214 | filter->sw_idx, |
| 5215 | (filter->action == IXGBE_FDIR_DROP_QUEUE) ? |
| 5216 | IXGBE_FDIR_DROP_QUEUE : |
| 5217 | adapter->rx_ring[filter->action]->reg_idx); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5221 | } |
| 5222 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5223 | /** |
| 5224 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 5225 | * @rx_ring: ring to free buffers from |
| 5226 | **/ |
| 5227 | static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring) |
| 5228 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5229 | u16 i = rx_ring->next_to_clean; |
| 5230 | struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i]; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5231 | |
| 5232 | /* Free all the Rx ring sk_buffs */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5233 | while (i != rx_ring->next_to_alloc) { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5234 | if (rx_buffer->skb) { |
| 5235 | struct sk_buff *skb = rx_buffer->skb; |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5236 | if (IXGBE_CB(skb)->page_released) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5237 | dma_unmap_page_attrs(rx_ring->dev, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5238 | IXGBE_CB(skb)->dma, |
| 5239 | ixgbe_rx_pg_size(rx_ring), |
| 5240 | DMA_FROM_DEVICE, |
| 5241 | IXGBE_RX_DMA_ATTR); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5242 | dev_kfree_skb(skb); |
| 5243 | } |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5244 | |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5245 | /* Invalidate cache lines that may have been written to by |
| 5246 | * device so that we avoid corrupting memory. |
| 5247 | */ |
| 5248 | dma_sync_single_range_for_cpu(rx_ring->dev, |
| 5249 | rx_buffer->dma, |
| 5250 | rx_buffer->page_offset, |
| 5251 | ixgbe_rx_bufsz(rx_ring), |
| 5252 | DMA_FROM_DEVICE); |
| 5253 | |
| 5254 | /* free resources associated with mapping */ |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5255 | dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
Alexander Duyck | f3213d9 | 2017-01-17 08:35:54 -0800 | [diff] [blame] | 5256 | ixgbe_rx_pg_size(rx_ring), |
| 5257 | DMA_FROM_DEVICE, |
| 5258 | IXGBE_RX_DMA_ATTR); |
Alexander Duyck | 1b56cf4 | 2017-01-17 08:36:03 -0800 | [diff] [blame] | 5259 | __page_frag_cache_drain(rx_buffer->page, |
| 5260 | rx_buffer->pagecnt_bias); |
Alexander Duyck | 18cb652 | 2014-11-14 00:56:29 +0000 | [diff] [blame] | 5261 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5262 | i++; |
| 5263 | rx_buffer++; |
| 5264 | if (i == rx_ring->count) { |
| 5265 | i = 0; |
| 5266 | rx_buffer = rx_ring->rx_buffer_info; |
| 5267 | } |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5268 | } |
| 5269 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5270 | rx_ring->next_to_alloc = 0; |
| 5271 | rx_ring->next_to_clean = 0; |
| 5272 | rx_ring->next_to_use = 0; |
| 5273 | } |
| 5274 | |
Alexander Duyck | 865255b | 2018-04-03 17:16:40 -0400 | [diff] [blame] | 5275 | static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5276 | struct ixgbe_fwd_adapter *accel) |
| 5277 | { |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 5278 | u16 rss_i = adapter->ring_feature[RING_F_RSS].indices; |
| 5279 | int num_tc = netdev_get_num_tc(adapter->netdev); |
Alexander Duyck | 865255b | 2018-04-03 17:16:40 -0400 | [diff] [blame] | 5280 | struct net_device *vdev = accel->netdev; |
Alexander Duyck | 16be45b | 2017-11-22 10:57:23 -0800 | [diff] [blame] | 5281 | int i, baseq, err; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5282 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5283 | baseq = accel->pool * adapter->num_rx_queues_per_pool; |
Alexander Duyck | 4e039c1 | 2017-11-22 10:56:40 -0800 | [diff] [blame] | 5284 | netdev_dbg(vdev, "pool %i:%i queues %i:%i\n", |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5285 | accel->pool, adapter->num_rx_pools, |
Alexander Duyck | 4e039c1 | 2017-11-22 10:56:40 -0800 | [diff] [blame] | 5286 | baseq, baseq + adapter->num_rx_queues_per_pool); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5287 | |
Alexander Duyck | 16be45b | 2017-11-22 10:57:23 -0800 | [diff] [blame] | 5288 | accel->rx_base_queue = baseq; |
| 5289 | accel->tx_base_queue = baseq; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5290 | |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 5291 | /* record configuration for macvlan interface in vdev */ |
| 5292 | for (i = 0; i < num_tc; i++) |
| 5293 | netdev_bind_sb_channel_queue(adapter->netdev, vdev, |
| 5294 | i, rss_i, baseq + (rss_i * i)); |
| 5295 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5296 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
Alexander Duyck | 16be45b | 2017-11-22 10:57:23 -0800 | [diff] [blame] | 5297 | adapter->rx_ring[baseq + i]->netdev = vdev; |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 5298 | |
| 5299 | /* Guarantee all rings are updated before we update the |
| 5300 | * MAC address filter. |
| 5301 | */ |
| 5302 | wmb(); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5303 | |
Alexander Duyck | 4a2512c | 2017-11-22 10:56:59 -0800 | [diff] [blame] | 5304 | /* ixgbe_add_mac_filter will return an index if it succeeds, so we |
| 5305 | * need to only treat it as an error value if it is negative. |
| 5306 | */ |
| 5307 | err = ixgbe_add_mac_filter(adapter, vdev->dev_addr, |
| 5308 | VMDQ_P(accel->pool)); |
Alexander Duyck | 81d4e91 | 2018-04-03 17:16:09 -0400 | [diff] [blame] | 5309 | if (err >= 0) |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 5310 | return 0; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5311 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 5312 | /* if we cannot add the MAC rule then disable the offload */ |
| 5313 | macvlan_release_l2fw_offload(vdev); |
| 5314 | |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 5315 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) |
| 5316 | adapter->rx_ring[baseq + i]->netdev = NULL; |
| 5317 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 5318 | netdev_err(vdev, "L2FW offload disabled due to L2 filter error\n"); |
| 5319 | |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 5320 | /* unbind the queues and drop the subordinate channel config */ |
| 5321 | netdev_unbind_sb_channel(adapter->netdev, vdev); |
| 5322 | netdev_set_sb_channel(vdev, 0); |
| 5323 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 5324 | clear_bit(accel->pool, adapter->fwd_bitmask); |
| 5325 | kfree(accel); |
| 5326 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5327 | return err; |
| 5328 | } |
| 5329 | |
Alexander Duyck | 865255b | 2018-04-03 17:16:40 -0400 | [diff] [blame] | 5330 | static int ixgbe_macvlan_up(struct net_device *vdev, void *data) |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5331 | { |
Alexander Duyck | 865255b | 2018-04-03 17:16:40 -0400 | [diff] [blame] | 5332 | struct ixgbe_adapter *adapter = data; |
| 5333 | struct ixgbe_fwd_adapter *accel; |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5334 | |
Alexander Duyck | 865255b | 2018-04-03 17:16:40 -0400 | [diff] [blame] | 5335 | if (!netif_is_macvlan(vdev)) |
| 5336 | return 0; |
| 5337 | |
| 5338 | accel = macvlan_accel_priv(vdev); |
| 5339 | if (!accel) |
| 5340 | return 0; |
| 5341 | |
| 5342 | ixgbe_fwd_ring_up(adapter, accel); |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5343 | |
| 5344 | return 0; |
| 5345 | } |
| 5346 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5347 | static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter) |
| 5348 | { |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 5349 | netdev_walk_all_upper_dev_rcu(adapter->netdev, |
Alexander Duyck | 865255b | 2018-04-03 17:16:40 -0400 | [diff] [blame] | 5350 | ixgbe_macvlan_up, adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5351 | } |
| 5352 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5353 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 5354 | { |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5355 | struct ixgbe_hw *hw = &adapter->hw; |
| 5356 | |
John Fastabend | 80605c65 | 2011-05-02 12:34:10 +0000 | [diff] [blame] | 5357 | ixgbe_configure_pb(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5358 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 67ebd79 | 2010-08-19 13:34:04 +0000 | [diff] [blame] | 5359 | ixgbe_configure_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5360 | #endif |
Alexander Duyck | b35d4d4 | 2012-05-23 05:39:25 +0000 | [diff] [blame] | 5361 | /* |
| 5362 | * We must restore virtualization before VLANs or else |
| 5363 | * the VLVF registers will not be populated |
| 5364 | */ |
| 5365 | ixgbe_configure_virtualization(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5366 | |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5367 | ixgbe_set_rx_mode(adapter->netdev); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5368 | ixgbe_restore_vlan(adapter); |
Shannon Nelson | 6d73a15 | 2017-12-19 15:59:58 -0800 | [diff] [blame] | 5369 | ixgbe_ipsec_restore(adapter); |
Jesse Gross | f62bbb5 | 2010-10-20 13:56:10 +0000 | [diff] [blame] | 5370 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5371 | switch (hw->mac.type) { |
| 5372 | case ixgbe_mac_82599EB: |
| 5373 | case ixgbe_mac_X540: |
| 5374 | hw->mac.ops.disable_rx_buff(hw); |
| 5375 | break; |
| 5376 | default: |
| 5377 | break; |
| 5378 | } |
| 5379 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5380 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5381 | ixgbe_init_fdir_signature_82599(&adapter->hw, |
| 5382 | adapter->fdir_pballoc); |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5383 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 5384 | ixgbe_init_fdir_perfect_82599(&adapter->hw, |
| 5385 | adapter->fdir_pballoc); |
| 5386 | ixgbe_fdir_filter_restore(adapter); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5387 | } |
Alexander Duyck | 4c1d7b4 | 2011-07-21 00:40:30 +0000 | [diff] [blame] | 5388 | |
Atita Shirwaikar | d2f5e7f | 2012-02-18 02:58:58 +0000 | [diff] [blame] | 5389 | switch (hw->mac.type) { |
| 5390 | case ixgbe_mac_82599EB: |
| 5391 | case ixgbe_mac_X540: |
| 5392 | hw->mac.ops.enable_rx_buff(hw); |
| 5393 | break; |
| 5394 | default: |
| 5395 | break; |
| 5396 | } |
| 5397 | |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 5398 | #ifdef CONFIG_IXGBE_DCA |
| 5399 | /* configure DCA */ |
| 5400 | if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE) |
| 5401 | ixgbe_setup_dca(adapter); |
| 5402 | #endif /* CONFIG_IXGBE_DCA */ |
| 5403 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 5404 | #ifdef IXGBE_FCOE |
| 5405 | /* configure FCoE L2 filters, redirection table, and Rx control */ |
| 5406 | ixgbe_configure_fcoe(adapter); |
| 5407 | |
| 5408 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5409 | ixgbe_configure_tx(adapter); |
| 5410 | ixgbe_configure_rx(adapter); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 5411 | ixgbe_configure_dfwd(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5412 | } |
| 5413 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5414 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5415 | * ixgbe_sfp_link_config - set up SFP+ link |
| 5416 | * @adapter: pointer to private adapter struct |
| 5417 | **/ |
| 5418 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 5419 | { |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5420 | /* |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5421 | * We are assuming the worst case scenario here, and that |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5422 | * is that an SFP was inserted/removed after the reset |
| 5423 | * but before SFP detection was enabled. As such the best |
| 5424 | * solution is to just start searching as soon as we start |
| 5425 | */ |
| 5426 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 5427 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5428 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5429 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 5430 | adapter->sfp_poll_time = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | /** |
| 5434 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5435 | * @hw: pointer to private hardware struct |
| 5436 | * |
| 5437 | * Returns 0 on success, negative on failure |
| 5438 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5439 | 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] | 5440 | { |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5441 | u32 speed; |
| 5442 | bool autoneg, link_up = false; |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 5443 | int ret = IXGBE_ERR_LINK_SETUP; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5444 | |
| 5445 | if (hw->mac.ops.check_link) |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5446 | 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] | 5447 | |
| 5448 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5449 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5450 | |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 5451 | speed = hw->phy.autoneg_advertised; |
| 5452 | if ((!speed) && (hw->mac.ops.get_link_capabilities)) |
| 5453 | ret = hw->mac.ops.get_link_capabilities(hw, &speed, |
| 5454 | &autoneg); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5455 | if (ret) |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5456 | return ret; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5457 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5458 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 5459 | ret = hw->mac.ops.setup_link(hw, speed, link_up); |
Mark Rustad | e90dd26 | 2014-07-22 06:51:08 +0000 | [diff] [blame] | 5460 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 5461 | return ret; |
| 5462 | } |
| 5463 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5464 | static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5465 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5466 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5467 | u32 gpie = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5468 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5469 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5470 | gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT | |
| 5471 | IXGBE_GPIE_OCD; |
| 5472 | gpie |= IXGBE_GPIE_EIAME; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5473 | /* |
| 5474 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 5475 | * this saves a register write for every interrupt |
| 5476 | */ |
| 5477 | switch (hw->mac.type) { |
| 5478 | case ixgbe_mac_82598EB: |
| 5479 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 5480 | break; |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5481 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5482 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5483 | case ixgbe_mac_X550: |
| 5484 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5485 | case ixgbe_mac_x550em_a: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5486 | default: |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 5487 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 5488 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 5489 | break; |
| 5490 | } |
| 5491 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5492 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 5493 | * specifically only auto mask tx and rx interrupts */ |
| 5494 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5495 | } |
| 5496 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5497 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 5498 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 5499 | |
| 5500 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 5501 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
Alexander Duyck | 73079ea | 2012-07-14 06:48:49 +0000 | [diff] [blame] | 5502 | |
| 5503 | switch (adapter->ring_feature[RING_F_VMDQ].mask) { |
| 5504 | case IXGBE_82599_VMDQ_8Q_MASK: |
| 5505 | gpie |= IXGBE_GPIE_VTMODE_16; |
| 5506 | break; |
| 5507 | case IXGBE_82599_VMDQ_4Q_MASK: |
| 5508 | gpie |= IXGBE_GPIE_VTMODE_32; |
| 5509 | break; |
| 5510 | default: |
| 5511 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 5512 | break; |
| 5513 | } |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5516 | /* Enable Thermal over heat sensor interrupt */ |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5517 | if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) { |
| 5518 | switch (adapter->hw.mac.type) { |
| 5519 | case ixgbe_mac_82599EB: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5520 | gpie |= IXGBE_SDP0_GPIEN_8259X; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5521 | break; |
Don Skidmore | f3df98e | 2011-08-17 10:15:21 +0000 | [diff] [blame] | 5522 | default: |
| 5523 | break; |
| 5524 | } |
| 5525 | } |
Alexander Duyck | 5fdd31f | 2011-07-21 00:40:45 +0000 | [diff] [blame] | 5526 | |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5527 | /* Enable fan failure interrupt */ |
| 5528 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 5529 | gpie |= IXGBE_SDP1_GPIEN(hw); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 5530 | |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5531 | switch (hw->mac.type) { |
| 5532 | case ixgbe_mac_82599EB: |
| 5533 | gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X; |
| 5534 | break; |
| 5535 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5536 | case ixgbe_mac_x550em_a: |
Don Skidmore | a023bbd | 2015-06-24 16:38:53 -0400 | [diff] [blame] | 5537 | gpie |= IXGBE_SDP0_GPIEN_X540; |
| 5538 | break; |
| 5539 | default: |
| 5540 | break; |
Don Skidmore | 2698b20 | 2011-04-13 07:01:52 +0000 | [diff] [blame] | 5541 | } |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5542 | |
| 5543 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 5544 | } |
| 5545 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5546 | static void ixgbe_up_complete(struct ixgbe_adapter *adapter) |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5547 | { |
| 5548 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5549 | int err; |
Alexander Duyck | a34bcff | 2010-08-19 13:39:20 +0000 | [diff] [blame] | 5550 | u32 ctrl_ext; |
| 5551 | |
| 5552 | ixgbe_get_hw_control(adapter); |
| 5553 | ixgbe_setup_gpie(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5554 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5555 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 5556 | ixgbe_configure_msix(adapter); |
| 5557 | else |
| 5558 | ixgbe_configure_msi_and_legacy(adapter); |
| 5559 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5560 | /* enable the optics for 82599 SFP+ fiber */ |
| 5561 | if (hw->mac.ops.enable_tx_laser) |
Peter Waskiewicz | 61fac74 | 2010-04-27 00:38:15 +0000 | [diff] [blame] | 5562 | hw->mac.ops.enable_tx_laser(hw); |
| 5563 | |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5564 | if (hw->phy.ops.set_phy_power) |
| 5565 | hw->phy.ops.set_phy_power(hw, true); |
| 5566 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 5567 | smp_mb__before_atomic(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5568 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5569 | ixgbe_napi_enable_all(adapter); |
| 5570 | |
Alexander Duyck | 73c4b7c | 2010-11-16 19:26:57 -0800 | [diff] [blame] | 5571 | if (ixgbe_is_sfp(hw)) { |
| 5572 | ixgbe_sfp_link_config(adapter); |
| 5573 | } else { |
| 5574 | err = ixgbe_non_sfp_link_config(hw); |
| 5575 | if (err) |
| 5576 | e_err(probe, "link_config FAILED %d\n", err); |
| 5577 | } |
| 5578 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5579 | /* clear any pending interrupts, may auto mask */ |
| 5580 | IXGBE_READ_REG(hw, IXGBE_EICR); |
Emil Tantilov | 6af3b9e | 2010-09-29 21:35:23 +0000 | [diff] [blame] | 5581 | ixgbe_irq_enable(adapter, true, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5582 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5583 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5584 | * If this adapter has a fan, check to see if we had a failure |
| 5585 | * before we enabled the interrupt. |
| 5586 | */ |
| 5587 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5588 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5589 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 5590 | e_crit(drv, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5591 | } |
| 5592 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5593 | /* bring the link up in the watchdog, this could race with our first |
| 5594 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5595 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5596 | adapter->link_check_timeout = jiffies; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5597 | mod_timer(&adapter->service_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 5598 | |
| 5599 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 5600 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 5601 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 5602 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5605 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 5606 | { |
| 5607 | WARN_ON(in_interrupt()); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5608 | /* put off any impending NetWatchDogTimeout */ |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 5609 | netif_trans_update(adapter->netdev); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5610 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5611 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5612 | usleep_range(1000, 2000); |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5613 | if (adapter->hw.phy.type == ixgbe_phy_fw) |
| 5614 | ixgbe_watchdog_link_is_down(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5615 | ixgbe_down(adapter); |
Greg Rose | 5809a1a | 2010-03-24 09:36:08 +0000 | [diff] [blame] | 5616 | /* |
| 5617 | * If SR-IOV enabled then wait a bit before bringing the adapter |
| 5618 | * back up to give the VFs time to respond to the reset. The |
| 5619 | * two second wait is based upon the watchdog timer cycle in |
| 5620 | * the VF driver. |
| 5621 | */ |
| 5622 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 5623 | msleep(2000); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 5624 | ixgbe_up(adapter); |
| 5625 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 5626 | } |
| 5627 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5628 | void ixgbe_up(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5629 | { |
| 5630 | /* hardware has been reset, we need to reload some things */ |
| 5631 | ixgbe_configure(adapter); |
| 5632 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 5633 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5634 | } |
| 5635 | |
| 5636 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 5637 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5638 | struct ixgbe_hw *hw = &adapter->hw; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5639 | struct net_device *netdev = adapter->netdev; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5640 | int err; |
| 5641 | |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 5642 | if (ixgbe_removed(hw->hw_addr)) |
| 5643 | return; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5644 | /* lock SFP init bit to prevent race conditions with the watchdog */ |
| 5645 | while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 5646 | usleep_range(1000, 2000); |
| 5647 | |
| 5648 | /* clear all SFP and link config related flags while holding SFP_INIT */ |
| 5649 | adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP | |
| 5650 | IXGBE_FLAG2_SFP_NEEDS_RESET); |
| 5651 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 5652 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5653 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5654 | switch (err) { |
| 5655 | case 0: |
| 5656 | case IXGBE_ERR_SFP_NOT_PRESENT: |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5657 | case IXGBE_ERR_SFP_NOT_SUPPORTED: |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5658 | break; |
| 5659 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5660 | e_dev_err("master disable timed out\n"); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5661 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5662 | case IXGBE_ERR_EEPROM_VERSION: |
| 5663 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5664 | e_dev_warn("This device is a pre-production adapter/LOM. " |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 5665 | "Please be aware there may be issues associated with " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5666 | "your hardware. If you are experiencing problems " |
| 5667 | "please contact your Intel or hardware " |
| 5668 | "representative who provided you with this " |
| 5669 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5670 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5671 | default: |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 5672 | e_dev_err("Hardware Error: %d\n", err); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 5673 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5674 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5675 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5676 | |
| 5677 | /* flush entries out of MAC table */ |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 5678 | ixgbe_flush_sw_mac_table(adapter); |
Alexander Duyck | 0f079d2 | 2015-10-22 16:26:36 -0700 | [diff] [blame] | 5679 | __dev_uc_unsync(netdev, NULL); |
| 5680 | |
| 5681 | /* do not flush user set addresses */ |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 5682 | ixgbe_mac_set_default_filter(adapter); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 5683 | |
| 5684 | /* update SAN MAC vmdq pool selection */ |
| 5685 | if (hw->mac.san_mac_rar_index) |
| 5686 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5687 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 5688 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 5689 | ixgbe_ptp_reset(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 5690 | |
| 5691 | if (hw->phy.ops.set_phy_power) { |
| 5692 | if (!netif_running(adapter->netdev) && !adapter->wol) |
| 5693 | hw->phy.ops.set_phy_power(hw, false); |
| 5694 | else |
| 5695 | hw->phy.ops.set_phy_power(hw, true); |
| 5696 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5697 | } |
| 5698 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5699 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5700 | * ixgbe_clean_tx_ring - Free Tx Buffers |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5701 | * @tx_ring: ring to be cleaned |
| 5702 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5703 | static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5704 | { |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5705 | u16 i = tx_ring->next_to_clean; |
| 5706 | struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5707 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5708 | while (i != tx_ring->next_to_use) { |
| 5709 | union ixgbe_adv_tx_desc *eop_desc, *tx_desc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5710 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5711 | /* Free all the Tx ring sk_buffs */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5712 | if (ring_is_xdp(tx_ring)) |
Jesper Dangaard Brouer | 0399309 | 2018-04-17 16:46:32 +0200 | [diff] [blame] | 5713 | xdp_return_frame(tx_buffer->xdpf); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5714 | else |
| 5715 | dev_kfree_skb_any(tx_buffer->skb); |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5716 | |
| 5717 | /* unmap skb header data */ |
| 5718 | dma_unmap_single(tx_ring->dev, |
| 5719 | dma_unmap_addr(tx_buffer, dma), |
| 5720 | dma_unmap_len(tx_buffer, len), |
| 5721 | DMA_TO_DEVICE); |
| 5722 | |
| 5723 | /* check for eop_desc to determine the end of the packet */ |
| 5724 | eop_desc = tx_buffer->next_to_watch; |
| 5725 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 5726 | |
| 5727 | /* unmap remaining buffers */ |
| 5728 | while (tx_desc != eop_desc) { |
| 5729 | tx_buffer++; |
| 5730 | tx_desc++; |
| 5731 | i++; |
| 5732 | if (unlikely(i == tx_ring->count)) { |
| 5733 | i = 0; |
| 5734 | tx_buffer = tx_ring->tx_buffer_info; |
| 5735 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 5736 | } |
| 5737 | |
| 5738 | /* unmap any remaining paged data */ |
| 5739 | if (dma_unmap_len(tx_buffer, len)) |
| 5740 | dma_unmap_page(tx_ring->dev, |
| 5741 | dma_unmap_addr(tx_buffer, dma), |
| 5742 | dma_unmap_len(tx_buffer, len), |
| 5743 | DMA_TO_DEVICE); |
| 5744 | } |
| 5745 | |
| 5746 | /* move us one more past the eop_desc for start of next pkt */ |
| 5747 | tx_buffer++; |
| 5748 | i++; |
| 5749 | if (unlikely(i == tx_ring->count)) { |
| 5750 | i = 0; |
| 5751 | tx_buffer = tx_ring->tx_buffer_info; |
| 5752 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5753 | } |
| 5754 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5755 | /* reset BQL for queue */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5756 | if (!ring_is_xdp(tx_ring)) |
| 5757 | netdev_tx_reset_queue(txring_txq(tx_ring)); |
John Fastabend | dad8a3b | 2012-04-23 12:22:39 +0000 | [diff] [blame] | 5758 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 5759 | /* reset next_to_use and next_to_clean */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5760 | tx_ring->next_to_use = 0; |
| 5761 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5762 | } |
| 5763 | |
| 5764 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5765 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 5766 | * @adapter: board private structure |
| 5767 | **/ |
| 5768 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 5769 | { |
| 5770 | int i; |
| 5771 | |
| 5772 | for (i = 0; i < adapter->num_rx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5773 | ixgbe_clean_rx_ring(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5774 | } |
| 5775 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5776 | /** |
| 5777 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 5778 | * @adapter: board private structure |
| 5779 | **/ |
| 5780 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 5781 | { |
| 5782 | int i; |
| 5783 | |
| 5784 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 5785 | ixgbe_clean_tx_ring(adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5786 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 5787 | ixgbe_clean_tx_ring(adapter->xdp_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5788 | } |
| 5789 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5790 | static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter) |
| 5791 | { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5792 | struct hlist_node *node2; |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5793 | struct ixgbe_fdir_filter *filter; |
| 5794 | |
| 5795 | spin_lock(&adapter->fdir_perfect_lock); |
| 5796 | |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 5797 | hlist_for_each_entry_safe(filter, node2, |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 5798 | &adapter->fdir_filter_list, fdir_node) { |
| 5799 | hlist_del(&filter->fdir_node); |
| 5800 | kfree(filter); |
| 5801 | } |
| 5802 | adapter->fdir_filter_count = 0; |
| 5803 | |
| 5804 | spin_unlock(&adapter->fdir_perfect_lock); |
| 5805 | } |
| 5806 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5807 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 5808 | { |
| 5809 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5810 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5811 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5812 | |
| 5813 | /* signal that we are down to the interrupt handler */ |
Mark Rustad | c3049c8 | 2014-01-14 18:53:12 -0800 | [diff] [blame] | 5814 | if (test_and_set_bit(__IXGBE_DOWN, &adapter->state)) |
| 5815 | return; /* do nothing if already down */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5816 | |
| 5817 | /* disable receives */ |
Don Skidmore | 1f9ac57 | 2015-03-13 13:54:30 -0700 | [diff] [blame] | 5818 | hw->mac.ops.disable_rx(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5819 | |
Yi Zou | 2d39d57 | 2011-01-06 14:29:56 +0000 | [diff] [blame] | 5820 | /* disable all enabled rx queues */ |
| 5821 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 5822 | /* this call also flushes the previous write */ |
| 5823 | ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 5824 | |
Don Skidmore | 032b432 | 2011-03-18 09:32:53 +0000 | [diff] [blame] | 5825 | usleep_range(10000, 20000); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5826 | |
John Fastabend | 11393cc | 2017-07-17 09:29:40 -0700 | [diff] [blame] | 5827 | /* synchronize_sched() needed for pending XDP buffers to drain */ |
| 5828 | if (adapter->xdp_ring[0]) |
| 5829 | synchronize_sched(); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5830 | netif_tx_stop_all_queues(netdev); |
| 5831 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5832 | /* call carrier off first to avoid false dev_watchdog timeouts */ |
John Fastabend | c0dfb90 | 2010-04-27 02:13:39 +0000 | [diff] [blame] | 5833 | netif_carrier_off(netdev); |
| 5834 | netif_tx_disable(netdev); |
| 5835 | |
| 5836 | ixgbe_irq_disable(adapter); |
| 5837 | |
| 5838 | ixgbe_napi_disable_all(adapter); |
| 5839 | |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 5840 | clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
| 5841 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 5842 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5843 | |
| 5844 | del_timer_sync(&adapter->service_timer); |
| 5845 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5846 | if (adapter->num_vfs) { |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5847 | /* Clear EITR Select mapping */ |
| 5848 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
| 5849 | |
| 5850 | /* Mark all the VFs as inactive */ |
| 5851 | for (i = 0 ; i < adapter->num_vfs; i++) |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 5852 | adapter->vfinfo[i].clear_to_send = false; |
Alexander Duyck | 8e34d1a | 2011-07-15 07:29:49 +0000 | [diff] [blame] | 5853 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 5854 | /* 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] | 5855 | ixgbe_ping_all_vfs(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5856 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5857 | /* Disable all VFTE/VFRE TX/RX */ |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5858 | ixgbe_disable_tx_rx(adapter); |
Peter Waskiewicz | b25ebfd | 2010-10-05 01:27:49 +0000 | [diff] [blame] | 5859 | } |
| 5860 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5861 | /* disable transmits in the hardware now that interrupts are off */ |
| 5862 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | bf29ee6 | 2010-11-16 19:27:07 -0800 | [diff] [blame] | 5863 | u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5864 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5865 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 5866 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 5867 | u8 reg_idx = adapter->xdp_ring[i]->reg_idx; |
| 5868 | |
| 5869 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
| 5870 | } |
Alexander Duyck | 34cecbb | 2011-04-22 04:08:14 +0000 | [diff] [blame] | 5871 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5872 | /* Disable the Tx DMA engine on 82599 and later MAC */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5873 | switch (hw->mac.type) { |
| 5874 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 5875 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 5876 | case ixgbe_mac_X550: |
| 5877 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 5878 | case ixgbe_mac_x550em_a: |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5879 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 5880 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 5881 | ~IXGBE_DMATXCTL_TE)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 5882 | break; |
| 5883 | default: |
| 5884 | break; |
| 5885 | } |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 5886 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 5887 | if (!pci_channel_offline(adapter->pdev)) |
| 5888 | ixgbe_reset(adapter); |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5889 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 5890 | /* power down the optics for 82599 SFP+ fiber */ |
| 5891 | if (hw->mac.ops.disable_tx_laser) |
Don Skidmore | c6ecf39 | 2010-12-03 03:31:51 +0000 | [diff] [blame] | 5892 | hw->mac.ops.disable_tx_laser(hw); |
| 5893 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5894 | ixgbe_clean_all_tx_rings(adapter); |
| 5895 | ixgbe_clean_all_rx_rings(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5896 | } |
| 5897 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5898 | /** |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 5899 | * ixgbe_eee_capable - helper function to determine EEE support on X550 |
| 5900 | * @adapter: board private structure |
| 5901 | */ |
| 5902 | static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter) |
| 5903 | { |
| 5904 | struct ixgbe_hw *hw = &adapter->hw; |
| 5905 | |
| 5906 | switch (hw->device_id) { |
| 5907 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 5908 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 5909 | if (!hw->phy.eee_speeds_supported) |
| 5910 | break; |
| 5911 | adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE; |
| 5912 | if (!hw->phy.eee_speeds_advertised) |
| 5913 | break; |
| 5914 | adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED; |
| 5915 | break; |
| 5916 | default: |
| 5917 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE; |
| 5918 | adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED; |
| 5919 | break; |
| 5920 | } |
| 5921 | } |
| 5922 | |
| 5923 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5924 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 5925 | * @netdev: network interface device structure |
| 5926 | **/ |
| 5927 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 5928 | { |
| 5929 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5930 | |
| 5931 | /* Do the reset outside of interrupt context */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 5932 | ixgbe_tx_timeout_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5933 | } |
| 5934 | |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 5935 | #ifdef CONFIG_IXGBE_DCB |
| 5936 | static void ixgbe_init_dcb(struct ixgbe_adapter *adapter) |
| 5937 | { |
| 5938 | struct ixgbe_hw *hw = &adapter->hw; |
| 5939 | struct tc_configuration *tc; |
| 5940 | int j; |
| 5941 | |
| 5942 | switch (hw->mac.type) { |
| 5943 | case ixgbe_mac_82598EB: |
| 5944 | case ixgbe_mac_82599EB: |
| 5945 | adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS; |
| 5946 | adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS; |
| 5947 | break; |
| 5948 | case ixgbe_mac_X540: |
| 5949 | case ixgbe_mac_X550: |
| 5950 | adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS; |
| 5951 | adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS; |
| 5952 | break; |
| 5953 | case ixgbe_mac_X550EM_x: |
| 5954 | case ixgbe_mac_x550em_a: |
| 5955 | default: |
| 5956 | adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS; |
| 5957 | adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS; |
| 5958 | break; |
| 5959 | } |
| 5960 | |
| 5961 | /* Configure DCB traffic classes */ |
| 5962 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 5963 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 5964 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 5965 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5966 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 5967 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 5968 | tc->dcb_pfc = pfc_disabled; |
| 5969 | } |
| 5970 | |
| 5971 | /* Initialize default user to priority mapping, UPx->TC0 */ |
| 5972 | tc = &adapter->dcb_cfg.tc_config[0]; |
| 5973 | tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5974 | tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF; |
| 5975 | |
| 5976 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 5977 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 5978 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 5979 | adapter->dcb_set_bitmap = 0x00; |
| 5980 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
| 5981 | adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE; |
| 5982 | memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg, |
| 5983 | sizeof(adapter->temp_dcb_cfg)); |
| 5984 | } |
| 5985 | #endif |
| 5986 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 5987 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5988 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 5989 | * @adapter: board private structure to initialize |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 5990 | * @ii: pointer to ixgbe_info for device |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5991 | * |
| 5992 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 5993 | * Fields are initialized based on PCI device information and |
| 5994 | * OS network device settings (MTU size). |
| 5995 | **/ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 5996 | static int ixgbe_sw_init(struct ixgbe_adapter *adapter, |
| 5997 | const struct ixgbe_info *ii) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5998 | { |
| 5999 | struct ixgbe_hw *hw = &adapter->hw; |
| 6000 | struct pci_dev *pdev = adapter->pdev; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 6001 | unsigned int rss, fdir; |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 6002 | u32 fwsm; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 6003 | int i; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6004 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6005 | /* PCI config space info */ |
| 6006 | |
| 6007 | hw->vendor_id = pdev->vendor; |
| 6008 | hw->device_id = pdev->device; |
| 6009 | hw->revision_id = pdev->revision; |
| 6010 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 6011 | hw->subsystem_device_id = pdev->subsystem_device; |
| 6012 | |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 6013 | /* get_invariants needs the device IDs */ |
| 6014 | ii->get_invariants(hw); |
| 6015 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6016 | /* Set common capability flags and settings */ |
Don Skidmore | 0f9b232 | 2014-11-18 09:35:08 +0000 | [diff] [blame] | 6017 | rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus()); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 6018 | adapter->ring_feature[RING_F_RSS].limit = rss; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6019 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6020 | adapter->max_q_vectors = MAX_Q_VECTORS_82599; |
| 6021 | adapter->atr_sample_rate = 20; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 6022 | fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus()); |
| 6023 | adapter->ring_feature[RING_F_FDIR].limit = fdir; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6024 | adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K; |
Alexander Duyck | a8e87d9 | 2017-11-22 10:57:05 -0800 | [diff] [blame] | 6025 | adapter->ring_feature[RING_F_VMDQ].limit = 1; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6026 | #ifdef CONFIG_IXGBE_DCA |
| 6027 | adapter->flags |= IXGBE_FLAG_DCA_CAPABLE; |
| 6028 | #endif |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 6029 | #ifdef CONFIG_IXGBE_DCB |
| 6030 | adapter->flags |= IXGBE_FLAG_DCB_CAPABLE; |
| 6031 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 6032 | #endif |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6033 | #ifdef IXGBE_FCOE |
| 6034 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 6035 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 6036 | #ifdef CONFIG_IXGBE_DCB |
| 6037 | /* Default traffic class to use for FCoE */ |
| 6038 | adapter->fcoe.up = IXGBE_FCOE_DEFTC; |
| 6039 | #endif /* CONFIG_IXGBE_DCB */ |
| 6040 | #endif /* IXGBE_FCOE */ |
| 6041 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 6042 | /* initialize static ixgbe jump table entries */ |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 6043 | adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]), |
| 6044 | GFP_KERNEL); |
| 6045 | if (!adapter->jump_tables[0]) |
| 6046 | return -ENOMEM; |
| 6047 | adapter->jump_tables[0]->mat = ixgbe_ipv4_fields; |
| 6048 | |
| 6049 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) |
| 6050 | adapter->jump_tables[i] = NULL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 6051 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 6052 | adapter->mac_table = kcalloc(hw->mac.num_rar_entries, |
| 6053 | sizeof(struct ixgbe_mac_addr), |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 6054 | GFP_ATOMIC); |
Alexander Duyck | 530fd82 | 2015-11-02 17:09:29 -0800 | [diff] [blame] | 6055 | if (!adapter->mac_table) |
| 6056 | return -ENOMEM; |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 6057 | |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 6058 | if (ixgbe_init_rss_key(adapter)) |
| 6059 | return -ENOMEM; |
| 6060 | |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6061 | /* Set MAC specific capability flags and exceptions */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6062 | switch (hw->mac.type) { |
| 6063 | case ixgbe_mac_82598EB: |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6064 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6065 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 6066 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 6067 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6068 | |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 6069 | adapter->max_q_vectors = MAX_Q_VECTORS_82598; |
Emil Tantilov | 8fc3bb6 | 2013-01-08 04:23:53 +0000 | [diff] [blame] | 6070 | adapter->ring_feature[RING_F_FDIR].limit = 0; |
| 6071 | adapter->atr_sample_rate = 0; |
| 6072 | adapter->fdir_pballoc = 0; |
| 6073 | #ifdef IXGBE_FCOE |
| 6074 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 6075 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 6076 | #ifdef CONFIG_IXGBE_DCB |
| 6077 | adapter->fcoe.up = 0; |
| 6078 | #endif /* IXGBE_DCB */ |
| 6079 | #endif /* IXGBE_FCOE */ |
| 6080 | break; |
| 6081 | case ixgbe_mac_82599EB: |
| 6082 | if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM) |
| 6083 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6084 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6085 | case ixgbe_mac_X540: |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 6086 | fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw)); |
Jacob Keller | cb6d0f5 | 2012-12-04 06:03:14 +0000 | [diff] [blame] | 6087 | if (fwsm & IXGBE_FWSM_TS_ENABLED) |
| 6088 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6089 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6090 | case ixgbe_mac_x550em_a: |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6091 | adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 6092 | switch (hw->device_id) { |
| 6093 | case IXGBE_DEV_ID_X550EM_A_1G_T: |
| 6094 | case IXGBE_DEV_ID_X550EM_A_1G_T_L: |
| 6095 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
| 6096 | break; |
| 6097 | default: |
| 6098 | break; |
| 6099 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6100 | /* fall through */ |
| 6101 | case ixgbe_mac_X550EM_x: |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 6102 | #ifdef CONFIG_IXGBE_DCB |
| 6103 | adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE; |
| 6104 | #endif |
| 6105 | #ifdef IXGBE_FCOE |
| 6106 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
| 6107 | #ifdef CONFIG_IXGBE_DCB |
| 6108 | adapter->fcoe.up = 0; |
| 6109 | #endif /* IXGBE_DCB */ |
| 6110 | #endif /* IXGBE_FCOE */ |
| 6111 | /* Fall Through */ |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6112 | case ixgbe_mac_X550: |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 6113 | if (hw->mac.type == ixgbe_mac_X550) |
| 6114 | adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6115 | #ifdef CONFIG_IXGBE_DCA |
| 6116 | adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE; |
| 6117 | #endif |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6118 | adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6119 | break; |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6120 | default: |
| 6121 | break; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6122 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6123 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6124 | #ifdef IXGBE_FCOE |
| 6125 | /* FCoE support exists, always init the FCoE lock */ |
| 6126 | spin_lock_init(&adapter->fcoe.lock); |
| 6127 | |
| 6128 | #endif |
Alexander Duyck | 1fc5f03 | 2011-06-02 04:28:39 +0000 | [diff] [blame] | 6129 | /* n-tuple support exists, always init our spinlock */ |
| 6130 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 6131 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 6132 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 6133 | ixgbe_init_dcb(adapter); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6134 | #endif |
Alexander Duyck | de7a7e3 | 2018-06-04 16:51:25 -0400 | [diff] [blame] | 6135 | ixgbe_init_ipsec_offload(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6136 | |
| 6137 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 6138 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 6139 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
John Fastabend | 9da712d | 2011-08-23 03:14:22 +0000 | [diff] [blame] | 6140 | ixgbe_pbthresh_setup(adapter); |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 6141 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 6142 | hw->fc.send_xon = true; |
Don Skidmore | 73d80953d | 2013-07-31 02:19:24 +0000 | [diff] [blame] | 6143 | hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6144 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 6145 | #ifdef CONFIG_PCI_IOV |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6146 | if (max_vfs > 0) |
| 6147 | e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n"); |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 6148 | |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6149 | /* assign number of SR-IOV VFs */ |
| 6150 | if (hw->mac.type != ixgbe_mac_82598EB) { |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 6151 | if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) { |
Emil Tantilov | 5c11f00 | 2017-01-20 14:11:56 -0800 | [diff] [blame] | 6152 | max_vfs = 0; |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6153 | e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n"); |
Jacob Keller | 170e854 | 2013-11-09 04:52:32 -0800 | [diff] [blame] | 6154 | } |
| 6155 | } |
| 6156 | #endif /* CONFIG_PCI_IOV */ |
| 6157 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 6158 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 6159 | adapter->rx_itr_setting = 1; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 6160 | adapter->tx_itr_setting = 1; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 6161 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 6162 | /* set default ring sizes */ |
| 6163 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 6164 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 6165 | |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 6166 | /* set default work limits */ |
Alexander Duyck | 5922455 | 2011-08-31 00:01:06 +0000 | [diff] [blame] | 6167 | adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK; |
Alexander Duyck | bd19805 | 2011-06-11 01:45:08 +0000 | [diff] [blame] | 6168 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6169 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6170 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6171 | e_dev_err("EEPROM initialization failed\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6172 | return -EIO; |
| 6173 | } |
| 6174 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6175 | /* PF holds first pool slot */ |
Alexander Duyck | 4e039c1 | 2017-11-22 10:56:40 -0800 | [diff] [blame] | 6176 | set_bit(0, adapter->fwd_bitmask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6177 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 6178 | |
| 6179 | return 0; |
| 6180 | } |
| 6181 | |
| 6182 | /** |
| 6183 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6184 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6185 | * |
| 6186 | * Return 0 on success, negative on failure |
| 6187 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6188 | int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6189 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6190 | struct device *dev = tx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6191 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6192 | int ring_node = -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6193 | int size; |
| 6194 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6195 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6196 | |
| 6197 | if (tx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6198 | ring_node = tx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6199 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6200 | tx_ring->tx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 6201 | if (!tx_ring->tx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6202 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6203 | if (!tx_ring->tx_buffer_info) |
| 6204 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6205 | |
| 6206 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 6207 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6208 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6209 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6210 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6211 | tx_ring->desc = dma_alloc_coherent(dev, |
| 6212 | tx_ring->size, |
| 6213 | &tx_ring->dma, |
| 6214 | GFP_KERNEL); |
| 6215 | set_dev_node(dev, orig_node); |
| 6216 | if (!tx_ring->desc) |
| 6217 | tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size, |
| 6218 | &tx_ring->dma, GFP_KERNEL); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6219 | if (!tx_ring->desc) |
| 6220 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6221 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6222 | tx_ring->next_to_use = 0; |
| 6223 | tx_ring->next_to_clean = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6224 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 6225 | |
| 6226 | err: |
| 6227 | vfree(tx_ring->tx_buffer_info); |
| 6228 | tx_ring->tx_buffer_info = NULL; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6229 | 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] | 6230 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6231 | } |
| 6232 | |
| 6233 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6234 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 6235 | * @adapter: board private structure |
| 6236 | * |
| 6237 | * If this function returns with an error, then it's possible one or |
| 6238 | * more of the rings is populated (while the rest are not). It is the |
| 6239 | * callers duty to clean those orphaned rings. |
| 6240 | * |
| 6241 | * Return 0 on success, negative on failure |
| 6242 | **/ |
| 6243 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6244 | { |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6245 | int i, j = 0, err = 0; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6246 | |
| 6247 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6248 | err = ixgbe_setup_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6249 | if (!err) |
| 6250 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6251 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6252 | e_err(probe, "Allocation for Tx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6253 | goto err_setup_tx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6254 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6255 | for (j = 0; j < adapter->num_xdp_queues; j++) { |
| 6256 | err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]); |
| 6257 | if (!err) |
| 6258 | continue; |
| 6259 | |
| 6260 | e_err(probe, "Allocation for Tx Queue %u failed\n", j); |
| 6261 | goto err_setup_tx; |
| 6262 | } |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6263 | |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6264 | return 0; |
| 6265 | err_setup_tx: |
| 6266 | /* rewind the index freeing the rings as we go */ |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6267 | while (j--) |
| 6268 | ixgbe_free_tx_resources(adapter->xdp_ring[j]); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6269 | while (i--) |
| 6270 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6271 | return err; |
| 6272 | } |
| 6273 | |
| 6274 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6275 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 6276 | * @adapter: pointer to ixgbe_adapter |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6277 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6278 | * |
| 6279 | * Returns 0 on success, negative on failure |
| 6280 | **/ |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6281 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
| 6282 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6283 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6284 | struct device *dev = rx_ring->dev; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6285 | int orig_node = dev_to_node(dev); |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6286 | int ring_node = -1; |
Jesper Dangaard Brouer | 8d5d885 | 2018-04-17 16:46:12 +0200 | [diff] [blame] | 6287 | int size, err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6288 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6289 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6290 | |
| 6291 | if (rx_ring->q_vector) |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6292 | ring_node = rx_ring->q_vector->numa_node; |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6293 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6294 | rx_ring->rx_buffer_info = vmalloc_node(size, ring_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 6295 | if (!rx_ring->rx_buffer_info) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 6296 | rx_ring->rx_buffer_info = vmalloc(size); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6297 | if (!rx_ring->rx_buffer_info) |
| 6298 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6299 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6300 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6301 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 6302 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6303 | |
Mark Rustad | ca8dfe2 | 2014-07-24 06:19:24 +0000 | [diff] [blame] | 6304 | set_dev_node(dev, ring_node); |
Alexander Duyck | de88eee | 2012-02-08 07:49:59 +0000 | [diff] [blame] | 6305 | rx_ring->desc = dma_alloc_coherent(dev, |
| 6306 | rx_ring->size, |
| 6307 | &rx_ring->dma, |
| 6308 | GFP_KERNEL); |
| 6309 | set_dev_node(dev, orig_node); |
| 6310 | if (!rx_ring->desc) |
| 6311 | rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size, |
| 6312 | &rx_ring->dma, GFP_KERNEL); |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6313 | if (!rx_ring->desc) |
| 6314 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6315 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 6316 | rx_ring->next_to_clean = 0; |
| 6317 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6318 | |
Jesper Dangaard Brouer | 99ffc5a | 2018-01-03 11:25:29 +0100 | [diff] [blame] | 6319 | /* XDP RX-queue info */ |
| 6320 | if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev, |
| 6321 | rx_ring->queue_index) < 0) |
| 6322 | goto err; |
| 6323 | |
Jesper Dangaard Brouer | 8d5d885 | 2018-04-17 16:46:12 +0200 | [diff] [blame] | 6324 | err = xdp_rxq_info_reg_mem_model(&rx_ring->xdp_rxq, |
| 6325 | MEM_TYPE_PAGE_SHARED, NULL); |
| 6326 | if (err) { |
| 6327 | xdp_rxq_info_unreg(&rx_ring->xdp_rxq); |
| 6328 | goto err; |
| 6329 | } |
| 6330 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6331 | rx_ring->xdp_prog = adapter->xdp_prog; |
| 6332 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6333 | return 0; |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6334 | err: |
| 6335 | vfree(rx_ring->rx_buffer_info); |
| 6336 | rx_ring->rx_buffer_info = NULL; |
| 6337 | 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] | 6338 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6339 | } |
| 6340 | |
| 6341 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6342 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 6343 | * @adapter: board private structure |
| 6344 | * |
| 6345 | * If this function returns with an error, then it's possible one or |
| 6346 | * more of the rings is populated (while the rest are not). It is the |
| 6347 | * callers duty to clean those orphaned rings. |
| 6348 | * |
| 6349 | * Return 0 on success, negative on failure |
| 6350 | **/ |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6351 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6352 | { |
| 6353 | int i, err = 0; |
| 6354 | |
| 6355 | for (i = 0; i < adapter->num_rx_queues; i++) { |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6356 | err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6357 | if (!err) |
| 6358 | continue; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6359 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6360 | e_err(probe, "Allocation for Rx Queue %u failed\n", i); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6361 | goto err_setup_rx; |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6362 | } |
| 6363 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6364 | #ifdef IXGBE_FCOE |
| 6365 | err = ixgbe_setup_fcoe_ddp_resources(adapter); |
| 6366 | if (!err) |
| 6367 | #endif |
| 6368 | return 0; |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6369 | err_setup_rx: |
| 6370 | /* rewind the index freeing the rings as we go */ |
| 6371 | while (i--) |
| 6372 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 6373 | return err; |
| 6374 | } |
| 6375 | |
| 6376 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6377 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6378 | * @tx_ring: Tx descriptor ring for a specific queue |
| 6379 | * |
| 6380 | * Free all transmit software resources |
| 6381 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6382 | void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6383 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6384 | ixgbe_clean_tx_ring(tx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6385 | |
| 6386 | vfree(tx_ring->tx_buffer_info); |
| 6387 | tx_ring->tx_buffer_info = NULL; |
| 6388 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6389 | /* if not set, then don't free */ |
| 6390 | if (!tx_ring->desc) |
| 6391 | return; |
| 6392 | |
| 6393 | dma_free_coherent(tx_ring->dev, tx_ring->size, |
| 6394 | tx_ring->desc, tx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6395 | |
| 6396 | tx_ring->desc = NULL; |
| 6397 | } |
| 6398 | |
| 6399 | /** |
| 6400 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 6401 | * @adapter: board private structure |
| 6402 | * |
| 6403 | * Free all transmit software resources |
| 6404 | **/ |
| 6405 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 6406 | { |
| 6407 | int i; |
| 6408 | |
| 6409 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6410 | if (adapter->tx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6411 | ixgbe_free_tx_resources(adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6412 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 6413 | if (adapter->xdp_ring[i]->desc) |
| 6414 | ixgbe_free_tx_resources(adapter->xdp_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6415 | } |
| 6416 | |
| 6417 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6418 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6419 | * @rx_ring: ring to clean the resources from |
| 6420 | * |
| 6421 | * Free all receive software resources |
| 6422 | **/ |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6423 | void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6424 | { |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6425 | ixgbe_clean_rx_ring(rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6426 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 6427 | rx_ring->xdp_prog = NULL; |
Jesper Dangaard Brouer | 99ffc5a | 2018-01-03 11:25:29 +0100 | [diff] [blame] | 6428 | xdp_rxq_info_unreg(&rx_ring->xdp_rxq); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6429 | vfree(rx_ring->rx_buffer_info); |
| 6430 | rx_ring->rx_buffer_info = NULL; |
| 6431 | |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6432 | /* if not set, then don't free */ |
| 6433 | if (!rx_ring->desc) |
| 6434 | return; |
| 6435 | |
| 6436 | dma_free_coherent(rx_ring->dev, rx_ring->size, |
| 6437 | rx_ring->desc, rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6438 | |
| 6439 | rx_ring->desc = NULL; |
| 6440 | } |
| 6441 | |
| 6442 | /** |
| 6443 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 6444 | * @adapter: board private structure |
| 6445 | * |
| 6446 | * Free all receive software resources |
| 6447 | **/ |
| 6448 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 6449 | { |
| 6450 | int i; |
| 6451 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 6452 | #ifdef IXGBE_FCOE |
| 6453 | ixgbe_free_fcoe_ddp_resources(adapter); |
| 6454 | |
| 6455 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6456 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 6457 | if (adapter->rx_ring[i]->desc) |
Alexander Duyck | b6ec895 | 2010-11-16 19:26:49 -0800 | [diff] [blame] | 6458 | ixgbe_free_rx_resources(adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6462 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 6463 | * @netdev: network interface device structure |
| 6464 | * @new_mtu: new value for maximum frame size |
| 6465 | * |
| 6466 | * Returns 0 on success, negative on failure |
| 6467 | **/ |
| 6468 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 6469 | { |
| 6470 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6471 | |
| 6472 | /* |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6473 | * For 82599EB we cannot allow legacy VFs to enable their receive |
| 6474 | * paths when MTU greater than 1500 is configured. So display a |
| 6475 | * warning that legacy VFs will be disabled. |
Alexander Duyck | 655309e | 2012-02-08 07:50:35 +0000 | [diff] [blame] | 6476 | */ |
| 6477 | if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && |
| 6478 | (adapter->hw.mac.type == ixgbe_mac_82599EB) && |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 6479 | (new_mtu > ETH_DATA_LEN)) |
Alexander Duyck | 872844d | 2012-08-15 02:10:43 +0000 | [diff] [blame] | 6480 | e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6481 | |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 6482 | 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] | 6483 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6484 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6485 | netdev->mtu = new_mtu; |
| 6486 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 6487 | if (netif_running(netdev)) |
| 6488 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6489 | |
| 6490 | return 0; |
| 6491 | } |
| 6492 | |
| 6493 | /** |
| 6494 | * ixgbe_open - Called when a network interface is made active |
| 6495 | * @netdev: network interface device structure |
| 6496 | * |
| 6497 | * Returns 0 on success, negative value on failure |
| 6498 | * |
| 6499 | * The open entry point is called when a network interface is made |
| 6500 | * active by the system (IFF_UP). At this point all resources needed |
| 6501 | * for transmit and receive operations are allocated, the interrupt |
| 6502 | * handler is registered with the OS, the watchdog timer is started, |
| 6503 | * and the stack is notified that the interface is ready. |
| 6504 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6505 | int ixgbe_open(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6506 | { |
| 6507 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6508 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6509 | int err, queues; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6510 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 6511 | /* disallow open during test */ |
| 6512 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 6513 | return -EBUSY; |
| 6514 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6515 | netif_carrier_off(netdev); |
| 6516 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6517 | /* allocate transmit descriptors */ |
| 6518 | err = ixgbe_setup_all_tx_resources(adapter); |
| 6519 | if (err) |
| 6520 | goto err_setup_tx; |
| 6521 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6522 | /* allocate receive descriptors */ |
| 6523 | err = ixgbe_setup_all_rx_resources(adapter); |
| 6524 | if (err) |
| 6525 | goto err_setup_rx; |
| 6526 | |
| 6527 | ixgbe_configure(adapter); |
| 6528 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6529 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6530 | if (err) |
| 6531 | goto err_req_irq; |
| 6532 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6533 | /* Notify the stack of the actual queue counts. */ |
Alexander Duyck | 49cfbeb | 2017-11-22 10:57:35 -0800 | [diff] [blame] | 6534 | queues = adapter->num_tx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6535 | err = netif_set_real_num_tx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6536 | if (err) |
| 6537 | goto err_set_queues; |
| 6538 | |
Alexander Duyck | 49cfbeb | 2017-11-22 10:57:35 -0800 | [diff] [blame] | 6539 | queues = adapter->num_rx_queues; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 6540 | err = netif_set_real_num_rx_queues(netdev, queues); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6541 | if (err) |
| 6542 | goto err_set_queues; |
| 6543 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6544 | ixgbe_ptp_init(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6545 | |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 6546 | ixgbe_up_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6547 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 6548 | ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK); |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 6549 | udp_tunnel_get_rx_info(netdev); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 6550 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6551 | return 0; |
| 6552 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6553 | err_set_queues: |
| 6554 | ixgbe_free_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6555 | err_req_irq: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6556 | ixgbe_free_all_rx_resources(adapter); |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6557 | if (hw->phy.ops.set_phy_power && !adapter->wol) |
| 6558 | hw->phy.ops.set_phy_power(&adapter->hw, false); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6559 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 6560 | ixgbe_free_all_tx_resources(adapter); |
Alexander Duyck | de3d5b9 | 2012-05-18 06:33:47 +0000 | [diff] [blame] | 6561 | err_setup_tx: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6562 | ixgbe_reset(adapter); |
| 6563 | |
| 6564 | return err; |
| 6565 | } |
| 6566 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6567 | static void ixgbe_close_suspend(struct ixgbe_adapter *adapter) |
| 6568 | { |
| 6569 | ixgbe_ptp_suspend(adapter); |
| 6570 | |
Don Skidmore | 6ac7439 | 2015-06-17 17:34:31 -0400 | [diff] [blame] | 6571 | if (adapter->hw.phy.ops.enter_lplu) { |
| 6572 | adapter->hw.phy.reset_disable = true; |
| 6573 | ixgbe_down(adapter); |
| 6574 | adapter->hw.phy.ops.enter_lplu(&adapter->hw); |
| 6575 | adapter->hw.phy.reset_disable = false; |
| 6576 | } else { |
| 6577 | ixgbe_down(adapter); |
| 6578 | } |
| 6579 | |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6580 | ixgbe_free_irq(adapter); |
| 6581 | |
| 6582 | ixgbe_free_all_tx_resources(adapter); |
| 6583 | ixgbe_free_all_rx_resources(adapter); |
| 6584 | } |
| 6585 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6586 | /** |
| 6587 | * ixgbe_close - Disables a network interface |
| 6588 | * @netdev: network interface device structure |
| 6589 | * |
| 6590 | * Returns 0, this is not allowed to fail |
| 6591 | * |
| 6592 | * The close entry point is called when an interface is de-activated |
| 6593 | * by the OS. The hardware is still under the drivers control, but |
| 6594 | * needs to be disabled. A global MAC reset is issued to stop the |
| 6595 | * hardware, and all transmit and receive resources are freed. |
| 6596 | **/ |
Stefan Assmann | 6c211fe1 | 2016-02-03 09:20:48 +0100 | [diff] [blame] | 6597 | int ixgbe_close(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6598 | { |
| 6599 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6600 | |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6601 | ixgbe_ptp_stop(adapter); |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 6602 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6603 | if (netif_device_present(netdev)) |
| 6604 | ixgbe_close_suspend(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6605 | |
Alexander Duyck | e4911d5 | 2011-05-11 07:18:52 +0000 | [diff] [blame] | 6606 | ixgbe_fdir_filter_exit(adapter); |
| 6607 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6608 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6609 | |
| 6610 | return 0; |
| 6611 | } |
| 6612 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6613 | #ifdef CONFIG_PM |
| 6614 | static int ixgbe_resume(struct pci_dev *pdev) |
| 6615 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6616 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6617 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6618 | u32 err; |
| 6619 | |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 6620 | adapter->hw.hw_addr = adapter->io_addr; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6621 | pci_set_power_state(pdev, PCI_D0); |
| 6622 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 6623 | /* |
| 6624 | * pci_restore_state clears dev->state_saved so call |
| 6625 | * pci_save_state to restore it. |
| 6626 | */ |
| 6627 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6628 | |
| 6629 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6630 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 6631 | e_dev_err("Cannot enable PCI device from suspend\n"); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6632 | return err; |
| 6633 | } |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 6634 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6635 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6636 | pci_set_master(pdev); |
| 6637 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6638 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6639 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6640 | ixgbe_reset(adapter); |
| 6641 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6642 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6643 | |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6644 | rtnl_lock(); |
| 6645 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6646 | if (!err && netif_running(netdev)) |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6647 | err = ixgbe_open(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6648 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6649 | |
| 6650 | if (!err) |
| 6651 | netif_device_attach(netdev); |
Alexander Duyck | ac802f5 | 2012-07-12 05:52:53 +0000 | [diff] [blame] | 6652 | rtnl_unlock(); |
| 6653 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6654 | return err; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6655 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6656 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6657 | |
| 6658 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6659 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 6660 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 6661 | struct net_device *netdev = adapter->netdev; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6662 | struct ixgbe_hw *hw = &adapter->hw; |
Emil Tantilov | d9d11eb | 2017-10-10 13:20:01 -0700 | [diff] [blame] | 6663 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6664 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6665 | #ifdef CONFIG_PM |
| 6666 | int retval = 0; |
| 6667 | #endif |
| 6668 | |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6669 | rtnl_lock(); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6670 | netif_device_detach(netdev); |
| 6671 | |
Jeff Kirsher | f0b99e3a | 2018-05-18 11:58:30 -0700 | [diff] [blame] | 6672 | if (netif_running(netdev)) |
Jacob Keller | a0cccce | 2014-05-16 05:12:29 +0000 | [diff] [blame] | 6673 | ixgbe_close_suspend(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6674 | |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6675 | ixgbe_clear_interrupt_scheme(adapter); |
Emil Tantilov | f7f37e7 | 2016-11-11 10:07:47 -0800 | [diff] [blame] | 6676 | rtnl_unlock(); |
Alexander Duyck | 5f5ae6f | 2010-11-16 19:26:52 -0800 | [diff] [blame] | 6677 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6678 | #ifdef CONFIG_PM |
| 6679 | retval = pci_save_state(pdev); |
| 6680 | if (retval) |
| 6681 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 6682 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6683 | #endif |
Jacob Keller | f4f1040 | 2013-06-25 07:59:23 +0000 | [diff] [blame] | 6684 | if (hw->mac.ops.stop_link_on_d3) |
| 6685 | hw->mac.ops.stop_link_on_d3(hw); |
| 6686 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6687 | if (wufc) { |
Emil Tantilov | d9d11eb | 2017-10-10 13:20:01 -0700 | [diff] [blame] | 6688 | u32 fctrl; |
| 6689 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6690 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6691 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 6692 | /* enable the optics for 82599 SFP+ fiber as we can WoL */ |
| 6693 | if (hw->mac.ops.enable_tx_laser) |
Don Skidmore | c509e75 | 2012-04-05 08:12:05 +0000 | [diff] [blame] | 6694 | hw->mac.ops.enable_tx_laser(hw); |
| 6695 | |
Emil Tantilov | d9d11eb | 2017-10-10 13:20:01 -0700 | [diff] [blame] | 6696 | /* enable the reception of multicast packets */ |
| 6697 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 6698 | fctrl |= IXGBE_FCTRL_MPE; |
| 6699 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6700 | |
| 6701 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 6702 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 6703 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 6704 | |
| 6705 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 6706 | } else { |
| 6707 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 6708 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 6709 | } |
| 6710 | |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6711 | switch (hw->mac.type) { |
| 6712 | case ixgbe_mac_82598EB: |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6713 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6714 | break; |
| 6715 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6716 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6717 | case ixgbe_mac_X550: |
| 6718 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6719 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6720 | pci_wake_from_d3(pdev, !!wufc); |
| 6721 | break; |
| 6722 | default: |
| 6723 | break; |
| 6724 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6725 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6726 | *enable_wake = !!wufc; |
Don Skidmore | 961fac8 | 2015-06-09 16:09:47 -0700 | [diff] [blame] | 6727 | if (hw->phy.ops.set_phy_power && !*enable_wake) |
| 6728 | hw->phy.ops.set_phy_power(hw, false); |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6729 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6730 | ixgbe_release_hw_control(adapter); |
| 6731 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 6732 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 6733 | pci_disable_device(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6734 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6735 | return 0; |
| 6736 | } |
| 6737 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6738 | #ifdef CONFIG_PM |
| 6739 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 6740 | { |
| 6741 | int retval; |
| 6742 | bool wake; |
| 6743 | |
| 6744 | retval = __ixgbe_shutdown(pdev, &wake); |
| 6745 | if (retval) |
| 6746 | return retval; |
| 6747 | |
| 6748 | if (wake) { |
| 6749 | pci_prepare_to_sleep(pdev); |
| 6750 | } else { |
| 6751 | pci_wake_from_d3(pdev, false); |
| 6752 | pci_set_power_state(pdev, PCI_D3hot); |
| 6753 | } |
| 6754 | |
| 6755 | return 0; |
| 6756 | } |
| 6757 | #endif /* CONFIG_PM */ |
| 6758 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6759 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 6760 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 6761 | bool wake; |
| 6762 | |
| 6763 | __ixgbe_shutdown(pdev, &wake); |
| 6764 | |
| 6765 | if (system_state == SYSTEM_POWER_OFF) { |
| 6766 | pci_wake_from_d3(pdev, wake); |
| 6767 | pci_set_power_state(pdev, PCI_D3hot); |
| 6768 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6772 | * ixgbe_update_stats - Update the board statistics counters. |
| 6773 | * @adapter: board private structure |
| 6774 | **/ |
| 6775 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 6776 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6777 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6778 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6779 | struct ixgbe_hw_stats *hwstats = &adapter->stats; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6780 | u64 total_mpc = 0; |
| 6781 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6782 | u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0; |
| 6783 | u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 6784 | u64 alloc_rx_page = 0; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6785 | u64 bytes = 0, packets = 0, hw_csum_rx_error = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6786 | |
Don Skidmore | d08935c | 2010-06-11 13:20:29 +0000 | [diff] [blame] | 6787 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 6788 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 6789 | return; |
| 6790 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6791 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6792 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6793 | u64 rsc_flush = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6794 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6795 | rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count; |
| 6796 | rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 6797 | } |
| 6798 | adapter->rsc_total_count = rsc_count; |
| 6799 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 6800 | } |
| 6801 | |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6802 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 6803 | struct ixgbe_ring *rx_ring = adapter->rx_ring[i]; |
| 6804 | non_eop_descs += rx_ring->rx_stats.non_eop_descs; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 6805 | alloc_rx_page += rx_ring->rx_stats.alloc_rx_page; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6806 | alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 6807 | alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6808 | hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6809 | bytes += rx_ring->stats.bytes; |
| 6810 | packets += rx_ring->stats.packets; |
| 6811 | } |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 6812 | adapter->non_eop_descs = non_eop_descs; |
Jesper Dangaard Brouer | 86e2349 | 2017-09-04 20:40:22 +0200 | [diff] [blame] | 6813 | adapter->alloc_rx_page = alloc_rx_page; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6814 | adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 6815 | adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
Alexander Duyck | 8a0da21 | 2012-01-31 02:59:49 +0000 | [diff] [blame] | 6816 | adapter->hw_csum_rx_error = hw_csum_rx_error; |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6817 | netdev->stats.rx_bytes = bytes; |
| 6818 | netdev->stats.rx_packets = packets; |
| 6819 | |
| 6820 | bytes = 0; |
| 6821 | packets = 0; |
| 6822 | /* gather some stats to the adapter struct that are per queue */ |
| 6823 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 6824 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 6825 | restart_queue += tx_ring->tx_stats.restart_queue; |
| 6826 | tx_busy += tx_ring->tx_stats.tx_busy; |
| 6827 | bytes += tx_ring->stats.bytes; |
| 6828 | packets += tx_ring->stats.packets; |
| 6829 | } |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 6830 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 6831 | struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i]; |
| 6832 | |
| 6833 | restart_queue += xdp_ring->tx_stats.restart_queue; |
| 6834 | tx_busy += xdp_ring->tx_stats.tx_busy; |
| 6835 | bytes += xdp_ring->stats.bytes; |
| 6836 | packets += xdp_ring->stats.packets; |
| 6837 | } |
Alexander Duyck | 5b7da51 | 2010-11-16 19:26:50 -0800 | [diff] [blame] | 6838 | adapter->restart_queue = restart_queue; |
| 6839 | adapter->tx_busy = tx_busy; |
| 6840 | netdev->stats.tx_bytes = bytes; |
| 6841 | netdev->stats.tx_packets = packets; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 6842 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6843 | hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6844 | |
| 6845 | /* 8 register reads */ |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6846 | for (i = 0; i < 8; i++) { |
| 6847 | /* for packet buffers not used, the register should read 0 */ |
| 6848 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 6849 | missed_rx += mpc; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6850 | hwstats->mpc[i] += mpc; |
| 6851 | total_mpc += hwstats->mpc[i]; |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6852 | hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); |
| 6853 | hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6854 | switch (hw->mac.type) { |
| 6855 | case ixgbe_mac_82598EB: |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6856 | hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
| 6857 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 6858 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6859 | hwstats->pxonrxc[i] += |
| 6860 | IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6861 | break; |
| 6862 | case ixgbe_mac_82599EB: |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6863 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6864 | case ixgbe_mac_X550: |
| 6865 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6866 | case ixgbe_mac_x550em_a: |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6867 | hwstats->pxonrxc[i] += |
| 6868 | IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6869 | break; |
| 6870 | default: |
| 6871 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6872 | } |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6873 | } |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6874 | |
| 6875 | /*16 register reads */ |
| 6876 | for (i = 0; i < 16; i++) { |
| 6877 | hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 6878 | hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 6879 | if ((hw->mac.type == ixgbe_mac_82599EB) || |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6880 | (hw->mac.type == ixgbe_mac_X540) || |
| 6881 | (hw->mac.type == ixgbe_mac_X550) || |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6882 | (hw->mac.type == ixgbe_mac_X550EM_x) || |
| 6883 | (hw->mac.type == ixgbe_mac_x550em_a)) { |
Emil Tantilov | 1a70db4b | 2011-07-26 07:51:41 +0000 | [diff] [blame] | 6884 | hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); |
| 6885 | IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */ |
| 6886 | hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i)); |
| 6887 | IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */ |
| 6888 | } |
| 6889 | } |
| 6890 | |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6891 | hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6892 | /* work around hardware counting issue */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6893 | hwstats->gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6894 | |
John Fastabend | c84d324 | 2010-11-16 19:27:12 -0800 | [diff] [blame] | 6895 | ixgbe_update_xoff_received(adapter); |
| 6896 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6897 | /* 82598 hardware only has a 32 bit counter in the high register */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6898 | switch (hw->mac.type) { |
| 6899 | case ixgbe_mac_82598EB: |
| 6900 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6901 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 6902 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 6903 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 6904 | break; |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 6905 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6906 | case ixgbe_mac_X550: |
| 6907 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 6908 | case ixgbe_mac_x550em_a: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 6909 | /* OS2BMC stats are X540 and later */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6910 | hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC); |
| 6911 | hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC); |
| 6912 | hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC); |
| 6913 | hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC); |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 6914 | /* fall through */ |
Emil Tantilov | 58f6bcf | 2011-04-21 08:43:43 +0000 | [diff] [blame] | 6915 | case ixgbe_mac_82599EB: |
Alexander Duyck | a4d4f62 | 2012-03-28 08:03:32 +0000 | [diff] [blame] | 6916 | for (i = 0; i < 16; i++) |
| 6917 | adapter->hw_rx_no_dma_resources += |
| 6918 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6919 | hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6920 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6921 | hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6922 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6923 | hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6924 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6925 | hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6926 | hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 6927 | hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6928 | #ifdef IXGBE_FCOE |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6929 | hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 6930 | hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 6931 | hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 6932 | hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 6933 | hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 6934 | hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6935 | /* Add up per cpu counters for total ddp aloc fail */ |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6936 | if (adapter->fcoe.ddp_pool) { |
| 6937 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 6938 | struct ixgbe_fcoe_ddp_pool *ddp_pool; |
| 6939 | unsigned int cpu; |
| 6940 | u64 noddp = 0, noddp_ext_buff = 0; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6941 | for_each_possible_cpu(cpu) { |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6942 | ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu); |
| 6943 | noddp += ddp_pool->noddp; |
| 6944 | noddp_ext_buff += ddp_pool->noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6945 | } |
Alexander Duyck | 5a1ee27 | 2012-05-05 17:14:28 +0000 | [diff] [blame] | 6946 | hwstats->fcoe_noddp = noddp; |
| 6947 | hwstats->fcoe_noddp_ext_buff = noddp_ext_buff; |
Amir Hanania | 7b859eb | 2011-08-31 02:07:55 +0000 | [diff] [blame] | 6948 | } |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 6949 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | bd50817 | 2010-11-16 19:27:03 -0800 | [diff] [blame] | 6950 | break; |
| 6951 | default: |
| 6952 | break; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6953 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6954 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6955 | hwstats->bprc += bprc; |
| 6956 | hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6957 | if (hw->mac.type == ixgbe_mac_82598EB) |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6958 | hwstats->mprc -= bprc; |
| 6959 | hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 6960 | hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 6961 | hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 6962 | hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 6963 | hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 6964 | hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 6965 | hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
| 6966 | hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6967 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6968 | hwstats->lxontxc += lxon; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6969 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6970 | hwstats->lxofftxc += lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6971 | hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
| 6972 | hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 6973 | /* |
| 6974 | * 82598 errata - tx of flow control packets is included in tx counters |
| 6975 | */ |
| 6976 | xon_off_tot = lxon + lxoff; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6977 | hwstats->gptc -= xon_off_tot; |
| 6978 | hwstats->mptc -= xon_off_tot; |
| 6979 | hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
| 6980 | hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 6981 | hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 6982 | hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
| 6983 | hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 6984 | hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
| 6985 | hwstats->ptc64 -= xon_off_tot; |
| 6986 | hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 6987 | hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 6988 | hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 6989 | hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 6990 | hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
| 6991 | hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6992 | |
| 6993 | /* Fill out the OS statistics structure */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6994 | netdev->stats.multicast = hwstats->mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6995 | |
| 6996 | /* Rx Errors */ |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6997 | netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 6998 | netdev->stats.rx_dropped = 0; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 6999 | netdev->stats.rx_length_errors = hwstats->rlec; |
| 7000 | netdev->stats.rx_crc_errors = hwstats->crcerrs; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 7001 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7002 | } |
| 7003 | |
| 7004 | /** |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7005 | * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7006 | * @adapter: pointer to the device adapter structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7007 | **/ |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7008 | static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7009 | { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7010 | struct ixgbe_hw *hw = &adapter->hw; |
| 7011 | int i; |
| 7012 | |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7013 | if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT)) |
| 7014 | return; |
| 7015 | |
| 7016 | adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT; |
| 7017 | |
| 7018 | /* if interface is down do nothing */ |
| 7019 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 7020 | return; |
| 7021 | |
| 7022 | /* do nothing if we are not using signature filters */ |
| 7023 | if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) |
| 7024 | return; |
| 7025 | |
| 7026 | adapter->fdir_overflow++; |
| 7027 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7028 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 7029 | for (i = 0; i < adapter->num_tx_queues; i++) |
Alexander Duyck | 7d637bc | 2010-11-16 19:26:56 -0800 | [diff] [blame] | 7030 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 7031 | &(adapter->tx_ring[i]->state)); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 7032 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 7033 | set_bit(__IXGBE_TX_FDIR_INIT_DONE, |
| 7034 | &adapter->xdp_ring[i]->state); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7035 | /* re-enable flow director interrupts */ |
| 7036 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7037 | } else { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 7038 | e_err(probe, "failed to finish FDIR re-initialization, " |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 7039 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7040 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7041 | } |
| 7042 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7043 | /** |
| 7044 | * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7045 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7046 | * |
| 7047 | * This function serves two purposes. First it strobes the interrupt lines |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 7048 | * in order to make certain interrupts are occurring. Secondly it sets the |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7049 | * 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] | 7050 | * determine if a hang has occurred. |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7051 | */ |
| 7052 | static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter) |
| 7053 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7054 | struct ixgbe_hw *hw = &adapter->hw; |
| 7055 | u64 eics = 0; |
| 7056 | int i; |
| 7057 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7058 | /* If we're down, removing or resetting, just bail */ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7059 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7060 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7061 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 7062 | return; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7063 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7064 | /* Force detection of hung controller */ |
| 7065 | if (netif_carrier_ok(adapter->netdev)) { |
| 7066 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 7067 | set_check_for_tx_hang(adapter->tx_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 7068 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 7069 | set_check_for_tx_hang(adapter->xdp_ring[i]); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7070 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7071 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 7072 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7073 | /* |
| 7074 | * for legacy and MSI interrupts don't set any bits |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 7075 | * that are enabled for EIAM, because this operation |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7076 | * would set *both* EIMS and EICS for any bit in EIAM |
| 7077 | */ |
| 7078 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 7079 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7080 | } else { |
| 7081 | /* get one bit for every active tx/rx interrupt vector */ |
Alexander Duyck | 49c7ffb | 2012-05-05 05:30:43 +0000 | [diff] [blame] | 7082 | for (i = 0; i < adapter->num_q_vectors; i++) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7083 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | efe3d3c | 2011-07-15 03:05:21 +0000 | [diff] [blame] | 7084 | if (qv->rx.ring || qv->tx.ring) |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 7085 | eics |= BIT_ULL(i); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7086 | } |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7087 | } |
| 7088 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7089 | /* Cause software interrupt to ensure rings are cleaned */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7090 | ixgbe_irq_rearm_queues(adapter, eics); |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 7091 | } |
| 7092 | |
| 7093 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7094 | * ixgbe_watchdog_update_link - update the link status |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7095 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7096 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7097 | static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7098 | { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 7099 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7100 | u32 link_speed = adapter->link_speed; |
| 7101 | bool link_up = adapter->link_up; |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 7102 | bool pfc_en = adapter->dcb_cfg.pfc_mode_enable; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7103 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7104 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) |
| 7105 | return; |
| 7106 | |
| 7107 | if (hw->mac.ops.check_link) { |
| 7108 | 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] | 7109 | } else { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7110 | /* always assume link is up, if no check link function */ |
| 7111 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7112 | link_up = true; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7113 | } |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 7114 | |
| 7115 | if (adapter->ixgbe_ieee_pfc) |
| 7116 | pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en); |
| 7117 | |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 7118 | if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) { |
Alexander Duyck | 041441d | 2012-04-19 17:48:48 +0000 | [diff] [blame] | 7119 | hw->mac.ops.fc_enable(hw); |
Alexander Duyck | 3ebe8fd | 2012-04-25 04:36:38 +0000 | [diff] [blame] | 7120 | ixgbe_set_rx_drop_en(adapter); |
| 7121 | } |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7122 | |
| 7123 | if (link_up || |
| 7124 | time_after(jiffies, (adapter->link_check_timeout + |
| 7125 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 7126 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7127 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 7128 | IXGBE_WRITE_FLUSH(hw); |
| 7129 | } |
| 7130 | |
| 7131 | adapter->link_up = link_up; |
| 7132 | adapter->link_speed = link_speed; |
| 7133 | } |
| 7134 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 7135 | static void ixgbe_update_default_up(struct ixgbe_adapter *adapter) |
| 7136 | { |
| 7137 | #ifdef CONFIG_IXGBE_DCB |
| 7138 | struct net_device *netdev = adapter->netdev; |
| 7139 | struct dcb_app app = { |
| 7140 | .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, |
| 7141 | .protocol = 0, |
| 7142 | }; |
| 7143 | u8 up = 0; |
| 7144 | |
| 7145 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE) |
| 7146 | up = dcb_ieee_getapp_mask(netdev, &app); |
| 7147 | |
| 7148 | adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0; |
| 7149 | #endif |
| 7150 | } |
| 7151 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7152 | /** |
| 7153 | * ixgbe_watchdog_link_is_up - update netif_carrier status and |
| 7154 | * print link up message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7155 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7156 | **/ |
| 7157 | static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter) |
| 7158 | { |
| 7159 | struct net_device *netdev = adapter->netdev; |
| 7160 | struct ixgbe_hw *hw = &adapter->hw; |
| 7161 | u32 link_speed = adapter->link_speed; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7162 | const char *speed_str; |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7163 | bool flow_rx, flow_tx; |
| 7164 | |
| 7165 | /* only continue if link was previously down */ |
| 7166 | if (netif_carrier_ok(netdev)) |
| 7167 | return; |
| 7168 | |
| 7169 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 7170 | |
| 7171 | switch (hw->mac.type) { |
| 7172 | case ixgbe_mac_82598EB: { |
| 7173 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 7174 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 7175 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 7176 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 7177 | } |
| 7178 | break; |
| 7179 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7180 | case ixgbe_mac_X550: |
| 7181 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 7182 | case ixgbe_mac_x550em_a: |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7183 | case ixgbe_mac_82599EB: { |
| 7184 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 7185 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 7186 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 7187 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 7188 | } |
| 7189 | break; |
| 7190 | default: |
| 7191 | flow_tx = false; |
| 7192 | flow_rx = false; |
| 7193 | break; |
| 7194 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7195 | |
Jacob Keller | 6cb562d | 2012-12-05 07:24:41 +0000 | [diff] [blame] | 7196 | adapter->last_rx_ptp_check = jiffies; |
| 7197 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7198 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 7199 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7200 | |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7201 | switch (link_speed) { |
| 7202 | case IXGBE_LINK_SPEED_10GB_FULL: |
| 7203 | speed_str = "10 Gbps"; |
| 7204 | break; |
Paul Greenwalt | 06e3f94 | 2018-01-11 09:10:51 -0500 | [diff] [blame] | 7205 | case IXGBE_LINK_SPEED_5GB_FULL: |
| 7206 | speed_str = "5 Gbps"; |
| 7207 | break; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7208 | case IXGBE_LINK_SPEED_2_5GB_FULL: |
| 7209 | speed_str = "2.5 Gbps"; |
| 7210 | break; |
| 7211 | case IXGBE_LINK_SPEED_1GB_FULL: |
| 7212 | speed_str = "1 Gbps"; |
| 7213 | break; |
| 7214 | case IXGBE_LINK_SPEED_100_FULL: |
| 7215 | speed_str = "100 Mbps"; |
| 7216 | break; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 7217 | case IXGBE_LINK_SPEED_10_FULL: |
| 7218 | speed_str = "10 Mbps"; |
| 7219 | break; |
Mark Rustad | 454adb0 | 2015-07-10 14:19:22 -0700 | [diff] [blame] | 7220 | default: |
| 7221 | speed_str = "unknown speed"; |
| 7222 | break; |
| 7223 | } |
| 7224 | e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str, |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7225 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 7226 | (flow_rx ? "RX" : |
| 7227 | (flow_tx ? "TX" : "None")))); |
| 7228 | |
| 7229 | netif_carrier_on(netdev); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7230 | ixgbe_check_vf_rate_limit(adapter); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7231 | |
Emil Tantilov | cdc04dc | 2014-03-20 03:47:53 +0000 | [diff] [blame] | 7232 | /* enable transmits */ |
| 7233 | netif_tx_wake_all_queues(adapter->netdev); |
| 7234 | |
Alexander Duyck | 107d301 | 2012-10-02 00:17:03 +0000 | [diff] [blame] | 7235 | /* update the default user priority for VFs */ |
| 7236 | ixgbe_update_default_up(adapter); |
| 7237 | |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7238 | /* ping all the active vfs to let them know link has changed */ |
| 7239 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | /** |
| 7243 | * ixgbe_watchdog_link_is_down - update netif_carrier status and |
| 7244 | * print link down message |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7245 | * @adapter: pointer to the adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7246 | **/ |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 7247 | static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7248 | { |
| 7249 | struct net_device *netdev = adapter->netdev; |
| 7250 | struct ixgbe_hw *hw = &adapter->hw; |
| 7251 | |
| 7252 | adapter->link_up = false; |
| 7253 | adapter->link_speed = 0; |
| 7254 | |
| 7255 | /* only continue if link was up previously */ |
| 7256 | if (!netif_carrier_ok(netdev)) |
| 7257 | return; |
| 7258 | |
| 7259 | /* poll for SFP+ cable when link is down */ |
| 7260 | if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB) |
| 7261 | adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP; |
| 7262 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7263 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) |
Jacob Keller | 1a71ab2 | 2012-08-25 03:54:19 +0000 | [diff] [blame] | 7264 | ixgbe_ptp_start_cyclecounter(adapter); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7265 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7266 | e_info(drv, "NIC Link is Down\n"); |
| 7267 | netif_carrier_off(netdev); |
Alexander Duyck | befa2af | 2012-05-05 05:30:38 +0000 | [diff] [blame] | 7268 | |
| 7269 | /* ping all the active vfs to let them know link has changed */ |
| 7270 | ixgbe_ping_all_vfs(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7271 | } |
| 7272 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7273 | static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter) |
| 7274 | { |
| 7275 | int i; |
| 7276 | |
| 7277 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 7278 | struct ixgbe_ring *tx_ring = adapter->tx_ring[i]; |
| 7279 | |
| 7280 | if (tx_ring->next_to_use != tx_ring->next_to_clean) |
| 7281 | return true; |
| 7282 | } |
| 7283 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 7284 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 7285 | struct ixgbe_ring *ring = adapter->xdp_ring[i]; |
| 7286 | |
| 7287 | if (ring->next_to_use != ring->next_to_clean) |
| 7288 | return true; |
| 7289 | } |
| 7290 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7291 | return false; |
| 7292 | } |
| 7293 | |
| 7294 | static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter) |
| 7295 | { |
| 7296 | struct ixgbe_hw *hw = &adapter->hw; |
| 7297 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
| 7298 | u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask); |
| 7299 | |
| 7300 | int i, j; |
| 7301 | |
| 7302 | if (!adapter->num_vfs) |
| 7303 | return false; |
| 7304 | |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 7305 | /* resetting the PF is only needed for MAC before X550 */ |
| 7306 | if (hw->mac.type >= ixgbe_mac_X550) |
| 7307 | return false; |
| 7308 | |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7309 | for (i = 0; i < adapter->num_vfs; i++) { |
| 7310 | for (j = 0; j < q_per_pool; j++) { |
| 7311 | u32 h, t; |
| 7312 | |
| 7313 | h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j)); |
| 7314 | t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j)); |
| 7315 | |
| 7316 | if (h != t) |
| 7317 | return true; |
| 7318 | } |
| 7319 | } |
| 7320 | |
| 7321 | return false; |
| 7322 | } |
| 7323 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7324 | /** |
| 7325 | * ixgbe_watchdog_flush_tx - flush queues on link down |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7326 | * @adapter: pointer to the device adapter structure |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7327 | **/ |
| 7328 | static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter) |
| 7329 | { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7330 | if (!netif_carrier_ok(adapter->netdev)) { |
Emil Tantilov | 07923c1 | 2014-08-12 07:12:08 +0000 | [diff] [blame] | 7331 | if (ixgbe_ring_tx_pending(adapter) || |
| 7332 | ixgbe_vf_tx_pending(adapter)) { |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7333 | /* We've lost link, so the controller stops DMA, |
| 7334 | * but we've got queued Tx work that's never going |
| 7335 | * to get done, so reset controller to flush Tx. |
| 7336 | * (Do the reset outside of interrupt context). |
| 7337 | */ |
Jacob Keller | 12ff3f3 | 2012-12-01 07:57:17 +0000 | [diff] [blame] | 7338 | e_warn(drv, "initiating reset to clear Tx work after link loss\n"); |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 7339 | set_bit(__IXGBE_RESET_REQUESTED, &adapter->state); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7340 | } |
| 7341 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7342 | } |
| 7343 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7344 | #ifdef CONFIG_PCI_IOV |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7345 | static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter) |
| 7346 | { |
| 7347 | struct ixgbe_hw *hw = &adapter->hw; |
| 7348 | struct pci_dev *pdev = adapter->pdev; |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7349 | unsigned int vf; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7350 | u32 gpc; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7351 | |
| 7352 | if (!(netif_carrier_ok(adapter->netdev))) |
| 7353 | return; |
| 7354 | |
| 7355 | gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC); |
| 7356 | if (gpc) /* If incrementing then no need for the check below */ |
| 7357 | return; |
| 7358 | /* Check to see if a bad DMA write target from an errant or |
| 7359 | * malicious VF has caused a PCIe error. If so then we can |
| 7360 | * issue a VFLR to the offending VF(s) and then resume without |
| 7361 | * requesting a full slot reset. |
| 7362 | */ |
| 7363 | |
| 7364 | if (!pdev) |
| 7365 | return; |
| 7366 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7367 | /* check status reg for all VFs owned by this PF */ |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7368 | for (vf = 0; vf < adapter->num_vfs; ++vf) { |
| 7369 | struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev; |
| 7370 | u16 status_reg; |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7371 | |
Mark Rustad | 988d130 | 2015-10-30 15:29:34 -0700 | [diff] [blame] | 7372 | if (!vfdev) |
| 7373 | continue; |
| 7374 | pci_read_config_word(vfdev, PCI_STATUS, &status_reg); |
| 7375 | if (status_reg != IXGBE_FAILED_READ_CFG_WORD && |
| 7376 | status_reg & PCI_STATUS_REC_MASTER_ABORT) |
Christoph Hellwig | 63af8f7 | 2017-04-14 21:11:28 +0200 | [diff] [blame] | 7377 | pcie_flr(vfdev); |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7378 | } |
| 7379 | } |
| 7380 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7381 | static void ixgbe_spoof_check(struct ixgbe_adapter *adapter) |
| 7382 | { |
| 7383 | u32 ssvpc; |
| 7384 | |
Greg Rose | 0584d99 | 2012-08-08 00:00:58 +0000 | [diff] [blame] | 7385 | /* Do not perform spoof check for 82598 or if not in IOV mode */ |
| 7386 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 7387 | adapter->num_vfs == 0) |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7388 | return; |
| 7389 | |
| 7390 | ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC); |
| 7391 | |
| 7392 | /* |
| 7393 | * ssvpc register is cleared on read, if zero then no |
| 7394 | * spoofed packets in the last interval. |
| 7395 | */ |
| 7396 | if (!ssvpc) |
| 7397 | return; |
| 7398 | |
Emil Tantilov | d6ea075 | 2012-08-08 06:28:37 +0000 | [diff] [blame] | 7399 | e_warn(drv, "%u Spoofed packets detected\n", ssvpc); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7400 | } |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7401 | #else |
| 7402 | static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter) |
| 7403 | { |
| 7404 | } |
| 7405 | |
| 7406 | static void |
| 7407 | ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter) |
| 7408 | { |
| 7409 | } |
| 7410 | #endif /* CONFIG_PCI_IOV */ |
| 7411 | |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7412 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 7413 | /** |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7414 | * ixgbe_watchdog_subtask - check and bring link up |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7415 | * @adapter: pointer to the device adapter structure |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7416 | **/ |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7417 | static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7418 | { |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7419 | /* if interface is down, removing or resetting, do nothing */ |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7420 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7421 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Emil Tantilov | 7edebf9 | 2011-08-27 07:18:37 +0000 | [diff] [blame] | 7422 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7423 | return; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 7424 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7425 | ixgbe_watchdog_update_link(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 7426 | |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7427 | if (adapter->link_up) |
| 7428 | ixgbe_watchdog_link_is_up(adapter); |
| 7429 | else |
| 7430 | ixgbe_watchdog_link_is_down(adapter); |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 7431 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7432 | ixgbe_check_for_bad_vf(adapter); |
Greg Rose | a985b6c3 | 2010-11-18 03:02:52 +0000 | [diff] [blame] | 7433 | ixgbe_spoof_check(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7434 | ixgbe_update_stats(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7435 | |
| 7436 | ixgbe_watchdog_flush_tx(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7437 | } |
| 7438 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7439 | /** |
| 7440 | * ixgbe_sfp_detection_subtask - poll for SFP+ cable |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7441 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7442 | **/ |
| 7443 | static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter) |
| 7444 | { |
| 7445 | struct ixgbe_hw *hw = &adapter->hw; |
| 7446 | s32 err; |
| 7447 | |
| 7448 | /* not searching for SFP so there is nothing to do here */ |
| 7449 | if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) && |
| 7450 | !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7451 | return; |
| 7452 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7453 | if (adapter->sfp_poll_time && |
| 7454 | time_after(adapter->sfp_poll_time, jiffies)) |
| 7455 | return; /* If not yet time to poll for SFP */ |
| 7456 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7457 | /* someone else is in init, wait until next service event */ |
| 7458 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7459 | return; |
| 7460 | |
Mark Rustad | 58e7cd2 | 2015-08-08 16:18:48 -0700 | [diff] [blame] | 7461 | adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1; |
| 7462 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7463 | err = hw->phy.ops.identify_sfp(hw); |
| 7464 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7465 | goto sfp_out; |
| 7466 | |
| 7467 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 7468 | /* If no cable is present, then we need to reset |
| 7469 | * the next time we find a good cable. */ |
| 7470 | adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7471 | } |
| 7472 | |
| 7473 | /* exit on error */ |
| 7474 | if (err) |
| 7475 | goto sfp_out; |
| 7476 | |
| 7477 | /* exit if reset not needed */ |
| 7478 | if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET)) |
| 7479 | goto sfp_out; |
| 7480 | |
| 7481 | adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET; |
| 7482 | |
| 7483 | /* |
| 7484 | * A module may be identified correctly, but the EEPROM may not have |
| 7485 | * support for that module. setup_sfp() will fail in that case, so |
| 7486 | * we should not allow that module to load. |
| 7487 | */ |
| 7488 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 7489 | err = hw->phy.ops.reset(hw); |
| 7490 | else |
| 7491 | err = hw->mac.ops.setup_sfp(hw); |
| 7492 | |
| 7493 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) |
| 7494 | goto sfp_out; |
| 7495 | |
| 7496 | adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7497 | e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type); |
| 7498 | |
| 7499 | sfp_out: |
| 7500 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7501 | |
| 7502 | if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) && |
| 7503 | (adapter->netdev->reg_state == NETREG_REGISTERED)) { |
| 7504 | e_dev_err("failed to initialize because an unsupported " |
| 7505 | "SFP+ module type was detected.\n"); |
| 7506 | e_dev_err("Reload the driver after installing a " |
| 7507 | "supported module.\n"); |
| 7508 | unregister_netdev(adapter->netdev); |
| 7509 | } |
| 7510 | } |
| 7511 | |
| 7512 | /** |
| 7513 | * ixgbe_sfp_link_config_subtask - set up link SFP after module install |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 7514 | * @adapter: the ixgbe adapter structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7515 | **/ |
| 7516 | static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter) |
| 7517 | { |
| 7518 | struct ixgbe_hw *hw = &adapter->hw; |
Paul Greenwalt | 3ead7c2 | 2017-10-24 11:00:40 -0400 | [diff] [blame] | 7519 | u32 cap_speed; |
Josh Hay | 3d29226 | 2012-12-15 03:28:19 +0000 | [diff] [blame] | 7520 | u32 speed; |
| 7521 | bool autoneg = false; |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7522 | |
| 7523 | if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG)) |
| 7524 | return; |
| 7525 | |
| 7526 | /* someone else is in init, wait until next service event */ |
| 7527 | if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state)) |
| 7528 | return; |
| 7529 | |
| 7530 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG; |
| 7531 | |
Paul Greenwalt | 3ead7c2 | 2017-10-24 11:00:40 -0400 | [diff] [blame] | 7532 | hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7533 | |
Paul Greenwalt | 3ead7c2 | 2017-10-24 11:00:40 -0400 | [diff] [blame] | 7534 | /* advertise highest capable link speed */ |
| 7535 | if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL)) |
| 7536 | speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 7537 | else |
| 7538 | speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL | |
| 7539 | IXGBE_LINK_SPEED_1GB_FULL); |
Emil Tantilov | ed33ff6 | 2013-08-30 07:55:24 +0000 | [diff] [blame] | 7540 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7541 | if (hw->mac.ops.setup_link) |
Josh Hay | fd0326f | 2012-12-15 03:28:30 +0000 | [diff] [blame] | 7542 | hw->mac.ops.setup_link(hw, speed, true); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7543 | |
| 7544 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 7545 | adapter->link_check_timeout = jiffies; |
| 7546 | clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state); |
| 7547 | } |
| 7548 | |
| 7549 | /** |
| 7550 | * ixgbe_service_timer - Timer Call-back |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 7551 | * @t: pointer to timer_list structure |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7552 | **/ |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 7553 | static void ixgbe_service_timer(struct timer_list *t) |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7554 | { |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 7555 | struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7556 | unsigned long next_event_offset; |
| 7557 | |
| 7558 | /* poll faster when waiting for link */ |
| 7559 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) |
| 7560 | next_event_offset = HZ / 10; |
| 7561 | else |
| 7562 | next_event_offset = HZ * 2; |
| 7563 | |
| 7564 | /* Reset the timer */ |
| 7565 | mod_timer(&adapter->service_timer, next_event_offset + jiffies); |
| 7566 | |
Emil Tantilov | 9079e41 | 2014-11-19 03:18:19 +0000 | [diff] [blame] | 7567 | ixgbe_service_event_schedule(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7568 | } |
| 7569 | |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7570 | static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter) |
| 7571 | { |
| 7572 | struct ixgbe_hw *hw = &adapter->hw; |
| 7573 | u32 status; |
| 7574 | |
| 7575 | if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT)) |
| 7576 | return; |
| 7577 | |
| 7578 | adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT; |
| 7579 | |
| 7580 | if (!hw->phy.ops.handle_lasi) |
| 7581 | return; |
| 7582 | |
| 7583 | status = hw->phy.ops.handle_lasi(&adapter->hw); |
| 7584 | if (status != IXGBE_ERR_OVERTEMP) |
| 7585 | return; |
| 7586 | |
| 7587 | e_crit(drv, "%s\n", ixgbe_overheat_msg); |
| 7588 | } |
| 7589 | |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7590 | static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter) |
| 7591 | { |
Emil Tantilov | 57ca2a4 | 2016-07-29 14:46:31 -0700 | [diff] [blame] | 7592 | if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state)) |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7593 | return; |
| 7594 | |
Tony Nguyen | 88adce4 | 2018-05-30 09:05:12 -0700 | [diff] [blame] | 7595 | rtnl_lock(); |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7596 | /* If we're already down, removing or resetting, just bail */ |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7597 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 7598 | test_bit(__IXGBE_REMOVING, &adapter->state) || |
Tony Nguyen | 88adce4 | 2018-05-30 09:05:12 -0700 | [diff] [blame] | 7599 | test_bit(__IXGBE_RESETTING, &adapter->state)) { |
| 7600 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7601 | return; |
Tony Nguyen | 88adce4 | 2018-05-30 09:05:12 -0700 | [diff] [blame] | 7602 | } |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7603 | |
| 7604 | ixgbe_dump(adapter); |
| 7605 | netdev_err(adapter->netdev, "Reset adapter\n"); |
| 7606 | adapter->tx_timeout_count++; |
| 7607 | |
| 7608 | ixgbe_reinit_locked(adapter); |
John Fastabend | 8f4c5c9 | 2014-01-16 02:30:05 -0800 | [diff] [blame] | 7609 | rtnl_unlock(); |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7610 | } |
| 7611 | |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7612 | /** |
| 7613 | * ixgbe_service_task - manages and runs subtasks |
| 7614 | * @work: pointer to work_struct containing our data |
| 7615 | **/ |
| 7616 | static void ixgbe_service_task(struct work_struct *work) |
| 7617 | { |
| 7618 | struct ixgbe_adapter *adapter = container_of(work, |
| 7619 | struct ixgbe_adapter, |
| 7620 | service_task); |
Mark Rustad | b0483c8 | 2014-01-14 18:53:17 -0800 | [diff] [blame] | 7621 | if (ixgbe_removed(adapter->hw.hw_addr)) { |
| 7622 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 7623 | rtnl_lock(); |
| 7624 | ixgbe_down(adapter); |
| 7625 | rtnl_unlock(); |
| 7626 | } |
| 7627 | ixgbe_service_event_complete(adapter); |
| 7628 | return; |
| 7629 | } |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7630 | if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) { |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7631 | rtnl_lock(); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 7632 | adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 7633 | udp_tunnel_get_rx_info(adapter->netdev); |
| 7634 | rtnl_unlock(); |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 7635 | } |
Alexander Duyck | c83c6cb | 2011-04-27 09:21:16 +0000 | [diff] [blame] | 7636 | ixgbe_reset_subtask(adapter); |
Don Skidmore | 597f22d | 2015-06-09 16:52:02 -0700 | [diff] [blame] | 7637 | ixgbe_phy_interrupt_subtask(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7638 | ixgbe_sfp_detection_subtask(adapter); |
| 7639 | ixgbe_sfp_link_config_subtask(adapter); |
Alexander Duyck | f0f9778 | 2011-04-22 04:08:09 +0000 | [diff] [blame] | 7640 | ixgbe_check_overtemp_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7641 | ixgbe_watchdog_subtask(adapter); |
Alexander Duyck | d034acf | 2011-04-27 09:25:34 +0000 | [diff] [blame] | 7642 | ixgbe_fdir_reinit_subtask(adapter); |
Alexander Duyck | 93c52dd | 2011-04-22 04:07:54 +0000 | [diff] [blame] | 7643 | ixgbe_check_hang_subtask(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7644 | |
Jacob Keller | 8fecf67 | 2013-06-21 08:14:32 +0000 | [diff] [blame] | 7645 | if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) { |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7646 | ixgbe_ptp_overflow_check(adapter); |
Jacob Keller | 6704a3a | 2018-01-29 15:57:48 -0800 | [diff] [blame] | 7647 | if (adapter->flags & IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER) |
| 7648 | ixgbe_ptp_rx_hang(adapter); |
Jacob Keller | 622a2ef | 2017-05-03 10:29:04 -0700 | [diff] [blame] | 7649 | ixgbe_ptp_tx_hang(adapter); |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 7650 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 7651 | |
| 7652 | ixgbe_service_event_complete(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7653 | } |
| 7654 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7655 | static int ixgbe_tso(struct ixgbe_ring *tx_ring, |
| 7656 | struct ixgbe_tx_buffer *first, |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 7657 | u8 *hdr_len, |
| 7658 | struct ixgbe_ipsec_tx_data *itd) |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7659 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7660 | u32 vlan_macip_lens, type_tucmd, mss_l4len_idx; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7661 | struct sk_buff *skb = first->skb; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7662 | union { |
| 7663 | struct iphdr *v4; |
| 7664 | struct ipv6hdr *v6; |
| 7665 | unsigned char *hdr; |
| 7666 | } ip; |
| 7667 | union { |
| 7668 | struct tcphdr *tcp; |
| 7669 | unsigned char *hdr; |
| 7670 | } l4; |
| 7671 | u32 paylen, l4_offset; |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 7672 | u32 fceof_saidx = 0; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7673 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7674 | |
Alexander Duyck | 8f4fbb9 | 2012-10-30 06:01:40 +0000 | [diff] [blame] | 7675 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 7676 | return 0; |
| 7677 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7678 | if (!skb_is_gso(skb)) |
| 7679 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7680 | |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 7681 | err = skb_cow_head(skb, 0); |
| 7682 | if (err < 0) |
| 7683 | return err; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7684 | |
Scott Peterson | 2a20525 | 2016-11-18 11:25:42 -0800 | [diff] [blame] | 7685 | if (eth_p_mpls(first->protocol)) |
| 7686 | ip.hdr = skb_inner_network_header(skb); |
| 7687 | else |
| 7688 | ip.hdr = skb_network_header(skb); |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7689 | l4.hdr = skb_checksum_start(skb); |
| 7690 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7691 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 7692 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7693 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7694 | /* initialize outer IP header fields */ |
| 7695 | if (ip.v4->version == 4) { |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7696 | unsigned char *csum_start = skb_checksum_start(skb); |
| 7697 | unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4); |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 7698 | int len = csum_start - trans_start; |
Alexander Duyck | c54cdc3 | 2016-11-28 10:42:29 -0500 | [diff] [blame] | 7699 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7700 | /* IP header will have to cancel out any data that |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 7701 | * is not a part of the outer IP header, so set to |
| 7702 | * a reverse csum if needed, else init check to 0. |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7703 | */ |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 7704 | ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ? |
| 7705 | csum_fold(csum_partial(trans_start, |
| 7706 | len, 0)) : 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7707 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7708 | |
| 7709 | ip.v4->tot_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7710 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7711 | IXGBE_TX_FLAGS_CSUM | |
| 7712 | IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7713 | } else { |
| 7714 | ip.v6->payload_len = 0; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7715 | first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 7716 | IXGBE_TX_FLAGS_CSUM; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7717 | } |
| 7718 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7719 | /* determine offset of inner transport header */ |
| 7720 | l4_offset = l4.hdr - skb->data; |
| 7721 | |
| 7722 | /* compute length of segmentation header */ |
| 7723 | *hdr_len = (l4.tcp->doff * 4) + l4_offset; |
| 7724 | |
| 7725 | /* remove payload length from inner checksum */ |
| 7726 | paylen = skb->len - l4_offset; |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 7727 | csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen)); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7728 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 7729 | /* update gso size and bytecount with header size */ |
| 7730 | first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 7731 | first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 7732 | |
Alexander Duyck | c44f5f5 | 2012-10-30 06:01:45 +0000 | [diff] [blame] | 7733 | /* mss_l4len_id: use 0 as index for TSO */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7734 | mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7735 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7736 | |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 7737 | fceof_saidx |= itd->sa_idx; |
| 7738 | type_tucmd |= itd->flags | itd->trailer_len; |
| 7739 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7740 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 7741 | vlan_macip_lens = l4.hdr - ip.hdr; |
| 7742 | vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7743 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7744 | |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 7745 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7746 | mss_l4len_idx); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7747 | |
| 7748 | return 1; |
Joe Perches | 7ca647b | 2010-09-07 21:35:40 +0000 | [diff] [blame] | 7749 | } |
| 7750 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7751 | static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb) |
| 7752 | { |
| 7753 | unsigned int offset = 0; |
| 7754 | |
| 7755 | ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL); |
| 7756 | |
| 7757 | return offset == skb_checksum_start_offset(skb); |
| 7758 | } |
| 7759 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7760 | static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring, |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 7761 | struct ixgbe_tx_buffer *first, |
| 7762 | struct ixgbe_ipsec_tx_data *itd) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7763 | { |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 7764 | struct sk_buff *skb = first->skb; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7765 | u32 vlan_macip_lens = 0; |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 7766 | u32 fceof_saidx = 0; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7767 | u32 type_tucmd = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7768 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7769 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7770 | csum_failed: |
| 7771 | if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | |
| 7772 | IXGBE_TX_FLAGS_CC))) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7773 | return; |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7774 | goto no_csum; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7775 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 7776 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7777 | switch (skb->csum_offset) { |
| 7778 | case offsetof(struct tcphdr, check): |
| 7779 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 7780 | /* fall through */ |
| 7781 | case offsetof(struct udphdr, check): |
| 7782 | break; |
| 7783 | case offsetof(struct sctphdr, checksum): |
| 7784 | /* validate that this is actually an SCTP request */ |
| 7785 | if (((first->protocol == htons(ETH_P_IP)) && |
| 7786 | (ip_hdr(skb)->protocol == IPPROTO_SCTP)) || |
| 7787 | ((first->protocol == htons(ETH_P_IPV6)) && |
| 7788 | ixgbe_ipv6_csum_is_sctp(skb))) { |
| 7789 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 7790 | break; |
| 7791 | } |
| 7792 | /* fall through */ |
| 7793 | default: |
| 7794 | skb_checksum_help(skb); |
| 7795 | goto csum_failed; |
| 7796 | } |
| 7797 | |
| 7798 | /* update TX checksum flag */ |
| 7799 | first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 7800 | vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 7801 | skb_network_offset(skb); |
Mark Rustad | 36a92d7 | 2015-11-18 09:21:28 -0800 | [diff] [blame] | 7802 | no_csum: |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7803 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 7804 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7805 | vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 7806 | |
Shannon Nelson | 871dd09 | 2018-03-16 11:09:05 -0700 | [diff] [blame] | 7807 | fceof_saidx |= itd->sa_idx; |
| 7808 | type_tucmd |= itd->flags | itd->trailer_len; |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 7809 | |
| 7810 | ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7811 | } |
| 7812 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7813 | #define IXGBE_SET_FLAG(_input, _flag, _result) \ |
| 7814 | ((_flag <= _result) ? \ |
| 7815 | ((u32)(_input & _flag) * (_result / _flag)) : \ |
| 7816 | ((u32)(_input & _flag) / (_flag / _result))) |
| 7817 | |
| 7818 | 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] | 7819 | { |
| 7820 | /* set type for advanced descriptor with frame checksum insertion */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7821 | u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 7822 | IXGBE_ADVTXD_DCMD_DEXT | |
| 7823 | IXGBE_ADVTXD_DCMD_IFCS; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7824 | |
| 7825 | /* set HW vlan bit if vlan is present */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7826 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN, |
| 7827 | IXGBE_ADVTXD_DCMD_VLE); |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 7828 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7829 | /* set segmentation enable bits for TSO/FSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7830 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO, |
| 7831 | IXGBE_ADVTXD_DCMD_TSE); |
| 7832 | |
| 7833 | /* set timestamp bit if present */ |
| 7834 | cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP, |
| 7835 | IXGBE_ADVTXD_MAC_TSTAMP); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7836 | |
Alexander Duyck | 62748b7 | 2012-07-20 08:09:01 +0000 | [diff] [blame] | 7837 | /* insert frame checksum */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7838 | 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] | 7839 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7840 | return cmd_type; |
| 7841 | } |
| 7842 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7843 | static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 7844 | u32 tx_flags, unsigned int paylen) |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7845 | { |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7846 | u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7847 | |
| 7848 | /* enable L4 checksum for TSO and TX checksum offload */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7849 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7850 | IXGBE_TX_FLAGS_CSUM, |
| 7851 | IXGBE_ADVTXD_POPTS_TXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7852 | |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 7853 | /* enable IPv4 checksum for TSO */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7854 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7855 | IXGBE_TX_FLAGS_IPV4, |
| 7856 | IXGBE_ADVTXD_POPTS_IXSM); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7857 | |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 7858 | /* enable IPsec */ |
| 7859 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7860 | IXGBE_TX_FLAGS_IPSEC, |
| 7861 | IXGBE_ADVTXD_POPTS_IPSEC); |
| 7862 | |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7863 | /* |
| 7864 | * Check Context must be set if Tx switch is enabled, which it |
| 7865 | * always is for case where virtual functions are running |
| 7866 | */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7867 | olinfo_status |= IXGBE_SET_FLAG(tx_flags, |
| 7868 | IXGBE_TX_FLAGS_CC, |
| 7869 | IXGBE_ADVTXD_CC); |
Alexander Duyck | 7f9643f | 2011-06-29 05:43:27 +0000 | [diff] [blame] | 7870 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7871 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7872 | } |
| 7873 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 7874 | static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7875 | { |
| 7876 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7877 | |
| 7878 | /* Herbert's original patch had: |
| 7879 | * smp_mb__after_netif_stop_queue(); |
| 7880 | * but since that doesn't exist yet, just open code it. |
| 7881 | */ |
| 7882 | smp_mb(); |
| 7883 | |
| 7884 | /* We need to check again in a case another CPU has just |
| 7885 | * made room available. |
| 7886 | */ |
| 7887 | if (likely(ixgbe_desc_unused(tx_ring) < size)) |
| 7888 | return -EBUSY; |
| 7889 | |
| 7890 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
| 7891 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 7892 | ++tx_ring->tx_stats.restart_queue; |
| 7893 | return 0; |
| 7894 | } |
| 7895 | |
| 7896 | static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size) |
| 7897 | { |
| 7898 | if (likely(ixgbe_desc_unused(tx_ring) >= size)) |
| 7899 | return 0; |
| 7900 | |
| 7901 | return __ixgbe_maybe_stop_tx(tx_ring, size); |
| 7902 | } |
| 7903 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7904 | #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \ |
| 7905 | IXGBE_TXD_CMD_RS) |
| 7906 | |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 7907 | static int ixgbe_tx_map(struct ixgbe_ring *tx_ring, |
| 7908 | struct ixgbe_tx_buffer *first, |
| 7909 | const u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7910 | { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7911 | struct sk_buff *skb = first->skb; |
| 7912 | struct ixgbe_tx_buffer *tx_buffer; |
| 7913 | union ixgbe_adv_tx_desc *tx_desc; |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7914 | struct skb_frag_struct *frag; |
| 7915 | dma_addr_t dma; |
| 7916 | unsigned int data_len, size; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 7917 | u32 tx_flags = first->tx_flags; |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7918 | u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7919 | u16 i = tx_ring->next_to_use; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7920 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7921 | tx_desc = IXGBE_TX_DESC(tx_ring, i); |
| 7922 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7923 | ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 7924 | |
| 7925 | size = skb_headlen(skb); |
| 7926 | data_len = skb->data_len; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7927 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7928 | #ifdef IXGBE_FCOE |
| 7929 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7930 | if (data_len < sizeof(struct fcoe_crc_eof)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7931 | size -= sizeof(struct fcoe_crc_eof) - data_len; |
| 7932 | data_len = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7933 | } else { |
| 7934 | data_len -= sizeof(struct fcoe_crc_eof); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7935 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7936 | } |
| 7937 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7938 | #endif |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7939 | 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] | 7940 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7941 | tx_buffer = first; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7942 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7943 | for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 7944 | if (dma_mapping_error(tx_ring->dev, dma)) |
| 7945 | goto dma_error; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7946 | |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7947 | /* record length, and DMA address */ |
| 7948 | dma_unmap_len_set(tx_buffer, len, size); |
| 7949 | dma_unmap_addr_set(tx_buffer, dma, dma); |
| 7950 | |
| 7951 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 7952 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7953 | while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7954 | tx_desc->read.cmd_type_len = |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7955 | cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7956 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7957 | i++; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7958 | tx_desc++; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7959 | if (i == tx_ring->count) { |
Alexander Duyck | e4f7402 | 2012-01-31 02:59:44 +0000 | [diff] [blame] | 7960 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7961 | i = 0; |
| 7962 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7963 | tx_desc->read.olinfo_status = 0; |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7964 | |
| 7965 | dma += IXGBE_MAX_DATA_PER_TXD; |
| 7966 | size -= IXGBE_MAX_DATA_PER_TXD; |
| 7967 | |
| 7968 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7969 | } |
| 7970 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7971 | if (likely(!data_len)) |
| 7972 | break; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7973 | |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7974 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7975 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7976 | i++; |
| 7977 | tx_desc++; |
| 7978 | if (i == tx_ring->count) { |
| 7979 | tx_desc = IXGBE_TX_DESC(tx_ring, 0); |
| 7980 | i = 0; |
| 7981 | } |
Alexander Duyck | ec71825 | 2012-10-30 06:01:55 +0000 | [diff] [blame] | 7982 | tx_desc->read.olinfo_status = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7983 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7984 | #ifdef IXGBE_FCOE |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7985 | size = min_t(unsigned int, data_len, skb_frag_size(frag)); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7986 | #else |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7987 | size = skb_frag_size(frag); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 7988 | #endif |
| 7989 | data_len -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7990 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7991 | dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 7992 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7993 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7994 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 7995 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 7996 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 7997 | /* write last descriptor with RS and EOP bits */ |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 7998 | cmd_type |= size | IXGBE_TXD_CMD; |
| 7999 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8000 | |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 8001 | netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount); |
Alexander Duyck | b2d96e0 | 2012-02-07 08:14:33 +0000 | [diff] [blame] | 8002 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8003 | /* set the timestamp */ |
| 8004 | first->time_stamp = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8005 | |
| 8006 | /* |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8007 | * Force memory writes to complete before letting h/w know there |
| 8008 | * are new descriptors to fetch. (Only applicable for weak-ordered |
| 8009 | * memory model archs, such as IA-64). |
| 8010 | * |
| 8011 | * We also need this memory barrier to make certain all of the |
| 8012 | * status bits have been updated before next_to_watch is written. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8013 | */ |
| 8014 | wmb(); |
| 8015 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8016 | /* set next_to_watch value indicating a packet is present */ |
| 8017 | first->next_to_watch = tx_desc; |
| 8018 | |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8019 | i++; |
| 8020 | if (i == tx_ring->count) |
| 8021 | i = 0; |
| 8022 | |
| 8023 | tx_ring->next_to_use = i; |
| 8024 | |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 8025 | ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 8026 | |
| 8027 | if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) { |
Alexander Duyck | ad435ec | 2014-11-14 00:56:35 +0000 | [diff] [blame] | 8028 | writel(i, tx_ring->tail); |
| 8029 | |
| 8030 | /* we need this if more than one processor can write to our tail |
| 8031 | * at a time, it synchronizes IO on IA64/Altix systems |
| 8032 | */ |
| 8033 | mmiowb(); |
Daniel Borkmann | 9c938cd | 2014-08-24 15:42:16 +0200 | [diff] [blame] | 8034 | } |
Daniel Borkmann | 2367a17 | 2014-08-26 19:34:18 +0200 | [diff] [blame] | 8035 | |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8036 | return 0; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8037 | dma_error: |
Alexander Duyck | 729739b | 2012-02-08 07:51:06 +0000 | [diff] [blame] | 8038 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8039 | |
| 8040 | /* clear dma mappings for failed tx_buffer_info map */ |
Alexander Duyck | 069db9c | 2017-10-19 17:07:13 -0400 | [diff] [blame] | 8041 | for (;;) { |
| 8042 | tx_buffer = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 8043 | if (dma_unmap_len(tx_buffer, len)) |
| 8044 | dma_unmap_page(tx_ring->dev, |
| 8045 | dma_unmap_addr(tx_buffer, dma), |
| 8046 | dma_unmap_len(tx_buffer, len), |
| 8047 | DMA_TO_DEVICE); |
| 8048 | dma_unmap_len_set(tx_buffer, len, 0); |
Alexander Duyck | 069db9c | 2017-10-19 17:07:13 -0400 | [diff] [blame] | 8049 | if (tx_buffer == first) |
| 8050 | break; |
| 8051 | if (i == 0) |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 8052 | i += tx_ring->count; |
Alexander Duyck | 069db9c | 2017-10-19 17:07:13 -0400 | [diff] [blame] | 8053 | i--; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8054 | } |
| 8055 | |
Alexander Duyck | ffed21b | 2017-01-17 08:37:29 -0800 | [diff] [blame] | 8056 | dev_kfree_skb_any(first->skb); |
| 8057 | first->skb = NULL; |
| 8058 | |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8059 | tx_ring->next_to_use = i; |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8060 | |
| 8061 | return -1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8062 | } |
| 8063 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8064 | static void ixgbe_atr(struct ixgbe_ring *ring, |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8065 | struct ixgbe_tx_buffer *first) |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8066 | { |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8067 | struct ixgbe_q_vector *q_vector = ring->q_vector; |
| 8068 | union ixgbe_atr_hash_dword input = { .dword = 0 }; |
| 8069 | union ixgbe_atr_hash_dword common = { .dword = 0 }; |
| 8070 | union { |
| 8071 | unsigned char *network; |
| 8072 | struct iphdr *ipv4; |
| 8073 | struct ipv6hdr *ipv6; |
| 8074 | } hdr; |
Alexander Duyck | ee9e0f0 | 2010-11-16 19:27:01 -0800 | [diff] [blame] | 8075 | struct tcphdr *th; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8076 | unsigned int hlen; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8077 | struct sk_buff *skb; |
Alexander Duyck | 905e4a4 | 2011-01-06 14:29:57 +0000 | [diff] [blame] | 8078 | __be16 vlan_id; |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8079 | int l4_proto; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8080 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8081 | /* if ring doesn't have a interrupt vector, cannot perform ATR */ |
| 8082 | if (!q_vector) |
Guillaume Gaudonville | d3ead24 | 2010-06-29 18:29:00 +0000 | [diff] [blame] | 8083 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8084 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8085 | /* do nothing if sampling is disabled */ |
| 8086 | if (!ring->atr_sample_rate) |
| 8087 | return; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8088 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8089 | ring->atr_count++; |
| 8090 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8091 | /* currently only IPv4/IPv6 with TCP is supported */ |
| 8092 | if ((first->protocol != htons(ETH_P_IP)) && |
| 8093 | (first->protocol != htons(ETH_P_IPV6))) |
| 8094 | return; |
| 8095 | |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8096 | /* snag network header to get L4 type and address */ |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8097 | skb = first->skb; |
| 8098 | hdr.network = skb_network_header(skb); |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8099 | if (unlikely(hdr.network <= skb->data)) |
| 8100 | return; |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8101 | if (skb->encapsulation && |
| 8102 | first->protocol == htons(ETH_P_IP) && |
Sowmini Varadhan | 5202882 | 2016-10-24 15:36:38 -0700 | [diff] [blame] | 8103 | hdr.ipv4->protocol == IPPROTO_UDP) { |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8104 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8105 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8106 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 8107 | VXLAN_HEADROOM)) |
| 8108 | return; |
| 8109 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8110 | /* verify the port is recognized as VXLAN */ |
| 8111 | if (adapter->vxlan_port && |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8112 | udp_hdr(skb)->dest == adapter->vxlan_port) |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8113 | hdr.network = skb_inner_network_header(skb); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 8114 | |
| 8115 | if (adapter->geneve_port && |
| 8116 | udp_hdr(skb)->dest == adapter->geneve_port) |
| 8117 | hdr.network = skb_inner_network_header(skb); |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8118 | } |
| 8119 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8120 | /* Make sure we have at least [minimum IPv4 header + TCP] |
| 8121 | * or [IPv6 header] bytes |
| 8122 | */ |
| 8123 | if (unlikely(skb_tail_pointer(skb) < hdr.network + 40)) |
| 8124 | return; |
| 8125 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8126 | /* Currently only IPv4/IPv6 with TCP is supported */ |
| 8127 | switch (hdr.ipv4->version) { |
| 8128 | case IPVERSION: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8129 | /* access ihl as u8 to avoid unaligned access on ia64 */ |
| 8130 | hlen = (hdr.network[0] & 0x0F) << 2; |
| 8131 | l4_proto = hdr.ipv4->protocol; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8132 | break; |
| 8133 | case 6: |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8134 | hlen = hdr.network - skb->data; |
| 8135 | l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL); |
| 8136 | hlen -= hdr.network - skb->data; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8137 | break; |
| 8138 | default: |
| 8139 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8140 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8141 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8142 | if (l4_proto != IPPROTO_TCP) |
| 8143 | return; |
| 8144 | |
Sowmini Varadhan | 9f3c750 | 2016-10-24 15:36:39 -0700 | [diff] [blame] | 8145 | if (unlikely(skb_tail_pointer(skb) < hdr.network + |
| 8146 | hlen + sizeof(struct tcphdr))) |
| 8147 | return; |
| 8148 | |
Alexander Duyck | e2873d4 | 2016-01-25 19:39:40 -0800 | [diff] [blame] | 8149 | th = (struct tcphdr *)(hdr.network + hlen); |
| 8150 | |
| 8151 | /* skip this packet since the socket is closing */ |
| 8152 | if (th->fin) |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8153 | return; |
| 8154 | |
| 8155 | /* sample on all syn packets or once every atr sample count */ |
| 8156 | if (!th->syn && (ring->atr_count < ring->atr_sample_rate)) |
| 8157 | return; |
| 8158 | |
| 8159 | /* reset sample count */ |
| 8160 | ring->atr_count = 0; |
| 8161 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8162 | vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8163 | |
| 8164 | /* |
| 8165 | * src and dst are inverted, think how the receiver sees them |
| 8166 | * |
| 8167 | * The input is broken into two sections, a non-compressed section |
| 8168 | * containing vm_pool, vlan_id, and flow_type. The rest of the data |
| 8169 | * is XORed together and stored in the compressed dword. |
| 8170 | */ |
| 8171 | input.formatted.vlan_id = vlan_id; |
| 8172 | |
| 8173 | /* |
| 8174 | * since src port and flex bytes occupy the same word XOR them together |
| 8175 | * and write the value to source port portion of compressed dword |
| 8176 | */ |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8177 | if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN)) |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8178 | common.port.src ^= th->dest ^ htons(ETH_P_8021Q); |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8179 | else |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8180 | common.port.src ^= th->dest ^ first->protocol; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8181 | common.port.dst ^= th->source; |
| 8182 | |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8183 | switch (hdr.ipv4->version) { |
| 8184 | case IPVERSION: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8185 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4; |
| 8186 | common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8187 | break; |
| 8188 | case 6: |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8189 | input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6; |
| 8190 | common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^ |
| 8191 | hdr.ipv6->saddr.s6_addr32[1] ^ |
| 8192 | hdr.ipv6->saddr.s6_addr32[2] ^ |
| 8193 | hdr.ipv6->saddr.s6_addr32[3] ^ |
| 8194 | hdr.ipv6->daddr.s6_addr32[0] ^ |
| 8195 | hdr.ipv6->daddr.s6_addr32[1] ^ |
| 8196 | hdr.ipv6->daddr.s6_addr32[2] ^ |
| 8197 | hdr.ipv6->daddr.s6_addr32[3]; |
Mark Rustad | e19dcde | 2015-12-09 14:55:37 -0800 | [diff] [blame] | 8198 | break; |
| 8199 | default: |
| 8200 | break; |
Alexander Duyck | 6983052 | 2011-01-06 14:29:58 +0000 | [diff] [blame] | 8201 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8202 | |
Alexander Duyck | 9f12df9 | 2016-01-25 19:36:29 -0800 | [diff] [blame] | 8203 | if (hdr.network != skb_network_header(skb)) |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8204 | input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 8205 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8206 | /* 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] | 8207 | ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw, |
| 8208 | input, common, ring->queue_index); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8209 | } |
| 8210 | |
Alexander Duyck | eadec877 | 2018-07-09 12:19:48 -0400 | [diff] [blame] | 8211 | #ifdef IXGBE_FCOE |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8212 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb, |
Alexander Duyck | 4f49dec | 2018-07-09 12:19:59 -0400 | [diff] [blame] | 8213 | struct net_device *sb_dev, |
| 8214 | select_queue_fallback_t fallback) |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8215 | { |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 8216 | struct ixgbe_adapter *adapter; |
Alexander Duyck | 16be45b | 2017-11-22 10:57:23 -0800 | [diff] [blame] | 8217 | struct ixgbe_ring_feature *f; |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 8218 | int txq; |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8219 | |
Alexander Duyck | 4f49dec | 2018-07-09 12:19:59 -0400 | [diff] [blame] | 8220 | if (sb_dev) { |
Alexander Duyck | eadec877 | 2018-07-09 12:19:48 -0400 | [diff] [blame] | 8221 | u8 tc = netdev_get_prio_tc_map(dev, skb->priority); |
Alexander Duyck | 4f49dec | 2018-07-09 12:19:59 -0400 | [diff] [blame] | 8222 | struct net_device *vdev = sb_dev; |
Alexander Duyck | 16be45b | 2017-11-22 10:57:23 -0800 | [diff] [blame] | 8223 | |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 8224 | txq = vdev->tc_to_txq[tc].offset; |
| 8225 | txq += reciprocal_scale(skb_get_hash(skb), |
| 8226 | vdev->tc_to_txq[tc].count); |
| 8227 | |
| 8228 | return txq; |
Alexander Duyck | 16be45b | 2017-11-22 10:57:23 -0800 | [diff] [blame] | 8229 | } |
Jason Wang | f663dd9 | 2014-01-10 16:18:26 +0800 | [diff] [blame] | 8230 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8231 | /* |
| 8232 | * only execute the code below if protocol is FCoE |
| 8233 | * or FIP and we have FCoE enabled on the adapter |
| 8234 | */ |
| 8235 | switch (vlan_get_protocol(skb)) { |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8236 | case htons(ETH_P_FCOE): |
| 8237 | case htons(ETH_P_FIP): |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8238 | adapter = netdev_priv(dev); |
Alexander Duyck | c087663 | 2012-05-10 00:01:46 +0000 | [diff] [blame] | 8239 | |
Alexander Duyck | 8ec56fc | 2018-07-09 12:20:04 -0400 | [diff] [blame] | 8240 | if (!sb_dev && (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8241 | break; |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 8242 | /* fall through */ |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8243 | default: |
Alexander Duyck | 8ec56fc | 2018-07-09 12:20:04 -0400 | [diff] [blame] | 8244 | return fallback(dev, skb, sb_dev); |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 8245 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 8246 | |
Alexander Duyck | 97488bd | 2013-01-12 06:33:37 +0000 | [diff] [blame] | 8247 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 8248 | |
| 8249 | txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : |
| 8250 | smp_processor_id(); |
| 8251 | |
| 8252 | while (txq >= f->indices) |
| 8253 | txq -= f->indices; |
| 8254 | |
| 8255 | return txq + f->offset; |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 8256 | } |
| 8257 | |
Alexander Duyck | eadec877 | 2018-07-09 12:19:48 -0400 | [diff] [blame] | 8258 | #endif |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8259 | static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter, |
Jesper Dangaard Brouer | 44fa2db | 2018-04-17 16:46:37 +0200 | [diff] [blame] | 8260 | struct xdp_frame *xdpf) |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8261 | { |
| 8262 | struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()]; |
| 8263 | struct ixgbe_tx_buffer *tx_buffer; |
| 8264 | union ixgbe_adv_tx_desc *tx_desc; |
| 8265 | u32 len, cmd_type; |
| 8266 | dma_addr_t dma; |
| 8267 | u16 i; |
| 8268 | |
Jesper Dangaard Brouer | 0399309 | 2018-04-17 16:46:32 +0200 | [diff] [blame] | 8269 | len = xdpf->len; |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8270 | |
| 8271 | if (unlikely(!ixgbe_desc_unused(ring))) |
| 8272 | return IXGBE_XDP_CONSUMED; |
| 8273 | |
Jesper Dangaard Brouer | 0399309 | 2018-04-17 16:46:32 +0200 | [diff] [blame] | 8274 | dma = dma_map_single(ring->dev, xdpf->data, len, DMA_TO_DEVICE); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8275 | if (dma_mapping_error(ring->dev, dma)) |
| 8276 | return IXGBE_XDP_CONSUMED; |
| 8277 | |
| 8278 | /* record the location of the first descriptor for this packet */ |
| 8279 | tx_buffer = &ring->tx_buffer_info[ring->next_to_use]; |
| 8280 | tx_buffer->bytecount = len; |
| 8281 | tx_buffer->gso_segs = 1; |
| 8282 | tx_buffer->protocol = 0; |
| 8283 | |
| 8284 | i = ring->next_to_use; |
| 8285 | tx_desc = IXGBE_TX_DESC(ring, i); |
| 8286 | |
| 8287 | dma_unmap_len_set(tx_buffer, len, len); |
| 8288 | dma_unmap_addr_set(tx_buffer, dma, dma); |
Jesper Dangaard Brouer | 0399309 | 2018-04-17 16:46:32 +0200 | [diff] [blame] | 8289 | tx_buffer->xdpf = xdpf; |
Jesper Dangaard Brouer | 189ead8 | 2018-04-17 16:45:32 +0200 | [diff] [blame] | 8290 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8291 | tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 8292 | |
| 8293 | /* put descriptor type bits */ |
| 8294 | cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 8295 | IXGBE_ADVTXD_DCMD_DEXT | |
| 8296 | IXGBE_ADVTXD_DCMD_IFCS; |
| 8297 | cmd_type |= len | IXGBE_TXD_CMD; |
| 8298 | tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
| 8299 | tx_desc->read.olinfo_status = |
| 8300 | cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 8301 | |
John Fastabend | 7379f97 | 2017-03-28 09:47:03 -0700 | [diff] [blame] | 8302 | /* Avoid any potential race with xdp_xmit and cleanup */ |
| 8303 | smp_wmb(); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8304 | |
| 8305 | /* set next_to_watch value indicating a packet is present */ |
| 8306 | i++; |
| 8307 | if (i == ring->count) |
| 8308 | i = 0; |
| 8309 | |
| 8310 | tx_buffer->next_to_watch = tx_desc; |
| 8311 | ring->next_to_use = i; |
| 8312 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8313 | return IXGBE_XDP_TX; |
| 8314 | } |
| 8315 | |
Alexander Duyck | fc77dc3 | 2010-11-16 19:26:51 -0800 | [diff] [blame] | 8316 | netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb, |
Alexander Duyck | 84418e3 | 2010-08-19 13:40:54 +0000 | [diff] [blame] | 8317 | struct ixgbe_adapter *adapter, |
| 8318 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8319 | { |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8320 | struct ixgbe_tx_buffer *first; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 8321 | int tso; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8322 | u32 tx_flags = 0; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8323 | unsigned short f; |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8324 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 8325 | struct ixgbe_ipsec_tx_data ipsec_tx = { 0 }; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8326 | __be16 protocol = skb->protocol; |
Alexander Duyck | 63544e9 | 2011-05-27 05:31:42 +0000 | [diff] [blame] | 8327 | u8 hdr_len = 0; |
Hao Zheng | 5e09a10 | 2010-11-11 13:47:59 +0000 | [diff] [blame] | 8328 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8329 | /* |
| 8330 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | 24ddd96 | 2012-02-10 02:08:32 +0000 | [diff] [blame] | 8331 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8332 | * + 2 desc gap to keep tail from touching head, |
| 8333 | * + 1 desc for context descriptor, |
| 8334 | * otherwise try next time |
| 8335 | */ |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8336 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 8337 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
Alexander Duyck | 7f66162 | 2013-02-09 01:19:55 +0000 | [diff] [blame] | 8338 | |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8339 | if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) { |
| 8340 | tx_ring->tx_stats.tx_busy++; |
| 8341 | return NETDEV_TX_BUSY; |
| 8342 | } |
| 8343 | |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8344 | /* record the location of the first descriptor for this packet */ |
| 8345 | first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 8346 | first->skb = skb; |
Alexander Duyck | 091a624 | 2012-02-08 07:51:01 +0000 | [diff] [blame] | 8347 | first->bytecount = skb->len; |
| 8348 | first->gso_segs = 1; |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8349 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8350 | /* if we have a HW VLAN tag being added default to the HW one */ |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 8351 | if (skb_vlan_tag_present(skb)) { |
| 8352 | tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8353 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8354 | /* else if it is a SW VLAN check the next protocol and store the tag */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8355 | } else if (protocol == htons(ETH_P_8021Q)) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8356 | struct vlan_hdr *vhdr, _vhdr; |
| 8357 | vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr); |
| 8358 | if (!vhdr) |
| 8359 | goto out_drop; |
| 8360 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8361 | tx_flags |= ntohs(vhdr->h_vlan_TCI) << |
| 8362 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8363 | tx_flags |= IXGBE_TX_FLAGS_SW_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8364 | } |
Toshiaki Makita | 0213668 | 2015-01-29 20:37:09 +0900 | [diff] [blame] | 8365 | protocol = vlan_get_protocol(skb); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8366 | |
Mark Rustad | d523493 | 2014-08-09 07:02:09 +0000 | [diff] [blame] | 8367 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && |
Jacob Keller | 4cc74c0 | 2017-05-03 10:29:00 -0700 | [diff] [blame] | 8368 | adapter->ptp_clock) { |
| 8369 | if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS, |
| 8370 | &adapter->state)) { |
| 8371 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 8372 | tx_flags |= IXGBE_TX_FLAGS_TSTAMP; |
Jacob Keller | 891dc08 | 2012-12-05 07:24:46 +0000 | [diff] [blame] | 8373 | |
Jacob Keller | 4cc74c0 | 2017-05-03 10:29:00 -0700 | [diff] [blame] | 8374 | /* schedule check for Tx timestamp */ |
| 8375 | adapter->ptp_tx_skb = skb_get(skb); |
| 8376 | adapter->ptp_tx_start = jiffies; |
| 8377 | schedule_work(&adapter->ptp_tx_work); |
| 8378 | } else { |
| 8379 | adapter->tx_hwtstamp_skipped++; |
| 8380 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8381 | } |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8382 | |
Jakub Kicinski | ff29a86 | 2014-03-15 14:55:16 +0000 | [diff] [blame] | 8383 | skb_tx_timestamp(skb); |
| 8384 | |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8385 | #ifdef CONFIG_PCI_IOV |
| 8386 | /* |
| 8387 | * Use the l2switch_enable flag - would be false if the DMA |
| 8388 | * Tx switch had been disabled. |
| 8389 | */ |
| 8390 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
Alexander Duyck | 472148c | 2012-11-07 02:34:28 +0000 | [diff] [blame] | 8391 | tx_flags |= IXGBE_TX_FLAGS_CC; |
Alexander Duyck | 9e0c564 | 2012-02-08 07:49:33 +0000 | [diff] [blame] | 8392 | |
| 8393 | #endif |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8394 | /* 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] | 8395 | if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
Alexander Duyck | 09dca47 | 2011-07-20 00:09:10 +0000 | [diff] [blame] | 8396 | ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) || |
| 8397 | (skb->priority != TC_PRIO_CONTROL))) { |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8398 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
John Fastabend | 32701dc | 2011-09-27 03:51:56 +0000 | [diff] [blame] | 8399 | tx_flags |= (skb->priority & 0x7) << |
| 8400 | IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT; |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8401 | if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) { |
| 8402 | struct vlan_ethhdr *vhdr; |
Francois Romieu | 2049e1f | 2014-03-30 03:14:27 +0000 | [diff] [blame] | 8403 | |
| 8404 | if (skb_cow_head(skb, 0)) |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8405 | goto out_drop; |
| 8406 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 8407 | vhdr->h_vlan_TCI = htons(tx_flags >> |
| 8408 | IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 8409 | } else { |
| 8410 | tx_flags |= IXGBE_TX_FLAGS_HW_VLAN; |
| 8411 | } |
| 8412 | } |
Alexander Duyck | a535c30 | 2011-05-27 05:31:52 +0000 | [diff] [blame] | 8413 | |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8414 | /* record initial flags and protocol */ |
| 8415 | first->tx_flags = tx_flags; |
| 8416 | first->protocol = protocol; |
| 8417 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 8418 | #ifdef IXGBE_FCOE |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8419 | /* setup tx offload for FCoE */ |
Joe Perches | a1108ff | 2014-03-13 05:19:25 +0000 | [diff] [blame] | 8420 | if ((protocol == htons(ETH_P_FCOE)) && |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 8421 | (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) { |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8422 | tso = ixgbe_fso(tx_ring, first, &hdr_len); |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8423 | if (tso < 0) |
| 8424 | goto out_drop; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8425 | |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8426 | goto xmit_fcoe; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 8427 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8428 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8429 | #endif /* IXGBE_FCOE */ |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 8430 | |
| 8431 | #ifdef CONFIG_XFRM_OFFLOAD |
| 8432 | if (skb->sp && !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx)) |
| 8433 | goto out_drop; |
| 8434 | #endif |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 8435 | tso = ixgbe_tso(tx_ring, first, &hdr_len, &ipsec_tx); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8436 | if (tso < 0) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8437 | goto out_drop; |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8438 | else if (!tso) |
Shannon Nelson | 5925947 | 2017-12-19 16:00:00 -0800 | [diff] [blame] | 8439 | ixgbe_tx_csum(tx_ring, first, &ipsec_tx); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8440 | |
| 8441 | /* add the ATR filter if ATR is on */ |
| 8442 | if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state)) |
Alexander Duyck | 244e27a | 2012-02-08 07:51:11 +0000 | [diff] [blame] | 8443 | ixgbe_atr(tx_ring, first); |
Alexander Duyck | 66f32a8 | 2011-06-29 05:43:22 +0000 | [diff] [blame] | 8444 | |
| 8445 | #ifdef IXGBE_FCOE |
| 8446 | xmit_fcoe: |
| 8447 | #endif /* IXGBE_FCOE */ |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8448 | if (ixgbe_tx_map(tx_ring, first, hdr_len)) |
| 8449 | goto cleanup_tx_timestamp; |
Alexander Duyck | d3d0023 | 2011-07-15 02:31:25 +0000 | [diff] [blame] | 8450 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8451 | return NETDEV_TX_OK; |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8452 | |
| 8453 | out_drop: |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8454 | dev_kfree_skb_any(first->skb); |
| 8455 | first->skb = NULL; |
Jacob Keller | 5fef124 | 2017-05-03 10:28:56 -0700 | [diff] [blame] | 8456 | cleanup_tx_timestamp: |
| 8457 | if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) { |
| 8458 | dev_kfree_skb_any(adapter->ptp_tx_skb); |
| 8459 | adapter->ptp_tx_skb = NULL; |
| 8460 | cancel_work_sync(&adapter->ptp_tx_work); |
| 8461 | clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state); |
| 8462 | } |
Alexander Duyck | fd0db0e | 2012-02-08 07:50:56 +0000 | [diff] [blame] | 8463 | |
Alexander Duyck | 897ab15 | 2011-05-27 05:31:47 +0000 | [diff] [blame] | 8464 | return NETDEV_TX_OK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8465 | } |
| 8466 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8467 | static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb, |
| 8468 | struct net_device *netdev, |
| 8469 | struct ixgbe_ring *ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8470 | { |
| 8471 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8472 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8473 | |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8474 | /* |
| 8475 | * The minimum packet size for olinfo paylen is 17 so pad the skb |
| 8476 | * in order to meet this minimum size requirement. |
| 8477 | */ |
Alexander Duyck | a94d9e2 | 2014-12-03 08:17:39 -0800 | [diff] [blame] | 8478 | if (skb_put_padto(skb, 17)) |
| 8479 | return NETDEV_TX_OK; |
Alexander Duyck | a50c29d | 2012-02-08 07:50:40 +0000 | [diff] [blame] | 8480 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8481 | tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping]; |
| 8482 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8483 | return ixgbe_xmit_frame_ring(skb, adapter, tx_ring); |
| 8484 | } |
| 8485 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 8486 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 8487 | struct net_device *netdev) |
| 8488 | { |
| 8489 | return __ixgbe_xmit_frame(skb, netdev, NULL); |
| 8490 | } |
| 8491 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8492 | /** |
| 8493 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 8494 | * @netdev: network interface device structure |
| 8495 | * @p: pointer to an address structure |
| 8496 | * |
| 8497 | * Returns 0 on success, negative on failure |
| 8498 | **/ |
| 8499 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 8500 | { |
| 8501 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8502 | struct ixgbe_hw *hw = &adapter->hw; |
| 8503 | struct sockaddr *addr = p; |
| 8504 | |
| 8505 | if (!is_valid_ether_addr(addr->sa_data)) |
| 8506 | return -EADDRNOTAVAIL; |
| 8507 | |
| 8508 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 8509 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8510 | |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 8511 | ixgbe_mac_set_default_filter(adapter); |
| 8512 | |
| 8513 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8514 | } |
| 8515 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8516 | static int |
| 8517 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 8518 | { |
| 8519 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8520 | struct ixgbe_hw *hw = &adapter->hw; |
| 8521 | u16 value; |
| 8522 | int rc; |
| 8523 | |
| 8524 | if (prtad != hw->phy.mdio.prtad) |
| 8525 | return -EINVAL; |
| 8526 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 8527 | if (!rc) |
| 8528 | rc = value; |
| 8529 | return rc; |
| 8530 | } |
| 8531 | |
| 8532 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 8533 | u16 addr, u16 value) |
| 8534 | { |
| 8535 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8536 | struct ixgbe_hw *hw = &adapter->hw; |
| 8537 | |
| 8538 | if (prtad != hw->phy.mdio.prtad) |
| 8539 | return -EINVAL; |
| 8540 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 8541 | } |
| 8542 | |
| 8543 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 8544 | { |
| 8545 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8546 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8547 | switch (cmd) { |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8548 | case SIOCSHWTSTAMP: |
Jacob Keller | 93501d4 | 2014-02-28 15:48:58 -0800 | [diff] [blame] | 8549 | return ixgbe_ptp_set_ts_config(adapter, req); |
| 8550 | case SIOCGHWTSTAMP: |
| 8551 | return ixgbe_ptp_get_ts_config(adapter, req); |
Mark D Rustad | e0f06bb | 2016-08-31 10:34:28 -0700 | [diff] [blame] | 8552 | case SIOCGMIIPHY: |
| 8553 | if (!adapter->hw.phy.ops.read_reg) |
| 8554 | return -EOPNOTSUPP; |
| 8555 | /* fall through */ |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 8556 | default: |
| 8557 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 8558 | } |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 8559 | } |
| 8560 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8561 | /** |
| 8562 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8563 | * netdev->dev_addrs |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 8564 | * @dev: network interface device structure |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8565 | * |
| 8566 | * Returns non-zero on failure |
| 8567 | **/ |
| 8568 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 8569 | { |
| 8570 | int err = 0; |
| 8571 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8572 | struct ixgbe_hw *hw = &adapter->hw; |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8573 | |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8574 | if (is_valid_ether_addr(hw->mac.san_addr)) { |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8575 | rtnl_lock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8576 | 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] | 8577 | rtnl_unlock(); |
Alexander Duyck | 7fa7c9d | 2012-05-05 05:32:52 +0000 | [diff] [blame] | 8578 | |
| 8579 | /* update SAN MAC vmdq pool selection */ |
| 8580 | hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0)); |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8581 | } |
| 8582 | return err; |
| 8583 | } |
| 8584 | |
| 8585 | /** |
| 8586 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 8587 | * netdev->dev_addrs |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 8588 | * @dev: network interface device structure |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 8589 | * |
| 8590 | * Returns non-zero on failure |
| 8591 | **/ |
| 8592 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 8593 | { |
| 8594 | int err = 0; |
| 8595 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8596 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 8597 | |
| 8598 | if (is_valid_ether_addr(mac->san_addr)) { |
| 8599 | rtnl_lock(); |
| 8600 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 8601 | rtnl_unlock(); |
| 8602 | } |
| 8603 | return err; |
| 8604 | } |
| 8605 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8606 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8607 | /* |
| 8608 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 8609 | * without having to re-enable interrupts. It's not called while |
| 8610 | * the interrupt routine is executing. |
| 8611 | */ |
| 8612 | static void ixgbe_netpoll(struct net_device *netdev) |
| 8613 | { |
| 8614 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 8615 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8616 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 8617 | /* if interface is down do nothing */ |
| 8618 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 8619 | return; |
| 8620 | |
Alexander Duyck | 856f606 | 2015-02-25 17:45:54 +0000 | [diff] [blame] | 8621 | /* loop through and schedule all active queues */ |
| 8622 | for (i = 0; i < adapter->num_q_vectors; i++) |
| 8623 | ixgbe_msix_clean_rings(0, adapter->q_vector[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8624 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 8625 | |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 8626 | #endif |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8627 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8628 | static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats, |
| 8629 | struct ixgbe_ring *ring) |
| 8630 | { |
| 8631 | u64 bytes, packets; |
| 8632 | unsigned int start; |
| 8633 | |
| 8634 | if (ring) { |
| 8635 | do { |
| 8636 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
| 8637 | packets = ring->stats.packets; |
| 8638 | bytes = ring->stats.bytes; |
| 8639 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
| 8640 | stats->tx_packets += packets; |
| 8641 | stats->tx_bytes += bytes; |
| 8642 | } |
| 8643 | } |
| 8644 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8645 | static void ixgbe_get_stats64(struct net_device *netdev, |
| 8646 | struct rtnl_link_stats64 *stats) |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8647 | { |
| 8648 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 8649 | int i; |
| 8650 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8651 | rcu_read_lock(); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8652 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 8653 | struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]); |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8654 | u64 bytes, packets; |
| 8655 | unsigned int start; |
| 8656 | |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8657 | if (ring) { |
| 8658 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8659 | start = u64_stats_fetch_begin_irq(&ring->syncp); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8660 | packets = ring->stats.packets; |
| 8661 | bytes = ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 8662 | } while (u64_stats_fetch_retry_irq(&ring->syncp, start)); |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8663 | stats->rx_packets += packets; |
| 8664 | stats->rx_bytes += bytes; |
| 8665 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8666 | } |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8667 | |
| 8668 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 8669 | struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8670 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8671 | ixgbe_get_ring_stats64(stats, ring); |
| 8672 | } |
| 8673 | for (i = 0; i < adapter->num_xdp_queues; i++) { |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 8674 | struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 8675 | |
| 8676 | ixgbe_get_ring_stats64(stats, ring); |
Eric Dumazet | 1ac9ad1 | 2011-01-12 12:13:14 +0000 | [diff] [blame] | 8677 | } |
Eric Dumazet | 1a51502 | 2010-11-16 19:26:42 -0800 | [diff] [blame] | 8678 | rcu_read_unlock(); |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8679 | |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8680 | /* following stats updated by ixgbe_watchdog_task() */ |
| 8681 | stats->multicast = netdev->stats.multicast; |
| 8682 | stats->rx_errors = netdev->stats.rx_errors; |
| 8683 | stats->rx_length_errors = netdev->stats.rx_length_errors; |
| 8684 | stats->rx_crc_errors = netdev->stats.rx_crc_errors; |
| 8685 | stats->rx_missed_errors = netdev->stats.rx_missed_errors; |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8686 | } |
| 8687 | |
Jeff Kirsher | 8af3c33 | 2012-02-18 07:08:14 +0000 | [diff] [blame] | 8688 | #ifdef CONFIG_IXGBE_DCB |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8689 | /** |
| 8690 | * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid. |
| 8691 | * @adapter: pointer to ixgbe_adapter |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8692 | * @tc: number of traffic classes currently enabled |
| 8693 | * |
| 8694 | * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm |
| 8695 | * 802.1Q priority maps to a packet buffer that exists. |
| 8696 | */ |
| 8697 | static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc) |
| 8698 | { |
| 8699 | struct ixgbe_hw *hw = &adapter->hw; |
| 8700 | u32 reg, rsave; |
| 8701 | int i; |
| 8702 | |
| 8703 | /* 82598 have a static priority to TC mapping that can not |
| 8704 | * be changed so no validation is needed. |
| 8705 | */ |
| 8706 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 8707 | return; |
| 8708 | |
| 8709 | reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC); |
| 8710 | rsave = reg; |
| 8711 | |
| 8712 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) { |
| 8713 | u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT); |
| 8714 | |
| 8715 | /* If up2tc is out of bounds default to zero */ |
| 8716 | if (up2tc > tc) |
| 8717 | reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT); |
| 8718 | } |
| 8719 | |
| 8720 | if (reg != rsave) |
| 8721 | IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg); |
| 8722 | |
| 8723 | return; |
| 8724 | } |
| 8725 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8726 | /** |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8727 | * ixgbe_set_prio_tc_map - Configure netdev prio tc map |
| 8728 | * @adapter: Pointer to adapter struct |
| 8729 | * |
| 8730 | * Populate the netdev user priority to tc map |
| 8731 | */ |
| 8732 | static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter) |
| 8733 | { |
| 8734 | struct net_device *dev = adapter->netdev; |
| 8735 | struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg; |
| 8736 | struct ieee_ets *ets = adapter->ixgbe_ieee_ets; |
| 8737 | u8 prio; |
| 8738 | |
| 8739 | for (prio = 0; prio < MAX_USER_PRIORITY; prio++) { |
| 8740 | u8 tc = 0; |
| 8741 | |
| 8742 | if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) |
| 8743 | tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio); |
| 8744 | else if (ets) |
| 8745 | tc = ets->prio_tc[prio]; |
| 8746 | |
| 8747 | netdev_set_prio_tc_map(dev, prio, tc); |
| 8748 | } |
| 8749 | } |
| 8750 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8751 | #endif /* CONFIG_IXGBE_DCB */ |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 8752 | static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data) |
| 8753 | { |
| 8754 | struct ixgbe_adapter *adapter = data; |
| 8755 | struct ixgbe_fwd_adapter *accel; |
| 8756 | int pool; |
| 8757 | |
| 8758 | /* we only care about macvlans... */ |
| 8759 | if (!netif_is_macvlan(vdev)) |
| 8760 | return 0; |
| 8761 | |
| 8762 | /* that have hardware offload enabled... */ |
| 8763 | accel = macvlan_accel_priv(vdev); |
| 8764 | if (!accel) |
| 8765 | return 0; |
| 8766 | |
| 8767 | /* If we can relocate to a different bit do so */ |
| 8768 | pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools); |
| 8769 | if (pool < adapter->num_rx_pools) { |
| 8770 | set_bit(pool, adapter->fwd_bitmask); |
| 8771 | accel->pool = pool; |
| 8772 | return 0; |
| 8773 | } |
| 8774 | |
| 8775 | /* if we cannot find a free pool then disable the offload */ |
| 8776 | netdev_err(vdev, "L2FW offload disabled due to lack of queue resources\n"); |
| 8777 | macvlan_release_l2fw_offload(vdev); |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 8778 | |
| 8779 | /* unbind the queues and drop the subordinate channel config */ |
| 8780 | netdev_unbind_sb_channel(adapter->netdev, vdev); |
| 8781 | netdev_set_sb_channel(vdev, 0); |
| 8782 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 8783 | kfree(accel); |
| 8784 | |
| 8785 | return 0; |
| 8786 | } |
| 8787 | |
| 8788 | static void ixgbe_defrag_macvlan_pools(struct net_device *dev) |
| 8789 | { |
| 8790 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8791 | |
| 8792 | /* flush any stale bits out of the fwd bitmask */ |
| 8793 | bitmap_clear(adapter->fwd_bitmask, 1, 63); |
| 8794 | |
| 8795 | /* walk through upper devices reassigning pools */ |
| 8796 | netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool, |
| 8797 | adapter); |
| 8798 | } |
| 8799 | |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8800 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 8801 | * ixgbe_setup_tc - configure net_device for multiple traffic classes |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8802 | * |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 8803 | * @dev: net device to configure |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8804 | * @tc: number of traffic classes to enable |
| 8805 | */ |
| 8806 | int ixgbe_setup_tc(struct net_device *dev, u8 tc) |
| 8807 | { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8808 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 8809 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8810 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8811 | /* Hardware supports up to 8 traffic classes */ |
Emil Tantilov | 7e3f5c8 | 2015-07-09 12:28:59 -0700 | [diff] [blame] | 8812 | if (tc > adapter->dcb_cfg.num_tcs.pg_tcs) |
| 8813 | return -EINVAL; |
| 8814 | |
| 8815 | if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS) |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8816 | return -EINVAL; |
| 8817 | |
| 8818 | /* Hardware has to reinitialize queues and interrupts to |
Stephen Hemminger | 52f33af | 2011-12-22 16:34:52 +0000 | [diff] [blame] | 8819 | * match packet buffer alignment. Unfortunately, the |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8820 | * hardware is not flexible enough to do this dynamically. |
| 8821 | */ |
| 8822 | if (netif_running(dev)) |
| 8823 | ixgbe_close(dev); |
Alexander Duyck | bf4d67d | 2015-10-20 13:28:17 -0700 | [diff] [blame] | 8824 | else |
| 8825 | ixgbe_reset(adapter); |
| 8826 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8827 | ixgbe_clear_interrupt_scheme(adapter); |
| 8828 | |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8829 | #ifdef CONFIG_IXGBE_DCB |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8830 | if (tc) { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8831 | netdev_set_num_tc(dev, tc); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8832 | ixgbe_set_prio_tc_map(adapter); |
| 8833 | |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 8834 | adapter->hw_tcs = tc; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8835 | adapter->flags |= IXGBE_FLAG_DCB_ENABLED; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8836 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8837 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 8838 | adapter->last_lfc_mode = adapter->hw.fc.requested_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8839 | adapter->hw.fc.requested_mode = ixgbe_fc_none; |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8840 | } |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8841 | } else { |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8842 | netdev_reset_tc(dev); |
Alexander Duyck | 02debdc | 2012-05-18 06:33:31 +0000 | [diff] [blame] | 8843 | |
Alexander Duyck | 943561d | 2012-05-09 22:14:44 -0700 | [diff] [blame] | 8844 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 8845 | adapter->hw.fc.requested_mode = adapter->last_lfc_mode; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8846 | |
| 8847 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 8848 | adapter->hw_tcs = tc; |
John Fastabend | e7589ea | 2011-07-18 22:38:36 +0000 | [diff] [blame] | 8849 | |
| 8850 | adapter->temp_dcb_cfg.pfc_mode_enable = false; |
| 8851 | adapter->dcb_cfg.pfc_mode_enable = false; |
| 8852 | } |
| 8853 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8854 | ixgbe_validate_rtr(adapter, tc); |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8855 | |
| 8856 | #endif /* CONFIG_IXGBE_DCB */ |
| 8857 | ixgbe_init_interrupt_scheme(adapter); |
| 8858 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 8859 | ixgbe_defrag_macvlan_pools(dev); |
| 8860 | |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8861 | if (netif_running(dev)) |
Alexander Duyck | cca73c5 | 2013-01-12 06:33:44 +0000 | [diff] [blame] | 8862 | return ixgbe_open(dev); |
John Fastabend | 8b1c0b2 | 2011-05-03 02:26:48 +0000 | [diff] [blame] | 8863 | |
| 8864 | return 0; |
| 8865 | } |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 8866 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8867 | static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter, |
| 8868 | struct tc_cls_u32_offload *cls) |
| 8869 | { |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8870 | u32 hdl = cls->knode.handle; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8871 | u32 uhtid = TC_U32_USERHTID(cls->knode.handle); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8872 | u32 loc = cls->knode.handle & 0xfffff; |
| 8873 | int err = 0, i, j; |
| 8874 | struct ixgbe_jump_table *jump = NULL; |
| 8875 | |
| 8876 | if (loc > IXGBE_MAX_HW_ENTRIES) |
| 8877 | return -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8878 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8879 | if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE)) |
| 8880 | return -EINVAL; |
| 8881 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8882 | /* Clear this filter in the link data it is associated with */ |
| 8883 | if (uhtid != 0x800) { |
| 8884 | jump = adapter->jump_tables[uhtid]; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 8885 | if (!jump) |
| 8886 | return -EINVAL; |
| 8887 | if (!test_bit(loc - 1, jump->child_loc_map)) |
| 8888 | return -EINVAL; |
| 8889 | clear_bit(loc - 1, jump->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 8890 | } |
| 8891 | |
| 8892 | /* Check if the filter being deleted is a link */ |
| 8893 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 8894 | jump = adapter->jump_tables[i]; |
| 8895 | if (jump && jump->link_hdl == hdl) { |
| 8896 | /* Delete filters in the hardware in the child hash |
| 8897 | * table associated with this link |
| 8898 | */ |
| 8899 | for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) { |
| 8900 | if (!test_bit(j, jump->child_loc_map)) |
| 8901 | continue; |
| 8902 | spin_lock(&adapter->fdir_perfect_lock); |
| 8903 | err = ixgbe_update_ethtool_fdir_entry(adapter, |
| 8904 | NULL, |
| 8905 | j + 1); |
| 8906 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8907 | clear_bit(j, jump->child_loc_map); |
| 8908 | } |
| 8909 | /* Remove resources for this link */ |
| 8910 | kfree(jump->input); |
| 8911 | kfree(jump->mask); |
| 8912 | kfree(jump); |
| 8913 | adapter->jump_tables[i] = NULL; |
| 8914 | return err; |
| 8915 | } |
| 8916 | } |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8917 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8918 | spin_lock(&adapter->fdir_perfect_lock); |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8919 | err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 8920 | spin_unlock(&adapter->fdir_perfect_lock); |
| 8921 | return err; |
| 8922 | } |
| 8923 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8924 | static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter, |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8925 | struct tc_cls_u32_offload *cls) |
| 8926 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8927 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8928 | |
| 8929 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8930 | return -EINVAL; |
| 8931 | |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8932 | /* This ixgbe devices do not support hash tables at the moment |
| 8933 | * so abort when given hash tables. |
| 8934 | */ |
| 8935 | if (cls->hnode.divisor > 0) |
| 8936 | return -EINVAL; |
| 8937 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8938 | set_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8939 | return 0; |
| 8940 | } |
| 8941 | |
| 8942 | static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter, |
| 8943 | struct tc_cls_u32_offload *cls) |
| 8944 | { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 8945 | u32 uhtid = TC_U32_USERHTID(cls->hnode.handle); |
| 8946 | |
| 8947 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 8948 | return -EINVAL; |
| 8949 | |
| 8950 | clear_bit(uhtid - 1, &adapter->tables); |
John Fastabend | db956ae | 2016-02-16 21:19:19 -0800 | [diff] [blame] | 8951 | return 0; |
| 8952 | } |
| 8953 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8954 | #ifdef CONFIG_NET_CLS_ACT |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8955 | struct upper_walk_data { |
| 8956 | struct ixgbe_adapter *adapter; |
| 8957 | u64 action; |
| 8958 | int ifindex; |
| 8959 | u8 queue; |
| 8960 | }; |
| 8961 | |
| 8962 | static int get_macvlan_queue(struct net_device *upper, void *_data) |
| 8963 | { |
| 8964 | if (netif_is_macvlan(upper)) { |
Alexander Duyck | 7d775f6 | 2018-04-03 17:16:03 -0400 | [diff] [blame] | 8965 | struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper); |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8966 | struct upper_walk_data *data = _data; |
| 8967 | struct ixgbe_adapter *adapter = data->adapter; |
| 8968 | int ifindex = data->ifindex; |
| 8969 | |
Alexander Duyck | 7d775f6 | 2018-04-03 17:16:03 -0400 | [diff] [blame] | 8970 | if (vadapter && upper->ifindex == ifindex) { |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8971 | data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx; |
| 8972 | data->action = data->queue; |
| 8973 | return 1; |
| 8974 | } |
| 8975 | } |
| 8976 | |
| 8977 | return 0; |
| 8978 | } |
| 8979 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8980 | static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex, |
| 8981 | u8 *queue, u64 *action) |
| 8982 | { |
Alexander Duyck | 361b534 | 2017-11-22 10:56:16 -0800 | [diff] [blame] | 8983 | struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ]; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8984 | unsigned int num_vfs = adapter->num_vfs, vf; |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 8985 | struct upper_walk_data data; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8986 | struct net_device *upper; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8987 | |
| 8988 | /* redirect to a SRIOV VF */ |
| 8989 | for (vf = 0; vf < num_vfs; ++vf) { |
| 8990 | upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev); |
| 8991 | if (upper->ifindex == ifindex) { |
Alexander Duyck | 361b534 | 2017-11-22 10:56:16 -0800 | [diff] [blame] | 8992 | *queue = vf * __ALIGN_MASK(1, ~vmdq->mask); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 8993 | *action = vf + 1; |
| 8994 | *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF; |
| 8995 | return 0; |
| 8996 | } |
| 8997 | } |
| 8998 | |
| 8999 | /* redirect to a offloaded macvlan netdev */ |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 9000 | data.adapter = adapter; |
| 9001 | data.ifindex = ifindex; |
| 9002 | data.action = 0; |
| 9003 | data.queue = 0; |
| 9004 | if (netdev_walk_all_upper_dev_rcu(adapter->netdev, |
| 9005 | get_macvlan_queue, &data)) { |
| 9006 | *action = data.action; |
| 9007 | *queue = data.queue; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9008 | |
David Ahern | 1cd127f | 2016-10-17 19:15:48 -0700 | [diff] [blame] | 9009 | return 0; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9010 | } |
| 9011 | |
| 9012 | return -EINVAL; |
| 9013 | } |
| 9014 | |
| 9015 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 9016 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 9017 | { |
| 9018 | const struct tc_action *a; |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 9019 | LIST_HEAD(actions); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9020 | |
Jiri Pirko | 3bcc0ce | 2017-08-04 14:28:58 +0200 | [diff] [blame] | 9021 | if (!tcf_exts_has_actions(exts)) |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9022 | return -EINVAL; |
| 9023 | |
WANG Cong | 22dc13c | 2016-08-13 22:35:00 -0700 | [diff] [blame] | 9024 | tcf_exts_to_list(exts, &actions); |
| 9025 | list_for_each_entry(a, &actions, list) { |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9026 | |
| 9027 | /* Drop action */ |
| 9028 | if (is_tcf_gact_shot(a)) { |
| 9029 | *action = IXGBE_FDIR_DROP_QUEUE; |
| 9030 | *queue = IXGBE_FDIR_DROP_QUEUE; |
| 9031 | return 0; |
| 9032 | } |
| 9033 | |
| 9034 | /* Redirect to a VF or a offloaded macvlan */ |
Shmulik Ladkani | 5724b8b | 2016-10-13 09:06:43 +0300 | [diff] [blame] | 9035 | if (is_tcf_mirred_egress_redirect(a)) { |
Cong Wang | 9f8a739 | 2017-12-05 16:17:26 -0800 | [diff] [blame] | 9036 | struct net_device *dev = tcf_mirred_dev(a); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9037 | |
Cong Wang | 9f8a739 | 2017-12-05 16:17:26 -0800 | [diff] [blame] | 9038 | if (!dev) |
| 9039 | return -EINVAL; |
Ondřej Hlavatý | 16e6653 | 2018-05-31 23:21:04 +0200 | [diff] [blame] | 9040 | return handle_redirect_action(adapter, dev->ifindex, |
| 9041 | queue, action); |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9042 | } |
Ondřej Hlavatý | 16e6653 | 2018-05-31 23:21:04 +0200 | [diff] [blame] | 9043 | |
| 9044 | return -EINVAL; |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9045 | } |
| 9046 | |
| 9047 | return -EINVAL; |
| 9048 | } |
| 9049 | #else |
| 9050 | static int parse_tc_actions(struct ixgbe_adapter *adapter, |
| 9051 | struct tcf_exts *exts, u64 *action, u8 *queue) |
| 9052 | { |
| 9053 | return -EINVAL; |
| 9054 | } |
| 9055 | #endif /* CONFIG_NET_CLS_ACT */ |
| 9056 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9057 | static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input, |
| 9058 | union ixgbe_atr_input *mask, |
| 9059 | struct tc_cls_u32_offload *cls, |
| 9060 | struct ixgbe_mat_field *field_ptr, |
| 9061 | struct ixgbe_nexthdr *nexthdr) |
| 9062 | { |
| 9063 | int i, j, off; |
| 9064 | __be32 val, m; |
| 9065 | bool found_entry = false, found_jump_field = false; |
| 9066 | |
| 9067 | for (i = 0; i < cls->knode.sel->nkeys; i++) { |
| 9068 | off = cls->knode.sel->keys[i].off; |
| 9069 | val = cls->knode.sel->keys[i].val; |
| 9070 | m = cls->knode.sel->keys[i].mask; |
| 9071 | |
| 9072 | for (j = 0; field_ptr[j].val; j++) { |
| 9073 | if (field_ptr[j].off == off) { |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 9074 | field_ptr[j].val(input, mask, (__force u32)val, |
| 9075 | (__force u32)m); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9076 | input->filter.formatted.flow_type |= |
| 9077 | field_ptr[j].type; |
| 9078 | found_entry = true; |
| 9079 | break; |
| 9080 | } |
| 9081 | } |
| 9082 | if (nexthdr) { |
| 9083 | if (nexthdr->off == cls->knode.sel->keys[i].off && |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 9084 | nexthdr->val == |
| 9085 | (__force u32)cls->knode.sel->keys[i].val && |
| 9086 | nexthdr->mask == |
| 9087 | (__force u32)cls->knode.sel->keys[i].mask) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9088 | found_jump_field = true; |
| 9089 | else |
| 9090 | continue; |
| 9091 | } |
| 9092 | } |
| 9093 | |
| 9094 | if (nexthdr && !found_jump_field) |
| 9095 | return -EINVAL; |
| 9096 | |
| 9097 | if (!found_entry) |
| 9098 | return 0; |
| 9099 | |
| 9100 | mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK | |
| 9101 | IXGBE_ATR_L4TYPE_MASK; |
| 9102 | |
| 9103 | if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4) |
| 9104 | mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK; |
| 9105 | |
| 9106 | return 0; |
| 9107 | } |
| 9108 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9109 | static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter, |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9110 | struct tc_cls_u32_offload *cls) |
| 9111 | { |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 9112 | __be16 protocol = cls->common.protocol; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9113 | u32 loc = cls->knode.handle & 0xfffff; |
| 9114 | struct ixgbe_hw *hw = &adapter->hw; |
| 9115 | struct ixgbe_mat_field *field_ptr; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9116 | struct ixgbe_fdir_filter *input = NULL; |
| 9117 | union ixgbe_atr_input *mask = NULL; |
| 9118 | struct ixgbe_jump_table *jump = NULL; |
| 9119 | int i, err = -EINVAL; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9120 | u8 queue; |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9121 | u32 uhtid, link_uhtid; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9122 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9123 | uhtid = TC_U32_USERHTID(cls->knode.handle); |
| 9124 | link_uhtid = TC_U32_USERHTID(cls->knode.link_handle); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9125 | |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9126 | /* At the moment cls_u32 jumps to network layer and skips past |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9127 | * L2 headers. The canonical method to match L2 frames is to use |
| 9128 | * negative values. However this is error prone at best but really |
| 9129 | * just broken because there is no way to "know" what sort of hdr |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9130 | * is in front of the network layer. Fix cls_u32 to support L2 |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9131 | * headers when needed. |
| 9132 | */ |
| 9133 | if (protocol != htons(ETH_P_IP)) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9134 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9135 | |
| 9136 | if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) { |
| 9137 | e_err(drv, "Location out of range\n"); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9138 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9139 | } |
| 9140 | |
| 9141 | /* cls u32 is a graph starting at root node 0x800. The driver tracks |
| 9142 | * links and also the fields used to advance the parser across each |
| 9143 | * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map |
| 9144 | * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h |
| 9145 | * To add support for new nodes update ixgbe_model.h parse structures |
| 9146 | * this function _should_ be generic try not to hardcode values here. |
| 9147 | */ |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9148 | if (uhtid == 0x800) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9149 | field_ptr = (adapter->jump_tables[0])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9150 | } else { |
Sridhar Samudrala | 176621c | 2016-03-07 09:41:47 -0800 | [diff] [blame] | 9151 | if (uhtid >= IXGBE_MAX_LINK_HANDLE) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9152 | return err; |
| 9153 | if (!adapter->jump_tables[uhtid]) |
| 9154 | return err; |
| 9155 | field_ptr = (adapter->jump_tables[uhtid])->mat; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9156 | } |
| 9157 | |
| 9158 | if (!field_ptr) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9159 | return err; |
| 9160 | |
| 9161 | /* At this point we know the field_ptr is valid and need to either |
| 9162 | * build cls_u32 link or attach filter. Because adding a link to |
| 9163 | * a handle that does not exist is invalid and the same for adding |
| 9164 | * rules to handles that don't exist. |
| 9165 | */ |
| 9166 | |
| 9167 | if (link_uhtid) { |
| 9168 | struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps; |
| 9169 | |
| 9170 | if (link_uhtid >= IXGBE_MAX_LINK_HANDLE) |
| 9171 | return err; |
| 9172 | |
| 9173 | if (!test_bit(link_uhtid - 1, &adapter->tables)) |
| 9174 | return err; |
| 9175 | |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9176 | /* Multiple filters as links to the same hash table are not |
| 9177 | * supported. To add a new filter with the same next header |
| 9178 | * but different match/jump conditions, create a new hash table |
| 9179 | * and link to it. |
| 9180 | */ |
| 9181 | if (adapter->jump_tables[link_uhtid] && |
| 9182 | (adapter->jump_tables[link_uhtid])->link_hdl) { |
| 9183 | e_err(drv, "Link filter exists for link: %x\n", |
| 9184 | link_uhtid); |
| 9185 | return err; |
| 9186 | } |
| 9187 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9188 | for (i = 0; nexthdr[i].jump; i++) { |
| 9189 | if (nexthdr[i].o != cls->knode.sel->offoff || |
| 9190 | nexthdr[i].s != cls->knode.sel->offshift || |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 9191 | nexthdr[i].m != |
| 9192 | (__force u32)cls->knode.sel->offmask) |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9193 | return err; |
| 9194 | |
| 9195 | jump = kzalloc(sizeof(*jump), GFP_KERNEL); |
| 9196 | if (!jump) |
| 9197 | return -ENOMEM; |
| 9198 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 9199 | if (!input) { |
| 9200 | err = -ENOMEM; |
| 9201 | goto free_jump; |
| 9202 | } |
| 9203 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 9204 | if (!mask) { |
| 9205 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9206 | goto free_input; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9207 | } |
| 9208 | jump->input = input; |
| 9209 | jump->mask = mask; |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9210 | jump->link_hdl = cls->knode.handle; |
| 9211 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9212 | err = ixgbe_clsu32_build_input(input, mask, cls, |
| 9213 | field_ptr, &nexthdr[i]); |
| 9214 | if (!err) { |
| 9215 | jump->mat = nexthdr[i].jump; |
| 9216 | adapter->jump_tables[link_uhtid] = jump; |
| 9217 | break; |
| 9218 | } |
| 9219 | } |
| 9220 | return 0; |
| 9221 | } |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9222 | |
| 9223 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 9224 | if (!input) |
| 9225 | return -ENOMEM; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9226 | mask = kzalloc(sizeof(*mask), GFP_KERNEL); |
| 9227 | if (!mask) { |
| 9228 | err = -ENOMEM; |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9229 | goto free_input; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9230 | } |
| 9231 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9232 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) { |
| 9233 | if ((adapter->jump_tables[uhtid])->input) |
| 9234 | memcpy(input, (adapter->jump_tables[uhtid])->input, |
| 9235 | sizeof(*input)); |
| 9236 | if ((adapter->jump_tables[uhtid])->mask) |
| 9237 | memcpy(mask, (adapter->jump_tables[uhtid])->mask, |
| 9238 | sizeof(*mask)); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9239 | |
| 9240 | /* Lookup in all child hash tables if this location is already |
| 9241 | * filled with a filter |
| 9242 | */ |
| 9243 | for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 9244 | struct ixgbe_jump_table *link = adapter->jump_tables[i]; |
| 9245 | |
| 9246 | if (link && (test_bit(loc - 1, link->child_loc_map))) { |
| 9247 | e_err(drv, "Filter exists in location: %x\n", |
| 9248 | loc); |
| 9249 | err = -EINVAL; |
| 9250 | goto err_out; |
| 9251 | } |
| 9252 | } |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9253 | } |
| 9254 | err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL); |
| 9255 | if (err) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9256 | goto err_out; |
| 9257 | |
Sridhar Samudrala | 947f8a4 | 2016-04-05 10:39:07 -0700 | [diff] [blame] | 9258 | err = parse_tc_actions(adapter, cls->knode.exts, &input->action, |
| 9259 | &queue); |
| 9260 | if (err < 0) |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9261 | goto err_out; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9262 | |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9263 | input->sw_idx = loc; |
| 9264 | |
| 9265 | spin_lock(&adapter->fdir_perfect_lock); |
| 9266 | |
| 9267 | if (hlist_empty(&adapter->fdir_filter_list)) { |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9268 | memcpy(&adapter->fdir_mask, mask, sizeof(*mask)); |
| 9269 | err = ixgbe_fdir_set_input_mask_82599(hw, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9270 | if (err) |
| 9271 | goto err_out_w_lock; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9272 | } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) { |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9273 | err = -EINVAL; |
| 9274 | goto err_out_w_lock; |
| 9275 | } |
| 9276 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9277 | ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9278 | err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter, |
| 9279 | input->sw_idx, queue); |
| 9280 | if (!err) |
| 9281 | ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx); |
| 9282 | spin_unlock(&adapter->fdir_perfect_lock); |
| 9283 | |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9284 | if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) |
| 9285 | set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map); |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9286 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9287 | kfree(mask); |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9288 | return err; |
| 9289 | err_out_w_lock: |
| 9290 | spin_unlock(&adapter->fdir_perfect_lock); |
| 9291 | err_out: |
Amritha Nambiar | 1ecedc9 | 2016-05-06 19:09:51 -0700 | [diff] [blame] | 9292 | kfree(mask); |
Amritha Nambiar | 12746fd | 2016-05-16 18:33:20 -0700 | [diff] [blame] | 9293 | free_input: |
| 9294 | kfree(input); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 9295 | free_jump: |
| 9296 | kfree(jump); |
| 9297 | return err; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9298 | } |
| 9299 | |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9300 | static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter, |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9301 | struct tc_cls_u32_offload *cls_u32) |
| 9302 | { |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9303 | switch (cls_u32->command) { |
| 9304 | case TC_CLSU32_NEW_KNODE: |
| 9305 | case TC_CLSU32_REPLACE_KNODE: |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 9306 | return ixgbe_configure_clsu32(adapter, cls_u32); |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9307 | case TC_CLSU32_DELETE_KNODE: |
| 9308 | return ixgbe_delete_clsu32(adapter, cls_u32); |
| 9309 | case TC_CLSU32_NEW_HNODE: |
| 9310 | case TC_CLSU32_REPLACE_HNODE: |
Jiri Pirko | 5fd9fc4 | 2017-08-07 10:15:29 +0200 | [diff] [blame] | 9311 | return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32); |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9312 | case TC_CLSU32_DELETE_HNODE: |
| 9313 | return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32); |
| 9314 | default: |
| 9315 | return -EOPNOTSUPP; |
| 9316 | } |
| 9317 | } |
| 9318 | |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9319 | static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data, |
| 9320 | void *cb_priv) |
| 9321 | { |
| 9322 | struct ixgbe_adapter *adapter = cb_priv; |
| 9323 | |
Jakub Kicinski | a60c3fd | 2018-01-25 14:00:49 -0800 | [diff] [blame] | 9324 | if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data)) |
Jiri Pirko | 44ae12a | 2017-11-01 11:47:39 +0100 | [diff] [blame] | 9325 | return -EOPNOTSUPP; |
| 9326 | |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9327 | switch (type) { |
| 9328 | case TC_SETUP_CLSU32: |
| 9329 | return ixgbe_setup_tc_cls_u32(adapter, type_data); |
| 9330 | default: |
| 9331 | return -EOPNOTSUPP; |
| 9332 | } |
| 9333 | } |
| 9334 | |
| 9335 | static int ixgbe_setup_tc_block(struct net_device *dev, |
| 9336 | struct tc_block_offload *f) |
| 9337 | { |
| 9338 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9339 | |
| 9340 | if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS) |
| 9341 | return -EOPNOTSUPP; |
| 9342 | |
| 9343 | switch (f->command) { |
| 9344 | case TC_BLOCK_BIND: |
| 9345 | return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb, |
John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 9346 | adapter, adapter, f->extack); |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9347 | case TC_BLOCK_UNBIND: |
| 9348 | tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb, |
| 9349 | adapter); |
| 9350 | return 0; |
| 9351 | default: |
| 9352 | return -EOPNOTSUPP; |
| 9353 | } |
| 9354 | } |
| 9355 | |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9356 | static int ixgbe_setup_tc_mqprio(struct net_device *dev, |
| 9357 | struct tc_mqprio_qopt *mqprio) |
| 9358 | { |
| 9359 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 9360 | return ixgbe_setup_tc(dev, mqprio->num_tc); |
| 9361 | } |
| 9362 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 9363 | static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type, |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 9364 | void *type_data) |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9365 | { |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9366 | switch (type) { |
Jiri Pirko | 6ea30f8 | 2017-10-19 15:50:41 +0200 | [diff] [blame] | 9367 | case TC_SETUP_BLOCK: |
| 9368 | return ixgbe_setup_tc_block(dev, type_data); |
Nogah Frankel | 575ed7d | 2017-11-06 07:23:42 +0100 | [diff] [blame] | 9369 | case TC_SETUP_QDISC_MQPRIO: |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 9370 | return ixgbe_setup_tc_mqprio(dev, type_data); |
Jiri Pirko | bc32afd | 2017-08-07 10:15:21 +0200 | [diff] [blame] | 9371 | default: |
Jiri Pirko | a5fcf8a | 2017-06-06 17:00:16 +0200 | [diff] [blame] | 9372 | return -EOPNOTSUPP; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9373 | } |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 9374 | } |
| 9375 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9376 | #ifdef CONFIG_PCI_IOV |
| 9377 | void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter) |
| 9378 | { |
| 9379 | struct net_device *netdev = adapter->netdev; |
| 9380 | |
| 9381 | rtnl_lock(); |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 9382 | ixgbe_setup_tc(netdev, adapter->hw_tcs); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 9383 | rtnl_unlock(); |
| 9384 | } |
| 9385 | |
| 9386 | #endif |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9387 | void ixgbe_do_reset(struct net_device *netdev) |
| 9388 | { |
| 9389 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 9390 | |
| 9391 | if (netif_running(netdev)) |
| 9392 | ixgbe_reinit_locked(adapter); |
| 9393 | else |
| 9394 | ixgbe_reset(adapter); |
| 9395 | } |
| 9396 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 9397 | static netdev_features_t ixgbe_fix_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9398 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9399 | { |
| 9400 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 9401 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9402 | /* If Rx checksum is disabled, then RSC/LRO should also be disabled */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9403 | if (!(features & NETIF_F_RXCSUM)) |
| 9404 | features &= ~NETIF_F_LRO; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9405 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9406 | /* Turn off LRO if not RSC capable */ |
| 9407 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) |
| 9408 | features &= ~NETIF_F_LRO; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 9409 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9410 | return features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9411 | } |
| 9412 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9413 | static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter *adapter) |
| 9414 | { |
| 9415 | int rss = min_t(int, ixgbe_max_rss_indices(adapter), |
| 9416 | num_online_cpus()); |
| 9417 | |
| 9418 | /* go back to full RSS if we're not running SR-IOV */ |
| 9419 | if (!adapter->ring_feature[RING_F_VMDQ].offset) |
| 9420 | adapter->flags &= ~(IXGBE_FLAG_VMDQ_ENABLED | |
| 9421 | IXGBE_FLAG_SRIOV_ENABLED); |
| 9422 | |
| 9423 | adapter->ring_feature[RING_F_RSS].limit = rss; |
| 9424 | adapter->ring_feature[RING_F_VMDQ].limit = 1; |
| 9425 | |
| 9426 | ixgbe_setup_tc(adapter->netdev, adapter->hw_tcs); |
| 9427 | } |
| 9428 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 9429 | static int ixgbe_set_features(struct net_device *netdev, |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9430 | netdev_features_t features) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9431 | { |
| 9432 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9433 | netdev_features_t changed = netdev->features ^ features; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9434 | bool need_reset = false; |
| 9435 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9436 | /* Make sure RSC matches LRO, reset if change */ |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9437 | if (!(features & NETIF_F_LRO)) { |
| 9438 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9439 | need_reset = true; |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9440 | adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED; |
| 9441 | } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) && |
| 9442 | !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) { |
| 9443 | if (adapter->rx_itr_setting == 1 || |
| 9444 | adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) { |
| 9445 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
| 9446 | need_reset = true; |
| 9447 | } else if ((changed ^ features) & NETIF_F_LRO) { |
| 9448 | e_info(probe, "rx-usecs set too low, " |
| 9449 | "disabling RSC\n"); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9450 | } |
| 9451 | } |
| 9452 | |
| 9453 | /* |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9454 | * Check if Flow Director n-tuple support or hw_tc support was |
| 9455 | * enabled or disabled. If the state changed, we need to reset. |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9456 | */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9457 | if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) { |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9458 | /* turn off ATR, enable perfect filters and reset */ |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9459 | if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 9460 | need_reset = true; |
| 9461 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9462 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 9463 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9464 | } else { |
Alexander Duyck | 39cb681 | 2012-06-06 05:38:20 +0000 | [diff] [blame] | 9465 | /* turn off perfect filters, enable ATR and reset */ |
| 9466 | if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 9467 | need_reset = true; |
| 9468 | |
| 9469 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 9470 | |
| 9471 | /* We cannot enable ATR if SR-IOV is enabled */ |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9472 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED || |
| 9473 | /* We cannot enable ATR if we have 2 or more tcs */ |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 9474 | (adapter->hw_tcs > 1) || |
John Fastabend | b82b17d | 2016-02-16 21:18:53 -0800 | [diff] [blame] | 9475 | /* We cannot enable ATR if RSS is disabled */ |
| 9476 | (adapter->ring_feature[RING_F_RSS].limit <= 1) || |
| 9477 | /* A sample rate of 0 indicates ATR disabled */ |
| 9478 | (!adapter->atr_sample_rate)) |
| 9479 | ; /* do nothing not supported */ |
| 9480 | else /* otherwise supported and set the flag */ |
| 9481 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9482 | } |
| 9483 | |
Ben Greear | 3f2d1c0 | 2012-03-08 08:28:41 +0000 | [diff] [blame] | 9484 | if (changed & NETIF_F_RXALL) |
| 9485 | need_reset = true; |
| 9486 | |
Alexander Duyck | 567d2de | 2012-02-11 07:18:57 +0000 | [diff] [blame] | 9487 | netdev->features = features; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9488 | |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9489 | if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) { |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9490 | if (features & NETIF_F_RXCSUM) { |
| 9491 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9492 | } else { |
| 9493 | u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9494 | |
| 9495 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9496 | } |
| 9497 | } |
| 9498 | |
| 9499 | if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) { |
| 9500 | if (features & NETIF_F_RXCSUM) { |
| 9501 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
| 9502 | } else { |
| 9503 | u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9504 | |
| 9505 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9506 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9507 | } |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9508 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9509 | if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1) |
| 9510 | ixgbe_reset_l2fw_offload(adapter); |
| 9511 | else if (need_reset) |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9512 | ixgbe_do_reset(netdev); |
Alexander Duyck | 0c5a616 | 2016-03-10 10:01:10 -0800 | [diff] [blame] | 9513 | else if (changed & (NETIF_F_HW_VLAN_CTAG_RX | |
| 9514 | NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 9515 | ixgbe_set_rx_mode(netdev); |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9516 | |
| 9517 | return 0; |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 9518 | } |
| 9519 | |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9520 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9521 | * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9522 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9523 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9524 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9525 | static void ixgbe_add_udp_tunnel_port(struct net_device *dev, |
| 9526 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9527 | { |
| 9528 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9529 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9530 | __be16 port = ti->port; |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9531 | u32 port_shift = 0; |
| 9532 | u32 reg; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9533 | |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9534 | if (ti->sa_family != AF_INET) |
| 9535 | return; |
| 9536 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9537 | switch (ti->type) { |
| 9538 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9539 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9540 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9541 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9542 | if (adapter->vxlan_port == port) |
| 9543 | return; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9544 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9545 | if (adapter->vxlan_port) { |
| 9546 | netdev_info(dev, |
| 9547 | "VXLAN port %d set, not adding port %d\n", |
| 9548 | ntohs(adapter->vxlan_port), |
| 9549 | ntohs(port)); |
| 9550 | return; |
| 9551 | } |
| 9552 | |
| 9553 | adapter->vxlan_port = port; |
| 9554 | break; |
| 9555 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9556 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9557 | return; |
| 9558 | |
| 9559 | if (adapter->geneve_port == port) |
| 9560 | return; |
| 9561 | |
| 9562 | if (adapter->geneve_port) { |
| 9563 | netdev_info(dev, |
| 9564 | "GENEVE port %d set, not adding port %d\n", |
| 9565 | ntohs(adapter->geneve_port), |
| 9566 | ntohs(port)); |
| 9567 | return; |
| 9568 | } |
| 9569 | |
| 9570 | port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT; |
| 9571 | adapter->geneve_port = port; |
| 9572 | break; |
| 9573 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9574 | return; |
| 9575 | } |
| 9576 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9577 | reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift; |
| 9578 | IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg); |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9579 | } |
| 9580 | |
| 9581 | /** |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9582 | * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9583 | * @dev: The port's netdev |
Sabrina Dubroca | e5de25d | 2016-07-11 13:12:28 +0200 | [diff] [blame] | 9584 | * @ti: Tunnel endpoint information |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9585 | **/ |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9586 | static void ixgbe_del_udp_tunnel_port(struct net_device *dev, |
| 9587 | struct udp_tunnel_info *ti) |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9588 | { |
| 9589 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9590 | u32 port_mask; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9591 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9592 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN && |
| 9593 | ti->type != UDP_TUNNEL_TYPE_GENEVE) |
Alexander Duyck | b3a4955 | 2016-06-16 12:22:19 -0700 | [diff] [blame] | 9594 | return; |
| 9595 | |
| 9596 | if (ti->sa_family != AF_INET) |
| 9597 | return; |
| 9598 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9599 | switch (ti->type) { |
| 9600 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9601 | if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) |
| 9602 | return; |
Mark Rustad | 67359c3 | 2015-06-15 11:33:25 -0700 | [diff] [blame] | 9603 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9604 | if (adapter->vxlan_port != ti->port) { |
| 9605 | netdev_info(dev, "VXLAN port %d not found\n", |
| 9606 | ntohs(ti->port)); |
| 9607 | return; |
| 9608 | } |
| 9609 | |
| 9610 | port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK; |
| 9611 | break; |
| 9612 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9613 | if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) |
| 9614 | return; |
| 9615 | |
| 9616 | if (adapter->geneve_port != ti->port) { |
| 9617 | netdev_info(dev, "GENEVE port %d not found\n", |
| 9618 | ntohs(ti->port)); |
| 9619 | return; |
| 9620 | } |
| 9621 | |
| 9622 | port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK; |
| 9623 | break; |
| 9624 | default: |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9625 | return; |
| 9626 | } |
| 9627 | |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 9628 | ixgbe_clear_udp_tunnel_port(adapter, port_mask); |
| 9629 | adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED; |
Don Skidmore | 3f20780 | 2014-12-23 07:40:34 +0000 | [diff] [blame] | 9630 | } |
| 9631 | |
stephen hemminger | edc7d57 | 2012-10-01 12:32:33 +0000 | [diff] [blame] | 9632 | static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9633 | struct net_device *dev, |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9634 | const unsigned char *addr, u16 vid, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9635 | u16 flags) |
| 9636 | { |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9637 | /* guarantee we can provide a unique filter for the unicast address */ |
Ben Hutchings | 46acc46 | 2012-11-01 09:11:11 +0000 | [diff] [blame] | 9638 | if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) { |
Alexander Duyck | 2f9be16 | 2015-10-22 16:26:42 -0700 | [diff] [blame] | 9639 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9640 | u16 pool = VMDQ_P(0); |
| 9641 | |
| 9642 | if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool)) |
Alexander Duyck | bcfd343 | 2014-07-17 02:11:22 +0000 | [diff] [blame] | 9643 | return -ENOMEM; |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9644 | } |
| 9645 | |
Jiri Pirko | f6f6424 | 2014-11-28 14:34:15 +0100 | [diff] [blame] | 9646 | return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags); |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 9647 | } |
| 9648 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9649 | /** |
| 9650 | * ixgbe_configure_bridge_mode - set various bridge modes |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 9651 | * @adapter: the private structure |
| 9652 | * @mode: requested bridge mode |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9653 | * |
| 9654 | * Configure some settings require for various bridge modes. |
| 9655 | **/ |
| 9656 | static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter, |
| 9657 | __u16 mode) |
| 9658 | { |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9659 | struct ixgbe_hw *hw = &adapter->hw; |
| 9660 | unsigned int p, num_pools; |
| 9661 | u32 vmdctl; |
| 9662 | |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9663 | switch (mode) { |
| 9664 | case BRIDGE_MODE_VEPA: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9665 | /* disable Tx loopback, rely on switch hairpin mode */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9666 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9667 | |
| 9668 | /* must enable Rx switching replication to allow multicast |
| 9669 | * packet reception on all VFs, and to enable source address |
| 9670 | * pruning. |
| 9671 | */ |
| 9672 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9673 | vmdctl |= IXGBE_VT_CTL_REPLEN; |
| 9674 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9675 | |
| 9676 | /* enable Rx source address pruning. Note, this requires |
| 9677 | * replication to be enabled or else it does nothing. |
| 9678 | */ |
| 9679 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9680 | for (p = 0; p < num_pools; p++) { |
| 9681 | if (hw->mac.ops.set_source_address_pruning) |
| 9682 | hw->mac.ops.set_source_address_pruning(hw, |
| 9683 | true, |
| 9684 | p); |
| 9685 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9686 | break; |
| 9687 | case BRIDGE_MODE_VEB: |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9688 | /* enable Tx loopback for internal VF/PF communication */ |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9689 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, |
| 9690 | IXGBE_PFDTXGSWC_VT_LBEN); |
Don Skidmore | 6d4c96a | 2015-04-09 22:03:23 -0700 | [diff] [blame] | 9691 | |
| 9692 | /* disable Rx switching replication unless we have SR-IOV |
| 9693 | * virtual functions |
| 9694 | */ |
| 9695 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL); |
| 9696 | if (!adapter->num_vfs) |
| 9697 | vmdctl &= ~IXGBE_VT_CTL_REPLEN; |
| 9698 | IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl); |
| 9699 | |
| 9700 | /* disable Rx source address pruning, since we don't expect to |
| 9701 | * be receiving external loopback of our transmitted frames. |
| 9702 | */ |
| 9703 | num_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9704 | for (p = 0; p < num_pools; p++) { |
| 9705 | if (hw->mac.ops.set_source_address_pruning) |
| 9706 | hw->mac.ops.set_source_address_pruning(hw, |
| 9707 | false, |
| 9708 | p); |
| 9709 | } |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9710 | break; |
| 9711 | default: |
| 9712 | return -EINVAL; |
| 9713 | } |
| 9714 | |
| 9715 | adapter->bridge_mode = mode; |
| 9716 | |
| 9717 | e_info(drv, "enabling bridge mode: %s\n", |
| 9718 | mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB"); |
| 9719 | |
| 9720 | return 0; |
| 9721 | } |
| 9722 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9723 | static int ixgbe_ndo_bridge_setlink(struct net_device *dev, |
Roopa Prabhu | add511b | 2015-01-29 22:40:12 -0800 | [diff] [blame] | 9724 | struct nlmsghdr *nlh, u16 flags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9725 | { |
| 9726 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9727 | struct nlattr *attr, *br_spec; |
| 9728 | int rem; |
| 9729 | |
| 9730 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9731 | return -EOPNOTSUPP; |
| 9732 | |
| 9733 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
Thomas Graf | 4ea85e8 | 2014-11-26 13:42:18 +0100 | [diff] [blame] | 9734 | if (!br_spec) |
| 9735 | return -EINVAL; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9736 | |
| 9737 | nla_for_each_nested(attr, br_spec, rem) { |
Mark Rustad | a1e869d | 2015-04-10 10:36:36 -0700 | [diff] [blame] | 9738 | int status; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9739 | __u16 mode; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9740 | |
| 9741 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9742 | continue; |
| 9743 | |
Thomas Graf | b7c1a31 | 2014-11-26 13:42:17 +0100 | [diff] [blame] | 9744 | if (nla_len(attr) < sizeof(mode)) |
| 9745 | return -EINVAL; |
| 9746 | |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9747 | mode = nla_get_u16(attr); |
Don Skidmore | 219efe9 | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9748 | status = ixgbe_configure_bridge_mode(adapter, mode); |
| 9749 | if (status) |
| 9750 | return status; |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9751 | |
| 9752 | break; |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9753 | } |
| 9754 | |
| 9755 | return 0; |
| 9756 | } |
| 9757 | |
| 9758 | 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] | 9759 | struct net_device *dev, |
Nicolas Dichtel | 46c264d | 2015-04-28 18:33:49 +0200 | [diff] [blame] | 9760 | u32 filter_mask, int nlflags) |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9761 | { |
| 9762 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9763 | |
| 9764 | if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) |
| 9765 | return 0; |
| 9766 | |
Don Skidmore | aa2bacb | 2015-04-09 22:03:22 -0700 | [diff] [blame] | 9767 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, |
Scott Feldman | 7d4f8d8 | 2015-06-22 00:27:17 -0700 | [diff] [blame] | 9768 | adapter->bridge_mode, 0, 0, nlflags, |
| 9769 | filter_mask, NULL); |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 9770 | } |
| 9771 | |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9772 | static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) |
| 9773 | { |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9774 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9775 | struct ixgbe_fwd_adapter *accel; |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 9776 | int tcs = adapter->hw_tcs ? : 1; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9777 | int pool, err; |
| 9778 | |
Alexander Duyck | 3335915 | 2018-04-03 17:16:35 -0400 | [diff] [blame] | 9779 | /* The hardware supported by ixgbe only filters on the destination MAC |
| 9780 | * address. In order to avoid issues we only support offloading modes |
| 9781 | * where the hardware can actually provide the functionality. |
| 9782 | */ |
| 9783 | if (!macvlan_supports_dest_filter(vdev)) |
| 9784 | return ERR_PTR(-EMEDIUMTYPE); |
| 9785 | |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 9786 | /* We need to lock down the macvlan to be a single queue device so that |
| 9787 | * we can reuse the tc_to_txq field in the macvlan netdev to represent |
| 9788 | * the queue mapping to our netdev. |
| 9789 | */ |
| 9790 | if (netif_is_multiqueue(vdev)) |
| 9791 | return ERR_PTR(-ERANGE); |
| 9792 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9793 | pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools); |
| 9794 | if (pool == adapter->num_rx_pools) { |
| 9795 | u16 used_pools = adapter->num_vfs + adapter->num_rx_pools; |
| 9796 | u16 reserved_pools; |
Jacob Keller | aac2f1b | 2014-08-21 06:17:59 +0000 | [diff] [blame] | 9797 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9798 | if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && |
| 9799 | adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) || |
| 9800 | adapter->num_rx_pools > IXGBE_MAX_MACVLANS) |
| 9801 | return ERR_PTR(-EBUSY); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9802 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9803 | /* Hardware has a limited number of available pools. Each VF, |
| 9804 | * and the PF require a pool. Check to ensure we don't |
| 9805 | * attempt to use more then the available number of pools. |
| 9806 | */ |
| 9807 | if (used_pools >= IXGBE_MAX_VF_FUNCTIONS) |
| 9808 | return ERR_PTR(-EBUSY); |
| 9809 | |
| 9810 | /* Enable VMDq flag so device will be set in VM mode */ |
| 9811 | adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED | |
| 9812 | IXGBE_FLAG_SRIOV_ENABLED; |
| 9813 | |
| 9814 | /* Try to reserve as many queues per pool as possible, |
| 9815 | * we start with the configurations that support 4 queues |
| 9816 | * per pools, followed by 2, and then by just 1 per pool. |
| 9817 | */ |
| 9818 | if (used_pools < 32 && adapter->num_rx_pools < 16) |
| 9819 | reserved_pools = min_t(u16, |
| 9820 | 32 - used_pools, |
| 9821 | 16 - adapter->num_rx_pools); |
| 9822 | else if (adapter->num_rx_pools < 32) |
| 9823 | reserved_pools = min_t(u16, |
| 9824 | 64 - used_pools, |
| 9825 | 32 - adapter->num_rx_pools); |
| 9826 | else |
| 9827 | reserved_pools = 64 - used_pools; |
| 9828 | |
| 9829 | |
| 9830 | if (!reserved_pools) |
| 9831 | return ERR_PTR(-EBUSY); |
| 9832 | |
| 9833 | adapter->ring_feature[RING_F_VMDQ].limit += reserved_pools; |
| 9834 | |
| 9835 | /* Force reinit of ring allocation with VMDQ enabled */ |
| 9836 | err = ixgbe_setup_tc(pdev, adapter->hw_tcs); |
| 9837 | if (err) |
| 9838 | return ERR_PTR(err); |
| 9839 | |
| 9840 | if (pool >= adapter->num_rx_pools) |
| 9841 | return ERR_PTR(-ENOMEM); |
| 9842 | } |
| 9843 | |
| 9844 | accel = kzalloc(sizeof(*accel), GFP_KERNEL); |
| 9845 | if (!accel) |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9846 | return ERR_PTR(-ENOMEM); |
| 9847 | |
Alexander Duyck | 4e039c1 | 2017-11-22 10:56:40 -0800 | [diff] [blame] | 9848 | set_bit(pool, adapter->fwd_bitmask); |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 9849 | netdev_set_sb_channel(vdev, pool); |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9850 | accel->pool = pool; |
| 9851 | accel->netdev = vdev; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9852 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9853 | if (!netif_running(pdev)) |
| 9854 | return accel; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9855 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9856 | err = ixgbe_fwd_ring_up(adapter, accel); |
| 9857 | if (err) |
| 9858 | return ERR_PTR(err); |
Emil Tantilov | a3b8cb1 | 2016-09-22 15:06:52 -0700 | [diff] [blame] | 9859 | |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9860 | return accel; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9861 | } |
| 9862 | |
| 9863 | static void ixgbe_fwd_del(struct net_device *pdev, void *priv) |
| 9864 | { |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 9865 | struct ixgbe_fwd_adapter *accel = priv; |
Alexander Duyck | 865255b | 2018-04-03 17:16:40 -0400 | [diff] [blame] | 9866 | struct ixgbe_adapter *adapter = netdev_priv(pdev); |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 9867 | unsigned int rxbase = accel->rx_base_queue; |
Alexander Duyck | 8315ef6 | 2018-04-03 17:16:45 -0400 | [diff] [blame] | 9868 | unsigned int i; |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9869 | |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 9870 | /* delete unicast filter associated with offloaded interface */ |
| 9871 | ixgbe_del_mac_filter(adapter, accel->netdev->dev_addr, |
| 9872 | VMDQ_P(accel->pool)); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9873 | |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 9874 | /* Allow remaining Rx packets to get flushed out of the |
| 9875 | * Rx FIFO before we drop the netdev for the ring. |
| 9876 | */ |
| 9877 | usleep_range(10000, 20000); |
| 9878 | |
| 9879 | for (i = 0; i < adapter->num_rx_queues_per_pool; i++) { |
| 9880 | struct ixgbe_ring *ring = adapter->rx_ring[rxbase + i]; |
| 9881 | struct ixgbe_q_vector *qv = ring->q_vector; |
| 9882 | |
| 9883 | /* Make sure we aren't processing any packets and clear |
| 9884 | * netdev to shut down the ring. |
| 9885 | */ |
| 9886 | if (netif_running(adapter->netdev)) |
| 9887 | napi_synchronize(&qv->napi); |
| 9888 | ring->netdev = NULL; |
| 9889 | } |
| 9890 | |
Alexander Duyck | 58b0b3e | 2018-07-09 12:19:43 -0400 | [diff] [blame] | 9891 | /* unbind the queues and drop the subordinate channel config */ |
| 9892 | netdev_unbind_sb_channel(pdev, accel->netdev); |
| 9893 | netdev_set_sb_channel(accel->netdev, 0); |
| 9894 | |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 9895 | clear_bit(accel->pool, adapter->fwd_bitmask); |
Alexander Duyck | b5f69cc | 2017-11-22 10:57:29 -0800 | [diff] [blame] | 9896 | kfree(accel); |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 9897 | } |
| 9898 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9899 | #define IXGBE_MAX_MAC_HDR_LEN 127 |
| 9900 | #define IXGBE_MAX_NETWORK_HDR_LEN 511 |
| 9901 | |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9902 | static netdev_features_t |
| 9903 | ixgbe_features_check(struct sk_buff *skb, struct net_device *dev, |
| 9904 | netdev_features_t features) |
| 9905 | { |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9906 | unsigned int network_hdr_len, mac_hdr_len; |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9907 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9908 | /* Make certain the headers can be described by a context descriptor */ |
| 9909 | mac_hdr_len = skb_network_header(skb) - skb->data; |
| 9910 | if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN)) |
| 9911 | return features & ~(NETIF_F_HW_CSUM | |
| 9912 | NETIF_F_SCTP_CRC | |
| 9913 | NETIF_F_HW_VLAN_CTAG_TX | |
| 9914 | NETIF_F_TSO | |
| 9915 | NETIF_F_TSO6); |
| 9916 | |
| 9917 | network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb); |
| 9918 | if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN)) |
| 9919 | return features & ~(NETIF_F_HW_CSUM | |
| 9920 | NETIF_F_SCTP_CRC | |
| 9921 | NETIF_F_TSO | |
| 9922 | NETIF_F_TSO6); |
| 9923 | |
| 9924 | /* We can only support IPV4 TSO in tunnels if we can mangle the |
| 9925 | * inner IP ID field, so strip TSO if MANGLEID is not supported. |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 9926 | * IPsec offoad sets skb->encapsulation but still can handle |
| 9927 | * the TSO, so it's the exception. |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 9928 | */ |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 9929 | if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) { |
Alexander Duyck | e433f3a | 2018-06-04 16:51:20 -0400 | [diff] [blame] | 9930 | #ifdef CONFIG_XFRM_OFFLOAD |
Shannon Nelson | 70da682 | 2018-03-16 11:09:07 -0700 | [diff] [blame] | 9931 | if (!skb->sp) |
| 9932 | #endif |
| 9933 | features &= ~NETIF_F_TSO; |
| 9934 | } |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 9935 | |
| 9936 | return features; |
| 9937 | } |
| 9938 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9939 | static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog) |
| 9940 | { |
| 9941 | int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 9942 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9943 | struct bpf_prog *old_prog; |
| 9944 | |
| 9945 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 9946 | return -EINVAL; |
| 9947 | |
| 9948 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 9949 | return -EINVAL; |
| 9950 | |
| 9951 | /* verify ixgbe ring attributes are sufficient for XDP */ |
| 9952 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 9953 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 9954 | |
| 9955 | if (ring_is_rsc_enabled(ring)) |
| 9956 | return -EINVAL; |
| 9957 | |
| 9958 | if (frame_size > ixgbe_rx_bufsz(ring)) |
| 9959 | return -EINVAL; |
| 9960 | } |
| 9961 | |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 9962 | if (nr_cpu_ids > MAX_XDP_QUEUES) |
| 9963 | return -ENOMEM; |
| 9964 | |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9965 | old_prog = xchg(&adapter->xdp_prog, prog); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 9966 | |
| 9967 | /* If transitioning XDP modes reconfigure rings */ |
| 9968 | if (!!prog != !!old_prog) { |
Alexander Duyck | 0efbf12 | 2017-11-22 10:57:11 -0800 | [diff] [blame] | 9969 | int err = ixgbe_setup_tc(dev, adapter->hw_tcs); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 9970 | |
| 9971 | if (err) { |
| 9972 | rcu_assign_pointer(adapter->xdp_prog, old_prog); |
| 9973 | return -EINVAL; |
| 9974 | } |
| 9975 | } else { |
| 9976 | for (i = 0; i < adapter->num_rx_queues; i++) |
Cathy Zhou | 9cfbfa7 | 2018-04-13 11:28:37 -0700 | [diff] [blame] | 9977 | (void)xchg(&adapter->rx_ring[i]->xdp_prog, |
| 9978 | adapter->xdp_prog); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 9979 | } |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9980 | |
| 9981 | if (old_prog) |
| 9982 | bpf_prog_put(old_prog); |
| 9983 | |
| 9984 | return 0; |
| 9985 | } |
| 9986 | |
Jakub Kicinski | f4e6352 | 2017-11-03 13:56:16 -0700 | [diff] [blame] | 9987 | static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp) |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9988 | { |
| 9989 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 9990 | |
| 9991 | switch (xdp->command) { |
| 9992 | case XDP_SETUP_PROG: |
| 9993 | return ixgbe_xdp_setup(dev, xdp->prog); |
| 9994 | case XDP_QUERY_PROG: |
| 9995 | xdp->prog_attached = !!(adapter->xdp_prog); |
Martin KaFai Lau | 4792093 | 2017-06-15 17:29:15 -0700 | [diff] [blame] | 9996 | xdp->prog_id = adapter->xdp_prog ? |
| 9997 | adapter->xdp_prog->aux->id : 0; |
John Fastabend | 9247080 | 2017-04-24 03:30:17 -0700 | [diff] [blame] | 9998 | return 0; |
| 9999 | default: |
| 10000 | return -EINVAL; |
| 10001 | } |
| 10002 | } |
| 10003 | |
Jesper Dangaard Brouer | 5e2e609 | 2018-05-31 10:59:57 +0200 | [diff] [blame] | 10004 | static void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring) |
| 10005 | { |
| 10006 | /* Force memory writes to complete before letting h/w know there |
| 10007 | * are new descriptors to fetch. |
| 10008 | */ |
| 10009 | wmb(); |
| 10010 | writel(ring->next_to_use, ring->tail); |
| 10011 | } |
| 10012 | |
Jesper Dangaard Brouer | 735fc40 | 2018-05-24 16:46:12 +0200 | [diff] [blame] | 10013 | static int ixgbe_xdp_xmit(struct net_device *dev, int n, |
Jesper Dangaard Brouer | 42b3346 | 2018-05-31 10:59:47 +0200 | [diff] [blame] | 10014 | struct xdp_frame **frames, u32 flags) |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10015 | { |
| 10016 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 10017 | struct ixgbe_ring *ring; |
Jesper Dangaard Brouer | 735fc40 | 2018-05-24 16:46:12 +0200 | [diff] [blame] | 10018 | int drops = 0; |
| 10019 | int i; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10020 | |
| 10021 | if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state))) |
Jesper Dangaard Brouer | 2886447 | 2017-08-24 12:33:13 +0200 | [diff] [blame] | 10022 | return -ENETDOWN; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10023 | |
Jesper Dangaard Brouer | 5e2e609 | 2018-05-31 10:59:57 +0200 | [diff] [blame] | 10024 | if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) |
Jesper Dangaard Brouer | 42b3346 | 2018-05-31 10:59:47 +0200 | [diff] [blame] | 10025 | return -EINVAL; |
| 10026 | |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10027 | /* During program transitions its possible adapter->xdp_prog is assigned |
| 10028 | * but ring has not been configured yet. In this case simply abort xmit. |
| 10029 | */ |
| 10030 | ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL; |
| 10031 | if (unlikely(!ring)) |
Jesper Dangaard Brouer | 2886447 | 2017-08-24 12:33:13 +0200 | [diff] [blame] | 10032 | return -ENXIO; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10033 | |
Jesper Dangaard Brouer | 735fc40 | 2018-05-24 16:46:12 +0200 | [diff] [blame] | 10034 | for (i = 0; i < n; i++) { |
| 10035 | struct xdp_frame *xdpf = frames[i]; |
| 10036 | int err; |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10037 | |
Jesper Dangaard Brouer | 735fc40 | 2018-05-24 16:46:12 +0200 | [diff] [blame] | 10038 | err = ixgbe_xmit_xdp_ring(adapter, xdpf); |
| 10039 | if (err != IXGBE_XDP_TX) { |
| 10040 | xdp_return_frame_rx_napi(xdpf); |
| 10041 | drops++; |
| 10042 | } |
| 10043 | } |
| 10044 | |
Jesper Dangaard Brouer | 5e2e609 | 2018-05-31 10:59:57 +0200 | [diff] [blame] | 10045 | if (unlikely(flags & XDP_XMIT_FLUSH)) |
| 10046 | ixgbe_xdp_ring_update_tail(ring); |
| 10047 | |
Jesper Dangaard Brouer | 735fc40 | 2018-05-24 16:46:12 +0200 | [diff] [blame] | 10048 | return n - drops; |
John Fastabend | 11393cc | 2017-07-17 09:29:40 -0700 | [diff] [blame] | 10049 | } |
| 10050 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10051 | static const struct net_device_ops ixgbe_netdev_ops = { |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10052 | .ndo_open = ixgbe_open, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10053 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 10054 | .ndo_start_xmit = ixgbe_xmit_frame, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 10055 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10056 | .ndo_validate_addr = eth_validate_addr, |
| 10057 | .ndo_set_mac_address = ixgbe_set_mac, |
| 10058 | .ndo_change_mtu = ixgbe_change_mtu, |
| 10059 | .ndo_tx_timeout = ixgbe_tx_timeout, |
Rostislav Pehlivanov | c04f90e | 2016-01-27 18:33:30 +0000 | [diff] [blame] | 10060 | .ndo_set_tx_maxrate = ixgbe_tx_maxrate, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10061 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 10062 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 10063 | .ndo_do_ioctl = ixgbe_ioctl, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 10064 | .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac, |
| 10065 | .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan, |
Sucheta Chakraborty | ed61668 | 2014-05-22 09:59:05 -0400 | [diff] [blame] | 10066 | .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw, |
Alexander Duyck | 581330b | 2012-02-08 07:51:47 +0000 | [diff] [blame] | 10067 | .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk, |
Vlad Zolotarov | e65ce0d | 2015-03-30 21:35:24 +0300 | [diff] [blame] | 10068 | .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en, |
Hiroshi Shimamoto | 54011e4 | 2015-08-28 06:58:33 +0000 | [diff] [blame] | 10069 | .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust, |
Greg Rose | 7f01648 | 2010-05-04 22:12:06 +0000 | [diff] [blame] | 10070 | .ndo_get_vf_config = ixgbe_ndo_get_vf_config, |
Eric Dumazet | de1036b | 2010-10-20 23:00:04 +0000 | [diff] [blame] | 10071 | .ndo_get_stats64 = ixgbe_get_stats64, |
John Fastabend | e4c6734 | 2016-02-16 21:16:15 -0800 | [diff] [blame] | 10072 | .ndo_setup_tc = __ixgbe_setup_tc, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10073 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 10074 | .ndo_poll_controller = ixgbe_netpoll, |
| 10075 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 10076 | #ifdef IXGBE_FCOE |
Alexander Duyck | eadec877 | 2018-07-09 12:19:48 -0400 | [diff] [blame] | 10077 | .ndo_select_queue = ixgbe_select_queue, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 10078 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
Yi Zou | 68a683c | 2011-02-01 07:22:16 +0000 | [diff] [blame] | 10079 | .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 10080 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 10081 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 10082 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 10083 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 10084 | .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 10085 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10086 | .ndo_set_features = ixgbe_set_features, |
| 10087 | .ndo_fix_features = ixgbe_fix_features, |
John Fastabend | 0f4b0ad | 2012-04-15 06:44:19 +0000 | [diff] [blame] | 10088 | .ndo_fdb_add = ixgbe_ndo_fdb_add, |
John Fastabend | 815cccb | 2012-10-24 08:13:09 +0000 | [diff] [blame] | 10089 | .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, |
| 10090 | .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, |
John Fastabend | 2a47fa4 | 2013-11-06 09:54:52 -0800 | [diff] [blame] | 10091 | .ndo_dfwd_add_station = ixgbe_fwd_add, |
| 10092 | .ndo_dfwd_del_station = ixgbe_fwd_del, |
Emil Tantilov | a21d082 | 2016-08-10 11:19:23 -0700 | [diff] [blame] | 10093 | .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port, |
| 10094 | .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port, |
Mark Rustad | f467bc0 | 2015-06-15 11:33:20 -0700 | [diff] [blame] | 10095 | .ndo_features_check = ixgbe_features_check, |
Jakub Kicinski | f4e6352 | 2017-11-03 13:56:16 -0700 | [diff] [blame] | 10096 | .ndo_bpf = ixgbe_xdp, |
John Fastabend | 6453073 | 2017-07-17 09:28:12 -0700 | [diff] [blame] | 10097 | .ndo_xdp_xmit = ixgbe_xdp_xmit, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10098 | }; |
| 10099 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10100 | /** |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10101 | * ixgbe_enumerate_functions - Get the number of ports this device has |
| 10102 | * @adapter: adapter structure |
| 10103 | * |
| 10104 | * This function enumerates the phsyical functions co-located on a single slot, |
| 10105 | * in order to determine how many ports a device has. This is most useful in |
| 10106 | * determining the required GT/s of PCIe bandwidth necessary for optimal |
| 10107 | * performance. |
| 10108 | **/ |
| 10109 | static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter) |
| 10110 | { |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 10111 | struct pci_dev *entry, *pdev = adapter->pdev; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10112 | int physfns = 0; |
| 10113 | |
Jacob Keller | f1f9657 | 2013-08-31 02:45:38 +0000 | [diff] [blame] | 10114 | /* Some cards can not use the generic count PCIe functions method, |
| 10115 | * because they are behind a parent switch, so we hardcode these with |
| 10116 | * the correct number of functions. |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10117 | */ |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 10118 | if (ixgbe_pcie_from_parent(&adapter->hw)) |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10119 | physfns = 4; |
Jacob Keller | 8818970 | 2014-07-19 07:17:16 +0000 | [diff] [blame] | 10120 | |
| 10121 | list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) { |
| 10122 | /* don't count virtual functions */ |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 10123 | if (entry->is_virtfn) |
| 10124 | continue; |
| 10125 | |
| 10126 | /* When the devices on the bus don't all match our device ID, |
| 10127 | * we can't reliably determine the correct number of |
| 10128 | * functions. This can occur if a function has been direct |
| 10129 | * attached to a virtual machine using VT-d, for example. In |
| 10130 | * this case, simply return -1 to indicate this. |
| 10131 | */ |
| 10132 | if ((entry->vendor != pdev->vendor) || |
| 10133 | (entry->device != pdev->device)) |
| 10134 | return -1; |
| 10135 | |
| 10136 | physfns++; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10137 | } |
| 10138 | |
| 10139 | return physfns; |
| 10140 | } |
| 10141 | |
| 10142 | /** |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10143 | * ixgbe_wol_supported - Check whether device supports WoL |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10144 | * @adapter: the adapter private structure |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10145 | * @device_id: the device ID |
Tony Nguyen | 5ba643c | 2017-12-04 11:28:30 -0800 | [diff] [blame] | 10146 | * @subdevice_id: the subsystem device ID |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10147 | * |
| 10148 | * This function is used by probe and ethtool to determine |
| 10149 | * which devices have WoL support |
| 10150 | * |
| 10151 | **/ |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10152 | bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id, |
| 10153 | u16 subdevice_id) |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10154 | { |
| 10155 | struct ixgbe_hw *hw = &adapter->hw; |
| 10156 | u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10157 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10158 | /* WOL not supported on 82598 */ |
| 10159 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 10160 | return false; |
| 10161 | |
| 10162 | /* check eeprom to see if WOL is enabled for X540 and newer */ |
| 10163 | if (hw->mac.type >= ixgbe_mac_X540) { |
| 10164 | if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) || |
| 10165 | ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) && |
| 10166 | (hw->bus.func == 0))) |
| 10167 | return true; |
| 10168 | } |
| 10169 | |
| 10170 | /* WOL is determined based on device IDs for 82599 MACs */ |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10171 | switch (device_id) { |
| 10172 | case IXGBE_DEV_ID_82599_SFP: |
| 10173 | /* Only these subdevices could supports WOL */ |
| 10174 | switch (subdevice_id) { |
| 10175 | case IXGBE_SUBDEV_ID_82599_560FLR: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 10176 | case IXGBE_SUBDEV_ID_82599_LOM_SNAP6: |
| 10177 | case IXGBE_SUBDEV_ID_82599_SFP_WOL0: |
| 10178 | case IXGBE_SUBDEV_ID_82599_SFP_2OCP: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10179 | /* only support first port */ |
| 10180 | if (hw->bus.func != 0) |
| 10181 | break; |
Tony Nguyen | 93df946 | 2017-05-31 04:43:47 -0700 | [diff] [blame] | 10182 | /* fall through */ |
Emil Tantilov | 5700ff2 | 2013-04-18 08:18:55 +0000 | [diff] [blame] | 10183 | case IXGBE_SUBDEV_ID_82599_SP_560FLR: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10184 | case IXGBE_SUBDEV_ID_82599_SFP: |
Don Skidmore | b6dfd93 | 2012-07-11 07:17:42 +0000 | [diff] [blame] | 10185 | case IXGBE_SUBDEV_ID_82599_RNDC: |
Emil Tantilov | f8a06c2 | 2012-08-16 08:13:07 +0000 | [diff] [blame] | 10186 | case IXGBE_SUBDEV_ID_82599_ECNA_DP: |
Emil Tantilov | 00103a6c | 2016-04-21 11:37:06 -0700 | [diff] [blame] | 10187 | case IXGBE_SUBDEV_ID_82599_SFP_1OCP: |
| 10188 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1: |
| 10189 | case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10190 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10191 | } |
| 10192 | break; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 10193 | case IXGBE_DEV_ID_82599EN_SFP: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10194 | /* Only these subdevices support WOL */ |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 10195 | switch (subdevice_id) { |
| 10196 | case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10197 | return true; |
Don Skidmore | 5daebbb | 2013-04-05 05:49:34 +0000 | [diff] [blame] | 10198 | } |
| 10199 | break; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10200 | case IXGBE_DEV_ID_82599_COMBO_BACKPLANE: |
| 10201 | /* All except this subdevice support WOL */ |
| 10202 | if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ) |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10203 | return true; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10204 | break; |
| 10205 | case IXGBE_DEV_ID_82599_KX4: |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10206 | return true; |
| 10207 | default: |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10208 | break; |
| 10209 | } |
| 10210 | |
Emil Tantilov | 740234f | 2016-04-21 11:37:12 -0700 | [diff] [blame] | 10211 | return false; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10212 | } |
| 10213 | |
| 10214 | /** |
Paul Greenwalt | 73834ae | 2017-10-27 10:32:40 -0400 | [diff] [blame] | 10215 | * ixgbe_set_fw_version - Set FW version |
| 10216 | * @adapter: the adapter private structure |
| 10217 | * |
| 10218 | * This function is used by probe and ethtool to determine the FW version to |
| 10219 | * format to display. The FW version is taken from the EEPROM/NVM. |
| 10220 | */ |
| 10221 | static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter) |
| 10222 | { |
| 10223 | struct ixgbe_hw *hw = &adapter->hw; |
| 10224 | struct ixgbe_nvm_version nvm_ver; |
| 10225 | |
| 10226 | ixgbe_get_oem_prod_version(hw, &nvm_ver); |
| 10227 | if (nvm_ver.oem_valid) { |
| 10228 | snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id), |
| 10229 | "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor, |
| 10230 | nvm_ver.oem_release); |
| 10231 | return; |
| 10232 | } |
| 10233 | |
| 10234 | ixgbe_get_etk_id(hw, &nvm_ver); |
| 10235 | ixgbe_get_orom_version(hw, &nvm_ver); |
| 10236 | |
| 10237 | if (nvm_ver.or_valid) { |
| 10238 | snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id), |
| 10239 | "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major, |
| 10240 | nvm_ver.or_build, nvm_ver.or_patch); |
| 10241 | return; |
| 10242 | } |
| 10243 | |
| 10244 | /* Set ETrack ID format */ |
| 10245 | snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id), |
| 10246 | "0x%08x", nvm_ver.etk_id); |
| 10247 | } |
| 10248 | |
| 10249 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10250 | * ixgbe_probe - Device Initialization Routine |
| 10251 | * @pdev: PCI device information struct |
| 10252 | * @ent: entry in ixgbe_pci_tbl |
| 10253 | * |
| 10254 | * Returns 0 on success, negative on failure |
| 10255 | * |
| 10256 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 10257 | * The OS initialization, configuring of the adapter private structure, |
| 10258 | * and a hardware reset occur. |
| 10259 | **/ |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 10260 | 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] | 10261 | { |
| 10262 | struct net_device *netdev; |
| 10263 | struct ixgbe_adapter *adapter = NULL; |
| 10264 | struct ixgbe_hw *hw; |
| 10265 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10266 | int i, err, pci_using_dac, expected_gts; |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10267 | unsigned int indices = MAX_TX_QUEUES; |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 10268 | u8 part_str[IXGBE_PBANUM_LENGTH]; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10269 | bool disable_dev = false; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10270 | #ifdef IXGBE_FCOE |
| 10271 | u16 device_caps; |
| 10272 | #endif |
Don Skidmore | 289700db | 2010-12-03 03:32:58 +0000 | [diff] [blame] | 10273 | u32 eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10274 | |
Andy Gospodarek | bded64a | 2010-07-21 06:40:31 +0000 | [diff] [blame] | 10275 | /* Catch broken hardware that put the wrong VF device ID in |
| 10276 | * the PCIe SR-IOV capability. |
| 10277 | */ |
| 10278 | if (pdev->is_virtfn) { |
| 10279 | WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n", |
| 10280 | pci_name(pdev), pdev->vendor, pdev->device); |
| 10281 | return -EINVAL; |
| 10282 | } |
| 10283 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 10284 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10285 | if (err) |
| 10286 | return err; |
| 10287 | |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 10288 | if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10289 | pci_using_dac = 1; |
| 10290 | } else { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 10291 | err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10292 | if (err) { |
Russell King | f5f2eda | 2013-06-10 12:47:42 +0100 | [diff] [blame] | 10293 | dev_err(&pdev->dev, |
| 10294 | "No usable DMA configuration, aborting\n"); |
| 10295 | goto err_dma; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10296 | } |
| 10297 | pci_using_dac = 0; |
| 10298 | } |
| 10299 | |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10300 | err = pci_request_mem_regions(pdev, ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10301 | if (err) { |
Dan Carpenter | b8bc042 | 2010-07-27 00:05:56 +0000 | [diff] [blame] | 10302 | dev_err(&pdev->dev, |
| 10303 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10304 | goto err_pci_reg; |
| 10305 | } |
| 10306 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 10307 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10308 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10309 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 10310 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10311 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10312 | if (ii->mac == ixgbe_mac_82598EB) { |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 10313 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10314 | /* 8 TC w/ 4 queues per TC */ |
| 10315 | indices = 4 * MAX_TRAFFIC_CLASS; |
| 10316 | #else |
| 10317 | indices = IXGBE_MAX_RSS_INDICES; |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 10318 | #endif |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10319 | } |
John Fastabend | e901acd | 2011-04-26 07:26:08 +0000 | [diff] [blame] | 10320 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 10321 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10322 | if (!netdev) { |
| 10323 | err = -ENOMEM; |
| 10324 | goto err_alloc_etherdev; |
| 10325 | } |
| 10326 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10327 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 10328 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10329 | adapter = netdev_priv(netdev); |
| 10330 | |
| 10331 | adapter->netdev = netdev; |
| 10332 | adapter->pdev = pdev; |
| 10333 | hw = &adapter->hw; |
| 10334 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 10335 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10336 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 10337 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 10338 | pci_resource_len(pdev, 0)); |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10339 | adapter->io_addr = hw->hw_addr; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10340 | if (!hw->hw_addr) { |
| 10341 | err = -EIO; |
| 10342 | goto err_ioremap; |
| 10343 | } |
| 10344 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 10345 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10346 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10347 | netdev->watchdog_timeo = 5 * HZ; |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 10348 | strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10349 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10350 | /* Setup hw api */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10351 | hw->mac.ops = *ii->mac_ops; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10352 | hw->mac.type = ii->mac; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 10353 | hw->mvals = ii->mvals; |
Emil Tantilov | b71f6c4 | 2016-10-10 14:54:03 -0700 | [diff] [blame] | 10354 | if (ii->link_ops) |
| 10355 | hw->link.ops = *ii->link_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10356 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10357 | /* EEPROM */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10358 | hw->eeprom.ops = *ii->eeprom_ops; |
Don Skidmore | 9a900ec | 2015-06-09 17:15:01 -0700 | [diff] [blame] | 10359 | eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw)); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10360 | if (ixgbe_removed(hw->hw_addr)) { |
| 10361 | err = -EIO; |
| 10362 | goto err_ioremap; |
| 10363 | } |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10364 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
Jacob Keller | b4f47a4 | 2016-04-13 16:08:22 -0700 | [diff] [blame] | 10365 | if (!(eec & BIT(8))) |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10366 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 10367 | |
| 10368 | /* PHY */ |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10369 | hw->phy.ops = *ii->phy_ops; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 10370 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 10371 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 10372 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 10373 | hw->phy.mdio.mmds = 0; |
| 10374 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 10375 | hw->phy.mdio.dev = netdev; |
| 10376 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 10377 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 10378 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10379 | /* setup the private structure */ |
Emil Tantilov | 55570b6 | 2016-10-12 12:34:25 -0700 | [diff] [blame] | 10380 | err = ixgbe_sw_init(adapter, ii); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10381 | if (err) |
| 10382 | goto err_sw_init; |
| 10383 | |
Don Skidmore | dbd15b8 | 2016-03-09 16:45:00 -0500 | [diff] [blame] | 10384 | /* Make sure the SWFW semaphore is in a valid state */ |
| 10385 | if (hw->mac.ops.init_swfw_sync) |
| 10386 | hw->mac.ops.init_swfw_sync(hw); |
| 10387 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 10388 | /* Make it possible the adapter to be woken up via WOL */ |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 10389 | switch (adapter->hw.mac.type) { |
| 10390 | case ixgbe_mac_82599EB: |
| 10391 | case ixgbe_mac_X540: |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 10392 | case ixgbe_mac_X550: |
| 10393 | case ixgbe_mac_X550EM_x: |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 10394 | case ixgbe_mac_x550em_a: |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 10395 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Don Skidmore | b93a222 | 2010-11-16 19:27:17 -0800 | [diff] [blame] | 10396 | break; |
| 10397 | default: |
| 10398 | break; |
| 10399 | } |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 10400 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 10401 | /* |
| 10402 | * If there is a fan on this device and it has failed log the |
| 10403 | * failure. |
| 10404 | */ |
| 10405 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 10406 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 10407 | if (esdp & IXGBE_ESDP_SDP1) |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10408 | e_crit(probe, "Fan has stopped, replace the adapter\n"); |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 10409 | } |
| 10410 | |
Peter P Waskiewicz Jr | 8ef78ad | 2012-02-01 09:19:21 +0000 | [diff] [blame] | 10411 | if (allow_unsupported_sfp) |
| 10412 | hw->allow_unsupported_sfp = allow_unsupported_sfp; |
| 10413 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10414 | /* reset_hw fills in the perm_addr as well */ |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 10415 | hw->phy.reset_if_overtemp = true; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10416 | err = hw->mac.ops.reset_hw(hw); |
Mallikarjuna R Chilakala | 119fc60 | 2010-05-20 23:07:06 -0700 | [diff] [blame] | 10417 | hw->phy.reset_if_overtemp = false; |
Mark Rustad | b3eb4e1 | 2016-12-14 11:02:16 -0800 | [diff] [blame] | 10418 | ixgbe_set_eee_capable(adapter); |
Mark Rustad | 29a8dca | 2015-08-08 16:17:46 -0700 | [diff] [blame] | 10419 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 10420 | err = 0; |
| 10421 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 1b1bf31 | 2013-07-31 05:27:04 +0000 | [diff] [blame] | 10422 | e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n"); |
| 10423 | e_dev_err("Reload the driver after installing a supported module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 10424 | goto err_sw_init; |
| 10425 | } else if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10426 | e_dev_err("HW Init failed: %d\n", err); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10427 | goto err_sw_init; |
| 10428 | } |
| 10429 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10430 | #ifdef CONFIG_PCI_IOV |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 10431 | /* SR-IOV not supported on the 82598 */ |
| 10432 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 10433 | goto skip_sriov; |
| 10434 | /* Mailbox */ |
| 10435 | ixgbe_init_mbx_params_pf(hw); |
Mark Rustad | 3768901 | 2016-01-07 10:13:03 -0800 | [diff] [blame] | 10436 | hw->mbx.ops = ii->mbx_ops; |
ethan.zhao | dcc23e3 | 2014-01-16 19:41:04 -0800 | [diff] [blame] | 10437 | pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT); |
Emil Tantilov | 5c11f00 | 2017-01-20 14:11:56 -0800 | [diff] [blame] | 10438 | ixgbe_enable_sriov(adapter, max_vfs); |
Greg Rose | 60a1a68 | 2012-12-11 08:26:33 +0000 | [diff] [blame] | 10439 | skip_sriov: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 10440 | |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10441 | #endif |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10442 | netdev->features = NETIF_F_SG | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10443 | NETIF_F_TSO | |
| 10444 | NETIF_F_TSO6 | |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10445 | NETIF_F_RXHASH | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10446 | NETIF_F_RXCSUM | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10447 | NETIF_F_HW_CSUM; |
| 10448 | |
| 10449 | #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \ |
| 10450 | NETIF_F_GSO_GRE_CSUM | \ |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 10451 | NETIF_F_GSO_IPXIP4 | \ |
Alexander Duyck | bf2d1df | 2016-05-18 10:44:53 -0700 | [diff] [blame] | 10452 | NETIF_F_GSO_IPXIP6 | \ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10453 | NETIF_F_GSO_UDP_TUNNEL | \ |
| 10454 | NETIF_F_GSO_UDP_TUNNEL_CSUM) |
| 10455 | |
| 10456 | netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES; |
| 10457 | netdev->features |= NETIF_F_GSO_PARTIAL | |
| 10458 | IXGBE_GSO_PARTIAL_FEATURES; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10459 | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10460 | if (hw->mac.type >= ixgbe_mac_82599EB) |
Tom Herbert | 53692b1 | 2015-12-14 11:19:41 -0800 | [diff] [blame] | 10461 | netdev->features |= NETIF_F_SCTP_CRC; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 10462 | |
Alexander Duyck | de7a7e3 | 2018-06-04 16:51:25 -0400 | [diff] [blame] | 10463 | #ifdef CONFIG_XFRM_OFFLOAD |
| 10464 | #define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \ |
| 10465 | NETIF_F_HW_ESP_TX_CSUM | \ |
| 10466 | NETIF_F_GSO_ESP) |
| 10467 | |
| 10468 | if (adapter->ipsec) |
| 10469 | netdev->features |= IXGBE_ESP_FEATURES; |
| 10470 | #endif |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10471 | /* copy netdev features into list of user selectable features */ |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10472 | netdev->hw_features |= netdev->features | |
Alexander Duyck | 3d95182 | 2016-08-12 09:53:39 -0700 | [diff] [blame] | 10473 | NETIF_F_HW_VLAN_CTAG_FILTER | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10474 | NETIF_F_HW_VLAN_CTAG_RX | |
| 10475 | NETIF_F_HW_VLAN_CTAG_TX | |
| 10476 | NETIF_F_RXALL | |
Alexander Duyck | 49763de | 2016-01-13 07:31:11 -0800 | [diff] [blame] | 10477 | NETIF_F_HW_L2FW_DOFFLOAD; |
| 10478 | |
| 10479 | if (hw->mac.type >= ixgbe_mac_82599EB) |
| 10480 | netdev->hw_features |= NETIF_F_NTUPLE | |
| 10481 | NETIF_F_HW_TC; |
| 10482 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10483 | if (pci_using_dac) |
| 10484 | netdev->features |= NETIF_F_HIGHDMA; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 10485 | |
Alexander Duyck | 5eee87c | 2016-05-11 13:23:34 -0700 | [diff] [blame] | 10486 | netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID; |
| 10487 | netdev->hw_enc_features |= netdev->vlan_features; |
Scott Peterson | 2a20525 | 2016-11-18 11:25:42 -0800 | [diff] [blame] | 10488 | netdev->mpls_features |= NETIF_F_SG | |
| 10489 | NETIF_F_TSO | |
| 10490 | NETIF_F_TSO6 | |
| 10491 | NETIF_F_HW_CSUM; |
| 10492 | netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES; |
Alexander Duyck | 5eee87c | 2016-05-11 13:23:34 -0700 | [diff] [blame] | 10493 | |
Alexander Duyck | b83e301 | 2016-04-14 17:19:31 -0400 | [diff] [blame] | 10494 | /* set this bit last since it cannot be part of vlan_features */ |
| 10495 | netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | |
| 10496 | NETIF_F_HW_VLAN_CTAG_RX | |
| 10497 | NETIF_F_HW_VLAN_CTAG_TX; |
| 10498 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 10499 | netdev->priv_flags |= IFF_UNICAST_FLT; |
Ben Greear | f43f313 | 2012-03-06 09:42:04 +0000 | [diff] [blame] | 10500 | netdev->priv_flags |= IFF_SUPP_NOFCS; |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 10501 | |
Jarod Wilson | 91c527a | 2016-10-17 15:54:05 -0400 | [diff] [blame] | 10502 | /* MTU range: 68 - 9710 */ |
| 10503 | netdev->min_mtu = ETH_MIN_MTU; |
| 10504 | netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN); |
| 10505 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 10506 | #ifdef CONFIG_IXGBE_DCB |
Usha Ketineni | 8829009 | 2016-04-26 05:00:26 -0700 | [diff] [blame] | 10507 | if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE) |
Stephen Hemminger | 3f40c74 | 2016-11-21 09:52:40 -0800 | [diff] [blame] | 10508 | netdev->dcbnl_ops = &ixgbe_dcbnl_ops; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 10509 | #endif |
| 10510 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10511 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 10512 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10513 | unsigned int fcoe_l; |
| 10514 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10515 | if (hw->mac.ops.get_device_caps) { |
| 10516 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 10517 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 10518 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10519 | } |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 10520 | |
Alexander Duyck | d3cb986 | 2013-01-16 01:35:35 +0000 | [diff] [blame] | 10521 | |
| 10522 | fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus()); |
| 10523 | adapter->ring_feature[RING_F_FCOE].limit = fcoe_l; |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 10524 | |
Alexander Duyck | a58915c | 2012-05-25 06:38:18 +0000 | [diff] [blame] | 10525 | netdev->features |= NETIF_F_FSO | |
| 10526 | NETIF_F_FCOE_CRC; |
| 10527 | |
Alexander Duyck | 7c8ae65 | 2012-05-05 05:32:47 +0000 | [diff] [blame] | 10528 | netdev->vlan_features |= NETIF_F_FSO | |
| 10529 | NETIF_F_FCOE_CRC | |
| 10530 | NETIF_F_FCOE_MTU; |
Yi Zou | 5e09d7f | 2010-07-19 13:59:52 +0000 | [diff] [blame] | 10531 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 10532 | #endif /* IXGBE_FCOE */ |
Don Skidmore | 082757a | 2011-07-21 05:55:00 +0000 | [diff] [blame] | 10533 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
| 10534 | netdev->hw_features |= NETIF_F_LRO; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 10535 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 10536 | netdev->features |= NETIF_F_LRO; |
| 10537 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10538 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 10539 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10540 | e_dev_err("The EEPROM Checksum Is Not Valid\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10541 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 10542 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10543 | } |
| 10544 | |
Sowmini Varadhan | c7374b5 | 2016-01-12 19:32:30 -0800 | [diff] [blame] | 10545 | eth_platform_get_mac_address(&adapter->pdev->dev, |
| 10546 | adapter->hw.mac.perm_addr); |
Martin K Petersen | c762dff | 2014-11-15 14:24:51 +0000 | [diff] [blame] | 10547 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10548 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10549 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 10550 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10551 | e_dev_err("invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10552 | err = -EIO; |
Alexander Duyck | 35937c0 | 2012-02-08 07:51:37 +0000 | [diff] [blame] | 10553 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10554 | } |
| 10555 | |
Tushar Dave | 5676804 | 2016-01-07 14:17:03 -0800 | [diff] [blame] | 10556 | /* Set hw->mac.addr to permanent MAC address */ |
| 10557 | ether_addr_copy(hw->mac.addr, hw->mac.perm_addr); |
Alexander Duyck | c9f53e6 | 2015-10-22 16:26:30 -0700 | [diff] [blame] | 10558 | ixgbe_mac_set_default_filter(adapter); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10559 | |
Kees Cook | 26566ea | 2017-10-16 17:29:35 -0700 | [diff] [blame] | 10560 | timer_setup(&adapter->service_timer, ixgbe_service_timer, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10561 | |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10562 | if (ixgbe_removed(hw->hw_addr)) { |
| 10563 | err = -EIO; |
| 10564 | goto err_sw_init; |
| 10565 | } |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10566 | INIT_WORK(&adapter->service_task, ixgbe_service_task); |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10567 | set_bit(__IXGBE_SERVICE_INITED, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10568 | clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10569 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10570 | err = ixgbe_init_interrupt_scheme(adapter); |
| 10571 | if (err) |
| 10572 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10573 | |
Liwei Song | b09457e | 2016-12-04 22:40:44 -0500 | [diff] [blame] | 10574 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 10575 | u64_stats_init(&adapter->rx_ring[i]->syncp); |
| 10576 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 10577 | u64_stats_init(&adapter->tx_ring[i]->syncp); |
John Fastabend | 33fdc82 | 2017-04-24 03:30:18 -0700 | [diff] [blame] | 10578 | for (i = 0; i < adapter->num_xdp_queues; i++) |
| 10579 | u64_stats_init(&adapter->xdp_ring[i]->syncp); |
| 10580 | |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10581 | /* WOL not supported for all devices */ |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 10582 | adapter->wol = 0; |
Jacob Keller | 8e2813f | 2012-04-21 06:05:40 +0000 | [diff] [blame] | 10583 | hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 10584 | hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device, |
Don Skidmore | b8f8363 | 2013-02-28 08:08:44 +0000 | [diff] [blame] | 10585 | pdev->subsystem_device); |
Jacob Keller | 6b92b0b | 2013-04-13 05:40:37 +0000 | [diff] [blame] | 10586 | if (hw->wol_enabled) |
Andy Gospodarek | 9417c46 | 2011-07-16 07:31:33 +0000 | [diff] [blame] | 10587 | adapter->wol = IXGBE_WUFC_MAG; |
Emil Tantilov | c23f5b6 | 2011-08-16 07:34:18 +0000 | [diff] [blame] | 10588 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 10589 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 10590 | |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 10591 | /* save off EEPROM version number */ |
Paul Greenwalt | 73834ae | 2017-10-27 10:32:40 -0400 | [diff] [blame] | 10592 | ixgbe_set_fw_version(adapter); |
Emil Tantilov | 15e5209 | 2011-09-29 05:01:29 +0000 | [diff] [blame] | 10593 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 10594 | /* pick up the PCI bus settings for reporting later */ |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10595 | if (ixgbe_pcie_from_parent(hw)) |
Jacob Keller | b8e8200 | 2013-04-09 07:20:09 +0000 | [diff] [blame] | 10596 | ixgbe_get_parent_bus_info(adapter); |
Don Skidmore | f9328bc | 2015-06-18 13:24:06 -0400 | [diff] [blame] | 10597 | else |
| 10598 | hw->mac.ops.get_bus_info(hw); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 10599 | |
Jacob Keller | e027d1a | 2013-07-31 06:53:31 +0000 | [diff] [blame] | 10600 | /* calculate the expected PCIe bandwidth required for optimal |
| 10601 | * performance. Note that some older parts will never have enough |
| 10602 | * bandwidth due to being older generation PCIe parts. We clamp these |
| 10603 | * parts to ensure no warning is displayed if it can't be fixed. |
| 10604 | */ |
| 10605 | switch (hw->mac.type) { |
| 10606 | case ixgbe_mac_82598EB: |
| 10607 | expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16); |
| 10608 | break; |
| 10609 | default: |
| 10610 | expected_gts = ixgbe_enumerate_functions(adapter) * 10; |
| 10611 | break; |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 10612 | } |
Jacob Keller | caafb95 | 2014-07-19 07:17:17 +0000 | [diff] [blame] | 10613 | |
| 10614 | /* don't check link if we failed to enumerate functions */ |
| 10615 | if (expected_gts > 0) |
| 10616 | ixgbe_check_minimum_link(adapter, expected_gts); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 10617 | |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 10618 | err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 10619 | if (err) |
Mark Rustad | 339de30 | 2014-06-06 01:57:06 +0000 | [diff] [blame] | 10620 | strlcpy(part_str, "Unknown", sizeof(part_str)); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 10621 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 10622 | e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n", |
| 10623 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
Jacob Keller | e7cf745 | 2014-04-09 06:03:10 +0000 | [diff] [blame] | 10624 | part_str); |
Jacob Keller | 6a2aae5 | 2013-10-18 05:09:24 +0000 | [diff] [blame] | 10625 | else |
| 10626 | e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n", |
| 10627 | hw->mac.type, hw->phy.type, part_str); |
| 10628 | |
| 10629 | e_dev_info("%pM\n", netdev->dev_addr); |
| 10630 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10631 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10632 | err = hw->mac.ops.start_hw(hw); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10633 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 10634 | /* We are running on a pre-production device, log a warning */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10635 | e_dev_warn("This device is a pre-production adapter/LOM. " |
| 10636 | "Please be aware there may be issues associated " |
| 10637 | "with your hardware. If you are experiencing " |
| 10638 | "problems please contact your Intel or hardware " |
| 10639 | "representative who provided you with this " |
| 10640 | "hardware.\n"); |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 10641 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10642 | strcpy(netdev->name, "eth%d"); |
Jeff Mahoney | a09c0fc | 2017-06-03 18:01:17 -0400 | [diff] [blame] | 10643 | pci_set_drvdata(pdev, adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10644 | err = register_netdev(netdev); |
| 10645 | if (err) |
| 10646 | goto err_register; |
| 10647 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10648 | |
Emil Tantilov | ec74a47 | 2012-09-20 03:33:56 +0000 | [diff] [blame] | 10649 | /* power down the optics for 82599 SFP+ fiber */ |
| 10650 | if (hw->mac.ops.disable_tx_laser) |
Emil Tantilov | 93d3ce8 | 2011-10-19 07:59:55 +0000 | [diff] [blame] | 10651 | hw->mac.ops.disable_tx_laser(hw); |
| 10652 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 10653 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 10654 | netif_carrier_off(netdev); |
| 10655 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10656 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 10657 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10658 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10659 | ixgbe_setup_dca(adapter); |
| 10660 | } |
| 10661 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 10662 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10663 | 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] | 10664 | for (i = 0; i < adapter->num_vfs; i++) |
| 10665 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 10666 | } |
| 10667 | |
Jacob Keller | 2466dd9 | 2011-09-08 03:50:54 +0000 | [diff] [blame] | 10668 | /* firmware requires driver version to be 0xFFFFFFFF |
| 10669 | * since os does not support feature |
| 10670 | */ |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10671 | if (hw->mac.ops.set_fw_drv_ver) |
Tony Nguyen | cb8e051 | 2016-10-26 16:25:18 -0700 | [diff] [blame] | 10672 | hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF, |
| 10673 | sizeof(ixgbe_driver_version) - 1, |
| 10674 | ixgbe_driver_version); |
Emil Tantilov | 9612de9 | 2011-05-07 07:40:20 +0000 | [diff] [blame] | 10675 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10676 | /* add san mac addr to netdev */ |
| 10677 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10678 | |
Neerav Parikh | ea81875 | 2012-01-04 20:23:40 +0000 | [diff] [blame] | 10679 | e_dev_info("%s\n", ixgbe_default_device_descr); |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10680 | |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10681 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10682 | if (ixgbe_sysfs_init(adapter)) |
| 10683 | e_err(probe, "failed to allocate sysfs resources\n"); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10684 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10685 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10686 | ixgbe_dbg_adapter_init(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10687 | |
Emil Tantilov | d1a35ee | 2014-05-13 08:24:00 +0000 | [diff] [blame] | 10688 | /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */ |
| 10689 | if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link) |
Don Skidmore | 0b2679d | 2013-02-21 03:00:04 +0000 | [diff] [blame] | 10690 | hw->mac.ops.setup_link(hw, |
| 10691 | IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL, |
| 10692 | true); |
| 10693 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10694 | return 0; |
| 10695 | |
| 10696 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10697 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10698 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10699 | err_sw_init: |
Alexander Duyck | 99d7448 | 2012-05-09 08:09:25 +0000 | [diff] [blame] | 10700 | ixgbe_disable_sriov(adapter); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10701 | adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP; |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10702 | iounmap(adapter->io_addr); |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10703 | kfree(adapter->jump_tables[0]); |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10704 | kfree(adapter->mac_table); |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 10705 | kfree(adapter->rss_key); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10706 | err_ioremap: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10707 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10708 | free_netdev(netdev); |
| 10709 | err_alloc_etherdev: |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10710 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10711 | err_pci_reg: |
| 10712 | err_dma: |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10713 | if (!adapter || disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10714 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10715 | return err; |
| 10716 | } |
| 10717 | |
| 10718 | /** |
| 10719 | * ixgbe_remove - Device Removal Routine |
| 10720 | * @pdev: PCI device information struct |
| 10721 | * |
| 10722 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 10723 | * that it should release a PCI device. The could be caused by a |
| 10724 | * Hot-Plug event, or because the driver is going to be removed from |
| 10725 | * memory. |
| 10726 | **/ |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 10727 | static void ixgbe_remove(struct pci_dev *pdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10728 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10729 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10730 | struct net_device *netdev; |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10731 | bool disable_dev; |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10732 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10733 | |
Emil Tantilov | 0fb6a55 | 2014-12-04 03:03:38 +0000 | [diff] [blame] | 10734 | /* if !adapter then we already cleaned up in probe */ |
| 10735 | if (!adapter) |
| 10736 | return; |
| 10737 | |
| 10738 | netdev = adapter->netdev; |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10739 | ixgbe_dbg_adapter_exit(adapter); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 10740 | |
Mark Rustad | 09f40ae | 2014-01-14 18:53:11 -0800 | [diff] [blame] | 10741 | set_bit(__IXGBE_REMOVING, &adapter->state); |
Alexander Duyck | 7086400 | 2011-04-27 09:13:56 +0000 | [diff] [blame] | 10742 | cancel_work_sync(&adapter->service_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10743 | |
Jacob Keller | 3a6a4ed | 2012-05-01 05:24:58 +0000 | [diff] [blame] | 10744 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 10745 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10746 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 10747 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 10748 | dca_remove_requester(&pdev->dev); |
Mark Rustad | 9de7605 | 2015-08-08 16:27:41 -0700 | [diff] [blame] | 10749 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, |
| 10750 | IXGBE_DCA_CTRL_DCA_DISABLE); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 10751 | } |
| 10752 | |
| 10753 | #endif |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10754 | #ifdef CONFIG_IXGBE_HWMON |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10755 | ixgbe_sysfs_exit(adapter); |
Don Skidmore | 1210982 | 2012-05-04 06:07:08 +0000 | [diff] [blame] | 10756 | #endif /* CONFIG_IXGBE_HWMON */ |
Don Skidmore | 3ca8bc6 | 2012-04-12 00:33:31 +0000 | [diff] [blame] | 10757 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 10758 | /* remove the added san mac */ |
| 10759 | ixgbe_del_sanmac_netdev(netdev); |
| 10760 | |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10761 | #ifdef CONFIG_PCI_IOV |
Alex Williamson | 7837e28 | 2015-07-10 15:31:34 -0600 | [diff] [blame] | 10762 | ixgbe_disable_sriov(adapter); |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 10763 | #endif |
Alex Williamson | 6b010e9 | 2015-07-29 14:38:21 -0600 | [diff] [blame] | 10764 | if (netdev->reg_state == NETREG_REGISTERED) |
| 10765 | unregister_netdev(netdev); |
| 10766 | |
Shannon Nelson | 63a67fe | 2017-12-19 15:59:57 -0800 | [diff] [blame] | 10767 | ixgbe_stop_ipsec_offload(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 10768 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 10769 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10770 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10771 | |
Alexander Duyck | 2b1588c | 2012-03-17 02:39:16 +0000 | [diff] [blame] | 10772 | #ifdef CONFIG_DCB |
| 10773 | kfree(adapter->ixgbe_ieee_pfc); |
| 10774 | kfree(adapter->ixgbe_ieee_ets); |
| 10775 | |
| 10776 | #endif |
Mark Rustad | 2a1a091 | 2014-01-14 18:53:15 -0800 | [diff] [blame] | 10777 | iounmap(adapter->io_addr); |
Johannes Thumshirn | 56d766d | 2016-06-07 09:44:05 +0200 | [diff] [blame] | 10778 | pci_release_mem_regions(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10779 | |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10780 | e_dev_info("complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 10781 | |
Amritha Nambiar | 1cdaaf5 | 2016-04-14 19:08:53 -0400 | [diff] [blame] | 10782 | for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) { |
| 10783 | if (adapter->jump_tables[i]) { |
| 10784 | kfree(adapter->jump_tables[i]->input); |
| 10785 | kfree(adapter->jump_tables[i]->mask); |
| 10786 | } |
| 10787 | kfree(adapter->jump_tables[i]); |
| 10788 | } |
| 10789 | |
Jacob Keller | 5d7daa3 | 2014-03-29 06:51:25 +0000 | [diff] [blame] | 10790 | kfree(adapter->mac_table); |
Tony Nguyen | 3dfbfc7 | 2017-04-13 07:26:05 -0700 | [diff] [blame] | 10791 | kfree(adapter->rss_key); |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10792 | disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10793 | free_netdev(netdev); |
| 10794 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 10795 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10796 | |
Daniel Borkmann | b5b2ffc | 2014-11-21 23:52:53 -0800 | [diff] [blame] | 10797 | if (disable_dev) |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10798 | pci_disable_device(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10799 | } |
| 10800 | |
| 10801 | /** |
| 10802 | * ixgbe_io_error_detected - called when PCI error is detected |
| 10803 | * @pdev: Pointer to PCI device |
| 10804 | * @state: The current pci connection state |
| 10805 | * |
| 10806 | * This function is called after a PCI bus error affecting |
| 10807 | * this device has been detected. |
| 10808 | */ |
| 10809 | 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] | 10810 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10811 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10812 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10813 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10814 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10815 | #ifdef CONFIG_PCI_IOV |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10816 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10817 | struct pci_dev *bdev, *vfdev; |
| 10818 | u32 dw0, dw1, dw2, dw3; |
| 10819 | int vf, pos; |
| 10820 | u16 req_id, pf_func; |
| 10821 | |
| 10822 | if (adapter->hw.mac.type == ixgbe_mac_82598EB || |
| 10823 | adapter->num_vfs == 0) |
| 10824 | goto skip_bad_vf_detection; |
| 10825 | |
| 10826 | bdev = pdev->bus->self; |
Yijing Wang | 62f87c0 | 2012-07-24 17:20:03 +0800 | [diff] [blame] | 10827 | while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT)) |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10828 | bdev = bdev->bus->self; |
| 10829 | |
| 10830 | if (!bdev) |
| 10831 | goto skip_bad_vf_detection; |
| 10832 | |
| 10833 | pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR); |
| 10834 | if (!pos) |
| 10835 | goto skip_bad_vf_detection; |
| 10836 | |
Mark Rustad | 1443846 | 2014-02-28 15:48:57 -0800 | [diff] [blame] | 10837 | dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG); |
| 10838 | dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4); |
| 10839 | dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8); |
| 10840 | dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12); |
| 10841 | if (ixgbe_removed(hw->hw_addr)) |
| 10842 | goto skip_bad_vf_detection; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10843 | |
| 10844 | req_id = dw1 >> 16; |
| 10845 | /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */ |
| 10846 | if (!(req_id & 0x0080)) |
| 10847 | goto skip_bad_vf_detection; |
| 10848 | |
| 10849 | pf_func = req_id & 0x01; |
| 10850 | if ((pf_func & 1) == (pdev->devfn & 1)) { |
| 10851 | unsigned int device_id; |
| 10852 | |
| 10853 | vf = (req_id & 0x7F) >> 1; |
| 10854 | e_dev_err("VF %d has caused a PCIe error\n", vf); |
| 10855 | e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: " |
| 10856 | "%8.8x\tdw3: %8.8x\n", |
| 10857 | dw0, dw1, dw2, dw3); |
| 10858 | switch (adapter->hw.mac.type) { |
| 10859 | case ixgbe_mac_82599EB: |
| 10860 | device_id = IXGBE_82599_VF_DEVICE_ID; |
| 10861 | break; |
| 10862 | case ixgbe_mac_X540: |
| 10863 | device_id = IXGBE_X540_VF_DEVICE_ID; |
| 10864 | break; |
Don Skidmore | 9a75a1a | 2014-11-07 03:53:35 +0000 | [diff] [blame] | 10865 | case ixgbe_mac_X550: |
| 10866 | device_id = IXGBE_DEV_ID_X550_VF; |
| 10867 | break; |
| 10868 | case ixgbe_mac_X550EM_x: |
| 10869 | device_id = IXGBE_DEV_ID_X550EM_X_VF; |
| 10870 | break; |
Mark Rustad | 49425df | 2016-04-01 12:18:09 -0700 | [diff] [blame] | 10871 | case ixgbe_mac_x550em_a: |
| 10872 | device_id = IXGBE_DEV_ID_X550EM_A_VF; |
| 10873 | break; |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10874 | default: |
| 10875 | device_id = 0; |
| 10876 | break; |
| 10877 | } |
| 10878 | |
| 10879 | /* Find the pci device of the offending VF */ |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10880 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10881 | while (vfdev) { |
| 10882 | if (vfdev->devfn == (req_id & 0xFF)) |
| 10883 | break; |
Jon Mason | 36e9031 | 2012-07-19 21:02:09 +0000 | [diff] [blame] | 10884 | vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10885 | device_id, vfdev); |
| 10886 | } |
| 10887 | /* |
| 10888 | * There's a slim chance the VF could have been hot plugged, |
| 10889 | * so if it is no longer present we don't need to issue the |
| 10890 | * VFLR. Just clean up the AER in that case. |
| 10891 | */ |
| 10892 | if (vfdev) { |
Christoph Hellwig | 63af8f7 | 2017-04-14 21:11:28 +0200 | [diff] [blame] | 10893 | pcie_flr(vfdev); |
Greg Rose | b4fafbe | 2012-12-13 01:14:06 +0000 | [diff] [blame] | 10894 | /* Free device reference count */ |
| 10895 | pci_dev_put(vfdev); |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10896 | } |
| 10897 | |
| 10898 | pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10899 | } |
| 10900 | |
| 10901 | /* |
| 10902 | * Even though the error may have occurred on the other port |
| 10903 | * we still need to increment the vf error reference count for |
| 10904 | * both ports because the I/O resume function will be called |
| 10905 | * for both of them. |
| 10906 | */ |
| 10907 | adapter->vferr_refcount++; |
| 10908 | |
| 10909 | return PCI_ERS_RESULT_RECOVERED; |
| 10910 | |
| 10911 | skip_bad_vf_detection: |
| 10912 | #endif /* CONFIG_PCI_IOV */ |
Mark Rustad | 58cf663 | 2014-03-12 00:38:40 +0000 | [diff] [blame] | 10913 | if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state)) |
| 10914 | return PCI_ERS_RESULT_DISCONNECT; |
| 10915 | |
Emil Tantilov | b64666a | 2017-09-29 10:55:42 -0700 | [diff] [blame] | 10916 | if (!netif_device_present(netdev)) |
| 10917 | return PCI_ERS_RESULT_DISCONNECT; |
| 10918 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10919 | rtnl_lock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10920 | netif_device_detach(netdev); |
| 10921 | |
Mauro S M Rodrigues | b212d81 | 2018-05-02 17:26:28 -0300 | [diff] [blame] | 10922 | if (netif_running(netdev)) |
| 10923 | ixgbe_close_suspend(adapter); |
| 10924 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10925 | if (state == pci_channel_io_perm_failure) { |
| 10926 | rtnl_unlock(); |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10927 | return PCI_ERS_RESULT_DISCONNECT; |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10928 | } |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 10929 | |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10930 | if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) |
| 10931 | pci_disable_device(pdev); |
| 10932 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10933 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 10934 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10935 | return PCI_ERS_RESULT_NEED_RESET; |
| 10936 | } |
| 10937 | |
| 10938 | /** |
| 10939 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 10940 | * @pdev: Pointer to PCI device |
| 10941 | * |
| 10942 | * Restart the card from scratch, as if from a cold-boot. |
| 10943 | */ |
| 10944 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 10945 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10946 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10947 | pci_ers_result_t result; |
| 10948 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10949 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 10950 | if (pci_enable_device_mem(pdev)) { |
Emil Tantilov | 396e799 | 2010-07-01 20:05:12 +0000 | [diff] [blame] | 10951 | 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] | 10952 | result = PCI_ERS_RESULT_DISCONNECT; |
| 10953 | } else { |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 10954 | smp_mb__before_atomic(); |
Mark Rustad | 41c6284 | 2014-03-12 00:38:35 +0000 | [diff] [blame] | 10955 | clear_bit(__IXGBE_DISABLED, &adapter->state); |
Mark Rustad | 0391bbe | 2014-02-28 15:48:55 -0800 | [diff] [blame] | 10956 | adapter->hw.hw_addr = adapter->io_addr; |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10957 | pci_set_master(pdev); |
| 10958 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 10959 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10960 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 10961 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10962 | |
| 10963 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 10964 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10965 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10966 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10967 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10968 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10969 | if (err) { |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 10970 | e_dev_err("pci_cleanup_aer_uncorrect_error_status " |
| 10971 | "failed 0x%0x\n", err); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10972 | /* non-fatal, continue */ |
| 10973 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10974 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 10975 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10976 | } |
| 10977 | |
| 10978 | /** |
| 10979 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 10980 | * @pdev: Pointer to PCI device |
| 10981 | * |
| 10982 | * This callback is called when the error recovery driver tells us that |
| 10983 | * its OK to resume normal operation. |
| 10984 | */ |
| 10985 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 10986 | { |
Alexander Duyck | c60fbb0 | 2010-11-16 19:26:54 -0800 | [diff] [blame] | 10987 | struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); |
| 10988 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 10989 | |
Greg Rose | 83c61fa | 2011-09-07 05:59:35 +0000 | [diff] [blame] | 10990 | #ifdef CONFIG_PCI_IOV |
| 10991 | if (adapter->vferr_refcount) { |
| 10992 | e_info(drv, "Resuming after VF err\n"); |
| 10993 | adapter->vferr_refcount--; |
| 10994 | return; |
| 10995 | } |
| 10996 | |
| 10997 | #endif |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 10998 | rtnl_lock(); |
Alexander Duyck | c7ccde0 | 2011-07-21 00:40:40 +0000 | [diff] [blame] | 10999 | if (netif_running(netdev)) |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 11000 | ixgbe_open(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11001 | |
| 11002 | netif_device_attach(netdev); |
Emil Tantilov | 126db13 | 2016-11-16 09:48:02 -0800 | [diff] [blame] | 11003 | rtnl_unlock(); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11004 | } |
| 11005 | |
Stephen Hemminger | 3646f0e | 2012-09-07 09:33:15 -0700 | [diff] [blame] | 11006 | static const struct pci_error_handlers ixgbe_err_handler = { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11007 | .error_detected = ixgbe_io_error_detected, |
| 11008 | .slot_reset = ixgbe_io_slot_reset, |
| 11009 | .resume = ixgbe_io_resume, |
| 11010 | }; |
| 11011 | |
| 11012 | static struct pci_driver ixgbe_driver = { |
| 11013 | .name = ixgbe_driver_name, |
| 11014 | .id_table = ixgbe_pci_tbl, |
| 11015 | .probe = ixgbe_probe, |
Bill Pemberton | 9f9a12f | 2012-12-03 09:24:25 -0500 | [diff] [blame] | 11016 | .remove = ixgbe_remove, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11017 | #ifdef CONFIG_PM |
| 11018 | .suspend = ixgbe_suspend, |
| 11019 | .resume = ixgbe_resume, |
| 11020 | #endif |
| 11021 | .shutdown = ixgbe_shutdown, |
Greg Rose | da36b64 | 2012-12-11 08:26:43 +0000 | [diff] [blame] | 11022 | .sriov_configure = ixgbe_pci_sriov_configure, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11023 | .err_handler = &ixgbe_err_handler |
| 11024 | }; |
| 11025 | |
| 11026 | /** |
| 11027 | * ixgbe_init_module - Driver Registration Routine |
| 11028 | * |
| 11029 | * ixgbe_init_module is the first routine called when the driver is |
| 11030 | * loaded. All it does is register with the PCI subsystem. |
| 11031 | **/ |
| 11032 | static int __init ixgbe_init_module(void) |
| 11033 | { |
| 11034 | int ret; |
Joe Perches | c768957 | 2010-09-07 21:35:17 +0000 | [diff] [blame] | 11035 | pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version); |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 11036 | pr_info("%s\n", ixgbe_copyright); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11037 | |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 11038 | ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name); |
| 11039 | if (!ixgbe_wq) { |
| 11040 | pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name); |
| 11041 | return -ENOMEM; |
| 11042 | } |
| 11043 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11044 | ixgbe_dbg_init(); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11045 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11046 | ret = pci_register_driver(&ixgbe_driver); |
| 11047 | if (ret) { |
Wei Yongjun | 6b83687 | 2016-07-12 15:17:02 +0000 | [diff] [blame] | 11048 | destroy_workqueue(ixgbe_wq); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11049 | ixgbe_dbg_exit(); |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11050 | return ret; |
| 11051 | } |
| 11052 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11053 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11054 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11055 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11056 | |
Jakub Kicinski | f01fc1a | 2013-04-03 16:50:54 +0000 | [diff] [blame] | 11057 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11058 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 11059 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11060 | module_init(ixgbe_init_module); |
| 11061 | |
| 11062 | /** |
| 11063 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 11064 | * |
| 11065 | * ixgbe_exit_module is called just before the driver is removed |
| 11066 | * from memory. |
| 11067 | **/ |
| 11068 | static void __exit ixgbe_exit_module(void) |
| 11069 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11070 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11071 | dca_unregister_notify(&dca_notifier); |
| 11072 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11073 | pci_unregister_driver(&ixgbe_driver); |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11074 | |
Catherine Sullivan | 0094916 | 2012-08-10 01:59:10 +0000 | [diff] [blame] | 11075 | ixgbe_dbg_exit(); |
Mark Rustad | 780484d | 2015-10-21 17:21:10 -0700 | [diff] [blame] | 11076 | if (ixgbe_wq) { |
| 11077 | destroy_workqueue(ixgbe_wq); |
| 11078 | ixgbe_wq = NULL; |
| 11079 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11080 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11081 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 11082 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11083 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 11084 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11085 | { |
| 11086 | int ret_val; |
| 11087 | |
| 11088 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Joe Perches | e8e9f69 | 2010-09-07 21:34:53 +0000 | [diff] [blame] | 11089 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11090 | |
| 11091 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 11092 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 11093 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 11094 | #endif /* CONFIG_IXGBE_DCA */ |
Emil Tantilov | 849c454 | 2010-06-03 16:53:41 +0000 | [diff] [blame] | 11095 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 11096 | module_exit(ixgbe_exit_module); |
| 11097 | |
| 11098 | /* ixgbe_main.c */ |