blob: 8d061af276d348a2f5c0785157fb49504784a7ba [file] [log] [blame]
Jeff Kirsher51dce242018-04-26 08:08:09 -07001// SPDX-License-Identifier: GPL-2.0
2/* Copyright(c) 1999 - 2018 Intel Corporation. */
Auke Kok9a799d72007-09-15 14:07:45 -07003
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 Dobriyana6b7a402011-06-06 10:43:46 +000011#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070012#include <linux/ip.h>
13#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000014#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000015#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070016#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070018#include <net/checksum.h>
19#include <net/ip6_checksum.h>
Martin K Petersenc762dff2014-11-15 14:24:51 +000020#include <linux/etherdevice.h>
Auke Kok9a799d72007-09-15 14:07:45 -070021#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000022#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070023#include <linux/if_vlan.h>
John Fastabend2a47fa42013-11-06 09:54:52 -080024#include <linux/if_macvlan.h>
John Fastabend815cccb2012-10-24 08:13:09 +000025#include <linux/if_bridge.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040026#include <linux/prefetch.h>
John Fastabend92470802017-04-24 03:30:17 -070027#include <linux/bpf.h>
28#include <linux/bpf_trace.h>
29#include <linux/atomic.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000030#include <scsi/fc/fc_fcoe.h>
Alexander Duyckb3a49552016-06-16 12:22:19 -070031#include <net/udp_tunnel.h>
John Fastabendb82b17d2016-02-16 21:18:53 -080032#include <net/pkt_cls.h>
33#include <net/tc_act/tc_gact.h>
Sridhar Samudrala947f8a42016-04-05 10:39:07 -070034#include <net/tc_act/tc_mirred.h>
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -070035#include <net/vxlan.h>
Scott Peterson2a205252016-11-18 11:25:42 -080036#include <net/mpls.h>
Auke Kok9a799d72007-09-15 14:07:45 -070037
38#include "ixgbe.h"
39#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000040#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000041#include "ixgbe_sriov.h"
John Fastabendb82b17d2016-02-16 21:18:53 -080042#include "ixgbe_model.h"
Auke Kok9a799d72007-09-15 14:07:45 -070043
44char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070045static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000046 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000047#ifdef IXGBE_FCOE
Neerav Parikhea818752012-01-04 20:23:40 +000048char ixgbe_default_device_descr[] =
49 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher8af3c332012-02-18 07:08:14 +000050#else
51static char ixgbe_default_device_descr[] =
52 "Intel(R) 10 Gigabit Network Connection";
53#endif
Tony Nguyen01ec5522017-05-18 14:55:07 -070054#define DRV_VERSION "5.1.0-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070055const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000056static const char ixgbe_copyright[] =
Mark Rustad49425df2016-04-01 12:18:09 -070057 "Copyright (c) 1999-2016 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070058
Don Skidmoref44e7512015-06-09 16:36:23 -070059static 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 Kok9a799d72007-09-15 14:07:45 -070061static const struct ixgbe_info *ixgbe_info_tbl[] = {
Don Skidmore6a14ee02014-12-05 03:59:50 +000062 [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 Greenwalt8dc963e2017-04-13 08:07:07 -040067 [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info,
Mark Rustad49425df2016-04-01 12:18:09 -070068 [board_x550em_a] = &ixgbe_x550em_a_info,
Mark Rustadb3eb4e12016-12-14 11:02:16 -080069 [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
Auke Kok9a799d72007-09-15 14:07:45 -070070};
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 Taine9baa3c32014-08-08 15:56:03 +020080static const struct pci_device_id ixgbe_pci_tbl[] = {
Alexander Duyck54239c62011-07-15 03:06:06 +000081 {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 Skidmore8f583322013-07-27 06:25:38 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
joshua.a.hay@intel.comdf376f02012-09-21 00:08:21 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
Don Skidmore6a14ee02014-12-05 03:59:50 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
Mark Rustada711ad82016-03-21 11:21:31 -0700112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
Don Skidmore18e01ee2016-12-30 21:07:58 -0500114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
Don Skidmore6a14ee02014-12-05 03:59:50 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
Don Skidmorededa5622015-06-09 17:39:46 -0700116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
Mark Rustad018d7142015-08-08 16:19:19 -0700117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
Paul Greenwalt8dc963e2017-04-13 08:07:07 -0400118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw},
Mark Rustadf572b2c2016-04-01 12:18:46 -0700119 {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 Rustad49425df2016-04-01 12:18:09 -0700121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
Mark Rustad200157c2016-04-01 12:18:40 -0700122 {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 Skidmore92ed8432016-08-17 20:34:40 -0400124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
Mark Rustad2d40cd12016-04-01 12:18:35 -0700125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800126 {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 Kok9a799d72007-09-15 14:07:45 -0700128 /* required last entry */
129 {0, }
130};
131MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
132
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400133#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800134static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000135 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800136static struct notifier_block dca_notifier = {
137 .notifier_call = ixgbe_notify_dca,
138 .next = NULL,
139 .priority = 0
140};
141#endif
142
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000143#ifdef CONFIG_PCI_IOV
144static unsigned int max_vfs;
145module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000146MODULE_PARM_DESC(max_vfs,
Jacob Keller170e8542013-11-09 04:52:32 -0800147 "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000148#endif /* CONFIG_PCI_IOV */
149
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000150static unsigned int allow_unsupported_sfp;
151module_param(allow_unsupported_sfp, uint, 0);
152MODULE_PARM_DESC(allow_unsupported_sfp,
153 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
154
stephen hemmingerb3f4d592012-03-13 06:04:20 +0000155#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
156static int debug = -1;
157module_param(debug, int, 0);
158MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
159
Auke Kok9a799d72007-09-15 14:07:45 -0700160MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
161MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
162MODULE_LICENSE("GPL");
163MODULE_VERSION(DRV_VERSION);
164
Mark Rustad780484d2015-10-21 17:21:10 -0700165static struct workqueue_struct *ixgbe_wq;
166
Mark Rustad14438462014-02-28 15:48:57 -0800167static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
Mark Rustadb3eb4e12016-12-14 11:02:16 -0800168static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
Mark Rustad14438462014-02-28 15:48:57 -0800169
Alexander Duyck68ae7422017-11-22 10:56:52 -0800170static const struct net_device_ops ixgbe_netdev_ops;
171
172static bool netif_is_ixgbe(struct net_device *dev)
173{
174 return dev && (dev->netdev_ops == &ixgbe_netdev_ops);
175}
176
Jacob Kellerb8e82002013-04-09 07:20:09 +0000177static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
178 u32 reg, u16 *value)
179{
Jacob Kellerb8e82002013-04-09 07:20:09 +0000180 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 Wangc0798ed2013-09-04 17:30:08 +0000191 if (!pci_is_pcie(parent_dev))
Jacob Kellerb8e82002013-04-09 07:20:09 +0000192 return -1;
193
Yijing Wangc0798ed2013-09-04 17:30:08 +0000194 pcie_capability_read_word(parent_dev, reg, value);
Mark Rustad14438462014-02-28 15:48:57 -0800195 if (*value == IXGBE_FAILED_READ_CFG_WORD &&
196 ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
197 return -1;
Jacob Kellerb8e82002013-04-09 07:20:09 +0000198 return 0;
199}
200
201static 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 Kellere027d1a2013-07-31 06:53:31 +0000224/**
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 */
233static 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 Skidmore8f583322013-07-27 06:25:38 +0000237 case IXGBE_DEV_ID_82599_QSFP_SF_QP:
Jacob Kellere027d1a2013-07-31 06:53:31 +0000238 return true;
239 default:
240 return false;
241 }
242}
243
244static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
245 int expected_gts)
246{
Don Skidmoref9328bc2015-06-18 13:24:06 -0400247 struct ixgbe_hw *hw = &adapter->hw;
Jacob Kellere027d1a2013-07-31 06:53:31 +0000248 struct pci_dev *pdev;
249
Don Skidmoref9328bc2015-06-18 13:24:06 -0400250 /* 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 Keller56d13922015-06-10 11:44:45 -0700257 /* determine whether to use the parent device */
Jacob Kellere027d1a2013-07-31 06:53:31 +0000258 if (ixgbe_pcie_from_parent(&adapter->hw))
259 pdev = adapter->pdev->bus->parent->self;
260 else
261 pdev = adapter->pdev;
262
Bjorn Helgaas4695ca92018-03-30 14:26:07 -0500263 pcie_print_link_status(pdev);
Jacob Kellere027d1a2013-07-31 06:53:31 +0000264}
265
Alexander Duyck70864002011-04-27 09:13:56 +0000266static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
267{
268 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
Mark Rustad09f40ae2014-01-14 18:53:11 -0800269 !test_bit(__IXGBE_REMOVING, &adapter->state) &&
Alexander Duyck70864002011-04-27 09:13:56 +0000270 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
Mark Rustad780484d2015-10-21 17:21:10 -0700271 queue_work(ixgbe_wq, &adapter->service_task);
Alexander Duyck70864002011-04-27 09:13:56 +0000272}
273
Mark Rustad2a1a0912014-01-14 18:53:15 -0800274static 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 Rustad58cf6632014-03-12 00:38:40 +0000282 if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
283 ixgbe_service_event_schedule(adapter);
Mark Rustad2a1a0912014-01-14 18:53:15 -0800284}
285
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400286static u32 ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
Mark Rustad2a1a0912014-01-14 18:53:15 -0800287{
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400288 u8 __iomem *reg_addr;
Mark Rustad2a1a0912014-01-14 18:53:15 -0800289 u32 value;
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400290 int i;
Mark Rustad2a1a0912014-01-14 18:53:15 -0800291
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400292 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 Rustad2a1a0912014-01-14 18:53:15 -0800299 */
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400300 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 Rustad2a1a0912014-01-14 18:53:15 -0800305 }
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400306
Mark Rustad2a1a0912014-01-14 18:53:15 -0800307 if (value == IXGBE_FAILED_READ_REG)
308 ixgbe_remove_adapter(hw);
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400309 else
310 value = readl(reg_addr + reg);
311 return value;
Mark Rustad2a1a0912014-01-14 18:53:15 -0800312}
313
Mark Rustadf8e24722014-03-18 07:03:40 +0000314/**
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 */
327u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
328{
Mark Rutland6aa7de02017-10-23 14:07:29 -0700329 u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
Mark Rustadf8e24722014-03-18 07:03:40 +0000330 u32 value;
331
332 if (ixgbe_removed(reg_addr))
333 return IXGBE_FAILED_READ_REG;
Mark Rustad2f2219b2016-04-07 10:43:50 -0700334 if (unlikely(hw->phy.nw_mng_if_sel &
Tony Nguyen48301cf2017-06-07 14:36:19 -0700335 IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) {
Mark Rustad2f2219b2016-04-07 10:43:50 -0700336 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
354writes_completed:
Mark Rustadf8e24722014-03-18 07:03:40 +0000355 value = readl(reg_addr + reg);
356 if (unlikely(value == IXGBE_FAILED_READ_REG))
Paul Greenwalt1aa37842018-03-12 09:22:55 -0400357 value = ixgbe_check_remove(hw, reg);
Mark Rustadf8e24722014-03-18 07:03:40 +0000358 return value;
359}
360
Mark Rustad14438462014-02-28 15:48:57 -0800361static 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
373u16 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
388static 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 Kellered192312014-02-22 01:23:53 +0000403void 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 Duyck70864002011-04-27 09:13:56 +0000412static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
413{
414 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
415
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000416 /* flush memory to make sure state is correct before next watchdog */
Peter Zijlstra4e857c52014-03-17 18:06:10 +0100417 smp_mb__before_atomic();
Alexander Duyck70864002011-04-27 09:13:56 +0000418 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
419}
420
Taku Izumidcd79ae2010-04-27 14:39:53 +0000421struct ixgbe_reg_info {
422 u32 ofs;
423 char *name;
424};
425
426static 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 Rustadca8dfe22014-07-24 06:19:24 +0000455 { .name = NULL }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456};
457
458
459/*
460 * ixgbe_regdump - register printout routine
461 */
462static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
463{
Joe Perches332f2352017-01-03 07:28:11 -0800464 int i;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000465 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 Perches332f2352017-01-03 07:28:11 -0800526 pr_info("%-15s %08x\n",
527 reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000528 return;
529 }
530
Joe Perches332f2352017-01-03 07:28:11 -0800531 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 Izumidcd79ae2010-04-27 14:39:53 +0000538 for (j = 0; j < 8; j++)
Joe Perches332f2352017-01-03 07:28:11 -0800539 p += sprintf(p, " %08x", regs[i++]);
540 pr_err("%-15s%s\n", rname, buf);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000541 }
542
543}
544
John Fastabend33fdc822017-04-24 03:30:18 -0700545static 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 Izumidcd79ae2010-04-27 14:39:53 +0000558/*
559 * ixgbe_dump - Print registers, tx-rings and rx-rings
560 */
561static 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 Fastabend33fdc822017-04-24 03:30:18 -0700567 struct ixgbe_ring *ring;
Alexander Duyck729739b2012-02-08 07:51:06 +0000568 struct ixgbe_tx_buffer *tx_buffer;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000569 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 Izumidcd79ae2010-04-27 14:39:53 +0000574 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 Perchesc7689572010-09-07 21:35:17 +0000582 pr_info("Device Name state "
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100583 "trans_start\n");
584 pr_info("%-15s %016lX %016lX\n",
Joe Perchesc7689572010-09-07 21:35:17 +0000585 netdev->name,
586 netdev->state,
Tobias Klauser4a7c9722017-01-18 17:45:01 +0100587 dev_trans_start(netdev));
Taku Izumidcd79ae2010-04-27 14:39:53 +0000588 }
589
590 /* Print Registers */
591 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000592 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000593 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 Rustade90dd262014-07-22 06:51:08 +0000600 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000601
602 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000603 pr_info(" %s %s %s %s\n",
604 "Queue [NTU] [NTC] [bi(ntc)->dma ]",
605 "leng", "ntw", "timestamp");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000606 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700607 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 Izumidcd79ae2010-04-27 14:39:53 +0000614 }
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 Hay39ac8682012-09-26 05:59:36 +0000624 * 82598 Advanced Transmit Descriptor
Taku Izumidcd79ae2010-04-27 14:39:53 +0000625 * +--------------------------------------------------------------+
626 * 0 | Buffer Address [63:0] |
627 * +--------------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000628 * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000629 * +--------------------------------------------------------------+
630 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000631 *
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 Izumidcd79ae2010-04-27 14:39:53 +0000655 */
656
657 for (n = 0; n < adapter->num_tx_queues; n++) {
John Fastabend33fdc822017-04-24 03:30:18 -0700658 ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000659 pr_info("------------------------------------\n");
John Fastabend33fdc822017-04-24 03:30:18 -0700660 pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
Joe Perchesc7689572010-09-07 21:35:17 +0000661 pr_info("------------------------------------\n");
Josh Hay8ad88e32012-09-26 05:59:41 +0000662 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 Izumidcd79ae2010-04-27 14:39:53 +0000666
John Fastabend33fdc822017-04-24 03:30:18 -0700667 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 Izumidcd79ae2010-04-27 14:39:53 +0000670 u0 = (struct my_u0 *)tx_desc;
Josh Hay8ad88e32012-09-26 05:59:41 +0000671 if (dma_unmap_len(tx_buffer, len) > 0) {
Joe Perches332f2352017-01-03 07:28:11 -0800672 const char *ring_desc;
673
John Fastabend33fdc822017-04-24 03:30:18 -0700674 if (i == ring->next_to_use &&
675 i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800676 ring_desc = " NTC/U";
John Fastabend33fdc822017-04-24 03:30:18 -0700677 else if (i == ring->next_to_use)
Joe Perches332f2352017-01-03 07:28:11 -0800678 ring_desc = " NTU";
John Fastabend33fdc822017-04-24 03:30:18 -0700679 else if (i == ring->next_to_clean)
Joe Perches332f2352017-01-03 07:28:11 -0800680 ring_desc = " NTC";
681 else
682 ring_desc = "";
683 pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
Josh Hay8ad88e32012-09-26 05:59:41 +0000684 i,
Cathy Zhou9cfbfa72018-04-13 11:28:37 -0700685 le64_to_cpu((__force __le64)u0->a),
686 le64_to_cpu((__force __le64)u0->b),
Josh Hay8ad88e32012-09-26 05:59:41 +0000687 (u64)dma_unmap_addr(tx_buffer, dma),
Alexander Duyck729739b2012-02-08 07:51:06 +0000688 dma_unmap_len(tx_buffer, len),
Josh Hay8ad88e32012-09-26 05:59:41 +0000689 tx_buffer->next_to_watch,
690 (u64)tx_buffer->time_stamp,
Joe Perches332f2352017-01-03 07:28:11 -0800691 tx_buffer->skb,
692 ring_desc);
Josh Hay8ad88e32012-09-26 05:59:41 +0000693
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 Izumidcd79ae2010-04-27 14:39:53 +0000702 }
703 }
704
705 /* Print RX Rings Summary */
706rx_ring_summary:
707 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000708 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000709 for (n = 0; n < adapter->num_rx_queues; n++) {
710 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000711 pr_info("%5d %5X %5X\n",
712 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000713 }
714
715 /* Print RX Rings */
716 if (!netif_msg_rx_status(adapter))
Mark Rustade90dd262014-07-22 06:51:08 +0000717 return;
Taku Izumidcd79ae2010-04-27 14:39:53 +0000718
719 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
720
Josh Hay39ac8682012-09-26 05:59:36 +0000721 /* Receive Descriptor Formats
722 *
723 * 82598 Advanced Receive Descriptor (Read) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000724 * 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 Hay39ac8682012-09-26 05:59:36 +0000732 * 82598 Advanced Receive Descriptor (Write-Back) Format
Taku Izumidcd79ae2010-04-27 14:39:53 +0000733 *
734 * 63 48 47 32 31 30 21 20 16 15 4 3 0
735 * +------------------------------------------------------+
Josh Hay39ac8682012-09-26 05:59:36 +0000736 * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
737 * | Packet | IP | | | | Type | Type |
738 * | Checksum | Ident | | | | | |
Taku Izumidcd79ae2010-04-27 14:39:53 +0000739 * +------------------------------------------------------+
740 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
741 * +------------------------------------------------------+
742 * 63 48 47 32 31 20 19 0
Josh Hay39ac8682012-09-26 05:59:36 +0000743 *
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 Izumidcd79ae2010-04-27 14:39:53 +0000764 */
Josh Hay39ac8682012-09-26 05:59:36 +0000765
Taku Izumidcd79ae2010-04-27 14:39:53 +0000766 for (n = 0; n < adapter->num_rx_queues; n++) {
767 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000768 pr_info("------------------------------------\n");
769 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
770 pr_info("------------------------------------\n");
Joe Perches332f2352017-01-03 07:28:11 -0800771 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000772 "R [desc] [ PktBuf A0] ",
773 "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800774 "<-- Adv Rx Read format");
775 pr_info("%s%s%s\n",
Josh Hay8ad88e32012-09-26 05:59:41 +0000776 "RWB[desc] [PcsmIpSHl PtRs] ",
777 "[vl er S cks ln] ---------------- [bi->skb ] ",
Joe Perches332f2352017-01-03 07:28:11 -0800778 "<-- Adv Rx Write-Back format");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000779
780 for (i = 0; i < rx_ring->count; i++) {
Joe Perches332f2352017-01-03 07:28:11 -0800781 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 Izumidcd79ae2010-04-27 14:39:53 +0000790 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000791 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000792 u0 = (struct my_u0 *)rx_desc;
Alexander Duyck18a8cc92017-03-02 15:01:36 -0800793 if (rx_desc->wb.upper.length) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000794 /* Descriptor Done */
Joe Perches332f2352017-01-03 07:28:11 -0800795 pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
796 i,
Cathy Zhou9cfbfa72018-04-13 11:28:37 -0700797 le64_to_cpu((__force __le64)u0->a),
798 le64_to_cpu((__force __le64)u0->b),
Joe Perches332f2352017-01-03 07:28:11 -0800799 rx_buffer_info->skb,
800 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000801 } else {
Joe Perches332f2352017-01-03 07:28:11 -0800802 pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
803 i,
Cathy Zhou9cfbfa72018-04-13 11:28:37 -0700804 le64_to_cpu((__force __le64)u0->a),
805 le64_to_cpu((__force __le64)u0->b),
Taku Izumidcd79ae2010-04-27 14:39:53 +0000806 (u64)rx_buffer_info->dma,
Joe Perches332f2352017-01-03 07:28:11 -0800807 rx_buffer_info->skb,
808 ring_desc);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000809
Emil Tantilov9c50c032012-07-26 01:21:24 +0000810 if (netif_msg_pktdata(adapter) &&
811 rx_buffer_info->dma) {
Taku Izumidcd79ae2010-04-27 14:39:53 +0000812 print_hex_dump(KERN_INFO, "",
813 DUMP_PREFIX_ADDRESS, 16, 1,
Emil Tantilov9c50c032012-07-26 01:21:24 +0000814 page_address(rx_buffer_info->page) +
815 rx_buffer_info->page_offset,
Alexander Duyckf8003262012-03-03 02:35:52 +0000816 ixgbe_rx_bufsz(rx_ring), true);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000817 }
818 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000819 }
820 }
Taku Izumidcd79ae2010-04-27 14:39:53 +0000821}
822
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800823static 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 Perchese8e9f692010-09-07 21:34:53 +0000830 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800831}
832
833static 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 Perchese8e9f692010-09-07 21:34:53 +0000840 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800841}
Auke Kok9a799d72007-09-15 14:07:45 -0700842
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000843/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000844 * 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 */
851static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000852 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700853{
854 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000855 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 Skidmoreb93a2222010-11-16 19:27:17 -0800868 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000869 case ixgbe_mac_X550:
870 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700871 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000872 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 Kok9a799d72007-09-15 14:07:45 -0700894}
895
Alexander Duyckfe49f042009-06-04 16:00:09 +0000896static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000897 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000898{
899 u32 mask;
900
Alexander Duyckbd508172010-11-16 19:27:03 -0800901 switch (adapter->hw.mac.type) {
902 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000903 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
904 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800905 break;
906 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800907 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +0000908 case ixgbe_mac_X550:
909 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -0700910 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000911 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 Duyckbd508172010-11-16 19:27:03 -0800915 break;
916 default:
917 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000918 }
919}
920
Alexander Duyck943561d2012-05-09 22:14:44 -0700921static 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 Fastabend33fdc822017-04-24 03:30:18 -0700948
949 for (i = 0; i < adapter->num_xdp_queues; i++)
950 clear_bit(__IXGBE_HANG_CHECK_ARMED,
951 &adapter->xdp_ring[i]->state);
Alexander Duyck943561d2012-05-09 22:14:44 -0700952}
953
John Fastabendc84d3242010-11-16 19:27:12 -0800954static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700955{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700956 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800957 struct ixgbe_hw_stats *hwstats = &adapter->stats;
John Fastabendc84d3242010-11-16 19:27:12 -0800958 u32 xoff[8] = {0};
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000959 u8 tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800960 int i;
Alexander Duyck943561d2012-05-09 22:14:44 -0700961 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700962
Alexander Duyck943561d2012-05-09 22:14:44 -0700963 if (adapter->ixgbe_ieee_pfc)
964 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
John Fastabendc84d3242010-11-16 19:27:12 -0800965
Alexander Duyck943561d2012-05-09 22:14:44 -0700966 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
967 ixgbe_update_xoff_rx_lfc(adapter);
John Fastabendc84d3242010-11-16 19:27:12 -0800968 return;
Alexander Duyck943561d2012-05-09 22:14:44 -0700969 }
John Fastabendc84d3242010-11-16 19:27:12 -0800970
971 /* update stats for each tc, only valid with PFC enabled */
972 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000973 u32 pxoffrxc;
974
John Fastabendc84d3242010-11-16 19:27:12 -0800975 switch (hw->mac.type) {
976 case ixgbe_mac_82598EB:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000977 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800978 break;
979 default:
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000980 pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
John Fastabendc84d3242010-11-16 19:27:12 -0800981 }
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000982 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 Kok9a799d72007-09-15 14:07:45 -0700986 }
987
John Fastabendc84d3242010-11-16 19:27:12 -0800988 /* 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 Fastabendc84d3242010-11-16 19:27:12 -0800991
Parikh, Neerav2afaa002012-09-27 12:02:22 +0000992 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800993 if (xoff[tc])
994 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
995 }
John Fastabend33fdc822017-04-24 03:30:18 -0700996
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 Fastabendc84d3242010-11-16 19:27:12 -08001004}
1005
1006static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
1007{
Alexander Duyck7d7ce682012-02-08 07:50:51 +00001008 return ring->stats.packets;
John Fastabendc84d3242010-11-16 19:27:12 -08001009}
1010
1011static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
1012{
Alexander Duyck14895422017-11-22 10:56:46 -08001013 unsigned int head, tail;
John Fastabendc84d3242010-11-16 19:27:12 -08001014
Alexander Duyck14895422017-11-22 10:56:46 -08001015 head = ring->next_to_clean;
1016 tail = ring->next_to_use;
John Fastabend2a47fa42013-11-06 09:54:52 -08001017
Alexander Duyck14895422017-11-22 10:56:46 -08001018 return ((head <= tail) ? tail : tail + ring->count) - head;
John Fastabendc84d3242010-11-16 19:27:12 -08001019}
1020
1021static 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 Fastabendc84d3242010-11-16 19:27:12 -08001026
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 Rustade90dd262014-07-22 06:51:08 +00001041 if (tx_done_old == tx_done && tx_pending)
John Fastabendc84d3242010-11-16 19:27:12 -08001042 /* make sure it is true for two checks in a row */
Mark Rustade90dd262014-07-22 06:51:08 +00001043 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 Fastabendc84d3242010-11-16 19:27:12 -08001049
Mark Rustade90dd262014-07-22 06:51:08 +00001050 return false;
Auke Kok9a799d72007-09-15 14:07:45 -07001051}
1052
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001053/**
1054 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
1055 * @adapter: driver private struct
1056 **/
1057static 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 Tantilov57ca2a42016-07-29 14:46:31 -07001062 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Jacob Keller12ff3f32012-12-01 07:57:17 +00001063 e_warn(drv, "initiating reset due to tx timeout\n");
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00001064 ixgbe_service_event_schedule(adapter);
1065 }
1066}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001067
Auke Kok9a799d72007-09-15 14:07:45 -07001068/**
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001069 * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
Tony Nguyen5ba643c2017-12-04 11:28:30 -08001070 * @netdev: network interface device structure
1071 * @queue_index: Tx queue to set
1072 * @maxrate: desired maximum transmit bitrate
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +00001073 **/
1074static 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 Kok9a799d72007-09-15 14:07:45 -07001102 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +00001103 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07001104 * @tx_ring: tx ring to clean
Alexander Duyck8220bbc2016-03-07 09:30:09 -08001105 * @napi_budget: Used to determine if we are in netpoll
Auke Kok9a799d72007-09-15 14:07:45 -07001106 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +00001107static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Jesper Dangaard Brouera3a87492016-02-08 13:15:09 +01001108 struct ixgbe_ring *tx_ring, int napi_budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001109{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001110 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001111 struct ixgbe_tx_buffer *tx_buffer;
1112 union ixgbe_adv_tx_desc *tx_desc;
Shannon Nelsona8a43fd2017-12-19 16:00:01 -08001113 unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0;
Alexander Duyck59224552011-08-31 00:01:06 +00001114 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyck729739b2012-02-08 07:51:06 +00001115 unsigned int i = tx_ring->next_to_clean;
1116
1117 if (test_bit(__IXGBE_DOWN, &adapter->state))
1118 return true;
Auke Kok9a799d72007-09-15 14:07:45 -07001119
Alexander Duyckd3d00232011-07-15 02:31:25 +00001120 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +00001121 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyck729739b2012-02-08 07:51:06 +00001122 i -= tx_ring->count;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08001123
Alexander Duyck729739b2012-02-08 07:51:06 +00001124 do {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001125 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -07001126
Alexander Duyckd3d00232011-07-15 02:31:25 +00001127 /* if next_to_watch is not set then there is no work pending */
1128 if (!eop_desc)
1129 break;
1130
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001131 /* prevent any other reads prior to eop_desc */
Brian King0a9a17e2017-11-17 11:05:43 -06001132 smp_rmb();
Alexander Duyck7f83a9e2012-02-08 07:49:23 +00001133
Alexander Duyckd3d00232011-07-15 02:31:25 +00001134 /* 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 Duyckd3d00232011-07-15 02:31:25 +00001138 /* clear next_to_watch to prevent false hangs */
1139 tx_buffer->next_to_watch = NULL;
1140
Alexander Duyck091a6242012-02-08 07:51:01 +00001141 /* update the statistics for this packet */
1142 total_bytes += tx_buffer->bytecount;
1143 total_packets += tx_buffer->gso_segs;
Shannon Nelsona8a43fd2017-12-19 16:00:01 -08001144 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC)
1145 total_ipsec++;
Alexander Duyck091a6242012-02-08 07:51:01 +00001146
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001147 /* free the skb */
John Fastabend33fdc822017-04-24 03:30:18 -07001148 if (ring_is_xdp(tx_ring))
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02001149 xdp_return_frame(tx_buffer->xdpf);
John Fastabend33fdc822017-04-24 03:30:18 -07001150 else
1151 napi_consume_skb(tx_buffer->skb, napi_budget);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001152
Alexander Duyck729739b2012-02-08 07:51:06 +00001153 /* 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 Duyckfd0db0e2012-02-08 07:50:56 +00001159 /* clear tx_buffer data */
Alexander Duyck729739b2012-02-08 07:51:06 +00001160 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00001161
Alexander Duyck729739b2012-02-08 07:51:06 +00001162 /* unmap remaining buffers */
1163 while (tx_desc != eop_desc) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00001164 tx_buffer++;
1165 tx_desc++;
1166 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00001167 if (unlikely(!i)) {
1168 i -= tx_ring->count;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001169 tx_buffer = tx_ring->tx_buffer_info;
Alexander Duycke4f74022012-01-31 02:59:44 +00001170 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00001171 }
1172
Alexander Duyck729739b2012-02-08 07:51:06 +00001173 /* 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 Jr12207e42009-02-06 21:47:24 -08001182
Alexander Duyck729739b2012-02-08 07:51:06 +00001183 /* 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 Kok9a799d72007-09-15 14:07:45 -07001201 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001202 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -08001203 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +00001204 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +00001205 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001206 q_vector->tx.total_bytes += total_bytes;
1207 q_vector->tx.total_packets += total_packets;
Shannon Nelsona8a43fd2017-12-19 16:00:01 -08001208 adapter->tx_ipsec += total_ipsec;
Alexander Duyckb9537992010-11-16 19:26:58 -08001209
John Fastabendc84d3242010-11-16 19:27:12 -08001210 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -08001211 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -08001212 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend33fdc822017-04-24 03:30:18 -07001213 e_err(drv, "Detected Tx Unit Hang %s\n"
John Fastabendc84d3242010-11-16 19:27:12 -08001214 " 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 Fastabend33fdc822017-04-24 03:30:18 -07001221 ring_is_xdp(tx_ring) ? "(XDP)" : "",
John Fastabendc84d3242010-11-16 19:27:12 -08001222 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 Duyckd3d00232011-07-15 02:31:25 +00001225 tx_ring->next_to_use, i,
1226 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -08001227
John Fastabend33fdc822017-04-24 03:30:18 -07001228 if (!ring_is_xdp(tx_ring))
1229 netif_stop_subqueue(tx_ring->netdev,
1230 tx_ring->queue_index);
John Fastabendc84d3242010-11-16 19:27:12 -08001231
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 Duyckc83c6cb2011-04-27 09:21:16 +00001237 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -08001238
1239 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +00001240 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -08001241 }
Auke Kok9a799d72007-09-15 14:07:45 -07001242
John Fastabend33fdc822017-04-24 03:30:18 -07001243 if (ring_is_xdp(tx_ring))
1244 return !!budget;
1245
Alexander Duyckb2d96e02012-02-07 08:14:33 +00001246 netdev_tx_completed_queue(txring_txq(tx_ring),
1247 total_packets, total_bytes);
1248
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001249#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +00001250 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001251 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001252 /* Make sure that anybody stopping the queue after this
1253 * sees the new next_to_clean.
1254 */
1255 smp_mb();
Alexander Duyck729739b2012-02-08 07:51:06 +00001256 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 Duyck5b7da512010-11-16 19:26:50 -08001261 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08001262 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08001263 }
Auke Kok9a799d72007-09-15 14:07:45 -07001264
Alexander Duyck59224552011-08-31 00:01:06 +00001265 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001266}
1267
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001268#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001269static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001270 struct ixgbe_ring *tx_ring,
1271 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001272{
Don Skidmoreee5f7842009-11-06 12:56:20 +00001273 struct ixgbe_hw *hw = &adapter->hw;
Mark Rustad9de76052015-08-08 16:27:41 -07001274 u32 txctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001275 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001276
Mark Rustad9de76052015-08-08 16:27:41 -07001277 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1278 txctrl = dca3_get_tag(tx_ring->dev, cpu);
1279
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001280 switch (hw->mac.type) {
1281 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001282 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001283 break;
1284 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001285 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001286 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
1306static 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 Rustad9de76052015-08-08 16:27:41 -07001311 u32 rxctrl = 0;
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001312 u8 reg_idx = rx_ring->reg_idx;
1313
Mark Rustad9de76052015-08-08 16:27:41 -07001314 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1315 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001316
1317 switch (hw->mac.type) {
1318 case ixgbe_mac_82599EB:
1319 case ixgbe_mac_X540:
1320 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001321 break;
1322 default:
1323 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001324 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001325
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 Rustad9de76052015-08-08 16:27:41 -07001332 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001333 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
1334
1335 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001336}
1337
1338static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1339{
1340 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001341 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001342 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001343
1344 if (q_vector->cpu == cpu)
1345 goto out_no_update;
1346
Alexander Duycka5579282012-02-08 07:50:04 +00001347 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001348 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001349
Alexander Duycka5579282012-02-08 07:50:04 +00001350 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001351 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001352
1353 q_vector->cpu = cpu;
1354out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001355 put_cpu();
1356}
1357
1358static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1359{
1360 int i;
1361
Alexander Duycke35ec122009-05-21 13:07:12 +00001362 /* always use CB2 mode, difference is masked in the CB driver */
Mark Rustad9de76052015-08-08 16:27:41 -07001363 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 Duycke35ec122009-05-21 13:07:12 +00001369
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001370 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001371 adapter->q_vector[i]->cpu = -1;
1372 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001373 }
1374}
1375
1376static int __ixgbe_notify_dca(struct device *dev, void *data)
1377{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001378 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001379 unsigned long event = *(unsigned long *)data;
1380
Don Skidmore2a72c312011-07-20 02:27:05 +00001381 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001382 return 0;
1383
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001384 switch (event) {
1385 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001386 /* if we're already enabled, don't do it again */
1387 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1388 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001389 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001390 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Mark Rustad9de76052015-08-08 16:27:41 -07001391 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1392 IXGBE_DCA_CTRL_DCA_MODE_CB2);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001393 break;
1394 }
Tony Nguyen93df9462017-05-31 04:43:47 -07001395 /* fall through - DCA is disabled. */
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001396 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 Rustad9de76052015-08-08 16:27:41 -07001400 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
1401 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001402 }
1403 break;
1404 }
1405
Denis V. Lunev652f0932008-03-27 14:39:17 +03001406 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001407}
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001408
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001409#endif /* CONFIG_IXGBE_DCA */
Fan Du7edda4b82015-04-29 10:57:39 +08001410
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 Duyck8a0da212012-01-31 02:59:49 +00001417static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1418 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001419 struct sk_buff *skb)
1420{
Fan Du7edda4b82015-04-29 10:57:39 +08001421 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 Tantilov67a74ee2011-04-23 04:50:40 +00001435}
1436
Alexander Duyckf8003262012-03-03 02:35:52 +00001437#ifdef IXGBE_FCOE
Auke Kok9a799d72007-09-15 14:07:45 -07001438/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001439 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
Alexander Duyck57efd442012-06-25 21:54:46 +00001440 * @ring: structure containing ring specific data
Alexander Duyckff886df2011-06-11 01:45:13 +00001441 * @rx_desc: advanced rx descriptor
1442 *
1443 * Returns : true if it is FCoE pkt
1444 */
Alexander Duyck57efd442012-06-25 21:54:46 +00001445static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
Alexander Duyckff886df2011-06-11 01:45:13 +00001446 union ixgbe_adv_rx_desc *rx_desc)
1447{
1448 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1449
Alexander Duyck57efd442012-06-25 21:54:46 +00001450 return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
Alexander Duyckff886df2011-06-11 01:45:13 +00001451 ((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 Duyckf8003262012-03-03 02:35:52 +00001456#endif /* IXGBE_FCOE */
Alexander Duyckff886df2011-06-11 01:45:13 +00001457/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001458 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001459 * @ring: structure containing ring specific data
1460 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001461 * @skb: skb currently being received and modified
1462 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001463static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001464 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001465 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001466{
Don Skidmore3f207802014-12-23 07:40:34 +00001467 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
Don Skidmore3f207802014-12-23 07:40:34 +00001468 bool encap_pkt = false;
1469
Alexander Duyck8a0da212012-01-31 02:59:49 +00001470 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001471
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001472 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001473 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001474 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001475
Emil Tantilova21d0822016-08-10 11:19:23 -07001476 /* check for VXLAN and Geneve packets */
1477 if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
Don Skidmore3f207802014-12-23 07:40:34 +00001478 encap_pkt = true;
1479 skb->encapsulation = 1;
Don Skidmore3f207802014-12-23 07:40:34 +00001480 }
1481
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001482 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001483 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1484 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001485 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001486 return;
1487 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001488
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001489 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001490 return;
1491
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001492 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001493 /*
1494 * 82599 errata, UDP frames with a 0 checksum can be marked as
1495 * checksum errors.
1496 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001497 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1498 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001499 return;
1500
Alexander Duyck8a0da212012-01-31 02:59:49 +00001501 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001502 return;
1503 }
1504
Auke Kok9a799d72007-09-15 14:07:45 -07001505 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001506 skb->ip_summed = CHECKSUM_UNNECESSARY;
Don Skidmore3f207802014-12-23 07:40:34 +00001507 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 Rustadd4692512015-12-04 11:26:43 -08001512 skb->ip_summed = CHECKSUM_NONE;
Don Skidmore3f207802014-12-23 07:40:34 +00001513 return;
1514 }
1515 /* If we checked the outer header let the stack know */
1516 skb->csum_level = 1;
1517 }
Auke Kok9a799d72007-09-15 14:07:45 -07001518}
1519
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001520static 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 Duyckf990b792012-01-31 02:59:34 +00001525static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1526 struct ixgbe_rx_buffer *bi)
1527{
1528 struct page *page = bi->page;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001529 dma_addr_t dma;
Alexander Duyckf990b792012-01-31 02:59:34 +00001530
Alexander Duyckf8003262012-03-03 02:35:52 +00001531 /* since we are recycling buffers we should seldom need to alloc */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001532 if (likely(page))
Alexander Duyckf990b792012-01-31 02:59:34 +00001533 return true;
1534
Alexander Duyckf8003262012-03-03 02:35:52 +00001535 /* alloc new page for storage */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001536 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 Duyckf990b792012-01-31 02:59:34 +00001540 }
1541
Alexander Duyckf8003262012-03-03 02:35:52 +00001542 /* map page for use */
Alexander Duyckf3213d92017-01-17 08:35:54 -08001543 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 Duyckf990b792012-01-31 02:59:34 +00001547
Alexander Duyckf8003262012-03-03 02:35:52 +00001548 /*
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 Duyckdd411ec2012-04-06 04:24:50 +00001553 __free_pages(page, ixgbe_rx_pg_order(rx_ring));
Alexander Duyckf8003262012-03-03 02:35:52 +00001554
Alexander Duyckf990b792012-01-31 02:59:34 +00001555 rx_ring->rx_stats.alloc_rx_page_failed++;
1556 return false;
1557 }
1558
Alexander Duyckf8003262012-03-03 02:35:52 +00001559 bi->dma = dma;
Alexander Duyck18cb6522014-11-14 00:56:29 +00001560 bi->page = page;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08001561 bi->page_offset = ixgbe_rx_offset(rx_ring);
Björn Töpeled93a392018-03-22 10:02:36 +01001562 page_ref_add(page, USHRT_MAX - 1);
1563 bi->pagecnt_bias = USHRT_MAX;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02001564 rx_ring->rx_stats.alloc_rx_page++;
Alexander Duyckf8003262012-03-03 02:35:52 +00001565
Alexander Duyckf990b792012-01-31 02:59:34 +00001566 return true;
1567}
1568
Auke Kok9a799d72007-09-15 14:07:45 -07001569/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001570 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001571 * @rx_ring: ring to place buffers on
1572 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001573 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001574void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001575{
Auke Kok9a799d72007-09-15 14:07:45 -07001576 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001577 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001578 u16 i = rx_ring->next_to_use;
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001579 u16 bufsz;
Auke Kok9a799d72007-09-15 14:07:45 -07001580
Alexander Duyckf8003262012-03-03 02:35:52 +00001581 /* nothing to do */
1582 if (!cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001583 return;
1584
Alexander Duycke4f74022012-01-31 02:59:44 +00001585 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001586 bi = &rx_ring->rx_buffer_info[i];
1587 i -= rx_ring->count;
1588
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001589 bufsz = ixgbe_rx_bufsz(rx_ring);
1590
Alexander Duyckf8003262012-03-03 02:35:52 +00001591 do {
1592 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
Alexander Duyckf990b792012-01-31 02:59:34 +00001593 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001594
Alexander Duyckf3213d92017-01-17 08:35:54 -08001595 /* sync the buffer for use by the device */
1596 dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
Alexander Duyck4f4542b2017-01-17 08:36:14 -08001597 bi->page_offset, bufsz,
Alexander Duyckf3213d92017-01-17 08:35:54 -08001598 DMA_FROM_DEVICE);
1599
Alexander Duyckf8003262012-03-03 02:35:52 +00001600 /*
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 Kok9a799d72007-09-15 14:07:45 -07001605
Alexander Duyckf990b792012-01-31 02:59:34 +00001606 rx_desc++;
1607 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001608 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001609 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001610 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001611 bi = rx_ring->rx_buffer_info;
1612 i -= rx_ring->count;
1613 }
1614
Alexander Duyckc3630cc2017-01-17 08:36:28 -08001615 /* clear the length for the next_to_use descriptor */
1616 rx_desc->wb.upper.length = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00001617
1618 cleaned_count--;
1619 } while (cleaned_count);
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001620
Alexander Duyckf990b792012-01-31 02:59:34 +00001621 i += rx_ring->count;
1622
Alexander Duyckad435ec2014-11-14 00:56:35 +00001623 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 Kok9a799d72007-09-15 14:07:45 -07001637}
1638
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001639static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1640 struct sk_buff *skb)
1641{
Alexander Duyckf8003262012-03-03 02:35:52 +00001642 u16 hdr_len = skb_headlen(skb);
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001643
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 Duyck96be80a2013-02-12 09:45:44 +00001647 skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001648}
1649
1650static 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 Duyck8a0da212012-01-31 02:59:49 +00001666/**
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 **/
1676static 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 Fastabend43e95f12012-05-15 06:12:17 +00001680 struct net_device *dev = rx_ring->netdev;
Mark Rustada9763f32015-10-27 09:58:07 -07001681 u32 flags = rx_ring->q_vector->adapter->flags;
John Fastabend43e95f12012-05-15 06:12:17 +00001682
Alexander Duyck8a0da212012-01-31 02:59:49 +00001683 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 Rustada9763f32015-10-27 09:58:07 -07001689 if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
1690 ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00001691
Patrick McHardyf6469682013-04-19 02:04:27 +00001692 if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
John Fastabend43e95f12012-05-15 06:12:17 +00001693 ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001694 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001695 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001696 }
1697
Shannon Nelson92103192017-12-19 15:59:59 -08001698 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP))
1699 ixgbe_ipsec_rx(rx_ring, rx_desc, skb);
1700
Alexander Duyck58918df2017-11-22 10:57:17 -08001701 /* 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 Duyck8d80ac42018-04-03 17:16:14 -04001706 false);
1707
1708 skb->protocol = eth_type_trans(skb, dev);
Alexander Duyck8a0da212012-01-31 02:59:49 +00001709}
1710
1711static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1712 struct sk_buff *skb)
1713{
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08001714 napi_gro_receive(&q_vector->napi, skb);
Alexander Duyckaa801752010-11-16 19:27:02 -08001715}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001716
Alexander Duyckf8003262012-03-03 02:35:52 +00001717/**
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 **/
1728static 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 Duyck5a02cbd2012-07-20 08:08:51 +00001740 /* 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 Duyckf8003262012-03-03 02:35:52 +00001759 if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
1760 return false;
1761
Alexander Duyckf8003262012-03-03 02:35:52 +00001762 /* 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 Duyck19861ce2012-07-20 08:08:33 +00001770 * 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 */
1781static 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 Duyck8496e3382014-09-05 19:22:18 -04001799 pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
Alexander Duyck19861ce2012-07-20 08:08:33 +00001800
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 Duyck19861ce2012-07-20 08:08:33 +00001809}
1810
1811/**
Alexander Duyck42073d92012-07-20 08:08:28 +00001812 * 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 */
1821static 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 Duyckf3213d92017-01-17 08:35:54 -08001826 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 Tantilov0c5661e2018-02-23 12:39:41 -08001830 } 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 Duyck42073d92012-07-20 08:08:28 +00001838 } 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 Duyckf215af82017-01-17 08:35:44 -08001844 skb_frag_size(frag),
Alexander Duyck42073d92012-07-20 08:08:28 +00001845 DMA_FROM_DEVICE);
1846 }
Alexander Duyck42073d92012-07-20 08:08:28 +00001847}
1848
1849/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001850 * 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 Fastabend92470802017-04-24 03:30:17 -07001855 * 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 Duyckf8003262012-03-03 02:35:52 +00001859 * 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 **/
1871static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
1872 union ixgbe_adv_rx_desc *rx_desc,
1873 struct sk_buff *skb)
1874{
Alexander Duyckf8003262012-03-03 02:35:52 +00001875 struct net_device *netdev = rx_ring->netdev;
Alexander Duyckf8003262012-03-03 02:35:52 +00001876
John Fastabend92470802017-04-24 03:30:17 -07001877 /* XDP packets use error pointer so abort at this point */
1878 if (IS_ERR(skb))
1879 return true;
1880
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08001881 /* 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 Duyckf8003262012-03-03 02:35:52 +00001888 dev_kfree_skb_any(skb);
1889 return true;
1890 }
1891
Alexander Duyck19861ce2012-07-20 08:08:33 +00001892 /* place header in linear portion of buffer */
Alexander Duyck6f429222017-01-17 08:37:13 -08001893 if (!skb_headlen(skb))
Alexander Duyckcf3fe7a2012-07-20 08:08:39 +00001894 ixgbe_pull_tail(rx_ring, skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00001895
Alexander Duyck57efd442012-06-25 21:54:46 +00001896#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 Duycka94d9e22014-12-03 08:17:39 -08001902 /* if eth_skb_pad returns an error the skb was freed */
1903 if (eth_skb_pad(skb))
1904 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001905
1906 return false;
1907}
1908
1909/**
Alexander Duyckf8003262012-03-03 02:35:52 +00001910 * 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 Duyck0549ae22012-07-20 08:08:18 +00001914 * Synchronizes page for reuse by the adapter
Alexander Duyckf8003262012-03-03 02:35:52 +00001915 **/
1916static 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 Duyckf8003262012-03-03 02:35:52 +00001921
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 Duyck3fd218762017-01-17 08:36:45 -08001928 /* 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 Duyckf8003262012-03-03 02:35:52 +00001936}
1937
Alexander Duyck18cb6522014-11-14 00:56:29 +00001938static inline bool ixgbe_page_is_reserved(struct page *page)
1939{
Michal Hocko2f064f32015-08-21 14:11:51 -07001940 return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
Alexander Duyck18cb6522014-11-14 00:56:29 +00001941}
1942
Alexander Duyck3fd218762017-01-17 08:36:45 -08001943static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
Alexander Duyckf8003262012-03-03 02:35:52 +00001944{
Alexander Duyck3fd218762017-01-17 08:36:45 -08001945 unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
1946 struct page *page = rx_buffer->page;
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001947
Alexander Duyck09816fb2012-07-20 08:08:23 +00001948 /* avoid re-using remote pages */
Alexander Duyck18cb6522014-11-14 00:56:29 +00001949 if (unlikely(ixgbe_page_is_reserved(page)))
Alexander Duyck09816fb2012-07-20 08:08:23 +00001950 return false;
1951
1952#if (PAGE_SIZE < 8192)
1953 /* if we are only owner of page we can reuse it */
Alexander Duyck3fd218762017-01-17 08:36:45 -08001954 if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
Alexander Duyck0549ae22012-07-20 08:08:18 +00001955 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001956#else
Alexander Duyck3fd218762017-01-17 08:36:45 -08001957 /* 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 Duyck09816fb2012-07-20 08:08:23 +00001965 return false;
Alexander Duyck09816fb2012-07-20 08:08:23 +00001966#endif
Alexander Duyck0549ae22012-07-20 08:08:18 +00001967
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001968 /* 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 Duyck18cb6522014-11-14 00:56:29 +00001971 */
Björn Töpeled93a392018-03-22 10:02:36 +01001972 if (unlikely(pagecnt_bias == 1)) {
1973 page_ref_add(page, USHRT_MAX - 1);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08001974 rx_buffer->pagecnt_bias = USHRT_MAX;
1975 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00001976
Alexander Duyck0549ae22012-07-20 08:08:18 +00001977 return true;
Alexander Duyckf8003262012-03-03 02:35:52 +00001978}
1979
Alexander Duyckaf43da02017-01-17 08:35:34 -08001980/**
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 Duyckaf43da02017-01-17 08:35:34 -08001984 * @skb: sk_buff to place the data into
Tony Nguyen5ba643c2017-12-04 11:28:30 -08001985 * @size: size of data in rx_buffer
Alexander Duyckaf43da02017-01-17 08:35:34 -08001986 *
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 Duyck3fd218762017-01-17 08:36:45 -08001995static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
Alexander Duyckaf43da02017-01-17 08:35:34 -08001996 struct ixgbe_rx_buffer *rx_buffer,
Alexander Duyck3fd218762017-01-17 08:36:45 -08001997 struct sk_buff *skb,
1998 unsigned int size)
Alexander Duyckaf43da02017-01-17 08:35:34 -08001999{
Alexander Duyckaf43da02017-01-17 08:35:34 -08002000#if (PAGE_SIZE < 8192)
Alexander Duyck4f4542b2017-01-17 08:36:14 -08002001 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
Alexander Duyckaf43da02017-01-17 08:35:34 -08002002#else
Alexander Duyck2de6aa32017-01-17 08:36:54 -08002003 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2004 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2005 SKB_DATA_ALIGN(size);
Alexander Duyckaf43da02017-01-17 08:35:34 -08002006#endif
Alexander Duyck3fd218762017-01-17 08:36:45 -08002007 skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
Alexander Duyckaf43da02017-01-17 08:35:34 -08002008 rx_buffer->page_offset, size, truesize);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002009#if (PAGE_SIZE < 8192)
2010 rx_buffer->page_offset ^= truesize;
2011#else
2012 rx_buffer->page_offset += truesize;
2013#endif
Alexander Duyckaf43da02017-01-17 08:35:34 -08002014}
2015
Alexander Duyck3fd218762017-01-17 08:36:45 -08002016static 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 Duyck18806c92012-07-20 08:08:44 +00002020{
2021 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyck18806c92012-07-20 08:08:44 +00002022
2023 rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
Alexander Duyck3fd218762017-01-17 08:36:45 -08002024 prefetchw(rx_buffer->page);
2025 *skb = rx_buffer->skb;
Alexander Duyck18806c92012-07-20 08:08:44 +00002026
Alexander Duyck3fd218762017-01-17 08:36:45 -08002027 /* 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 Duyck18806c92012-07-20 08:08:44 +00002034 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002035 if (*skb)
2036 ixgbe_dma_sync_frag(rx_ring, *skb);
Alexander Duyck18806c92012-07-20 08:08:44 +00002037 }
2038
Alexander Duyck3fd218762017-01-17 08:36:45 -08002039 /* 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);
2045skip_sync:
2046 rx_buffer->pagecnt_bias--;
2047
2048 return rx_buffer;
2049}
2050
2051static 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 Duyck18806c92012-07-20 08:08:44 +00002056 /* hand second half of page back to the ring */
2057 ixgbe_reuse_rx_page(rx_ring, rx_buffer);
Alexander Duyck18806c92012-07-20 08:08:44 +00002058 } else {
John Fastabend92470802017-04-24 03:30:17 -07002059 if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002060 /* 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 Duyck3fd218762017-01-17 08:36:45 -08002069 __page_frag_cache_drain(rx_buffer->page,
Alexander Duyck1b56cf42017-01-17 08:36:03 -08002070 rx_buffer->pagecnt_bias);
Alexander Duyck18806c92012-07-20 08:08:44 +00002071 }
2072
Alexander Duyck3fd218762017-01-17 08:36:45 -08002073 /* clear contents of rx_buffer */
Alexander Duyck18806c92012-07-20 08:08:44 +00002074 rx_buffer->page = NULL;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002075 rx_buffer->skb = NULL;
2076}
2077
2078static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
2079 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002080 struct xdp_buff *xdp,
2081 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck3fd218762017-01-17 08:36:45 -08002082{
John Fastabend92470802017-04-24 03:30:17 -07002083 unsigned int size = xdp->data_end - xdp->data;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002084#if (PAGE_SIZE < 8192)
2085 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2086#else
John Fastabend92470802017-04-24 03:30:17 -07002087 unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
2088 xdp->data_hard_start);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002089#endif
2090 struct sk_buff *skb;
2091
2092 /* prefetch first cache line of first page */
John Fastabend92470802017-04-24 03:30:17 -07002093 prefetch(xdp->data);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002094#if L1_CACHE_BYTES < 128
John Fastabend92470802017-04-24 03:30:17 -07002095 prefetch(xdp->data + L1_CACHE_BYTES);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002096#endif
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002097 /* 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 Duyck3fd218762017-01-17 08:36:45 -08002112
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 Fastabend92470802017-04-24 03:30:17 -07002123 xdp->data - page_address(rx_buffer->page),
Alexander Duyck3fd218762017-01-17 08:36:45 -08002124 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 Fastabend92470802017-04-24 03:30:17 -07002131 memcpy(__skb_put(skb, size),
2132 xdp->data, ALIGN(size, sizeof(long)));
Alexander Duyck3fd218762017-01-17 08:36:45 -08002133 rx_buffer->pagecnt_bias++;
2134 }
Alexander Duyck18806c92012-07-20 08:08:44 +00002135
2136 return skb;
Alexander Duyckf8003262012-03-03 02:35:52 +00002137}
2138
Alexander Duyck6f429222017-01-17 08:37:13 -08002139static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
2140 struct ixgbe_rx_buffer *rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002141 struct xdp_buff *xdp,
2142 union ixgbe_adv_rx_desc *rx_desc)
Alexander Duyck6f429222017-01-17 08:37:13 -08002143{
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002144 unsigned int metasize = xdp->data - xdp->data_meta;
Alexander Duyck6f429222017-01-17 08:37:13 -08002145#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 Fastabend92470802017-04-24 03:30:17 -07002149 SKB_DATA_ALIGN(xdp->data_end -
2150 xdp->data_hard_start);
Alexander Duyck6f429222017-01-17 08:37:13 -08002151#endif
2152 struct sk_buff *skb;
2153
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002154 /* 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 Duyck6f429222017-01-17 08:37:13 -08002160#if L1_CACHE_BYTES < 128
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002161 prefetch(xdp->data_meta + L1_CACHE_BYTES);
Alexander Duyck6f429222017-01-17 08:37:13 -08002162#endif
2163
John Fastabend92470802017-04-24 03:30:17 -07002164 /* build an skb to around the page buffer */
2165 skb = build_skb(xdp->data_hard_start, truesize);
Alexander Duyck6f429222017-01-17 08:37:13 -08002166 if (unlikely(!skb))
2167 return NULL;
2168
2169 /* update pointers within the skb to store the data */
John Fastabend92470802017-04-24 03:30:17 -07002170 skb_reserve(skb, xdp->data - xdp->data_hard_start);
2171 __skb_put(skb, xdp->data_end - xdp->data);
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002172 if (metasize)
2173 skb_metadata_set(skb, metasize);
Alexander Duyck6f429222017-01-17 08:37:13 -08002174
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
John Fastabend92470802017-04-24 03:30:17 -07002189#define IXGBE_XDP_PASS 0
2190#define IXGBE_XDP_CONSUMED 1
John Fastabend33fdc822017-04-24 03:30:18 -07002191#define IXGBE_XDP_TX 2
John Fastabend92470802017-04-24 03:30:17 -07002192
John Fastabend33fdc822017-04-24 03:30:18 -07002193static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002194 struct xdp_frame *xdpf);
John Fastabend33fdc822017-04-24 03:30:18 -07002195
2196static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
2197 struct ixgbe_ring *rx_ring,
John Fastabend92470802017-04-24 03:30:17 -07002198 struct xdp_buff *xdp)
2199{
John Fastabend64530732017-07-17 09:28:12 -07002200 int err, result = IXGBE_XDP_PASS;
John Fastabend92470802017-04-24 03:30:17 -07002201 struct bpf_prog *xdp_prog;
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002202 struct xdp_frame *xdpf;
John Fastabend92470802017-04-24 03:30:17 -07002203 u32 act;
2204
2205 rcu_read_lock();
2206 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
2207
2208 if (!xdp_prog)
2209 goto xdp_out;
2210
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002211 prefetchw(xdp->data_hard_start); /* xdp_frame write */
2212
John Fastabend92470802017-04-24 03:30:17 -07002213 act = bpf_prog_run_xdp(xdp_prog, xdp);
2214 switch (act) {
2215 case XDP_PASS:
2216 break;
John Fastabend33fdc822017-04-24 03:30:18 -07002217 case XDP_TX:
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002218 xdpf = convert_to_xdp_frame(xdp);
2219 if (unlikely(!xdpf)) {
2220 result = IXGBE_XDP_CONSUMED;
2221 break;
2222 }
2223 result = ixgbe_xmit_xdp_ring(adapter, xdpf);
John Fastabend33fdc822017-04-24 03:30:18 -07002224 break;
John Fastabend64530732017-07-17 09:28:12 -07002225 case XDP_REDIRECT:
John Fastabend5acaee02017-07-17 09:28:35 -07002226 err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
John Fastabend64530732017-07-17 09:28:12 -07002227 if (!err)
2228 result = IXGBE_XDP_TX;
2229 else
2230 result = IXGBE_XDP_CONSUMED;
2231 break;
John Fastabend92470802017-04-24 03:30:17 -07002232 default:
2233 bpf_warn_invalid_xdp_action(act);
Tony Nguyen93df9462017-05-31 04:43:47 -07002234 /* fallthrough */
John Fastabend92470802017-04-24 03:30:17 -07002235 case XDP_ABORTED:
2236 trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
2237 /* fallthrough -- handle aborts by dropping packet */
2238 case XDP_DROP:
2239 result = IXGBE_XDP_CONSUMED;
2240 break;
2241 }
2242xdp_out:
2243 rcu_read_unlock();
2244 return ERR_PTR(-result);
2245}
2246
John Fastabend33fdc822017-04-24 03:30:18 -07002247static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
2248 struct ixgbe_rx_buffer *rx_buffer,
2249 unsigned int size)
2250{
2251#if (PAGE_SIZE < 8192)
2252 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2253
2254 rx_buffer->page_offset ^= truesize;
2255#else
2256 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2257 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2258 SKB_DATA_ALIGN(size);
2259
2260 rx_buffer->page_offset += truesize;
2261#endif
2262}
2263
Alexander Duyckf8003262012-03-03 02:35:52 +00002264/**
2265 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2266 * @q_vector: structure containing interrupt and ring information
2267 * @rx_ring: rx descriptor ring to transact packets on
2268 * @budget: Total limit on number of packets to process
2269 *
2270 * This function provides a "bounce buffer" approach to Rx interrupt
2271 * processing. The advantage to this is that on systems that have
2272 * expensive overhead for IOMMU access this provides a means of avoiding
2273 * it by maintaining the mapping of the page to the syste.
2274 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002275 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002276 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002277static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002278 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002279 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002280{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002281 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00002282 struct ixgbe_adapter *adapter = q_vector->adapter;
John Fastabend33fdc822017-04-24 03:30:18 -07002283#ifdef IXGBE_FCOE
Mark Rustad4ffdf912012-07-18 06:05:50 +00002284 int ddp_bytes;
2285 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002286#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002287 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
John Fastabend7379f972017-03-28 09:47:03 -07002288 bool xdp_xmit = false;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01002289 struct xdp_buff xdp;
2290
2291 xdp.rxq = &rx_ring->xdp_rxq;
Auke Kok9a799d72007-09-15 14:07:45 -07002292
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002293 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002294 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002295 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002296 struct sk_buff *skb;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002297 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002298
Alexander Duyckf8003262012-03-03 02:35:52 +00002299 /* return some buffers to hardware, one at a time is too slow */
2300 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2301 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2302 cleaned_count = 0;
2303 }
Auke Kok9a799d72007-09-15 14:07:45 -07002304
Alexander Duyck18806c92012-07-20 08:08:44 +00002305 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002306 size = le16_to_cpu(rx_desc->wb.upper.length);
2307 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002308 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002309
Alexander Duyck124b74c2014-12-11 15:02:28 -08002310 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002311 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002312 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002313 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002314 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002315
Alexander Duyck3fd218762017-01-17 08:36:45 -08002316 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2317
Alexander Duyck18806c92012-07-20 08:08:44 +00002318 /* retrieve a buffer from the ring */
John Fastabend92470802017-04-24 03:30:17 -07002319 if (!skb) {
2320 xdp.data = page_address(rx_buffer->page) +
2321 rx_buffer->page_offset;
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002322 xdp.data_meta = xdp.data;
John Fastabend92470802017-04-24 03:30:17 -07002323 xdp.data_hard_start = xdp.data -
2324 ixgbe_rx_offset(rx_ring);
2325 xdp.data_end = xdp.data + size;
2326
John Fastabend33fdc822017-04-24 03:30:18 -07002327 skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
John Fastabend92470802017-04-24 03:30:17 -07002328 }
2329
2330 if (IS_ERR(skb)) {
John Fastabend7379f972017-03-28 09:47:03 -07002331 if (PTR_ERR(skb) == -IXGBE_XDP_TX) {
2332 xdp_xmit = true;
John Fastabend33fdc822017-04-24 03:30:18 -07002333 ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
John Fastabend7379f972017-03-28 09:47:03 -07002334 } else {
John Fastabend33fdc822017-04-24 03:30:18 -07002335 rx_buffer->pagecnt_bias++;
John Fastabend7379f972017-03-28 09:47:03 -07002336 }
John Fastabend92470802017-04-24 03:30:17 -07002337 total_rx_packets++;
2338 total_rx_bytes += size;
John Fastabend92470802017-04-24 03:30:17 -07002339 } else if (skb) {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002340 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
John Fastabend92470802017-04-24 03:30:17 -07002341 } else if (ring_uses_build_skb(rx_ring)) {
Alexander Duyck6f429222017-01-17 08:37:13 -08002342 skb = ixgbe_build_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002343 &xdp, rx_desc);
2344 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002345 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002346 &xdp, rx_desc);
2347 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002348
Alexander Duyck18806c92012-07-20 08:08:44 +00002349 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002350 if (!skb) {
2351 rx_ring->rx_stats.alloc_rx_buff_failed++;
2352 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002353 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002354 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002355
Alexander Duyck3fd218762017-01-17 08:36:45 -08002356 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002357 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002358
Alexander Duyckf8003262012-03-03 02:35:52 +00002359 /* place incomplete frames back on ring for completion */
2360 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2361 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002362
Alexander Duyckf8003262012-03-03 02:35:52 +00002363 /* verify the packet layout is correct */
2364 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2365 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002366
2367 /* probably a little skewed due to removing CRC */
2368 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002369
Alexander Duyck8a0da212012-01-31 02:59:49 +00002370 /* populate checksum, timestamp, VLAN, and protocol */
2371 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2372
Yi Zou332d4a72009-05-13 13:11:53 +00002373#ifdef IXGBE_FCOE
2374 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002375 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002376 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002377 /* include DDPed FCoE data */
2378 if (ddp_bytes > 0) {
2379 if (!mss) {
2380 mss = rx_ring->netdev->mtu -
2381 sizeof(struct fcoe_hdr) -
2382 sizeof(struct fc_frame_header) -
2383 sizeof(struct fcoe_crc_eof);
2384 if (mss > 512)
2385 mss &= ~511;
2386 }
2387 total_rx_bytes += ddp_bytes;
2388 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2389 mss);
2390 }
David S. Miller823dcd22011-08-20 10:39:12 -07002391 if (!ddp_bytes) {
2392 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002393 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002394 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002395 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002396
Yi Zou332d4a72009-05-13 13:11:53 +00002397#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002398 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002399
Alexander Duyckf8003262012-03-03 02:35:52 +00002400 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002401 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002402 }
Auke Kok9a799d72007-09-15 14:07:45 -07002403
John Fastabend7379f972017-03-28 09:47:03 -07002404 if (xdp_xmit) {
2405 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
2406
2407 /* Force memory writes to complete before letting h/w
2408 * know there are new descriptors to fetch.
2409 */
2410 wmb();
2411 writel(ring->next_to_use, ring->tail);
John Fastabend11393cc2017-07-17 09:29:40 -07002412
2413 xdp_do_flush_map();
John Fastabend7379f972017-03-28 09:47:03 -07002414 }
2415
Alexander Duyckc267fc12010-11-16 19:27:00 -08002416 u64_stats_update_begin(&rx_ring->syncp);
2417 rx_ring->stats.packets += total_rx_packets;
2418 rx_ring->stats.bytes += total_rx_bytes;
2419 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002420 q_vector->rx.total_packets += total_rx_packets;
2421 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002422
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002423 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002424}
2425
Auke Kok9a799d72007-09-15 14:07:45 -07002426/**
2427 * ixgbe_configure_msix - Configure MSI-X hardware
2428 * @adapter: board private structure
2429 *
2430 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2431 * interrupts.
2432 **/
2433static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2434{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002435 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002436 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002437 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002438
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002439 /* Populate MSIX to EITR Select */
2440 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002441 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002442 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2443 }
2444
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002445 /*
2446 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002447 * corresponding register.
2448 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002449 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002450 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002451 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452
Alexander Duycka5579282012-02-08 07:50:04 +00002453 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002454 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002455
Alexander Duycka5579282012-02-08 07:50:04 +00002456 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002457 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002458
Alexander Duyckfe49f042009-06-04 16:00:09 +00002459 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002460 }
2461
Alexander Duyckbd508172010-11-16 19:27:03 -08002462 switch (adapter->hw.mac.type) {
2463 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002464 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002465 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002466 break;
2467 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002468 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002469 case ixgbe_mac_X550:
2470 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002471 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002472 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002473 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002474 default:
2475 break;
2476 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002477 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002478
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002479 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002480 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002481 mask &= ~(IXGBE_EIMS_OTHER |
2482 IXGBE_EIMS_MAILBOX |
2483 IXGBE_EIMS_LSC);
2484
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002485 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002486}
2487
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002488/**
2489 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002490 * @q_vector: structure containing interrupt and ring information
2491 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002492 *
2493 * Stores a new ITR value based on packets and byte
2494 * counts during the last interrupt. The advantage of per interrupt
2495 * computation is faster updates and more accurate ITR for the current
2496 * traffic pattern. Constants in this function were computed
2497 * based on theoretical maximum wire speed and thresholds were set based
2498 * on testing data as well as attempting to minimize response time
2499 * while increasing bulk throughput.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002500 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002501static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2502 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002503{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002504 unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
2505 IXGBE_ITR_ADAPTIVE_LATENCY;
2506 unsigned int avg_wire_size, packets, bytes;
2507 unsigned long next_update = jiffies;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002508
Alexander Duyckb4ded832017-09-25 14:55:36 -07002509 /* If we don't have any rings just leave ourselves set for maximum
2510 * possible latency so we take ourselves out of the equation.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002511 */
Alexander Duyckb4ded832017-09-25 14:55:36 -07002512 if (!ring_container->ring)
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002513 return;
2514
Alexander Duyckb4ded832017-09-25 14:55:36 -07002515 /* If we didn't update within up to 1 - 2 jiffies we can assume
2516 * that either packets are coming in so slow there hasn't been
2517 * any work, or that there is so much work that NAPI is dealing
2518 * with interrupt moderation and we don't need to do anything.
2519 */
2520 if (time_after(next_update, ring_container->next_update))
2521 goto clear_counts;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002522
Alexander Duyckb4ded832017-09-25 14:55:36 -07002523 packets = ring_container->total_packets;
2524
2525 /* We have no packets to actually measure against. This means
2526 * either one of the other queues on this vector is active or
2527 * we are a Tx queue doing TSO with too high of an interrupt rate.
2528 *
2529 * When this occurs just tick up our delay by the minimum value
2530 * and hope that this extra delay will prevent us from being called
2531 * without any work on our queue.
2532 */
2533 if (!packets) {
2534 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2535 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2536 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2537 itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
2538 goto clear_counts;
2539 }
2540
2541 bytes = ring_container->total_bytes;
2542
2543 /* If packets are less than 4 or bytes are less than 9000 assume
2544 * insufficient data to use bulk rate limiting approach. We are
2545 * likely latency driven.
2546 */
2547 if (packets < 4 && bytes < 9000) {
2548 itr = IXGBE_ITR_ADAPTIVE_LATENCY;
2549 goto adjust_by_size;
2550 }
2551
2552 /* Between 4 and 48 we can assume that our current interrupt delay
2553 * is only slightly too low. As such we should increase it by a small
2554 * fixed amount.
2555 */
2556 if (packets < 48) {
2557 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2558 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2559 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2560 goto clear_counts;
2561 }
2562
2563 /* Between 48 and 96 is our "goldilocks" zone where we are working
2564 * out "just right". Just report that our current ITR is good for us.
2565 */
2566 if (packets < 96) {
2567 itr = q_vector->itr >> 2;
2568 goto clear_counts;
2569 }
2570
2571 /* If packet count is 96 or greater we are likely looking at a slight
2572 * overrun of the delay we want. Try halving our delay to see if that
2573 * will cut the number of packets in half per interrupt.
2574 */
2575 if (packets < 256) {
2576 itr = q_vector->itr >> 3;
2577 if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
2578 itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
2579 goto clear_counts;
2580 }
2581
2582 /* The paths below assume we are dealing with a bulk ITR since number
2583 * of packets is 256 or greater. We are just going to have to compute
2584 * a value and try to bring the count under control, though for smaller
2585 * packet sizes there isn't much we can do as NAPI polling will likely
2586 * be kicking in sooner rather than later.
2587 */
2588 itr = IXGBE_ITR_ADAPTIVE_BULK;
2589
2590adjust_by_size:
2591 /* If packet counts are 256 or greater we can assume we have a gross
2592 * overestimation of what the rate should be. Instead of trying to fine
2593 * tune it just use the formula below to try and dial in an exact value
2594 * give the current packet size of the frame.
2595 */
2596 avg_wire_size = bytes / packets;
2597
2598 /* The following is a crude approximation of:
2599 * wmem_default / (size + overhead) = desired_pkts_per_int
2600 * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
2601 * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
2602 *
2603 * Assuming wmem_default is 212992 and overhead is 640 bytes per
2604 * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
2605 * formula down to
2606 *
2607 * (170 * (size + 24)) / (size + 640) = ITR
2608 *
2609 * We first do some math on the packet size and then finally bitshift
2610 * by 8 after rounding up. We also have to account for PCIe link speed
2611 * difference as ITR scales based on this.
2612 */
2613 if (avg_wire_size <= 60) {
2614 /* Start at 50k ints/sec */
2615 avg_wire_size = 5120;
2616 } else if (avg_wire_size <= 316) {
2617 /* 50K ints/sec to 16K ints/sec */
2618 avg_wire_size *= 40;
2619 avg_wire_size += 2720;
2620 } else if (avg_wire_size <= 1084) {
2621 /* 16K ints/sec to 9.2K ints/sec */
2622 avg_wire_size *= 15;
2623 avg_wire_size += 11452;
2624 } else if (avg_wire_size <= 1980) {
2625 /* 9.2K ints/sec to 8K ints/sec */
2626 avg_wire_size *= 5;
2627 avg_wire_size += 22420;
2628 } else {
2629 /* plateau at a limit of 8K ints/sec */
2630 avg_wire_size = 32256;
2631 }
2632
2633 /* If we are in low latency mode half our delay which doubles the rate
2634 * to somewhere between 100K to 16K ints/sec
2635 */
2636 if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
2637 avg_wire_size >>= 1;
2638
2639 /* Resultant value is 256 times larger than it needs to be. This
2640 * gives us room to adjust the value as needed to either increase
2641 * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
2642 *
2643 * Use addition as we have already recorded the new latency flag
2644 * for the ITR value.
2645 */
2646 switch (q_vector->adapter->link_speed) {
2647 case IXGBE_LINK_SPEED_10GB_FULL:
2648 case IXGBE_LINK_SPEED_100_FULL:
2649 default:
2650 itr += DIV_ROUND_UP(avg_wire_size,
2651 IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
2652 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002653 break;
Alexander Duyckb4ded832017-09-25 14:55:36 -07002654 case IXGBE_LINK_SPEED_2_5GB_FULL:
2655 case IXGBE_LINK_SPEED_1GB_FULL:
2656 case IXGBE_LINK_SPEED_10_FULL:
2657 itr += DIV_ROUND_UP(avg_wire_size,
2658 IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
2659 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002660 break;
2661 }
2662
Alexander Duyckb4ded832017-09-25 14:55:36 -07002663clear_counts:
2664 /* write back value */
2665 ring_container->itr = itr;
2666
2667 /* next update should occur within next jiffy */
2668 ring_container->next_update = next_update + 1;
2669
Alexander Duyckbd198052011-06-11 01:45:08 +00002670 ring_container->total_bytes = 0;
2671 ring_container->total_packets = 0;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002672}
2673
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002674/**
2675 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002676 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002677 *
2678 * This function is made to be called by ethtool and by the driver
2679 * when it needs to update EITR registers at runtime. Hardware
2680 * specific quirks/differences are taken care of here.
2681 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002682void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002683{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002684 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002685 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002686 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002687 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002688
Alexander Duyckbd508172010-11-16 19:27:03 -08002689 switch (adapter->hw.mac.type) {
2690 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002691 /* must write high and low 16 bits to reset counter */
2692 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002693 break;
2694 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002695 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002696 case ixgbe_mac_X550:
2697 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002698 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002699 /*
2700 * set the WDIS bit to not clear the timer bits and cause an
2701 * immediate assertion of the interrupt
2702 */
2703 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002704 break;
2705 default:
2706 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002707 }
2708 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2709}
2710
Alexander Duyckbd198052011-06-11 01:45:08 +00002711static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002712{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002713 u32 new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002714
Alexander Duyckbd198052011-06-11 01:45:08 +00002715 ixgbe_update_itr(q_vector, &q_vector->tx);
2716 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002717
Alexander Duyckb4ded832017-09-25 14:55:36 -07002718 /* use the smallest value of new ITR delay calculations */
2719 new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002720
Alexander Duyckb4ded832017-09-25 14:55:36 -07002721 /* Clear latency flag if set, shift into correct position */
2722 new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
2723 new_itr <<= 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002724
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002725 if (new_itr != q_vector->itr) {
Alexander Duyckbd198052011-06-11 01:45:08 +00002726 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002727 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002728
2729 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002730 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002731}
2732
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002733/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002734 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002735 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002736 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002737static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002738{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002739 struct ixgbe_hw *hw = &adapter->hw;
2740 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002741 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002742
Alexander Duyckf0f97782011-04-22 04:08:09 +00002743 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002744 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002745
Mark Rustad22cb4ff2017-04-25 13:55:25 -07002746 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
Alexander Duyckf0f97782011-04-22 04:08:09 +00002747 return;
2748
2749 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2750
Joe Perches7ca647b2010-09-07 21:35:40 +00002751 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002752 case IXGBE_DEV_ID_82599_T3_LOM:
2753 /*
2754 * Since the warning interrupt is for both ports
2755 * we don't have to check if:
2756 * - This interrupt wasn't for our port.
2757 * - We may have missed the interrupt so always have to
2758 * check if we got a LSC
2759 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002760 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002761 !(eicr & IXGBE_EICR_LSC))
2762 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002763
Alexander Duyckf0f97782011-04-22 04:08:09 +00002764 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002765 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002766 bool link_up = false;
2767
Josh Hay3d292262012-12-15 03:28:19 +00002768 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002769
Alexander Duyckf0f97782011-04-22 04:08:09 +00002770 if (link_up)
2771 return;
2772 }
2773
2774 /* Check if this is not due to overtemp */
2775 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2776 return;
2777
2778 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002779 case IXGBE_DEV_ID_X550EM_A_1G_T:
2780 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2781 rc = hw->phy.ops.check_overtemp(hw);
2782 if (rc != IXGBE_ERR_OVERTEMP)
2783 return;
2784 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002785 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002786 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2787 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002788 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002789 return;
2790 break;
2791 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002792 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002793
2794 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002795}
2796
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002797static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2798{
2799 struct ixgbe_hw *hw = &adapter->hw;
2800
2801 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002802 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002803 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002804 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002805 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002806 }
2807}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002808
Jacob Keller4f51bf72011-08-20 04:49:45 +00002809static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2810{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002811 struct ixgbe_hw *hw = &adapter->hw;
2812
Jacob Keller4f51bf72011-08-20 04:49:45 +00002813 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2814 return;
2815
2816 switch (adapter->hw.mac.type) {
2817 case ixgbe_mac_82599EB:
2818 /*
2819 * Need to check link state so complete overtemp check
2820 * on service task
2821 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002822 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2823 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002824 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2825 adapter->interrupt_event = eicr;
2826 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2827 ixgbe_service_event_schedule(adapter);
2828 return;
2829 }
2830 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002831 case ixgbe_mac_x550em_a:
2832 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2833 adapter->interrupt_event = eicr;
2834 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2835 ixgbe_service_event_schedule(adapter);
2836 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2837 IXGBE_EICR_GPI_SDP0_X550EM_a);
2838 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2839 IXGBE_EICR_GPI_SDP0_X550EM_a);
2840 }
2841 return;
2842 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002843 case ixgbe_mac_X540:
2844 if (!(eicr & IXGBE_EICR_TS))
2845 return;
2846 break;
2847 default:
2848 return;
2849 }
2850
Don Skidmoref44e7512015-06-09 16:36:23 -07002851 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002852}
2853
Don Skidmore45788d22015-06-09 16:59:04 -07002854static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2855{
2856 switch (hw->mac.type) {
2857 case ixgbe_mac_82598EB:
2858 if (hw->phy.type == ixgbe_phy_nl)
2859 return true;
2860 return false;
2861 case ixgbe_mac_82599EB:
2862 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002863 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002864 switch (hw->mac.ops.get_media_type(hw)) {
2865 case ixgbe_media_type_fiber:
2866 case ixgbe_media_type_fiber_qsfp:
2867 return true;
2868 default:
2869 return false;
2870 }
2871 default:
2872 return false;
2873 }
2874}
2875
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002876static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2877{
2878 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002879 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002880
Don Skidmore4ccc6502015-09-02 13:47:54 -07002881 if (!ixgbe_is_sfp(hw))
2882 return;
2883
2884 /* Later MAC's use different SDP */
2885 if (hw->mac.type >= ixgbe_mac_X540)
2886 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2887
2888 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002889 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002890 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002891 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2892 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002893 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002894 ixgbe_service_event_schedule(adapter);
2895 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002896 }
2897
Don Skidmore4ccc6502015-09-02 13:47:54 -07002898 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2899 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002900 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002901 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002902 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2903 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2904 ixgbe_service_event_schedule(adapter);
2905 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002906 }
2907}
2908
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002909static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2910{
2911 struct ixgbe_hw *hw = &adapter->hw;
2912
2913 adapter->lsc_int++;
2914 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2915 adapter->link_check_timeout = jiffies;
2916 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2917 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002918 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002919 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002920 }
2921}
2922
Alexander Duyckfe49f042009-06-04 16:00:09 +00002923static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2924 u64 qmask)
2925{
2926 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002927 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002928
Alexander Duyckbd508172010-11-16 19:27:03 -08002929 switch (hw->mac.type) {
2930 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002931 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002932 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2933 break;
2934 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002935 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002936 case ixgbe_mac_X550:
2937 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002938 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002939 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002940 if (mask)
2941 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002942 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002943 if (mask)
2944 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2945 break;
2946 default:
2947 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002948 }
2949 /* skip the flush */
2950}
2951
2952static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002953 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002954{
2955 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002956 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002957
Alexander Duyckbd508172010-11-16 19:27:03 -08002958 switch (hw->mac.type) {
2959 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002960 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002961 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2962 break;
2963 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002964 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002965 case ixgbe_mac_X550:
2966 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002967 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002968 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002969 if (mask)
2970 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002971 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002972 if (mask)
2973 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2974 break;
2975 default:
2976 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002977 }
2978 /* skip the flush */
2979}
2980
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002981/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002982 * ixgbe_irq_enable - Enable default interrupt generation settings
2983 * @adapter: board private structure
Tony Nguyen5ba643c2017-12-04 11:28:30 -08002984 * @queues: enable irqs for queues
2985 * @flush: flush register write
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002986 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002987static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2988 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002989{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002990 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002991 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002992
Alexander Duyck2c4af692011-07-15 07:29:55 +00002993 /* don't reenable LSC while waiting for link */
2994 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2995 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002996
Alexander Duyck2c4af692011-07-15 07:29:55 +00002997 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002998 switch (adapter->hw.mac.type) {
2999 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003000 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003001 break;
3002 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003003 case ixgbe_mac_X550:
3004 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003005 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00003006 mask |= IXGBE_EIMS_TS;
3007 break;
3008 default:
3009 break;
3010 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003011 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07003012 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003013 switch (adapter->hw.mac.type) {
3014 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003015 mask |= IXGBE_EIMS_GPI_SDP1(hw);
3016 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003017 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00003018 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003019 case ixgbe_mac_X550:
3020 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003021 case ixgbe_mac_x550em_a:
3022 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07003023 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07003024 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07003025 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07003026 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
3027 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00003028 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003029 mask |= IXGBE_EIMS_MAILBOX;
3030 break;
3031 default:
3032 break;
3033 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003034
Alexander Duyck2c4af692011-07-15 07:29:55 +00003035 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
3036 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
3037 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003038
Alexander Duyck2c4af692011-07-15 07:29:55 +00003039 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
3040 if (queues)
3041 ixgbe_irq_enable_queues(adapter, ~0);
3042 if (flush)
3043 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003044}
3045
Alexander Duyck2c4af692011-07-15 07:29:55 +00003046static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003047{
Alexander Duyck2c4af692011-07-15 07:29:55 +00003048 struct ixgbe_adapter *adapter = data;
3049 struct ixgbe_hw *hw = &adapter->hw;
3050 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003051
Alexander Duyck2c4af692011-07-15 07:29:55 +00003052 /*
3053 * Workaround for Silicon errata. Use clear-by-write instead
3054 * of clear-by-read. Reading with EICS will return the
3055 * interrupt causes without clearing, which later be done
3056 * with the write to EICR.
3057 */
3058 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00003059
3060 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08003061 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00003062 * the bits are high when ixgbe_msix_other is called. There is a race
3063 * condition otherwise which results in possible performance loss
3064 * especially if the ixgbe_msix_other interrupt is triggering
3065 * consistently (as it would when PPS is turned on for the X540 device)
3066 */
3067 eicr &= 0xFFFF0000;
3068
Alexander Duyck2c4af692011-07-15 07:29:55 +00003069 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003070
Alexander Duyck2c4af692011-07-15 07:29:55 +00003071 if (eicr & IXGBE_EICR_LSC)
3072 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003073
Alexander Duyck2c4af692011-07-15 07:29:55 +00003074 if (eicr & IXGBE_EICR_MAILBOX)
3075 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003076
Alexander Duyck2c4af692011-07-15 07:29:55 +00003077 switch (hw->mac.type) {
3078 case ixgbe_mac_82599EB:
3079 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003080 case ixgbe_mac_X550:
3081 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003082 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07003083 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
3084 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
3085 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
3086 ixgbe_service_event_schedule(adapter);
3087 IXGBE_WRITE_REG(hw, IXGBE_EICR,
3088 IXGBE_EICR_GPI_SDP0_X540);
3089 }
Don Skidmored773ce22014-02-25 17:58:53 -08003090 if (eicr & IXGBE_EICR_ECC) {
3091 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003092 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003093 ixgbe_service_event_schedule(adapter);
3094 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3095 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003096 /* Handle Flow Director Full threshold interrupt */
3097 if (eicr & IXGBE_EICR_FLOW_DIR) {
3098 int reinit_count = 0;
3099 int i;
3100 for (i = 0; i < adapter->num_tx_queues; i++) {
3101 struct ixgbe_ring *ring = adapter->tx_ring[i];
3102 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
3103 &ring->state))
3104 reinit_count++;
3105 }
3106 if (reinit_count) {
3107 /* no more flow director interrupts until after init */
3108 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
3109 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
3110 ixgbe_service_event_schedule(adapter);
3111 }
3112 }
3113 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003114 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003115 break;
3116 default:
3117 break;
Auke Kok9a799d72007-09-15 14:07:45 -07003118 }
3119
Alexander Duyck2c4af692011-07-15 07:29:55 +00003120 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003121
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003122 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003123 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003124
Alexander Duyck2c4af692011-07-15 07:29:55 +00003125 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00003126 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00003127 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003128
Alexander Duyck2c4af692011-07-15 07:29:55 +00003129 return IRQ_HANDLED;
3130}
3131
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003132static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07003133{
3134 struct ixgbe_q_vector *q_vector = data;
3135
Auke Kok9a799d72007-09-15 14:07:45 -07003136 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003137
3138 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07003139 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003140
3141 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003142}
3143
Auke Kok9a799d72007-09-15 14:07:45 -07003144/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00003145 * ixgbe_poll - NAPI Rx polling callback
3146 * @napi: structure for representing this polling device
3147 * @budget: how many packets driver is allowed to clean
3148 *
3149 * This function is used for legacy and MSI, NAPI mode
3150 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00003151int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00003152{
3153 struct ixgbe_q_vector *q_vector =
3154 container_of(napi, struct ixgbe_q_vector, napi);
3155 struct ixgbe_adapter *adapter = q_vector->adapter;
3156 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003157 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00003158 bool clean_complete = true;
3159
3160#ifdef CONFIG_IXGBE_DCA
3161 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
3162 ixgbe_update_dca(q_vector);
3163#endif
3164
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003165 ixgbe_for_each_ring(ring, q_vector->tx) {
3166 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
3167 clean_complete = false;
3168 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003169
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08003170 /* Exit if we are called by netpoll */
3171 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003172 return budget;
3173
Alexander Duyckeb01b972012-02-08 07:51:27 +00003174 /* attempt to distribute budget to each queue fairly, but don't allow
3175 * the budget to go below 1 because we'll exit polling */
3176 if (q_vector->rx.count > 1)
3177 per_ring_budget = max(budget/q_vector->rx.count, 1);
3178 else
3179 per_ring_budget = budget;
3180
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003181 ixgbe_for_each_ring(ring, q_vector->rx) {
3182 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
3183 per_ring_budget);
3184
3185 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003186 if (cleaned >= per_ring_budget)
3187 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003188 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003189
3190 /* If all work not completed, return budget and keep polling */
3191 if (!clean_complete)
3192 return budget;
3193
3194 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003195 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003196 if (adapter->rx_itr_setting & 1)
3197 ixgbe_set_itr(q_vector);
3198 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003199 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00003200
Paolo Abeni4b732cd2016-06-15 15:37:59 +02003201 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003202}
3203
3204/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003205 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3206 * @adapter: board private structure
3207 *
3208 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3209 * interrupts from the kernel.
3210 **/
3211static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
3212{
3213 struct net_device *netdev = adapter->netdev;
Tony Nguyene61e4c82017-05-12 11:38:07 -07003214 unsigned int ri = 0, ti = 0;
Alexander Duyck207867f2011-07-15 03:05:37 +00003215 int vector, err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003216
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003217 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003218 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00003219 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08003220
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003221 if (q_vector->tx.ring && q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003222 snprintf(q_vector->name, sizeof(q_vector->name),
3223 "%s-TxRx-%u", netdev->name, ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003224 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003225 } else if (q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003226 snprintf(q_vector->name, sizeof(q_vector->name),
3227 "%s-rx-%u", netdev->name, ri++);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003228 } else if (q_vector->tx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003229 snprintf(q_vector->name, sizeof(q_vector->name),
3230 "%s-tx-%u", netdev->name, ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003231 } else {
3232 /* skip this unused q_vector */
3233 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003234 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003235 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
3236 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003237 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00003238 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00003239 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003240 goto free_queue_irqs;
3241 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003242 /* If Flow Director is enabled, set interrupt affinity */
3243 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3244 /* assign the mask for this irq */
3245 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003246 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003247 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003248 }
3249
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003250 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003251 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003252 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003253 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003254 goto free_queue_irqs;
3255 }
3256
3257 return 0;
3258
3259free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003260 while (vector) {
3261 vector--;
3262 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3263 NULL);
3264 free_irq(adapter->msix_entries[vector].vector,
3265 adapter->q_vector[vector]);
3266 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003267 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3268 pci_disable_msix(adapter->pdev);
3269 kfree(adapter->msix_entries);
3270 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003271 return err;
3272}
3273
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003274/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003275 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003276 * @irq: interrupt number
3277 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003278 **/
3279static irqreturn_t ixgbe_intr(int irq, void *data)
3280{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003281 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003282 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003283 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003284 u32 eicr;
3285
Don Skidmore54037502009-02-21 15:42:56 -08003286 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003287 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003288 * before the read of EICR.
3289 */
3290 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3291
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003292 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003293 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003294 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003295 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003296 /*
3297 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003298 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003299 * have disabled interrupts due to EIAM
3300 * finish the workaround of silicon errata on 82598. Unmask
3301 * the interrupt that we masked before the EICR read.
3302 */
3303 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3304 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003305 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003306 }
Auke Kok9a799d72007-09-15 14:07:45 -07003307
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003308 if (eicr & IXGBE_EICR_LSC)
3309 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003310
Alexander Duyckbd508172010-11-16 19:27:03 -08003311 switch (hw->mac.type) {
3312 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003313 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003314 /* Fall through */
3315 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003316 case ixgbe_mac_X550:
3317 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003318 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003319 if (eicr & IXGBE_EICR_ECC) {
3320 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003321 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003322 ixgbe_service_event_schedule(adapter);
3323 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3324 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003325 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003326 break;
3327 default:
3328 break;
3329 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003330
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003331 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003332 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003333 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003334
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003335 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003336 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003337
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003338 /*
3339 * re-enable link(maybe) and non-queue interrupts, no flush.
3340 * ixgbe_poll will re-enable the queue interrupts
3341 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003342 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3343 ixgbe_irq_enable(adapter, false, false);
3344
Auke Kok9a799d72007-09-15 14:07:45 -07003345 return IRQ_HANDLED;
3346}
3347
3348/**
3349 * ixgbe_request_irq - initialize interrupts
3350 * @adapter: board private structure
3351 *
3352 * Attempts to configure interrupts using the best available
3353 * capabilities of the hardware and kernel.
3354 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003355static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003356{
3357 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003358 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003359
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003360 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003361 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003362 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003363 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003364 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003365 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003366 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003367 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003368
Alexander Duyckde88eee2012-02-08 07:49:59 +00003369 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003370 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003371
Auke Kok9a799d72007-09-15 14:07:45 -07003372 return err;
3373}
3374
3375static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3376{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003377 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003378
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003379 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003380 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003381 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003382 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003383
Mark Rustad1fa71252016-09-28 15:36:38 -07003384 if (!adapter->msix_entries)
3385 return;
3386
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003387 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3388 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3389 struct msix_entry *entry = &adapter->msix_entries[vector];
3390
3391 /* free only the irqs that were actually requested */
3392 if (!q_vector->rx.ring && !q_vector->tx.ring)
3393 continue;
3394
3395 /* clear the affinity_mask in the IRQ descriptor */
3396 irq_set_affinity_hint(entry->vector, NULL);
3397
3398 free_irq(entry->vector, q_vector);
3399 }
3400
Babu Moger90c6f872016-06-18 17:40:47 -07003401 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003402}
3403
3404/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003405 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3406 * @adapter: board private structure
3407 **/
3408static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3409{
Alexander Duyckbd508172010-11-16 19:27:03 -08003410 switch (adapter->hw.mac.type) {
3411 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003412 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003413 break;
3414 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003415 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003416 case ixgbe_mac_X550:
3417 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003418 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003419 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3420 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003421 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003422 break;
3423 default:
3424 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003425 }
3426 IXGBE_WRITE_FLUSH(&adapter->hw);
3427 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003428 int vector;
3429
3430 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3431 synchronize_irq(adapter->msix_entries[vector].vector);
3432
3433 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003434 } else {
3435 synchronize_irq(adapter->pdev->irq);
3436 }
3437}
3438
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003439/**
Auke Kok9a799d72007-09-15 14:07:45 -07003440 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
Tony Nguyen5ba643c2017-12-04 11:28:30 -08003441 * @adapter: board private structure
Auke Kok9a799d72007-09-15 14:07:45 -07003442 *
3443 **/
3444static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3445{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003446 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003447
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003448 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003449
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003450 ixgbe_set_ivar(adapter, 0, 0, 0);
3451 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003452
Emil Tantilov396e7992010-07-01 20:05:12 +00003453 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003454}
3455
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003456/**
3457 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3458 * @adapter: board private structure
3459 * @ring: structure containing ring specific data
3460 *
3461 * Configure the Tx descriptor ring after a reset.
3462 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003463void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3464 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003465{
3466 struct ixgbe_hw *hw = &adapter->hw;
3467 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003468 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003469 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003470 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003471
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003472 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003473 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003474 IXGBE_WRITE_FLUSH(hw);
3475
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003476 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003477 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003478 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3479 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3480 ring->count * sizeof(union ixgbe_adv_tx_desc));
3481 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3482 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003483 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003484
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003485 /*
3486 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003487 * higher than 1 when:
3488 * - ITR is 0 as it could cause false TX hangs
3489 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003490 *
3491 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3492 * to or less than the number of on chip descriptors, which is
3493 * currently 40.
3494 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003495 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003496 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003497 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003498 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003499
Alexander Duycke954b372012-02-08 07:49:38 +00003500 /*
3501 * Setting PTHRESH to 32 both improves performance
3502 * and avoids a TX hang with DFP enabled
3503 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003504 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003505 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003506
3507 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003508 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003509 ring->atr_sample_rate = adapter->atr_sample_rate;
3510 ring->atr_count = 0;
3511 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3512 } else {
3513 ring->atr_sample_rate = 0;
3514 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003515
Alexander Duyckfd786b72013-01-12 06:33:31 +00003516 /* initialize XPS */
3517 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3518 struct ixgbe_q_vector *q_vector = ring->q_vector;
3519
3520 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003521 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003522 &q_vector->affinity_mask,
3523 ring->queue_index);
3524 }
3525
John Fastabendc84d3242010-11-16 19:27:12 -08003526 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3527
Alexander Duyckffed21b2017-01-17 08:37:29 -08003528 /* reinitialize tx_buffer_info */
3529 memset(ring->tx_buffer_info, 0,
3530 sizeof(struct ixgbe_tx_buffer) * ring->count);
3531
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003532 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003533 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3534
3535 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3536 if (hw->mac.type == ixgbe_mac_82598EB &&
3537 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3538 return;
3539
3540 /* poll to verify queue is enabled */
3541 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003542 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003543 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3544 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3545 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003546 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003547}
3548
Alexander Duyck120ff942010-08-19 13:34:50 +00003549static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3550{
3551 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003552 u32 rttdcs, mtqc;
Alexander Duyck0efbf122017-11-22 10:57:11 -08003553 u8 tcs = adapter->hw_tcs;
Alexander Duyck120ff942010-08-19 13:34:50 +00003554
3555 if (hw->mac.type == ixgbe_mac_82598EB)
3556 return;
3557
3558 /* disable the arbiter while setting MTQC */
3559 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3560 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3561 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3562
3563 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003564 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3565 mtqc = IXGBE_MTQC_VT_ENA;
3566 if (tcs > 4)
3567 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3568 else if (tcs > 1)
3569 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003570 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3571 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003572 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003573 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003574 mtqc |= IXGBE_MTQC_64VF;
3575 } else {
3576 if (tcs > 4)
3577 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3578 else if (tcs > 1)
3579 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3580 else
3581 mtqc = IXGBE_MTQC_64Q_1PB;
3582 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003583
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003584 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003585
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003586 /* Enable Security TX Buffer IFG for multiple pb */
3587 if (tcs) {
3588 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3589 sectx |= IXGBE_SECTX_DCB;
3590 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003591 }
3592
3593 /* re-enable the arbiter */
3594 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3595 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3596}
3597
Auke Kok9a799d72007-09-15 14:07:45 -07003598/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003599 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003600 * @adapter: board private structure
3601 *
3602 * Configure the Tx unit of the MAC after a reset.
3603 **/
3604static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3605{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003606 struct ixgbe_hw *hw = &adapter->hw;
3607 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003608 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003609
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003610 ixgbe_setup_mtqc(adapter);
3611
3612 if (hw->mac.type != ixgbe_mac_82598EB) {
3613 /* DMATXCTL.EN must be before Tx queues are enabled */
3614 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3615 dmatxctl |= IXGBE_DMATXCTL_TE;
3616 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3617 }
3618
Auke Kok9a799d72007-09-15 14:07:45 -07003619 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003620 for (i = 0; i < adapter->num_tx_queues; i++)
3621 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07003622 for (i = 0; i < adapter->num_xdp_queues; i++)
3623 ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003624}
3625
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003626static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3627 struct ixgbe_ring *ring)
3628{
3629 struct ixgbe_hw *hw = &adapter->hw;
3630 u8 reg_idx = ring->reg_idx;
3631 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3632
3633 srrctl |= IXGBE_SRRCTL_DROP_EN;
3634
3635 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3636}
3637
3638static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3639 struct ixgbe_ring *ring)
3640{
3641 struct ixgbe_hw *hw = &adapter->hw;
3642 u8 reg_idx = ring->reg_idx;
3643 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3644
3645 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3646
3647 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3648}
3649
3650#ifdef CONFIG_IXGBE_DCB
3651void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3652#else
3653static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3654#endif
3655{
3656 int i;
3657 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3658
3659 if (adapter->ixgbe_ieee_pfc)
3660 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3661
3662 /*
3663 * We should set the drop enable bit if:
3664 * SR-IOV is enabled
3665 * or
3666 * Number of Rx queues > 1 and flow control is disabled
3667 *
3668 * This allows us to avoid head of line blocking for security
3669 * and performance reasons.
3670 */
3671 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3672 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3673 for (i = 0; i < adapter->num_rx_queues; i++)
3674 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3675 } else {
3676 for (i = 0; i < adapter->num_rx_queues; i++)
3677 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3678 }
3679}
3680
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003681#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003682
Yi Zoua6616b42009-08-06 13:05:23 +00003683static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003684 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003685{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003686 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003687 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003688 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003689
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003690 if (hw->mac.type == ixgbe_mac_82598EB) {
3691 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3692
3693 /*
3694 * if VMDq is not active we must program one srrctl register
3695 * per RSS queue since we have enabled RDRXCTL.MVMEN
3696 */
3697 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003698 }
3699
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003700 /* configure header buffer length, needed for RSC */
3701 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003702
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003703 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003704 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3705 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3706 else
3707 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003708
3709 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003710 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003711
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003712 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003713}
3714
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003715/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003716 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003717 * @adapter: device handle
3718 *
3719 * - 82598/82599/X540: 128
3720 * - X550(non-SRIOV mode): 512
3721 * - X550(SRIOV mode): 64
3722 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003723u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003724{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003725 if (adapter->hw.mac.type < ixgbe_mac_X550)
3726 return 128;
3727 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3728 return 64;
3729 else
3730 return 512;
3731}
3732
3733/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003734 * ixgbe_store_key - Write the RSS key to HW
3735 * @adapter: device handle
3736 *
3737 * Write the RSS key stored in adapter.rss_key to HW.
3738 */
3739void ixgbe_store_key(struct ixgbe_adapter *adapter)
3740{
3741 struct ixgbe_hw *hw = &adapter->hw;
3742 int i;
3743
3744 for (i = 0; i < 10; i++)
3745 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3746}
3747
3748/**
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003749 * ixgbe_init_rss_key - Initialize adapter RSS key
3750 * @adapter: device handle
3751 *
3752 * Allocates and initializes the RSS key if it is not allocated.
3753 **/
3754static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
3755{
3756 u32 *rss_key;
3757
3758 if (!adapter->rss_key) {
3759 rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
3760 if (unlikely(!rss_key))
3761 return -ENOMEM;
3762
3763 netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
3764 adapter->rss_key = rss_key;
3765 }
3766
3767 return 0;
3768}
3769
3770/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003771 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003772 * @adapter: device handle
3773 *
3774 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3775 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003776void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003777{
3778 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003779 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003780 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003781 u32 indices_multi;
3782 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003783
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003784 /* Fill out the redirection table as follows:
3785 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3786 * indices.
3787 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3788 * - X550: 8 bit wide entries containing 6 bit RSS index
3789 */
3790 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3791 indices_multi = 0x11;
3792 else
3793 indices_multi = 0x1;
3794
3795 /* Write redirection table to HW */
3796 for (i = 0; i < reta_entries; i++) {
3797 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3798 if ((i & 3) == 3) {
3799 if (i < 128)
3800 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3801 else
3802 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3803 reta);
3804 reta = 0;
3805 }
3806 }
3807}
3808
3809/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003810 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003811 * @adapter: device handle
3812 *
3813 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3814 */
3815static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3816{
3817 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3818 struct ixgbe_hw *hw = &adapter->hw;
3819 u32 vfreta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003820
3821 /* Write redirection table to HW */
3822 for (i = 0; i < reta_entries; i++) {
Alexander Duyck2af62c52017-11-22 10:56:28 -08003823 u16 pool = adapter->num_rx_pools;
3824
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003825 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
Alexander Duyck2af62c52017-11-22 10:56:28 -08003826 if ((i & 3) != 3)
3827 continue;
3828
3829 while (pool--)
3830 IXGBE_WRITE_REG(hw,
3831 IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)),
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003832 vfreta);
Alexander Duyck2af62c52017-11-22 10:56:28 -08003833 vfreta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003834 }
3835}
3836
3837static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3838{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003839 u32 i, j;
3840 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3841 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3842
Alexander Duycke24fcf22016-09-07 20:28:24 -07003843 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003844 * make full use of any rings they may have. We will use the
3845 * PSRTYPE register to control how many rings we use within the PF.
3846 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003847 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3848 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003849
Alexander Duyck05abb122010-08-19 13:35:41 +00003850 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003851 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003852
Alexander Duyck05abb122010-08-19 13:35:41 +00003853 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003854 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3855
Don Skidmore0f9b2322014-11-18 09:35:08 +00003856 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003857 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003858 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003859
3860 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003861 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003862
3863 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003864}
3865
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003866static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003867{
3868 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003869 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003870 int i, j;
3871
3872 /* Fill out hash function seeds */
Alexander Duyck2af62c52017-11-22 10:56:28 -08003873 for (i = 0; i < 10; i++) {
3874 u16 pool = adapter->num_rx_pools;
3875
3876 while (pool--)
3877 IXGBE_WRITE_REG(hw,
3878 IXGBE_PFVFRSSRK(i, VMDQ_P(pool)),
3879 *(adapter->rss_key + i));
3880 }
Don Skidmore0f9b2322014-11-18 09:35:08 +00003881
3882 /* Fill out the redirection table */
3883 for (i = 0, j = 0; i < 64; i++, j++) {
3884 if (j == rss_i)
3885 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003886
3887 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003888 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003889
3890 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003891}
3892
3893static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3894{
3895 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003896 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003897 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003898
3899 /* Disable indicating checksum in descriptor, enables RSS hash */
3900 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3901 rxcsum |= IXGBE_RXCSUM_PCSD;
3902 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3903
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003904 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003905 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003906 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003907 } else {
Alexander Duyck0efbf122017-11-22 10:57:11 -08003908 u8 tcs = adapter->hw_tcs;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003909
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003910 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3911 if (tcs > 4)
3912 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3913 else if (tcs > 1)
3914 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003915 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3916 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003917 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3918 else
3919 mrqc = IXGBE_MRQC_VMDQRSS64EN;
Emil Tantilove6b41c82017-04-25 11:31:06 -07003920
3921 /* Enable L3/L4 for Tx Switched packets */
3922 mrqc |= IXGBE_MRQC_L3L4TXSWEN;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003923 } else {
3924 if (tcs > 4)
3925 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3926 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003927 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3928 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003929 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003930 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003931 }
3932
Alexander Duyck05abb122010-08-19 13:35:41 +00003933 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003934 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3935 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3936 IXGBE_MRQC_RSS_FIELD_IPV6 |
3937 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003938
Alexander Duyckef6afc02012-02-08 07:51:53 +00003939 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003940 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003941 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003942 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003943
Don Skidmore0f9b2322014-11-18 09:35:08 +00003944 if ((hw->mac.type >= ixgbe_mac_X550) &&
3945 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
Alexander Duyck2af62c52017-11-22 10:56:28 -08003946 u16 pool = adapter->num_rx_pools;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003947
3948 /* Enable VF RSS mode */
3949 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3950 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3951
3952 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003953 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003954 vfmrqc = IXGBE_MRQC_RSSEN;
3955 vfmrqc |= rss_field;
Alexander Duyck2af62c52017-11-22 10:56:28 -08003956
3957 while (pool--)
3958 IXGBE_WRITE_REG(hw,
3959 IXGBE_PFVFMRQC(VMDQ_P(pool)),
3960 vfmrqc);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003961 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003962 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003963 mrqc |= rss_field;
3964 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3965 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003966}
3967
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003968/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003969 * ixgbe_configure_rscctl - enable RSC for the indicated ring
Tony Nguyen5ba643c2017-12-04 11:28:30 -08003970 * @adapter: address of board private structure
3971 * @ring: structure containing ring specific data
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003972 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003973static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003974 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003975{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003976 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003977 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003978 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003979
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003980 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003981 return;
3982
Alexander Duyck73670962010-08-19 13:38:34 +00003983 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003984 rscctrl |= IXGBE_RSCCTL_RSCEN;
3985 /*
3986 * we must limit the number of descriptors so that the
3987 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003988 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003989 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003990 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003991 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003992}
3993
Alexander Duyck9e10e042010-08-19 13:40:06 +00003994#define IXGBE_MAX_RX_DESC_POLL 10
3995static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3996 struct ixgbe_ring *ring)
3997{
3998 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003999 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4000 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004001 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004002
Mark Rustadb0483c82014-01-14 18:53:17 -08004003 if (ixgbe_removed(hw->hw_addr))
4004 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004005 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
4006 if (hw->mac.type == ixgbe_mac_82598EB &&
4007 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4008 return;
4009
4010 do {
Don Skidmore032b4322011-03-18 09:32:53 +00004011 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004012 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4013 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
4014
4015 if (!wait_loop) {
4016 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
4017 "the polling period\n", reg_idx);
4018 }
4019}
4020
Yi Zou2d39d572011-01-06 14:29:56 +00004021void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
4022 struct ixgbe_ring *ring)
4023{
4024 struct ixgbe_hw *hw = &adapter->hw;
4025 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4026 u32 rxdctl;
4027 u8 reg_idx = ring->reg_idx;
4028
Mark Rustadb0483c82014-01-14 18:53:17 -08004029 if (ixgbe_removed(hw->hw_addr))
4030 return;
Yi Zou2d39d572011-01-06 14:29:56 +00004031 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4032 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
4033
4034 /* write value back with RXDCTL.ENABLE bit cleared */
4035 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4036
4037 if (hw->mac.type == ixgbe_mac_82598EB &&
4038 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4039 return;
4040
4041 /* the hardware may take up to 100us to really disable the rx queue */
4042 do {
4043 udelay(10);
4044 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4045 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
4046
4047 if (!wait_loop) {
4048 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
4049 "the polling period\n", reg_idx);
4050 }
4051}
4052
Alexander Duyck84418e32010-08-19 13:40:54 +00004053void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
4054 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00004055{
4056 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004057 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00004058 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004059 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004060 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00004061
Alexander Duyck9e10e042010-08-19 13:40:06 +00004062 /* disable queue to avoid issues while updating state */
4063 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00004064 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004065
Alexander Duyckacd37172010-08-19 13:36:05 +00004066 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
4067 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
4068 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
4069 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08004070 /* Force flushing of IXGBE_RDLEN to prevent MDD */
4071 IXGBE_WRITE_FLUSH(hw);
4072
Alexander Duyckacd37172010-08-19 13:36:05 +00004073 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
4074 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08004075 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004076
4077 ixgbe_configure_srrctl(adapter, ring);
4078 ixgbe_configure_rscctl(adapter, ring);
4079
4080 if (hw->mac.type == ixgbe_mac_82598EB) {
4081 /*
4082 * enable cache line friendly hardware writes:
4083 * PTHRESH=32 descriptors (half the internal cache),
4084 * this also removes ugly rx_no_buffer_count increment
4085 * HTHRESH=4 descriptors (to minimize latency on fetch)
4086 * WTHRESH=8 burst writeback up to two cache lines
4087 */
4088 rxdctl &= ~0x3FFFFF;
4089 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004090#if (PAGE_SIZE < 8192)
Emil Tantilov2bafa8f2018-01-12 14:02:56 -08004091 /* RXDCTL.RLPML does not work on 82599 */
4092 } else if (hw->mac.type != ixgbe_mac_82599EB) {
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004093 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
4094 IXGBE_RXDCTL_RLPML_EN);
4095
Emil Tantilov2bafa8f2018-01-12 14:02:56 -08004096 /* Limit the maximum frame size so we don't overrun the skb.
4097 * This can happen in SRIOV mode when the MTU of the VF is
4098 * higher than the MTU of the PF.
4099 */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004100 if (ring_uses_build_skb(ring) &&
4101 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
Alexander Duyck541ea692017-03-02 15:01:05 -08004102 rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004103 IXGBE_RXDCTL_RLPML_EN;
4104#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00004105 }
4106
Alexander Duyckffed21b2017-01-17 08:37:29 -08004107 /* initialize rx_buffer_info */
4108 memset(ring->rx_buffer_info, 0,
4109 sizeof(struct ixgbe_rx_buffer) * ring->count);
4110
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004111 /* initialize Rx descriptor 0 */
4112 rx_desc = IXGBE_RX_DESC(ring, 0);
4113 rx_desc->wb.upper.length = 0;
4114
Alexander Duyck9e10e042010-08-19 13:40:06 +00004115 /* enable receive descriptor ring */
4116 rxdctl |= IXGBE_RXDCTL_ENABLE;
4117 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4118
4119 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00004120 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00004121}
4122
Alexander Duyck48654522010-08-19 13:36:27 +00004123static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
4124{
4125 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004126 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck2af62c52017-11-22 10:56:28 -08004127 u16 pool = adapter->num_rx_pools;
Alexander Duyck48654522010-08-19 13:36:27 +00004128
4129 /* PSRTYPE must be initialized in non 82598 adapters */
4130 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004131 IXGBE_PSRTYPE_UDPHDR |
4132 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00004133 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004134 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00004135
4136 if (hw->mac.type == ixgbe_mac_82598EB)
4137 return;
4138
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004139 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004140 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004141 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004142 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00004143
Alexander Duyck2af62c52017-11-22 10:56:28 -08004144 while (pool--)
John Fastabend2a47fa42013-11-06 09:54:52 -08004145 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00004146}
4147
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004148static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
4149{
4150 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck81d4e912018-04-03 17:16:09 -04004151 u16 pool = adapter->num_rx_pools;
4152 u32 reg_offset, vf_shift, vmolr;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004153 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00004154 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004155
4156 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
4157 return;
4158
4159 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00004160 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
4161 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004162 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004163 vmdctl |= IXGBE_VT_CTL_REPLEN;
4164 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004165
Alexander Duyck81d4e912018-04-03 17:16:09 -04004166 /* accept untagged packets until a vlan tag is
4167 * specifically set for the VMDQ queue/pool
4168 */
4169 vmolr = IXGBE_VMOLR_AUPE;
4170 while (pool--)
4171 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(pool)), vmolr);
4172
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004173 vf_shift = VMDQ_P(0) % 32;
4174 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004175
4176 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07004177 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004178 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07004179 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004180 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07004181 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00004182 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004183
4184 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004185 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004186
Alexander Duyck16369562015-11-02 17:10:13 -08004187 /* clear VLAN promisc flag so VFTA will be updated if necessary */
4188 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4189
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004190 /*
4191 * Set up VF register offsets for selected VT Mode,
4192 * i.e. 32 or 64 VFs for SR-IOV
4193 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00004194 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4195 case IXGBE_82599_VMDQ_8Q_MASK:
4196 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
4197 break;
4198 case IXGBE_82599_VMDQ_4Q_MASK:
4199 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
4200 break;
4201 default:
4202 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
4203 break;
4204 }
4205
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004206 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4207
Greg Rosede4c7f62011-09-29 05:57:33 +00004208 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07004209 /* configure spoof checking */
4210 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
4211 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03004212
4213 /* Enable/Disable RSS query feature */
4214 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
4215 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00004216 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004217}
4218
Alexander Duyck477de6e2010-08-19 13:38:11 +00004219static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004220{
Auke Kok9a799d72007-09-15 14:07:45 -07004221 struct ixgbe_hw *hw = &adapter->hw;
4222 struct net_device *netdev = adapter->netdev;
4223 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004224 struct ixgbe_ring *rx_ring;
4225 int i;
4226 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00004227
Alexander Duyck477de6e2010-08-19 13:38:11 +00004228#ifdef IXGBE_FCOE
4229 /* adjust max frame to be able to do baby jumbo for FCoE */
4230 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
4231 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
4232 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4233
4234#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00004235
4236 /* adjust max frame to be at least the size of a standard frame */
4237 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
4238 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
4239
Alexander Duyck477de6e2010-08-19 13:38:11 +00004240 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
4241 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
4242 mhadd &= ~IXGBE_MHADD_MFS_MASK;
4243 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
4244
4245 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07004246 }
4247
Auke Kok9a799d72007-09-15 14:07:45 -07004248 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004249 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
4250 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07004251 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4252
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004253 /*
4254 * Setup the HW Rx Head and Tail Descriptor Pointers and
4255 * the Base and Length of the Rx Descriptor Ring
4256 */
Auke Kok9a799d72007-09-15 14:07:45 -07004257 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004258 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004259
4260 clear_ring_rsc_enabled(rx_ring);
4261 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004262 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004263
Alexander Duyck7d637bc2010-11-16 19:26:56 -08004264 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4265 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004266
4267 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
4268 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004269
Alexander Duyck6f429222017-01-17 08:37:13 -08004270 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004271 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
4272 continue;
4273
4274 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4275
4276#if (PAGE_SIZE < 8192)
4277 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4278 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4279
Alexander Duyck541ea692017-03-02 15:01:05 -08004280 if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
4281 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004282 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4283#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00004284 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00004285}
4286
Alexander Duyck73670962010-08-19 13:38:34 +00004287static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
4288{
4289 struct ixgbe_hw *hw = &adapter->hw;
4290 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
4291
4292 switch (hw->mac.type) {
4293 case ixgbe_mac_82598EB:
4294 /*
4295 * For VMDq support of different descriptor types or
4296 * buffer sizes through the use of multiple SRRCTL
4297 * registers, RDRXCTL.MVMEN must be set to 1
4298 *
4299 * also, the manual doesn't mention it clearly but DCA hints
4300 * will only use queue 0's tags unless this bit is set. Side
4301 * effects of setting this bit are only that SRRCTL must be
4302 * fully programmed [0..15]
4303 */
4304 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4305 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004306 case ixgbe_mac_X550:
4307 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004308 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004309 if (adapter->num_vfs)
4310 rdrxctl |= IXGBE_RDRXCTL_PSP;
Tony Nguyen93df9462017-05-31 04:43:47 -07004311 /* fall through */
Alexander Duyck73670962010-08-19 13:38:34 +00004312 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004313 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004314 /* Disable RSC for ACK packets */
4315 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4316 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4317 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4318 /* hardware requires some bits to be set by default */
4319 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4320 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4321 break;
4322 default:
4323 /* We should do nothing since we don't know this hardware */
4324 return;
4325 }
4326
4327 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4328}
4329
Alexander Duyck477de6e2010-08-19 13:38:11 +00004330/**
4331 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4332 * @adapter: board private structure
4333 *
4334 * Configure the Rx unit of the MAC after a reset.
4335 **/
4336static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4337{
4338 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004339 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004340 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004341
4342 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004343 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004344
4345 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004346 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004347
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004348 /* RSC Setup */
4349 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4350 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4351 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4352 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004353
4354 /* disable NFS filtering */
4355 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004356 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4357
Alexander Duyck9e10e042010-08-19 13:40:06 +00004358 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004359 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004360
Alexander Duyck477de6e2010-08-19 13:38:11 +00004361 /* set_rx_buffer_len must be called before ring initialization */
4362 ixgbe_set_rx_buffer_len(adapter);
4363
4364 /*
4365 * Setup the HW Rx Head and Tail Descriptor Pointers and
4366 * the Base and Length of the Rx Descriptor Ring
4367 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004368 for (i = 0; i < adapter->num_rx_queues; i++)
4369 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004370
Don Skidmore1f9ac572015-03-13 13:54:30 -07004371 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004372 /* disable drop enable for 82598 parts */
4373 if (hw->mac.type == ixgbe_mac_82598EB)
4374 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4375
4376 /* enable all receives */
4377 rxctrl |= IXGBE_RXCTRL_RXEN;
4378 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004379}
4380
Patrick McHardy80d5c362013-04-19 02:04:28 +00004381static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4382 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004383{
4384 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004385 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004386
4387 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004388 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4389 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4390
Jesse Grossf62bbb52010-10-20 13:56:10 +00004391 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004392
4393 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004394}
4395
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004396static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4397{
4398 u32 vlvf;
4399 int idx;
4400
4401 /* short cut the special case */
4402 if (vlan == 0)
4403 return 0;
4404
4405 /* Search for the vlan id in the VLVF entries */
4406 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4407 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4408 if ((vlvf & VLAN_VID_MASK) == vlan)
4409 break;
4410 }
4411
4412 return idx;
4413}
4414
4415void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4416{
4417 struct ixgbe_hw *hw = &adapter->hw;
4418 u32 bits, word;
4419 int idx;
4420
4421 idx = ixgbe_find_vlvf_entry(hw, vid);
4422 if (!idx)
4423 return;
4424
4425 /* See if any other pools are set for this VLAN filter
4426 * entry other than the PF.
4427 */
4428 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004429 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004430 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4431
4432 /* Disable the filter so this falls into the default pool. */
4433 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4434 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4435 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4436 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4437 }
4438}
4439
Patrick McHardy80d5c362013-04-19 02:04:28 +00004440static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4441 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004442{
4443 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004444 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004445
Auke Kok9a799d72007-09-15 14:07:45 -07004446 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004447 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004448 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4449
Jesse Grossf62bbb52010-10-20 13:56:10 +00004450 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004451
4452 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004453}
4454
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004455/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004456 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4457 * @adapter: driver data
4458 */
4459static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4460{
4461 struct ixgbe_hw *hw = &adapter->hw;
4462 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004463 int i, j;
4464
4465 switch (hw->mac.type) {
4466 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004467 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4468 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004469 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4470 break;
4471 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004472 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004473 case ixgbe_mac_X550:
4474 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004475 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004476 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004477 struct ixgbe_ring *ring = adapter->rx_ring[i];
4478
Alexander Duyck68ae7422017-11-22 10:56:52 -08004479 if (!netif_is_ixgbe(ring->netdev))
John Fastabend2a47fa42013-11-06 09:54:52 -08004480 continue;
Alexander Duyck68ae7422017-11-22 10:56:52 -08004481
John Fastabend2a47fa42013-11-06 09:54:52 -08004482 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004483 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4484 vlnctrl &= ~IXGBE_RXDCTL_VME;
4485 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4486 }
4487 break;
4488 default:
4489 break;
4490 }
4491}
4492
4493/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004494 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004495 * @adapter: driver data
4496 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004497static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004498{
4499 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004500 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004501 int i, j;
4502
4503 switch (hw->mac.type) {
4504 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004505 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4506 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004507 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4508 break;
4509 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004510 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004511 case ixgbe_mac_X550:
4512 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004513 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004514 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004515 struct ixgbe_ring *ring = adapter->rx_ring[i];
4516
Alexander Duyck68ae7422017-11-22 10:56:52 -08004517 if (!netif_is_ixgbe(ring->netdev))
John Fastabend2a47fa42013-11-06 09:54:52 -08004518 continue;
Alexander Duyck68ae7422017-11-22 10:56:52 -08004519
John Fastabend2a47fa42013-11-06 09:54:52 -08004520 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004521 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4522 vlnctrl |= IXGBE_RXDCTL_VME;
4523 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4524 }
4525 break;
4526 default:
4527 break;
4528 }
4529}
4530
Alexander Duyck16369562015-11-02 17:10:13 -08004531static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4532{
4533 struct ixgbe_hw *hw = &adapter->hw;
4534 u32 vlnctrl, i;
4535
Alexander Duyckf60439b2016-08-11 14:51:56 -07004536 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4537
Emil Tantilov691e4122016-08-22 16:17:46 -07004538 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4539 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4540 vlnctrl |= IXGBE_VLNCTRL_VFE;
4541 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4542 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004543 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004544 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4545 return;
4546 }
4547
Emil Tantilov691e4122016-08-22 16:17:46 -07004548 /* Nothing to do for 82598 */
4549 if (hw->mac.type == ixgbe_mac_82598EB)
4550 return;
4551
Alexander Duyck16369562015-11-02 17:10:13 -08004552 /* We are already in VLAN promisc, nothing to do */
4553 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4554 return;
4555
4556 /* Set flag so we don't redo unnecessary work */
4557 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4558
4559 /* Add PF to all active pools */
4560 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4561 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4562 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4563
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004564 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004565 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4566 }
4567
4568 /* Set all bits in the VLAN filter table array */
4569 for (i = hw->mac.vft_size; i--;)
4570 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4571}
4572
4573#define VFTA_BLOCK_SIZE 8
4574static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4575{
4576 struct ixgbe_hw *hw = &adapter->hw;
4577 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4578 u32 vid_start = vfta_offset * 32;
4579 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4580 u32 i, vid, word, bits;
4581
4582 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4583 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4584
4585 /* pull VLAN ID from VLVF */
4586 vid = vlvf & VLAN_VID_MASK;
4587
4588 /* only concern outselves with a certain range */
4589 if (vid < vid_start || vid >= vid_end)
4590 continue;
4591
4592 if (vlvf) {
4593 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004594 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004595
4596 /* if PF is part of this then continue */
4597 if (test_bit(vid, adapter->active_vlans))
4598 continue;
4599 }
4600
4601 /* remove PF from the pool */
4602 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004603 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004604 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4605 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4606 }
4607
4608 /* extract values from active_vlans and write back to VFTA */
4609 for (i = VFTA_BLOCK_SIZE; i--;) {
4610 vid = (vfta_offset + i) * 32;
4611 word = vid / BITS_PER_LONG;
4612 bits = vid % BITS_PER_LONG;
4613
4614 vfta[i] |= adapter->active_vlans[word] >> bits;
4615
4616 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4617 }
4618}
4619
4620static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4621{
4622 struct ixgbe_hw *hw = &adapter->hw;
4623 u32 vlnctrl, i;
4624
Alexander Duyckf60439b2016-08-11 14:51:56 -07004625 /* Set VLAN filtering to enabled */
4626 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4627 vlnctrl |= IXGBE_VLNCTRL_VFE;
4628 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4629
Emil Tantilov691e4122016-08-22 16:17:46 -07004630 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4631 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004632 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004633
4634 /* We are not in VLAN promisc, nothing to do */
4635 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4636 return;
4637
4638 /* Set flag so we don't redo unnecessary work */
4639 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4640
4641 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4642 ixgbe_scrub_vfta(adapter, i);
4643}
4644
Auke Kok9a799d72007-09-15 14:07:45 -07004645static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4646{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004647 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004648
Patrick McHardy80d5c362013-04-19 02:04:28 +00004649 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004650
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004651 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004652 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004653}
4654
4655/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004656 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4657 * @netdev: network interface device structure
4658 *
4659 * Writes multicast address list to the MTA hash table.
4660 * Returns: -ENOMEM on failure
4661 * 0 on no addresses written
4662 * X on writing X addresses to MTA
4663 **/
4664static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4665{
4666 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4667 struct ixgbe_hw *hw = &adapter->hw;
4668
4669 if (!netif_running(netdev))
4670 return 0;
4671
4672 if (hw->mac.ops.update_mc_addr_list)
4673 hw->mac.ops.update_mc_addr_list(hw, netdev);
4674 else
4675 return -ENOMEM;
4676
4677#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004678 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004679#endif
4680
4681 return netdev_mc_count(netdev);
4682}
4683
Jacob Keller5d7daa32014-03-29 06:51:25 +00004684#ifdef CONFIG_PCI_IOV
4685void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4686{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004687 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004688 struct ixgbe_hw *hw = &adapter->hw;
4689 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004690
4691 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4692 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4693
4694 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4695 hw->mac.ops.set_rar(hw, i,
4696 mac_table->addr,
4697 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004698 IXGBE_RAH_AV);
4699 else
4700 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004701 }
4702}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004703
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004704#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004705static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4706{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004707 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004708 struct ixgbe_hw *hw = &adapter->hw;
4709 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004710
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004711 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4712 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4713 continue;
4714
4715 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4716
4717 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4718 hw->mac.ops.set_rar(hw, i,
4719 mac_table->addr,
4720 mac_table->pool,
4721 IXGBE_RAH_AV);
4722 else
4723 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004724 }
4725}
4726
4727static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4728{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004729 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004730 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004731 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004732
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004733 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4734 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4735 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004736 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004737
Jacob Keller5d7daa32014-03-29 06:51:25 +00004738 ixgbe_sync_mac_table(adapter);
4739}
4740
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004741static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004742{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004743 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004744 struct ixgbe_hw *hw = &adapter->hw;
4745 int i, count = 0;
4746
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004747 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4748 /* do not count default RAR as available */
4749 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4750 continue;
4751
4752 /* only count unused and addresses that belong to us */
4753 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4754 if (mac_table->pool != pool)
4755 continue;
4756 }
4757
4758 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004759 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004760
Jacob Keller5d7daa32014-03-29 06:51:25 +00004761 return count;
4762}
4763
4764/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004765static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004766{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004767 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004768 struct ixgbe_hw *hw = &adapter->hw;
4769
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004770 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4771 mac_table->pool = VMDQ_P(0);
4772
4773 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4774
4775 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004776 IXGBE_RAH_AV);
4777}
4778
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004779int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4780 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004781{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004782 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004783 struct ixgbe_hw *hw = &adapter->hw;
4784 int i;
4785
4786 if (is_zero_ether_addr(addr))
4787 return -EINVAL;
4788
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004789 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4790 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004791 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004792
4793 ether_addr_copy(mac_table->addr, addr);
4794 mac_table->pool = pool;
4795
4796 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4797 IXGBE_MAC_STATE_IN_USE;
4798
Jacob Keller5d7daa32014-03-29 06:51:25 +00004799 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004800
Jacob Keller5d7daa32014-03-29 06:51:25 +00004801 return i;
4802 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004803
Jacob Keller5d7daa32014-03-29 06:51:25 +00004804 return -ENOMEM;
4805}
4806
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004807int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4808 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004809{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004810 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004811 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004812 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004813
4814 if (is_zero_ether_addr(addr))
4815 return -EINVAL;
4816
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004817 /* search table for addr, if found clear IN_USE flag and sync */
4818 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4819 /* we can only delete an entry if it is in use */
4820 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4821 continue;
4822 /* we only care about entries that belong to the given pool */
4823 if (mac_table->pool != pool)
4824 continue;
4825 /* we only care about a specific MAC address */
4826 if (!ether_addr_equal(addr, mac_table->addr))
4827 continue;
4828
4829 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4830 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4831
4832 ixgbe_sync_mac_table(adapter);
4833
4834 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004835 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004836
Jacob Keller5d7daa32014-03-29 06:51:25 +00004837 return -ENOMEM;
4838}
Tony Nguyen5ba643c2017-12-04 11:28:30 -08004839
Alexander Duyck0f079d22015-10-22 16:26:36 -07004840static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4841{
4842 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4843 int ret;
4844
4845 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4846
4847 return min_t(int, ret, 0);
4848}
4849
4850static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4851{
4852 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4853
4854 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4855
4856 return 0;
4857}
4858
Alexander Duyck28500622010-06-15 09:25:48 +00004859/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004860 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004861 * @netdev: network interface device structure
4862 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004863 * The set_rx_method entry point is called whenever the unicast/multicast
4864 * address list or the network interface flags are updated. This routine is
4865 * responsible for configuring the hardware for proper unicast, multicast and
4866 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004867 **/
Greg Rose7f870472010-01-09 02:25:29 +00004868void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004869{
4870 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4871 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004872 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004873 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004874 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004875
4876 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004877 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4878
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004879 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004880 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004881 fctrl |= IXGBE_FCTRL_BAM;
4882 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4883 fctrl |= IXGBE_FCTRL_PMCF;
4884
Alexander Duyck28500622010-06-15 09:25:48 +00004885 /* clear the bits we are changing the status of */
4886 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004887 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004888 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004889 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004890 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004891 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004892 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004893 if (netdev->flags & IFF_ALLMULTI) {
4894 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004895 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004896 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004897 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004898 }
4899
4900 /*
4901 * Write addresses to available RAR registers, if there is not
4902 * sufficient space to store all the addresses then enable
4903 * unicast promiscuous mode
4904 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004905 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004906 fctrl |= IXGBE_FCTRL_UPE;
4907 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004908 }
4909
Emil Tantilovcf789592013-10-26 08:13:20 +00004910 /* Write addresses to the MTA, if the attempt fails
4911 * then we should just turn on promiscuous mode so
4912 * that we can at least receive multicast traffic
4913 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004914 count = ixgbe_write_mc_addr_list(netdev);
4915 if (count < 0) {
4916 fctrl |= IXGBE_FCTRL_MPE;
4917 vmolr |= IXGBE_VMOLR_MPE;
4918 } else if (count) {
4919 vmolr |= IXGBE_VMOLR_ROMPE;
4920 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004921
4922 if (hw->mac.type != ixgbe_mac_82598EB) {
4923 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004924 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4925 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004926 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004927 }
4928
Ben Greear3f2d1c02012-03-08 08:28:41 +00004929 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004930 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004931 /* UPE and MPE will be handled by normal PROMISC logic
4932 * in e1000e_set_rx_mode */
4933 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4934 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4935 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4936
4937 fctrl &= ~(IXGBE_FCTRL_DPF);
4938 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4939 }
4940
Auke Kok9a799d72007-09-15 14:07:45 -07004941 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004942
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004943 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004944 ixgbe_vlan_strip_enable(adapter);
4945 else
4946 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004947
4948 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4949 ixgbe_vlan_promisc_disable(adapter);
4950 else
4951 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004952}
4953
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004954static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4955{
4956 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004957
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004958 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004959 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004960}
4961
4962static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4963{
4964 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004965
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004966 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004967 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004968}
4969
Emil Tantilova21d0822016-08-10 11:19:23 -07004970static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07004971{
Emil Tantilova21d0822016-08-10 11:19:23 -07004972 struct ixgbe_hw *hw = &adapter->hw;
4973 u32 vxlanctrl;
4974
4975 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4976 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4977 return;
4978
Sabrina Dubrocaa39221c2017-07-03 13:02:55 +02004979 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
Emil Tantilova21d0822016-08-10 11:19:23 -07004980 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4981
4982 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07004983 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07004984
4985 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4986 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004987}
4988
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004989#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004990/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004991 * ixgbe_configure_dcb - Configure DCB hardware
4992 * @adapter: ixgbe adapter struct
4993 *
4994 * This is called by the driver on open to configure the DCB hardware.
4995 * This is also called by the gennetlink interface when reconfiguring
4996 * the DCB state.
4997 */
4998static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
4999{
5000 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00005001 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005002
Alexander Duyck67ebd792010-08-19 13:34:04 +00005003 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
5004 if (hw->mac.type == ixgbe_mac_82598EB)
5005 netif_set_gso_max_size(adapter->netdev, 65536);
5006 return;
5007 }
5008
5009 if (hw->mac.type == ixgbe_mac_82598EB)
5010 netif_set_gso_max_size(adapter->netdev, 32768);
5011
John Fastabendb1208182011-10-15 05:00:10 +00005012#ifdef IXGBE_FCOE
5013 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
5014 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
5015#endif
5016
Alexander Duyck01fa7d92010-11-16 19:26:53 -08005017 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00005018 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00005019 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5020 DCB_TX_CONFIG);
5021 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5022 DCB_RX_CONFIG);
5023 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00005024 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
5025 ixgbe_dcb_hw_ets(&adapter->hw,
5026 adapter->ixgbe_ieee_ets,
5027 max_frame);
5028 ixgbe_dcb_hw_pfc_config(&adapter->hw,
5029 adapter->ixgbe_ieee_pfc->pfc_en,
5030 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00005031 }
John Fastabend8187cd42011-02-23 05:58:08 +00005032
5033 /* Enable RSS Hash per TC */
5034 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00005035 u32 msb = 0;
5036 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005037
Alexander Duyckd411a932012-06-30 00:14:01 +00005038 while (rss_i) {
5039 msb++;
5040 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005041 }
Alexander Duyckd411a932012-06-30 00:14:01 +00005042
Alexander Duyck4ae63732012-06-22 06:46:33 +00005043 /* write msb to all 8 TCs in one write */
5044 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00005045 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005046}
John Fastabend9da712d2011-08-23 03:14:22 +00005047#endif
5048
5049/* Additional bittime to account for IXGBE framing */
5050#define IXGBE_ETH_FRAMING 20
5051
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005052/**
John Fastabend9da712d2011-08-23 03:14:22 +00005053 * ixgbe_hpbthresh - calculate high water mark for flow control
5054 *
5055 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005056 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005057 */
5058static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
5059{
5060 struct ixgbe_hw *hw = &adapter->hw;
5061 struct net_device *dev = adapter->netdev;
5062 int link, tc, kb, marker;
5063 u32 dv_id, rx_pba;
5064
5065 /* Calculate max LAN frame size */
5066 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
5067
5068#ifdef IXGBE_FCOE
5069 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00005070 if ((dev->features & NETIF_F_FCOE_MTU) &&
5071 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5072 (pb == ixgbe_fcoe_get_tc(adapter)))
5073 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005074#endif
Jacob Kellere5776622014-04-05 02:35:52 +00005075
John Fastabend9da712d2011-08-23 03:14:22 +00005076 /* Calculate delay value for device */
5077 switch (hw->mac.type) {
5078 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005079 case ixgbe_mac_X550:
5080 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005081 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005082 dv_id = IXGBE_DV_X540(link, tc);
5083 break;
5084 default:
5085 dv_id = IXGBE_DV(link, tc);
5086 break;
5087 }
5088
5089 /* Loopback switch introduces additional latency */
5090 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5091 dv_id += IXGBE_B2BT(tc);
5092
5093 /* Delay value is calculated in bit times convert to KB */
5094 kb = IXGBE_BT2KB(dv_id);
5095 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
5096
5097 marker = rx_pba - kb;
5098
5099 /* It is possible that the packet buffer is not large enough
5100 * to provide required headroom. In this case throw an error
5101 * to user and a do the best we can.
5102 */
5103 if (marker < 0) {
5104 e_warn(drv, "Packet Buffer(%i) can not provide enough"
5105 "headroom to support flow control."
5106 "Decrease MTU or number of traffic classes\n", pb);
5107 marker = tc + 1;
5108 }
5109
5110 return marker;
5111}
5112
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005113/**
John Fastabend9da712d2011-08-23 03:14:22 +00005114 * ixgbe_lpbthresh - calculate low water mark for for flow control
5115 *
5116 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005117 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005118 */
Jacob Kellere5776622014-04-05 02:35:52 +00005119static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00005120{
5121 struct ixgbe_hw *hw = &adapter->hw;
5122 struct net_device *dev = adapter->netdev;
5123 int tc;
5124 u32 dv_id;
5125
5126 /* Calculate max LAN frame size */
5127 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5128
Jacob Kellere5776622014-04-05 02:35:52 +00005129#ifdef IXGBE_FCOE
5130 /* FCoE traffic class uses FCOE jumbo frames */
5131 if ((dev->features & NETIF_F_FCOE_MTU) &&
5132 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5133 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
5134 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5135#endif
5136
John Fastabend9da712d2011-08-23 03:14:22 +00005137 /* Calculate delay value for device */
5138 switch (hw->mac.type) {
5139 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005140 case ixgbe_mac_X550:
5141 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005142 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005143 dv_id = IXGBE_LOW_DV_X540(tc);
5144 break;
5145 default:
5146 dv_id = IXGBE_LOW_DV(tc);
5147 break;
5148 }
5149
5150 /* Delay value is calculated in bit times convert to KB */
5151 return IXGBE_BT2KB(dv_id);
5152}
5153
5154/*
5155 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5156 */
5157static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
5158{
5159 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck0efbf122017-11-22 10:57:11 -08005160 int num_tc = adapter->hw_tcs;
John Fastabend9da712d2011-08-23 03:14:22 +00005161 int i;
5162
5163 if (!num_tc)
5164 num_tc = 1;
5165
John Fastabend9da712d2011-08-23 03:14:22 +00005166 for (i = 0; i < num_tc; i++) {
5167 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00005168 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00005169
5170 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00005171 if (hw->fc.low_water[i] > hw->fc.high_water[i])
5172 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005173 }
Jacob Kellere5776622014-04-05 02:35:52 +00005174
5175 for (; i < MAX_TRAFFIC_CLASS; i++)
5176 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005177}
John Fastabend80605c652011-05-02 12:34:10 +00005178
5179static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
5180{
John Fastabend80605c652011-05-02 12:34:10 +00005181 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00005182 int hdrm;
Alexander Duyck0efbf122017-11-22 10:57:11 -08005183 u8 tc = adapter->hw_tcs;
John Fastabend80605c652011-05-02 12:34:10 +00005184
5185 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5186 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00005187 hdrm = 32 << adapter->fdir_pballoc;
5188 else
5189 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00005190
Alexander Duyckf7e10272011-07-21 00:40:35 +00005191 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00005192 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00005193}
5194
Alexander Duycke4911d52011-05-11 07:18:52 +00005195static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
5196{
5197 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08005198 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005199 struct ixgbe_fdir_filter *filter;
5200
5201 spin_lock(&adapter->fdir_perfect_lock);
5202
5203 if (!hlist_empty(&adapter->fdir_filter_list))
5204 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
5205
Sasha Levinb67bfe02013-02-27 17:06:00 -08005206 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005207 &adapter->fdir_filter_list, fdir_node) {
5208 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00005209 &filter->filter,
5210 filter->sw_idx,
5211 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
5212 IXGBE_FDIR_DROP_QUEUE :
5213 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00005214 }
5215
5216 spin_unlock(&adapter->fdir_perfect_lock);
5217}
5218
John Fastabend2a47fa42013-11-06 09:54:52 -08005219/**
5220 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5221 * @rx_ring: ring to free buffers from
5222 **/
5223static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5224{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005225 u16 i = rx_ring->next_to_clean;
5226 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005227
5228 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005229 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005230 if (rx_buffer->skb) {
5231 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005232 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005233 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005234 IXGBE_CB(skb)->dma,
5235 ixgbe_rx_pg_size(rx_ring),
5236 DMA_FROM_DEVICE,
5237 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005238 dev_kfree_skb(skb);
5239 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005240
Alexander Duyckf3213d92017-01-17 08:35:54 -08005241 /* Invalidate cache lines that may have been written to by
5242 * device so that we avoid corrupting memory.
5243 */
5244 dma_sync_single_range_for_cpu(rx_ring->dev,
5245 rx_buffer->dma,
5246 rx_buffer->page_offset,
5247 ixgbe_rx_bufsz(rx_ring),
5248 DMA_FROM_DEVICE);
5249
5250 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005251 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005252 ixgbe_rx_pg_size(rx_ring),
5253 DMA_FROM_DEVICE,
5254 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005255 __page_frag_cache_drain(rx_buffer->page,
5256 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005257
Alexander Duyckffed21b2017-01-17 08:37:29 -08005258 i++;
5259 rx_buffer++;
5260 if (i == rx_ring->count) {
5261 i = 0;
5262 rx_buffer = rx_ring->rx_buffer_info;
5263 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005264 }
5265
John Fastabend2a47fa42013-11-06 09:54:52 -08005266 rx_ring->next_to_alloc = 0;
5267 rx_ring->next_to_clean = 0;
5268 rx_ring->next_to_use = 0;
5269}
5270
Alexander Duyck865255b2018-04-03 17:16:40 -04005271static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter,
John Fastabend2a47fa42013-11-06 09:54:52 -08005272 struct ixgbe_fwd_adapter *accel)
5273{
Alexander Duyck865255b2018-04-03 17:16:40 -04005274 struct net_device *vdev = accel->netdev;
Alexander Duyck16be45b2017-11-22 10:57:23 -08005275 int i, baseq, err;
John Fastabend2a47fa42013-11-06 09:54:52 -08005276
John Fastabend2a47fa42013-11-06 09:54:52 -08005277 baseq = accel->pool * adapter->num_rx_queues_per_pool;
Alexander Duyck4e039c12017-11-22 10:56:40 -08005278 netdev_dbg(vdev, "pool %i:%i queues %i:%i\n",
John Fastabend2a47fa42013-11-06 09:54:52 -08005279 accel->pool, adapter->num_rx_pools,
Alexander Duyck4e039c12017-11-22 10:56:40 -08005280 baseq, baseq + adapter->num_rx_queues_per_pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08005281
Alexander Duyck16be45b2017-11-22 10:57:23 -08005282 accel->rx_base_queue = baseq;
5283 accel->tx_base_queue = baseq;
John Fastabend2a47fa42013-11-06 09:54:52 -08005284
5285 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
Alexander Duyck16be45b2017-11-22 10:57:23 -08005286 adapter->rx_ring[baseq + i]->netdev = vdev;
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08005287
5288 /* Guarantee all rings are updated before we update the
5289 * MAC address filter.
5290 */
5291 wmb();
John Fastabend2a47fa42013-11-06 09:54:52 -08005292
Alexander Duyck4a2512c2017-11-22 10:56:59 -08005293 /* ixgbe_add_mac_filter will return an index if it succeeds, so we
5294 * need to only treat it as an error value if it is negative.
5295 */
5296 err = ixgbe_add_mac_filter(adapter, vdev->dev_addr,
5297 VMDQ_P(accel->pool));
Alexander Duyck81d4e912018-04-03 17:16:09 -04005298 if (err >= 0)
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08005299 return 0;
John Fastabend2a47fa42013-11-06 09:54:52 -08005300
Alexander Duyck8315ef62018-04-03 17:16:45 -04005301 /* if we cannot add the MAC rule then disable the offload */
5302 macvlan_release_l2fw_offload(vdev);
5303
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08005304 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5305 adapter->rx_ring[baseq + i]->netdev = NULL;
5306
Alexander Duyck8315ef62018-04-03 17:16:45 -04005307 netdev_err(vdev, "L2FW offload disabled due to L2 filter error\n");
5308
5309 clear_bit(accel->pool, adapter->fwd_bitmask);
5310 kfree(accel);
5311
John Fastabend2a47fa42013-11-06 09:54:52 -08005312 return err;
5313}
5314
Alexander Duyck865255b2018-04-03 17:16:40 -04005315static int ixgbe_macvlan_up(struct net_device *vdev, void *data)
David Ahern1cd127f2016-10-17 19:15:48 -07005316{
Alexander Duyck865255b2018-04-03 17:16:40 -04005317 struct ixgbe_adapter *adapter = data;
5318 struct ixgbe_fwd_adapter *accel;
David Ahern1cd127f2016-10-17 19:15:48 -07005319
Alexander Duyck865255b2018-04-03 17:16:40 -04005320 if (!netif_is_macvlan(vdev))
5321 return 0;
5322
5323 accel = macvlan_accel_priv(vdev);
5324 if (!accel)
5325 return 0;
5326
5327 ixgbe_fwd_ring_up(adapter, accel);
David Ahern1cd127f2016-10-17 19:15:48 -07005328
5329 return 0;
5330}
5331
John Fastabend2a47fa42013-11-06 09:54:52 -08005332static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5333{
David Ahern1cd127f2016-10-17 19:15:48 -07005334 netdev_walk_all_upper_dev_rcu(adapter->netdev,
Alexander Duyck865255b2018-04-03 17:16:40 -04005335 ixgbe_macvlan_up, adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005336}
5337
Auke Kok9a799d72007-09-15 14:07:45 -07005338static void ixgbe_configure(struct ixgbe_adapter *adapter)
5339{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005340 struct ixgbe_hw *hw = &adapter->hw;
5341
John Fastabend80605c652011-05-02 12:34:10 +00005342 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005343#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005344 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005345#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005346 /*
5347 * We must restore virtualization before VLANs or else
5348 * the VLVF registers will not be populated
5349 */
5350 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005351
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005352 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005353 ixgbe_restore_vlan(adapter);
Shannon Nelson6d73a152017-12-19 15:59:58 -08005354 ixgbe_ipsec_restore(adapter);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005355
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005356 switch (hw->mac.type) {
5357 case ixgbe_mac_82599EB:
5358 case ixgbe_mac_X540:
5359 hw->mac.ops.disable_rx_buff(hw);
5360 break;
5361 default:
5362 break;
5363 }
5364
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005365 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005366 ixgbe_init_fdir_signature_82599(&adapter->hw,
5367 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005368 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5369 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5370 adapter->fdir_pballoc);
5371 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005372 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005373
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005374 switch (hw->mac.type) {
5375 case ixgbe_mac_82599EB:
5376 case ixgbe_mac_X540:
5377 hw->mac.ops.enable_rx_buff(hw);
5378 break;
5379 default:
5380 break;
5381 }
5382
Mark Rustad9de76052015-08-08 16:27:41 -07005383#ifdef CONFIG_IXGBE_DCA
5384 /* configure DCA */
5385 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5386 ixgbe_setup_dca(adapter);
5387#endif /* CONFIG_IXGBE_DCA */
5388
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005389#ifdef IXGBE_FCOE
5390 /* configure FCoE L2 filters, redirection table, and Rx control */
5391 ixgbe_configure_fcoe(adapter);
5392
5393#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005394 ixgbe_configure_tx(adapter);
5395 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005396 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005397}
5398
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005399/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005400 * ixgbe_sfp_link_config - set up SFP+ link
5401 * @adapter: pointer to private adapter struct
5402 **/
5403static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5404{
Alexander Duyck70864002011-04-27 09:13:56 +00005405 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005406 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005407 * is that an SFP was inserted/removed after the reset
5408 * but before SFP detection was enabled. As such the best
5409 * solution is to just start searching as soon as we start
5410 */
5411 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5412 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005413
Alexander Duyck70864002011-04-27 09:13:56 +00005414 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005415 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005416}
5417
5418/**
5419 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005420 * @hw: pointer to private hardware struct
5421 *
5422 * Returns 0 on success, negative on failure
5423 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005424static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005425{
Josh Hay3d292262012-12-15 03:28:19 +00005426 u32 speed;
5427 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005428 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005429
5430 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005431 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005432
5433 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005434 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005435
Josh Hay3d292262012-12-15 03:28:19 +00005436 speed = hw->phy.autoneg_advertised;
5437 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5438 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5439 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005440 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005441 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005442
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005443 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005444 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005445
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005446 return ret;
5447}
5448
Alexander Duycka34bcff2010-08-19 13:39:20 +00005449static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005450{
Auke Kok9a799d72007-09-15 14:07:45 -07005451 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005452 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005453
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005454 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005455 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5456 IXGBE_GPIE_OCD;
5457 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005458 /*
5459 * use EIAM to auto-mask when MSI-X interrupt is asserted
5460 * this saves a register write for every interrupt
5461 */
5462 switch (hw->mac.type) {
5463 case ixgbe_mac_82598EB:
5464 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5465 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005466 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005467 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005468 case ixgbe_mac_X550:
5469 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005470 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005471 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005472 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5473 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5474 break;
5475 }
5476 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005477 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5478 * specifically only auto mask tx and rx interrupts */
5479 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005480 }
5481
Alexander Duycka34bcff2010-08-19 13:39:20 +00005482 /* XXX: to interrupt immediately for EICS writes, enable this */
5483 /* gpie |= IXGBE_GPIE_EIMEN; */
5484
5485 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5486 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005487
5488 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5489 case IXGBE_82599_VMDQ_8Q_MASK:
5490 gpie |= IXGBE_GPIE_VTMODE_16;
5491 break;
5492 case IXGBE_82599_VMDQ_4Q_MASK:
5493 gpie |= IXGBE_GPIE_VTMODE_32;
5494 break;
5495 default:
5496 gpie |= IXGBE_GPIE_VTMODE_64;
5497 break;
5498 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005499 }
5500
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005501 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005502 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5503 switch (adapter->hw.mac.type) {
5504 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005505 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005506 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005507 default:
5508 break;
5509 }
5510 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005511
Alexander Duycka34bcff2010-08-19 13:39:20 +00005512 /* Enable fan failure interrupt */
5513 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005514 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005515
Don Skidmorea023bbd2015-06-24 16:38:53 -04005516 switch (hw->mac.type) {
5517 case ixgbe_mac_82599EB:
5518 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5519 break;
5520 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005521 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005522 gpie |= IXGBE_SDP0_GPIEN_X540;
5523 break;
5524 default:
5525 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005526 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005527
5528 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5529}
5530
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005531static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005532{
5533 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005534 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005535 u32 ctrl_ext;
5536
5537 ixgbe_get_hw_control(adapter);
5538 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005539
Auke Kok9a799d72007-09-15 14:07:45 -07005540 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5541 ixgbe_configure_msix(adapter);
5542 else
5543 ixgbe_configure_msi_and_legacy(adapter);
5544
Emil Tantilovec74a472012-09-20 03:33:56 +00005545 /* enable the optics for 82599 SFP+ fiber */
5546 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005547 hw->mac.ops.enable_tx_laser(hw);
5548
Don Skidmore961fac82015-06-09 16:09:47 -07005549 if (hw->phy.ops.set_phy_power)
5550 hw->phy.ops.set_phy_power(hw, true);
5551
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005552 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005553 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005554 ixgbe_napi_enable_all(adapter);
5555
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005556 if (ixgbe_is_sfp(hw)) {
5557 ixgbe_sfp_link_config(adapter);
5558 } else {
5559 err = ixgbe_non_sfp_link_config(hw);
5560 if (err)
5561 e_err(probe, "link_config FAILED %d\n", err);
5562 }
5563
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005564 /* clear any pending interrupts, may auto mask */
5565 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005566 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005567
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005568 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005569 * If this adapter has a fan, check to see if we had a failure
5570 * before we enabled the interrupt.
5571 */
5572 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5573 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5574 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005575 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005576 }
5577
Auke Kok9a799d72007-09-15 14:07:45 -07005578 /* bring the link up in the watchdog, this could race with our first
5579 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005580 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5581 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005582 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005583
5584 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5585 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5586 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5587 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005588}
5589
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005590void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5591{
5592 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005593 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005594 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005595
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005596 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005597 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005598 if (adapter->hw.phy.type == ixgbe_phy_fw)
5599 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005600 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005601 /*
5602 * If SR-IOV enabled then wait a bit before bringing the adapter
5603 * back up to give the VFs time to respond to the reset. The
5604 * two second wait is based upon the watchdog timer cycle in
5605 * the VF driver.
5606 */
5607 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5608 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005609 ixgbe_up(adapter);
5610 clear_bit(__IXGBE_RESETTING, &adapter->state);
5611}
5612
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005613void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005614{
5615 /* hardware has been reset, we need to reload some things */
5616 ixgbe_configure(adapter);
5617
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005618 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005619}
5620
5621void ixgbe_reset(struct ixgbe_adapter *adapter)
5622{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005623 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005624 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005625 int err;
5626
Mark Rustadb0483c82014-01-14 18:53:17 -08005627 if (ixgbe_removed(hw->hw_addr))
5628 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005629 /* lock SFP init bit to prevent race conditions with the watchdog */
5630 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5631 usleep_range(1000, 2000);
5632
5633 /* clear all SFP and link config related flags while holding SFP_INIT */
5634 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5635 IXGBE_FLAG2_SFP_NEEDS_RESET);
5636 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5637
Don Skidmore8ca783a2009-05-26 20:40:47 -07005638 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005639 switch (err) {
5640 case 0:
5641 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005642 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005643 break;
5644 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005645 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005646 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005647 case IXGBE_ERR_EEPROM_VERSION:
5648 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005649 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005650 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005651 "your hardware. If you are experiencing problems "
5652 "please contact your Intel or hardware "
5653 "representative who provided you with this "
5654 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005655 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005656 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005657 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005658 }
Auke Kok9a799d72007-09-15 14:07:45 -07005659
Alexander Duyck70864002011-04-27 09:13:56 +00005660 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005661
5662 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005663 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005664 __dev_uc_unsync(netdev, NULL);
5665
5666 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005667 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005668
5669 /* update SAN MAC vmdq pool selection */
5670 if (hw->mac.san_mac_rar_index)
5671 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005672
Jacob Keller8fecf672013-06-21 08:14:32 +00005673 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005674 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005675
5676 if (hw->phy.ops.set_phy_power) {
5677 if (!netif_running(adapter->netdev) && !adapter->wol)
5678 hw->phy.ops.set_phy_power(hw, false);
5679 else
5680 hw->phy.ops.set_phy_power(hw, true);
5681 }
Auke Kok9a799d72007-09-15 14:07:45 -07005682}
5683
Auke Kok9a799d72007-09-15 14:07:45 -07005684/**
Auke Kok9a799d72007-09-15 14:07:45 -07005685 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005686 * @tx_ring: ring to be cleaned
5687 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005688static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005689{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005690 u16 i = tx_ring->next_to_clean;
5691 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005692
Alexander Duyckffed21b2017-01-17 08:37:29 -08005693 while (i != tx_ring->next_to_use) {
5694 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005695
Alexander Duyckffed21b2017-01-17 08:37:29 -08005696 /* Free all the Tx ring sk_buffs */
John Fastabend33fdc822017-04-24 03:30:18 -07005697 if (ring_is_xdp(tx_ring))
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02005698 xdp_return_frame(tx_buffer->xdpf);
John Fastabend33fdc822017-04-24 03:30:18 -07005699 else
5700 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckffed21b2017-01-17 08:37:29 -08005701
5702 /* unmap skb header data */
5703 dma_unmap_single(tx_ring->dev,
5704 dma_unmap_addr(tx_buffer, dma),
5705 dma_unmap_len(tx_buffer, len),
5706 DMA_TO_DEVICE);
5707
5708 /* check for eop_desc to determine the end of the packet */
5709 eop_desc = tx_buffer->next_to_watch;
5710 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5711
5712 /* unmap remaining buffers */
5713 while (tx_desc != eop_desc) {
5714 tx_buffer++;
5715 tx_desc++;
5716 i++;
5717 if (unlikely(i == tx_ring->count)) {
5718 i = 0;
5719 tx_buffer = tx_ring->tx_buffer_info;
5720 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5721 }
5722
5723 /* unmap any remaining paged data */
5724 if (dma_unmap_len(tx_buffer, len))
5725 dma_unmap_page(tx_ring->dev,
5726 dma_unmap_addr(tx_buffer, dma),
5727 dma_unmap_len(tx_buffer, len),
5728 DMA_TO_DEVICE);
5729 }
5730
5731 /* move us one more past the eop_desc for start of next pkt */
5732 tx_buffer++;
5733 i++;
5734 if (unlikely(i == tx_ring->count)) {
5735 i = 0;
5736 tx_buffer = tx_ring->tx_buffer_info;
5737 }
Auke Kok9a799d72007-09-15 14:07:45 -07005738 }
5739
Alexander Duyckffed21b2017-01-17 08:37:29 -08005740 /* reset BQL for queue */
John Fastabend33fdc822017-04-24 03:30:18 -07005741 if (!ring_is_xdp(tx_ring))
5742 netdev_tx_reset_queue(txring_txq(tx_ring));
John Fastabenddad8a3b2012-04-23 12:22:39 +00005743
Alexander Duyckffed21b2017-01-17 08:37:29 -08005744 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005745 tx_ring->next_to_use = 0;
5746 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005747}
5748
5749/**
Auke Kok9a799d72007-09-15 14:07:45 -07005750 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5751 * @adapter: board private structure
5752 **/
5753static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5754{
5755 int i;
5756
5757 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005758 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005759}
5760
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005761/**
5762 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5763 * @adapter: board private structure
5764 **/
5765static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5766{
5767 int i;
5768
5769 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005770 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07005771 for (i = 0; i < adapter->num_xdp_queues; i++)
5772 ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005773}
5774
Alexander Duycke4911d52011-05-11 07:18:52 +00005775static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5776{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005777 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005778 struct ixgbe_fdir_filter *filter;
5779
5780 spin_lock(&adapter->fdir_perfect_lock);
5781
Sasha Levinb67bfe02013-02-27 17:06:00 -08005782 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005783 &adapter->fdir_filter_list, fdir_node) {
5784 hlist_del(&filter->fdir_node);
5785 kfree(filter);
5786 }
5787 adapter->fdir_filter_count = 0;
5788
5789 spin_unlock(&adapter->fdir_perfect_lock);
5790}
5791
Auke Kok9a799d72007-09-15 14:07:45 -07005792void ixgbe_down(struct ixgbe_adapter *adapter)
5793{
5794 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005795 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005796 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005797
5798 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005799 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5800 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005801
5802 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005803 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005804
Yi Zou2d39d572011-01-06 14:29:56 +00005805 /* disable all enabled rx queues */
5806 for (i = 0; i < adapter->num_rx_queues; i++)
5807 /* this call also flushes the previous write */
5808 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5809
Don Skidmore032b4322011-03-18 09:32:53 +00005810 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005811
John Fastabend11393cc2017-07-17 09:29:40 -07005812 /* synchronize_sched() needed for pending XDP buffers to drain */
5813 if (adapter->xdp_ring[0])
5814 synchronize_sched();
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005815 netif_tx_stop_all_queues(netdev);
5816
Alexander Duyck70864002011-04-27 09:13:56 +00005817 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005818 netif_carrier_off(netdev);
5819 netif_tx_disable(netdev);
5820
5821 ixgbe_irq_disable(adapter);
5822
5823 ixgbe_napi_disable_all(adapter);
5824
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005825 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5826 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005827 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5828
5829 del_timer_sync(&adapter->service_timer);
5830
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005831 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005832 /* Clear EITR Select mapping */
5833 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5834
5835 /* Mark all the VFs as inactive */
5836 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005837 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005838
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005839 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005840 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005841
Auke Kok9a799d72007-09-15 14:07:45 -07005842 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005843 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005844 }
5845
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005846 /* disable transmits in the hardware now that interrupts are off */
5847 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005848 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005849 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005850 }
John Fastabend33fdc822017-04-24 03:30:18 -07005851 for (i = 0; i < adapter->num_xdp_queues; i++) {
5852 u8 reg_idx = adapter->xdp_ring[i]->reg_idx;
5853
5854 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5855 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005856
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005857 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005858 switch (hw->mac.type) {
5859 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005860 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005861 case ixgbe_mac_X550:
5862 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005863 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005864 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005865 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5866 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005867 break;
5868 default:
5869 break;
5870 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005871
Paul Larson6f4a0e42008-06-24 17:00:56 -07005872 if (!pci_channel_offline(adapter->pdev))
5873 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005874
Emil Tantilovec74a472012-09-20 03:33:56 +00005875 /* power down the optics for 82599 SFP+ fiber */
5876 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005877 hw->mac.ops.disable_tx_laser(hw);
5878
Auke Kok9a799d72007-09-15 14:07:45 -07005879 ixgbe_clean_all_tx_rings(adapter);
5880 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005881}
5882
Auke Kok9a799d72007-09-15 14:07:45 -07005883/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005884 * ixgbe_eee_capable - helper function to determine EEE support on X550
5885 * @adapter: board private structure
5886 */
5887static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
5888{
5889 struct ixgbe_hw *hw = &adapter->hw;
5890
5891 switch (hw->device_id) {
5892 case IXGBE_DEV_ID_X550EM_A_1G_T:
5893 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5894 if (!hw->phy.eee_speeds_supported)
5895 break;
5896 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
5897 if (!hw->phy.eee_speeds_advertised)
5898 break;
5899 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
5900 break;
5901 default:
5902 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
5903 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
5904 break;
5905 }
5906}
5907
5908/**
Auke Kok9a799d72007-09-15 14:07:45 -07005909 * ixgbe_tx_timeout - Respond to a Tx Hang
5910 * @netdev: network interface device structure
5911 **/
5912static void ixgbe_tx_timeout(struct net_device *netdev)
5913{
5914 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5915
5916 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005917 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005918}
5919
Usha Ketineni88290092016-04-26 05:00:26 -07005920#ifdef CONFIG_IXGBE_DCB
5921static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
5922{
5923 struct ixgbe_hw *hw = &adapter->hw;
5924 struct tc_configuration *tc;
5925 int j;
5926
5927 switch (hw->mac.type) {
5928 case ixgbe_mac_82598EB:
5929 case ixgbe_mac_82599EB:
5930 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5931 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5932 break;
5933 case ixgbe_mac_X540:
5934 case ixgbe_mac_X550:
5935 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5936 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5937 break;
5938 case ixgbe_mac_X550EM_x:
5939 case ixgbe_mac_x550em_a:
5940 default:
5941 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
5942 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
5943 break;
5944 }
5945
5946 /* Configure DCB traffic classes */
5947 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5948 tc = &adapter->dcb_cfg.tc_config[j];
5949 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5950 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5951 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5952 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5953 tc->dcb_pfc = pfc_disabled;
5954 }
5955
5956 /* Initialize default user to priority mapping, UPx->TC0 */
5957 tc = &adapter->dcb_cfg.tc_config[0];
5958 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5959 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5960
5961 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5962 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5963 adapter->dcb_cfg.pfc_mode_enable = false;
5964 adapter->dcb_set_bitmap = 0x00;
5965 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
5966 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5967 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5968 sizeof(adapter->temp_dcb_cfg));
5969}
5970#endif
5971
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005972/**
Auke Kok9a799d72007-09-15 14:07:45 -07005973 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5974 * @adapter: board private structure to initialize
Tony Nguyen5ba643c2017-12-04 11:28:30 -08005975 * @ii: pointer to ixgbe_info for device
Auke Kok9a799d72007-09-15 14:07:45 -07005976 *
5977 * ixgbe_sw_init initializes the Adapter private data structure.
5978 * Fields are initialized based on PCI device information and
5979 * OS network device settings (MTU size).
5980 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07005981static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
5982 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07005983{
5984 struct ixgbe_hw *hw = &adapter->hw;
5985 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005986 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005987 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005988 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005989
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005990 /* PCI config space info */
5991
5992 hw->vendor_id = pdev->vendor;
5993 hw->device_id = pdev->device;
5994 hw->revision_id = pdev->revision;
5995 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5996 hw->subsystem_device_id = pdev->subsystem_device;
5997
Emil Tantilov55570b62016-10-12 12:34:25 -07005998 /* get_invariants needs the device IDs */
5999 ii->get_invariants(hw);
6000
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006001 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00006002 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00006003 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006004 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006005 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
6006 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006007 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
6008 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006009 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Alexander Duycka8e87d92017-11-22 10:57:05 -08006010 adapter->ring_feature[RING_F_VMDQ].limit = 1;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006011#ifdef CONFIG_IXGBE_DCA
6012 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
6013#endif
Usha Ketineni88290092016-04-26 05:00:26 -07006014#ifdef CONFIG_IXGBE_DCB
6015 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
6016 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6017#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006018#ifdef IXGBE_FCOE
6019 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
6020 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6021#ifdef CONFIG_IXGBE_DCB
6022 /* Default traffic class to use for FCoE */
6023 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
6024#endif /* CONFIG_IXGBE_DCB */
6025#endif /* IXGBE_FCOE */
6026
John Fastabendb82b17d2016-02-16 21:18:53 -08006027 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006028 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
6029 GFP_KERNEL);
6030 if (!adapter->jump_tables[0])
6031 return -ENOMEM;
6032 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
6033
6034 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
6035 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08006036
Jacob Keller5d7daa32014-03-29 06:51:25 +00006037 adapter->mac_table = kzalloc(sizeof(struct ixgbe_mac_addr) *
6038 hw->mac.num_rar_entries,
6039 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08006040 if (!adapter->mac_table)
6041 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00006042
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07006043 if (ixgbe_init_rss_key(adapter))
6044 return -ENOMEM;
6045
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006046 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08006047 switch (hw->mac.type) {
6048 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006049 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006050
Don Skidmorebf069c92009-05-07 10:39:54 +00006051 if (hw->device_id == IXGBE_DEV_ID_82598AT)
6052 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006053
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006054 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006055 adapter->ring_feature[RING_F_FDIR].limit = 0;
6056 adapter->atr_sample_rate = 0;
6057 adapter->fdir_pballoc = 0;
6058#ifdef IXGBE_FCOE
6059 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6060 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6061#ifdef CONFIG_IXGBE_DCB
6062 adapter->fcoe.up = 0;
6063#endif /* IXGBE_DCB */
6064#endif /* IXGBE_FCOE */
6065 break;
6066 case ixgbe_mac_82599EB:
6067 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
6068 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006069 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006070 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07006071 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006072 if (fwsm & IXGBE_FWSM_TS_ENABLED)
6073 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006074 break;
Mark Rustad49425df2016-04-01 12:18:09 -07006075 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07006076 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006077 switch (hw->device_id) {
6078 case IXGBE_DEV_ID_X550EM_A_1G_T:
6079 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6080 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6081 break;
6082 default:
6083 break;
6084 }
Emil Tantilova21d0822016-08-10 11:19:23 -07006085 /* fall through */
6086 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07006087#ifdef CONFIG_IXGBE_DCB
6088 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
6089#endif
6090#ifdef IXGBE_FCOE
6091 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6092#ifdef CONFIG_IXGBE_DCB
6093 adapter->fcoe.up = 0;
6094#endif /* IXGBE_DCB */
6095#endif /* IXGBE_FCOE */
6096 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006097 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006098 if (hw->mac.type == ixgbe_mac_X550)
6099 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006100#ifdef CONFIG_IXGBE_DCA
6101 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
6102#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006103 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006104 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08006105 default:
6106 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00006107 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08006108
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006109#ifdef IXGBE_FCOE
6110 /* FCoE support exists, always init the FCoE lock */
6111 spin_lock_init(&adapter->fcoe.lock);
6112
6113#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00006114 /* n-tuple support exists, always init our spinlock */
6115 spin_lock_init(&adapter->fdir_perfect_lock);
6116
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08006117#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07006118 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006119#endif
Alexander Duyckde7a7e32018-06-04 16:51:25 -04006120 ixgbe_init_ipsec_offload(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006121
6122 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00006123 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00006124 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00006125 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07006126 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
6127 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00006128 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006129
Alexander Duyck99d74482012-05-09 08:09:25 +00006130#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08006131 if (max_vfs > 0)
6132 e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
Alexander Duyck99d74482012-05-09 08:09:25 +00006133
Jacob Keller170e8542013-11-09 04:52:32 -08006134 /* assign number of SR-IOV VFs */
6135 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08006136 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Emil Tantilov5c11f002017-01-20 14:11:56 -08006137 max_vfs = 0;
Jacob Keller170e8542013-11-09 04:52:32 -08006138 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
Jacob Keller170e8542013-11-09 04:52:32 -08006139 }
6140 }
6141#endif /* CONFIG_PCI_IOV */
6142
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006143 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006144 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006145 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006146
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006147 /* set default ring sizes */
6148 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
6149 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
6150
Alexander Duyckbd198052011-06-11 01:45:08 +00006151 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00006152 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00006153
Auke Kok9a799d72007-09-15 14:07:45 -07006154 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006155 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006156 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006157 return -EIO;
6158 }
6159
John Fastabend2a47fa42013-11-06 09:54:52 -08006160 /* PF holds first pool slot */
Alexander Duyck4e039c12017-11-22 10:56:40 -08006161 set_bit(0, adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07006162 set_bit(__IXGBE_DOWN, &adapter->state);
6163
6164 return 0;
6165}
6166
6167/**
6168 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006169 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006170 *
6171 * Return 0 on success, negative on failure
6172 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006173int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006174{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006175 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006176 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006177 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07006178 int size;
6179
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006180 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006181
6182 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006183 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006184
Alexander Duyckffed21b2017-01-17 08:37:29 -08006185 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006186 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006187 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006188 if (!tx_ring->tx_buffer_info)
6189 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006190
6191 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006192 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006193 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006194
Mark Rustadca8dfe22014-07-24 06:19:24 +00006195 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006196 tx_ring->desc = dma_alloc_coherent(dev,
6197 tx_ring->size,
6198 &tx_ring->dma,
6199 GFP_KERNEL);
6200 set_dev_node(dev, orig_node);
6201 if (!tx_ring->desc)
6202 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6203 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006204 if (!tx_ring->desc)
6205 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006206
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006207 tx_ring->next_to_use = 0;
6208 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006209 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006210
6211err:
6212 vfree(tx_ring->tx_buffer_info);
6213 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006214 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006215 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006216}
6217
6218/**
Alexander Duyck69888672008-09-11 20:05:39 -07006219 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6220 * @adapter: board private structure
6221 *
6222 * If this function returns with an error, then it's possible one or
6223 * more of the rings is populated (while the rest are not). It is the
6224 * callers duty to clean those orphaned rings.
6225 *
6226 * Return 0 on success, negative on failure
6227 **/
6228static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6229{
John Fastabend33fdc822017-04-24 03:30:18 -07006230 int i, j = 0, err = 0;
Alexander Duyck69888672008-09-11 20:05:39 -07006231
6232 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006233 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006234 if (!err)
6235 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006236
Emil Tantilov396e7992010-07-01 20:05:12 +00006237 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006238 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006239 }
John Fastabend33fdc822017-04-24 03:30:18 -07006240 for (j = 0; j < adapter->num_xdp_queues; j++) {
6241 err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
6242 if (!err)
6243 continue;
6244
6245 e_err(probe, "Allocation for Tx Queue %u failed\n", j);
6246 goto err_setup_tx;
6247 }
Alexander Duyck69888672008-09-11 20:05:39 -07006248
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006249 return 0;
6250err_setup_tx:
6251 /* rewind the index freeing the rings as we go */
John Fastabend33fdc822017-04-24 03:30:18 -07006252 while (j--)
6253 ixgbe_free_tx_resources(adapter->xdp_ring[j]);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006254 while (i--)
6255 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006256 return err;
6257}
6258
6259/**
Auke Kok9a799d72007-09-15 14:07:45 -07006260 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Tony Nguyen5ba643c2017-12-04 11:28:30 -08006261 * @adapter: pointer to ixgbe_adapter
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006262 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006263 *
6264 * Returns 0 on success, negative on failure
6265 **/
John Fastabend92470802017-04-24 03:30:17 -07006266int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
6267 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006268{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006269 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006270 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006271 int ring_node = -1;
Jesper Dangaard Brouer8d5d8852018-04-17 16:46:12 +02006272 int size, err;
Auke Kok9a799d72007-09-15 14:07:45 -07006273
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006274 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006275
6276 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006277 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006278
Alexander Duyckffed21b2017-01-17 08:37:29 -08006279 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006280 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006281 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006282 if (!rx_ring->rx_buffer_info)
6283 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006284
Auke Kok9a799d72007-09-15 14:07:45 -07006285 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006286 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6287 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006288
Mark Rustadca8dfe22014-07-24 06:19:24 +00006289 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006290 rx_ring->desc = dma_alloc_coherent(dev,
6291 rx_ring->size,
6292 &rx_ring->dma,
6293 GFP_KERNEL);
6294 set_dev_node(dev, orig_node);
6295 if (!rx_ring->desc)
6296 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6297 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006298 if (!rx_ring->desc)
6299 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006300
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006301 rx_ring->next_to_clean = 0;
6302 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006303
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006304 /* XDP RX-queue info */
6305 if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
6306 rx_ring->queue_index) < 0)
6307 goto err;
6308
Jesper Dangaard Brouer8d5d8852018-04-17 16:46:12 +02006309 err = xdp_rxq_info_reg_mem_model(&rx_ring->xdp_rxq,
6310 MEM_TYPE_PAGE_SHARED, NULL);
6311 if (err) {
6312 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
6313 goto err;
6314 }
6315
John Fastabend92470802017-04-24 03:30:17 -07006316 rx_ring->xdp_prog = adapter->xdp_prog;
6317
Auke Kok9a799d72007-09-15 14:07:45 -07006318 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006319err:
6320 vfree(rx_ring->rx_buffer_info);
6321 rx_ring->rx_buffer_info = NULL;
6322 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006323 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006324}
6325
6326/**
Alexander Duyck69888672008-09-11 20:05:39 -07006327 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6328 * @adapter: board private structure
6329 *
6330 * If this function returns with an error, then it's possible one or
6331 * more of the rings is populated (while the rest are not). It is the
6332 * callers duty to clean those orphaned rings.
6333 *
6334 * Return 0 on success, negative on failure
6335 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006336static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6337{
6338 int i, err = 0;
6339
6340 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend92470802017-04-24 03:30:17 -07006341 err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006342 if (!err)
6343 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006344
Emil Tantilov396e7992010-07-01 20:05:12 +00006345 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006346 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006347 }
6348
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006349#ifdef IXGBE_FCOE
6350 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6351 if (!err)
6352#endif
6353 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006354err_setup_rx:
6355 /* rewind the index freeing the rings as we go */
6356 while (i--)
6357 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006358 return err;
6359}
6360
6361/**
Auke Kok9a799d72007-09-15 14:07:45 -07006362 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006363 * @tx_ring: Tx descriptor ring for a specific queue
6364 *
6365 * Free all transmit software resources
6366 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006367void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006368{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006369 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006370
6371 vfree(tx_ring->tx_buffer_info);
6372 tx_ring->tx_buffer_info = NULL;
6373
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006374 /* if not set, then don't free */
6375 if (!tx_ring->desc)
6376 return;
6377
6378 dma_free_coherent(tx_ring->dev, tx_ring->size,
6379 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006380
6381 tx_ring->desc = NULL;
6382}
6383
6384/**
6385 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6386 * @adapter: board private structure
6387 *
6388 * Free all transmit software resources
6389 **/
6390static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6391{
6392 int i;
6393
6394 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006395 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006396 ixgbe_free_tx_resources(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07006397 for (i = 0; i < adapter->num_xdp_queues; i++)
6398 if (adapter->xdp_ring[i]->desc)
6399 ixgbe_free_tx_resources(adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006400}
6401
6402/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006403 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006404 * @rx_ring: ring to clean the resources from
6405 *
6406 * Free all receive software resources
6407 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006408void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006409{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006410 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006411
John Fastabend92470802017-04-24 03:30:17 -07006412 rx_ring->xdp_prog = NULL;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006413 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
Auke Kok9a799d72007-09-15 14:07:45 -07006414 vfree(rx_ring->rx_buffer_info);
6415 rx_ring->rx_buffer_info = NULL;
6416
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006417 /* if not set, then don't free */
6418 if (!rx_ring->desc)
6419 return;
6420
6421 dma_free_coherent(rx_ring->dev, rx_ring->size,
6422 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006423
6424 rx_ring->desc = NULL;
6425}
6426
6427/**
6428 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6429 * @adapter: board private structure
6430 *
6431 * Free all receive software resources
6432 **/
6433static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6434{
6435 int i;
6436
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006437#ifdef IXGBE_FCOE
6438 ixgbe_free_fcoe_ddp_resources(adapter);
6439
6440#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006441 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006442 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006443 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006444}
6445
6446/**
Auke Kok9a799d72007-09-15 14:07:45 -07006447 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6448 * @netdev: network interface device structure
6449 * @new_mtu: new value for maximum frame size
6450 *
6451 * Returns 0 on success, negative on failure
6452 **/
6453static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6454{
6455 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006456
6457 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006458 * For 82599EB we cannot allow legacy VFs to enable their receive
6459 * paths when MTU greater than 1500 is configured. So display a
6460 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006461 */
6462 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6463 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006464 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006465 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006466
Emil Tantilov396e7992010-07-01 20:05:12 +00006467 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006468
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006469 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006470 netdev->mtu = new_mtu;
6471
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006472 if (netif_running(netdev))
6473 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006474
6475 return 0;
6476}
6477
6478/**
6479 * ixgbe_open - Called when a network interface is made active
6480 * @netdev: network interface device structure
6481 *
6482 * Returns 0 on success, negative value on failure
6483 *
6484 * The open entry point is called when a network interface is made
6485 * active by the system (IFF_UP). At this point all resources needed
6486 * for transmit and receive operations are allocated, the interrupt
6487 * handler is registered with the OS, the watchdog timer is started,
6488 * and the stack is notified that the interface is ready.
6489 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006490int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006491{
6492 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006493 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006494 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006495
Auke Kok4bebfaa2008-02-11 09:26:01 -08006496 /* disallow open during test */
6497 if (test_bit(__IXGBE_TESTING, &adapter->state))
6498 return -EBUSY;
6499
Jesse Brandeburg54386462009-04-17 20:44:27 +00006500 netif_carrier_off(netdev);
6501
Auke Kok9a799d72007-09-15 14:07:45 -07006502 /* allocate transmit descriptors */
6503 err = ixgbe_setup_all_tx_resources(adapter);
6504 if (err)
6505 goto err_setup_tx;
6506
Auke Kok9a799d72007-09-15 14:07:45 -07006507 /* allocate receive descriptors */
6508 err = ixgbe_setup_all_rx_resources(adapter);
6509 if (err)
6510 goto err_setup_rx;
6511
6512 ixgbe_configure(adapter);
6513
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006514 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006515 if (err)
6516 goto err_req_irq;
6517
Alexander Duyckac802f52012-07-12 05:52:53 +00006518 /* Notify the stack of the actual queue counts. */
Alexander Duyck49cfbeb2017-11-22 10:57:35 -08006519 queues = adapter->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08006520 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006521 if (err)
6522 goto err_set_queues;
6523
Alexander Duyck49cfbeb2017-11-22 10:57:35 -08006524 queues = adapter->num_rx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08006525 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006526 if (err)
6527 goto err_set_queues;
6528
Jacob Keller1a71ab22012-08-25 03:54:19 +00006529 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006530
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006531 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006532
Emil Tantilova21d0822016-08-10 11:19:23 -07006533 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006534 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006535
Auke Kok9a799d72007-09-15 14:07:45 -07006536 return 0;
6537
Alexander Duyckac802f52012-07-12 05:52:53 +00006538err_set_queues:
6539 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006540err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006541 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006542 if (hw->phy.ops.set_phy_power && !adapter->wol)
6543 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006544err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006545 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006546err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006547 ixgbe_reset(adapter);
6548
6549 return err;
6550}
6551
Jacob Kellera0cccce2014-05-16 05:12:29 +00006552static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6553{
6554 ixgbe_ptp_suspend(adapter);
6555
Don Skidmore6ac74392015-06-17 17:34:31 -04006556 if (adapter->hw.phy.ops.enter_lplu) {
6557 adapter->hw.phy.reset_disable = true;
6558 ixgbe_down(adapter);
6559 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6560 adapter->hw.phy.reset_disable = false;
6561 } else {
6562 ixgbe_down(adapter);
6563 }
6564
Jacob Kellera0cccce2014-05-16 05:12:29 +00006565 ixgbe_free_irq(adapter);
6566
6567 ixgbe_free_all_tx_resources(adapter);
6568 ixgbe_free_all_rx_resources(adapter);
6569}
6570
Auke Kok9a799d72007-09-15 14:07:45 -07006571/**
6572 * ixgbe_close - Disables a network interface
6573 * @netdev: network interface device structure
6574 *
6575 * Returns 0, this is not allowed to fail
6576 *
6577 * The close entry point is called when an interface is de-activated
6578 * by the OS. The hardware is still under the drivers control, but
6579 * needs to be disabled. A global MAC reset is issued to stop the
6580 * hardware, and all transmit and receive resources are freed.
6581 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006582int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006583{
6584 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006585
Jacob Keller1a71ab22012-08-25 03:54:19 +00006586 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006587
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006588 if (netif_device_present(netdev))
6589 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006590
Alexander Duycke4911d52011-05-11 07:18:52 +00006591 ixgbe_fdir_filter_exit(adapter);
6592
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006593 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006594
6595 return 0;
6596}
6597
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006598#ifdef CONFIG_PM
6599static int ixgbe_resume(struct pci_dev *pdev)
6600{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006601 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6602 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006603 u32 err;
6604
Mark Rustad0391bbe2014-02-28 15:48:55 -08006605 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006606 pci_set_power_state(pdev, PCI_D0);
6607 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006608 /*
6609 * pci_restore_state clears dev->state_saved so call
6610 * pci_save_state to restore it.
6611 */
6612 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006613
6614 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006615 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006616 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006617 return err;
6618 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006619 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006620 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006621 pci_set_master(pdev);
6622
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006623 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006624
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006625 ixgbe_reset(adapter);
6626
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006627 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6628
Alexander Duyckac802f52012-07-12 05:52:53 +00006629 rtnl_lock();
6630 err = ixgbe_init_interrupt_scheme(adapter);
6631 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006632 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006633
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006634
6635 if (!err)
6636 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006637 rtnl_unlock();
6638
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006639 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006640}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006641#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006642
6643static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006644{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006645 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6646 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006647 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006648 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006649 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006650#ifdef CONFIG_PM
6651 int retval = 0;
6652#endif
6653
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006654 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006655 netif_device_detach(netdev);
6656
Jeff Kirsherf0b99e3a2018-05-18 11:58:30 -07006657 if (netif_running(netdev))
Jacob Kellera0cccce2014-05-16 05:12:29 +00006658 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006659
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006660 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006661 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006662
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006663#ifdef CONFIG_PM
6664 retval = pci_save_state(pdev);
6665 if (retval)
6666 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006667
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006668#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006669 if (hw->mac.ops.stop_link_on_d3)
6670 hw->mac.ops.stop_link_on_d3(hw);
6671
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006672 if (wufc) {
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006673 u32 fctrl;
6674
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006675 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006676
Emil Tantilovec74a472012-09-20 03:33:56 +00006677 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6678 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006679 hw->mac.ops.enable_tx_laser(hw);
6680
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006681 /* enable the reception of multicast packets */
6682 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6683 fctrl |= IXGBE_FCTRL_MPE;
6684 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006685
6686 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6687 ctrl |= IXGBE_CTRL_GIO_DIS;
6688 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6689
6690 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6691 } else {
6692 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6693 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6694 }
6695
Alexander Duyckbd508172010-11-16 19:27:03 -08006696 switch (hw->mac.type) {
6697 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006698 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006699 break;
6700 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006701 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006702 case ixgbe_mac_X550:
6703 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006704 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006705 pci_wake_from_d3(pdev, !!wufc);
6706 break;
6707 default:
6708 break;
6709 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006710
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006711 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006712 if (hw->phy.ops.set_phy_power && !*enable_wake)
6713 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006714
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006715 ixgbe_release_hw_control(adapter);
6716
Mark Rustad41c62842014-03-12 00:38:35 +00006717 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6718 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006719
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006720 return 0;
6721}
6722
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006723#ifdef CONFIG_PM
6724static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6725{
6726 int retval;
6727 bool wake;
6728
6729 retval = __ixgbe_shutdown(pdev, &wake);
6730 if (retval)
6731 return retval;
6732
6733 if (wake) {
6734 pci_prepare_to_sleep(pdev);
6735 } else {
6736 pci_wake_from_d3(pdev, false);
6737 pci_set_power_state(pdev, PCI_D3hot);
6738 }
6739
6740 return 0;
6741}
6742#endif /* CONFIG_PM */
6743
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006744static void ixgbe_shutdown(struct pci_dev *pdev)
6745{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006746 bool wake;
6747
6748 __ixgbe_shutdown(pdev, &wake);
6749
6750 if (system_state == SYSTEM_POWER_OFF) {
6751 pci_wake_from_d3(pdev, wake);
6752 pci_set_power_state(pdev, PCI_D3hot);
6753 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006754}
6755
6756/**
Auke Kok9a799d72007-09-15 14:07:45 -07006757 * ixgbe_update_stats - Update the board statistics counters.
6758 * @adapter: board private structure
6759 **/
6760void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6761{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006762 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006763 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006764 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006765 u64 total_mpc = 0;
6766 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006767 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6768 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006769 u64 alloc_rx_page = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006770 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006771
Don Skidmored08935c2010-06-11 13:20:29 +00006772 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6773 test_bit(__IXGBE_RESETTING, &adapter->state))
6774 return;
6775
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006776 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006777 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006778 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006779 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006780 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6781 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006782 }
6783 adapter->rsc_total_count = rsc_count;
6784 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006785 }
6786
Alexander Duyck5b7da512010-11-16 19:26:50 -08006787 for (i = 0; i < adapter->num_rx_queues; i++) {
6788 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6789 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006790 alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006791 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6792 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006793 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006794 bytes += rx_ring->stats.bytes;
6795 packets += rx_ring->stats.packets;
6796 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006797 adapter->non_eop_descs = non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006798 adapter->alloc_rx_page = alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006799 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6800 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006801 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006802 netdev->stats.rx_bytes = bytes;
6803 netdev->stats.rx_packets = packets;
6804
6805 bytes = 0;
6806 packets = 0;
6807 /* gather some stats to the adapter struct that are per queue */
6808 for (i = 0; i < adapter->num_tx_queues; i++) {
6809 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6810 restart_queue += tx_ring->tx_stats.restart_queue;
6811 tx_busy += tx_ring->tx_stats.tx_busy;
6812 bytes += tx_ring->stats.bytes;
6813 packets += tx_ring->stats.packets;
6814 }
John Fastabend33fdc822017-04-24 03:30:18 -07006815 for (i = 0; i < adapter->num_xdp_queues; i++) {
6816 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
6817
6818 restart_queue += xdp_ring->tx_stats.restart_queue;
6819 tx_busy += xdp_ring->tx_stats.tx_busy;
6820 bytes += xdp_ring->stats.bytes;
6821 packets += xdp_ring->stats.packets;
6822 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08006823 adapter->restart_queue = restart_queue;
6824 adapter->tx_busy = tx_busy;
6825 netdev->stats.tx_bytes = bytes;
6826 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006827
Joe Perches7ca647b2010-09-07 21:35:40 +00006828 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006829
6830 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006831 for (i = 0; i < 8; i++) {
6832 /* for packet buffers not used, the register should read 0 */
6833 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6834 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006835 hwstats->mpc[i] += mpc;
6836 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006837 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6838 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006839 switch (hw->mac.type) {
6840 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006841 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6842 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6843 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006844 hwstats->pxonrxc[i] +=
6845 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006846 break;
6847 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006848 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006849 case ixgbe_mac_X550:
6850 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006851 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006852 hwstats->pxonrxc[i] +=
6853 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006854 break;
6855 default:
6856 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006857 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006858 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006859
6860 /*16 register reads */
6861 for (i = 0; i < 16; i++) {
6862 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6863 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6864 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006865 (hw->mac.type == ixgbe_mac_X540) ||
6866 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006867 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6868 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006869 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6870 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6871 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6872 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6873 }
6874 }
6875
Joe Perches7ca647b2010-09-07 21:35:40 +00006876 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006877 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006878 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006879
John Fastabendc84d3242010-11-16 19:27:12 -08006880 ixgbe_update_xoff_received(adapter);
6881
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006882 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006883 switch (hw->mac.type) {
6884 case ixgbe_mac_82598EB:
6885 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006886 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6887 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6888 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6889 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006890 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006891 case ixgbe_mac_X550:
6892 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006893 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006894 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006895 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6896 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6897 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6898 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
Tony Nguyen93df9462017-05-31 04:43:47 -07006899 /* fall through */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006900 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006901 for (i = 0; i < 16; i++)
6902 adapter->hw_rx_no_dma_resources +=
6903 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006904 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006905 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006906 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006907 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006908 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006909 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006910 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006911 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6912 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006913#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006914 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6915 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6916 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6917 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6918 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6919 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006920 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006921 if (adapter->fcoe.ddp_pool) {
6922 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6923 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6924 unsigned int cpu;
6925 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006926 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006927 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6928 noddp += ddp_pool->noddp;
6929 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006930 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006931 hwstats->fcoe_noddp = noddp;
6932 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006933 }
Yi Zou6d455222009-05-13 13:12:16 +00006934#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006935 break;
6936 default:
6937 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006938 }
Auke Kok9a799d72007-09-15 14:07:45 -07006939 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006940 hwstats->bprc += bprc;
6941 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006942 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006943 hwstats->mprc -= bprc;
6944 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6945 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6946 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6947 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6948 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6949 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6950 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6951 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006952 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006953 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006954 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006955 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006956 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6957 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006958 /*
6959 * 82598 errata - tx of flow control packets is included in tx counters
6960 */
6961 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006962 hwstats->gptc -= xon_off_tot;
6963 hwstats->mptc -= xon_off_tot;
6964 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6965 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6966 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6967 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6968 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6969 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6970 hwstats->ptc64 -= xon_off_tot;
6971 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6972 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6973 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6974 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6975 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6976 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006977
6978 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006979 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006980
6981 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006982 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006983 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006984 netdev->stats.rx_length_errors = hwstats->rlec;
6985 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006986 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006987}
6988
6989/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006990 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006991 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006992 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006993static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006994{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006995 struct ixgbe_hw *hw = &adapter->hw;
6996 int i;
6997
Alexander Duyckd034acf2011-04-27 09:25:34 +00006998 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
6999 return;
7000
7001 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
7002
7003 /* if interface is down do nothing */
7004 if (test_bit(__IXGBE_DOWN, &adapter->state))
7005 return;
7006
7007 /* do nothing if we are not using signature filters */
7008 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
7009 return;
7010
7011 adapter->fdir_overflow++;
7012
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007013 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
7014 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08007015 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00007016 &(adapter->tx_ring[i]->state));
John Fastabend33fdc822017-04-24 03:30:18 -07007017 for (i = 0; i < adapter->num_xdp_queues; i++)
7018 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
7019 &adapter->xdp_ring[i]->state);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007020 /* re-enable flow director interrupts */
7021 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007022 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00007023 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00007024 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007025 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007026}
7027
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007028/**
7029 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007030 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007031 *
7032 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007033 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007034 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007035 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007036 */
7037static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
7038{
Auke Kok9a799d72007-09-15 14:07:45 -07007039 struct ixgbe_hw *hw = &adapter->hw;
7040 u64 eics = 0;
7041 int i;
7042
Mark Rustad09f40ae2014-01-14 18:53:11 -08007043 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007044 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007045 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007046 test_bit(__IXGBE_RESETTING, &adapter->state))
7047 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00007048
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007049 /* Force detection of hung controller */
7050 if (netif_carrier_ok(adapter->netdev)) {
7051 for (i = 0; i < adapter->num_tx_queues; i++)
7052 set_check_for_tx_hang(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07007053 for (i = 0; i < adapter->num_xdp_queues; i++)
7054 set_check_for_tx_hang(adapter->xdp_ring[i]);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007055 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007056
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007057 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00007058 /*
7059 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007060 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00007061 * would set *both* EIMS and EICS for any bit in EIAM
7062 */
7063 IXGBE_WRITE_REG(hw, IXGBE_EICS,
7064 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007065 } else {
7066 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00007067 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007068 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00007069 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07007070 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007071 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007072 }
7073
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007074 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00007075 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00007076}
7077
7078/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007079 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007080 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007081 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007082static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007083{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007084 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007085 u32 link_speed = adapter->link_speed;
7086 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00007087 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007088
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007089 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
7090 return;
7091
7092 if (hw->mac.ops.check_link) {
7093 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007094 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007095 /* always assume link is up, if no check link function */
7096 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
7097 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007098 }
Alexander Duyck041441d2012-04-19 17:48:48 +00007099
7100 if (adapter->ixgbe_ieee_pfc)
7101 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
7102
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007103 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00007104 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007105 ixgbe_set_rx_drop_en(adapter);
7106 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007107
7108 if (link_up ||
7109 time_after(jiffies, (adapter->link_check_timeout +
7110 IXGBE_TRY_LINK_TIMEOUT))) {
7111 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
7112 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
7113 IXGBE_WRITE_FLUSH(hw);
7114 }
7115
7116 adapter->link_up = link_up;
7117 adapter->link_speed = link_speed;
7118}
7119
Alexander Duyck107d3012012-10-02 00:17:03 +00007120static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
7121{
7122#ifdef CONFIG_IXGBE_DCB
7123 struct net_device *netdev = adapter->netdev;
7124 struct dcb_app app = {
7125 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
7126 .protocol = 0,
7127 };
7128 u8 up = 0;
7129
7130 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
7131 up = dcb_ieee_getapp_mask(netdev, &app);
7132
7133 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
7134#endif
7135}
7136
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007137/**
7138 * ixgbe_watchdog_link_is_up - update netif_carrier status and
7139 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007140 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007141 **/
7142static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
7143{
7144 struct net_device *netdev = adapter->netdev;
7145 struct ixgbe_hw *hw = &adapter->hw;
7146 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07007147 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007148 bool flow_rx, flow_tx;
7149
7150 /* only continue if link was previously down */
7151 if (netif_carrier_ok(netdev))
7152 return;
7153
7154 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7155
7156 switch (hw->mac.type) {
7157 case ixgbe_mac_82598EB: {
7158 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
7159 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
7160 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
7161 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
7162 }
7163 break;
7164 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007165 case ixgbe_mac_X550:
7166 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07007167 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007168 case ixgbe_mac_82599EB: {
7169 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
7170 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
7171 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
7172 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
7173 }
7174 break;
7175 default:
7176 flow_tx = false;
7177 flow_rx = false;
7178 break;
7179 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007180
Jacob Keller6cb562d2012-12-05 07:24:41 +00007181 adapter->last_rx_ptp_check = jiffies;
7182
Jacob Keller8fecf672013-06-21 08:14:32 +00007183 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007184 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007185
Mark Rustad454adb02015-07-10 14:19:22 -07007186 switch (link_speed) {
7187 case IXGBE_LINK_SPEED_10GB_FULL:
7188 speed_str = "10 Gbps";
7189 break;
Paul Greenwalt06e3f942018-01-11 09:10:51 -05007190 case IXGBE_LINK_SPEED_5GB_FULL:
7191 speed_str = "5 Gbps";
7192 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007193 case IXGBE_LINK_SPEED_2_5GB_FULL:
7194 speed_str = "2.5 Gbps";
7195 break;
7196 case IXGBE_LINK_SPEED_1GB_FULL:
7197 speed_str = "1 Gbps";
7198 break;
7199 case IXGBE_LINK_SPEED_100_FULL:
7200 speed_str = "100 Mbps";
7201 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08007202 case IXGBE_LINK_SPEED_10_FULL:
7203 speed_str = "10 Mbps";
7204 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007205 default:
7206 speed_str = "unknown speed";
7207 break;
7208 }
7209 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007210 ((flow_rx && flow_tx) ? "RX/TX" :
7211 (flow_rx ? "RX" :
7212 (flow_tx ? "TX" : "None"))));
7213
7214 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007215 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007216
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007217 /* enable transmits */
7218 netif_tx_wake_all_queues(adapter->netdev);
7219
Alexander Duyck107d3012012-10-02 00:17:03 +00007220 /* update the default user priority for VFs */
7221 ixgbe_update_default_up(adapter);
7222
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007223 /* ping all the active vfs to let them know link has changed */
7224 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007225}
7226
7227/**
7228 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7229 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007230 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007231 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007232static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007233{
7234 struct net_device *netdev = adapter->netdev;
7235 struct ixgbe_hw *hw = &adapter->hw;
7236
7237 adapter->link_up = false;
7238 adapter->link_speed = 0;
7239
7240 /* only continue if link was up previously */
7241 if (!netif_carrier_ok(netdev))
7242 return;
7243
7244 /* poll for SFP+ cable when link is down */
7245 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7246 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7247
Jacob Keller8fecf672013-06-21 08:14:32 +00007248 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007249 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007250
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007251 e_info(drv, "NIC Link is Down\n");
7252 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007253
7254 /* ping all the active vfs to let them know link has changed */
7255 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007256}
7257
Emil Tantilov07923c12014-08-12 07:12:08 +00007258static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7259{
7260 int i;
7261
7262 for (i = 0; i < adapter->num_tx_queues; i++) {
7263 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7264
7265 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7266 return true;
7267 }
7268
John Fastabend33fdc822017-04-24 03:30:18 -07007269 for (i = 0; i < adapter->num_xdp_queues; i++) {
7270 struct ixgbe_ring *ring = adapter->xdp_ring[i];
7271
7272 if (ring->next_to_use != ring->next_to_clean)
7273 return true;
7274 }
7275
Emil Tantilov07923c12014-08-12 07:12:08 +00007276 return false;
7277}
7278
7279static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7280{
7281 struct ixgbe_hw *hw = &adapter->hw;
7282 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7283 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7284
7285 int i, j;
7286
7287 if (!adapter->num_vfs)
7288 return false;
7289
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007290 /* resetting the PF is only needed for MAC before X550 */
7291 if (hw->mac.type >= ixgbe_mac_X550)
7292 return false;
7293
Emil Tantilov07923c12014-08-12 07:12:08 +00007294 for (i = 0; i < adapter->num_vfs; i++) {
7295 for (j = 0; j < q_per_pool; j++) {
7296 u32 h, t;
7297
7298 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7299 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7300
7301 if (h != t)
7302 return true;
7303 }
7304 }
7305
7306 return false;
7307}
7308
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007309/**
7310 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007311 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007312 **/
7313static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7314{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007315 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007316 if (ixgbe_ring_tx_pending(adapter) ||
7317 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007318 /* We've lost link, so the controller stops DMA,
7319 * but we've got queued Tx work that's never going
7320 * to get done, so reset controller to flush Tx.
7321 * (Do the reset outside of interrupt context).
7322 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007323 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007324 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007325 }
7326 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007327}
7328
Emil Tantilov9079e412014-11-19 03:18:19 +00007329#ifdef CONFIG_PCI_IOV
Emil Tantilov9079e412014-11-19 03:18:19 +00007330static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7331{
7332 struct ixgbe_hw *hw = &adapter->hw;
7333 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007334 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007335 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007336
7337 if (!(netif_carrier_ok(adapter->netdev)))
7338 return;
7339
7340 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7341 if (gpc) /* If incrementing then no need for the check below */
7342 return;
7343 /* Check to see if a bad DMA write target from an errant or
7344 * malicious VF has caused a PCIe error. If so then we can
7345 * issue a VFLR to the offending VF(s) and then resume without
7346 * requesting a full slot reset.
7347 */
7348
7349 if (!pdev)
7350 return;
7351
Emil Tantilov9079e412014-11-19 03:18:19 +00007352 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007353 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7354 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7355 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007356
Mark Rustad988d1302015-10-30 15:29:34 -07007357 if (!vfdev)
7358 continue;
7359 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7360 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7361 status_reg & PCI_STATUS_REC_MASTER_ABORT)
Christoph Hellwig63af8f72017-04-14 21:11:28 +02007362 pcie_flr(vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007363 }
7364}
7365
Greg Rosea985b6c32010-11-18 03:02:52 +00007366static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7367{
7368 u32 ssvpc;
7369
Greg Rose0584d992012-08-08 00:00:58 +00007370 /* Do not perform spoof check for 82598 or if not in IOV mode */
7371 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7372 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007373 return;
7374
7375 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7376
7377 /*
7378 * ssvpc register is cleared on read, if zero then no
7379 * spoofed packets in the last interval.
7380 */
7381 if (!ssvpc)
7382 return;
7383
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007384 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007385}
Emil Tantilov9079e412014-11-19 03:18:19 +00007386#else
7387static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7388{
7389}
7390
7391static void
7392ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7393{
7394}
7395#endif /* CONFIG_PCI_IOV */
7396
Greg Rosea985b6c32010-11-18 03:02:52 +00007397
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007398/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007399 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007400 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007401 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007402static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007403{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007404 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007405 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007406 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007407 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007408 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007409
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007410 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007411
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007412 if (adapter->link_up)
7413 ixgbe_watchdog_link_is_up(adapter);
7414 else
7415 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007416
Emil Tantilov9079e412014-11-19 03:18:19 +00007417 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007418 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007419 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007420
7421 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007422}
7423
Alexander Duyck70864002011-04-27 09:13:56 +00007424/**
7425 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007426 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007427 **/
7428static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7429{
7430 struct ixgbe_hw *hw = &adapter->hw;
7431 s32 err;
7432
7433 /* not searching for SFP so there is nothing to do here */
7434 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7435 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7436 return;
7437
Mark Rustad58e7cd22015-08-08 16:18:48 -07007438 if (adapter->sfp_poll_time &&
7439 time_after(adapter->sfp_poll_time, jiffies))
7440 return; /* If not yet time to poll for SFP */
7441
Alexander Duyck70864002011-04-27 09:13:56 +00007442 /* someone else is in init, wait until next service event */
7443 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7444 return;
7445
Mark Rustad58e7cd22015-08-08 16:18:48 -07007446 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7447
Alexander Duyck70864002011-04-27 09:13:56 +00007448 err = hw->phy.ops.identify_sfp(hw);
7449 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7450 goto sfp_out;
7451
7452 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7453 /* If no cable is present, then we need to reset
7454 * the next time we find a good cable. */
7455 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7456 }
7457
7458 /* exit on error */
7459 if (err)
7460 goto sfp_out;
7461
7462 /* exit if reset not needed */
7463 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7464 goto sfp_out;
7465
7466 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7467
7468 /*
7469 * A module may be identified correctly, but the EEPROM may not have
7470 * support for that module. setup_sfp() will fail in that case, so
7471 * we should not allow that module to load.
7472 */
7473 if (hw->mac.type == ixgbe_mac_82598EB)
7474 err = hw->phy.ops.reset(hw);
7475 else
7476 err = hw->mac.ops.setup_sfp(hw);
7477
7478 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7479 goto sfp_out;
7480
7481 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7482 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7483
7484sfp_out:
7485 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7486
7487 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7488 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7489 e_dev_err("failed to initialize because an unsupported "
7490 "SFP+ module type was detected.\n");
7491 e_dev_err("Reload the driver after installing a "
7492 "supported module.\n");
7493 unregister_netdev(adapter->netdev);
7494 }
7495}
7496
7497/**
7498 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007499 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007500 **/
7501static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7502{
7503 struct ixgbe_hw *hw = &adapter->hw;
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007504 u32 cap_speed;
Josh Hay3d292262012-12-15 03:28:19 +00007505 u32 speed;
7506 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007507
7508 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7509 return;
7510
7511 /* someone else is in init, wait until next service event */
7512 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7513 return;
7514
7515 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7516
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007517 hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007518
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007519 /* advertise highest capable link speed */
7520 if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
7521 speed = IXGBE_LINK_SPEED_10GB_FULL;
7522 else
7523 speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
7524 IXGBE_LINK_SPEED_1GB_FULL);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007525
Alexander Duyck70864002011-04-27 09:13:56 +00007526 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007527 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007528
7529 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7530 adapter->link_check_timeout = jiffies;
7531 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7532}
7533
7534/**
7535 * ixgbe_service_timer - Timer Call-back
Tony Nguyen5ba643c2017-12-04 11:28:30 -08007536 * @t: pointer to timer_list structure
Alexander Duyck70864002011-04-27 09:13:56 +00007537 **/
Kees Cook26566ea2017-10-16 17:29:35 -07007538static void ixgbe_service_timer(struct timer_list *t)
Alexander Duyck70864002011-04-27 09:13:56 +00007539{
Kees Cook26566ea2017-10-16 17:29:35 -07007540 struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
Alexander Duyck70864002011-04-27 09:13:56 +00007541 unsigned long next_event_offset;
7542
7543 /* poll faster when waiting for link */
7544 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7545 next_event_offset = HZ / 10;
7546 else
7547 next_event_offset = HZ * 2;
7548
7549 /* Reset the timer */
7550 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7551
Emil Tantilov9079e412014-11-19 03:18:19 +00007552 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007553}
7554
Don Skidmore597f22d2015-06-09 16:52:02 -07007555static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7556{
7557 struct ixgbe_hw *hw = &adapter->hw;
7558 u32 status;
7559
7560 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7561 return;
7562
7563 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7564
7565 if (!hw->phy.ops.handle_lasi)
7566 return;
7567
7568 status = hw->phy.ops.handle_lasi(&adapter->hw);
7569 if (status != IXGBE_ERR_OVERTEMP)
7570 return;
7571
7572 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7573}
7574
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007575static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7576{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007577 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007578 return;
7579
Tony Nguyen88adce42018-05-30 09:05:12 -07007580 rtnl_lock();
Mark Rustad09f40ae2014-01-14 18:53:11 -08007581 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007582 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007583 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Tony Nguyen88adce42018-05-30 09:05:12 -07007584 test_bit(__IXGBE_RESETTING, &adapter->state)) {
7585 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007586 return;
Tony Nguyen88adce42018-05-30 09:05:12 -07007587 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007588
7589 ixgbe_dump(adapter);
7590 netdev_err(adapter->netdev, "Reset adapter\n");
7591 adapter->tx_timeout_count++;
7592
7593 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007594 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007595}
7596
Alexander Duyck70864002011-04-27 09:13:56 +00007597/**
7598 * ixgbe_service_task - manages and runs subtasks
7599 * @work: pointer to work_struct containing our data
7600 **/
7601static void ixgbe_service_task(struct work_struct *work)
7602{
7603 struct ixgbe_adapter *adapter = container_of(work,
7604 struct ixgbe_adapter,
7605 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007606 if (ixgbe_removed(adapter->hw.hw_addr)) {
7607 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7608 rtnl_lock();
7609 ixgbe_down(adapter);
7610 rtnl_unlock();
7611 }
7612 ixgbe_service_event_complete(adapter);
7613 return;
7614 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007615 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007616 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007617 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007618 udp_tunnel_get_rx_info(adapter->netdev);
7619 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007620 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007621 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007622 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007623 ixgbe_sfp_detection_subtask(adapter);
7624 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007625 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007626 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007627 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007628 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007629
Jacob Keller8fecf672013-06-21 08:14:32 +00007630 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007631 ixgbe_ptp_overflow_check(adapter);
Jacob Keller6704a3a2018-01-29 15:57:48 -08007632 if (adapter->flags & IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER)
7633 ixgbe_ptp_rx_hang(adapter);
Jacob Keller622a2ef2017-05-03 10:29:04 -07007634 ixgbe_ptp_tx_hang(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007635 }
Alexander Duyck70864002011-04-27 09:13:56 +00007636
7637 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007638}
7639
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007640static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7641 struct ixgbe_tx_buffer *first,
Shannon Nelson70da6822018-03-16 11:09:07 -07007642 u8 *hdr_len,
7643 struct ixgbe_ipsec_tx_data *itd)
Alexander Duyck897ab152011-05-27 05:31:47 +00007644{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007645 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007646 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007647 union {
7648 struct iphdr *v4;
7649 struct ipv6hdr *v6;
7650 unsigned char *hdr;
7651 } ip;
7652 union {
7653 struct tcphdr *tcp;
7654 unsigned char *hdr;
7655 } l4;
7656 u32 paylen, l4_offset;
Shannon Nelson70da6822018-03-16 11:09:07 -07007657 u32 fceof_saidx = 0;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007658 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007659
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007660 if (skb->ip_summed != CHECKSUM_PARTIAL)
7661 return 0;
7662
Alexander Duyck897ab152011-05-27 05:31:47 +00007663 if (!skb_is_gso(skb))
7664 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007665
Francois Romieu2049e1f2014-03-30 03:14:27 +00007666 err = skb_cow_head(skb, 0);
7667 if (err < 0)
7668 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007669
Scott Peterson2a205252016-11-18 11:25:42 -08007670 if (eth_p_mpls(first->protocol))
7671 ip.hdr = skb_inner_network_header(skb);
7672 else
7673 ip.hdr = skb_network_header(skb);
Alexander Duyckb83e3012016-04-14 17:19:31 -04007674 l4.hdr = skb_checksum_start(skb);
7675
Alexander Duyck897ab152011-05-27 05:31:47 +00007676 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7677 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7678
Alexander Duyckb83e3012016-04-14 17:19:31 -04007679 /* initialize outer IP header fields */
7680 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007681 unsigned char *csum_start = skb_checksum_start(skb);
7682 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
Shannon Nelson70da6822018-03-16 11:09:07 -07007683 int len = csum_start - trans_start;
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007684
Alexander Duyckb83e3012016-04-14 17:19:31 -04007685 /* IP header will have to cancel out any data that
Shannon Nelson70da6822018-03-16 11:09:07 -07007686 * is not a part of the outer IP header, so set to
7687 * a reverse csum if needed, else init check to 0.
Alexander Duyckb83e3012016-04-14 17:19:31 -04007688 */
Shannon Nelson70da6822018-03-16 11:09:07 -07007689 ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ?
7690 csum_fold(csum_partial(trans_start,
7691 len, 0)) : 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007692 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007693
7694 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007695 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7696 IXGBE_TX_FLAGS_CSUM |
7697 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007698 } else {
7699 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007700 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7701 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007702 }
7703
Alexander Duyckb83e3012016-04-14 17:19:31 -04007704 /* determine offset of inner transport header */
7705 l4_offset = l4.hdr - skb->data;
7706
7707 /* compute length of segmentation header */
7708 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7709
7710 /* remove payload length from inner checksum */
7711 paylen = skb->len - l4_offset;
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07007712 csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007713
Alexander Duyck091a6242012-02-08 07:51:01 +00007714 /* update gso size and bytecount with header size */
7715 first->gso_segs = skb_shinfo(skb)->gso_segs;
7716 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7717
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007718 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007719 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007720 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007721
Shannon Nelson70da6822018-03-16 11:09:07 -07007722 fceof_saidx |= itd->sa_idx;
7723 type_tucmd |= itd->flags | itd->trailer_len;
7724
Alexander Duyck897ab152011-05-27 05:31:47 +00007725 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007726 vlan_macip_lens = l4.hdr - ip.hdr;
7727 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007728 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007729
Shannon Nelson70da6822018-03-16 11:09:07 -07007730 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007731 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007732
7733 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007734}
7735
Alexander Duyck49763de2016-01-13 07:31:11 -08007736static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7737{
7738 unsigned int offset = 0;
7739
7740 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7741
7742 return offset == skb_checksum_start_offset(skb);
7743}
7744
Alexander Duyck244e27a2012-02-08 07:51:11 +00007745static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Shannon Nelson59259472017-12-19 16:00:00 -08007746 struct ixgbe_tx_buffer *first,
7747 struct ixgbe_ipsec_tx_data *itd)
Auke Kok9a799d72007-09-15 14:07:45 -07007748{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007749 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007750 u32 vlan_macip_lens = 0;
Shannon Nelson59259472017-12-19 16:00:00 -08007751 u32 fceof_saidx = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007752 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007753
Alexander Duyck897ab152011-05-27 05:31:47 +00007754 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007755csum_failed:
7756 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7757 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007758 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007759 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007760 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007761
Alexander Duyck49763de2016-01-13 07:31:11 -08007762 switch (skb->csum_offset) {
7763 case offsetof(struct tcphdr, check):
7764 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7765 /* fall through */
7766 case offsetof(struct udphdr, check):
7767 break;
7768 case offsetof(struct sctphdr, checksum):
7769 /* validate that this is actually an SCTP request */
7770 if (((first->protocol == htons(ETH_P_IP)) &&
7771 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7772 ((first->protocol == htons(ETH_P_IPV6)) &&
7773 ixgbe_ipv6_csum_is_sctp(skb))) {
7774 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7775 break;
7776 }
7777 /* fall through */
7778 default:
7779 skb_checksum_help(skb);
7780 goto csum_failed;
7781 }
7782
7783 /* update TX checksum flag */
7784 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7785 vlan_macip_lens = skb_checksum_start_offset(skb) -
7786 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007787no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007788 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007789 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007790 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007791
Shannon Nelson871dd092018-03-16 11:09:05 -07007792 fceof_saidx |= itd->sa_idx;
7793 type_tucmd |= itd->flags | itd->trailer_len;
Shannon Nelson59259472017-12-19 16:00:00 -08007794
7795 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007796}
7797
Alexander Duyck472148c2012-11-07 02:34:28 +00007798#define IXGBE_SET_FLAG(_input, _flag, _result) \
7799 ((_flag <= _result) ? \
7800 ((u32)(_input & _flag) * (_result / _flag)) : \
7801 ((u32)(_input & _flag) / (_flag / _result)))
7802
7803static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007804{
7805 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007806 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7807 IXGBE_ADVTXD_DCMD_DEXT |
7808 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007809
7810 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007811 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7812 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007813
Alexander Duyckd3d00232011-07-15 02:31:25 +00007814 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007815 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7816 IXGBE_ADVTXD_DCMD_TSE);
7817
7818 /* set timestamp bit if present */
7819 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7820 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007821
Alexander Duyck62748b72012-07-20 08:09:01 +00007822 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007823 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007824
Alexander Duyckd3d00232011-07-15 02:31:25 +00007825 return cmd_type;
7826}
7827
Alexander Duyck729739b2012-02-08 07:51:06 +00007828static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7829 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007830{
Alexander Duyck472148c2012-11-07 02:34:28 +00007831 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007832
7833 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007834 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7835 IXGBE_TX_FLAGS_CSUM,
7836 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007837
Shannon Nelson59259472017-12-19 16:00:00 -08007838 /* enable IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007839 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7840 IXGBE_TX_FLAGS_IPV4,
7841 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007842
Shannon Nelson59259472017-12-19 16:00:00 -08007843 /* enable IPsec */
7844 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7845 IXGBE_TX_FLAGS_IPSEC,
7846 IXGBE_ADVTXD_POPTS_IPSEC);
7847
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007848 /*
7849 * Check Context must be set if Tx switch is enabled, which it
7850 * always is for case where virtual functions are running
7851 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007852 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7853 IXGBE_TX_FLAGS_CC,
7854 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007855
Alexander Duyck472148c2012-11-07 02:34:28 +00007856 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007857}
7858
Daniel Borkmann2367a172014-08-26 19:34:18 +02007859static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7860{
7861 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7862
7863 /* Herbert's original patch had:
7864 * smp_mb__after_netif_stop_queue();
7865 * but since that doesn't exist yet, just open code it.
7866 */
7867 smp_mb();
7868
7869 /* We need to check again in a case another CPU has just
7870 * made room available.
7871 */
7872 if (likely(ixgbe_desc_unused(tx_ring) < size))
7873 return -EBUSY;
7874
7875 /* A reprieve! - use start_queue because it doesn't call schedule */
7876 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7877 ++tx_ring->tx_stats.restart_queue;
7878 return 0;
7879}
7880
7881static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7882{
7883 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7884 return 0;
7885
7886 return __ixgbe_maybe_stop_tx(tx_ring, size);
7887}
7888
Alexander Duyckd3d00232011-07-15 02:31:25 +00007889#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7890 IXGBE_TXD_CMD_RS)
7891
Jacob Keller5fef1242017-05-03 10:28:56 -07007892static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
7893 struct ixgbe_tx_buffer *first,
7894 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007895{
Alexander Duyck729739b2012-02-08 07:51:06 +00007896 struct sk_buff *skb = first->skb;
7897 struct ixgbe_tx_buffer *tx_buffer;
7898 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007899 struct skb_frag_struct *frag;
7900 dma_addr_t dma;
7901 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007902 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007903 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007904 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007905
Alexander Duyck729739b2012-02-08 07:51:06 +00007906 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7907
Alexander Duyckec718252012-10-30 06:01:55 +00007908 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7909
7910 size = skb_headlen(skb);
7911 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007912
Alexander Duyckd3d00232011-07-15 02:31:25 +00007913#ifdef IXGBE_FCOE
7914 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007915 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007916 size -= sizeof(struct fcoe_crc_eof) - data_len;
7917 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007918 } else {
7919 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007920 }
Auke Kok9a799d72007-09-15 14:07:45 -07007921 }
7922
Alexander Duyckd3d00232011-07-15 02:31:25 +00007923#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007924 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007925
Alexander Duyckec718252012-10-30 06:01:55 +00007926 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007927
Alexander Duyckec718252012-10-30 06:01:55 +00007928 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7929 if (dma_mapping_error(tx_ring->dev, dma))
7930 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007931
Alexander Duyckec718252012-10-30 06:01:55 +00007932 /* record length, and DMA address */
7933 dma_unmap_len_set(tx_buffer, len, size);
7934 dma_unmap_addr_set(tx_buffer, dma, dma);
7935
7936 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7937
Alexander Duyck729739b2012-02-08 07:51:06 +00007938 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007939 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007940 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007941
Alexander Duyckd3d00232011-07-15 02:31:25 +00007942 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007943 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007944 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007945 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007946 i = 0;
7947 }
Alexander Duyckec718252012-10-30 06:01:55 +00007948 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007949
7950 dma += IXGBE_MAX_DATA_PER_TXD;
7951 size -= IXGBE_MAX_DATA_PER_TXD;
7952
7953 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007954 }
7955
Alexander Duyck729739b2012-02-08 07:51:06 +00007956 if (likely(!data_len))
7957 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007958
Alexander Duyck472148c2012-11-07 02:34:28 +00007959 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007960
Alexander Duyck729739b2012-02-08 07:51:06 +00007961 i++;
7962 tx_desc++;
7963 if (i == tx_ring->count) {
7964 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7965 i = 0;
7966 }
Alexander Duyckec718252012-10-30 06:01:55 +00007967 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007968
Alexander Duyckd3d00232011-07-15 02:31:25 +00007969#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007970 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007971#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007972 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007973#endif
7974 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007975
Alexander Duyck729739b2012-02-08 07:51:06 +00007976 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7977 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007978
Alexander Duyck729739b2012-02-08 07:51:06 +00007979 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007980 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007981
Alexander Duyck729739b2012-02-08 07:51:06 +00007982 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007983 cmd_type |= size | IXGBE_TXD_CMD;
7984 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007985
Alexander Duyck091a6242012-02-08 07:51:01 +00007986 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007987
Alexander Duyckd3d00232011-07-15 02:31:25 +00007988 /* set the timestamp */
7989 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007990
7991 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007992 * Force memory writes to complete before letting h/w know there
7993 * are new descriptors to fetch. (Only applicable for weak-ordered
7994 * memory model archs, such as IA-64).
7995 *
7996 * We also need this memory barrier to make certain all of the
7997 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07007998 */
7999 wmb();
8000
Alexander Duyckd3d00232011-07-15 02:31:25 +00008001 /* set next_to_watch value indicating a packet is present */
8002 first->next_to_watch = tx_desc;
8003
Alexander Duyck729739b2012-02-08 07:51:06 +00008004 i++;
8005 if (i == tx_ring->count)
8006 i = 0;
8007
8008 tx_ring->next_to_use = i;
8009
Daniel Borkmann2367a172014-08-26 19:34:18 +02008010 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
8011
8012 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00008013 writel(i, tx_ring->tail);
8014
8015 /* we need this if more than one processor can write to our tail
8016 * at a time, it synchronizes IO on IA64/Altix systems
8017 */
8018 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02008019 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02008020
Jacob Keller5fef1242017-05-03 10:28:56 -07008021 return 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008022dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00008023 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00008024
8025 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyck069db9c2017-10-19 17:07:13 -04008026 for (;;) {
8027 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckffed21b2017-01-17 08:37:29 -08008028 if (dma_unmap_len(tx_buffer, len))
8029 dma_unmap_page(tx_ring->dev,
8030 dma_unmap_addr(tx_buffer, dma),
8031 dma_unmap_len(tx_buffer, len),
8032 DMA_TO_DEVICE);
8033 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyck069db9c2017-10-19 17:07:13 -04008034 if (tx_buffer == first)
8035 break;
8036 if (i == 0)
Alexander Duyckffed21b2017-01-17 08:37:29 -08008037 i += tx_ring->count;
Alexander Duyck069db9c2017-10-19 17:07:13 -04008038 i--;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008039 }
8040
Alexander Duyckffed21b2017-01-17 08:37:29 -08008041 dev_kfree_skb_any(first->skb);
8042 first->skb = NULL;
8043
Alexander Duyckd3d00232011-07-15 02:31:25 +00008044 tx_ring->next_to_use = i;
Jacob Keller5fef1242017-05-03 10:28:56 -07008045
8046 return -1;
Auke Kok9a799d72007-09-15 14:07:45 -07008047}
8048
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008049static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00008050 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008051{
Alexander Duyck69830522011-01-06 14:29:58 +00008052 struct ixgbe_q_vector *q_vector = ring->q_vector;
8053 union ixgbe_atr_hash_dword input = { .dword = 0 };
8054 union ixgbe_atr_hash_dword common = { .dword = 0 };
8055 union {
8056 unsigned char *network;
8057 struct iphdr *ipv4;
8058 struct ipv6hdr *ipv6;
8059 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08008060 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08008061 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07008062 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00008063 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08008064 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008065
Alexander Duyck69830522011-01-06 14:29:58 +00008066 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8067 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00008068 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008069
Alexander Duyck69830522011-01-06 14:29:58 +00008070 /* do nothing if sampling is disabled */
8071 if (!ring->atr_sample_rate)
8072 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008073
Alexander Duyck69830522011-01-06 14:29:58 +00008074 ring->atr_count++;
8075
Alexander Duycke2873d42016-01-25 19:39:40 -08008076 /* currently only IPv4/IPv6 with TCP is supported */
8077 if ((first->protocol != htons(ETH_P_IP)) &&
8078 (first->protocol != htons(ETH_P_IPV6)))
8079 return;
8080
Alexander Duyck69830522011-01-06 14:29:58 +00008081 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07008082 skb = first->skb;
8083 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008084 if (unlikely(hdr.network <= skb->data))
8085 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08008086 if (skb->encapsulation &&
8087 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07008088 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07008089 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00008090
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008091 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8092 VXLAN_HEADROOM))
8093 return;
8094
Alexander Duyck9f12df92016-01-25 19:36:29 -08008095 /* verify the port is recognized as VXLAN */
8096 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08008097 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08008098 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07008099
8100 if (adapter->geneve_port &&
8101 udp_hdr(skb)->dest == adapter->geneve_port)
8102 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08008103 }
8104
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008105 /* Make sure we have at least [minimum IPv4 header + TCP]
8106 * or [IPv6 header] bytes
8107 */
8108 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
8109 return;
8110
Mark Rustade19dcde2015-12-09 14:55:37 -08008111 /* Currently only IPv4/IPv6 with TCP is supported */
8112 switch (hdr.ipv4->version) {
8113 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08008114 /* access ihl as u8 to avoid unaligned access on ia64 */
8115 hlen = (hdr.network[0] & 0x0F) << 2;
8116 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08008117 break;
8118 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08008119 hlen = hdr.network - skb->data;
8120 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
8121 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08008122 break;
8123 default:
8124 return;
Mark Rustad67359c32015-06-15 11:33:25 -07008125 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008126
Alexander Duycke2873d42016-01-25 19:39:40 -08008127 if (l4_proto != IPPROTO_TCP)
8128 return;
8129
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008130 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8131 hlen + sizeof(struct tcphdr)))
8132 return;
8133
Alexander Duycke2873d42016-01-25 19:39:40 -08008134 th = (struct tcphdr *)(hdr.network + hlen);
8135
8136 /* skip this packet since the socket is closing */
8137 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00008138 return;
8139
8140 /* sample on all syn packets or once every atr sample count */
8141 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
8142 return;
8143
8144 /* reset sample count */
8145 ring->atr_count = 0;
8146
Alexander Duyck244e27a2012-02-08 07:51:11 +00008147 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00008148
8149 /*
8150 * src and dst are inverted, think how the receiver sees them
8151 *
8152 * The input is broken into two sections, a non-compressed section
8153 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8154 * is XORed together and stored in the compressed dword.
8155 */
8156 input.formatted.vlan_id = vlan_id;
8157
8158 /*
8159 * since src port and flex bytes occupy the same word XOR them together
8160 * and write the value to source port portion of compressed dword
8161 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008162 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00008163 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00008164 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00008165 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00008166 common.port.dst ^= th->source;
8167
Mark Rustade19dcde2015-12-09 14:55:37 -08008168 switch (hdr.ipv4->version) {
8169 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00008170 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
8171 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08008172 break;
8173 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00008174 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
8175 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
8176 hdr.ipv6->saddr.s6_addr32[1] ^
8177 hdr.ipv6->saddr.s6_addr32[2] ^
8178 hdr.ipv6->saddr.s6_addr32[3] ^
8179 hdr.ipv6->daddr.s6_addr32[0] ^
8180 hdr.ipv6->daddr.s6_addr32[1] ^
8181 hdr.ipv6->daddr.s6_addr32[2] ^
8182 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08008183 break;
8184 default:
8185 break;
Alexander Duyck69830522011-01-06 14:29:58 +00008186 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008187
Alexander Duyck9f12df92016-01-25 19:36:29 -08008188 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07008189 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07008190
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008191 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00008192 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
8193 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008194}
8195
Jason Wangf663dd92014-01-10 16:18:26 +08008196static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01008197 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008198{
Jason Wangf663dd92014-01-10 16:18:26 +08008199 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
Alexander Duyck97488bd2013-01-12 06:33:37 +00008200 struct ixgbe_adapter *adapter;
Alexander Duyck97488bd2013-01-12 06:33:37 +00008201 int txq;
Alexander Duyck16be45b2017-11-22 10:57:23 -08008202#ifdef IXGBE_FCOE
8203 struct ixgbe_ring_feature *f;
Jason Wangf663dd92014-01-10 16:18:26 +08008204#endif
8205
Alexander Duyck16be45b2017-11-22 10:57:23 -08008206 if (fwd_adapter) {
8207 adapter = netdev_priv(dev);
8208 txq = reciprocal_scale(skb_get_hash(skb),
8209 adapter->num_rx_queues_per_pool);
8210
8211 return txq + fwd_adapter->tx_base_queue;
8212 }
Jason Wangf663dd92014-01-10 16:18:26 +08008213
8214#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00008215
Alexander Duyck97488bd2013-01-12 06:33:37 +00008216 /*
8217 * only execute the code below if protocol is FCoE
8218 * or FIP and we have FCoE enabled on the adapter
8219 */
8220 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008221 case htons(ETH_P_FCOE):
8222 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008223 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008224
Alexander Duyck97488bd2013-01-12 06:33:37 +00008225 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8226 break;
Tony Nguyen93df9462017-05-31 04:43:47 -07008227 /* fall through */
Alexander Duyck97488bd2013-01-12 06:33:37 +00008228 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008229 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008230 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008231
Alexander Duyck97488bd2013-01-12 06:33:37 +00008232 f = &adapter->ring_feature[RING_F_FCOE];
8233
8234 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8235 smp_processor_id();
8236
8237 while (txq >= f->indices)
8238 txq -= f->indices;
8239
8240 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008241#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008242 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008243#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008244}
8245
John Fastabend33fdc822017-04-24 03:30:18 -07008246static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02008247 struct xdp_frame *xdpf)
John Fastabend33fdc822017-04-24 03:30:18 -07008248{
8249 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
8250 struct ixgbe_tx_buffer *tx_buffer;
8251 union ixgbe_adv_tx_desc *tx_desc;
8252 u32 len, cmd_type;
8253 dma_addr_t dma;
8254 u16 i;
8255
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02008256 len = xdpf->len;
John Fastabend33fdc822017-04-24 03:30:18 -07008257
8258 if (unlikely(!ixgbe_desc_unused(ring)))
8259 return IXGBE_XDP_CONSUMED;
8260
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02008261 dma = dma_map_single(ring->dev, xdpf->data, len, DMA_TO_DEVICE);
John Fastabend33fdc822017-04-24 03:30:18 -07008262 if (dma_mapping_error(ring->dev, dma))
8263 return IXGBE_XDP_CONSUMED;
8264
8265 /* record the location of the first descriptor for this packet */
8266 tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
8267 tx_buffer->bytecount = len;
8268 tx_buffer->gso_segs = 1;
8269 tx_buffer->protocol = 0;
8270
8271 i = ring->next_to_use;
8272 tx_desc = IXGBE_TX_DESC(ring, i);
8273
8274 dma_unmap_len_set(tx_buffer, len, len);
8275 dma_unmap_addr_set(tx_buffer, dma, dma);
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02008276 tx_buffer->xdpf = xdpf;
Jesper Dangaard Brouer189ead82018-04-17 16:45:32 +02008277
John Fastabend33fdc822017-04-24 03:30:18 -07008278 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8279
8280 /* put descriptor type bits */
8281 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8282 IXGBE_ADVTXD_DCMD_DEXT |
8283 IXGBE_ADVTXD_DCMD_IFCS;
8284 cmd_type |= len | IXGBE_TXD_CMD;
8285 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8286 tx_desc->read.olinfo_status =
8287 cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
8288
John Fastabend7379f972017-03-28 09:47:03 -07008289 /* Avoid any potential race with xdp_xmit and cleanup */
8290 smp_wmb();
John Fastabend33fdc822017-04-24 03:30:18 -07008291
8292 /* set next_to_watch value indicating a packet is present */
8293 i++;
8294 if (i == ring->count)
8295 i = 0;
8296
8297 tx_buffer->next_to_watch = tx_desc;
8298 ring->next_to_use = i;
8299
John Fastabend33fdc822017-04-24 03:30:18 -07008300 return IXGBE_XDP_TX;
8301}
8302
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008303netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008304 struct ixgbe_adapter *adapter,
8305 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008306{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008307 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008308 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008309 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008310 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008311 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Shannon Nelson59259472017-12-19 16:00:00 -08008312 struct ixgbe_ipsec_tx_data ipsec_tx = { 0 };
Alexander Duyck66f32a82011-06-29 05:43:22 +00008313 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008314 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008315
Alexander Duycka535c302011-05-27 05:31:52 +00008316 /*
8317 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008318 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008319 * + 2 desc gap to keep tail from touching head,
8320 * + 1 desc for context descriptor,
8321 * otherwise try next time
8322 */
Alexander Duycka535c302011-05-27 05:31:52 +00008323 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8324 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008325
Alexander Duycka535c302011-05-27 05:31:52 +00008326 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8327 tx_ring->tx_stats.tx_busy++;
8328 return NETDEV_TX_BUSY;
8329 }
8330
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008331 /* record the location of the first descriptor for this packet */
8332 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8333 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008334 first->bytecount = skb->len;
8335 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008336
Alexander Duyck66f32a82011-06-29 05:43:22 +00008337 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008338 if (skb_vlan_tag_present(skb)) {
8339 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008340 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8341 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008342 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008343 struct vlan_hdr *vhdr, _vhdr;
8344 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8345 if (!vhdr)
8346 goto out_drop;
8347
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008348 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8349 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008350 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008351 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008352 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008353
Mark Rustadd5234932014-08-09 07:02:09 +00008354 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
Jacob Keller4cc74c02017-05-03 10:29:00 -07008355 adapter->ptp_clock) {
8356 if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8357 &adapter->state)) {
8358 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8359 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008360
Jacob Keller4cc74c02017-05-03 10:29:00 -07008361 /* schedule check for Tx timestamp */
8362 adapter->ptp_tx_skb = skb_get(skb);
8363 adapter->ptp_tx_start = jiffies;
8364 schedule_work(&adapter->ptp_tx_work);
8365 } else {
8366 adapter->tx_hwtstamp_skipped++;
8367 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008368 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008369
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008370 skb_tx_timestamp(skb);
8371
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008372#ifdef CONFIG_PCI_IOV
8373 /*
8374 * Use the l2switch_enable flag - would be false if the DMA
8375 * Tx switch had been disabled.
8376 */
8377 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008378 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008379
8380#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008381 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008382 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008383 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8384 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008385 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008386 tx_flags |= (skb->priority & 0x7) <<
8387 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008388 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8389 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008390
8391 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008392 goto out_drop;
8393 vhdr = (struct vlan_ethhdr *)skb->data;
8394 vhdr->h_vlan_TCI = htons(tx_flags >>
8395 IXGBE_TX_FLAGS_VLAN_SHIFT);
8396 } else {
8397 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8398 }
8399 }
Alexander Duycka535c302011-05-27 05:31:52 +00008400
Alexander Duyck244e27a2012-02-08 07:51:11 +00008401 /* record initial flags and protocol */
8402 first->tx_flags = tx_flags;
8403 first->protocol = protocol;
8404
Yi Zoueacd73f2009-05-13 13:11:06 +00008405#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008406 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008407 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008408 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008409 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008410 if (tso < 0)
8411 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008412
Alexander Duyck66f32a82011-06-29 05:43:22 +00008413 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008414 }
Auke Kok9a799d72007-09-15 14:07:45 -07008415
Auke Kok9a799d72007-09-15 14:07:45 -07008416#endif /* IXGBE_FCOE */
Shannon Nelson59259472017-12-19 16:00:00 -08008417
8418#ifdef CONFIG_XFRM_OFFLOAD
8419 if (skb->sp && !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx))
8420 goto out_drop;
8421#endif
Shannon Nelson70da6822018-03-16 11:09:07 -07008422 tso = ixgbe_tso(tx_ring, first, &hdr_len, &ipsec_tx);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008423 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008424 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008425 else if (!tso)
Shannon Nelson59259472017-12-19 16:00:00 -08008426 ixgbe_tx_csum(tx_ring, first, &ipsec_tx);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008427
8428 /* add the ATR filter if ATR is on */
8429 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008430 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008431
8432#ifdef IXGBE_FCOE
8433xmit_fcoe:
8434#endif /* IXGBE_FCOE */
Jacob Keller5fef1242017-05-03 10:28:56 -07008435 if (ixgbe_tx_map(tx_ring, first, hdr_len))
8436 goto cleanup_tx_timestamp;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008437
Auke Kok9a799d72007-09-15 14:07:45 -07008438 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008439
8440out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008441 dev_kfree_skb_any(first->skb);
8442 first->skb = NULL;
Jacob Keller5fef1242017-05-03 10:28:56 -07008443cleanup_tx_timestamp:
8444 if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
8445 dev_kfree_skb_any(adapter->ptp_tx_skb);
8446 adapter->ptp_tx_skb = NULL;
8447 cancel_work_sync(&adapter->ptp_tx_work);
8448 clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
8449 }
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008450
Alexander Duyck897ab152011-05-27 05:31:47 +00008451 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008452}
8453
John Fastabend2a47fa42013-11-06 09:54:52 -08008454static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8455 struct net_device *netdev,
8456 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008457{
8458 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008459 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008460
Alexander Duycka50c29d2012-02-08 07:50:40 +00008461 /*
8462 * The minimum packet size for olinfo paylen is 17 so pad the skb
8463 * in order to meet this minimum size requirement.
8464 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008465 if (skb_put_padto(skb, 17))
8466 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008467
John Fastabend2a47fa42013-11-06 09:54:52 -08008468 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8469
Auke Kok9a799d72007-09-15 14:07:45 -07008470 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8471}
8472
John Fastabend2a47fa42013-11-06 09:54:52 -08008473static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8474 struct net_device *netdev)
8475{
8476 return __ixgbe_xmit_frame(skb, netdev, NULL);
8477}
8478
Auke Kok9a799d72007-09-15 14:07:45 -07008479/**
8480 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8481 * @netdev: network interface device structure
8482 * @p: pointer to an address structure
8483 *
8484 * Returns 0 on success, negative on failure
8485 **/
8486static int ixgbe_set_mac(struct net_device *netdev, void *p)
8487{
8488 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8489 struct ixgbe_hw *hw = &adapter->hw;
8490 struct sockaddr *addr = p;
8491
8492 if (!is_valid_ether_addr(addr->sa_data))
8493 return -EADDRNOTAVAIL;
8494
8495 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008496 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008497
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008498 ixgbe_mac_set_default_filter(adapter);
8499
8500 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008501}
8502
Ben Hutchings6b73e102009-04-29 08:08:58 +00008503static int
8504ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8505{
8506 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8507 struct ixgbe_hw *hw = &adapter->hw;
8508 u16 value;
8509 int rc;
8510
8511 if (prtad != hw->phy.mdio.prtad)
8512 return -EINVAL;
8513 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8514 if (!rc)
8515 rc = value;
8516 return rc;
8517}
8518
8519static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8520 u16 addr, u16 value)
8521{
8522 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8523 struct ixgbe_hw *hw = &adapter->hw;
8524
8525 if (prtad != hw->phy.mdio.prtad)
8526 return -EINVAL;
8527 return hw->phy.ops.write_reg(hw, addr, devad, value);
8528}
8529
8530static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8531{
8532 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8533
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008534 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008535 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008536 return ixgbe_ptp_set_ts_config(adapter, req);
8537 case SIOCGHWTSTAMP:
8538 return ixgbe_ptp_get_ts_config(adapter, req);
Mark D Rustade0f06bb2016-08-31 10:34:28 -07008539 case SIOCGMIIPHY:
8540 if (!adapter->hw.phy.ops.read_reg)
8541 return -EOPNOTSUPP;
8542 /* fall through */
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008543 default:
8544 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8545 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008546}
8547
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008548/**
8549 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008550 * netdev->dev_addrs
Tony Nguyen5ba643c2017-12-04 11:28:30 -08008551 * @dev: network interface device structure
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008552 *
8553 * Returns non-zero on failure
8554 **/
8555static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8556{
8557 int err = 0;
8558 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008559 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008560
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008561 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008562 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008563 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008564 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008565
8566 /* update SAN MAC vmdq pool selection */
8567 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008568 }
8569 return err;
8570}
8571
8572/**
8573 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008574 * netdev->dev_addrs
Tony Nguyen5ba643c2017-12-04 11:28:30 -08008575 * @dev: network interface device structure
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008576 *
8577 * Returns non-zero on failure
8578 **/
8579static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8580{
8581 int err = 0;
8582 struct ixgbe_adapter *adapter = netdev_priv(dev);
8583 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8584
8585 if (is_valid_ether_addr(mac->san_addr)) {
8586 rtnl_lock();
8587 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8588 rtnl_unlock();
8589 }
8590 return err;
8591}
8592
Auke Kok9a799d72007-09-15 14:07:45 -07008593#ifdef CONFIG_NET_POLL_CONTROLLER
8594/*
8595 * Polling 'interrupt' - used by things like netconsole to send skbs
8596 * without having to re-enable interrupts. It's not called while
8597 * the interrupt routine is executing.
8598 */
8599static void ixgbe_netpoll(struct net_device *netdev)
8600{
8601 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008602 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008603
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008604 /* if interface is down do nothing */
8605 if (test_bit(__IXGBE_DOWN, &adapter->state))
8606 return;
8607
Alexander Duyck856f6062015-02-25 17:45:54 +00008608 /* loop through and schedule all active queues */
8609 for (i = 0; i < adapter->num_q_vectors; i++)
8610 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008611}
Auke Kok9a799d72007-09-15 14:07:45 -07008612
Alexander Duyck581330b2012-02-08 07:51:47 +00008613#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008614
John Fastabend33fdc822017-04-24 03:30:18 -07008615static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
8616 struct ixgbe_ring *ring)
8617{
8618 u64 bytes, packets;
8619 unsigned int start;
8620
8621 if (ring) {
8622 do {
8623 start = u64_stats_fetch_begin_irq(&ring->syncp);
8624 packets = ring->stats.packets;
8625 bytes = ring->stats.bytes;
8626 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8627 stats->tx_packets += packets;
8628 stats->tx_bytes += bytes;
8629 }
8630}
8631
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008632static void ixgbe_get_stats64(struct net_device *netdev,
8633 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008634{
8635 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8636 int i;
8637
Eric Dumazet1a515022010-11-16 19:26:42 -08008638 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008639 for (i = 0; i < adapter->num_rx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008640 struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008641 u64 bytes, packets;
8642 unsigned int start;
8643
Eric Dumazet1a515022010-11-16 19:26:42 -08008644 if (ring) {
8645 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008646 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008647 packets = ring->stats.packets;
8648 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008649 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008650 stats->rx_packets += packets;
8651 stats->rx_bytes += bytes;
8652 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008653 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008654
8655 for (i = 0; i < adapter->num_tx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008656 struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008657
John Fastabend33fdc822017-04-24 03:30:18 -07008658 ixgbe_get_ring_stats64(stats, ring);
8659 }
8660 for (i = 0; i < adapter->num_xdp_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008661 struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07008662
8663 ixgbe_get_ring_stats64(stats, ring);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008664 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008665 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008666
Eric Dumazetde1036b2010-10-20 23:00:04 +00008667 /* following stats updated by ixgbe_watchdog_task() */
8668 stats->multicast = netdev->stats.multicast;
8669 stats->rx_errors = netdev->stats.rx_errors;
8670 stats->rx_length_errors = netdev->stats.rx_length_errors;
8671 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8672 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008673}
8674
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008675#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008676/**
8677 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8678 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008679 * @tc: number of traffic classes currently enabled
8680 *
8681 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8682 * 802.1Q priority maps to a packet buffer that exists.
8683 */
8684static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8685{
8686 struct ixgbe_hw *hw = &adapter->hw;
8687 u32 reg, rsave;
8688 int i;
8689
8690 /* 82598 have a static priority to TC mapping that can not
8691 * be changed so no validation is needed.
8692 */
8693 if (hw->mac.type == ixgbe_mac_82598EB)
8694 return;
8695
8696 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8697 rsave = reg;
8698
8699 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8700 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8701
8702 /* If up2tc is out of bounds default to zero */
8703 if (up2tc > tc)
8704 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8705 }
8706
8707 if (reg != rsave)
8708 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8709
8710 return;
8711}
8712
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008713/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008714 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8715 * @adapter: Pointer to adapter struct
8716 *
8717 * Populate the netdev user priority to tc map
8718 */
8719static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8720{
8721 struct net_device *dev = adapter->netdev;
8722 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8723 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8724 u8 prio;
8725
8726 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8727 u8 tc = 0;
8728
8729 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8730 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8731 else if (ets)
8732 tc = ets->prio_tc[prio];
8733
8734 netdev_set_prio_tc_map(dev, prio, tc);
8735 }
8736}
8737
Alexander Duyckcca73c52013-01-12 06:33:44 +00008738#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck8315ef62018-04-03 17:16:45 -04008739static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data)
8740{
8741 struct ixgbe_adapter *adapter = data;
8742 struct ixgbe_fwd_adapter *accel;
8743 int pool;
8744
8745 /* we only care about macvlans... */
8746 if (!netif_is_macvlan(vdev))
8747 return 0;
8748
8749 /* that have hardware offload enabled... */
8750 accel = macvlan_accel_priv(vdev);
8751 if (!accel)
8752 return 0;
8753
8754 /* If we can relocate to a different bit do so */
8755 pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
8756 if (pool < adapter->num_rx_pools) {
8757 set_bit(pool, adapter->fwd_bitmask);
8758 accel->pool = pool;
8759 return 0;
8760 }
8761
8762 /* if we cannot find a free pool then disable the offload */
8763 netdev_err(vdev, "L2FW offload disabled due to lack of queue resources\n");
8764 macvlan_release_l2fw_offload(vdev);
8765 kfree(accel);
8766
8767 return 0;
8768}
8769
8770static void ixgbe_defrag_macvlan_pools(struct net_device *dev)
8771{
8772 struct ixgbe_adapter *adapter = netdev_priv(dev);
8773
8774 /* flush any stale bits out of the fwd bitmask */
8775 bitmap_clear(adapter->fwd_bitmask, 1, 63);
8776
8777 /* walk through upper devices reassigning pools */
8778 netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool,
8779 adapter);
8780}
8781
Alexander Duyck02debdc2012-05-18 06:33:31 +00008782/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008783 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008784 *
Tony Nguyen5ba643c2017-12-04 11:28:30 -08008785 * @dev: net device to configure
John Fastabend8b1c0b22011-05-03 02:26:48 +00008786 * @tc: number of traffic classes to enable
8787 */
8788int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8789{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008790 struct ixgbe_adapter *adapter = netdev_priv(dev);
8791 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008792
John Fastabend8b1c0b22011-05-03 02:26:48 +00008793 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008794 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8795 return -EINVAL;
8796
8797 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008798 return -EINVAL;
8799
8800 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008801 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008802 * hardware is not flexible enough to do this dynamically.
8803 */
8804 if (netif_running(dev))
8805 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008806 else
8807 ixgbe_reset(adapter);
8808
John Fastabend8b1c0b22011-05-03 02:26:48 +00008809 ixgbe_clear_interrupt_scheme(adapter);
8810
Alexander Duyckcca73c52013-01-12 06:33:44 +00008811#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008812 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008813 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008814 ixgbe_set_prio_tc_map(adapter);
8815
Alexander Duyck0efbf122017-11-22 10:57:11 -08008816 adapter->hw_tcs = tc;
John Fastabende7589ea2011-07-18 22:38:36 +00008817 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008818
Alexander Duyck943561d2012-05-09 22:14:44 -07008819 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8820 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008821 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008822 }
John Fastabende7589ea2011-07-18 22:38:36 +00008823 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008824 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008825
Alexander Duyck943561d2012-05-09 22:14:44 -07008826 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8827 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008828
8829 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Alexander Duyck0efbf122017-11-22 10:57:11 -08008830 adapter->hw_tcs = tc;
John Fastabende7589ea2011-07-18 22:38:36 +00008831
8832 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8833 adapter->dcb_cfg.pfc_mode_enable = false;
8834 }
8835
John Fastabend8b1c0b22011-05-03 02:26:48 +00008836 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008837
8838#endif /* CONFIG_IXGBE_DCB */
8839 ixgbe_init_interrupt_scheme(adapter);
8840
Alexander Duyck8315ef62018-04-03 17:16:45 -04008841 ixgbe_defrag_macvlan_pools(dev);
8842
John Fastabend8b1c0b22011-05-03 02:26:48 +00008843 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008844 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008845
8846 return 0;
8847}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008848
John Fastabendb82b17d2016-02-16 21:18:53 -08008849static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8850 struct tc_cls_u32_offload *cls)
8851{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008852 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008853 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008854 u32 loc = cls->knode.handle & 0xfffff;
8855 int err = 0, i, j;
8856 struct ixgbe_jump_table *jump = NULL;
8857
8858 if (loc > IXGBE_MAX_HW_ENTRIES)
8859 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008860
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008861 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8862 return -EINVAL;
8863
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008864 /* Clear this filter in the link data it is associated with */
8865 if (uhtid != 0x800) {
8866 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008867 if (!jump)
8868 return -EINVAL;
8869 if (!test_bit(loc - 1, jump->child_loc_map))
8870 return -EINVAL;
8871 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008872 }
8873
8874 /* Check if the filter being deleted is a link */
8875 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8876 jump = adapter->jump_tables[i];
8877 if (jump && jump->link_hdl == hdl) {
8878 /* Delete filters in the hardware in the child hash
8879 * table associated with this link
8880 */
8881 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8882 if (!test_bit(j, jump->child_loc_map))
8883 continue;
8884 spin_lock(&adapter->fdir_perfect_lock);
8885 err = ixgbe_update_ethtool_fdir_entry(adapter,
8886 NULL,
8887 j + 1);
8888 spin_unlock(&adapter->fdir_perfect_lock);
8889 clear_bit(j, jump->child_loc_map);
8890 }
8891 /* Remove resources for this link */
8892 kfree(jump->input);
8893 kfree(jump->mask);
8894 kfree(jump);
8895 adapter->jump_tables[i] = NULL;
8896 return err;
8897 }
8898 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008899
John Fastabendb82b17d2016-02-16 21:18:53 -08008900 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008901 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008902 spin_unlock(&adapter->fdir_perfect_lock);
8903 return err;
8904}
8905
John Fastabenddb956ae2016-02-16 21:19:19 -08008906static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
John Fastabenddb956ae2016-02-16 21:19:19 -08008907 struct tc_cls_u32_offload *cls)
8908{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008909 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8910
8911 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8912 return -EINVAL;
8913
John Fastabenddb956ae2016-02-16 21:19:19 -08008914 /* This ixgbe devices do not support hash tables at the moment
8915 * so abort when given hash tables.
8916 */
8917 if (cls->hnode.divisor > 0)
8918 return -EINVAL;
8919
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008920 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008921 return 0;
8922}
8923
8924static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8925 struct tc_cls_u32_offload *cls)
8926{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008927 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8928
8929 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8930 return -EINVAL;
8931
8932 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008933 return 0;
8934}
8935
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008936#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008937struct upper_walk_data {
8938 struct ixgbe_adapter *adapter;
8939 u64 action;
8940 int ifindex;
8941 u8 queue;
8942};
8943
8944static int get_macvlan_queue(struct net_device *upper, void *_data)
8945{
8946 if (netif_is_macvlan(upper)) {
Alexander Duyck7d775f62018-04-03 17:16:03 -04008947 struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper);
David Ahern1cd127f2016-10-17 19:15:48 -07008948 struct upper_walk_data *data = _data;
8949 struct ixgbe_adapter *adapter = data->adapter;
8950 int ifindex = data->ifindex;
8951
Alexander Duyck7d775f62018-04-03 17:16:03 -04008952 if (vadapter && upper->ifindex == ifindex) {
David Ahern1cd127f2016-10-17 19:15:48 -07008953 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
8954 data->action = data->queue;
8955 return 1;
8956 }
8957 }
8958
8959 return 0;
8960}
8961
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008962static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
8963 u8 *queue, u64 *action)
8964{
Alexander Duyck361b5342017-11-22 10:56:16 -08008965 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008966 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07008967 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008968 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008969
8970 /* redirect to a SRIOV VF */
8971 for (vf = 0; vf < num_vfs; ++vf) {
8972 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
8973 if (upper->ifindex == ifindex) {
Alexander Duyck361b5342017-11-22 10:56:16 -08008974 *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008975 *action = vf + 1;
8976 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
8977 return 0;
8978 }
8979 }
8980
8981 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07008982 data.adapter = adapter;
8983 data.ifindex = ifindex;
8984 data.action = 0;
8985 data.queue = 0;
8986 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
8987 get_macvlan_queue, &data)) {
8988 *action = data.action;
8989 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008990
David Ahern1cd127f2016-10-17 19:15:48 -07008991 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008992 }
8993
8994 return -EINVAL;
8995}
8996
8997static int parse_tc_actions(struct ixgbe_adapter *adapter,
8998 struct tcf_exts *exts, u64 *action, u8 *queue)
8999{
9000 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07009001 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009002
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +02009003 if (!tcf_exts_has_actions(exts))
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009004 return -EINVAL;
9005
WANG Cong22dc13c2016-08-13 22:35:00 -07009006 tcf_exts_to_list(exts, &actions);
9007 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009008
9009 /* Drop action */
9010 if (is_tcf_gact_shot(a)) {
9011 *action = IXGBE_FDIR_DROP_QUEUE;
9012 *queue = IXGBE_FDIR_DROP_QUEUE;
9013 return 0;
9014 }
9015
9016 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03009017 if (is_tcf_mirred_egress_redirect(a)) {
Cong Wang9f8a7392017-12-05 16:17:26 -08009018 struct net_device *dev = tcf_mirred_dev(a);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009019
Cong Wang9f8a7392017-12-05 16:17:26 -08009020 if (!dev)
9021 return -EINVAL;
Ondřej Hlavatý16e66532018-05-31 23:21:04 +02009022 return handle_redirect_action(adapter, dev->ifindex,
9023 queue, action);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009024 }
Ondřej Hlavatý16e66532018-05-31 23:21:04 +02009025
9026 return -EINVAL;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009027 }
9028
9029 return -EINVAL;
9030}
9031#else
9032static int parse_tc_actions(struct ixgbe_adapter *adapter,
9033 struct tcf_exts *exts, u64 *action, u8 *queue)
9034{
9035 return -EINVAL;
9036}
9037#endif /* CONFIG_NET_CLS_ACT */
9038
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009039static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
9040 union ixgbe_atr_input *mask,
9041 struct tc_cls_u32_offload *cls,
9042 struct ixgbe_mat_field *field_ptr,
9043 struct ixgbe_nexthdr *nexthdr)
9044{
9045 int i, j, off;
9046 __be32 val, m;
9047 bool found_entry = false, found_jump_field = false;
9048
9049 for (i = 0; i < cls->knode.sel->nkeys; i++) {
9050 off = cls->knode.sel->keys[i].off;
9051 val = cls->knode.sel->keys[i].val;
9052 m = cls->knode.sel->keys[i].mask;
9053
9054 for (j = 0; field_ptr[j].val; j++) {
9055 if (field_ptr[j].off == off) {
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009056 field_ptr[j].val(input, mask, (__force u32)val,
9057 (__force u32)m);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009058 input->filter.formatted.flow_type |=
9059 field_ptr[j].type;
9060 found_entry = true;
9061 break;
9062 }
9063 }
9064 if (nexthdr) {
9065 if (nexthdr->off == cls->knode.sel->keys[i].off &&
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009066 nexthdr->val ==
9067 (__force u32)cls->knode.sel->keys[i].val &&
9068 nexthdr->mask ==
9069 (__force u32)cls->knode.sel->keys[i].mask)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009070 found_jump_field = true;
9071 else
9072 continue;
9073 }
9074 }
9075
9076 if (nexthdr && !found_jump_field)
9077 return -EINVAL;
9078
9079 if (!found_entry)
9080 return 0;
9081
9082 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
9083 IXGBE_ATR_L4TYPE_MASK;
9084
9085 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
9086 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
9087
9088 return 0;
9089}
9090
John Fastabendb82b17d2016-02-16 21:18:53 -08009091static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
John Fastabendb82b17d2016-02-16 21:18:53 -08009092 struct tc_cls_u32_offload *cls)
9093{
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009094 __be16 protocol = cls->common.protocol;
John Fastabendb82b17d2016-02-16 21:18:53 -08009095 u32 loc = cls->knode.handle & 0xfffff;
9096 struct ixgbe_hw *hw = &adapter->hw;
9097 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009098 struct ixgbe_fdir_filter *input = NULL;
9099 union ixgbe_atr_input *mask = NULL;
9100 struct ixgbe_jump_table *jump = NULL;
9101 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08009102 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009103 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08009104
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009105 uhtid = TC_U32_USERHTID(cls->knode.handle);
9106 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08009107
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009108 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08009109 * L2 headers. The canonical method to match L2 frames is to use
9110 * negative values. However this is error prone at best but really
9111 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009112 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08009113 * headers when needed.
9114 */
9115 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009116 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009117
9118 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
9119 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009120 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009121 }
9122
9123 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9124 * links and also the fields used to advance the parser across each
9125 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9126 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9127 * To add support for new nodes update ixgbe_model.h parse structures
9128 * this function _should_ be generic try not to hardcode values here.
9129 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009130 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009131 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009132 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009133 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009134 return err;
9135 if (!adapter->jump_tables[uhtid])
9136 return err;
9137 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009138 }
9139
9140 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009141 return err;
9142
9143 /* At this point we know the field_ptr is valid and need to either
9144 * build cls_u32 link or attach filter. Because adding a link to
9145 * a handle that does not exist is invalid and the same for adding
9146 * rules to handles that don't exist.
9147 */
9148
9149 if (link_uhtid) {
9150 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
9151
9152 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
9153 return err;
9154
9155 if (!test_bit(link_uhtid - 1, &adapter->tables))
9156 return err;
9157
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009158 /* Multiple filters as links to the same hash table are not
9159 * supported. To add a new filter with the same next header
9160 * but different match/jump conditions, create a new hash table
9161 * and link to it.
9162 */
9163 if (adapter->jump_tables[link_uhtid] &&
9164 (adapter->jump_tables[link_uhtid])->link_hdl) {
9165 e_err(drv, "Link filter exists for link: %x\n",
9166 link_uhtid);
9167 return err;
9168 }
9169
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009170 for (i = 0; nexthdr[i].jump; i++) {
9171 if (nexthdr[i].o != cls->knode.sel->offoff ||
9172 nexthdr[i].s != cls->knode.sel->offshift ||
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009173 nexthdr[i].m !=
9174 (__force u32)cls->knode.sel->offmask)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009175 return err;
9176
9177 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
9178 if (!jump)
9179 return -ENOMEM;
9180 input = kzalloc(sizeof(*input), GFP_KERNEL);
9181 if (!input) {
9182 err = -ENOMEM;
9183 goto free_jump;
9184 }
9185 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9186 if (!mask) {
9187 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009188 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009189 }
9190 jump->input = input;
9191 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009192 jump->link_hdl = cls->knode.handle;
9193
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009194 err = ixgbe_clsu32_build_input(input, mask, cls,
9195 field_ptr, &nexthdr[i]);
9196 if (!err) {
9197 jump->mat = nexthdr[i].jump;
9198 adapter->jump_tables[link_uhtid] = jump;
9199 break;
9200 }
9201 }
9202 return 0;
9203 }
John Fastabendb82b17d2016-02-16 21:18:53 -08009204
9205 input = kzalloc(sizeof(*input), GFP_KERNEL);
9206 if (!input)
9207 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009208 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9209 if (!mask) {
9210 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009211 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08009212 }
9213
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009214 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
9215 if ((adapter->jump_tables[uhtid])->input)
9216 memcpy(input, (adapter->jump_tables[uhtid])->input,
9217 sizeof(*input));
9218 if ((adapter->jump_tables[uhtid])->mask)
9219 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
9220 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009221
9222 /* Lookup in all child hash tables if this location is already
9223 * filled with a filter
9224 */
9225 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9226 struct ixgbe_jump_table *link = adapter->jump_tables[i];
9227
9228 if (link && (test_bit(loc - 1, link->child_loc_map))) {
9229 e_err(drv, "Filter exists in location: %x\n",
9230 loc);
9231 err = -EINVAL;
9232 goto err_out;
9233 }
9234 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009235 }
9236 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
9237 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08009238 goto err_out;
9239
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009240 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
9241 &queue);
9242 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08009243 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08009244
John Fastabendb82b17d2016-02-16 21:18:53 -08009245 input->sw_idx = loc;
9246
9247 spin_lock(&adapter->fdir_perfect_lock);
9248
9249 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009250 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
9251 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009252 if (err)
9253 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009254 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08009255 err = -EINVAL;
9256 goto err_out_w_lock;
9257 }
9258
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009259 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009260 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
9261 input->sw_idx, queue);
9262 if (!err)
9263 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
9264 spin_unlock(&adapter->fdir_perfect_lock);
9265
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009266 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
9267 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009268
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009269 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009270 return err;
9271err_out_w_lock:
9272 spin_unlock(&adapter->fdir_perfect_lock);
9273err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009274 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009275free_input:
9276 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009277free_jump:
9278 kfree(jump);
9279 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009280}
9281
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009282static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009283 struct tc_cls_u32_offload *cls_u32)
9284{
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009285 switch (cls_u32->command) {
9286 case TC_CLSU32_NEW_KNODE:
9287 case TC_CLSU32_REPLACE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009288 return ixgbe_configure_clsu32(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009289 case TC_CLSU32_DELETE_KNODE:
9290 return ixgbe_delete_clsu32(adapter, cls_u32);
9291 case TC_CLSU32_NEW_HNODE:
9292 case TC_CLSU32_REPLACE_HNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009293 return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009294 case TC_CLSU32_DELETE_HNODE:
9295 return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
9296 default:
9297 return -EOPNOTSUPP;
9298 }
9299}
9300
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009301static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
9302 void *cb_priv)
9303{
9304 struct ixgbe_adapter *adapter = cb_priv;
9305
Jakub Kicinskia60c3fd2018-01-25 14:00:49 -08009306 if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
Jiri Pirko44ae12a2017-11-01 11:47:39 +01009307 return -EOPNOTSUPP;
9308
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009309 switch (type) {
9310 case TC_SETUP_CLSU32:
9311 return ixgbe_setup_tc_cls_u32(adapter, type_data);
9312 default:
9313 return -EOPNOTSUPP;
9314 }
9315}
9316
9317static int ixgbe_setup_tc_block(struct net_device *dev,
9318 struct tc_block_offload *f)
9319{
9320 struct ixgbe_adapter *adapter = netdev_priv(dev);
9321
9322 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9323 return -EOPNOTSUPP;
9324
9325 switch (f->command) {
9326 case TC_BLOCK_BIND:
9327 return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
9328 adapter, adapter);
9329 case TC_BLOCK_UNBIND:
9330 tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
9331 adapter);
9332 return 0;
9333 default:
9334 return -EOPNOTSUPP;
9335 }
9336}
9337
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009338static int ixgbe_setup_tc_mqprio(struct net_device *dev,
9339 struct tc_mqprio_qopt *mqprio)
9340{
9341 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
9342 return ixgbe_setup_tc(dev, mqprio->num_tc);
9343}
9344
Jiri Pirko2572ac52017-08-07 10:15:17 +02009345static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02009346 void *type_data)
John Fastabende4c67342016-02-16 21:16:15 -08009347{
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009348 switch (type) {
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009349 case TC_SETUP_BLOCK:
9350 return ixgbe_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01009351 case TC_SETUP_QDISC_MQPRIO:
Jiri Pirkode4784c2017-08-07 10:15:32 +02009352 return ixgbe_setup_tc_mqprio(dev, type_data);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009353 default:
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +02009354 return -EOPNOTSUPP;
John Fastabendb82b17d2016-02-16 21:18:53 -08009355 }
John Fastabende4c67342016-02-16 21:16:15 -08009356}
9357
Greg Roseda36b642012-12-11 08:26:43 +00009358#ifdef CONFIG_PCI_IOV
9359void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
9360{
9361 struct net_device *netdev = adapter->netdev;
9362
9363 rtnl_lock();
Alexander Duyck0efbf122017-11-22 10:57:11 -08009364 ixgbe_setup_tc(netdev, adapter->hw_tcs);
Greg Roseda36b642012-12-11 08:26:43 +00009365 rtnl_unlock();
9366}
9367
9368#endif
Don Skidmore082757a2011-07-21 05:55:00 +00009369void ixgbe_do_reset(struct net_device *netdev)
9370{
9371 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9372
9373 if (netif_running(netdev))
9374 ixgbe_reinit_locked(adapter);
9375 else
9376 ixgbe_reset(adapter);
9377}
9378
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009379static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009380 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009381{
9382 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9383
Don Skidmore082757a2011-07-21 05:55:00 +00009384 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009385 if (!(features & NETIF_F_RXCSUM))
9386 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00009387
Alexander Duyck567d2de2012-02-11 07:18:57 +00009388 /* Turn off LRO if not RSC capable */
9389 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
9390 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009391
Alexander Duyck567d2de2012-02-11 07:18:57 +00009392 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009393}
9394
Alexander Duyck8315ef62018-04-03 17:16:45 -04009395static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter *adapter)
9396{
9397 int rss = min_t(int, ixgbe_max_rss_indices(adapter),
9398 num_online_cpus());
9399
9400 /* go back to full RSS if we're not running SR-IOV */
9401 if (!adapter->ring_feature[RING_F_VMDQ].offset)
9402 adapter->flags &= ~(IXGBE_FLAG_VMDQ_ENABLED |
9403 IXGBE_FLAG_SRIOV_ENABLED);
9404
9405 adapter->ring_feature[RING_F_RSS].limit = rss;
9406 adapter->ring_feature[RING_F_VMDQ].limit = 1;
9407
9408 ixgbe_setup_tc(adapter->netdev, adapter->hw_tcs);
9409}
9410
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009411static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009412 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009413{
9414 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009415 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009416 bool need_reset = false;
9417
Don Skidmore082757a2011-07-21 05:55:00 +00009418 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009419 if (!(features & NETIF_F_LRO)) {
9420 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009421 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009422 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9423 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9424 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9425 if (adapter->rx_itr_setting == 1 ||
9426 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9427 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9428 need_reset = true;
9429 } else if ((changed ^ features) & NETIF_F_LRO) {
9430 e_info(probe, "rx-usecs set too low, "
9431 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009432 }
9433 }
9434
9435 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009436 * Check if Flow Director n-tuple support or hw_tc support was
9437 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009438 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009439 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009440 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009441 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9442 need_reset = true;
9443
Alexander Duyck567d2de2012-02-11 07:18:57 +00009444 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9445 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009446 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009447 /* turn off perfect filters, enable ATR and reset */
9448 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9449 need_reset = true;
9450
9451 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9452
9453 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009454 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9455 /* We cannot enable ATR if we have 2 or more tcs */
Alexander Duyck0efbf122017-11-22 10:57:11 -08009456 (adapter->hw_tcs > 1) ||
John Fastabendb82b17d2016-02-16 21:18:53 -08009457 /* We cannot enable ATR if RSS is disabled */
9458 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9459 /* A sample rate of 0 indicates ATR disabled */
9460 (!adapter->atr_sample_rate))
9461 ; /* do nothing not supported */
9462 else /* otherwise supported and set the flag */
9463 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009464 }
9465
Ben Greear3f2d1c02012-03-08 08:28:41 +00009466 if (changed & NETIF_F_RXALL)
9467 need_reset = true;
9468
Alexander Duyck567d2de2012-02-11 07:18:57 +00009469 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009470
Mark Rustad67359c32015-06-15 11:33:25 -07009471 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009472 if (features & NETIF_F_RXCSUM) {
9473 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9474 } else {
9475 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9476
9477 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9478 }
9479 }
9480
9481 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9482 if (features & NETIF_F_RXCSUM) {
9483 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9484 } else {
9485 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9486
9487 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9488 }
Mark Rustad67359c32015-06-15 11:33:25 -07009489 }
Mark Rustad67359c32015-06-15 11:33:25 -07009490
Alexander Duyck8315ef62018-04-03 17:16:45 -04009491 if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
9492 ixgbe_reset_l2fw_offload(adapter);
9493 else if (need_reset)
Don Skidmore082757a2011-07-21 05:55:00 +00009494 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009495 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9496 NETIF_F_HW_VLAN_CTAG_FILTER))
9497 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009498
9499 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009500}
9501
Don Skidmore3f207802014-12-23 07:40:34 +00009502/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009503 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009504 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009505 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009506 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009507static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9508 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009509{
9510 struct ixgbe_adapter *adapter = netdev_priv(dev);
9511 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009512 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009513 u32 port_shift = 0;
9514 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009515
Alexander Duyckb3a49552016-06-16 12:22:19 -07009516 if (ti->sa_family != AF_INET)
9517 return;
9518
Emil Tantilova21d0822016-08-10 11:19:23 -07009519 switch (ti->type) {
9520 case UDP_TUNNEL_TYPE_VXLAN:
9521 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9522 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009523
Emil Tantilova21d0822016-08-10 11:19:23 -07009524 if (adapter->vxlan_port == port)
9525 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009526
Emil Tantilova21d0822016-08-10 11:19:23 -07009527 if (adapter->vxlan_port) {
9528 netdev_info(dev,
9529 "VXLAN port %d set, not adding port %d\n",
9530 ntohs(adapter->vxlan_port),
9531 ntohs(port));
9532 return;
9533 }
9534
9535 adapter->vxlan_port = port;
9536 break;
9537 case UDP_TUNNEL_TYPE_GENEVE:
9538 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9539 return;
9540
9541 if (adapter->geneve_port == port)
9542 return;
9543
9544 if (adapter->geneve_port) {
9545 netdev_info(dev,
9546 "GENEVE port %d set, not adding port %d\n",
9547 ntohs(adapter->geneve_port),
9548 ntohs(port));
9549 return;
9550 }
9551
9552 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9553 adapter->geneve_port = port;
9554 break;
9555 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009556 return;
9557 }
9558
Emil Tantilova21d0822016-08-10 11:19:23 -07009559 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9560 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009561}
9562
9563/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009564 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009565 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009566 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009567 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009568static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9569 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009570{
9571 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009572 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009573
Emil Tantilova21d0822016-08-10 11:19:23 -07009574 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9575 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009576 return;
9577
9578 if (ti->sa_family != AF_INET)
9579 return;
9580
Emil Tantilova21d0822016-08-10 11:19:23 -07009581 switch (ti->type) {
9582 case UDP_TUNNEL_TYPE_VXLAN:
9583 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9584 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009585
Emil Tantilova21d0822016-08-10 11:19:23 -07009586 if (adapter->vxlan_port != ti->port) {
9587 netdev_info(dev, "VXLAN port %d not found\n",
9588 ntohs(ti->port));
9589 return;
9590 }
9591
9592 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9593 break;
9594 case UDP_TUNNEL_TYPE_GENEVE:
9595 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9596 return;
9597
9598 if (adapter->geneve_port != ti->port) {
9599 netdev_info(dev, "GENEVE port %d not found\n",
9600 ntohs(ti->port));
9601 return;
9602 }
9603
9604 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9605 break;
9606 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009607 return;
9608 }
9609
Emil Tantilova21d0822016-08-10 11:19:23 -07009610 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9611 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009612}
9613
stephen hemmingeredc7d572012-10-01 12:32:33 +00009614static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009615 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009616 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009617 u16 flags)
9618{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009619 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009620 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009621 struct ixgbe_adapter *adapter = netdev_priv(dev);
9622 u16 pool = VMDQ_P(0);
9623
9624 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009625 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009626 }
9627
Jiri Pirkof6f64242014-11-28 14:34:15 +01009628 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009629}
9630
Don Skidmore219efe92015-04-09 22:03:22 -07009631/**
9632 * ixgbe_configure_bridge_mode - set various bridge modes
Tony Nguyen5ba643c2017-12-04 11:28:30 -08009633 * @adapter: the private structure
9634 * @mode: requested bridge mode
Don Skidmore219efe92015-04-09 22:03:22 -07009635 *
9636 * Configure some settings require for various bridge modes.
9637 **/
9638static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9639 __u16 mode)
9640{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009641 struct ixgbe_hw *hw = &adapter->hw;
9642 unsigned int p, num_pools;
9643 u32 vmdctl;
9644
Don Skidmore219efe92015-04-09 22:03:22 -07009645 switch (mode) {
9646 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009647 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009648 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009649
9650 /* must enable Rx switching replication to allow multicast
9651 * packet reception on all VFs, and to enable source address
9652 * pruning.
9653 */
9654 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9655 vmdctl |= IXGBE_VT_CTL_REPLEN;
9656 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9657
9658 /* enable Rx source address pruning. Note, this requires
9659 * replication to be enabled or else it does nothing.
9660 */
9661 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9662 for (p = 0; p < num_pools; p++) {
9663 if (hw->mac.ops.set_source_address_pruning)
9664 hw->mac.ops.set_source_address_pruning(hw,
9665 true,
9666 p);
9667 }
Don Skidmore219efe92015-04-09 22:03:22 -07009668 break;
9669 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009670 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009671 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9672 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009673
9674 /* disable Rx switching replication unless we have SR-IOV
9675 * virtual functions
9676 */
9677 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9678 if (!adapter->num_vfs)
9679 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9680 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9681
9682 /* disable Rx source address pruning, since we don't expect to
9683 * be receiving external loopback of our transmitted frames.
9684 */
9685 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9686 for (p = 0; p < num_pools; p++) {
9687 if (hw->mac.ops.set_source_address_pruning)
9688 hw->mac.ops.set_source_address_pruning(hw,
9689 false,
9690 p);
9691 }
Don Skidmore219efe92015-04-09 22:03:22 -07009692 break;
9693 default:
9694 return -EINVAL;
9695 }
9696
9697 adapter->bridge_mode = mode;
9698
9699 e_info(drv, "enabling bridge mode: %s\n",
9700 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9701
9702 return 0;
9703}
9704
John Fastabend815cccb2012-10-24 08:13:09 +00009705static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009706 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009707{
9708 struct ixgbe_adapter *adapter = netdev_priv(dev);
9709 struct nlattr *attr, *br_spec;
9710 int rem;
9711
9712 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9713 return -EOPNOTSUPP;
9714
9715 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009716 if (!br_spec)
9717 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009718
9719 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009720 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009721 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009722
9723 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9724 continue;
9725
Thomas Grafb7c1a312014-11-26 13:42:17 +01009726 if (nla_len(attr) < sizeof(mode))
9727 return -EINVAL;
9728
John Fastabend815cccb2012-10-24 08:13:09 +00009729 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009730 status = ixgbe_configure_bridge_mode(adapter, mode);
9731 if (status)
9732 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009733
9734 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009735 }
9736
9737 return 0;
9738}
9739
9740static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009741 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009742 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009743{
9744 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009745
9746 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9747 return 0;
9748
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009749 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009750 adapter->bridge_mode, 0, 0, nlflags,
9751 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009752}
9753
John Fastabend2a47fa42013-11-06 09:54:52 -08009754static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9755{
John Fastabend2a47fa42013-11-06 09:54:52 -08009756 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Alexander Duyck8315ef62018-04-03 17:16:45 -04009757 struct ixgbe_fwd_adapter *accel;
Alexander Duyck0efbf122017-11-22 10:57:11 -08009758 int tcs = adapter->hw_tcs ? : 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009759 int pool, err;
9760
Alexander Duyck33359152018-04-03 17:16:35 -04009761 /* The hardware supported by ixgbe only filters on the destination MAC
9762 * address. In order to avoid issues we only support offloading modes
9763 * where the hardware can actually provide the functionality.
9764 */
9765 if (!macvlan_supports_dest_filter(vdev))
9766 return ERR_PTR(-EMEDIUMTYPE);
9767
Alexander Duyck8315ef62018-04-03 17:16:45 -04009768 pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
9769 if (pool == adapter->num_rx_pools) {
9770 u16 used_pools = adapter->num_vfs + adapter->num_rx_pools;
9771 u16 reserved_pools;
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009772
Alexander Duyck8315ef62018-04-03 17:16:45 -04009773 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9774 adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) ||
9775 adapter->num_rx_pools > IXGBE_MAX_MACVLANS)
9776 return ERR_PTR(-EBUSY);
John Fastabend2a47fa42013-11-06 09:54:52 -08009777
Alexander Duyck8315ef62018-04-03 17:16:45 -04009778 /* Hardware has a limited number of available pools. Each VF,
9779 * and the PF require a pool. Check to ensure we don't
9780 * attempt to use more then the available number of pools.
9781 */
9782 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9783 return ERR_PTR(-EBUSY);
9784
9785 /* Enable VMDq flag so device will be set in VM mode */
9786 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED |
9787 IXGBE_FLAG_SRIOV_ENABLED;
9788
9789 /* Try to reserve as many queues per pool as possible,
9790 * we start with the configurations that support 4 queues
9791 * per pools, followed by 2, and then by just 1 per pool.
9792 */
9793 if (used_pools < 32 && adapter->num_rx_pools < 16)
9794 reserved_pools = min_t(u16,
9795 32 - used_pools,
9796 16 - adapter->num_rx_pools);
9797 else if (adapter->num_rx_pools < 32)
9798 reserved_pools = min_t(u16,
9799 64 - used_pools,
9800 32 - adapter->num_rx_pools);
9801 else
9802 reserved_pools = 64 - used_pools;
9803
9804
9805 if (!reserved_pools)
9806 return ERR_PTR(-EBUSY);
9807
9808 adapter->ring_feature[RING_F_VMDQ].limit += reserved_pools;
9809
9810 /* Force reinit of ring allocation with VMDQ enabled */
9811 err = ixgbe_setup_tc(pdev, adapter->hw_tcs);
9812 if (err)
9813 return ERR_PTR(err);
9814
9815 if (pool >= adapter->num_rx_pools)
9816 return ERR_PTR(-ENOMEM);
9817 }
9818
9819 accel = kzalloc(sizeof(*accel), GFP_KERNEL);
9820 if (!accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08009821 return ERR_PTR(-ENOMEM);
9822
Alexander Duyck4e039c12017-11-22 10:56:40 -08009823 set_bit(pool, adapter->fwd_bitmask);
Alexander Duyck8315ef62018-04-03 17:16:45 -04009824 accel->pool = pool;
9825 accel->netdev = vdev;
John Fastabend2a47fa42013-11-06 09:54:52 -08009826
Alexander Duyck8315ef62018-04-03 17:16:45 -04009827 if (!netif_running(pdev))
9828 return accel;
John Fastabend2a47fa42013-11-06 09:54:52 -08009829
Alexander Duyck8315ef62018-04-03 17:16:45 -04009830 err = ixgbe_fwd_ring_up(adapter, accel);
9831 if (err)
9832 return ERR_PTR(err);
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009833
Alexander Duyck8315ef62018-04-03 17:16:45 -04009834 return accel;
John Fastabend2a47fa42013-11-06 09:54:52 -08009835}
9836
9837static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9838{
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009839 struct ixgbe_fwd_adapter *accel = priv;
Alexander Duyck865255b2018-04-03 17:16:40 -04009840 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009841 unsigned int rxbase = accel->rx_base_queue;
Alexander Duyck8315ef62018-04-03 17:16:45 -04009842 unsigned int i;
John Fastabend2a47fa42013-11-06 09:54:52 -08009843
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009844 /* delete unicast filter associated with offloaded interface */
9845 ixgbe_del_mac_filter(adapter, accel->netdev->dev_addr,
9846 VMDQ_P(accel->pool));
John Fastabend2a47fa42013-11-06 09:54:52 -08009847
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009848 /* Allow remaining Rx packets to get flushed out of the
9849 * Rx FIFO before we drop the netdev for the ring.
9850 */
9851 usleep_range(10000, 20000);
9852
9853 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
9854 struct ixgbe_ring *ring = adapter->rx_ring[rxbase + i];
9855 struct ixgbe_q_vector *qv = ring->q_vector;
9856
9857 /* Make sure we aren't processing any packets and clear
9858 * netdev to shut down the ring.
9859 */
9860 if (netif_running(adapter->netdev))
9861 napi_synchronize(&qv->napi);
9862 ring->netdev = NULL;
9863 }
9864
9865 clear_bit(accel->pool, adapter->fwd_bitmask);
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009866 kfree(accel);
John Fastabend2a47fa42013-11-06 09:54:52 -08009867}
9868
Alexander Duyckb83e3012016-04-14 17:19:31 -04009869#define IXGBE_MAX_MAC_HDR_LEN 127
9870#define IXGBE_MAX_NETWORK_HDR_LEN 511
9871
Mark Rustadf467bc02015-06-15 11:33:20 -07009872static netdev_features_t
9873ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9874 netdev_features_t features)
9875{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009876 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009877
Alexander Duyckb83e3012016-04-14 17:19:31 -04009878 /* Make certain the headers can be described by a context descriptor */
9879 mac_hdr_len = skb_network_header(skb) - skb->data;
9880 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9881 return features & ~(NETIF_F_HW_CSUM |
9882 NETIF_F_SCTP_CRC |
9883 NETIF_F_HW_VLAN_CTAG_TX |
9884 NETIF_F_TSO |
9885 NETIF_F_TSO6);
9886
9887 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9888 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9889 return features & ~(NETIF_F_HW_CSUM |
9890 NETIF_F_SCTP_CRC |
9891 NETIF_F_TSO |
9892 NETIF_F_TSO6);
9893
9894 /* We can only support IPV4 TSO in tunnels if we can mangle the
9895 * inner IP ID field, so strip TSO if MANGLEID is not supported.
Shannon Nelson70da6822018-03-16 11:09:07 -07009896 * IPsec offoad sets skb->encapsulation but still can handle
9897 * the TSO, so it's the exception.
Alexander Duyckb83e3012016-04-14 17:19:31 -04009898 */
Shannon Nelson70da6822018-03-16 11:09:07 -07009899 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) {
Alexander Duycke433f3a2018-06-04 16:51:20 -04009900#ifdef CONFIG_XFRM_OFFLOAD
Shannon Nelson70da6822018-03-16 11:09:07 -07009901 if (!skb->sp)
9902#endif
9903 features &= ~NETIF_F_TSO;
9904 }
Mark Rustadf467bc02015-06-15 11:33:20 -07009905
9906 return features;
9907}
9908
John Fastabend92470802017-04-24 03:30:17 -07009909static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
9910{
9911 int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9912 struct ixgbe_adapter *adapter = netdev_priv(dev);
9913 struct bpf_prog *old_prog;
9914
9915 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
9916 return -EINVAL;
9917
9918 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
9919 return -EINVAL;
9920
9921 /* verify ixgbe ring attributes are sufficient for XDP */
9922 for (i = 0; i < adapter->num_rx_queues; i++) {
9923 struct ixgbe_ring *ring = adapter->rx_ring[i];
9924
9925 if (ring_is_rsc_enabled(ring))
9926 return -EINVAL;
9927
9928 if (frame_size > ixgbe_rx_bufsz(ring))
9929 return -EINVAL;
9930 }
9931
John Fastabend33fdc822017-04-24 03:30:18 -07009932 if (nr_cpu_ids > MAX_XDP_QUEUES)
9933 return -ENOMEM;
9934
John Fastabend92470802017-04-24 03:30:17 -07009935 old_prog = xchg(&adapter->xdp_prog, prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009936
9937 /* If transitioning XDP modes reconfigure rings */
9938 if (!!prog != !!old_prog) {
Alexander Duyck0efbf122017-11-22 10:57:11 -08009939 int err = ixgbe_setup_tc(dev, adapter->hw_tcs);
John Fastabend33fdc822017-04-24 03:30:18 -07009940
9941 if (err) {
9942 rcu_assign_pointer(adapter->xdp_prog, old_prog);
9943 return -EINVAL;
9944 }
9945 } else {
9946 for (i = 0; i < adapter->num_rx_queues; i++)
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009947 (void)xchg(&adapter->rx_ring[i]->xdp_prog,
9948 adapter->xdp_prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009949 }
John Fastabend92470802017-04-24 03:30:17 -07009950
9951 if (old_prog)
9952 bpf_prog_put(old_prog);
9953
9954 return 0;
9955}
9956
Jakub Kicinskif4e63522017-11-03 13:56:16 -07009957static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
John Fastabend92470802017-04-24 03:30:17 -07009958{
9959 struct ixgbe_adapter *adapter = netdev_priv(dev);
9960
9961 switch (xdp->command) {
9962 case XDP_SETUP_PROG:
9963 return ixgbe_xdp_setup(dev, xdp->prog);
9964 case XDP_QUERY_PROG:
9965 xdp->prog_attached = !!(adapter->xdp_prog);
Martin KaFai Lau47920932017-06-15 17:29:15 -07009966 xdp->prog_id = adapter->xdp_prog ?
9967 adapter->xdp_prog->aux->id : 0;
John Fastabend92470802017-04-24 03:30:17 -07009968 return 0;
9969 default:
9970 return -EINVAL;
9971 }
9972}
9973
Jesper Dangaard Brouer5e2e6092018-05-31 10:59:57 +02009974static void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring)
9975{
9976 /* Force memory writes to complete before letting h/w know there
9977 * are new descriptors to fetch.
9978 */
9979 wmb();
9980 writel(ring->next_to_use, ring->tail);
9981}
9982
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +02009983static int ixgbe_xdp_xmit(struct net_device *dev, int n,
Jesper Dangaard Brouer42b33462018-05-31 10:59:47 +02009984 struct xdp_frame **frames, u32 flags)
John Fastabend64530732017-07-17 09:28:12 -07009985{
9986 struct ixgbe_adapter *adapter = netdev_priv(dev);
9987 struct ixgbe_ring *ring;
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +02009988 int drops = 0;
9989 int i;
John Fastabend64530732017-07-17 09:28:12 -07009990
9991 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +02009992 return -ENETDOWN;
John Fastabend64530732017-07-17 09:28:12 -07009993
Jesper Dangaard Brouer5e2e6092018-05-31 10:59:57 +02009994 if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
Jesper Dangaard Brouer42b33462018-05-31 10:59:47 +02009995 return -EINVAL;
9996
John Fastabend64530732017-07-17 09:28:12 -07009997 /* During program transitions its possible adapter->xdp_prog is assigned
9998 * but ring has not been configured yet. In this case simply abort xmit.
9999 */
10000 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10001 if (unlikely(!ring))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010002 return -ENXIO;
John Fastabend64530732017-07-17 09:28:12 -070010003
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +020010004 for (i = 0; i < n; i++) {
10005 struct xdp_frame *xdpf = frames[i];
10006 int err;
John Fastabend64530732017-07-17 09:28:12 -070010007
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +020010008 err = ixgbe_xmit_xdp_ring(adapter, xdpf);
10009 if (err != IXGBE_XDP_TX) {
10010 xdp_return_frame_rx_napi(xdpf);
10011 drops++;
10012 }
10013 }
10014
Jesper Dangaard Brouer5e2e6092018-05-31 10:59:57 +020010015 if (unlikely(flags & XDP_XMIT_FLUSH))
10016 ixgbe_xdp_ring_update_tail(ring);
10017
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +020010018 return n - drops;
John Fastabend11393cc2017-07-17 09:29:40 -070010019}
10020
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010021static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +000010022 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010023 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -080010024 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -070010025 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +000010026 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010027 .ndo_validate_addr = eth_validate_addr,
10028 .ndo_set_mac_address = ixgbe_set_mac,
10029 .ndo_change_mtu = ixgbe_change_mtu,
10030 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +000010031 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010032 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
10033 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +000010034 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +000010035 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
10036 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -040010037 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +000010038 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +030010039 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +000010040 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +000010041 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +000010042 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -080010043 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010044#ifdef CONFIG_NET_POLL_CONTROLLER
10045 .ndo_poll_controller = ixgbe_netpoll,
10046#endif
Yi Zou332d4a72009-05-13 13:11:53 +000010047#ifdef IXGBE_FCOE
10048 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +000010049 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +000010050 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +000010051 .ndo_fcoe_enable = ixgbe_fcoe_enable,
10052 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +000010053 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +000010054 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +000010055#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +000010056 .ndo_set_features = ixgbe_set_features,
10057 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +000010058 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +000010059 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
10060 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -080010061 .ndo_dfwd_add_station = ixgbe_fwd_add,
10062 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -070010063 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
10064 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -070010065 .ndo_features_check = ixgbe_features_check,
Jakub Kicinskif4e63522017-11-03 13:56:16 -070010066 .ndo_bpf = ixgbe_xdp,
John Fastabend64530732017-07-17 09:28:12 -070010067 .ndo_xdp_xmit = ixgbe_xdp_xmit,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010068};
10069
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010070/**
Jacob Kellere027d1a2013-07-31 06:53:31 +000010071 * ixgbe_enumerate_functions - Get the number of ports this device has
10072 * @adapter: adapter structure
10073 *
10074 * This function enumerates the phsyical functions co-located on a single slot,
10075 * in order to determine how many ports a device has. This is most useful in
10076 * determining the required GT/s of PCIe bandwidth necessary for optimal
10077 * performance.
10078 **/
10079static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
10080{
Jacob Kellercaafb952014-07-19 07:17:17 +000010081 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010082 int physfns = 0;
10083
Jacob Kellerf1f96572013-08-31 02:45:38 +000010084 /* Some cards can not use the generic count PCIe functions method,
10085 * because they are behind a parent switch, so we hardcode these with
10086 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +000010087 */
Jacob Keller88189702014-07-19 07:17:16 +000010088 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +000010089 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +000010090
10091 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
10092 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +000010093 if (entry->is_virtfn)
10094 continue;
10095
10096 /* When the devices on the bus don't all match our device ID,
10097 * we can't reliably determine the correct number of
10098 * functions. This can occur if a function has been direct
10099 * attached to a virtual machine using VT-d, for example. In
10100 * this case, simply return -1 to indicate this.
10101 */
10102 if ((entry->vendor != pdev->vendor) ||
10103 (entry->device != pdev->device))
10104 return -1;
10105
10106 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010107 }
10108
10109 return physfns;
10110}
10111
10112/**
Jacob Keller8e2813f2012-04-21 06:05:40 +000010113 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -070010114 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +000010115 * @device_id: the device ID
Tony Nguyen5ba643c2017-12-04 11:28:30 -080010116 * @subdevice_id: the subsystem device ID
Jacob Keller8e2813f2012-04-21 06:05:40 +000010117 *
10118 * This function is used by probe and ethtool to determine
10119 * which devices have WoL support
10120 *
10121 **/
Emil Tantilov740234f2016-04-21 11:37:12 -070010122bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
10123 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +000010124{
10125 struct ixgbe_hw *hw = &adapter->hw;
10126 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010127
Emil Tantilov740234f2016-04-21 11:37:12 -070010128 /* WOL not supported on 82598 */
10129 if (hw->mac.type == ixgbe_mac_82598EB)
10130 return false;
10131
10132 /* check eeprom to see if WOL is enabled for X540 and newer */
10133 if (hw->mac.type >= ixgbe_mac_X540) {
10134 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
10135 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
10136 (hw->bus.func == 0)))
10137 return true;
10138 }
10139
10140 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +000010141 switch (device_id) {
10142 case IXGBE_DEV_ID_82599_SFP:
10143 /* Only these subdevices could supports WOL */
10144 switch (subdevice_id) {
10145 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010146 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
10147 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
10148 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010149 /* only support first port */
10150 if (hw->bus.func != 0)
10151 break;
Tony Nguyen93df9462017-05-31 04:43:47 -070010152 /* fall through */
Emil Tantilov5700ff22013-04-18 08:18:55 +000010153 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010154 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +000010155 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +000010156 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010157 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
10158 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
10159 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -070010160 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010161 }
10162 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010163 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -070010164 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +000010165 switch (subdevice_id) {
10166 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -070010167 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010168 }
10169 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010170 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
10171 /* All except this subdevice support WOL */
10172 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -070010173 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010174 break;
10175 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -070010176 return true;
10177 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010178 break;
10179 }
10180
Emil Tantilov740234f2016-04-21 11:37:12 -070010181 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010182}
10183
10184/**
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010185 * ixgbe_set_fw_version - Set FW version
10186 * @adapter: the adapter private structure
10187 *
10188 * This function is used by probe and ethtool to determine the FW version to
10189 * format to display. The FW version is taken from the EEPROM/NVM.
10190 */
10191static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
10192{
10193 struct ixgbe_hw *hw = &adapter->hw;
10194 struct ixgbe_nvm_version nvm_ver;
10195
10196 ixgbe_get_oem_prod_version(hw, &nvm_ver);
10197 if (nvm_ver.oem_valid) {
10198 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10199 "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
10200 nvm_ver.oem_release);
10201 return;
10202 }
10203
10204 ixgbe_get_etk_id(hw, &nvm_ver);
10205 ixgbe_get_orom_version(hw, &nvm_ver);
10206
10207 if (nvm_ver.or_valid) {
10208 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10209 "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
10210 nvm_ver.or_build, nvm_ver.or_patch);
10211 return;
10212 }
10213
10214 /* Set ETrack ID format */
10215 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10216 "0x%08x", nvm_ver.etk_id);
10217}
10218
10219/**
Auke Kok9a799d72007-09-15 14:07:45 -070010220 * ixgbe_probe - Device Initialization Routine
10221 * @pdev: PCI device information struct
10222 * @ent: entry in ixgbe_pci_tbl
10223 *
10224 * Returns 0 on success, negative on failure
10225 *
10226 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
10227 * The OS initialization, configuring of the adapter private structure,
10228 * and a hardware reset occur.
10229 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010230static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -070010231{
10232 struct net_device *netdev;
10233 struct ixgbe_adapter *adapter = NULL;
10234 struct ixgbe_hw *hw;
10235 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +000010236 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010237 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +000010238 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010239 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +000010240#ifdef IXGBE_FCOE
10241 u16 device_caps;
10242#endif
Don Skidmore289700db2010-12-03 03:32:58 +000010243 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -070010244
Andy Gospodarekbded64a2010-07-21 06:40:31 +000010245 /* Catch broken hardware that put the wrong VF device ID in
10246 * the PCIe SR-IOV capability.
10247 */
10248 if (pdev->is_virtfn) {
10249 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
10250 pci_name(pdev), pdev->vendor, pdev->device);
10251 return -EINVAL;
10252 }
10253
gouji-new9ce77662009-05-06 10:44:45 +000010254 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010255 if (err)
10256 return err;
10257
Russell Kingf5f2eda2013-06-10 12:47:42 +010010258 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -070010259 pci_using_dac = 1;
10260 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010261 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -070010262 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010263 dev_err(&pdev->dev,
10264 "No usable DMA configuration, aborting\n");
10265 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -070010266 }
10267 pci_using_dac = 0;
10268 }
10269
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010270 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -070010271 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +000010272 dev_err(&pdev->dev,
10273 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -070010274 goto err_pci_reg;
10275 }
10276
Frans Pop19d5afd2009-10-02 10:04:12 -070010277 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010278
Auke Kok9a799d72007-09-15 14:07:45 -070010279 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -070010280 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010281
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010282 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +000010283#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010284 /* 8 TC w/ 4 queues per TC */
10285 indices = 4 * MAX_TRAFFIC_CLASS;
10286#else
10287 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +000010288#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010289 }
John Fastabende901acd2011-04-26 07:26:08 +000010290
John Fastabendc85a2612010-02-25 23:15:21 +000010291 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -070010292 if (!netdev) {
10293 err = -ENOMEM;
10294 goto err_alloc_etherdev;
10295 }
10296
Auke Kok9a799d72007-09-15 14:07:45 -070010297 SET_NETDEV_DEV(netdev, &pdev->dev);
10298
Auke Kok9a799d72007-09-15 14:07:45 -070010299 adapter = netdev_priv(netdev);
10300
10301 adapter->netdev = netdev;
10302 adapter->pdev = pdev;
10303 hw = &adapter->hw;
10304 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +000010305 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -070010306
Jeff Kirsher05857982008-09-11 19:57:00 -070010307 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +000010308 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -080010309 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -070010310 if (!hw->hw_addr) {
10311 err = -EIO;
10312 goto err_ioremap;
10313 }
10314
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010315 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010316 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010317 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +000010318 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -070010319
Auke Kok9a799d72007-09-15 14:07:45 -070010320 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -080010321 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010322 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010323 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -070010324 if (ii->link_ops)
10325 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010326
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010327 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -080010328 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010329 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +000010330 if (ixgbe_removed(hw->hw_addr)) {
10331 err = -EIO;
10332 goto err_ioremap;
10333 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010334 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -070010335 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010336 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
10337
10338 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -080010339 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010340 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +000010341 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10342 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
10343 hw->phy.mdio.mmds = 0;
10344 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10345 hw->phy.mdio.dev = netdev;
10346 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
10347 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010348
Auke Kok9a799d72007-09-15 14:07:45 -070010349 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -070010350 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -070010351 if (err)
10352 goto err_sw_init;
10353
Don Skidmoredbd15b82016-03-09 16:45:00 -050010354 /* Make sure the SWFW semaphore is in a valid state */
10355 if (hw->mac.ops.init_swfw_sync)
10356 hw->mac.ops.init_swfw_sync(hw);
10357
Don Skidmoree86bff02010-02-11 04:14:08 +000010358 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -080010359 switch (adapter->hw.mac.type) {
10360 case ixgbe_mac_82599EB:
10361 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010362 case ixgbe_mac_X550:
10363 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -070010364 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +000010365 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -080010366 break;
10367 default:
10368 break;
10369 }
Don Skidmoree86bff02010-02-11 04:14:08 +000010370
Don Skidmorebf069c92009-05-07 10:39:54 +000010371 /*
10372 * If there is a fan on this device and it has failed log the
10373 * failure.
10374 */
10375 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
10376 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
10377 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +000010378 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +000010379 }
10380
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +000010381 if (allow_unsupported_sfp)
10382 hw->allow_unsupported_sfp = allow_unsupported_sfp;
10383
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010384 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010385 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010386 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010387 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -080010388 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -070010389 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -070010390 err = 0;
10391 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +000010392 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10393 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010394 goto err_sw_init;
10395 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010396 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010397 goto err_sw_init;
10398 }
10399
Alexander Duyck99d74482012-05-09 08:09:25 +000010400#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +000010401 /* SR-IOV not supported on the 82598 */
10402 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
10403 goto skip_sriov;
10404 /* Mailbox */
10405 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -080010406 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -080010407 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
Emil Tantilov5c11f002017-01-20 14:11:56 -080010408 ixgbe_enable_sriov(adapter, max_vfs);
Greg Rose60a1a682012-12-11 08:26:33 +000010409skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010410
Alexander Duyck99d74482012-05-09 08:09:25 +000010411#endif
Emil Tantilov396e7992010-07-01 20:05:12 +000010412 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +000010413 NETIF_F_TSO |
10414 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +000010415 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -080010416 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010417 NETIF_F_HW_CSUM;
10418
10419#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
10420 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -070010421 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -070010422 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -040010423 NETIF_F_GSO_UDP_TUNNEL | \
10424 NETIF_F_GSO_UDP_TUNNEL_CSUM)
10425
10426 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
10427 netdev->features |= NETIF_F_GSO_PARTIAL |
10428 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -070010429
Alexander Duyck49763de2016-01-13 07:31:11 -080010430 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -080010431 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +000010432
Alexander Duyckde7a7e32018-06-04 16:51:25 -040010433#ifdef CONFIG_XFRM_OFFLOAD
10434#define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \
10435 NETIF_F_HW_ESP_TX_CSUM | \
10436 NETIF_F_GSO_ESP)
10437
10438 if (adapter->ipsec)
10439 netdev->features |= IXGBE_ESP_FEATURES;
10440#endif
Alexander Duyck49763de2016-01-13 07:31:11 -080010441 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -040010442 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -070010443 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010444 NETIF_F_HW_VLAN_CTAG_RX |
10445 NETIF_F_HW_VLAN_CTAG_TX |
10446 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -080010447 NETIF_F_HW_L2FW_DOFFLOAD;
10448
10449 if (hw->mac.type >= ixgbe_mac_82599EB)
10450 netdev->hw_features |= NETIF_F_NTUPLE |
10451 NETIF_F_HW_TC;
10452
Alexander Duyckb83e3012016-04-14 17:19:31 -040010453 if (pci_using_dac)
10454 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -070010455
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010456 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
10457 netdev->hw_enc_features |= netdev->vlan_features;
Scott Peterson2a205252016-11-18 11:25:42 -080010458 netdev->mpls_features |= NETIF_F_SG |
10459 NETIF_F_TSO |
10460 NETIF_F_TSO6 |
10461 NETIF_F_HW_CSUM;
10462 netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010463
Alexander Duyckb83e3012016-04-14 17:19:31 -040010464 /* set this bit last since it cannot be part of vlan_features */
10465 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
10466 NETIF_F_HW_VLAN_CTAG_RX |
10467 NETIF_F_HW_VLAN_CTAG_TX;
10468
Jiri Pirko01789342011-08-16 06:29:00 +000010469 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +000010470 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +000010471
Jarod Wilson91c527a2016-10-17 15:54:05 -040010472 /* MTU range: 68 - 9710 */
10473 netdev->min_mtu = ETH_MIN_MTU;
10474 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
10475
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080010476#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -070010477 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -080010478 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -080010479#endif
10480
Yi Zoueacd73f2009-05-13 13:11:06 +000010481#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +000010482 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010483 unsigned int fcoe_l;
10484
Yi Zoueacd73f2009-05-13 13:11:06 +000010485 if (hw->mac.ops.get_device_caps) {
10486 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +000010487 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
10488 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +000010489 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010490
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010491
10492 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
10493 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010494
Alexander Duycka58915c2012-05-25 06:38:18 +000010495 netdev->features |= NETIF_F_FSO |
10496 NETIF_F_FCOE_CRC;
10497
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010498 netdev->vlan_features |= NETIF_F_FSO |
10499 NETIF_F_FCOE_CRC |
10500 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +000010501 }
Yi Zoueacd73f2009-05-13 13:11:06 +000010502#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +000010503 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
10504 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +000010505 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +000010506 netdev->features |= NETIF_F_LRO;
10507
Auke Kok9a799d72007-09-15 14:07:45 -070010508 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010509 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010510 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010511 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010512 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010513 }
10514
Sowmini Varadhanc7374b52016-01-12 19:32:30 -080010515 eth_platform_get_mac_address(&adapter->pdev->dev,
10516 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +000010517
Auke Kok9a799d72007-09-15 14:07:45 -070010518 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -070010519
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +000010520 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010521 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010522 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010523 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010524 }
10525
Tushar Dave56768042016-01-07 14:17:03 -080010526 /* Set hw->mac.addr to permanent MAC address */
10527 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -070010528 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010529
Kees Cook26566ea2017-10-16 17:29:35 -070010530 timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
Auke Kok9a799d72007-09-15 14:07:45 -070010531
Mark Rustad58cf6632014-03-12 00:38:40 +000010532 if (ixgbe_removed(hw->hw_addr)) {
10533 err = -EIO;
10534 goto err_sw_init;
10535 }
Alexander Duyck70864002011-04-27 09:13:56 +000010536 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +000010537 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010538 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010539
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010540 err = ixgbe_init_interrupt_scheme(adapter);
10541 if (err)
10542 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010543
Liwei Songb09457e2016-12-04 22:40:44 -050010544 for (i = 0; i < adapter->num_rx_queues; i++)
10545 u64_stats_init(&adapter->rx_ring[i]->syncp);
10546 for (i = 0; i < adapter->num_tx_queues; i++)
10547 u64_stats_init(&adapter->tx_ring[i]->syncp);
John Fastabend33fdc822017-04-24 03:30:18 -070010548 for (i = 0; i < adapter->num_xdp_queues; i++)
10549 u64_stats_init(&adapter->xdp_ring[i]->syncp);
10550
Jacob Keller8e2813f2012-04-21 06:05:40 +000010551 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010552 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010553 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010554 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +000010555 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010556 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +000010557 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010558
PJ Waskiewicze8e26352009-02-27 15:45:05 +000010559 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
10560
Emil Tantilov15e52092011-09-29 05:01:29 +000010561 /* save off EEPROM version number */
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010562 ixgbe_set_fw_version(adapter);
Emil Tantilov15e52092011-09-29 05:01:29 +000010563
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010564 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +000010565 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +000010566 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -040010567 else
10568 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010569
Jacob Kellere027d1a2013-07-31 06:53:31 +000010570 /* calculate the expected PCIe bandwidth required for optimal
10571 * performance. Note that some older parts will never have enough
10572 * bandwidth due to being older generation PCIe parts. We clamp these
10573 * parts to ensure no warning is displayed if it can't be fixed.
10574 */
10575 switch (hw->mac.type) {
10576 case ixgbe_mac_82598EB:
10577 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
10578 break;
10579 default:
10580 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
10581 break;
Auke Kok0c254d82008-02-11 09:25:56 -080010582 }
Jacob Kellercaafb952014-07-19 07:17:17 +000010583
10584 /* don't check link if we failed to enumerate functions */
10585 if (expected_gts > 0)
10586 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -080010587
Mark Rustad339de302014-06-06 01:57:06 +000010588 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010589 if (err)
Mark Rustad339de302014-06-06 01:57:06 +000010590 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010591 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
10592 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
10593 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +000010594 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +000010595 else
10596 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
10597 hw->mac.type, hw->phy.type, part_str);
10598
10599 e_dev_info("%pM\n", netdev->dev_addr);
10600
Auke Kok9a799d72007-09-15 14:07:45 -070010601 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010602 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010603 if (err == IXGBE_ERR_EEPROM_VERSION) {
10604 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010605 e_dev_warn("This device is a pre-production adapter/LOM. "
10606 "Please be aware there may be issues associated "
10607 "with your hardware. If you are experiencing "
10608 "problems please contact your Intel or hardware "
10609 "representative who provided you with this "
10610 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010611 }
Auke Kok9a799d72007-09-15 14:07:45 -070010612 strcpy(netdev->name, "eth%d");
Jeff Mahoneya09c0fc2017-06-03 18:01:17 -040010613 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010614 err = register_netdev(netdev);
10615 if (err)
10616 goto err_register;
10617
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010618
Emil Tantilovec74a472012-09-20 03:33:56 +000010619 /* power down the optics for 82599 SFP+ fiber */
10620 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010621 hw->mac.ops.disable_tx_laser(hw);
10622
Jesse Brandeburg54386462009-04-17 20:44:27 +000010623 /* carrier off reporting is important to ethtool even BEFORE open */
10624 netif_carrier_off(netdev);
10625
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010626#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010627 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010628 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010629 ixgbe_setup_dca(adapter);
10630 }
10631#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010632 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010633 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010634 for (i = 0; i < adapter->num_vfs; i++)
10635 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10636 }
10637
Jacob Keller2466dd92011-09-08 03:50:54 +000010638 /* firmware requires driver version to be 0xFFFFFFFF
10639 * since os does not support feature
10640 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010641 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010642 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10643 sizeof(ixgbe_driver_version) - 1,
10644 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010645
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010646 /* add san mac addr to netdev */
10647 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010648
Neerav Parikhea818752012-01-04 20:23:40 +000010649 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010650
Don Skidmore12109822012-05-04 06:07:08 +000010651#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010652 if (ixgbe_sysfs_init(adapter))
10653 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010654#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010655
Catherine Sullivan00949162012-08-10 01:59:10 +000010656 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010657
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010658 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10659 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010660 hw->mac.ops.setup_link(hw,
10661 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10662 true);
10663
Auke Kok9a799d72007-09-15 14:07:45 -070010664 return 0;
10665
10666err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010667 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010668 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010669err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010670 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010671 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010672 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010673 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010674 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010675 kfree(adapter->rss_key);
Auke Kok9a799d72007-09-15 14:07:45 -070010676err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010677 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010678 free_netdev(netdev);
10679err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010680 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010681err_pci_reg:
10682err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010683 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010684 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010685 return err;
10686}
10687
10688/**
10689 * ixgbe_remove - Device Removal Routine
10690 * @pdev: PCI device information struct
10691 *
10692 * ixgbe_remove is called by the PCI subsystem to alert the driver
10693 * that it should release a PCI device. The could be caused by a
10694 * Hot-Plug event, or because the driver is going to be removed from
10695 * memory.
10696 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010697static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010698{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010699 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010700 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010701 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010702 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010703
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010704 /* if !adapter then we already cleaned up in probe */
10705 if (!adapter)
10706 return;
10707
10708 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010709 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010710
Mark Rustad09f40ae2014-01-14 18:53:11 -080010711 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010712 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010713
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010714
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010715#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010716 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10717 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10718 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010719 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10720 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010721 }
10722
10723#endif
Don Skidmore12109822012-05-04 06:07:08 +000010724#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010725 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010726#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010727
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010728 /* remove the added san mac */
10729 ixgbe_del_sanmac_netdev(netdev);
10730
Greg Roseda36b642012-12-11 08:26:43 +000010731#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010732 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010733#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010734 if (netdev->reg_state == NETREG_REGISTERED)
10735 unregister_netdev(netdev);
10736
Shannon Nelson63a67fe2017-12-19 15:59:57 -080010737 ixgbe_stop_ipsec_offload(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010738 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010739
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010740 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010741
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010742#ifdef CONFIG_DCB
10743 kfree(adapter->ixgbe_ieee_pfc);
10744 kfree(adapter->ixgbe_ieee_ets);
10745
10746#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010747 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010748 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010749
Emil Tantilov849c4542010-06-03 16:53:41 +000010750 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010751
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010752 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10753 if (adapter->jump_tables[i]) {
10754 kfree(adapter->jump_tables[i]->input);
10755 kfree(adapter->jump_tables[i]->mask);
10756 }
10757 kfree(adapter->jump_tables[i]);
10758 }
10759
Jacob Keller5d7daa32014-03-29 06:51:25 +000010760 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010761 kfree(adapter->rss_key);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010762 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010763 free_netdev(netdev);
10764
Frans Pop19d5afd2009-10-02 10:04:12 -070010765 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010766
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010767 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010768 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010769}
10770
10771/**
10772 * ixgbe_io_error_detected - called when PCI error is detected
10773 * @pdev: Pointer to PCI device
10774 * @state: The current pci connection state
10775 *
10776 * This function is called after a PCI bus error affecting
10777 * this device has been detected.
10778 */
10779static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010780 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010781{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010782 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10783 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010784
Greg Rose83c61fa2011-09-07 05:59:35 +000010785#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010786 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010787 struct pci_dev *bdev, *vfdev;
10788 u32 dw0, dw1, dw2, dw3;
10789 int vf, pos;
10790 u16 req_id, pf_func;
10791
10792 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10793 adapter->num_vfs == 0)
10794 goto skip_bad_vf_detection;
10795
10796 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010797 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010798 bdev = bdev->bus->self;
10799
10800 if (!bdev)
10801 goto skip_bad_vf_detection;
10802
10803 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10804 if (!pos)
10805 goto skip_bad_vf_detection;
10806
Mark Rustad14438462014-02-28 15:48:57 -080010807 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10808 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10809 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10810 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10811 if (ixgbe_removed(hw->hw_addr))
10812 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010813
10814 req_id = dw1 >> 16;
10815 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10816 if (!(req_id & 0x0080))
10817 goto skip_bad_vf_detection;
10818
10819 pf_func = req_id & 0x01;
10820 if ((pf_func & 1) == (pdev->devfn & 1)) {
10821 unsigned int device_id;
10822
10823 vf = (req_id & 0x7F) >> 1;
10824 e_dev_err("VF %d has caused a PCIe error\n", vf);
10825 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10826 "%8.8x\tdw3: %8.8x\n",
10827 dw0, dw1, dw2, dw3);
10828 switch (adapter->hw.mac.type) {
10829 case ixgbe_mac_82599EB:
10830 device_id = IXGBE_82599_VF_DEVICE_ID;
10831 break;
10832 case ixgbe_mac_X540:
10833 device_id = IXGBE_X540_VF_DEVICE_ID;
10834 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010835 case ixgbe_mac_X550:
10836 device_id = IXGBE_DEV_ID_X550_VF;
10837 break;
10838 case ixgbe_mac_X550EM_x:
10839 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10840 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010841 case ixgbe_mac_x550em_a:
10842 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10843 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010844 default:
10845 device_id = 0;
10846 break;
10847 }
10848
10849 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010850 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010851 while (vfdev) {
10852 if (vfdev->devfn == (req_id & 0xFF))
10853 break;
Jon Mason36e90312012-07-19 21:02:09 +000010854 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010855 device_id, vfdev);
10856 }
10857 /*
10858 * There's a slim chance the VF could have been hot plugged,
10859 * so if it is no longer present we don't need to issue the
10860 * VFLR. Just clean up the AER in that case.
10861 */
10862 if (vfdev) {
Christoph Hellwig63af8f72017-04-14 21:11:28 +020010863 pcie_flr(vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010864 /* Free device reference count */
10865 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010866 }
10867
10868 pci_cleanup_aer_uncorrect_error_status(pdev);
10869 }
10870
10871 /*
10872 * Even though the error may have occurred on the other port
10873 * we still need to increment the vf error reference count for
10874 * both ports because the I/O resume function will be called
10875 * for both of them.
10876 */
10877 adapter->vferr_refcount++;
10878
10879 return PCI_ERS_RESULT_RECOVERED;
10880
10881skip_bad_vf_detection:
10882#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010883 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10884 return PCI_ERS_RESULT_DISCONNECT;
10885
Emil Tantilovb64666a2017-09-29 10:55:42 -070010886 if (!netif_device_present(netdev))
10887 return PCI_ERS_RESULT_DISCONNECT;
10888
Mark Rustad41c62842014-03-12 00:38:35 +000010889 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010890 netif_device_detach(netdev);
10891
Mauro S M Rodriguesb212d812018-05-02 17:26:28 -030010892 if (netif_running(netdev))
10893 ixgbe_close_suspend(adapter);
10894
Mark Rustad41c62842014-03-12 00:38:35 +000010895 if (state == pci_channel_io_perm_failure) {
10896 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010897 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010898 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010899
Mark Rustad41c62842014-03-12 00:38:35 +000010900 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10901 pci_disable_device(pdev);
10902 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010903
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010904 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010905 return PCI_ERS_RESULT_NEED_RESET;
10906}
10907
10908/**
10909 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10910 * @pdev: Pointer to PCI device
10911 *
10912 * Restart the card from scratch, as if from a cold-boot.
10913 */
10914static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10915{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010916 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010917 pci_ers_result_t result;
10918 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010919
gouji-new9ce77662009-05-06 10:44:45 +000010920 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010921 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010922 result = PCI_ERS_RESULT_DISCONNECT;
10923 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010924 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010925 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010926 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010927 pci_set_master(pdev);
10928 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010929 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010930
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010931 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010932
10933 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010934 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010935 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010936 }
Auke Kok9a799d72007-09-15 14:07:45 -070010937
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010938 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10939 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010940 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10941 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010942 /* non-fatal, continue */
10943 }
Auke Kok9a799d72007-09-15 14:07:45 -070010944
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010945 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010946}
10947
10948/**
10949 * ixgbe_io_resume - called when traffic can start flowing again.
10950 * @pdev: Pointer to PCI device
10951 *
10952 * This callback is called when the error recovery driver tells us that
10953 * its OK to resume normal operation.
10954 */
10955static void ixgbe_io_resume(struct pci_dev *pdev)
10956{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010957 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10958 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010959
Greg Rose83c61fa2011-09-07 05:59:35 +000010960#ifdef CONFIG_PCI_IOV
10961 if (adapter->vferr_refcount) {
10962 e_info(drv, "Resuming after VF err\n");
10963 adapter->vferr_refcount--;
10964 return;
10965 }
10966
10967#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010968 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010969 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010970 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010971
10972 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010973 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010974}
10975
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010976static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010977 .error_detected = ixgbe_io_error_detected,
10978 .slot_reset = ixgbe_io_slot_reset,
10979 .resume = ixgbe_io_resume,
10980};
10981
10982static struct pci_driver ixgbe_driver = {
10983 .name = ixgbe_driver_name,
10984 .id_table = ixgbe_pci_tbl,
10985 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010986 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010987#ifdef CONFIG_PM
10988 .suspend = ixgbe_suspend,
10989 .resume = ixgbe_resume,
10990#endif
10991 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000010992 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070010993 .err_handler = &ixgbe_err_handler
10994};
10995
10996/**
10997 * ixgbe_init_module - Driver Registration Routine
10998 *
10999 * ixgbe_init_module is the first routine called when the driver is
11000 * loaded. All it does is register with the PCI subsystem.
11001 **/
11002static int __init ixgbe_init_module(void)
11003{
11004 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000011005 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000011006 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070011007
Mark Rustad780484d2015-10-21 17:21:10 -070011008 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
11009 if (!ixgbe_wq) {
11010 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
11011 return -ENOMEM;
11012 }
11013
Catherine Sullivan00949162012-08-10 01:59:10 +000011014 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000011015
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011016 ret = pci_register_driver(&ixgbe_driver);
11017 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000011018 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011019 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011020 return ret;
11021 }
11022
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011023#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011024 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011025#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011026
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011027 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070011028}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070011029
Auke Kok9a799d72007-09-15 14:07:45 -070011030module_init(ixgbe_init_module);
11031
11032/**
11033 * ixgbe_exit_module - Driver Exit Cleanup Routine
11034 *
11035 * ixgbe_exit_module is called just before the driver is removed
11036 * from memory.
11037 **/
11038static void __exit ixgbe_exit_module(void)
11039{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011040#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011041 dca_unregister_notify(&dca_notifier);
11042#endif
Auke Kok9a799d72007-09-15 14:07:45 -070011043 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000011044
Catherine Sullivan00949162012-08-10 01:59:10 +000011045 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070011046 if (ixgbe_wq) {
11047 destroy_workqueue(ixgbe_wq);
11048 ixgbe_wq = NULL;
11049 }
Auke Kok9a799d72007-09-15 14:07:45 -070011050}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011051
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011052#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011053static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011054 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011055{
11056 int ret_val;
11057
11058 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011059 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011060
11061 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
11062}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011063
Alexander Duyckb4533682009-03-31 21:32:42 +000011064#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000011065
Auke Kok9a799d72007-09-15 14:07:45 -070011066module_exit(ixgbe_exit_module);
11067
11068/* ixgbe_main.c */