blob: 62e57b05a0aed3d9a02bf8d473aa49505608728f [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
Jesper Dangaard Brouerad088ec2018-06-26 17:39:48 +02002189#define IXGBE_XDP_PASS 0
2190#define IXGBE_XDP_CONSUMED BIT(0)
2191#define IXGBE_XDP_TX BIT(1)
2192#define IXGBE_XDP_REDIR BIT(2)
John Fastabend92470802017-04-24 03:30:17 -07002193
John Fastabend33fdc822017-04-24 03:30:18 -07002194static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002195 struct xdp_frame *xdpf);
John Fastabend33fdc822017-04-24 03:30:18 -07002196
2197static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
2198 struct ixgbe_ring *rx_ring,
John Fastabend92470802017-04-24 03:30:17 -07002199 struct xdp_buff *xdp)
2200{
John Fastabend64530732017-07-17 09:28:12 -07002201 int err, result = IXGBE_XDP_PASS;
John Fastabend92470802017-04-24 03:30:17 -07002202 struct bpf_prog *xdp_prog;
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002203 struct xdp_frame *xdpf;
John Fastabend92470802017-04-24 03:30:17 -07002204 u32 act;
2205
2206 rcu_read_lock();
2207 xdp_prog = READ_ONCE(rx_ring->xdp_prog);
2208
2209 if (!xdp_prog)
2210 goto xdp_out;
2211
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002212 prefetchw(xdp->data_hard_start); /* xdp_frame write */
2213
John Fastabend92470802017-04-24 03:30:17 -07002214 act = bpf_prog_run_xdp(xdp_prog, xdp);
2215 switch (act) {
2216 case XDP_PASS:
2217 break;
John Fastabend33fdc822017-04-24 03:30:18 -07002218 case XDP_TX:
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02002219 xdpf = convert_to_xdp_frame(xdp);
2220 if (unlikely(!xdpf)) {
2221 result = IXGBE_XDP_CONSUMED;
2222 break;
2223 }
2224 result = ixgbe_xmit_xdp_ring(adapter, xdpf);
John Fastabend33fdc822017-04-24 03:30:18 -07002225 break;
John Fastabend64530732017-07-17 09:28:12 -07002226 case XDP_REDIRECT:
John Fastabend5acaee02017-07-17 09:28:35 -07002227 err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
John Fastabend64530732017-07-17 09:28:12 -07002228 if (!err)
Jesper Dangaard Brouerad088ec2018-06-26 17:39:48 +02002229 result = IXGBE_XDP_REDIR;
John Fastabend64530732017-07-17 09:28:12 -07002230 else
2231 result = IXGBE_XDP_CONSUMED;
2232 break;
John Fastabend92470802017-04-24 03:30:17 -07002233 default:
2234 bpf_warn_invalid_xdp_action(act);
Tony Nguyen93df9462017-05-31 04:43:47 -07002235 /* fallthrough */
John Fastabend92470802017-04-24 03:30:17 -07002236 case XDP_ABORTED:
2237 trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
2238 /* fallthrough -- handle aborts by dropping packet */
2239 case XDP_DROP:
2240 result = IXGBE_XDP_CONSUMED;
2241 break;
2242 }
2243xdp_out:
2244 rcu_read_unlock();
2245 return ERR_PTR(-result);
2246}
2247
John Fastabend33fdc822017-04-24 03:30:18 -07002248static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
2249 struct ixgbe_rx_buffer *rx_buffer,
2250 unsigned int size)
2251{
2252#if (PAGE_SIZE < 8192)
2253 unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
2254
2255 rx_buffer->page_offset ^= truesize;
2256#else
2257 unsigned int truesize = ring_uses_build_skb(rx_ring) ?
2258 SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
2259 SKB_DATA_ALIGN(size);
2260
2261 rx_buffer->page_offset += truesize;
2262#endif
2263}
2264
Alexander Duyckf8003262012-03-03 02:35:52 +00002265/**
2266 * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
2267 * @q_vector: structure containing interrupt and ring information
2268 * @rx_ring: rx descriptor ring to transact packets on
2269 * @budget: Total limit on number of packets to process
2270 *
2271 * This function provides a "bounce buffer" approach to Rx interrupt
2272 * processing. The advantage to this is that on systems that have
2273 * expensive overhead for IOMMU access this provides a means of avoiding
2274 * it by maintaining the mapping of the page to the syste.
2275 *
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002276 * Returns amount of work completed
Alexander Duyckf8003262012-03-03 02:35:52 +00002277 **/
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002278static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002279 struct ixgbe_ring *rx_ring,
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002280 const int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07002281{
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002282 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckf8003262012-03-03 02:35:52 +00002283 struct ixgbe_adapter *adapter = q_vector->adapter;
John Fastabend33fdc822017-04-24 03:30:18 -07002284#ifdef IXGBE_FCOE
Mark Rustad4ffdf912012-07-18 06:05:50 +00002285 int ddp_bytes;
2286 unsigned int mss = 0;
Yi Zou3d8fd382009-06-08 14:38:44 +00002287#endif /* IXGBE_FCOE */
Alexander Duyckf8003262012-03-03 02:35:52 +00002288 u16 cleaned_count = ixgbe_desc_unused(rx_ring);
Jesper Dangaard Brouerad088ec2018-06-26 17:39:48 +02002289 unsigned int xdp_xmit = 0;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01002290 struct xdp_buff xdp;
2291
2292 xdp.rxq = &rx_ring->xdp_rxq;
Auke Kok9a799d72007-09-15 14:07:45 -07002293
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002294 while (likely(total_rx_packets < budget)) {
Alexander Duyckf8003262012-03-03 02:35:52 +00002295 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002296 struct ixgbe_rx_buffer *rx_buffer;
Alexander Duyckf8003262012-03-03 02:35:52 +00002297 struct sk_buff *skb;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002298 unsigned int size;
Auke Kok9a799d72007-09-15 14:07:45 -07002299
Alexander Duyckf8003262012-03-03 02:35:52 +00002300 /* return some buffers to hardware, one at a time is too slow */
2301 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
2302 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
2303 cleaned_count = 0;
2304 }
Auke Kok9a799d72007-09-15 14:07:45 -07002305
Alexander Duyck18806c92012-07-20 08:08:44 +00002306 rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
Alexander Duyck3fd218762017-01-17 08:36:45 -08002307 size = le16_to_cpu(rx_desc->wb.upper.length);
2308 if (!size)
Alexander Duyckf8003262012-03-03 02:35:52 +00002309 break;
Alexander Duyckc267fc12010-11-16 19:27:00 -08002310
Alexander Duyck124b74c2014-12-11 15:02:28 -08002311 /* This memory barrier is needed to keep us from reading
Alexander Duyckf8003262012-03-03 02:35:52 +00002312 * any other fields out of the rx_desc until we know the
Alexander Duyck124b74c2014-12-11 15:02:28 -08002313 * descriptor has been written back
Alexander Duyckf8003262012-03-03 02:35:52 +00002314 */
Alexander Duyck124b74c2014-12-11 15:02:28 -08002315 dma_rmb();
Auke Kok9a799d72007-09-15 14:07:45 -07002316
Alexander Duyck3fd218762017-01-17 08:36:45 -08002317 rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
2318
Alexander Duyck18806c92012-07-20 08:08:44 +00002319 /* retrieve a buffer from the ring */
John Fastabend92470802017-04-24 03:30:17 -07002320 if (!skb) {
2321 xdp.data = page_address(rx_buffer->page) +
2322 rx_buffer->page_offset;
Daniel Borkmann366a88f2017-09-25 02:25:55 +02002323 xdp.data_meta = xdp.data;
John Fastabend92470802017-04-24 03:30:17 -07002324 xdp.data_hard_start = xdp.data -
2325 ixgbe_rx_offset(rx_ring);
2326 xdp.data_end = xdp.data + size;
2327
John Fastabend33fdc822017-04-24 03:30:18 -07002328 skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
John Fastabend92470802017-04-24 03:30:17 -07002329 }
2330
2331 if (IS_ERR(skb)) {
Jesper Dangaard Brouerad088ec2018-06-26 17:39:48 +02002332 unsigned int xdp_res = -PTR_ERR(skb);
2333
2334 if (xdp_res & (IXGBE_XDP_TX | IXGBE_XDP_REDIR)) {
2335 xdp_xmit |= xdp_res;
John Fastabend33fdc822017-04-24 03:30:18 -07002336 ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
John Fastabend7379f972017-03-28 09:47:03 -07002337 } else {
John Fastabend33fdc822017-04-24 03:30:18 -07002338 rx_buffer->pagecnt_bias++;
John Fastabend7379f972017-03-28 09:47:03 -07002339 }
John Fastabend92470802017-04-24 03:30:17 -07002340 total_rx_packets++;
2341 total_rx_bytes += size;
John Fastabend92470802017-04-24 03:30:17 -07002342 } else if (skb) {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002343 ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
John Fastabend92470802017-04-24 03:30:17 -07002344 } else if (ring_uses_build_skb(rx_ring)) {
Alexander Duyck6f429222017-01-17 08:37:13 -08002345 skb = ixgbe_build_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002346 &xdp, rx_desc);
2347 } else {
Alexander Duyck3fd218762017-01-17 08:36:45 -08002348 skb = ixgbe_construct_skb(rx_ring, rx_buffer,
John Fastabend92470802017-04-24 03:30:17 -07002349 &xdp, rx_desc);
2350 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002351
Alexander Duyck18806c92012-07-20 08:08:44 +00002352 /* exit if we failed to retrieve a buffer */
Alexander Duyck3fd218762017-01-17 08:36:45 -08002353 if (!skb) {
2354 rx_ring->rx_stats.alloc_rx_buff_failed++;
2355 rx_buffer->pagecnt_bias++;
Alexander Duyck18806c92012-07-20 08:08:44 +00002356 break;
Alexander Duyck3fd218762017-01-17 08:36:45 -08002357 }
Alexander Duyck4c1975d2012-01-31 02:59:23 +00002358
Alexander Duyck3fd218762017-01-17 08:36:45 -08002359 ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002360 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002361
Alexander Duyckf8003262012-03-03 02:35:52 +00002362 /* place incomplete frames back on ring for completion */
2363 if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
2364 continue;
Alexander Duyckf8212f92009-04-27 22:42:37 +00002365
Alexander Duyckf8003262012-03-03 02:35:52 +00002366 /* verify the packet layout is correct */
2367 if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
2368 continue;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002369
2370 /* probably a little skewed due to removing CRC */
2371 total_rx_bytes += skb->len;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08002372
Alexander Duyck8a0da212012-01-31 02:59:49 +00002373 /* populate checksum, timestamp, VLAN, and protocol */
2374 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
2375
Yi Zou332d4a72009-05-13 13:11:53 +00002376#ifdef IXGBE_FCOE
2377 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyck57efd442012-06-25 21:54:46 +00002378 if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00002379 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
Mark Rustad4ffdf912012-07-18 06:05:50 +00002380 /* include DDPed FCoE data */
2381 if (ddp_bytes > 0) {
2382 if (!mss) {
2383 mss = rx_ring->netdev->mtu -
2384 sizeof(struct fcoe_hdr) -
2385 sizeof(struct fc_frame_header) -
2386 sizeof(struct fcoe_crc_eof);
2387 if (mss > 512)
2388 mss &= ~511;
2389 }
2390 total_rx_bytes += ddp_bytes;
2391 total_rx_packets += DIV_ROUND_UP(ddp_bytes,
2392 mss);
2393 }
David S. Miller823dcd22011-08-20 10:39:12 -07002394 if (!ddp_bytes) {
2395 dev_kfree_skb_any(skb);
Alexander Duyckf8003262012-03-03 02:35:52 +00002396 continue;
David S. Miller823dcd22011-08-20 10:39:12 -07002397 }
Yi Zou3d8fd382009-06-08 14:38:44 +00002398 }
Alexander Duyckf8003262012-03-03 02:35:52 +00002399
Yi Zou332d4a72009-05-13 13:11:53 +00002400#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00002401 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07002402
Alexander Duyckf8003262012-03-03 02:35:52 +00002403 /* update budget accounting */
Alexander Duyckf4de00e2012-09-25 00:29:37 +00002404 total_rx_packets++;
Eric W. Biedermanfdabfc8a2014-03-14 18:00:41 -07002405 }
Auke Kok9a799d72007-09-15 14:07:45 -07002406
Jesper Dangaard Brouerad088ec2018-06-26 17:39:48 +02002407 if (xdp_xmit & IXGBE_XDP_REDIR)
2408 xdp_do_flush_map();
2409
2410 if (xdp_xmit & IXGBE_XDP_TX) {
John Fastabend7379f972017-03-28 09:47:03 -07002411 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
2412
2413 /* Force memory writes to complete before letting h/w
2414 * know there are new descriptors to fetch.
2415 */
2416 wmb();
2417 writel(ring->next_to_use, ring->tail);
2418 }
2419
Alexander Duyckc267fc12010-11-16 19:27:00 -08002420 u64_stats_update_begin(&rx_ring->syncp);
2421 rx_ring->stats.packets += total_rx_packets;
2422 rx_ring->stats.bytes += total_rx_bytes;
2423 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00002424 q_vector->rx.total_packets += total_rx_packets;
2425 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002426
Eliezer Tamir5a85e732013-06-10 11:40:20 +03002427 return total_rx_packets;
Auke Kok9a799d72007-09-15 14:07:45 -07002428}
2429
Auke Kok9a799d72007-09-15 14:07:45 -07002430/**
2431 * ixgbe_configure_msix - Configure MSI-X hardware
2432 * @adapter: board private structure
2433 *
2434 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
2435 * interrupts.
2436 **/
2437static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
2438{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002439 struct ixgbe_q_vector *q_vector;
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002440 int v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002441 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07002442
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002443 /* Populate MSIX to EITR Select */
2444 if (adapter->num_vfs > 32) {
Jacob Kellerb4f47a42016-04-13 16:08:22 -07002445 u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00002446 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2447 }
2448
Jesse Brandeburg4df10462009-03-13 22:15:31 +00002449 /*
2450 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002451 * corresponding register.
2452 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00002453 for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002454 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002455 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002456
Alexander Duycka5579282012-02-08 07:50:04 +00002457 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002458 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002459
Alexander Duycka5579282012-02-08 07:50:04 +00002460 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002461 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002462
Alexander Duyckfe49f042009-06-04 16:00:09 +00002463 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002464 }
2465
Alexander Duyckbd508172010-11-16 19:27:03 -08002466 switch (adapter->hw.mac.type) {
2467 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002468 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00002469 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002470 break;
2471 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002472 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002473 case ixgbe_mac_X550:
2474 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002475 case ixgbe_mac_x550em_a:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002476 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08002477 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08002478 default:
2479 break;
2480 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002481 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07002482
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07002483 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002484 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002485 mask &= ~(IXGBE_EIMS_OTHER |
2486 IXGBE_EIMS_MAILBOX |
2487 IXGBE_EIMS_LSC);
2488
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002489 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07002490}
2491
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002492/**
2493 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00002494 * @q_vector: structure containing interrupt and ring information
2495 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002496 *
2497 * Stores a new ITR value based on packets and byte
2498 * counts during the last interrupt. The advantage of per interrupt
2499 * computation is faster updates and more accurate ITR for the current
2500 * traffic pattern. Constants in this function were computed
2501 * based on theoretical maximum wire speed and thresholds were set based
2502 * on testing data as well as attempting to minimize response time
2503 * while increasing bulk throughput.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002504 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00002505static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
2506 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002507{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002508 unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
2509 IXGBE_ITR_ADAPTIVE_LATENCY;
2510 unsigned int avg_wire_size, packets, bytes;
2511 unsigned long next_update = jiffies;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002512
Alexander Duyckb4ded832017-09-25 14:55:36 -07002513 /* If we don't have any rings just leave ourselves set for maximum
2514 * possible latency so we take ourselves out of the equation.
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002515 */
Alexander Duyckb4ded832017-09-25 14:55:36 -07002516 if (!ring_container->ring)
Don Skidmorebdbeefe2013-03-02 07:17:37 +00002517 return;
2518
Alexander Duyckb4ded832017-09-25 14:55:36 -07002519 /* If we didn't update within up to 1 - 2 jiffies we can assume
2520 * that either packets are coming in so slow there hasn't been
2521 * any work, or that there is so much work that NAPI is dealing
2522 * with interrupt moderation and we don't need to do anything.
2523 */
2524 if (time_after(next_update, ring_container->next_update))
2525 goto clear_counts;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002526
Alexander Duyckb4ded832017-09-25 14:55:36 -07002527 packets = ring_container->total_packets;
2528
2529 /* We have no packets to actually measure against. This means
2530 * either one of the other queues on this vector is active or
2531 * we are a Tx queue doing TSO with too high of an interrupt rate.
2532 *
2533 * When this occurs just tick up our delay by the minimum value
2534 * and hope that this extra delay will prevent us from being called
2535 * without any work on our queue.
2536 */
2537 if (!packets) {
2538 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2539 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2540 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2541 itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
2542 goto clear_counts;
2543 }
2544
2545 bytes = ring_container->total_bytes;
2546
2547 /* If packets are less than 4 or bytes are less than 9000 assume
2548 * insufficient data to use bulk rate limiting approach. We are
2549 * likely latency driven.
2550 */
2551 if (packets < 4 && bytes < 9000) {
2552 itr = IXGBE_ITR_ADAPTIVE_LATENCY;
2553 goto adjust_by_size;
2554 }
2555
2556 /* Between 4 and 48 we can assume that our current interrupt delay
2557 * is only slightly too low. As such we should increase it by a small
2558 * fixed amount.
2559 */
2560 if (packets < 48) {
2561 itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
2562 if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
2563 itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
2564 goto clear_counts;
2565 }
2566
2567 /* Between 48 and 96 is our "goldilocks" zone where we are working
2568 * out "just right". Just report that our current ITR is good for us.
2569 */
2570 if (packets < 96) {
2571 itr = q_vector->itr >> 2;
2572 goto clear_counts;
2573 }
2574
2575 /* If packet count is 96 or greater we are likely looking at a slight
2576 * overrun of the delay we want. Try halving our delay to see if that
2577 * will cut the number of packets in half per interrupt.
2578 */
2579 if (packets < 256) {
2580 itr = q_vector->itr >> 3;
2581 if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
2582 itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
2583 goto clear_counts;
2584 }
2585
2586 /* The paths below assume we are dealing with a bulk ITR since number
2587 * of packets is 256 or greater. We are just going to have to compute
2588 * a value and try to bring the count under control, though for smaller
2589 * packet sizes there isn't much we can do as NAPI polling will likely
2590 * be kicking in sooner rather than later.
2591 */
2592 itr = IXGBE_ITR_ADAPTIVE_BULK;
2593
2594adjust_by_size:
2595 /* If packet counts are 256 or greater we can assume we have a gross
2596 * overestimation of what the rate should be. Instead of trying to fine
2597 * tune it just use the formula below to try and dial in an exact value
2598 * give the current packet size of the frame.
2599 */
2600 avg_wire_size = bytes / packets;
2601
2602 /* The following is a crude approximation of:
2603 * wmem_default / (size + overhead) = desired_pkts_per_int
2604 * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
2605 * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
2606 *
2607 * Assuming wmem_default is 212992 and overhead is 640 bytes per
2608 * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
2609 * formula down to
2610 *
2611 * (170 * (size + 24)) / (size + 640) = ITR
2612 *
2613 * We first do some math on the packet size and then finally bitshift
2614 * by 8 after rounding up. We also have to account for PCIe link speed
2615 * difference as ITR scales based on this.
2616 */
2617 if (avg_wire_size <= 60) {
2618 /* Start at 50k ints/sec */
2619 avg_wire_size = 5120;
2620 } else if (avg_wire_size <= 316) {
2621 /* 50K ints/sec to 16K ints/sec */
2622 avg_wire_size *= 40;
2623 avg_wire_size += 2720;
2624 } else if (avg_wire_size <= 1084) {
2625 /* 16K ints/sec to 9.2K ints/sec */
2626 avg_wire_size *= 15;
2627 avg_wire_size += 11452;
2628 } else if (avg_wire_size <= 1980) {
2629 /* 9.2K ints/sec to 8K ints/sec */
2630 avg_wire_size *= 5;
2631 avg_wire_size += 22420;
2632 } else {
2633 /* plateau at a limit of 8K ints/sec */
2634 avg_wire_size = 32256;
2635 }
2636
2637 /* If we are in low latency mode half our delay which doubles the rate
2638 * to somewhere between 100K to 16K ints/sec
2639 */
2640 if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
2641 avg_wire_size >>= 1;
2642
2643 /* Resultant value is 256 times larger than it needs to be. This
2644 * gives us room to adjust the value as needed to either increase
2645 * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
2646 *
2647 * Use addition as we have already recorded the new latency flag
2648 * for the ITR value.
2649 */
2650 switch (q_vector->adapter->link_speed) {
2651 case IXGBE_LINK_SPEED_10GB_FULL:
2652 case IXGBE_LINK_SPEED_100_FULL:
2653 default:
2654 itr += DIV_ROUND_UP(avg_wire_size,
2655 IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
2656 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002657 break;
Alexander Duyckb4ded832017-09-25 14:55:36 -07002658 case IXGBE_LINK_SPEED_2_5GB_FULL:
2659 case IXGBE_LINK_SPEED_1GB_FULL:
2660 case IXGBE_LINK_SPEED_10_FULL:
2661 itr += DIV_ROUND_UP(avg_wire_size,
2662 IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
2663 IXGBE_ITR_ADAPTIVE_MIN_INC;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002664 break;
2665 }
2666
Alexander Duyckb4ded832017-09-25 14:55:36 -07002667clear_counts:
2668 /* write back value */
2669 ring_container->itr = itr;
2670
2671 /* next update should occur within next jiffy */
2672 ring_container->next_update = next_update + 1;
2673
Alexander Duyckbd198052011-06-11 01:45:08 +00002674 ring_container->total_bytes = 0;
2675 ring_container->total_packets = 0;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002676}
2677
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002678/**
2679 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00002680 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002681 *
2682 * This function is made to be called by ethtool and by the driver
2683 * when it needs to update EITR registers at runtime. Hardware
2684 * specific quirks/differences are taken care of here.
2685 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00002686void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002687{
Alexander Duyckfe49f042009-06-04 16:00:09 +00002688 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002689 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002690 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002691 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002692
Alexander Duyckbd508172010-11-16 19:27:03 -08002693 switch (adapter->hw.mac.type) {
2694 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002695 /* must write high and low 16 bits to reset counter */
2696 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08002697 break;
2698 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002699 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002700 case ixgbe_mac_X550:
2701 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002702 case ixgbe_mac_x550em_a:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002703 /*
2704 * set the WDIS bit to not clear the timer bits and cause an
2705 * immediate assertion of the interrupt
2706 */
2707 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08002708 break;
2709 default:
2710 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002711 }
2712 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
2713}
2714
Alexander Duyckbd198052011-06-11 01:45:08 +00002715static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002716{
Alexander Duyckb4ded832017-09-25 14:55:36 -07002717 u32 new_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002718
Alexander Duyckbd198052011-06-11 01:45:08 +00002719 ixgbe_update_itr(q_vector, &q_vector->tx);
2720 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002721
Alexander Duyckb4ded832017-09-25 14:55:36 -07002722 /* use the smallest value of new ITR delay calculations */
2723 new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002724
Alexander Duyckb4ded832017-09-25 14:55:36 -07002725 /* Clear latency flag if set, shift into correct position */
2726 new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
2727 new_itr <<= 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002728
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002729 if (new_itr != q_vector->itr) {
Alexander Duyckbd198052011-06-11 01:45:08 +00002730 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00002731 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002732
2733 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002734 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002735}
2736
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002737/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00002738 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00002739 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002740 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00002741static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002742{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002743 struct ixgbe_hw *hw = &adapter->hw;
2744 u32 eicr = adapter->interrupt_event;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002745 s32 rc;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002746
Alexander Duyckf0f97782011-04-22 04:08:09 +00002747 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00002748 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002749
Mark Rustad22cb4ff2017-04-25 13:55:25 -07002750 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
Alexander Duyckf0f97782011-04-22 04:08:09 +00002751 return;
2752
2753 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2754
Joe Perches7ca647b2010-09-07 21:35:40 +00002755 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002756 case IXGBE_DEV_ID_82599_T3_LOM:
2757 /*
2758 * Since the warning interrupt is for both ports
2759 * we don't have to check if:
2760 * - This interrupt wasn't for our port.
2761 * - We may have missed the interrupt so always have to
2762 * check if we got a LSC
2763 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002764 if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
Alexander Duyckf0f97782011-04-22 04:08:09 +00002765 !(eicr & IXGBE_EICR_LSC))
2766 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002767
Alexander Duyckf0f97782011-04-22 04:08:09 +00002768 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
Josh Hay3d292262012-12-15 03:28:19 +00002769 u32 speed;
Alexander Duyckf0f97782011-04-22 04:08:09 +00002770 bool link_up = false;
2771
Josh Hay3d292262012-12-15 03:28:19 +00002772 hw->mac.ops.check_link(hw, &speed, &link_up, false);
Joe Perches7ca647b2010-09-07 21:35:40 +00002773
Alexander Duyckf0f97782011-04-22 04:08:09 +00002774 if (link_up)
2775 return;
2776 }
2777
2778 /* Check if this is not due to overtemp */
2779 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
2780 return;
2781
2782 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002783 case IXGBE_DEV_ID_X550EM_A_1G_T:
2784 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
2785 rc = hw->phy.ops.check_overtemp(hw);
2786 if (rc != IXGBE_ERR_OVERTEMP)
2787 return;
2788 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00002789 default:
Don Skidmore597f22d2015-06-09 16:52:02 -07002790 if (adapter->hw.mac.type >= ixgbe_mac_X540)
2791 return;
Don Skidmore9a900ec2015-06-09 17:15:01 -07002792 if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
Joe Perches7ca647b2010-09-07 21:35:40 +00002793 return;
2794 break;
2795 }
Don Skidmoref44e7512015-06-09 16:36:23 -07002796 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Alexander Duyckf0f97782011-04-22 04:08:09 +00002797
2798 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002799}
2800
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002801static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
2802{
2803 struct ixgbe_hw *hw = &adapter->hw;
2804
2805 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
Don Skidmore9a900ec2015-06-09 17:15:01 -07002806 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002807 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002808 /* write to clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002809 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002810 }
2811}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002812
Jacob Keller4f51bf72011-08-20 04:49:45 +00002813static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
2814{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002815 struct ixgbe_hw *hw = &adapter->hw;
2816
Jacob Keller4f51bf72011-08-20 04:49:45 +00002817 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
2818 return;
2819
2820 switch (adapter->hw.mac.type) {
2821 case ixgbe_mac_82599EB:
2822 /*
2823 * Need to check link state so complete overtemp check
2824 * on service task
2825 */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002826 if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
2827 (eicr & IXGBE_EICR_LSC)) &&
Jacob Keller4f51bf72011-08-20 04:49:45 +00002828 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
2829 adapter->interrupt_event = eicr;
2830 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2831 ixgbe_service_event_schedule(adapter);
2832 return;
2833 }
2834 return;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08002835 case ixgbe_mac_x550em_a:
2836 if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
2837 adapter->interrupt_event = eicr;
2838 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2839 ixgbe_service_event_schedule(adapter);
2840 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
2841 IXGBE_EICR_GPI_SDP0_X550EM_a);
2842 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
2843 IXGBE_EICR_GPI_SDP0_X550EM_a);
2844 }
2845 return;
2846 case ixgbe_mac_X550:
Jacob Keller4f51bf72011-08-20 04:49:45 +00002847 case ixgbe_mac_X540:
2848 if (!(eicr & IXGBE_EICR_TS))
2849 return;
2850 break;
2851 default:
2852 return;
2853 }
2854
Don Skidmoref44e7512015-06-09 16:36:23 -07002855 e_crit(drv, "%s\n", ixgbe_overheat_msg);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002856}
2857
Don Skidmore45788d22015-06-09 16:59:04 -07002858static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
2859{
2860 switch (hw->mac.type) {
2861 case ixgbe_mac_82598EB:
2862 if (hw->phy.type == ixgbe_phy_nl)
2863 return true;
2864 return false;
2865 case ixgbe_mac_82599EB:
2866 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002867 case ixgbe_mac_x550em_a:
Don Skidmore45788d22015-06-09 16:59:04 -07002868 switch (hw->mac.ops.get_media_type(hw)) {
2869 case ixgbe_media_type_fiber:
2870 case ixgbe_media_type_fiber_qsfp:
2871 return true;
2872 default:
2873 return false;
2874 }
2875 default:
2876 return false;
2877 }
2878}
2879
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002880static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2881{
2882 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore4ccc6502015-09-02 13:47:54 -07002883 u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002884
Don Skidmore4ccc6502015-09-02 13:47:54 -07002885 if (!ixgbe_is_sfp(hw))
2886 return;
2887
2888 /* Later MAC's use different SDP */
2889 if (hw->mac.type >= ixgbe_mac_X540)
2890 eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
2891
2892 if (eicr & eicr_mask) {
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002893 /* Clear the interrupt */
Don Skidmore4ccc6502015-09-02 13:47:54 -07002894 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
Alexander Duyck70864002011-04-27 09:13:56 +00002895 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2896 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07002897 adapter->sfp_poll_time = 0;
Alexander Duyck70864002011-04-27 09:13:56 +00002898 ixgbe_service_event_schedule(adapter);
2899 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002900 }
2901
Don Skidmore4ccc6502015-09-02 13:47:54 -07002902 if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
2903 (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002904 /* Clear the interrupt */
Don Skidmore9a900ec2015-06-09 17:15:01 -07002905 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
Alexander Duyck70864002011-04-27 09:13:56 +00002906 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2907 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2908 ixgbe_service_event_schedule(adapter);
2909 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002910 }
2911}
2912
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002913static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2914{
2915 struct ixgbe_hw *hw = &adapter->hw;
2916
2917 adapter->lsc_int++;
2918 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2919 adapter->link_check_timeout = jiffies;
2920 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2921 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002922 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002923 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002924 }
2925}
2926
Alexander Duyckfe49f042009-06-04 16:00:09 +00002927static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2928 u64 qmask)
2929{
2930 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002931 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002932
Alexander Duyckbd508172010-11-16 19:27:03 -08002933 switch (hw->mac.type) {
2934 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002935 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002936 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2937 break;
2938 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002939 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002940 case ixgbe_mac_X550:
2941 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002942 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002943 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002944 if (mask)
2945 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002946 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002947 if (mask)
2948 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2949 break;
2950 default:
2951 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002952 }
2953 /* skip the flush */
2954}
2955
2956static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002957 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002958{
2959 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002960 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002961
Alexander Duyckbd508172010-11-16 19:27:03 -08002962 switch (hw->mac.type) {
2963 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002964 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002965 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2966 break;
2967 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002968 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00002969 case ixgbe_mac_X550:
2970 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07002971 case ixgbe_mac_x550em_a:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002972 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002973 if (mask)
2974 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002975 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002976 if (mask)
2977 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2978 break;
2979 default:
2980 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002981 }
2982 /* skip the flush */
2983}
2984
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002985/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002986 * ixgbe_irq_enable - Enable default interrupt generation settings
2987 * @adapter: board private structure
Tony Nguyen5ba643c2017-12-04 11:28:30 -08002988 * @queues: enable irqs for queues
2989 * @flush: flush register write
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002990 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002991static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2992 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002993{
Don Skidmore9a900ec2015-06-09 17:15:01 -07002994 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002995 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002996
Alexander Duyck2c4af692011-07-15 07:29:55 +00002997 /* don't reenable LSC while waiting for link */
2998 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2999 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003000
Alexander Duyck2c4af692011-07-15 07:29:55 +00003001 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00003002 switch (adapter->hw.mac.type) {
3003 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003004 mask |= IXGBE_EIMS_GPI_SDP0(hw);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003005 break;
3006 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003007 case ixgbe_mac_X550:
3008 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003009 case ixgbe_mac_x550em_a:
Jacob Keller4f51bf72011-08-20 04:49:45 +00003010 mask |= IXGBE_EIMS_TS;
3011 break;
3012 default:
3013 break;
3014 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003015 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07003016 mask |= IXGBE_EIMS_GPI_SDP1(hw);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003017 switch (adapter->hw.mac.type) {
3018 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07003019 mask |= IXGBE_EIMS_GPI_SDP1(hw);
3020 mask |= IXGBE_EIMS_GPI_SDP2(hw);
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003021 /* fall through */
Don Skidmore858bc082011-08-04 09:28:30 +00003022 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003023 case ixgbe_mac_X550:
3024 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003025 case ixgbe_mac_x550em_a:
3026 if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
Mark Rustad2d40cd12016-04-01 12:18:35 -07003027 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
Mark Rustad49425df2016-04-01 12:18:09 -07003028 adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
Mark Rustadcbd45ec2015-08-08 16:17:51 -07003029 mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
Don Skidmore597f22d2015-06-09 16:52:02 -07003030 if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
3031 mask |= IXGBE_EICR_GPI_SDP0_X540;
Don Skidmore858bc082011-08-04 09:28:30 +00003032 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00003033 mask |= IXGBE_EIMS_MAILBOX;
3034 break;
3035 default:
3036 break;
3037 }
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003038
Alexander Duyck2c4af692011-07-15 07:29:55 +00003039 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
3040 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
3041 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003042
Alexander Duyck2c4af692011-07-15 07:29:55 +00003043 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
3044 if (queues)
3045 ixgbe_irq_enable_queues(adapter, ~0);
3046 if (flush)
3047 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07003048}
3049
Alexander Duyck2c4af692011-07-15 07:29:55 +00003050static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003051{
Alexander Duyck2c4af692011-07-15 07:29:55 +00003052 struct ixgbe_adapter *adapter = data;
3053 struct ixgbe_hw *hw = &adapter->hw;
3054 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003055
Alexander Duyck2c4af692011-07-15 07:29:55 +00003056 /*
3057 * Workaround for Silicon errata. Use clear-by-write instead
3058 * of clear-by-read. Reading with EICS will return the
3059 * interrupt causes without clearing, which later be done
3060 * with the write to EICR.
3061 */
3062 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
Jacob Kellerd87d8302013-03-02 07:51:42 +00003063
3064 /* The lower 16bits of the EICR register are for the queue interrupts
Joe Perchesdbedd442015-03-06 20:49:12 -08003065 * which should be masked here in order to not accidentally clear them if
Jacob Kellerd87d8302013-03-02 07:51:42 +00003066 * the bits are high when ixgbe_msix_other is called. There is a race
3067 * condition otherwise which results in possible performance loss
3068 * especially if the ixgbe_msix_other interrupt is triggering
3069 * consistently (as it would when PPS is turned on for the X540 device)
3070 */
3071 eicr &= 0xFFFF0000;
3072
Alexander Duyck2c4af692011-07-15 07:29:55 +00003073 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003074
Alexander Duyck2c4af692011-07-15 07:29:55 +00003075 if (eicr & IXGBE_EICR_LSC)
3076 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003077
Alexander Duyck2c4af692011-07-15 07:29:55 +00003078 if (eicr & IXGBE_EICR_MAILBOX)
3079 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003080
Alexander Duyck2c4af692011-07-15 07:29:55 +00003081 switch (hw->mac.type) {
3082 case ixgbe_mac_82599EB:
3083 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003084 case ixgbe_mac_X550:
3085 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003086 case ixgbe_mac_x550em_a:
Don Skidmore597f22d2015-06-09 16:52:02 -07003087 if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
3088 (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
3089 adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
3090 ixgbe_service_event_schedule(adapter);
3091 IXGBE_WRITE_REG(hw, IXGBE_EICR,
3092 IXGBE_EICR_GPI_SDP0_X540);
3093 }
Don Skidmored773ce22014-02-25 17:58:53 -08003094 if (eicr & IXGBE_EICR_ECC) {
3095 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003096 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003097 ixgbe_service_event_schedule(adapter);
3098 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3099 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00003100 /* Handle Flow Director Full threshold interrupt */
3101 if (eicr & IXGBE_EICR_FLOW_DIR) {
3102 int reinit_count = 0;
3103 int i;
3104 for (i = 0; i < adapter->num_tx_queues; i++) {
3105 struct ixgbe_ring *ring = adapter->tx_ring[i];
3106 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
3107 &ring->state))
3108 reinit_count++;
3109 }
3110 if (reinit_count) {
3111 /* no more flow director interrupts until after init */
3112 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
3113 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
3114 ixgbe_service_event_schedule(adapter);
3115 }
3116 }
3117 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00003118 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00003119 break;
3120 default:
3121 break;
Auke Kok9a799d72007-09-15 14:07:45 -07003122 }
3123
Alexander Duyck2c4af692011-07-15 07:29:55 +00003124 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003125
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003126 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003127 ixgbe_ptp_check_pps_event(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003128
Alexander Duyck2c4af692011-07-15 07:29:55 +00003129 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00003130 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00003131 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00003132
Alexander Duyck2c4af692011-07-15 07:29:55 +00003133 return IRQ_HANDLED;
3134}
3135
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003136static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07003137{
3138 struct ixgbe_q_vector *q_vector = data;
3139
Auke Kok9a799d72007-09-15 14:07:45 -07003140 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003141
3142 if (q_vector->rx.ring || q_vector->tx.ring)
Alexander Duyckef2662b2015-09-29 15:19:43 -07003143 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003144
3145 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003146}
3147
Auke Kok9a799d72007-09-15 14:07:45 -07003148/**
Alexander Duyckeb01b972012-02-08 07:51:27 +00003149 * ixgbe_poll - NAPI Rx polling callback
3150 * @napi: structure for representing this polling device
3151 * @budget: how many packets driver is allowed to clean
3152 *
3153 * This function is used for legacy and MSI, NAPI mode
3154 **/
Jeff Kirsher8af3c332012-02-18 07:08:14 +00003155int ixgbe_poll(struct napi_struct *napi, int budget)
Alexander Duyckeb01b972012-02-08 07:51:27 +00003156{
3157 struct ixgbe_q_vector *q_vector =
3158 container_of(napi, struct ixgbe_q_vector, napi);
3159 struct ixgbe_adapter *adapter = q_vector->adapter;
3160 struct ixgbe_ring *ring;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003161 int per_ring_budget, work_done = 0;
Alexander Duyckeb01b972012-02-08 07:51:27 +00003162 bool clean_complete = true;
3163
3164#ifdef CONFIG_IXGBE_DCA
3165 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
3166 ixgbe_update_dca(q_vector);
3167#endif
3168
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003169 ixgbe_for_each_ring(ring, q_vector->tx) {
3170 if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
3171 clean_complete = false;
3172 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003173
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08003174 /* Exit if we are called by netpoll */
3175 if (budget <= 0)
Eliezer Tamir5a85e732013-06-10 11:40:20 +03003176 return budget;
3177
Alexander Duyckeb01b972012-02-08 07:51:27 +00003178 /* attempt to distribute budget to each queue fairly, but don't allow
3179 * the budget to go below 1 because we'll exit polling */
3180 if (q_vector->rx.count > 1)
3181 per_ring_budget = max(budget/q_vector->rx.count, 1);
3182 else
3183 per_ring_budget = budget;
3184
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003185 ixgbe_for_each_ring(ring, q_vector->rx) {
3186 int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
3187 per_ring_budget);
3188
3189 work_done += cleaned;
Alexander Duyck8220bbc2016-03-07 09:30:09 -08003190 if (cleaned >= per_ring_budget)
3191 clean_complete = false;
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003192 }
Alexander Duyckeb01b972012-02-08 07:51:27 +00003193
3194 /* If all work not completed, return budget and keep polling */
3195 if (!clean_complete)
3196 return budget;
3197
3198 /* all work done, exit the polling mode */
Jesse Brandeburg32b3e082015-09-24 16:35:47 -07003199 napi_complete_done(napi, work_done);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003200 if (adapter->rx_itr_setting & 1)
3201 ixgbe_set_itr(q_vector);
3202 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003203 ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
Alexander Duyckeb01b972012-02-08 07:51:27 +00003204
Paolo Abeni4b732cd2016-06-15 15:37:59 +02003205 return min(work_done, budget - 1);
Alexander Duyckeb01b972012-02-08 07:51:27 +00003206}
3207
3208/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003209 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
3210 * @adapter: board private structure
3211 *
3212 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
3213 * interrupts from the kernel.
3214 **/
3215static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
3216{
3217 struct net_device *netdev = adapter->netdev;
Tony Nguyene61e4c82017-05-12 11:38:07 -07003218 unsigned int ri = 0, ti = 0;
Alexander Duyck207867f2011-07-15 03:05:37 +00003219 int vector, err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003220
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003221 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003222 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00003223 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08003224
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003225 if (q_vector->tx.ring && q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003226 snprintf(q_vector->name, sizeof(q_vector->name),
3227 "%s-TxRx-%u", netdev->name, ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003228 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003229 } else if (q_vector->rx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003230 snprintf(q_vector->name, sizeof(q_vector->name),
3231 "%s-rx-%u", netdev->name, ri++);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003232 } else if (q_vector->tx.ring) {
Tony Nguyene61e4c82017-05-12 11:38:07 -07003233 snprintf(q_vector->name, sizeof(q_vector->name),
3234 "%s-tx-%u", netdev->name, ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08003235 } else {
3236 /* skip this unused q_vector */
3237 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08003238 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003239 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
3240 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003241 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00003242 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00003243 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003244 goto free_queue_irqs;
3245 }
Alexander Duyck207867f2011-07-15 03:05:37 +00003246 /* If Flow Director is enabled, set interrupt affinity */
3247 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3248 /* assign the mask for this irq */
3249 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00003250 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00003251 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003252 }
3253
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003254 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00003255 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003256 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00003257 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003258 goto free_queue_irqs;
3259 }
3260
3261 return 0;
3262
3263free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00003264 while (vector) {
3265 vector--;
3266 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
3267 NULL);
3268 free_irq(adapter->msix_entries[vector].vector,
3269 adapter->q_vector[vector]);
3270 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003271 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
3272 pci_disable_msix(adapter->pdev);
3273 kfree(adapter->msix_entries);
3274 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003275 return err;
3276}
3277
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08003278/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003279 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07003280 * @irq: interrupt number
3281 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07003282 **/
3283static irqreturn_t ixgbe_intr(int irq, void *data)
3284{
Alexander Duycka65151ba22011-05-27 05:31:32 +00003285 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07003286 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003287 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003288 u32 eicr;
3289
Don Skidmore54037502009-02-21 15:42:56 -08003290 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00003291 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08003292 * before the read of EICR.
3293 */
3294 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
3295
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003296 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003297 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003298 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003299 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003300 /*
3301 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003302 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003303 * have disabled interrupts due to EIAM
3304 * finish the workaround of silicon errata on 82598. Unmask
3305 * the interrupt that we masked before the EICR read.
3306 */
3307 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3308 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003309 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07003310 }
Auke Kok9a799d72007-09-15 14:07:45 -07003311
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003312 if (eicr & IXGBE_EICR_LSC)
3313 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003314
Alexander Duyckbd508172010-11-16 19:27:03 -08003315 switch (hw->mac.type) {
3316 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003317 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00003318 /* Fall through */
3319 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003320 case ixgbe_mac_X550:
3321 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003322 case ixgbe_mac_x550em_a:
Don Skidmored773ce22014-02-25 17:58:53 -08003323 if (eicr & IXGBE_EICR_ECC) {
3324 e_info(link, "Received ECC Err, initiating reset\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07003325 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Don Skidmored773ce22014-02-25 17:58:53 -08003326 ixgbe_service_event_schedule(adapter);
3327 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
3328 }
Jacob Keller4f51bf72011-08-20 04:49:45 +00003329 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08003330 break;
3331 default:
3332 break;
3333 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003334
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003335 ixgbe_check_fan_failure(adapter, eicr);
Jacob Kellerdb0677f2012-08-24 07:46:54 +00003336 if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
Mark Rustada9763f32015-10-27 09:58:07 -07003337 ixgbe_ptp_check_pps_event(adapter);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003338
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00003339 /* would disable interrupts here but EIAM disabled it */
Alexander Duyckef2662b2015-09-29 15:19:43 -07003340 napi_schedule_irqoff(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07003341
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003342 /*
3343 * re-enable link(maybe) and non-queue interrupts, no flush.
3344 * ixgbe_poll will re-enable the queue interrupts
3345 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003346 if (!test_bit(__IXGBE_DOWN, &adapter->state))
3347 ixgbe_irq_enable(adapter, false, false);
3348
Auke Kok9a799d72007-09-15 14:07:45 -07003349 return IRQ_HANDLED;
3350}
3351
3352/**
3353 * ixgbe_request_irq - initialize interrupts
3354 * @adapter: board private structure
3355 *
3356 * Attempts to configure interrupts using the best available
3357 * capabilities of the hardware and kernel.
3358 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003359static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003360{
3361 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003362 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07003363
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003364 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003365 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003366 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08003367 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003368 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00003369 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08003370 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00003371 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003372
Alexander Duyckde88eee2012-02-08 07:49:59 +00003373 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00003374 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07003375
Auke Kok9a799d72007-09-15 14:07:45 -07003376 return err;
3377}
3378
3379static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
3380{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003381 int vector;
Auke Kok9a799d72007-09-15 14:07:45 -07003382
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003383 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duycka65151ba22011-05-27 05:31:32 +00003384 free_irq(adapter->pdev->irq, adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003385 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003386 }
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003387
Mark Rustad1fa71252016-09-28 15:36:38 -07003388 if (!adapter->msix_entries)
3389 return;
3390
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003391 for (vector = 0; vector < adapter->num_q_vectors; vector++) {
3392 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
3393 struct msix_entry *entry = &adapter->msix_entries[vector];
3394
3395 /* free only the irqs that were actually requested */
3396 if (!q_vector->rx.ring && !q_vector->tx.ring)
3397 continue;
3398
3399 /* clear the affinity_mask in the IRQ descriptor */
3400 irq_set_affinity_hint(entry->vector, NULL);
3401
3402 free_irq(entry->vector, q_vector);
3403 }
3404
Babu Moger90c6f872016-06-18 17:40:47 -07003405 free_irq(adapter->msix_entries[vector].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003406}
3407
3408/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003409 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
3410 * @adapter: board private structure
3411 **/
3412static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
3413{
Alexander Duyckbd508172010-11-16 19:27:03 -08003414 switch (adapter->hw.mac.type) {
3415 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003416 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003417 break;
3418 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003419 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00003420 case ixgbe_mac_X550:
3421 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07003422 case ixgbe_mac_x550em_a:
Nelson, Shannon835462f2009-04-27 22:42:54 +00003423 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
3424 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003425 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08003426 break;
3427 default:
3428 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003429 }
3430 IXGBE_WRITE_FLUSH(&adapter->hw);
3431 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00003432 int vector;
3433
3434 for (vector = 0; vector < adapter->num_q_vectors; vector++)
3435 synchronize_irq(adapter->msix_entries[vector].vector);
3436
3437 synchronize_irq(adapter->msix_entries[vector++].vector);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003438 } else {
3439 synchronize_irq(adapter->pdev->irq);
3440 }
3441}
3442
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00003443/**
Auke Kok9a799d72007-09-15 14:07:45 -07003444 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
Tony Nguyen5ba643c2017-12-04 11:28:30 -08003445 * @adapter: board private structure
Auke Kok9a799d72007-09-15 14:07:45 -07003446 *
3447 **/
3448static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
3449{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003450 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07003451
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00003452 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07003453
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003454 ixgbe_set_ivar(adapter, 0, 0, 0);
3455 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003456
Emil Tantilov396e7992010-07-01 20:05:12 +00003457 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07003458}
3459
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003460/**
3461 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
3462 * @adapter: board private structure
3463 * @ring: structure containing ring specific data
3464 *
3465 * Configure the Tx descriptor ring after a reset.
3466 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00003467void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
3468 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003469{
3470 struct ixgbe_hw *hw = &adapter->hw;
3471 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003472 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003473 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003474 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003475
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003476 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003477 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003478 IXGBE_WRITE_FLUSH(hw);
3479
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003480 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00003481 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003482 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
3483 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
3484 ring->count * sizeof(union ixgbe_adv_tx_desc));
3485 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
3486 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08003487 ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003488
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003489 /*
3490 * set WTHRESH to encourage burst writeback, it should not be set
Emil Tantilov67da0972013-01-25 06:19:20 +00003491 * higher than 1 when:
3492 * - ITR is 0 as it could cause false TX hangs
3493 * - ITR is set to > 100k int/sec and BQL is enabled
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003494 *
3495 * In order to avoid issues WTHRESH + PTHRESH should always be equal
3496 * to or less than the number of on chip descriptors, which is
3497 * currently 40.
3498 */
Emil Tantilov67da0972013-01-25 06:19:20 +00003499 if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003500 txdctl |= 1u << 16; /* WTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003501 else
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003502 txdctl |= 8u << 16; /* WTHRESH = 8 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003503
Alexander Duycke954b372012-02-08 07:49:38 +00003504 /*
3505 * Setting PTHRESH to 32 both improves performance
3506 * and avoids a TX hang with DFP enabled
3507 */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07003508 txdctl |= (1u << 8) | /* HTHRESH = 1 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00003509 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003510
3511 /* reinitialize flowdirector state */
Alexander Duyck39cb6812012-06-06 05:38:20 +00003512 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyckee9e0f02010-11-16 19:27:01 -08003513 ring->atr_sample_rate = adapter->atr_sample_rate;
3514 ring->atr_count = 0;
3515 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
3516 } else {
3517 ring->atr_sample_rate = 0;
3518 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003519
Alexander Duyckfd786b72013-01-12 06:33:31 +00003520 /* initialize XPS */
3521 if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
3522 struct ixgbe_q_vector *q_vector = ring->q_vector;
3523
3524 if (q_vector)
John Fastabend2a47fa42013-11-06 09:54:52 -08003525 netif_set_xps_queue(ring->netdev,
Alexander Duyckfd786b72013-01-12 06:33:31 +00003526 &q_vector->affinity_mask,
3527 ring->queue_index);
3528 }
3529
John Fastabendc84d3242010-11-16 19:27:12 -08003530 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
3531
Alexander Duyckffed21b2017-01-17 08:37:29 -08003532 /* reinitialize tx_buffer_info */
3533 memset(ring->tx_buffer_info, 0,
3534 sizeof(struct ixgbe_tx_buffer) * ring->count);
3535
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003536 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003537 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
3538
3539 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3540 if (hw->mac.type == ixgbe_mac_82598EB &&
3541 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3542 return;
3543
3544 /* poll to verify queue is enabled */
3545 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003546 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003547 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
3548 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
3549 if (!wait_loop)
Emil Tantilova55defd2016-07-29 10:30:06 -07003550 hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003551}
3552
Alexander Duyck120ff942010-08-19 13:34:50 +00003553static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
3554{
3555 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003556 u32 rttdcs, mtqc;
Alexander Duyck0efbf122017-11-22 10:57:11 -08003557 u8 tcs = adapter->hw_tcs;
Alexander Duyck120ff942010-08-19 13:34:50 +00003558
3559 if (hw->mac.type == ixgbe_mac_82598EB)
3560 return;
3561
3562 /* disable the arbiter while setting MTQC */
3563 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
3564 rttdcs |= IXGBE_RTTDCS_ARBDIS;
3565 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3566
3567 /* set transmit pool layout */
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003568 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3569 mtqc = IXGBE_MTQC_VT_ENA;
3570 if (tcs > 4)
3571 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3572 else if (tcs > 1)
3573 mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
Alexander Duycke24fcf22016-09-07 20:28:24 -07003574 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3575 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003576 mtqc |= IXGBE_MTQC_32VF;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003577 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003578 mtqc |= IXGBE_MTQC_64VF;
3579 } else {
3580 if (tcs > 4)
3581 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
3582 else if (tcs > 1)
3583 mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
3584 else
3585 mtqc = IXGBE_MTQC_64Q_1PB;
3586 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00003587
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003588 IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
John Fastabend8b1c0b22011-05-03 02:26:48 +00003589
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003590 /* Enable Security TX Buffer IFG for multiple pb */
3591 if (tcs) {
3592 u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
3593 sectx |= IXGBE_SECTX_DCB;
3594 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
Alexander Duyck120ff942010-08-19 13:34:50 +00003595 }
3596
3597 /* re-enable the arbiter */
3598 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
3599 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
3600}
3601
Auke Kok9a799d72007-09-15 14:07:45 -07003602/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07003603 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07003604 * @adapter: board private structure
3605 *
3606 * Configure the Tx unit of the MAC after a reset.
3607 **/
3608static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
3609{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003610 struct ixgbe_hw *hw = &adapter->hw;
3611 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003612 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003613
Alexander Duyck2f1860b2010-08-19 13:39:43 +00003614 ixgbe_setup_mtqc(adapter);
3615
3616 if (hw->mac.type != ixgbe_mac_82598EB) {
3617 /* DMATXCTL.EN must be before Tx queues are enabled */
3618 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
3619 dmatxctl |= IXGBE_DMATXCTL_TE;
3620 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
3621 }
3622
Auke Kok9a799d72007-09-15 14:07:45 -07003623 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00003624 for (i = 0; i < adapter->num_tx_queues; i++)
3625 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07003626 for (i = 0; i < adapter->num_xdp_queues; i++)
3627 ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07003628}
3629
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00003630static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
3631 struct ixgbe_ring *ring)
3632{
3633 struct ixgbe_hw *hw = &adapter->hw;
3634 u8 reg_idx = ring->reg_idx;
3635 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3636
3637 srrctl |= IXGBE_SRRCTL_DROP_EN;
3638
3639 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3640}
3641
3642static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
3643 struct ixgbe_ring *ring)
3644{
3645 struct ixgbe_hw *hw = &adapter->hw;
3646 u8 reg_idx = ring->reg_idx;
3647 u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
3648
3649 srrctl &= ~IXGBE_SRRCTL_DROP_EN;
3650
3651 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
3652}
3653
3654#ifdef CONFIG_IXGBE_DCB
3655void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3656#else
3657static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
3658#endif
3659{
3660 int i;
3661 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
3662
3663 if (adapter->ixgbe_ieee_pfc)
3664 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
3665
3666 /*
3667 * We should set the drop enable bit if:
3668 * SR-IOV is enabled
3669 * or
3670 * Number of Rx queues > 1 and flow control is disabled
3671 *
3672 * This allows us to avoid head of line blocking for security
3673 * and performance reasons.
3674 */
3675 if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
3676 !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
3677 for (i = 0; i < adapter->num_rx_queues; i++)
3678 ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
3679 } else {
3680 for (i = 0; i < adapter->num_rx_queues; i++)
3681 ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
3682 }
3683}
3684
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003685#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07003686
Yi Zoua6616b42009-08-06 13:05:23 +00003687static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00003688 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003689{
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003690 struct ixgbe_hw *hw = &adapter->hw;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003691 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003692 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003693
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003694 if (hw->mac.type == ixgbe_mac_82598EB) {
3695 u16 mask = adapter->ring_feature[RING_F_RSS].mask;
3696
3697 /*
3698 * if VMDq is not active we must program one srrctl register
3699 * per RSS queue since we have enabled RDRXCTL.MVMEN
3700 */
3701 reg_idx &= mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08003702 }
3703
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003704 /* configure header buffer length, needed for RSC */
3705 srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003706
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003707 /* configure the packet buffer length */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08003708 if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
3709 srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
3710 else
3711 srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003712
3713 /* configure descriptor type */
Alexander Duyckf8003262012-03-03 02:35:52 +00003714 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003715
Alexander Duyck45e9baa2012-05-05 05:30:59 +00003716 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003717}
3718
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003719/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003720 * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003721 * @adapter: device handle
3722 *
3723 * - 82598/82599/X540: 128
3724 * - X550(non-SRIOV mode): 512
3725 * - X550(SRIOV mode): 64
3726 */
Vlad Zolotarov7f276ef2015-03-30 21:18:58 +03003727u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003728{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003729 if (adapter->hw.mac.type < ixgbe_mac_X550)
3730 return 128;
3731 else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3732 return 64;
3733 else
3734 return 512;
3735}
3736
3737/**
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003738 * ixgbe_store_key - Write the RSS key to HW
3739 * @adapter: device handle
3740 *
3741 * Write the RSS key stored in adapter.rss_key to HW.
3742 */
3743void ixgbe_store_key(struct ixgbe_adapter *adapter)
3744{
3745 struct ixgbe_hw *hw = &adapter->hw;
3746 int i;
3747
3748 for (i = 0; i < 10; i++)
3749 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
3750}
3751
3752/**
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07003753 * ixgbe_init_rss_key - Initialize adapter RSS key
3754 * @adapter: device handle
3755 *
3756 * Allocates and initializes the RSS key if it is not allocated.
3757 **/
3758static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
3759{
3760 u32 *rss_key;
3761
3762 if (!adapter->rss_key) {
3763 rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
3764 if (unlikely(!rss_key))
3765 return -ENOMEM;
3766
3767 netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
3768 adapter->rss_key = rss_key;
3769 }
3770
3771 return 0;
3772}
3773
3774/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003775 * ixgbe_store_reta - Write the RETA table to HW
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003776 * @adapter: device handle
3777 *
3778 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3779 */
Tom Barbette1c7cf072015-06-26 15:40:18 +02003780void ixgbe_store_reta(struct ixgbe_adapter *adapter)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003781{
3782 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
Alexander Duyck05abb122010-08-19 13:35:41 +00003783 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmored1b849b2014-11-09 06:42:57 +00003784 u32 reta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003785 u32 indices_multi;
3786 u8 *indir_tbl = adapter->rss_indir_tbl;
John Fastabend86b4db32011-04-26 07:26:19 +00003787
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003788 /* Fill out the redirection table as follows:
3789 * - 82598: 8 bit wide entries containing pair of 4 bit RSS
3790 * indices.
3791 * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
3792 * - X550: 8 bit wide entries containing 6 bit RSS index
3793 */
3794 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3795 indices_multi = 0x11;
3796 else
3797 indices_multi = 0x1;
3798
3799 /* Write redirection table to HW */
3800 for (i = 0; i < reta_entries; i++) {
3801 reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
3802 if ((i & 3) == 3) {
3803 if (i < 128)
3804 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
3805 else
3806 IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
3807 reta);
3808 reta = 0;
3809 }
3810 }
3811}
3812
3813/**
Jean Sacrena897a2a2015-09-19 05:08:44 -06003814 * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003815 * @adapter: device handle
3816 *
3817 * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
3818 */
3819static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
3820{
3821 u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3822 struct ixgbe_hw *hw = &adapter->hw;
3823 u32 vfreta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003824
3825 /* Write redirection table to HW */
3826 for (i = 0; i < reta_entries; i++) {
Alexander Duyck2af62c52017-11-22 10:56:28 -08003827 u16 pool = adapter->num_rx_pools;
3828
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003829 vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
Alexander Duyck2af62c52017-11-22 10:56:28 -08003830 if ((i & 3) != 3)
3831 continue;
3832
3833 while (pool--)
3834 IXGBE_WRITE_REG(hw,
3835 IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)),
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003836 vfreta);
Alexander Duyck2af62c52017-11-22 10:56:28 -08003837 vfreta = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003838 }
3839}
3840
3841static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
3842{
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003843 u32 i, j;
3844 u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
3845 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
3846
Alexander Duycke24fcf22016-09-07 20:28:24 -07003847 /* Program table for at least 4 queues w/ SR-IOV so that VFs can
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003848 * make full use of any rings they may have. We will use the
3849 * PSRTYPE register to control how many rings we use within the PF.
3850 */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003851 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
3852 rss_i = 4;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003853
Alexander Duyck05abb122010-08-19 13:35:41 +00003854 /* Fill out hash function seeds */
Paolo Abenid3aa9c92016-12-15 15:20:34 +01003855 ixgbe_store_key(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003856
Alexander Duyck05abb122010-08-19 13:35:41 +00003857 /* Fill out redirection table */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003858 memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
3859
Don Skidmore0f9b2322014-11-18 09:35:08 +00003860 for (i = 0, j = 0; i < reta_entries; i++, j++) {
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003861 if (j == rss_i)
Alexander Duyck05abb122010-08-19 13:35:41 +00003862 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003863
3864 adapter->rss_indir_tbl[i] = j;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003865 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003866
3867 ixgbe_store_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003868}
3869
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003870static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
Don Skidmore0f9b2322014-11-18 09:35:08 +00003871{
3872 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003873 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003874 int i, j;
3875
3876 /* Fill out hash function seeds */
Alexander Duyck2af62c52017-11-22 10:56:28 -08003877 for (i = 0; i < 10; i++) {
3878 u16 pool = adapter->num_rx_pools;
3879
3880 while (pool--)
3881 IXGBE_WRITE_REG(hw,
3882 IXGBE_PFVFRSSRK(i, VMDQ_P(pool)),
3883 *(adapter->rss_key + i));
3884 }
Don Skidmore0f9b2322014-11-18 09:35:08 +00003885
3886 /* Fill out the redirection table */
3887 for (i = 0, j = 0; i < 64; i++, j++) {
3888 if (j == rss_i)
3889 j = 0;
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003890
3891 adapter->rss_indir_tbl[i] = j;
Alexander Duyck05abb122010-08-19 13:35:41 +00003892 }
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003893
3894 ixgbe_store_vfreta(adapter);
Don Skidmored1b849b2014-11-09 06:42:57 +00003895}
3896
3897static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
3898{
3899 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003900 u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
Don Skidmored1b849b2014-11-09 06:42:57 +00003901 u32 rxcsum;
Alexander Duyck05abb122010-08-19 13:35:41 +00003902
3903 /* Disable indicating checksum in descriptor, enables RSS hash */
3904 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
3905 rxcsum |= IXGBE_RXCSUM_PCSD;
3906 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
3907
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003908 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00003909 if (adapter->ring_feature[RING_F_RSS].mask)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003910 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003911 } else {
Alexander Duyck0efbf122017-11-22 10:57:11 -08003912 u8 tcs = adapter->hw_tcs;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003913
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003914 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3915 if (tcs > 4)
3916 mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
3917 else if (tcs > 1)
3918 mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
Alexander Duycke24fcf22016-09-07 20:28:24 -07003919 else if (adapter->ring_feature[RING_F_VMDQ].mask ==
3920 IXGBE_82599_VMDQ_4Q_MASK)
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003921 mrqc = IXGBE_MRQC_VMDQRSS32EN;
3922 else
3923 mrqc = IXGBE_MRQC_VMDQRSS64EN;
Emil Tantilove6b41c82017-04-25 11:31:06 -07003924
3925 /* Enable L3/L4 for Tx Switched packets */
3926 mrqc |= IXGBE_MRQC_L3L4TXSWEN;
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003927 } else {
3928 if (tcs > 4)
3929 mrqc = IXGBE_MRQC_RTRSS8TCEN;
3930 else if (tcs > 1)
John Fastabend8b1c0b22011-05-03 02:26:48 +00003931 mrqc = IXGBE_MRQC_RTRSS4TCEN;
3932 else
Alexander Duyck671c0ad2012-05-18 06:34:02 +00003933 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00003934 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003935 }
3936
Alexander Duyck05abb122010-08-19 13:35:41 +00003937 /* Perform hash on these packet types */
Don Skidmored1b849b2014-11-09 06:42:57 +00003938 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
3939 IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
3940 IXGBE_MRQC_RSS_FIELD_IPV6 |
3941 IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
Alexander Duyck05abb122010-08-19 13:35:41 +00003942
Alexander Duyckef6afc02012-02-08 07:51:53 +00003943 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003944 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003945 if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
Don Skidmored1b849b2014-11-09 06:42:57 +00003946 rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
Alexander Duyckef6afc02012-02-08 07:51:53 +00003947
Don Skidmore0f9b2322014-11-18 09:35:08 +00003948 if ((hw->mac.type >= ixgbe_mac_X550) &&
3949 (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
Alexander Duyck2af62c52017-11-22 10:56:28 -08003950 u16 pool = adapter->num_rx_pools;
Don Skidmore0f9b2322014-11-18 09:35:08 +00003951
3952 /* Enable VF RSS mode */
3953 mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
3954 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3955
3956 /* Setup RSS through the VF registers */
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003957 ixgbe_setup_vfreta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003958 vfmrqc = IXGBE_MRQC_RSSEN;
3959 vfmrqc |= rss_field;
Alexander Duyck2af62c52017-11-22 10:56:28 -08003960
3961 while (pool--)
3962 IXGBE_WRITE_REG(hw,
3963 IXGBE_PFVFMRQC(VMDQ_P(pool)),
3964 vfmrqc);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003965 } else {
Vlad Zolotarovdfaf8912015-03-30 21:18:57 +03003966 ixgbe_setup_reta(adapter);
Don Skidmore0f9b2322014-11-18 09:35:08 +00003967 mrqc |= rss_field;
3968 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
3969 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003970}
3971
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003972/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003973 * ixgbe_configure_rscctl - enable RSC for the indicated ring
Tony Nguyen5ba643c2017-12-04 11:28:30 -08003974 * @adapter: address of board private structure
3975 * @ring: structure containing ring specific data
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003976 **/
Don Skidmore082757a2011-07-21 05:55:00 +00003977static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003978 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003979{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003980 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003981 u32 rscctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003982 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003983
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003984 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003985 return;
3986
Alexander Duyck73670962010-08-19 13:38:34 +00003987 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003988 rscctrl |= IXGBE_RSCCTL_RSCEN;
3989 /*
3990 * we must limit the number of descriptors so that the
3991 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00003992 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003993 */
Alexander Duyckf8003262012-03-03 02:35:52 +00003994 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck73670962010-08-19 13:38:34 +00003995 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003996}
3997
Alexander Duyck9e10e042010-08-19 13:40:06 +00003998#define IXGBE_MAX_RX_DESC_POLL 10
3999static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
4000 struct ixgbe_ring *ring)
4001{
4002 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004003 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4004 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004005 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004006
Mark Rustadb0483c82014-01-14 18:53:17 -08004007 if (ixgbe_removed(hw->hw_addr))
4008 return;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004009 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
4010 if (hw->mac.type == ixgbe_mac_82598EB &&
4011 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4012 return;
4013
4014 do {
Don Skidmore032b4322011-03-18 09:32:53 +00004015 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004016 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4017 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
4018
4019 if (!wait_loop) {
4020 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
4021 "the polling period\n", reg_idx);
4022 }
4023}
4024
Yi Zou2d39d572011-01-06 14:29:56 +00004025void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
4026 struct ixgbe_ring *ring)
4027{
4028 struct ixgbe_hw *hw = &adapter->hw;
4029 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
4030 u32 rxdctl;
4031 u8 reg_idx = ring->reg_idx;
4032
Mark Rustadb0483c82014-01-14 18:53:17 -08004033 if (ixgbe_removed(hw->hw_addr))
4034 return;
Yi Zou2d39d572011-01-06 14:29:56 +00004035 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4036 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
4037
4038 /* write value back with RXDCTL.ENABLE bit cleared */
4039 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4040
4041 if (hw->mac.type == ixgbe_mac_82598EB &&
4042 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
4043 return;
4044
4045 /* the hardware may take up to 100us to really disable the rx queue */
4046 do {
4047 udelay(10);
4048 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
4049 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
4050
4051 if (!wait_loop) {
4052 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
4053 "the polling period\n", reg_idx);
4054 }
4055}
4056
Alexander Duyck84418e32010-08-19 13:40:54 +00004057void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
4058 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00004059{
4060 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004061 union ixgbe_adv_rx_desc *rx_desc;
Alexander Duyckacd37172010-08-19 13:36:05 +00004062 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00004063 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004064 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00004065
Alexander Duyck9e10e042010-08-19 13:40:06 +00004066 /* disable queue to avoid issues while updating state */
4067 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00004068 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004069
Alexander Duyckacd37172010-08-19 13:36:05 +00004070 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
4071 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
4072 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
4073 ring->count * sizeof(union ixgbe_adv_rx_desc));
Neerav Parikh8b754512015-12-08 22:13:58 -08004074 /* Force flushing of IXGBE_RDLEN to prevent MDD */
4075 IXGBE_WRITE_FLUSH(hw);
4076
Alexander Duyckacd37172010-08-19 13:36:05 +00004077 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
4078 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Mark Rustad2a1a0912014-01-14 18:53:15 -08004079 ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004080
4081 ixgbe_configure_srrctl(adapter, ring);
4082 ixgbe_configure_rscctl(adapter, ring);
4083
4084 if (hw->mac.type == ixgbe_mac_82598EB) {
4085 /*
4086 * enable cache line friendly hardware writes:
4087 * PTHRESH=32 descriptors (half the internal cache),
4088 * this also removes ugly rx_no_buffer_count increment
4089 * HTHRESH=4 descriptors (to minimize latency on fetch)
4090 * WTHRESH=8 burst writeback up to two cache lines
4091 */
4092 rxdctl &= ~0x3FFFFF;
4093 rxdctl |= 0x080420;
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004094#if (PAGE_SIZE < 8192)
Emil Tantilov2bafa8f2018-01-12 14:02:56 -08004095 /* RXDCTL.RLPML does not work on 82599 */
4096 } else if (hw->mac.type != ixgbe_mac_82599EB) {
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004097 rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
4098 IXGBE_RXDCTL_RLPML_EN);
4099
Emil Tantilov2bafa8f2018-01-12 14:02:56 -08004100 /* Limit the maximum frame size so we don't overrun the skb.
4101 * This can happen in SRIOV mode when the MTU of the VF is
4102 * higher than the MTU of the PF.
4103 */
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004104 if (ring_uses_build_skb(ring) &&
4105 !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
Alexander Duyck541ea692017-03-02 15:01:05 -08004106 rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004107 IXGBE_RXDCTL_RLPML_EN;
4108#endif
Alexander Duyck9e10e042010-08-19 13:40:06 +00004109 }
4110
Alexander Duyckffed21b2017-01-17 08:37:29 -08004111 /* initialize rx_buffer_info */
4112 memset(ring->rx_buffer_info, 0,
4113 sizeof(struct ixgbe_rx_buffer) * ring->count);
4114
Alexander Duyckc3630cc2017-01-17 08:36:28 -08004115 /* initialize Rx descriptor 0 */
4116 rx_desc = IXGBE_RX_DESC(ring, 0);
4117 rx_desc->wb.upper.length = 0;
4118
Alexander Duyck9e10e042010-08-19 13:40:06 +00004119 /* enable receive descriptor ring */
4120 rxdctl |= IXGBE_RXDCTL_ENABLE;
4121 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
4122
4123 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00004124 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00004125}
4126
Alexander Duyck48654522010-08-19 13:36:27 +00004127static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
4128{
4129 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004130 int rss_i = adapter->ring_feature[RING_F_RSS].indices;
Alexander Duyck2af62c52017-11-22 10:56:28 -08004131 u16 pool = adapter->num_rx_pools;
Alexander Duyck48654522010-08-19 13:36:27 +00004132
4133 /* PSRTYPE must be initialized in non 82598 adapters */
4134 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004135 IXGBE_PSRTYPE_UDPHDR |
4136 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00004137 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00004138 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00004139
4140 if (hw->mac.type == ixgbe_mac_82598EB)
4141 return;
4142
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004143 if (rss_i > 3)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004144 psrtype |= 2u << 29;
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00004145 else if (rss_i > 1)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004146 psrtype |= 1u << 29;
Alexander Duyck48654522010-08-19 13:36:27 +00004147
Alexander Duyck2af62c52017-11-22 10:56:28 -08004148 while (pool--)
John Fastabend2a47fa42013-11-06 09:54:52 -08004149 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
Alexander Duyck48654522010-08-19 13:36:27 +00004150}
4151
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004152static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
4153{
4154 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck81d4e912018-04-03 17:16:09 -04004155 u16 pool = adapter->num_rx_pools;
4156 u32 reg_offset, vf_shift, vmolr;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004157 u32 gcr_ext, vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00004158 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004159
4160 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
4161 return;
4162
4163 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
Alexander Duyck435b19f2012-05-18 06:34:08 +00004164 vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
4165 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004166 vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
Alexander Duyck435b19f2012-05-18 06:34:08 +00004167 vmdctl |= IXGBE_VT_CTL_REPLEN;
4168 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004169
Alexander Duyck81d4e912018-04-03 17:16:09 -04004170 /* accept untagged packets until a vlan tag is
4171 * specifically set for the VMDQ queue/pool
4172 */
4173 vmolr = IXGBE_VMOLR_AUPE;
4174 while (pool--)
4175 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(pool)), vmolr);
4176
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004177 vf_shift = VMDQ_P(0) % 32;
4178 reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004179
4180 /* Enable only the PF's pool for Tx/Rx */
Emil Tantilov11f2b492016-05-04 15:01:27 -07004181 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004182 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
Emil Tantilov11f2b492016-05-04 15:01:27 -07004183 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
Alexander Duyck435b19f2012-05-18 06:34:08 +00004184 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07004185 if (adapter->bridge_mode == BRIDGE_MODE_VEB)
Greg Rose9b735982012-11-08 02:41:35 +00004186 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004187
4188 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004189 hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004190
Alexander Duyck16369562015-11-02 17:10:13 -08004191 /* clear VLAN promisc flag so VFTA will be updated if necessary */
4192 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4193
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004194 /*
4195 * Set up VF register offsets for selected VT Mode,
4196 * i.e. 32 or 64 VFs for SR-IOV
4197 */
Alexander Duyck73079ea2012-07-14 06:48:49 +00004198 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
4199 case IXGBE_82599_VMDQ_8Q_MASK:
4200 gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
4201 break;
4202 case IXGBE_82599_VMDQ_4Q_MASK:
4203 gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
4204 break;
4205 default:
4206 gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
4207 break;
4208 }
4209
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004210 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4211
Greg Rosede4c7f62011-09-29 05:57:33 +00004212 for (i = 0; i < adapter->num_vfs; i++) {
Emil Tantilov77f192a2016-03-18 16:11:14 -07004213 /* configure spoof checking */
4214 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
4215 adapter->vfinfo[i].spoofchk_enabled);
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +03004216
4217 /* Enable/Disable RSS query feature */
4218 ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
4219 adapter->vfinfo[i].rss_query_enabled);
Greg Rosede4c7f62011-09-29 05:57:33 +00004220 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004221}
4222
Alexander Duyck477de6e2010-08-19 13:38:11 +00004223static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004224{
Auke Kok9a799d72007-09-15 14:07:45 -07004225 struct ixgbe_hw *hw = &adapter->hw;
4226 struct net_device *netdev = adapter->netdev;
4227 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004228 struct ixgbe_ring *rx_ring;
4229 int i;
4230 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00004231
Alexander Duyck477de6e2010-08-19 13:38:11 +00004232#ifdef IXGBE_FCOE
4233 /* adjust max frame to be able to do baby jumbo for FCoE */
4234 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
4235 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
4236 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
4237
4238#endif /* IXGBE_FCOE */
Alexander Duyck872844d2012-08-15 02:10:43 +00004239
4240 /* adjust max frame to be at least the size of a standard frame */
4241 if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
4242 max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
4243
Alexander Duyck477de6e2010-08-19 13:38:11 +00004244 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
4245 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
4246 mhadd &= ~IXGBE_MHADD_MFS_MASK;
4247 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
4248
4249 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07004250 }
4251
Auke Kok9a799d72007-09-15 14:07:45 -07004252 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004253 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
4254 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07004255 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4256
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004257 /*
4258 * Setup the HW Rx Head and Tail Descriptor Pointers and
4259 * the Base and Length of the Rx Descriptor Ring
4260 */
Auke Kok9a799d72007-09-15 14:07:45 -07004261 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004262 rx_ring = adapter->rx_ring[i];
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004263
4264 clear_ring_rsc_enabled(rx_ring);
4265 clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004266 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004267
Alexander Duyck7d637bc2010-11-16 19:26:56 -08004268 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4269 set_ring_rsc_enabled(rx_ring);
Alexander Duyck4f4542b2017-01-17 08:36:14 -08004270
4271 if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
4272 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004273
Alexander Duyck6f429222017-01-17 08:37:13 -08004274 clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004275 if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
4276 continue;
4277
4278 set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
4279
4280#if (PAGE_SIZE < 8192)
4281 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
4282 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4283
Alexander Duyck541ea692017-03-02 15:01:05 -08004284 if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
4285 (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
Alexander Duyck2de6aa32017-01-17 08:36:54 -08004286 set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
4287#endif
Alexander Duyck477de6e2010-08-19 13:38:11 +00004288 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00004289}
4290
Alexander Duyck73670962010-08-19 13:38:34 +00004291static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
4292{
4293 struct ixgbe_hw *hw = &adapter->hw;
4294 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
4295
4296 switch (hw->mac.type) {
4297 case ixgbe_mac_82598EB:
4298 /*
4299 * For VMDq support of different descriptor types or
4300 * buffer sizes through the use of multiple SRRCTL
4301 * registers, RDRXCTL.MVMEN must be set to 1
4302 *
4303 * also, the manual doesn't mention it clearly but DCA hints
4304 * will only use queue 0's tags unless this bit is set. Side
4305 * effects of setting this bit are only that SRRCTL must be
4306 * fully programmed [0..15]
4307 */
4308 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
4309 break;
Mark Rustad052a1a72015-08-08 16:19:04 -07004310 case ixgbe_mac_X550:
4311 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004312 case ixgbe_mac_x550em_a:
Mark Rustadf961dda2015-08-08 16:19:09 -07004313 if (adapter->num_vfs)
4314 rdrxctl |= IXGBE_RDRXCTL_PSP;
Tony Nguyen93df9462017-05-31 04:43:47 -07004315 /* fall through */
Alexander Duyck73670962010-08-19 13:38:34 +00004316 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004317 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00004318 /* Disable RSC for ACK packets */
4319 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
4320 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
4321 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
4322 /* hardware requires some bits to be set by default */
4323 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
4324 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
4325 break;
4326 default:
4327 /* We should do nothing since we don't know this hardware */
4328 return;
4329 }
4330
4331 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
4332}
4333
Alexander Duyck477de6e2010-08-19 13:38:11 +00004334/**
4335 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
4336 * @adapter: board private structure
4337 *
4338 * Configure the Rx unit of the MAC after a reset.
4339 **/
4340static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
4341{
4342 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004343 int i;
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004344 u32 rxctrl, rfctl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00004345
4346 /* disable receives while setting up the descriptors */
Don Skidmore1f9ac572015-03-13 13:54:30 -07004347 hw->mac.ops.disable_rx(hw);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004348
4349 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00004350 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00004351
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004352 /* RSC Setup */
4353 rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
4354 rfctl &= ~IXGBE_RFCTL_RSC_DIS;
4355 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
4356 rfctl |= IXGBE_RFCTL_RSC_DIS;
Emil Tantilova21d0822016-08-10 11:19:23 -07004357
4358 /* disable NFS filtering */
4359 rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
Jacob Keller6dcc28b2013-07-17 02:53:23 +00004360 IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
4361
Alexander Duyck9e10e042010-08-19 13:40:06 +00004362 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004363 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00004364
Alexander Duyck477de6e2010-08-19 13:38:11 +00004365 /* set_rx_buffer_len must be called before ring initialization */
4366 ixgbe_set_rx_buffer_len(adapter);
4367
4368 /*
4369 * Setup the HW Rx Head and Tail Descriptor Pointers and
4370 * the Base and Length of the Rx Descriptor Ring
4371 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00004372 for (i = 0; i < adapter->num_rx_queues; i++)
4373 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07004374
Don Skidmore1f9ac572015-03-13 13:54:30 -07004375 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
Alexander Duyck9e10e042010-08-19 13:40:06 +00004376 /* disable drop enable for 82598 parts */
4377 if (hw->mac.type == ixgbe_mac_82598EB)
4378 rxctrl |= IXGBE_RXCTRL_DMBYPS;
4379
4380 /* enable all receives */
4381 rxctrl |= IXGBE_RXCTRL_RXEN;
4382 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07004383}
4384
Patrick McHardy80d5c362013-04-19 02:04:28 +00004385static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
4386 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004387{
4388 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004389 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004390
4391 /* add VID to filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004392 if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4393 hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
4394
Jesse Grossf62bbb52010-10-20 13:56:10 +00004395 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004396
4397 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004398}
4399
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004400static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
4401{
4402 u32 vlvf;
4403 int idx;
4404
4405 /* short cut the special case */
4406 if (vlan == 0)
4407 return 0;
4408
4409 /* Search for the vlan id in the VLVF entries */
4410 for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
4411 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
4412 if ((vlvf & VLAN_VID_MASK) == vlan)
4413 break;
4414 }
4415
4416 return idx;
4417}
4418
4419void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
4420{
4421 struct ixgbe_hw *hw = &adapter->hw;
4422 u32 bits, word;
4423 int idx;
4424
4425 idx = ixgbe_find_vlvf_entry(hw, vid);
4426 if (!idx)
4427 return;
4428
4429 /* See if any other pools are set for this VLAN filter
4430 * entry other than the PF.
4431 */
4432 word = idx * 2 + (VMDQ_P(0) / 32);
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004433 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004434 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4435
4436 /* Disable the filter so this falls into the default pool. */
4437 if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
4438 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4439 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
4440 IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
4441 }
4442}
4443
Patrick McHardy80d5c362013-04-19 02:04:28 +00004444static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
4445 __be16 proto, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07004446{
4447 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004448 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004449
Auke Kok9a799d72007-09-15 14:07:45 -07004450 /* remove VID from filter table */
Alexander Duyck18be4fc2016-01-06 22:48:44 -08004451 if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
Alexander Duycke1d0a2a2015-11-02 17:10:19 -08004452 hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
4453
Jesse Grossf62bbb52010-10-20 13:56:10 +00004454 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05004455
4456 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004457}
4458
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004459/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004460 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
4461 * @adapter: driver data
4462 */
4463static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
4464{
4465 struct ixgbe_hw *hw = &adapter->hw;
4466 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004467 int i, j;
4468
4469 switch (hw->mac.type) {
4470 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004471 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4472 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004473 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4474 break;
4475 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004476 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004477 case ixgbe_mac_X550:
4478 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004479 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004480 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004481 struct ixgbe_ring *ring = adapter->rx_ring[i];
4482
Alexander Duyck68ae7422017-11-22 10:56:52 -08004483 if (!netif_is_ixgbe(ring->netdev))
John Fastabend2a47fa42013-11-06 09:54:52 -08004484 continue;
Alexander Duyck68ae7422017-11-22 10:56:52 -08004485
John Fastabend2a47fa42013-11-06 09:54:52 -08004486 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004487 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4488 vlnctrl &= ~IXGBE_RXDCTL_VME;
4489 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4490 }
4491 break;
4492 default:
4493 break;
4494 }
4495}
4496
4497/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00004498 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004499 * @adapter: driver data
4500 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00004501static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004502{
4503 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00004504 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004505 int i, j;
4506
4507 switch (hw->mac.type) {
4508 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00004509 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4510 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004511 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4512 break;
4513 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004514 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00004515 case ixgbe_mac_X550:
4516 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07004517 case ixgbe_mac_x550em_a:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004518 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend2a47fa42013-11-06 09:54:52 -08004519 struct ixgbe_ring *ring = adapter->rx_ring[i];
4520
Alexander Duyck68ae7422017-11-22 10:56:52 -08004521 if (!netif_is_ixgbe(ring->netdev))
John Fastabend2a47fa42013-11-06 09:54:52 -08004522 continue;
Alexander Duyck68ae7422017-11-22 10:56:52 -08004523
John Fastabend2a47fa42013-11-06 09:54:52 -08004524 j = ring->reg_idx;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07004525 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
4526 vlnctrl |= IXGBE_RXDCTL_VME;
4527 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
4528 }
4529 break;
4530 default:
4531 break;
4532 }
4533}
4534
Alexander Duyck16369562015-11-02 17:10:13 -08004535static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
4536{
4537 struct ixgbe_hw *hw = &adapter->hw;
4538 u32 vlnctrl, i;
4539
Alexander Duyckf60439b2016-08-11 14:51:56 -07004540 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4541
Emil Tantilov691e4122016-08-22 16:17:46 -07004542 if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
4543 /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
4544 vlnctrl |= IXGBE_VLNCTRL_VFE;
4545 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4546 } else {
Alexander Duyckf60439b2016-08-11 14:51:56 -07004547 vlnctrl &= ~IXGBE_VLNCTRL_VFE;
Alexander Duyck16369562015-11-02 17:10:13 -08004548 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4549 return;
4550 }
4551
Emil Tantilov691e4122016-08-22 16:17:46 -07004552 /* Nothing to do for 82598 */
4553 if (hw->mac.type == ixgbe_mac_82598EB)
4554 return;
4555
Alexander Duyck16369562015-11-02 17:10:13 -08004556 /* We are already in VLAN promisc, nothing to do */
4557 if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
4558 return;
4559
4560 /* Set flag so we don't redo unnecessary work */
4561 adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
4562
4563 /* Add PF to all active pools */
4564 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4565 u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
4566 u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
4567
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004568 vlvfb |= BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004569 IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
4570 }
4571
4572 /* Set all bits in the VLAN filter table array */
4573 for (i = hw->mac.vft_size; i--;)
4574 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
4575}
4576
4577#define VFTA_BLOCK_SIZE 8
4578static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
4579{
4580 struct ixgbe_hw *hw = &adapter->hw;
4581 u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
4582 u32 vid_start = vfta_offset * 32;
4583 u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
4584 u32 i, vid, word, bits;
4585
4586 for (i = IXGBE_VLVF_ENTRIES; --i;) {
4587 u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
4588
4589 /* pull VLAN ID from VLVF */
4590 vid = vlvf & VLAN_VID_MASK;
4591
4592 /* only concern outselves with a certain range */
4593 if (vid < vid_start || vid >= vid_end)
4594 continue;
4595
4596 if (vlvf) {
4597 /* record VLAN ID in VFTA */
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004598 vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004599
4600 /* if PF is part of this then continue */
4601 if (test_bit(vid, adapter->active_vlans))
4602 continue;
4603 }
4604
4605 /* remove PF from the pool */
4606 word = i * 2 + VMDQ_P(0) / 32;
Jacob Kellerb4f47a42016-04-13 16:08:22 -07004607 bits = ~BIT(VMDQ_P(0) % 32);
Alexander Duyck16369562015-11-02 17:10:13 -08004608 bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
4609 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
4610 }
4611
4612 /* extract values from active_vlans and write back to VFTA */
4613 for (i = VFTA_BLOCK_SIZE; i--;) {
4614 vid = (vfta_offset + i) * 32;
4615 word = vid / BITS_PER_LONG;
4616 bits = vid % BITS_PER_LONG;
4617
4618 vfta[i] |= adapter->active_vlans[word] >> bits;
4619
4620 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
4621 }
4622}
4623
4624static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
4625{
4626 struct ixgbe_hw *hw = &adapter->hw;
4627 u32 vlnctrl, i;
4628
Alexander Duyckf60439b2016-08-11 14:51:56 -07004629 /* Set VLAN filtering to enabled */
4630 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
4631 vlnctrl |= IXGBE_VLNCTRL_VFE;
4632 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
4633
Emil Tantilov691e4122016-08-22 16:17:46 -07004634 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
4635 hw->mac.type == ixgbe_mac_82598EB)
Alexander Duyck16369562015-11-02 17:10:13 -08004636 return;
Alexander Duyck16369562015-11-02 17:10:13 -08004637
4638 /* We are not in VLAN promisc, nothing to do */
4639 if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
4640 return;
4641
4642 /* Set flag so we don't redo unnecessary work */
4643 adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
4644
4645 for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
4646 ixgbe_scrub_vfta(adapter, i);
4647}
4648
Auke Kok9a799d72007-09-15 14:07:45 -07004649static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
4650{
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004651 u16 vid = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07004652
Patrick McHardy80d5c362013-04-19 02:04:28 +00004653 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004654
Alexander Duyck06bb1c32016-01-06 22:48:50 -08004655 for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
Patrick McHardy80d5c362013-04-19 02:04:28 +00004656 ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
Auke Kok9a799d72007-09-15 14:07:45 -07004657}
4658
4659/**
Jacob Kellerb335e752014-03-25 07:45:27 +00004660 * ixgbe_write_mc_addr_list - write multicast addresses to MTA
4661 * @netdev: network interface device structure
4662 *
4663 * Writes multicast address list to the MTA hash table.
4664 * Returns: -ENOMEM on failure
4665 * 0 on no addresses written
4666 * X on writing X addresses to MTA
4667 **/
4668static int ixgbe_write_mc_addr_list(struct net_device *netdev)
4669{
4670 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4671 struct ixgbe_hw *hw = &adapter->hw;
4672
4673 if (!netif_running(netdev))
4674 return 0;
4675
4676 if (hw->mac.ops.update_mc_addr_list)
4677 hw->mac.ops.update_mc_addr_list(hw, netdev);
4678 else
4679 return -ENOMEM;
4680
4681#ifdef CONFIG_PCI_IOV
Jacob Keller5d7daa32014-03-29 06:51:25 +00004682 ixgbe_restore_vf_multicasts(adapter);
Jacob Kellerb335e752014-03-25 07:45:27 +00004683#endif
4684
4685 return netdev_mc_count(netdev);
4686}
4687
Jacob Keller5d7daa32014-03-29 06:51:25 +00004688#ifdef CONFIG_PCI_IOV
4689void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
4690{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004691 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004692 struct ixgbe_hw *hw = &adapter->hw;
4693 int i;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004694
4695 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4696 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4697
4698 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4699 hw->mac.ops.set_rar(hw, i,
4700 mac_table->addr,
4701 mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004702 IXGBE_RAH_AV);
4703 else
4704 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004705 }
4706}
Jacob Keller5d7daa32014-03-29 06:51:25 +00004707
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004708#endif
Jacob Keller5d7daa32014-03-29 06:51:25 +00004709static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
4710{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004711 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004712 struct ixgbe_hw *hw = &adapter->hw;
4713 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004714
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004715 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4716 if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
4717 continue;
4718
4719 mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
4720
4721 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
4722 hw->mac.ops.set_rar(hw, i,
4723 mac_table->addr,
4724 mac_table->pool,
4725 IXGBE_RAH_AV);
4726 else
4727 hw->mac.ops.clear_rar(hw, i);
Jacob Keller5d7daa32014-03-29 06:51:25 +00004728 }
4729}
4730
4731static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
4732{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004733 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004734 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004735 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004736
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004737 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4738 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4739 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004740 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004741
Jacob Keller5d7daa32014-03-29 06:51:25 +00004742 ixgbe_sync_mac_table(adapter);
4743}
4744
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004745static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004746{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004747 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004748 struct ixgbe_hw *hw = &adapter->hw;
4749 int i, count = 0;
4750
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004751 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4752 /* do not count default RAR as available */
4753 if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
4754 continue;
4755
4756 /* only count unused and addresses that belong to us */
4757 if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
4758 if (mac_table->pool != pool)
4759 continue;
4760 }
4761
4762 count++;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004763 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004764
Jacob Keller5d7daa32014-03-29 06:51:25 +00004765 return count;
4766}
4767
4768/* this function destroys the first RAR entry */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004769static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004770{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004771 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004772 struct ixgbe_hw *hw = &adapter->hw;
4773
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004774 memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
4775 mac_table->pool = VMDQ_P(0);
4776
4777 mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
4778
4779 hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
Jacob Keller5d7daa32014-03-29 06:51:25 +00004780 IXGBE_RAH_AV);
4781}
4782
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004783int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
4784 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004785{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004786 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004787 struct ixgbe_hw *hw = &adapter->hw;
4788 int i;
4789
4790 if (is_zero_ether_addr(addr))
4791 return -EINVAL;
4792
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004793 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4794 if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004795 continue;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004796
4797 ether_addr_copy(mac_table->addr, addr);
4798 mac_table->pool = pool;
4799
4800 mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
4801 IXGBE_MAC_STATE_IN_USE;
4802
Jacob Keller5d7daa32014-03-29 06:51:25 +00004803 ixgbe_sync_mac_table(adapter);
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004804
Jacob Keller5d7daa32014-03-29 06:51:25 +00004805 return i;
4806 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004807
Jacob Keller5d7daa32014-03-29 06:51:25 +00004808 return -ENOMEM;
4809}
4810
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004811int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
4812 const u8 *addr, u16 pool)
Jacob Keller5d7daa32014-03-29 06:51:25 +00004813{
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004814 struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
Jacob Keller5d7daa32014-03-29 06:51:25 +00004815 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004816 int i;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004817
4818 if (is_zero_ether_addr(addr))
4819 return -EINVAL;
4820
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004821 /* search table for addr, if found clear IN_USE flag and sync */
4822 for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
4823 /* we can only delete an entry if it is in use */
4824 if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
4825 continue;
4826 /* we only care about entries that belong to the given pool */
4827 if (mac_table->pool != pool)
4828 continue;
4829 /* we only care about a specific MAC address */
4830 if (!ether_addr_equal(addr, mac_table->addr))
4831 continue;
4832
4833 mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
4834 mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
4835
4836 ixgbe_sync_mac_table(adapter);
4837
4838 return 0;
Jacob Keller5d7daa32014-03-29 06:51:25 +00004839 }
Alexander Duyckc9f53e62015-10-22 16:26:30 -07004840
Jacob Keller5d7daa32014-03-29 06:51:25 +00004841 return -ENOMEM;
4842}
Tony Nguyen5ba643c2017-12-04 11:28:30 -08004843
Alexander Duyck0f079d22015-10-22 16:26:36 -07004844static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
4845{
4846 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4847 int ret;
4848
4849 ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
4850
4851 return min_t(int, ret, 0);
4852}
4853
4854static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
4855{
4856 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4857
4858 ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
4859
4860 return 0;
4861}
4862
Alexander Duyck28500622010-06-15 09:25:48 +00004863/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07004864 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07004865 * @netdev: network interface device structure
4866 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07004867 * The set_rx_method entry point is called whenever the unicast/multicast
4868 * address list or the network interface flags are updated. This routine is
4869 * responsible for configuring the hardware for proper unicast, multicast and
4870 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07004871 **/
Greg Rose7f870472010-01-09 02:25:29 +00004872void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07004873{
4874 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4875 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00004876 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004877 netdev_features_t features = netdev->features;
Alexander Duyck28500622010-06-15 09:25:48 +00004878 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07004879
4880 /* Check for Promiscuous and All Multicast modes */
Auke Kok9a799d72007-09-15 14:07:45 -07004881 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
4882
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004883 /* set all bits that we expect to always be set */
Ben Greear3f2d1c02012-03-08 08:28:41 +00004884 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
Alexander Duyckf5dc4422010-08-19 13:36:49 +00004885 fctrl |= IXGBE_FCTRL_BAM;
4886 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
4887 fctrl |= IXGBE_FCTRL_PMCF;
4888
Alexander Duyck28500622010-06-15 09:25:48 +00004889 /* clear the bits we are changing the status of */
4890 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Auke Kok9a799d72007-09-15 14:07:45 -07004891 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00004892 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004893 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Jacob Kellerb335e752014-03-25 07:45:27 +00004894 vmolr |= IXGBE_VMOLR_MPE;
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004895 features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07004896 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07004897 if (netdev->flags & IFF_ALLMULTI) {
4898 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004899 vmolr |= IXGBE_VMOLR_MPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07004900 }
Emil Tantilove433ea12010-05-13 17:33:00 +00004901 hw->addr_ctrl.user_set_promisc = false;
John Fastabend9dcb3732012-04-15 06:44:25 +00004902 }
4903
4904 /*
4905 * Write addresses to available RAR registers, if there is not
4906 * sufficient space to store all the addresses then enable
4907 * unicast promiscuous mode
4908 */
Alexander Duyck0f079d22015-10-22 16:26:36 -07004909 if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
John Fastabend9dcb3732012-04-15 06:44:25 +00004910 fctrl |= IXGBE_FCTRL_UPE;
4911 vmolr |= IXGBE_VMOLR_ROPE;
Alexander Duyck28500622010-06-15 09:25:48 +00004912 }
4913
Emil Tantilovcf789592013-10-26 08:13:20 +00004914 /* Write addresses to the MTA, if the attempt fails
4915 * then we should just turn on promiscuous mode so
4916 * that we can at least receive multicast traffic
4917 */
Jacob Kellerb335e752014-03-25 07:45:27 +00004918 count = ixgbe_write_mc_addr_list(netdev);
4919 if (count < 0) {
4920 fctrl |= IXGBE_FCTRL_MPE;
4921 vmolr |= IXGBE_VMOLR_MPE;
4922 } else if (count) {
4923 vmolr |= IXGBE_VMOLR_ROMPE;
4924 }
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004925
4926 if (hw->mac.type != ixgbe_mac_82598EB) {
4927 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
Alexander Duyck28500622010-06-15 09:25:48 +00004928 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
4929 IXGBE_VMOLR_ROPE);
Alexander Duyck1d9c0bf2012-05-05 05:32:21 +00004930 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07004931 }
4932
Ben Greear3f2d1c02012-03-08 08:28:41 +00004933 /* This is useful for sniffing bad packets. */
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004934 if (features & NETIF_F_RXALL) {
Ben Greear3f2d1c02012-03-08 08:28:41 +00004935 /* UPE and MPE will be handled by normal PROMISC logic
4936 * in e1000e_set_rx_mode */
4937 fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
4938 IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
4939 IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
4940
4941 fctrl &= ~(IXGBE_FCTRL_DPF);
4942 /* NOTE: VLAN filtering is disabled by setting PROMISC */
4943 }
4944
Auke Kok9a799d72007-09-15 14:07:45 -07004945 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00004946
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004947 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jesse Grossf62bbb52010-10-20 13:56:10 +00004948 ixgbe_vlan_strip_enable(adapter);
4949 else
4950 ixgbe_vlan_strip_disable(adapter);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08004951
4952 if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
4953 ixgbe_vlan_promisc_disable(adapter);
4954 else
4955 ixgbe_vlan_promisc_enable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004956}
4957
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004958static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
4959{
4960 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004961
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004962 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004963 napi_enable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004964}
4965
4966static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
4967{
4968 int q_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004969
Eric Dumazet3ffc1af2017-02-02 16:26:39 -08004970 for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00004971 napi_disable(&adapter->q_vector[q_idx]->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004972}
4973
Emil Tantilova21d0822016-08-10 11:19:23 -07004974static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
Mark Rustad67359c32015-06-15 11:33:25 -07004975{
Emil Tantilova21d0822016-08-10 11:19:23 -07004976 struct ixgbe_hw *hw = &adapter->hw;
4977 u32 vxlanctrl;
4978
4979 if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
4980 IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
4981 return;
4982
Sabrina Dubrocaa39221c2017-07-03 13:02:55 +02004983 vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
Emil Tantilova21d0822016-08-10 11:19:23 -07004984 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
4985
4986 if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
Mark Rustad67359c32015-06-15 11:33:25 -07004987 adapter->vxlan_port = 0;
Emil Tantilova21d0822016-08-10 11:19:23 -07004988
4989 if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
4990 adapter->geneve_port = 0;
Mark Rustad67359c32015-06-15 11:33:25 -07004991}
4992
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08004993#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00004994/**
Alexander Duyck2f90b862008-11-20 20:52:10 -08004995 * ixgbe_configure_dcb - Configure DCB hardware
4996 * @adapter: ixgbe adapter struct
4997 *
4998 * This is called by the driver on open to configure the DCB hardware.
4999 * This is also called by the gennetlink interface when reconfiguring
5000 * the DCB state.
5001 */
5002static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
5003{
5004 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00005005 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005006
Alexander Duyck67ebd792010-08-19 13:34:04 +00005007 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
5008 if (hw->mac.type == ixgbe_mac_82598EB)
5009 netif_set_gso_max_size(adapter->netdev, 65536);
5010 return;
5011 }
5012
5013 if (hw->mac.type == ixgbe_mac_82598EB)
5014 netif_set_gso_max_size(adapter->netdev, 32768);
5015
John Fastabendb1208182011-10-15 05:00:10 +00005016#ifdef IXGBE_FCOE
5017 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
5018 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
5019#endif
5020
Alexander Duyck01fa7d92010-11-16 19:26:53 -08005021 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00005022 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00005023 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5024 DCB_TX_CONFIG);
5025 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
5026 DCB_RX_CONFIG);
5027 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00005028 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
5029 ixgbe_dcb_hw_ets(&adapter->hw,
5030 adapter->ixgbe_ieee_ets,
5031 max_frame);
5032 ixgbe_dcb_hw_pfc_config(&adapter->hw,
5033 adapter->ixgbe_ieee_pfc->pfc_en,
5034 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00005035 }
John Fastabend8187cd42011-02-23 05:58:08 +00005036
5037 /* Enable RSS Hash per TC */
5038 if (hw->mac.type != ixgbe_mac_82598EB) {
Alexander Duyck4ae63732012-06-22 06:46:33 +00005039 u32 msb = 0;
5040 u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005041
Alexander Duyckd411a932012-06-30 00:14:01 +00005042 while (rss_i) {
5043 msb++;
5044 rss_i >>= 1;
John Fastabend8187cd42011-02-23 05:58:08 +00005045 }
Alexander Duyckd411a932012-06-30 00:14:01 +00005046
Alexander Duyck4ae63732012-06-22 06:46:33 +00005047 /* write msb to all 8 TCs in one write */
5048 IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
John Fastabend8187cd42011-02-23 05:58:08 +00005049 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005050}
John Fastabend9da712d2011-08-23 03:14:22 +00005051#endif
5052
5053/* Additional bittime to account for IXGBE framing */
5054#define IXGBE_ETH_FRAMING 20
5055
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005056/**
John Fastabend9da712d2011-08-23 03:14:22 +00005057 * ixgbe_hpbthresh - calculate high water mark for flow control
5058 *
5059 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005060 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005061 */
5062static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
5063{
5064 struct ixgbe_hw *hw = &adapter->hw;
5065 struct net_device *dev = adapter->netdev;
5066 int link, tc, kb, marker;
5067 u32 dv_id, rx_pba;
5068
5069 /* Calculate max LAN frame size */
5070 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
5071
5072#ifdef IXGBE_FCOE
5073 /* FCoE traffic class uses FCOE jumbo frames */
Alexander Duyck800bd602012-06-02 00:11:02 +00005074 if ((dev->features & NETIF_F_FCOE_MTU) &&
5075 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5076 (pb == ixgbe_fcoe_get_tc(adapter)))
5077 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005078#endif
Jacob Kellere5776622014-04-05 02:35:52 +00005079
John Fastabend9da712d2011-08-23 03:14:22 +00005080 /* Calculate delay value for device */
5081 switch (hw->mac.type) {
5082 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005083 case ixgbe_mac_X550:
5084 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005085 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005086 dv_id = IXGBE_DV_X540(link, tc);
5087 break;
5088 default:
5089 dv_id = IXGBE_DV(link, tc);
5090 break;
5091 }
5092
5093 /* Loopback switch introduces additional latency */
5094 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5095 dv_id += IXGBE_B2BT(tc);
5096
5097 /* Delay value is calculated in bit times convert to KB */
5098 kb = IXGBE_BT2KB(dv_id);
5099 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
5100
5101 marker = rx_pba - kb;
5102
5103 /* It is possible that the packet buffer is not large enough
5104 * to provide required headroom. In this case throw an error
5105 * to user and a do the best we can.
5106 */
5107 if (marker < 0) {
5108 e_warn(drv, "Packet Buffer(%i) can not provide enough"
5109 "headroom to support flow control."
5110 "Decrease MTU or number of traffic classes\n", pb);
5111 marker = tc + 1;
5112 }
5113
5114 return marker;
5115}
5116
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005117/**
John Fastabend9da712d2011-08-23 03:14:22 +00005118 * ixgbe_lpbthresh - calculate low water mark for for flow control
5119 *
5120 * @adapter: board private structure to calculate for
Ben Hutchings49ce9c22012-07-10 10:56:00 +00005121 * @pb: packet buffer to calculate
John Fastabend9da712d2011-08-23 03:14:22 +00005122 */
Jacob Kellere5776622014-04-05 02:35:52 +00005123static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
John Fastabend9da712d2011-08-23 03:14:22 +00005124{
5125 struct ixgbe_hw *hw = &adapter->hw;
5126 struct net_device *dev = adapter->netdev;
5127 int tc;
5128 u32 dv_id;
5129
5130 /* Calculate max LAN frame size */
5131 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
5132
Jacob Kellere5776622014-04-05 02:35:52 +00005133#ifdef IXGBE_FCOE
5134 /* FCoE traffic class uses FCOE jumbo frames */
5135 if ((dev->features & NETIF_F_FCOE_MTU) &&
5136 (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
5137 (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
5138 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
5139#endif
5140
John Fastabend9da712d2011-08-23 03:14:22 +00005141 /* Calculate delay value for device */
5142 switch (hw->mac.type) {
5143 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005144 case ixgbe_mac_X550:
5145 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005146 case ixgbe_mac_x550em_a:
John Fastabend9da712d2011-08-23 03:14:22 +00005147 dv_id = IXGBE_LOW_DV_X540(tc);
5148 break;
5149 default:
5150 dv_id = IXGBE_LOW_DV(tc);
5151 break;
5152 }
5153
5154 /* Delay value is calculated in bit times convert to KB */
5155 return IXGBE_BT2KB(dv_id);
5156}
5157
5158/*
5159 * ixgbe_pbthresh_setup - calculate and setup high low water marks
5160 */
5161static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
5162{
5163 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck0efbf122017-11-22 10:57:11 -08005164 int num_tc = adapter->hw_tcs;
John Fastabend9da712d2011-08-23 03:14:22 +00005165 int i;
5166
5167 if (!num_tc)
5168 num_tc = 1;
5169
John Fastabend9da712d2011-08-23 03:14:22 +00005170 for (i = 0; i < num_tc; i++) {
5171 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
Jacob Kellere5776622014-04-05 02:35:52 +00005172 hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
John Fastabend9da712d2011-08-23 03:14:22 +00005173
5174 /* Low water marks must not be larger than high water marks */
Jacob Kellere5776622014-04-05 02:35:52 +00005175 if (hw->fc.low_water[i] > hw->fc.high_water[i])
5176 hw->fc.low_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005177 }
Jacob Kellere5776622014-04-05 02:35:52 +00005178
5179 for (; i < MAX_TRAFFIC_CLASS; i++)
5180 hw->fc.high_water[i] = 0;
John Fastabend9da712d2011-08-23 03:14:22 +00005181}
John Fastabend80605c652011-05-02 12:34:10 +00005182
5183static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
5184{
John Fastabend80605c652011-05-02 12:34:10 +00005185 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00005186 int hdrm;
Alexander Duyck0efbf122017-11-22 10:57:11 -08005187 u8 tc = adapter->hw_tcs;
John Fastabend80605c652011-05-02 12:34:10 +00005188
5189 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
5190 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00005191 hdrm = 32 << adapter->fdir_pballoc;
5192 else
5193 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00005194
Alexander Duyckf7e10272011-07-21 00:40:35 +00005195 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00005196 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00005197}
5198
Alexander Duycke4911d52011-05-11 07:18:52 +00005199static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
5200{
5201 struct ixgbe_hw *hw = &adapter->hw;
Sasha Levinb67bfe02013-02-27 17:06:00 -08005202 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005203 struct ixgbe_fdir_filter *filter;
5204
5205 spin_lock(&adapter->fdir_perfect_lock);
5206
5207 if (!hlist_empty(&adapter->fdir_filter_list))
5208 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
5209
Sasha Levinb67bfe02013-02-27 17:06:00 -08005210 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005211 &adapter->fdir_filter_list, fdir_node) {
5212 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00005213 &filter->filter,
5214 filter->sw_idx,
5215 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
5216 IXGBE_FDIR_DROP_QUEUE :
5217 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00005218 }
5219
5220 spin_unlock(&adapter->fdir_perfect_lock);
5221}
5222
John Fastabend2a47fa42013-11-06 09:54:52 -08005223/**
5224 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
5225 * @rx_ring: ring to free buffers from
5226 **/
5227static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
5228{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005229 u16 i = rx_ring->next_to_clean;
5230 struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
John Fastabend2a47fa42013-11-06 09:54:52 -08005231
5232 /* Free all the Rx ring sk_buffs */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005233 while (i != rx_ring->next_to_alloc) {
John Fastabend2a47fa42013-11-06 09:54:52 -08005234 if (rx_buffer->skb) {
5235 struct sk_buff *skb = rx_buffer->skb;
Alexander Duyck18cb6522014-11-14 00:56:29 +00005236 if (IXGBE_CB(skb)->page_released)
Alexander Duyckffed21b2017-01-17 08:37:29 -08005237 dma_unmap_page_attrs(rx_ring->dev,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005238 IXGBE_CB(skb)->dma,
5239 ixgbe_rx_pg_size(rx_ring),
5240 DMA_FROM_DEVICE,
5241 IXGBE_RX_DMA_ATTR);
John Fastabend2a47fa42013-11-06 09:54:52 -08005242 dev_kfree_skb(skb);
5243 }
Alexander Duyck18cb6522014-11-14 00:56:29 +00005244
Alexander Duyckf3213d92017-01-17 08:35:54 -08005245 /* Invalidate cache lines that may have been written to by
5246 * device so that we avoid corrupting memory.
5247 */
5248 dma_sync_single_range_for_cpu(rx_ring->dev,
5249 rx_buffer->dma,
5250 rx_buffer->page_offset,
5251 ixgbe_rx_bufsz(rx_ring),
5252 DMA_FROM_DEVICE);
5253
5254 /* free resources associated with mapping */
Alexander Duyckffed21b2017-01-17 08:37:29 -08005255 dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
Alexander Duyckf3213d92017-01-17 08:35:54 -08005256 ixgbe_rx_pg_size(rx_ring),
5257 DMA_FROM_DEVICE,
5258 IXGBE_RX_DMA_ATTR);
Alexander Duyck1b56cf42017-01-17 08:36:03 -08005259 __page_frag_cache_drain(rx_buffer->page,
5260 rx_buffer->pagecnt_bias);
Alexander Duyck18cb6522014-11-14 00:56:29 +00005261
Alexander Duyckffed21b2017-01-17 08:37:29 -08005262 i++;
5263 rx_buffer++;
5264 if (i == rx_ring->count) {
5265 i = 0;
5266 rx_buffer = rx_ring->rx_buffer_info;
5267 }
John Fastabend2a47fa42013-11-06 09:54:52 -08005268 }
5269
John Fastabend2a47fa42013-11-06 09:54:52 -08005270 rx_ring->next_to_alloc = 0;
5271 rx_ring->next_to_clean = 0;
5272 rx_ring->next_to_use = 0;
5273}
5274
Alexander Duyck865255b2018-04-03 17:16:40 -04005275static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter,
John Fastabend2a47fa42013-11-06 09:54:52 -08005276 struct ixgbe_fwd_adapter *accel)
5277{
Alexander Duyck865255b2018-04-03 17:16:40 -04005278 struct net_device *vdev = accel->netdev;
Alexander Duyck16be45b2017-11-22 10:57:23 -08005279 int i, baseq, err;
John Fastabend2a47fa42013-11-06 09:54:52 -08005280
John Fastabend2a47fa42013-11-06 09:54:52 -08005281 baseq = accel->pool * adapter->num_rx_queues_per_pool;
Alexander Duyck4e039c12017-11-22 10:56:40 -08005282 netdev_dbg(vdev, "pool %i:%i queues %i:%i\n",
John Fastabend2a47fa42013-11-06 09:54:52 -08005283 accel->pool, adapter->num_rx_pools,
Alexander Duyck4e039c12017-11-22 10:56:40 -08005284 baseq, baseq + adapter->num_rx_queues_per_pool);
John Fastabend2a47fa42013-11-06 09:54:52 -08005285
Alexander Duyck16be45b2017-11-22 10:57:23 -08005286 accel->rx_base_queue = baseq;
5287 accel->tx_base_queue = baseq;
John Fastabend2a47fa42013-11-06 09:54:52 -08005288
5289 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
Alexander Duyck16be45b2017-11-22 10:57:23 -08005290 adapter->rx_ring[baseq + i]->netdev = vdev;
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08005291
5292 /* Guarantee all rings are updated before we update the
5293 * MAC address filter.
5294 */
5295 wmb();
John Fastabend2a47fa42013-11-06 09:54:52 -08005296
Alexander Duyck4a2512c2017-11-22 10:56:59 -08005297 /* ixgbe_add_mac_filter will return an index if it succeeds, so we
5298 * need to only treat it as an error value if it is negative.
5299 */
5300 err = ixgbe_add_mac_filter(adapter, vdev->dev_addr,
5301 VMDQ_P(accel->pool));
Alexander Duyck81d4e912018-04-03 17:16:09 -04005302 if (err >= 0)
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08005303 return 0;
John Fastabend2a47fa42013-11-06 09:54:52 -08005304
Alexander Duyck8315ef62018-04-03 17:16:45 -04005305 /* if we cannot add the MAC rule then disable the offload */
5306 macvlan_release_l2fw_offload(vdev);
5307
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08005308 for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
5309 adapter->rx_ring[baseq + i]->netdev = NULL;
5310
Alexander Duyck8315ef62018-04-03 17:16:45 -04005311 netdev_err(vdev, "L2FW offload disabled due to L2 filter error\n");
5312
5313 clear_bit(accel->pool, adapter->fwd_bitmask);
5314 kfree(accel);
5315
John Fastabend2a47fa42013-11-06 09:54:52 -08005316 return err;
5317}
5318
Alexander Duyck865255b2018-04-03 17:16:40 -04005319static int ixgbe_macvlan_up(struct net_device *vdev, void *data)
David Ahern1cd127f2016-10-17 19:15:48 -07005320{
Alexander Duyck865255b2018-04-03 17:16:40 -04005321 struct ixgbe_adapter *adapter = data;
5322 struct ixgbe_fwd_adapter *accel;
David Ahern1cd127f2016-10-17 19:15:48 -07005323
Alexander Duyck865255b2018-04-03 17:16:40 -04005324 if (!netif_is_macvlan(vdev))
5325 return 0;
5326
5327 accel = macvlan_accel_priv(vdev);
5328 if (!accel)
5329 return 0;
5330
5331 ixgbe_fwd_ring_up(adapter, accel);
David Ahern1cd127f2016-10-17 19:15:48 -07005332
5333 return 0;
5334}
5335
John Fastabend2a47fa42013-11-06 09:54:52 -08005336static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
5337{
David Ahern1cd127f2016-10-17 19:15:48 -07005338 netdev_walk_all_upper_dev_rcu(adapter->netdev,
Alexander Duyck865255b2018-04-03 17:16:40 -04005339 ixgbe_macvlan_up, adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005340}
5341
Auke Kok9a799d72007-09-15 14:07:45 -07005342static void ixgbe_configure(struct ixgbe_adapter *adapter)
5343{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005344 struct ixgbe_hw *hw = &adapter->hw;
5345
John Fastabend80605c652011-05-02 12:34:10 +00005346 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005347#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00005348 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005349#endif
Alexander Duyckb35d4d42012-05-23 05:39:25 +00005350 /*
5351 * We must restore virtualization before VLANs or else
5352 * the VLVF registers will not be populated
5353 */
5354 ixgbe_configure_virtualization(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005355
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005356 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005357 ixgbe_restore_vlan(adapter);
Shannon Nelson6d73a152017-12-19 15:59:58 -08005358 ixgbe_ipsec_restore(adapter);
Jesse Grossf62bbb52010-10-20 13:56:10 +00005359
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005360 switch (hw->mac.type) {
5361 case ixgbe_mac_82599EB:
5362 case ixgbe_mac_X540:
5363 hw->mac.ops.disable_rx_buff(hw);
5364 break;
5365 default:
5366 break;
5367 }
5368
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005369 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005370 ixgbe_init_fdir_signature_82599(&adapter->hw,
5371 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00005372 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
5373 ixgbe_init_fdir_perfect_82599(&adapter->hw,
5374 adapter->fdir_pballoc);
5375 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005376 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00005377
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00005378 switch (hw->mac.type) {
5379 case ixgbe_mac_82599EB:
5380 case ixgbe_mac_X540:
5381 hw->mac.ops.enable_rx_buff(hw);
5382 break;
5383 default:
5384 break;
5385 }
5386
Mark Rustad9de76052015-08-08 16:27:41 -07005387#ifdef CONFIG_IXGBE_DCA
5388 /* configure DCA */
5389 if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
5390 ixgbe_setup_dca(adapter);
5391#endif /* CONFIG_IXGBE_DCA */
5392
Alexander Duyck7c8ae652012-05-05 05:32:47 +00005393#ifdef IXGBE_FCOE
5394 /* configure FCoE L2 filters, redirection table, and Rx control */
5395 ixgbe_configure_fcoe(adapter);
5396
5397#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005398 ixgbe_configure_tx(adapter);
5399 ixgbe_configure_rx(adapter);
John Fastabend2a47fa42013-11-06 09:54:52 -08005400 ixgbe_configure_dfwd(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005401}
5402
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005403/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005404 * ixgbe_sfp_link_config - set up SFP+ link
5405 * @adapter: pointer to private adapter struct
5406 **/
5407static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
5408{
Alexander Duyck70864002011-04-27 09:13:56 +00005409 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005410 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00005411 * is that an SFP was inserted/removed after the reset
5412 * but before SFP detection was enabled. As such the best
5413 * solution is to just start searching as soon as we start
5414 */
5415 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
5416 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005417
Alexander Duyck70864002011-04-27 09:13:56 +00005418 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
Mark Rustad58e7cd22015-08-08 16:18:48 -07005419 adapter->sfp_poll_time = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005420}
5421
5422/**
5423 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005424 * @hw: pointer to private hardware struct
5425 *
5426 * Returns 0 on success, negative on failure
5427 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005428static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005429{
Josh Hay3d292262012-12-15 03:28:19 +00005430 u32 speed;
5431 bool autoneg, link_up = false;
Mark Rustada1e869d2015-04-10 10:36:36 -07005432 int ret = IXGBE_ERR_LINK_SETUP;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005433
5434 if (hw->mac.ops.check_link)
Josh Hay3d292262012-12-15 03:28:19 +00005435 ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005436
5437 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005438 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005439
Josh Hay3d292262012-12-15 03:28:19 +00005440 speed = hw->phy.autoneg_advertised;
5441 if ((!speed) && (hw->mac.ops.get_link_capabilities))
5442 ret = hw->mac.ops.get_link_capabilities(hw, &speed,
5443 &autoneg);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005444 if (ret)
Mark Rustade90dd262014-07-22 06:51:08 +00005445 return ret;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005446
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00005447 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00005448 ret = hw->mac.ops.setup_link(hw, speed, link_up);
Mark Rustade90dd262014-07-22 06:51:08 +00005449
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08005450 return ret;
5451}
5452
Alexander Duycka34bcff2010-08-19 13:39:20 +00005453static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005454{
Auke Kok9a799d72007-09-15 14:07:45 -07005455 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005456 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005457
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005458 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00005459 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
5460 IXGBE_GPIE_OCD;
5461 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005462 /*
5463 * use EIAM to auto-mask when MSI-X interrupt is asserted
5464 * this saves a register write for every interrupt
5465 */
5466 switch (hw->mac.type) {
5467 case ixgbe_mac_82598EB:
5468 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
5469 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005470 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005471 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005472 case ixgbe_mac_X550:
5473 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005474 case ixgbe_mac_x550em_a:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005475 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00005476 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
5477 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
5478 break;
5479 }
5480 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005481 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
5482 * specifically only auto mask tx and rx interrupts */
5483 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07005484 }
5485
Alexander Duycka34bcff2010-08-19 13:39:20 +00005486 /* XXX: to interrupt immediately for EICS writes, enable this */
5487 /* gpie |= IXGBE_GPIE_EIMEN; */
5488
5489 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
5490 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
Alexander Duyck73079ea2012-07-14 06:48:49 +00005491
5492 switch (adapter->ring_feature[RING_F_VMDQ].mask) {
5493 case IXGBE_82599_VMDQ_8Q_MASK:
5494 gpie |= IXGBE_GPIE_VTMODE_16;
5495 break;
5496 case IXGBE_82599_VMDQ_4Q_MASK:
5497 gpie |= IXGBE_GPIE_VTMODE_32;
5498 break;
5499 default:
5500 gpie |= IXGBE_GPIE_VTMODE_64;
5501 break;
5502 }
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005503 }
5504
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005505 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00005506 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
5507 switch (adapter->hw.mac.type) {
5508 case ixgbe_mac_82599EB:
Don Skidmore9a900ec2015-06-09 17:15:01 -07005509 gpie |= IXGBE_SDP0_GPIEN_8259X;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005510 break;
Don Skidmoref3df98e2011-08-17 10:15:21 +00005511 default:
5512 break;
5513 }
5514 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00005515
Alexander Duycka34bcff2010-08-19 13:39:20 +00005516 /* Enable fan failure interrupt */
5517 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Don Skidmore9a900ec2015-06-09 17:15:01 -07005518 gpie |= IXGBE_SDP1_GPIEN(hw);
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07005519
Don Skidmorea023bbd2015-06-24 16:38:53 -04005520 switch (hw->mac.type) {
5521 case ixgbe_mac_82599EB:
5522 gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
5523 break;
5524 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005525 case ixgbe_mac_x550em_a:
Don Skidmorea023bbd2015-06-24 16:38:53 -04005526 gpie |= IXGBE_SDP0_GPIEN_X540;
5527 break;
5528 default:
5529 break;
Don Skidmore2698b202011-04-13 07:01:52 +00005530 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00005531
5532 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
5533}
5534
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005535static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00005536{
5537 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005538 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00005539 u32 ctrl_ext;
5540
5541 ixgbe_get_hw_control(adapter);
5542 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005543
Auke Kok9a799d72007-09-15 14:07:45 -07005544 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
5545 ixgbe_configure_msix(adapter);
5546 else
5547 ixgbe_configure_msi_and_legacy(adapter);
5548
Emil Tantilovec74a472012-09-20 03:33:56 +00005549 /* enable the optics for 82599 SFP+ fiber */
5550 if (hw->mac.ops.enable_tx_laser)
Peter Waskiewicz61fac742010-04-27 00:38:15 +00005551 hw->mac.ops.enable_tx_laser(hw);
5552
Don Skidmore961fac82015-06-09 16:09:47 -07005553 if (hw->phy.ops.set_phy_power)
5554 hw->phy.ops.set_phy_power(hw, true);
5555
Peter Zijlstra4e857c52014-03-17 18:06:10 +01005556 smp_mb__before_atomic();
Auke Kok9a799d72007-09-15 14:07:45 -07005557 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005558 ixgbe_napi_enable_all(adapter);
5559
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08005560 if (ixgbe_is_sfp(hw)) {
5561 ixgbe_sfp_link_config(adapter);
5562 } else {
5563 err = ixgbe_non_sfp_link_config(hw);
5564 if (err)
5565 e_err(probe, "link_config FAILED %d\n", err);
5566 }
5567
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005568 /* clear any pending interrupts, may auto mask */
5569 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00005570 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07005571
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005572 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00005573 * If this adapter has a fan, check to see if we had a failure
5574 * before we enabled the interrupt.
5575 */
5576 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
5577 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5578 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00005579 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00005580 }
5581
Auke Kok9a799d72007-09-15 14:07:45 -07005582 /* bring the link up in the watchdog, this could race with our first
5583 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005584 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
5585 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00005586 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00005587
5588 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
5589 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
5590 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
5591 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07005592}
5593
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005594void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
5595{
5596 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00005597 /* put off any impending NetWatchDogTimeout */
Florian Westphal860e9532016-05-03 16:33:13 +02005598 netif_trans_update(adapter->netdev);
Alexander Duyck70864002011-04-27 09:13:56 +00005599
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005600 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00005601 usleep_range(1000, 2000);
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005602 if (adapter->hw.phy.type == ixgbe_phy_fw)
5603 ixgbe_watchdog_link_is_down(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005604 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00005605 /*
5606 * If SR-IOV enabled then wait a bit before bringing the adapter
5607 * back up to give the VFs time to respond to the reset. The
5608 * two second wait is based upon the watchdog timer cycle in
5609 * the VF driver.
5610 */
5611 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
5612 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005613 ixgbe_up(adapter);
5614 clear_bit(__IXGBE_RESETTING, &adapter->state);
5615}
5616
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005617void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005618{
5619 /* hardware has been reset, we need to reload some things */
5620 ixgbe_configure(adapter);
5621
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005622 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005623}
5624
5625void ixgbe_reset(struct ixgbe_adapter *adapter)
5626{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005627 struct ixgbe_hw *hw = &adapter->hw;
Jacob Keller5d7daa32014-03-29 06:51:25 +00005628 struct net_device *netdev = adapter->netdev;
Don Skidmore8ca783a2009-05-26 20:40:47 -07005629 int err;
5630
Mark Rustadb0483c82014-01-14 18:53:17 -08005631 if (ixgbe_removed(hw->hw_addr))
5632 return;
Alexander Duyck70864002011-04-27 09:13:56 +00005633 /* lock SFP init bit to prevent race conditions with the watchdog */
5634 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
5635 usleep_range(1000, 2000);
5636
5637 /* clear all SFP and link config related flags while holding SFP_INIT */
5638 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
5639 IXGBE_FLAG2_SFP_NEEDS_RESET);
5640 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
5641
Don Skidmore8ca783a2009-05-26 20:40:47 -07005642 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005643 switch (err) {
5644 case 0:
5645 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00005646 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005647 break;
5648 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00005649 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005650 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005651 case IXGBE_ERR_EEPROM_VERSION:
5652 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00005653 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005654 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00005655 "your hardware. If you are experiencing problems "
5656 "please contact your Intel or hardware "
5657 "representative who provided you with this "
5658 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00005659 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005660 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00005661 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00005662 }
Auke Kok9a799d72007-09-15 14:07:45 -07005663
Alexander Duyck70864002011-04-27 09:13:56 +00005664 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005665
5666 /* flush entries out of MAC table */
Jacob Keller5d7daa32014-03-29 06:51:25 +00005667 ixgbe_flush_sw_mac_table(adapter);
Alexander Duyck0f079d22015-10-22 16:26:36 -07005668 __dev_uc_unsync(netdev, NULL);
5669
5670 /* do not flush user set addresses */
Alexander Duyckc9f53e62015-10-22 16:26:30 -07005671 ixgbe_mac_set_default_filter(adapter);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00005672
5673 /* update SAN MAC vmdq pool selection */
5674 if (hw->mac.san_mac_rar_index)
5675 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
Jacob Keller1a71ab22012-08-25 03:54:19 +00005676
Jacob Keller8fecf672013-06-21 08:14:32 +00005677 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00005678 ixgbe_ptp_reset(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07005679
5680 if (hw->phy.ops.set_phy_power) {
5681 if (!netif_running(adapter->netdev) && !adapter->wol)
5682 hw->phy.ops.set_phy_power(hw, false);
5683 else
5684 hw->phy.ops.set_phy_power(hw, true);
5685 }
Auke Kok9a799d72007-09-15 14:07:45 -07005686}
5687
Auke Kok9a799d72007-09-15 14:07:45 -07005688/**
Auke Kok9a799d72007-09-15 14:07:45 -07005689 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07005690 * @tx_ring: ring to be cleaned
5691 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005692static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005693{
Alexander Duyckffed21b2017-01-17 08:37:29 -08005694 u16 i = tx_ring->next_to_clean;
5695 struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07005696
Alexander Duyckffed21b2017-01-17 08:37:29 -08005697 while (i != tx_ring->next_to_use) {
5698 union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
Auke Kok9a799d72007-09-15 14:07:45 -07005699
Alexander Duyckffed21b2017-01-17 08:37:29 -08005700 /* Free all the Tx ring sk_buffs */
John Fastabend33fdc822017-04-24 03:30:18 -07005701 if (ring_is_xdp(tx_ring))
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02005702 xdp_return_frame(tx_buffer->xdpf);
John Fastabend33fdc822017-04-24 03:30:18 -07005703 else
5704 dev_kfree_skb_any(tx_buffer->skb);
Alexander Duyckffed21b2017-01-17 08:37:29 -08005705
5706 /* unmap skb header data */
5707 dma_unmap_single(tx_ring->dev,
5708 dma_unmap_addr(tx_buffer, dma),
5709 dma_unmap_len(tx_buffer, len),
5710 DMA_TO_DEVICE);
5711
5712 /* check for eop_desc to determine the end of the packet */
5713 eop_desc = tx_buffer->next_to_watch;
5714 tx_desc = IXGBE_TX_DESC(tx_ring, i);
5715
5716 /* unmap remaining buffers */
5717 while (tx_desc != eop_desc) {
5718 tx_buffer++;
5719 tx_desc++;
5720 i++;
5721 if (unlikely(i == tx_ring->count)) {
5722 i = 0;
5723 tx_buffer = tx_ring->tx_buffer_info;
5724 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
5725 }
5726
5727 /* unmap any remaining paged data */
5728 if (dma_unmap_len(tx_buffer, len))
5729 dma_unmap_page(tx_ring->dev,
5730 dma_unmap_addr(tx_buffer, dma),
5731 dma_unmap_len(tx_buffer, len),
5732 DMA_TO_DEVICE);
5733 }
5734
5735 /* move us one more past the eop_desc for start of next pkt */
5736 tx_buffer++;
5737 i++;
5738 if (unlikely(i == tx_ring->count)) {
5739 i = 0;
5740 tx_buffer = tx_ring->tx_buffer_info;
5741 }
Auke Kok9a799d72007-09-15 14:07:45 -07005742 }
5743
Alexander Duyckffed21b2017-01-17 08:37:29 -08005744 /* reset BQL for queue */
John Fastabend33fdc822017-04-24 03:30:18 -07005745 if (!ring_is_xdp(tx_ring))
5746 netdev_tx_reset_queue(txring_txq(tx_ring));
John Fastabenddad8a3b2012-04-23 12:22:39 +00005747
Alexander Duyckffed21b2017-01-17 08:37:29 -08005748 /* reset next_to_use and next_to_clean */
Auke Kok9a799d72007-09-15 14:07:45 -07005749 tx_ring->next_to_use = 0;
5750 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005751}
5752
5753/**
Auke Kok9a799d72007-09-15 14:07:45 -07005754 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
5755 * @adapter: board private structure
5756 **/
5757static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
5758{
5759 int i;
5760
5761 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005762 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005763}
5764
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005765/**
5766 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
5767 * @adapter: board private structure
5768 **/
5769static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
5770{
5771 int i;
5772
5773 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005774 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07005775 for (i = 0; i < adapter->num_xdp_queues; i++)
5776 ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005777}
5778
Alexander Duycke4911d52011-05-11 07:18:52 +00005779static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
5780{
Sasha Levinb67bfe02013-02-27 17:06:00 -08005781 struct hlist_node *node2;
Alexander Duycke4911d52011-05-11 07:18:52 +00005782 struct ixgbe_fdir_filter *filter;
5783
5784 spin_lock(&adapter->fdir_perfect_lock);
5785
Sasha Levinb67bfe02013-02-27 17:06:00 -08005786 hlist_for_each_entry_safe(filter, node2,
Alexander Duycke4911d52011-05-11 07:18:52 +00005787 &adapter->fdir_filter_list, fdir_node) {
5788 hlist_del(&filter->fdir_node);
5789 kfree(filter);
5790 }
5791 adapter->fdir_filter_count = 0;
5792
5793 spin_unlock(&adapter->fdir_perfect_lock);
5794}
5795
Auke Kok9a799d72007-09-15 14:07:45 -07005796void ixgbe_down(struct ixgbe_adapter *adapter)
5797{
5798 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005799 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005800 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005801
5802 /* signal that we are down to the interrupt handler */
Mark Rustadc3049c82014-01-14 18:53:12 -08005803 if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
5804 return; /* do nothing if already down */
Auke Kok9a799d72007-09-15 14:07:45 -07005805
5806 /* disable receives */
Don Skidmore1f9ac572015-03-13 13:54:30 -07005807 hw->mac.ops.disable_rx(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07005808
Yi Zou2d39d572011-01-06 14:29:56 +00005809 /* disable all enabled rx queues */
5810 for (i = 0; i < adapter->num_rx_queues; i++)
5811 /* this call also flushes the previous write */
5812 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
5813
Don Skidmore032b4322011-03-18 09:32:53 +00005814 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07005815
John Fastabend11393cc2017-07-17 09:29:40 -07005816 /* synchronize_sched() needed for pending XDP buffers to drain */
5817 if (adapter->xdp_ring[0])
5818 synchronize_sched();
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005819 netif_tx_stop_all_queues(netdev);
5820
Alexander Duyck70864002011-04-27 09:13:56 +00005821 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00005822 netif_carrier_off(netdev);
5823 netif_tx_disable(netdev);
5824
5825 ixgbe_irq_disable(adapter);
5826
5827 ixgbe_napi_disable_all(adapter);
5828
Emil Tantilov57ca2a42016-07-29 14:46:31 -07005829 clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
5830 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
Alexander Duyck70864002011-04-27 09:13:56 +00005831 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5832
5833 del_timer_sync(&adapter->service_timer);
5834
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005835 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005836 /* Clear EITR Select mapping */
5837 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
5838
5839 /* Mark all the VFs as inactive */
5840 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00005841 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00005842
Don Skidmore0a1f87c2009-09-18 09:45:43 +00005843 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07005844 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005845
Auke Kok9a799d72007-09-15 14:07:45 -07005846 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005847 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00005848 }
5849
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005850 /* disable transmits in the hardware now that interrupts are off */
5851 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08005852 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005853 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005854 }
John Fastabend33fdc822017-04-24 03:30:18 -07005855 for (i = 0; i < adapter->num_xdp_queues; i++) {
5856 u8 reg_idx = adapter->xdp_ring[i]->reg_idx;
5857
5858 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
5859 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00005860
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005861 /* Disable the Tx DMA engine on 82599 and later MAC */
Alexander Duyckbd508172010-11-16 19:27:03 -08005862 switch (hw->mac.type) {
5863 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005864 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00005865 case ixgbe_mac_X550:
5866 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07005867 case ixgbe_mac_x550em_a:
PJ Waskiewicz88512532009-03-13 22:15:10 +00005868 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00005869 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
5870 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08005871 break;
5872 default:
5873 break;
5874 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07005875
Paul Larson6f4a0e42008-06-24 17:00:56 -07005876 if (!pci_channel_offline(adapter->pdev))
5877 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00005878
Emil Tantilovec74a472012-09-20 03:33:56 +00005879 /* power down the optics for 82599 SFP+ fiber */
5880 if (hw->mac.ops.disable_tx_laser)
Don Skidmorec6ecf392010-12-03 03:31:51 +00005881 hw->mac.ops.disable_tx_laser(hw);
5882
Auke Kok9a799d72007-09-15 14:07:45 -07005883 ixgbe_clean_all_tx_rings(adapter);
5884 ixgbe_clean_all_rx_rings(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005885}
5886
Auke Kok9a799d72007-09-15 14:07:45 -07005887/**
Mark Rustadb3eb4e12016-12-14 11:02:16 -08005888 * ixgbe_eee_capable - helper function to determine EEE support on X550
5889 * @adapter: board private structure
5890 */
5891static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
5892{
5893 struct ixgbe_hw *hw = &adapter->hw;
5894
5895 switch (hw->device_id) {
5896 case IXGBE_DEV_ID_X550EM_A_1G_T:
5897 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
5898 if (!hw->phy.eee_speeds_supported)
5899 break;
5900 adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
5901 if (!hw->phy.eee_speeds_advertised)
5902 break;
5903 adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
5904 break;
5905 default:
5906 adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
5907 adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
5908 break;
5909 }
5910}
5911
5912/**
Auke Kok9a799d72007-09-15 14:07:45 -07005913 * ixgbe_tx_timeout - Respond to a Tx Hang
5914 * @netdev: network interface device structure
5915 **/
5916static void ixgbe_tx_timeout(struct net_device *netdev)
5917{
5918 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5919
5920 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00005921 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005922}
5923
Usha Ketineni88290092016-04-26 05:00:26 -07005924#ifdef CONFIG_IXGBE_DCB
5925static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
5926{
5927 struct ixgbe_hw *hw = &adapter->hw;
5928 struct tc_configuration *tc;
5929 int j;
5930
5931 switch (hw->mac.type) {
5932 case ixgbe_mac_82598EB:
5933 case ixgbe_mac_82599EB:
5934 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5935 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5936 break;
5937 case ixgbe_mac_X540:
5938 case ixgbe_mac_X550:
5939 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5940 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5941 break;
5942 case ixgbe_mac_X550EM_x:
5943 case ixgbe_mac_x550em_a:
5944 default:
5945 adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
5946 adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
5947 break;
5948 }
5949
5950 /* Configure DCB traffic classes */
5951 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5952 tc = &adapter->dcb_cfg.tc_config[j];
5953 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5954 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5955 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5956 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5957 tc->dcb_pfc = pfc_disabled;
5958 }
5959
5960 /* Initialize default user to priority mapping, UPx->TC0 */
5961 tc = &adapter->dcb_cfg.tc_config[0];
5962 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5963 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5964
5965 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5966 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5967 adapter->dcb_cfg.pfc_mode_enable = false;
5968 adapter->dcb_set_bitmap = 0x00;
5969 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
5970 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
5971 memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
5972 sizeof(adapter->temp_dcb_cfg));
5973}
5974#endif
5975
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005976/**
Auke Kok9a799d72007-09-15 14:07:45 -07005977 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5978 * @adapter: board private structure to initialize
Tony Nguyen5ba643c2017-12-04 11:28:30 -08005979 * @ii: pointer to ixgbe_info for device
Auke Kok9a799d72007-09-15 14:07:45 -07005980 *
5981 * ixgbe_sw_init initializes the Adapter private data structure.
5982 * Fields are initialized based on PCI device information and
5983 * OS network device settings (MTU size).
5984 **/
Emil Tantilov55570b62016-10-12 12:34:25 -07005985static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
5986 const struct ixgbe_info *ii)
Auke Kok9a799d72007-09-15 14:07:45 -07005987{
5988 struct ixgbe_hw *hw = &adapter->hw;
5989 struct pci_dev *pdev = adapter->pdev;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00005990 unsigned int rss, fdir;
Jacob Kellercb6d0f52012-12-04 06:03:14 +00005991 u32 fwsm;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04005992 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005993
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005994 /* PCI config space info */
5995
5996 hw->vendor_id = pdev->vendor;
5997 hw->device_id = pdev->device;
5998 hw->revision_id = pdev->revision;
5999 hw->subsystem_vendor_id = pdev->subsystem_vendor;
6000 hw->subsystem_device_id = pdev->subsystem_device;
6001
Emil Tantilov55570b62016-10-12 12:34:25 -07006002 /* get_invariants needs the device IDs */
6003 ii->get_invariants(hw);
6004
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006005 /* Set common capability flags and settings */
Don Skidmore0f9b2322014-11-18 09:35:08 +00006006 rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
Alexander Duyckc0876632012-05-10 00:01:46 +00006007 adapter->ring_feature[RING_F_RSS].limit = rss;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006008 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006009 adapter->max_q_vectors = MAX_Q_VECTORS_82599;
6010 adapter->atr_sample_rate = 20;
Alexander Duyckd3cb9862013-01-16 01:35:35 +00006011 fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
6012 adapter->ring_feature[RING_F_FDIR].limit = fdir;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006013 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Alexander Duycka8e87d92017-11-22 10:57:05 -08006014 adapter->ring_feature[RING_F_VMDQ].limit = 1;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006015#ifdef CONFIG_IXGBE_DCA
6016 adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
6017#endif
Usha Ketineni88290092016-04-26 05:00:26 -07006018#ifdef CONFIG_IXGBE_DCB
6019 adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
6020 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
6021#endif
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006022#ifdef IXGBE_FCOE
6023 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
6024 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6025#ifdef CONFIG_IXGBE_DCB
6026 /* Default traffic class to use for FCoE */
6027 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
6028#endif /* CONFIG_IXGBE_DCB */
6029#endif /* IXGBE_FCOE */
6030
John Fastabendb82b17d2016-02-16 21:18:53 -08006031 /* initialize static ixgbe jump table entries */
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04006032 adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
6033 GFP_KERNEL);
6034 if (!adapter->jump_tables[0])
6035 return -ENOMEM;
6036 adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
6037
6038 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
6039 adapter->jump_tables[i] = NULL;
John Fastabendb82b17d2016-02-16 21:18:53 -08006040
Kees Cook6396bb22018-06-12 14:03:40 -07006041 adapter->mac_table = kcalloc(hw->mac.num_rar_entries,
6042 sizeof(struct ixgbe_mac_addr),
Jacob Keller5d7daa32014-03-29 06:51:25 +00006043 GFP_ATOMIC);
Alexander Duyck530fd822015-11-02 17:09:29 -08006044 if (!adapter->mac_table)
6045 return -ENOMEM;
Jacob Keller5d7daa32014-03-29 06:51:25 +00006046
Tony Nguyen3dfbfc72017-04-13 07:26:05 -07006047 if (ixgbe_init_rss_key(adapter))
6048 return -ENOMEM;
6049
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006050 /* Set MAC specific capability flags and exceptions */
Alexander Duyckbd508172010-11-16 19:27:03 -08006051 switch (hw->mac.type) {
6052 case ixgbe_mac_82598EB:
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006053 adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006054
Don Skidmorebf069c92009-05-07 10:39:54 +00006055 if (hw->device_id == IXGBE_DEV_ID_82598AT)
6056 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006057
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00006058 adapter->max_q_vectors = MAX_Q_VECTORS_82598;
Emil Tantilov8fc3bb62013-01-08 04:23:53 +00006059 adapter->ring_feature[RING_F_FDIR].limit = 0;
6060 adapter->atr_sample_rate = 0;
6061 adapter->fdir_pballoc = 0;
6062#ifdef IXGBE_FCOE
6063 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6064 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
6065#ifdef CONFIG_IXGBE_DCB
6066 adapter->fcoe.up = 0;
6067#endif /* IXGBE_DCB */
6068#endif /* IXGBE_FCOE */
6069 break;
6070 case ixgbe_mac_82599EB:
6071 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
6072 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006073 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006074 case ixgbe_mac_X540:
Don Skidmore9a900ec2015-06-09 17:15:01 -07006075 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
Jacob Kellercb6d0f52012-12-04 06:03:14 +00006076 if (fwsm & IXGBE_FWSM_TS_ENABLED)
6077 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyckbd508172010-11-16 19:27:03 -08006078 break;
Mark Rustad49425df2016-04-01 12:18:09 -07006079 case ixgbe_mac_x550em_a:
Emil Tantilova21d0822016-08-10 11:19:23 -07006080 adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006081 switch (hw->device_id) {
6082 case IXGBE_DEV_ID_X550EM_A_1G_T:
6083 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
6084 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
6085 break;
6086 default:
6087 break;
6088 }
Emil Tantilova21d0822016-08-10 11:19:23 -07006089 /* fall through */
6090 case ixgbe_mac_X550EM_x:
Usha Ketineni88290092016-04-26 05:00:26 -07006091#ifdef CONFIG_IXGBE_DCB
6092 adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
6093#endif
6094#ifdef IXGBE_FCOE
6095 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
6096#ifdef CONFIG_IXGBE_DCB
6097 adapter->fcoe.up = 0;
6098#endif /* IXGBE_DCB */
6099#endif /* IXGBE_FCOE */
6100 /* Fall Through */
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006101 case ixgbe_mac_X550:
Mark Rustadb3eb4e12016-12-14 11:02:16 -08006102 if (hw->mac.type == ixgbe_mac_X550)
6103 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006104#ifdef CONFIG_IXGBE_DCA
6105 adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
6106#endif
Mark Rustad67359c32015-06-15 11:33:25 -07006107 adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006108 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08006109 default:
6110 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00006111 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08006112
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006113#ifdef IXGBE_FCOE
6114 /* FCoE support exists, always init the FCoE lock */
6115 spin_lock_init(&adapter->fcoe.lock);
6116
6117#endif
Alexander Duyck1fc5f032011-06-02 04:28:39 +00006118 /* n-tuple support exists, always init our spinlock */
6119 spin_lock_init(&adapter->fdir_perfect_lock);
6120
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08006121#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -07006122 ixgbe_init_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006123#endif
Alexander Duyckde7a7e32018-06-04 16:51:25 -04006124 ixgbe_init_ipsec_offload(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006125
6126 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00006127 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00006128 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
John Fastabend9da712d2011-08-23 03:14:22 +00006129 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07006130 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
6131 hw->fc.send_xon = true;
Don Skidmore73d80953d2013-07-31 02:19:24 +00006132 hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07006133
Alexander Duyck99d74482012-05-09 08:09:25 +00006134#ifdef CONFIG_PCI_IOV
Jacob Keller170e8542013-11-09 04:52:32 -08006135 if (max_vfs > 0)
6136 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 +00006137
Jacob Keller170e8542013-11-09 04:52:32 -08006138 /* assign number of SR-IOV VFs */
6139 if (hw->mac.type != ixgbe_mac_82598EB) {
ethan.zhaodcc23e32014-01-16 19:41:04 -08006140 if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
Emil Tantilov5c11f002017-01-20 14:11:56 -08006141 max_vfs = 0;
Jacob Keller170e8542013-11-09 04:52:32 -08006142 e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
Jacob Keller170e8542013-11-09 04:52:32 -08006143 }
6144 }
6145#endif /* CONFIG_PCI_IOV */
6146
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006147 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006148 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00006149 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006150
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07006151 /* set default ring sizes */
6152 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
6153 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
6154
Alexander Duyckbd198052011-06-11 01:45:08 +00006155 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00006156 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00006157
Auke Kok9a799d72007-09-15 14:07:45 -07006158 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07006159 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006160 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006161 return -EIO;
6162 }
6163
John Fastabend2a47fa42013-11-06 09:54:52 -08006164 /* PF holds first pool slot */
Alexander Duyck4e039c12017-11-22 10:56:40 -08006165 set_bit(0, adapter->fwd_bitmask);
Auke Kok9a799d72007-09-15 14:07:45 -07006166 set_bit(__IXGBE_DOWN, &adapter->state);
6167
6168 return 0;
6169}
6170
6171/**
6172 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006173 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006174 *
6175 * Return 0 on success, negative on failure
6176 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006177int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006178{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006179 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006180 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006181 int ring_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07006182 int size;
6183
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006184 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006185
6186 if (tx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006187 ring_node = tx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006188
Alexander Duyckffed21b2017-01-17 08:37:29 -08006189 tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006190 if (!tx_ring->tx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006191 tx_ring->tx_buffer_info = vmalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006192 if (!tx_ring->tx_buffer_info)
6193 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006194
6195 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08006196 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006197 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006198
Mark Rustadca8dfe22014-07-24 06:19:24 +00006199 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006200 tx_ring->desc = dma_alloc_coherent(dev,
6201 tx_ring->size,
6202 &tx_ring->dma,
6203 GFP_KERNEL);
6204 set_dev_node(dev, orig_node);
6205 if (!tx_ring->desc)
6206 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
6207 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006208 if (!tx_ring->desc)
6209 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006210
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006211 tx_ring->next_to_use = 0;
6212 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006213 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006214
6215err:
6216 vfree(tx_ring->tx_buffer_info);
6217 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006218 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07006219 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006220}
6221
6222/**
Alexander Duyck69888672008-09-11 20:05:39 -07006223 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
6224 * @adapter: board private structure
6225 *
6226 * If this function returns with an error, then it's possible one or
6227 * more of the rings is populated (while the rest are not). It is the
6228 * callers duty to clean those orphaned rings.
6229 *
6230 * Return 0 on success, negative on failure
6231 **/
6232static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
6233{
John Fastabend33fdc822017-04-24 03:30:18 -07006234 int i, j = 0, err = 0;
Alexander Duyck69888672008-09-11 20:05:39 -07006235
6236 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006237 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006238 if (!err)
6239 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006240
Emil Tantilov396e7992010-07-01 20:05:12 +00006241 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006242 goto err_setup_tx;
Alexander Duyck69888672008-09-11 20:05:39 -07006243 }
John Fastabend33fdc822017-04-24 03:30:18 -07006244 for (j = 0; j < adapter->num_xdp_queues; j++) {
6245 err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
6246 if (!err)
6247 continue;
6248
6249 e_err(probe, "Allocation for Tx Queue %u failed\n", j);
6250 goto err_setup_tx;
6251 }
Alexander Duyck69888672008-09-11 20:05:39 -07006252
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006253 return 0;
6254err_setup_tx:
6255 /* rewind the index freeing the rings as we go */
John Fastabend33fdc822017-04-24 03:30:18 -07006256 while (j--)
6257 ixgbe_free_tx_resources(adapter->xdp_ring[j]);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006258 while (i--)
6259 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006260 return err;
6261}
6262
6263/**
Auke Kok9a799d72007-09-15 14:07:45 -07006264 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Tony Nguyen5ba643c2017-12-04 11:28:30 -08006265 * @adapter: pointer to ixgbe_adapter
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006266 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07006267 *
6268 * Returns 0 on success, negative on failure
6269 **/
John Fastabend92470802017-04-24 03:30:17 -07006270int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
6271 struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006272{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006273 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006274 int orig_node = dev_to_node(dev);
Mark Rustadca8dfe22014-07-24 06:19:24 +00006275 int ring_node = -1;
Jesper Dangaard Brouer8d5d8852018-04-17 16:46:12 +02006276 int size, err;
Auke Kok9a799d72007-09-15 14:07:45 -07006277
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006278 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006279
6280 if (rx_ring->q_vector)
Mark Rustadca8dfe22014-07-24 06:19:24 +00006281 ring_node = rx_ring->q_vector->numa_node;
Alexander Duyckde88eee2012-02-08 07:49:59 +00006282
Alexander Duyckffed21b2017-01-17 08:37:29 -08006283 rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00006284 if (!rx_ring->rx_buffer_info)
Alexander Duyckffed21b2017-01-17 08:37:29 -08006285 rx_ring->rx_buffer_info = vmalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006286 if (!rx_ring->rx_buffer_info)
6287 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006288
Auke Kok9a799d72007-09-15 14:07:45 -07006289 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006290 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
6291 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07006292
Mark Rustadca8dfe22014-07-24 06:19:24 +00006293 set_dev_node(dev, ring_node);
Alexander Duyckde88eee2012-02-08 07:49:59 +00006294 rx_ring->desc = dma_alloc_coherent(dev,
6295 rx_ring->size,
6296 &rx_ring->dma,
6297 GFP_KERNEL);
6298 set_dev_node(dev, orig_node);
6299 if (!rx_ring->desc)
6300 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
6301 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006302 if (!rx_ring->desc)
6303 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07006304
Jesse Brandeburg3a581072008-08-26 04:27:08 -07006305 rx_ring->next_to_clean = 0;
6306 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006307
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006308 /* XDP RX-queue info */
6309 if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
6310 rx_ring->queue_index) < 0)
6311 goto err;
6312
Jesper Dangaard Brouer8d5d8852018-04-17 16:46:12 +02006313 err = xdp_rxq_info_reg_mem_model(&rx_ring->xdp_rxq,
6314 MEM_TYPE_PAGE_SHARED, NULL);
6315 if (err) {
6316 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
6317 goto err;
6318 }
6319
John Fastabend92470802017-04-24 03:30:17 -07006320 rx_ring->xdp_prog = adapter->xdp_prog;
6321
Auke Kok9a799d72007-09-15 14:07:45 -07006322 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006323err:
6324 vfree(rx_ring->rx_buffer_info);
6325 rx_ring->rx_buffer_info = NULL;
6326 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07006327 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07006328}
6329
6330/**
Alexander Duyck69888672008-09-11 20:05:39 -07006331 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
6332 * @adapter: board private structure
6333 *
6334 * If this function returns with an error, then it's possible one or
6335 * more of the rings is populated (while the rest are not). It is the
6336 * callers duty to clean those orphaned rings.
6337 *
6338 * Return 0 on success, negative on failure
6339 **/
Alexander Duyck69888672008-09-11 20:05:39 -07006340static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
6341{
6342 int i, err = 0;
6343
6344 for (i = 0; i < adapter->num_rx_queues; i++) {
John Fastabend92470802017-04-24 03:30:17 -07006345 err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006346 if (!err)
6347 continue;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006348
Emil Tantilov396e7992010-07-01 20:05:12 +00006349 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006350 goto err_setup_rx;
Alexander Duyck69888672008-09-11 20:05:39 -07006351 }
6352
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006353#ifdef IXGBE_FCOE
6354 err = ixgbe_setup_fcoe_ddp_resources(adapter);
6355 if (!err)
6356#endif
6357 return 0;
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006358err_setup_rx:
6359 /* rewind the index freeing the rings as we go */
6360 while (i--)
6361 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07006362 return err;
6363}
6364
6365/**
Auke Kok9a799d72007-09-15 14:07:45 -07006366 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07006367 * @tx_ring: Tx descriptor ring for a specific queue
6368 *
6369 * Free all transmit software resources
6370 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006371void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006372{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006373 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006374
6375 vfree(tx_ring->tx_buffer_info);
6376 tx_ring->tx_buffer_info = NULL;
6377
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006378 /* if not set, then don't free */
6379 if (!tx_ring->desc)
6380 return;
6381
6382 dma_free_coherent(tx_ring->dev, tx_ring->size,
6383 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006384
6385 tx_ring->desc = NULL;
6386}
6387
6388/**
6389 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
6390 * @adapter: board private structure
6391 *
6392 * Free all transmit software resources
6393 **/
6394static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
6395{
6396 int i;
6397
6398 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006399 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006400 ixgbe_free_tx_resources(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07006401 for (i = 0; i < adapter->num_xdp_queues; i++)
6402 if (adapter->xdp_ring[i]->desc)
6403 ixgbe_free_tx_resources(adapter->xdp_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006404}
6405
6406/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006407 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07006408 * @rx_ring: ring to clean the resources from
6409 *
6410 * Free all receive software resources
6411 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006412void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006413{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006414 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07006415
John Fastabend92470802017-04-24 03:30:17 -07006416 rx_ring->xdp_prog = NULL;
Jesper Dangaard Brouer99ffc5a2018-01-03 11:25:29 +01006417 xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
Auke Kok9a799d72007-09-15 14:07:45 -07006418 vfree(rx_ring->rx_buffer_info);
6419 rx_ring->rx_buffer_info = NULL;
6420
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006421 /* if not set, then don't free */
6422 if (!rx_ring->desc)
6423 return;
6424
6425 dma_free_coherent(rx_ring->dev, rx_ring->size,
6426 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07006427
6428 rx_ring->desc = NULL;
6429}
6430
6431/**
6432 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
6433 * @adapter: board private structure
6434 *
6435 * Free all receive software resources
6436 **/
6437static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
6438{
6439 int i;
6440
Alexander Duyck7c8ae652012-05-05 05:32:47 +00006441#ifdef IXGBE_FCOE
6442 ixgbe_free_fcoe_ddp_resources(adapter);
6443
6444#endif
Auke Kok9a799d72007-09-15 14:07:45 -07006445 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006446 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006447 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07006448}
6449
6450/**
Auke Kok9a799d72007-09-15 14:07:45 -07006451 * ixgbe_change_mtu - Change the Maximum Transfer Unit
6452 * @netdev: network interface device structure
6453 * @new_mtu: new value for maximum frame size
6454 *
6455 * Returns 0 on success, negative on failure
6456 **/
6457static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
6458{
6459 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck655309e2012-02-08 07:50:35 +00006460
6461 /*
Alexander Duyck872844d2012-08-15 02:10:43 +00006462 * For 82599EB we cannot allow legacy VFs to enable their receive
6463 * paths when MTU greater than 1500 is configured. So display a
6464 * warning that legacy VFs will be disabled.
Alexander Duyck655309e2012-02-08 07:50:35 +00006465 */
6466 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
6467 (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
Jarod Wilson91c527a2016-10-17 15:54:05 -04006468 (new_mtu > ETH_DATA_LEN))
Alexander Duyck872844d2012-08-15 02:10:43 +00006469 e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006470
Emil Tantilov396e7992010-07-01 20:05:12 +00006471 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Alexander Duyck655309e2012-02-08 07:50:35 +00006472
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006473 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07006474 netdev->mtu = new_mtu;
6475
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08006476 if (netif_running(netdev))
6477 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006478
6479 return 0;
6480}
6481
6482/**
6483 * ixgbe_open - Called when a network interface is made active
6484 * @netdev: network interface device structure
6485 *
6486 * Returns 0 on success, negative value on failure
6487 *
6488 * The open entry point is called when a network interface is made
6489 * active by the system (IFF_UP). At this point all resources needed
6490 * for transmit and receive operations are allocated, the interrupt
6491 * handler is registered with the OS, the watchdog timer is started,
6492 * and the stack is notified that the interface is ready.
6493 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006494int ixgbe_open(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006495{
6496 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Don Skidmore961fac82015-06-09 16:09:47 -07006497 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend2a47fa42013-11-06 09:54:52 -08006498 int err, queues;
Auke Kok9a799d72007-09-15 14:07:45 -07006499
Auke Kok4bebfaa2008-02-11 09:26:01 -08006500 /* disallow open during test */
6501 if (test_bit(__IXGBE_TESTING, &adapter->state))
6502 return -EBUSY;
6503
Jesse Brandeburg54386462009-04-17 20:44:27 +00006504 netif_carrier_off(netdev);
6505
Auke Kok9a799d72007-09-15 14:07:45 -07006506 /* allocate transmit descriptors */
6507 err = ixgbe_setup_all_tx_resources(adapter);
6508 if (err)
6509 goto err_setup_tx;
6510
Auke Kok9a799d72007-09-15 14:07:45 -07006511 /* allocate receive descriptors */
6512 err = ixgbe_setup_all_rx_resources(adapter);
6513 if (err)
6514 goto err_setup_rx;
6515
6516 ixgbe_configure(adapter);
6517
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08006518 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006519 if (err)
6520 goto err_req_irq;
6521
Alexander Duyckac802f52012-07-12 05:52:53 +00006522 /* Notify the stack of the actual queue counts. */
Alexander Duyck49cfbeb2017-11-22 10:57:35 -08006523 queues = adapter->num_tx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08006524 err = netif_set_real_num_tx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006525 if (err)
6526 goto err_set_queues;
6527
Alexander Duyck49cfbeb2017-11-22 10:57:35 -08006528 queues = adapter->num_rx_queues;
John Fastabend2a47fa42013-11-06 09:54:52 -08006529 err = netif_set_real_num_rx_queues(netdev, queues);
Alexander Duyckac802f52012-07-12 05:52:53 +00006530 if (err)
6531 goto err_set_queues;
6532
Jacob Keller1a71ab22012-08-25 03:54:19 +00006533 ixgbe_ptp_init(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006534
Alexander Duyckc7ccde02011-07-21 00:40:40 +00006535 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006536
Emil Tantilova21d0822016-08-10 11:19:23 -07006537 ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
Alexander Duyckb3a49552016-06-16 12:22:19 -07006538 udp_tunnel_get_rx_info(netdev);
Mark Rustad67359c32015-06-15 11:33:25 -07006539
Auke Kok9a799d72007-09-15 14:07:45 -07006540 return 0;
6541
Alexander Duyckac802f52012-07-12 05:52:53 +00006542err_set_queues:
6543 ixgbe_free_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006544err_req_irq:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006545 ixgbe_free_all_rx_resources(adapter);
Don Skidmore961fac82015-06-09 16:09:47 -07006546 if (hw->phy.ops.set_phy_power && !adapter->wol)
6547 hw->phy.ops.set_phy_power(&adapter->hw, false);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006548err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00006549 ixgbe_free_all_tx_resources(adapter);
Alexander Duyckde3d5b92012-05-18 06:33:47 +00006550err_setup_tx:
Auke Kok9a799d72007-09-15 14:07:45 -07006551 ixgbe_reset(adapter);
6552
6553 return err;
6554}
6555
Jacob Kellera0cccce2014-05-16 05:12:29 +00006556static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
6557{
6558 ixgbe_ptp_suspend(adapter);
6559
Don Skidmore6ac74392015-06-17 17:34:31 -04006560 if (adapter->hw.phy.ops.enter_lplu) {
6561 adapter->hw.phy.reset_disable = true;
6562 ixgbe_down(adapter);
6563 adapter->hw.phy.ops.enter_lplu(&adapter->hw);
6564 adapter->hw.phy.reset_disable = false;
6565 } else {
6566 ixgbe_down(adapter);
6567 }
6568
Jacob Kellera0cccce2014-05-16 05:12:29 +00006569 ixgbe_free_irq(adapter);
6570
6571 ixgbe_free_all_tx_resources(adapter);
6572 ixgbe_free_all_rx_resources(adapter);
6573}
6574
Auke Kok9a799d72007-09-15 14:07:45 -07006575/**
6576 * ixgbe_close - Disables a network interface
6577 * @netdev: network interface device structure
6578 *
6579 * Returns 0, this is not allowed to fail
6580 *
6581 * The close entry point is called when an interface is de-activated
6582 * by the OS. The hardware is still under the drivers control, but
6583 * needs to be disabled. A global MAC reset is issued to stop the
6584 * hardware, and all transmit and receive resources are freed.
6585 **/
Stefan Assmann6c211fe12016-02-03 09:20:48 +01006586int ixgbe_close(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07006587{
6588 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006589
Jacob Keller1a71ab22012-08-25 03:54:19 +00006590 ixgbe_ptp_stop(adapter);
Jacob Keller1a71ab22012-08-25 03:54:19 +00006591
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006592 if (netif_device_present(netdev))
6593 ixgbe_close_suspend(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006594
Alexander Duycke4911d52011-05-11 07:18:52 +00006595 ixgbe_fdir_filter_exit(adapter);
6596
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08006597 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006598
6599 return 0;
6600}
6601
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006602#ifdef CONFIG_PM
6603static int ixgbe_resume(struct pci_dev *pdev)
6604{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006605 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6606 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006607 u32 err;
6608
Mark Rustad0391bbe2014-02-28 15:48:55 -08006609 adapter->hw.hw_addr = adapter->io_addr;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006610 pci_set_power_state(pdev, PCI_D0);
6611 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08006612 /*
6613 * pci_restore_state clears dev->state_saved so call
6614 * pci_save_state to restore it.
6615 */
6616 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00006617
6618 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006619 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006620 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006621 return err;
6622 }
Peter Zijlstra4e857c52014-03-17 18:06:10 +01006623 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +00006624 clear_bit(__IXGBE_DISABLED, &adapter->state);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006625 pci_set_master(pdev);
6626
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006627 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006628
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006629 ixgbe_reset(adapter);
6630
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00006631 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
6632
Alexander Duyckac802f52012-07-12 05:52:53 +00006633 rtnl_lock();
6634 err = ixgbe_init_interrupt_scheme(adapter);
6635 if (!err && netif_running(netdev))
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006636 err = ixgbe_open(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006637
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006638
6639 if (!err)
6640 netif_device_attach(netdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00006641 rtnl_unlock();
6642
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006643 return err;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006644}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006645#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006646
6647static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006648{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08006649 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
6650 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006651 struct ixgbe_hw *hw = &adapter->hw;
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006652 u32 ctrl;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006653 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006654#ifdef CONFIG_PM
6655 int retval = 0;
6656#endif
6657
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006658 rtnl_lock();
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006659 netif_device_detach(netdev);
6660
Jeff Kirsherf0b99e3a2018-05-18 11:58:30 -07006661 if (netif_running(netdev))
Jacob Kellera0cccce2014-05-16 05:12:29 +00006662 ixgbe_close_suspend(adapter);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006663
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006664 ixgbe_clear_interrupt_scheme(adapter);
Emil Tantilovf7f37e72016-11-11 10:07:47 -08006665 rtnl_unlock();
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08006666
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006667#ifdef CONFIG_PM
6668 retval = pci_save_state(pdev);
6669 if (retval)
6670 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00006671
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006672#endif
Jacob Kellerf4f10402013-06-25 07:59:23 +00006673 if (hw->mac.ops.stop_link_on_d3)
6674 hw->mac.ops.stop_link_on_d3(hw);
6675
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006676 if (wufc) {
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006677 u32 fctrl;
6678
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006679 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006680
Emil Tantilovec74a472012-09-20 03:33:56 +00006681 /* enable the optics for 82599 SFP+ fiber as we can WoL */
6682 if (hw->mac.ops.enable_tx_laser)
Don Skidmorec509e752012-04-05 08:12:05 +00006683 hw->mac.ops.enable_tx_laser(hw);
6684
Emil Tantilovd9d11eb2017-10-10 13:20:01 -07006685 /* enable the reception of multicast packets */
6686 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6687 fctrl |= IXGBE_FCTRL_MPE;
6688 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006689
6690 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
6691 ctrl |= IXGBE_CTRL_GIO_DIS;
6692 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
6693
6694 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
6695 } else {
6696 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
6697 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
6698 }
6699
Alexander Duyckbd508172010-11-16 19:27:03 -08006700 switch (hw->mac.type) {
6701 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07006702 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08006703 break;
6704 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006705 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006706 case ixgbe_mac_X550:
6707 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006708 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006709 pci_wake_from_d3(pdev, !!wufc);
6710 break;
6711 default:
6712 break;
6713 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006714
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006715 *enable_wake = !!wufc;
Don Skidmore961fac82015-06-09 16:09:47 -07006716 if (hw->phy.ops.set_phy_power && !*enable_wake)
6717 hw->phy.ops.set_phy_power(hw, false);
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006718
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006719 ixgbe_release_hw_control(adapter);
6720
Mark Rustad41c62842014-03-12 00:38:35 +00006721 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
6722 pci_disable_device(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006723
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006724 return 0;
6725}
6726
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006727#ifdef CONFIG_PM
6728static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
6729{
6730 int retval;
6731 bool wake;
6732
6733 retval = __ixgbe_shutdown(pdev, &wake);
6734 if (retval)
6735 return retval;
6736
6737 if (wake) {
6738 pci_prepare_to_sleep(pdev);
6739 } else {
6740 pci_wake_from_d3(pdev, false);
6741 pci_set_power_state(pdev, PCI_D3hot);
6742 }
6743
6744 return 0;
6745}
6746#endif /* CONFIG_PM */
6747
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006748static void ixgbe_shutdown(struct pci_dev *pdev)
6749{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00006750 bool wake;
6751
6752 __ixgbe_shutdown(pdev, &wake);
6753
6754 if (system_state == SYSTEM_POWER_OFF) {
6755 pci_wake_from_d3(pdev, wake);
6756 pci_set_power_state(pdev, PCI_D3hot);
6757 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07006758}
6759
6760/**
Auke Kok9a799d72007-09-15 14:07:45 -07006761 * ixgbe_update_stats - Update the board statistics counters.
6762 * @adapter: board private structure
6763 **/
6764void ixgbe_update_stats(struct ixgbe_adapter *adapter)
6765{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006766 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07006767 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006768 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006769 u64 total_mpc = 0;
6770 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006771 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
6772 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006773 u64 alloc_rx_page = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006774 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006775
Don Skidmored08935c2010-06-11 13:20:29 +00006776 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6777 test_bit(__IXGBE_RESETTING, &adapter->state))
6778 return;
6779
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006780 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00006781 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006782 u64 rsc_flush = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006783 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006784 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
6785 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00006786 }
6787 adapter->rsc_total_count = rsc_count;
6788 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00006789 }
6790
Alexander Duyck5b7da512010-11-16 19:26:50 -08006791 for (i = 0; i < adapter->num_rx_queues; i++) {
6792 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
6793 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006794 alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006795 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
6796 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006797 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006798 bytes += rx_ring->stats.bytes;
6799 packets += rx_ring->stats.packets;
6800 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00006801 adapter->non_eop_descs = non_eop_descs;
Jesper Dangaard Brouer86e23492017-09-04 20:40:22 +02006802 adapter->alloc_rx_page = alloc_rx_page;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006803 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
6804 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00006805 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08006806 netdev->stats.rx_bytes = bytes;
6807 netdev->stats.rx_packets = packets;
6808
6809 bytes = 0;
6810 packets = 0;
6811 /* gather some stats to the adapter struct that are per queue */
6812 for (i = 0; i < adapter->num_tx_queues; i++) {
6813 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6814 restart_queue += tx_ring->tx_stats.restart_queue;
6815 tx_busy += tx_ring->tx_stats.tx_busy;
6816 bytes += tx_ring->stats.bytes;
6817 packets += tx_ring->stats.packets;
6818 }
John Fastabend33fdc822017-04-24 03:30:18 -07006819 for (i = 0; i < adapter->num_xdp_queues; i++) {
6820 struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
6821
6822 restart_queue += xdp_ring->tx_stats.restart_queue;
6823 tx_busy += xdp_ring->tx_stats.tx_busy;
6824 bytes += xdp_ring->stats.bytes;
6825 packets += xdp_ring->stats.packets;
6826 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08006827 adapter->restart_queue = restart_queue;
6828 adapter->tx_busy = tx_busy;
6829 netdev->stats.tx_bytes = bytes;
6830 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00006831
Joe Perches7ca647b2010-09-07 21:35:40 +00006832 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006833
6834 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006835 for (i = 0; i < 8; i++) {
6836 /* for packet buffers not used, the register should read 0 */
6837 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
6838 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00006839 hwstats->mpc[i] += mpc;
6840 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006841 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
6842 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006843 switch (hw->mac.type) {
6844 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006845 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
6846 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
6847 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006848 hwstats->pxonrxc[i] +=
6849 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006850 break;
6851 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08006852 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006853 case ixgbe_mac_X550:
6854 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006855 case ixgbe_mac_x550em_a:
Alexander Duyckbd508172010-11-16 19:27:03 -08006856 hwstats->pxonrxc[i] +=
6857 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08006858 break;
6859 default:
6860 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006861 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006862 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006863
6864 /*16 register reads */
6865 for (i = 0; i < 16; i++) {
6866 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
6867 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
6868 if ((hw->mac.type == ixgbe_mac_82599EB) ||
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006869 (hw->mac.type == ixgbe_mac_X540) ||
6870 (hw->mac.type == ixgbe_mac_X550) ||
Mark Rustad49425df2016-04-01 12:18:09 -07006871 (hw->mac.type == ixgbe_mac_X550EM_x) ||
6872 (hw->mac.type == ixgbe_mac_x550em_a)) {
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00006873 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
6874 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
6875 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
6876 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
6877 }
6878 }
6879
Joe Perches7ca647b2010-09-07 21:35:40 +00006880 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006881 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00006882 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07006883
John Fastabendc84d3242010-11-16 19:27:12 -08006884 ixgbe_update_xoff_received(adapter);
6885
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006886 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08006887 switch (hw->mac.type) {
6888 case ixgbe_mac_82598EB:
6889 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08006890 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
6891 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
6892 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
6893 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006894 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006895 case ixgbe_mac_X550:
6896 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07006897 case ixgbe_mac_x550em_a:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00006898 /* OS2BMC stats are X540 and later */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006899 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
6900 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
6901 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
6902 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
Tony Nguyen93df9462017-05-31 04:43:47 -07006903 /* fall through */
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00006904 case ixgbe_mac_82599EB:
Alexander Duycka4d4f622012-03-28 08:03:32 +00006905 for (i = 0; i < 16; i++)
6906 adapter->hw_rx_no_dma_resources +=
6907 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00006908 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006909 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006910 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006911 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006912 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08006913 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00006914 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00006915 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
6916 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00006917#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00006918 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
6919 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
6920 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
6921 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
6922 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
6923 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00006924 /* Add up per cpu counters for total ddp aloc fail */
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006925 if (adapter->fcoe.ddp_pool) {
6926 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
6927 struct ixgbe_fcoe_ddp_pool *ddp_pool;
6928 unsigned int cpu;
6929 u64 noddp = 0, noddp_ext_buff = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006930 for_each_possible_cpu(cpu) {
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006931 ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
6932 noddp += ddp_pool->noddp;
6933 noddp_ext_buff += ddp_pool->noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006934 }
Alexander Duyck5a1ee272012-05-05 17:14:28 +00006935 hwstats->fcoe_noddp = noddp;
6936 hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
Amir Hanania7b859eb2011-08-31 02:07:55 +00006937 }
Yi Zou6d455222009-05-13 13:12:16 +00006938#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08006939 break;
6940 default:
6941 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006942 }
Auke Kok9a799d72007-09-15 14:07:45 -07006943 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006944 hwstats->bprc += bprc;
6945 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006946 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00006947 hwstats->mprc -= bprc;
6948 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
6949 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
6950 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
6951 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
6952 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
6953 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
6954 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
6955 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006956 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006957 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006958 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00006959 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006960 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
6961 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08006962 /*
6963 * 82598 errata - tx of flow control packets is included in tx counters
6964 */
6965 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00006966 hwstats->gptc -= xon_off_tot;
6967 hwstats->mptc -= xon_off_tot;
6968 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
6969 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
6970 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
6971 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
6972 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
6973 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
6974 hwstats->ptc64 -= xon_off_tot;
6975 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
6976 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
6977 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
6978 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
6979 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
6980 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07006981
6982 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00006983 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07006984
6985 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00006986 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006987 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006988 netdev->stats.rx_length_errors = hwstats->rlec;
6989 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00006990 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07006991}
6992
6993/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00006994 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
Ben Hutchings49ce9c22012-07-10 10:56:00 +00006995 * @adapter: pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07006996 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00006997static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07006998{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006999 struct ixgbe_hw *hw = &adapter->hw;
7000 int i;
7001
Alexander Duyckd034acf2011-04-27 09:25:34 +00007002 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
7003 return;
7004
7005 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
7006
7007 /* if interface is down do nothing */
7008 if (test_bit(__IXGBE_DOWN, &adapter->state))
7009 return;
7010
7011 /* do nothing if we are not using signature filters */
7012 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
7013 return;
7014
7015 adapter->fdir_overflow++;
7016
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007017 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
7018 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08007019 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Jacob Kellere7cf7452014-04-09 06:03:10 +00007020 &(adapter->tx_ring[i]->state));
John Fastabend33fdc822017-04-24 03:30:18 -07007021 for (i = 0; i < adapter->num_xdp_queues; i++)
7022 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
7023 &adapter->xdp_ring[i]->state);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007024 /* re-enable flow director interrupts */
7025 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007026 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00007027 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00007028 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007029 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007030}
7031
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007032/**
7033 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007034 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007035 *
7036 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007037 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007038 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007039 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007040 */
7041static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
7042{
Auke Kok9a799d72007-09-15 14:07:45 -07007043 struct ixgbe_hw *hw = &adapter->hw;
7044 u64 eics = 0;
7045 int i;
7046
Mark Rustad09f40ae2014-01-14 18:53:11 -08007047 /* If we're down, removing or resetting, just bail */
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007048 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007049 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007050 test_bit(__IXGBE_RESETTING, &adapter->state))
7051 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00007052
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007053 /* Force detection of hung controller */
7054 if (netif_carrier_ok(adapter->netdev)) {
7055 for (i = 0; i < adapter->num_tx_queues; i++)
7056 set_check_for_tx_hang(adapter->tx_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07007057 for (i = 0; i < adapter->num_xdp_queues; i++)
7058 set_check_for_tx_hang(adapter->xdp_ring[i]);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007059 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007060
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007061 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00007062 /*
7063 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00007064 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00007065 * would set *both* EIMS and EICS for any bit in EIAM
7066 */
7067 IXGBE_WRITE_REG(hw, IXGBE_EICS,
7068 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007069 } else {
7070 /* get one bit for every active tx/rx interrupt vector */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00007071 for (i = 0; i < adapter->num_q_vectors; i++) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007072 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00007073 if (qv->rx.ring || qv->tx.ring)
Jacob Kellerb4f47a42016-04-13 16:08:22 -07007074 eics |= BIT_ULL(i);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007075 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00007076 }
7077
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007078 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00007079 ixgbe_irq_rearm_queues(adapter, eics);
Alexander Duyckfe49f042009-06-04 16:00:09 +00007080}
7081
7082/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007083 * ixgbe_watchdog_update_link - update the link status
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007084 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007085 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007086static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007087{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007088 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007089 u32 link_speed = adapter->link_speed;
7090 bool link_up = adapter->link_up;
Alexander Duyck041441d2012-04-19 17:48:48 +00007091 bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007092
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007093 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
7094 return;
7095
7096 if (hw->mac.ops.check_link) {
7097 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007098 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007099 /* always assume link is up, if no check link function */
7100 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
7101 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007102 }
Alexander Duyck041441d2012-04-19 17:48:48 +00007103
7104 if (adapter->ixgbe_ieee_pfc)
7105 pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
7106
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007107 if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
Alexander Duyck041441d2012-04-19 17:48:48 +00007108 hw->mac.ops.fc_enable(hw);
Alexander Duyck3ebe8fd2012-04-25 04:36:38 +00007109 ixgbe_set_rx_drop_en(adapter);
7110 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007111
7112 if (link_up ||
7113 time_after(jiffies, (adapter->link_check_timeout +
7114 IXGBE_TRY_LINK_TIMEOUT))) {
7115 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
7116 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
7117 IXGBE_WRITE_FLUSH(hw);
7118 }
7119
7120 adapter->link_up = link_up;
7121 adapter->link_speed = link_speed;
7122}
7123
Alexander Duyck107d3012012-10-02 00:17:03 +00007124static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
7125{
7126#ifdef CONFIG_IXGBE_DCB
7127 struct net_device *netdev = adapter->netdev;
7128 struct dcb_app app = {
7129 .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
7130 .protocol = 0,
7131 };
7132 u8 up = 0;
7133
7134 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
7135 up = dcb_ieee_getapp_mask(netdev, &app);
7136
7137 adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
7138#endif
7139}
7140
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007141/**
7142 * ixgbe_watchdog_link_is_up - update netif_carrier status and
7143 * print link up message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007144 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007145 **/
7146static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
7147{
7148 struct net_device *netdev = adapter->netdev;
7149 struct ixgbe_hw *hw = &adapter->hw;
7150 u32 link_speed = adapter->link_speed;
Mark Rustad454adb02015-07-10 14:19:22 -07007151 const char *speed_str;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007152 bool flow_rx, flow_tx;
7153
7154 /* only continue if link was previously down */
7155 if (netif_carrier_ok(netdev))
7156 return;
7157
7158 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
7159
7160 switch (hw->mac.type) {
7161 case ixgbe_mac_82598EB: {
7162 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
7163 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
7164 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
7165 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
7166 }
7167 break;
7168 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007169 case ixgbe_mac_X550:
7170 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -07007171 case ixgbe_mac_x550em_a:
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007172 case ixgbe_mac_82599EB: {
7173 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
7174 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
7175 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
7176 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
7177 }
7178 break;
7179 default:
7180 flow_tx = false;
7181 flow_rx = false;
7182 break;
7183 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007184
Jacob Keller6cb562d2012-12-05 07:24:41 +00007185 adapter->last_rx_ptp_check = jiffies;
7186
Jacob Keller8fecf672013-06-21 08:14:32 +00007187 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007188 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007189
Mark Rustad454adb02015-07-10 14:19:22 -07007190 switch (link_speed) {
7191 case IXGBE_LINK_SPEED_10GB_FULL:
7192 speed_str = "10 Gbps";
7193 break;
Paul Greenwalt06e3f942018-01-11 09:10:51 -05007194 case IXGBE_LINK_SPEED_5GB_FULL:
7195 speed_str = "5 Gbps";
7196 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007197 case IXGBE_LINK_SPEED_2_5GB_FULL:
7198 speed_str = "2.5 Gbps";
7199 break;
7200 case IXGBE_LINK_SPEED_1GB_FULL:
7201 speed_str = "1 Gbps";
7202 break;
7203 case IXGBE_LINK_SPEED_100_FULL:
7204 speed_str = "100 Mbps";
7205 break;
Mark Rustadb3eb4e12016-12-14 11:02:16 -08007206 case IXGBE_LINK_SPEED_10_FULL:
7207 speed_str = "10 Mbps";
7208 break;
Mark Rustad454adb02015-07-10 14:19:22 -07007209 default:
7210 speed_str = "unknown speed";
7211 break;
7212 }
7213 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007214 ((flow_rx && flow_tx) ? "RX/TX" :
7215 (flow_rx ? "RX" :
7216 (flow_tx ? "TX" : "None"))));
7217
7218 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007219 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007220
Emil Tantilovcdc04dc2014-03-20 03:47:53 +00007221 /* enable transmits */
7222 netif_tx_wake_all_queues(adapter->netdev);
7223
Alexander Duyck107d3012012-10-02 00:17:03 +00007224 /* update the default user priority for VFs */
7225 ixgbe_update_default_up(adapter);
7226
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007227 /* ping all the active vfs to let them know link has changed */
7228 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007229}
7230
7231/**
7232 * ixgbe_watchdog_link_is_down - update netif_carrier status and
7233 * print link down message
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007234 * @adapter: pointer to the adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007235 **/
Alexander Duyck581330b2012-02-08 07:51:47 +00007236static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007237{
7238 struct net_device *netdev = adapter->netdev;
7239 struct ixgbe_hw *hw = &adapter->hw;
7240
7241 adapter->link_up = false;
7242 adapter->link_speed = 0;
7243
7244 /* only continue if link was up previously */
7245 if (!netif_carrier_ok(netdev))
7246 return;
7247
7248 /* poll for SFP+ cable when link is down */
7249 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
7250 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
7251
Jacob Keller8fecf672013-06-21 08:14:32 +00007252 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
Jacob Keller1a71ab22012-08-25 03:54:19 +00007253 ixgbe_ptp_start_cyclecounter(adapter);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007254
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007255 e_info(drv, "NIC Link is Down\n");
7256 netif_carrier_off(netdev);
Alexander Duyckbefa2af2012-05-05 05:30:38 +00007257
7258 /* ping all the active vfs to let them know link has changed */
7259 ixgbe_ping_all_vfs(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007260}
7261
Emil Tantilov07923c12014-08-12 07:12:08 +00007262static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
7263{
7264 int i;
7265
7266 for (i = 0; i < adapter->num_tx_queues; i++) {
7267 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
7268
7269 if (tx_ring->next_to_use != tx_ring->next_to_clean)
7270 return true;
7271 }
7272
John Fastabend33fdc822017-04-24 03:30:18 -07007273 for (i = 0; i < adapter->num_xdp_queues; i++) {
7274 struct ixgbe_ring *ring = adapter->xdp_ring[i];
7275
7276 if (ring->next_to_use != ring->next_to_clean)
7277 return true;
7278 }
7279
Emil Tantilov07923c12014-08-12 07:12:08 +00007280 return false;
7281}
7282
7283static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
7284{
7285 struct ixgbe_hw *hw = &adapter->hw;
7286 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
7287 u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
7288
7289 int i, j;
7290
7291 if (!adapter->num_vfs)
7292 return false;
7293
Don Skidmore9a75a1a2014-11-07 03:53:35 +00007294 /* resetting the PF is only needed for MAC before X550 */
7295 if (hw->mac.type >= ixgbe_mac_X550)
7296 return false;
7297
Emil Tantilov07923c12014-08-12 07:12:08 +00007298 for (i = 0; i < adapter->num_vfs; i++) {
7299 for (j = 0; j < q_per_pool; j++) {
7300 u32 h, t;
7301
7302 h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
7303 t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
7304
7305 if (h != t)
7306 return true;
7307 }
7308 }
7309
7310 return false;
7311}
7312
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007313/**
7314 * ixgbe_watchdog_flush_tx - flush queues on link down
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007315 * @adapter: pointer to the device adapter structure
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007316 **/
7317static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
7318{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007319 if (!netif_carrier_ok(adapter->netdev)) {
Emil Tantilov07923c12014-08-12 07:12:08 +00007320 if (ixgbe_ring_tx_pending(adapter) ||
7321 ixgbe_vf_tx_pending(adapter)) {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007322 /* We've lost link, so the controller stops DMA,
7323 * but we've got queued Tx work that's never going
7324 * to get done, so reset controller to flush Tx.
7325 * (Do the reset outside of interrupt context).
7326 */
Jacob Keller12ff3f32012-12-01 07:57:17 +00007327 e_warn(drv, "initiating reset to clear Tx work after link loss\n");
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007328 set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007329 }
7330 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007331}
7332
Emil Tantilov9079e412014-11-19 03:18:19 +00007333#ifdef CONFIG_PCI_IOV
Emil Tantilov9079e412014-11-19 03:18:19 +00007334static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
7335{
7336 struct ixgbe_hw *hw = &adapter->hw;
7337 struct pci_dev *pdev = adapter->pdev;
Mark Rustad988d1302015-10-30 15:29:34 -07007338 unsigned int vf;
Emil Tantilov9079e412014-11-19 03:18:19 +00007339 u32 gpc;
Emil Tantilov9079e412014-11-19 03:18:19 +00007340
7341 if (!(netif_carrier_ok(adapter->netdev)))
7342 return;
7343
7344 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
7345 if (gpc) /* If incrementing then no need for the check below */
7346 return;
7347 /* Check to see if a bad DMA write target from an errant or
7348 * malicious VF has caused a PCIe error. If so then we can
7349 * issue a VFLR to the offending VF(s) and then resume without
7350 * requesting a full slot reset.
7351 */
7352
7353 if (!pdev)
7354 return;
7355
Emil Tantilov9079e412014-11-19 03:18:19 +00007356 /* check status reg for all VFs owned by this PF */
Mark Rustad988d1302015-10-30 15:29:34 -07007357 for (vf = 0; vf < adapter->num_vfs; ++vf) {
7358 struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
7359 u16 status_reg;
Emil Tantilov9079e412014-11-19 03:18:19 +00007360
Mark Rustad988d1302015-10-30 15:29:34 -07007361 if (!vfdev)
7362 continue;
7363 pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
7364 if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
7365 status_reg & PCI_STATUS_REC_MASTER_ABORT)
Christoph Hellwig63af8f72017-04-14 21:11:28 +02007366 pcie_flr(vfdev);
Emil Tantilov9079e412014-11-19 03:18:19 +00007367 }
7368}
7369
Greg Rosea985b6c32010-11-18 03:02:52 +00007370static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
7371{
7372 u32 ssvpc;
7373
Greg Rose0584d992012-08-08 00:00:58 +00007374 /* Do not perform spoof check for 82598 or if not in IOV mode */
7375 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
7376 adapter->num_vfs == 0)
Greg Rosea985b6c32010-11-18 03:02:52 +00007377 return;
7378
7379 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
7380
7381 /*
7382 * ssvpc register is cleared on read, if zero then no
7383 * spoofed packets in the last interval.
7384 */
7385 if (!ssvpc)
7386 return;
7387
Emil Tantilovd6ea0752012-08-08 06:28:37 +00007388 e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
Greg Rosea985b6c32010-11-18 03:02:52 +00007389}
Emil Tantilov9079e412014-11-19 03:18:19 +00007390#else
7391static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
7392{
7393}
7394
7395static void
7396ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
7397{
7398}
7399#endif /* CONFIG_PCI_IOV */
7400
Greg Rosea985b6c32010-11-18 03:02:52 +00007401
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007402/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007403 * ixgbe_watchdog_subtask - check and bring link up
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007404 * @adapter: pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007405 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007406static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007407{
Mark Rustad09f40ae2014-01-14 18:53:11 -08007408 /* if interface is down, removing or resetting, do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00007409 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007410 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Emil Tantilov7edebf92011-08-27 07:18:37 +00007411 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007412 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007413
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007414 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00007415
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007416 if (adapter->link_up)
7417 ixgbe_watchdog_link_is_up(adapter);
7418 else
7419 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00007420
Emil Tantilov9079e412014-11-19 03:18:19 +00007421 ixgbe_check_for_bad_vf(adapter);
Greg Rosea985b6c32010-11-18 03:02:52 +00007422 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007423 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007424
7425 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007426}
7427
Alexander Duyck70864002011-04-27 09:13:56 +00007428/**
7429 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007430 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007431 **/
7432static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
7433{
7434 struct ixgbe_hw *hw = &adapter->hw;
7435 s32 err;
7436
7437 /* not searching for SFP so there is nothing to do here */
7438 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
7439 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7440 return;
7441
Mark Rustad58e7cd22015-08-08 16:18:48 -07007442 if (adapter->sfp_poll_time &&
7443 time_after(adapter->sfp_poll_time, jiffies))
7444 return; /* If not yet time to poll for SFP */
7445
Alexander Duyck70864002011-04-27 09:13:56 +00007446 /* someone else is in init, wait until next service event */
7447 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7448 return;
7449
Mark Rustad58e7cd22015-08-08 16:18:48 -07007450 adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
7451
Alexander Duyck70864002011-04-27 09:13:56 +00007452 err = hw->phy.ops.identify_sfp(hw);
7453 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7454 goto sfp_out;
7455
7456 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
7457 /* If no cable is present, then we need to reset
7458 * the next time we find a good cable. */
7459 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
7460 }
7461
7462 /* exit on error */
7463 if (err)
7464 goto sfp_out;
7465
7466 /* exit if reset not needed */
7467 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
7468 goto sfp_out;
7469
7470 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
7471
7472 /*
7473 * A module may be identified correctly, but the EEPROM may not have
7474 * support for that module. setup_sfp() will fail in that case, so
7475 * we should not allow that module to load.
7476 */
7477 if (hw->mac.type == ixgbe_mac_82598EB)
7478 err = hw->phy.ops.reset(hw);
7479 else
7480 err = hw->mac.ops.setup_sfp(hw);
7481
7482 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
7483 goto sfp_out;
7484
7485 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
7486 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
7487
7488sfp_out:
7489 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7490
7491 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
7492 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
7493 e_dev_err("failed to initialize because an unsupported "
7494 "SFP+ module type was detected.\n");
7495 e_dev_err("Reload the driver after installing a "
7496 "supported module.\n");
7497 unregister_netdev(adapter->netdev);
7498 }
7499}
7500
7501/**
7502 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
Ben Hutchings49ce9c22012-07-10 10:56:00 +00007503 * @adapter: the ixgbe adapter structure
Alexander Duyck70864002011-04-27 09:13:56 +00007504 **/
7505static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
7506{
7507 struct ixgbe_hw *hw = &adapter->hw;
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007508 u32 cap_speed;
Josh Hay3d292262012-12-15 03:28:19 +00007509 u32 speed;
7510 bool autoneg = false;
Alexander Duyck70864002011-04-27 09:13:56 +00007511
7512 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
7513 return;
7514
7515 /* someone else is in init, wait until next service event */
7516 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
7517 return;
7518
7519 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
7520
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007521 hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007522
Paul Greenwalt3ead7c22017-10-24 11:00:40 -04007523 /* advertise highest capable link speed */
7524 if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
7525 speed = IXGBE_LINK_SPEED_10GB_FULL;
7526 else
7527 speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
7528 IXGBE_LINK_SPEED_1GB_FULL);
Emil Tantiloved33ff62013-08-30 07:55:24 +00007529
Alexander Duyck70864002011-04-27 09:13:56 +00007530 if (hw->mac.ops.setup_link)
Josh Hayfd0326f2012-12-15 03:28:30 +00007531 hw->mac.ops.setup_link(hw, speed, true);
Alexander Duyck70864002011-04-27 09:13:56 +00007532
7533 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
7534 adapter->link_check_timeout = jiffies;
7535 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
7536}
7537
7538/**
7539 * ixgbe_service_timer - Timer Call-back
Tony Nguyen5ba643c2017-12-04 11:28:30 -08007540 * @t: pointer to timer_list structure
Alexander Duyck70864002011-04-27 09:13:56 +00007541 **/
Kees Cook26566ea2017-10-16 17:29:35 -07007542static void ixgbe_service_timer(struct timer_list *t)
Alexander Duyck70864002011-04-27 09:13:56 +00007543{
Kees Cook26566ea2017-10-16 17:29:35 -07007544 struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
Alexander Duyck70864002011-04-27 09:13:56 +00007545 unsigned long next_event_offset;
7546
7547 /* poll faster when waiting for link */
7548 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
7549 next_event_offset = HZ / 10;
7550 else
7551 next_event_offset = HZ * 2;
7552
7553 /* Reset the timer */
7554 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
7555
Emil Tantilov9079e412014-11-19 03:18:19 +00007556 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007557}
7558
Don Skidmore597f22d2015-06-09 16:52:02 -07007559static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
7560{
7561 struct ixgbe_hw *hw = &adapter->hw;
7562 u32 status;
7563
7564 if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
7565 return;
7566
7567 adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
7568
7569 if (!hw->phy.ops.handle_lasi)
7570 return;
7571
7572 status = hw->phy.ops.handle_lasi(&adapter->hw);
7573 if (status != IXGBE_ERR_OVERTEMP)
7574 return;
7575
7576 e_crit(drv, "%s\n", ixgbe_overheat_msg);
7577}
7578
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007579static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
7580{
Emil Tantilov57ca2a42016-07-29 14:46:31 -07007581 if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007582 return;
7583
Tony Nguyen88adce42018-05-30 09:05:12 -07007584 rtnl_lock();
Mark Rustad09f40ae2014-01-14 18:53:11 -08007585 /* If we're already down, removing or resetting, just bail */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007586 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
Mark Rustad09f40ae2014-01-14 18:53:11 -08007587 test_bit(__IXGBE_REMOVING, &adapter->state) ||
Tony Nguyen88adce42018-05-30 09:05:12 -07007588 test_bit(__IXGBE_RESETTING, &adapter->state)) {
7589 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007590 return;
Tony Nguyen88adce42018-05-30 09:05:12 -07007591 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007592
7593 ixgbe_dump(adapter);
7594 netdev_err(adapter->netdev, "Reset adapter\n");
7595 adapter->tx_timeout_count++;
7596
7597 ixgbe_reinit_locked(adapter);
John Fastabend8f4c5c92014-01-16 02:30:05 -08007598 rtnl_unlock();
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007599}
7600
Alexander Duyck70864002011-04-27 09:13:56 +00007601/**
7602 * ixgbe_service_task - manages and runs subtasks
7603 * @work: pointer to work_struct containing our data
7604 **/
7605static void ixgbe_service_task(struct work_struct *work)
7606{
7607 struct ixgbe_adapter *adapter = container_of(work,
7608 struct ixgbe_adapter,
7609 service_task);
Mark Rustadb0483c82014-01-14 18:53:17 -08007610 if (ixgbe_removed(adapter->hw.hw_addr)) {
7611 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
7612 rtnl_lock();
7613 ixgbe_down(adapter);
7614 rtnl_unlock();
7615 }
7616 ixgbe_service_event_complete(adapter);
7617 return;
7618 }
Emil Tantilova21d0822016-08-10 11:19:23 -07007619 if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
Alexander Duyckb3a49552016-06-16 12:22:19 -07007620 rtnl_lock();
Emil Tantilova21d0822016-08-10 11:19:23 -07007621 adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Alexander Duyckb3a49552016-06-16 12:22:19 -07007622 udp_tunnel_get_rx_info(adapter->netdev);
7623 rtnl_unlock();
Mark Rustad67359c32015-06-15 11:33:25 -07007624 }
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00007625 ixgbe_reset_subtask(adapter);
Don Skidmore597f22d2015-06-09 16:52:02 -07007626 ixgbe_phy_interrupt_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007627 ixgbe_sfp_detection_subtask(adapter);
7628 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00007629 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007630 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00007631 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00007632 ixgbe_check_hang_subtask(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007633
Jacob Keller8fecf672013-06-21 08:14:32 +00007634 if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
Jacob Keller891dc082012-12-05 07:24:46 +00007635 ixgbe_ptp_overflow_check(adapter);
Jacob Keller6704a3a2018-01-29 15:57:48 -08007636 if (adapter->flags & IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER)
7637 ixgbe_ptp_rx_hang(adapter);
Jacob Keller622a2ef2017-05-03 10:29:04 -07007638 ixgbe_ptp_tx_hang(adapter);
Jacob Keller891dc082012-12-05 07:24:46 +00007639 }
Alexander Duyck70864002011-04-27 09:13:56 +00007640
7641 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007642}
7643
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007644static int ixgbe_tso(struct ixgbe_ring *tx_ring,
7645 struct ixgbe_tx_buffer *first,
Shannon Nelson70da6822018-03-16 11:09:07 -07007646 u8 *hdr_len,
7647 struct ixgbe_ipsec_tx_data *itd)
Alexander Duyck897ab152011-05-27 05:31:47 +00007648{
Alexander Duyckb83e3012016-04-14 17:19:31 -04007649 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007650 struct sk_buff *skb = first->skb;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007651 union {
7652 struct iphdr *v4;
7653 struct ipv6hdr *v6;
7654 unsigned char *hdr;
7655 } ip;
7656 union {
7657 struct tcphdr *tcp;
7658 unsigned char *hdr;
7659 } l4;
7660 u32 paylen, l4_offset;
Shannon Nelson70da6822018-03-16 11:09:07 -07007661 u32 fceof_saidx = 0;
Francois Romieu2049e1f2014-03-30 03:14:27 +00007662 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007663
Alexander Duyck8f4fbb92012-10-30 06:01:40 +00007664 if (skb->ip_summed != CHECKSUM_PARTIAL)
7665 return 0;
7666
Alexander Duyck897ab152011-05-27 05:31:47 +00007667 if (!skb_is_gso(skb))
7668 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007669
Francois Romieu2049e1f2014-03-30 03:14:27 +00007670 err = skb_cow_head(skb, 0);
7671 if (err < 0)
7672 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00007673
Scott Peterson2a205252016-11-18 11:25:42 -08007674 if (eth_p_mpls(first->protocol))
7675 ip.hdr = skb_inner_network_header(skb);
7676 else
7677 ip.hdr = skb_network_header(skb);
Alexander Duyckb83e3012016-04-14 17:19:31 -04007678 l4.hdr = skb_checksum_start(skb);
7679
Alexander Duyck897ab152011-05-27 05:31:47 +00007680 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
7681 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7682
Alexander Duyckb83e3012016-04-14 17:19:31 -04007683 /* initialize outer IP header fields */
7684 if (ip.v4->version == 4) {
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007685 unsigned char *csum_start = skb_checksum_start(skb);
7686 unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
Shannon Nelson70da6822018-03-16 11:09:07 -07007687 int len = csum_start - trans_start;
Alexander Duyckc54cdc32016-11-28 10:42:29 -05007688
Alexander Duyckb83e3012016-04-14 17:19:31 -04007689 /* IP header will have to cancel out any data that
Shannon Nelson70da6822018-03-16 11:09:07 -07007690 * is not a part of the outer IP header, so set to
7691 * a reverse csum if needed, else init check to 0.
Alexander Duyckb83e3012016-04-14 17:19:31 -04007692 */
Shannon Nelson70da6822018-03-16 11:09:07 -07007693 ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ?
7694 csum_fold(csum_partial(trans_start,
7695 len, 0)) : 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007696 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007697
7698 ip.v4->tot_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007699 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7700 IXGBE_TX_FLAGS_CSUM |
7701 IXGBE_TX_FLAGS_IPV4;
Alexander Duyckb83e3012016-04-14 17:19:31 -04007702 } else {
7703 ip.v6->payload_len = 0;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007704 first->tx_flags |= IXGBE_TX_FLAGS_TSO |
7705 IXGBE_TX_FLAGS_CSUM;
Alexander Duyck897ab152011-05-27 05:31:47 +00007706 }
7707
Alexander Duyckb83e3012016-04-14 17:19:31 -04007708 /* determine offset of inner transport header */
7709 l4_offset = l4.hdr - skb->data;
7710
7711 /* compute length of segmentation header */
7712 *hdr_len = (l4.tcp->doff * 4) + l4_offset;
7713
7714 /* remove payload length from inner checksum */
7715 paylen = skb->len - l4_offset;
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07007716 csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen));
Alexander Duyck897ab152011-05-27 05:31:47 +00007717
Alexander Duyck091a6242012-02-08 07:51:01 +00007718 /* update gso size and bytecount with header size */
7719 first->gso_segs = skb_shinfo(skb)->gso_segs;
7720 first->bytecount += (first->gso_segs - 1) * *hdr_len;
7721
Alexander Duyckc44f5f52012-10-30 06:01:45 +00007722 /* mss_l4len_id: use 0 as index for TSO */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007723 mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007724 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
Alexander Duyck897ab152011-05-27 05:31:47 +00007725
Shannon Nelson70da6822018-03-16 11:09:07 -07007726 fceof_saidx |= itd->sa_idx;
7727 type_tucmd |= itd->flags | itd->trailer_len;
7728
Alexander Duyck897ab152011-05-27 05:31:47 +00007729 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
Alexander Duyckb83e3012016-04-14 17:19:31 -04007730 vlan_macip_lens = l4.hdr - ip.hdr;
7731 vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007732 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007733
Shannon Nelson70da6822018-03-16 11:09:07 -07007734 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd,
Alexander Duyck244e27a2012-02-08 07:51:11 +00007735 mss_l4len_idx);
Alexander Duyck897ab152011-05-27 05:31:47 +00007736
7737 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00007738}
7739
Alexander Duyck49763de2016-01-13 07:31:11 -08007740static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
7741{
7742 unsigned int offset = 0;
7743
7744 ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
7745
7746 return offset == skb_checksum_start_offset(skb);
7747}
7748
Alexander Duyck244e27a2012-02-08 07:51:11 +00007749static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Shannon Nelson59259472017-12-19 16:00:00 -08007750 struct ixgbe_tx_buffer *first,
7751 struct ixgbe_ipsec_tx_data *itd)
Auke Kok9a799d72007-09-15 14:07:45 -07007752{
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00007753 struct sk_buff *skb = first->skb;
Alexander Duyck897ab152011-05-27 05:31:47 +00007754 u32 vlan_macip_lens = 0;
Shannon Nelson59259472017-12-19 16:00:00 -08007755 u32 fceof_saidx = 0;
Alexander Duyck897ab152011-05-27 05:31:47 +00007756 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007757
Alexander Duyck897ab152011-05-27 05:31:47 +00007758 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck49763de2016-01-13 07:31:11 -08007759csum_failed:
7760 if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
7761 IXGBE_TX_FLAGS_CC)))
Alexander Duyck472148c2012-11-07 02:34:28 +00007762 return;
Alexander Duyck49763de2016-01-13 07:31:11 -08007763 goto no_csum;
Auke Kok9a799d72007-09-15 14:07:45 -07007764 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07007765
Alexander Duyck49763de2016-01-13 07:31:11 -08007766 switch (skb->csum_offset) {
7767 case offsetof(struct tcphdr, check):
7768 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
7769 /* fall through */
7770 case offsetof(struct udphdr, check):
7771 break;
7772 case offsetof(struct sctphdr, checksum):
7773 /* validate that this is actually an SCTP request */
7774 if (((first->protocol == htons(ETH_P_IP)) &&
7775 (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
7776 ((first->protocol == htons(ETH_P_IPV6)) &&
7777 ixgbe_ipv6_csum_is_sctp(skb))) {
7778 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
7779 break;
7780 }
7781 /* fall through */
7782 default:
7783 skb_checksum_help(skb);
7784 goto csum_failed;
7785 }
7786
7787 /* update TX checksum flag */
7788 first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
7789 vlan_macip_lens = skb_checksum_start_offset(skb) -
7790 skb_network_offset(skb);
Mark Rustad36a92d72015-11-18 09:21:28 -08007791no_csum:
Alexander Duyck244e27a2012-02-08 07:51:11 +00007792 /* vlan_macip_lens: MACLEN, VLAN tag */
Alexander Duyck49763de2016-01-13 07:31:11 -08007793 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007794 vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007795
Shannon Nelson871dd092018-03-16 11:09:05 -07007796 fceof_saidx |= itd->sa_idx;
7797 type_tucmd |= itd->flags | itd->trailer_len;
Shannon Nelson59259472017-12-19 16:00:00 -08007798
7799 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07007800}
7801
Alexander Duyck472148c2012-11-07 02:34:28 +00007802#define IXGBE_SET_FLAG(_input, _flag, _result) \
7803 ((_flag <= _result) ? \
7804 ((u32)(_input & _flag) * (_result / _flag)) : \
7805 ((u32)(_input & _flag) / (_flag / _result)))
7806
7807static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007808{
7809 /* set type for advanced descriptor with frame checksum insertion */
Alexander Duyck472148c2012-11-07 02:34:28 +00007810 u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
7811 IXGBE_ADVTXD_DCMD_DEXT |
7812 IXGBE_ADVTXD_DCMD_IFCS;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007813
7814 /* set HW vlan bit if vlan is present */
Alexander Duyck472148c2012-11-07 02:34:28 +00007815 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
7816 IXGBE_ADVTXD_DCMD_VLE);
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00007817
Alexander Duyckd3d00232011-07-15 02:31:25 +00007818 /* set segmentation enable bits for TSO/FSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007819 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
7820 IXGBE_ADVTXD_DCMD_TSE);
7821
7822 /* set timestamp bit if present */
7823 cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
7824 IXGBE_ADVTXD_MAC_TSTAMP);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007825
Alexander Duyck62748b72012-07-20 08:09:01 +00007826 /* insert frame checksum */
Alexander Duyck472148c2012-11-07 02:34:28 +00007827 cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
Alexander Duyck62748b72012-07-20 08:09:01 +00007828
Alexander Duyckd3d00232011-07-15 02:31:25 +00007829 return cmd_type;
7830}
7831
Alexander Duyck729739b2012-02-08 07:51:06 +00007832static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
7833 u32 tx_flags, unsigned int paylen)
Alexander Duyckd3d00232011-07-15 02:31:25 +00007834{
Alexander Duyck472148c2012-11-07 02:34:28 +00007835 u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007836
7837 /* enable L4 checksum for TSO and TX checksum offload */
Alexander Duyck472148c2012-11-07 02:34:28 +00007838 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7839 IXGBE_TX_FLAGS_CSUM,
7840 IXGBE_ADVTXD_POPTS_TXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007841
Shannon Nelson59259472017-12-19 16:00:00 -08007842 /* enable IPv4 checksum for TSO */
Alexander Duyck472148c2012-11-07 02:34:28 +00007843 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7844 IXGBE_TX_FLAGS_IPV4,
7845 IXGBE_ADVTXD_POPTS_IXSM);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007846
Shannon Nelson59259472017-12-19 16:00:00 -08007847 /* enable IPsec */
7848 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7849 IXGBE_TX_FLAGS_IPSEC,
7850 IXGBE_ADVTXD_POPTS_IPSEC);
7851
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007852 /*
7853 * Check Context must be set if Tx switch is enabled, which it
7854 * always is for case where virtual functions are running
7855 */
Alexander Duyck472148c2012-11-07 02:34:28 +00007856 olinfo_status |= IXGBE_SET_FLAG(tx_flags,
7857 IXGBE_TX_FLAGS_CC,
7858 IXGBE_ADVTXD_CC);
Alexander Duyck7f9643f2011-06-29 05:43:27 +00007859
Alexander Duyck472148c2012-11-07 02:34:28 +00007860 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007861}
7862
Daniel Borkmann2367a172014-08-26 19:34:18 +02007863static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7864{
7865 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
7866
7867 /* Herbert's original patch had:
7868 * smp_mb__after_netif_stop_queue();
7869 * but since that doesn't exist yet, just open code it.
7870 */
7871 smp_mb();
7872
7873 /* We need to check again in a case another CPU has just
7874 * made room available.
7875 */
7876 if (likely(ixgbe_desc_unused(tx_ring) < size))
7877 return -EBUSY;
7878
7879 /* A reprieve! - use start_queue because it doesn't call schedule */
7880 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
7881 ++tx_ring->tx_stats.restart_queue;
7882 return 0;
7883}
7884
7885static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
7886{
7887 if (likely(ixgbe_desc_unused(tx_ring) >= size))
7888 return 0;
7889
7890 return __ixgbe_maybe_stop_tx(tx_ring, size);
7891}
7892
Alexander Duyckd3d00232011-07-15 02:31:25 +00007893#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
7894 IXGBE_TXD_CMD_RS)
7895
Jacob Keller5fef1242017-05-03 10:28:56 -07007896static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
7897 struct ixgbe_tx_buffer *first,
7898 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07007899{
Alexander Duyck729739b2012-02-08 07:51:06 +00007900 struct sk_buff *skb = first->skb;
7901 struct ixgbe_tx_buffer *tx_buffer;
7902 union ixgbe_adv_tx_desc *tx_desc;
Alexander Duyckec718252012-10-30 06:01:55 +00007903 struct skb_frag_struct *frag;
7904 dma_addr_t dma;
7905 unsigned int data_len, size;
Alexander Duyck244e27a2012-02-08 07:51:11 +00007906 u32 tx_flags = first->tx_flags;
Alexander Duyck472148c2012-11-07 02:34:28 +00007907 u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007908 u16 i = tx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07007909
Alexander Duyck729739b2012-02-08 07:51:06 +00007910 tx_desc = IXGBE_TX_DESC(tx_ring, i);
7911
Alexander Duyckec718252012-10-30 06:01:55 +00007912 ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
7913
7914 size = skb_headlen(skb);
7915 data_len = skb->data_len;
Alexander Duyck729739b2012-02-08 07:51:06 +00007916
Alexander Duyckd3d00232011-07-15 02:31:25 +00007917#ifdef IXGBE_FCOE
7918 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
Alexander Duyck729739b2012-02-08 07:51:06 +00007919 if (data_len < sizeof(struct fcoe_crc_eof)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007920 size -= sizeof(struct fcoe_crc_eof) - data_len;
7921 data_len = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007922 } else {
7923 data_len -= sizeof(struct fcoe_crc_eof);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007924 }
Auke Kok9a799d72007-09-15 14:07:45 -07007925 }
7926
Alexander Duyckd3d00232011-07-15 02:31:25 +00007927#endif
Alexander Duyck729739b2012-02-08 07:51:06 +00007928 dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007929
Alexander Duyckec718252012-10-30 06:01:55 +00007930 tx_buffer = first;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007931
Alexander Duyckec718252012-10-30 06:01:55 +00007932 for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
7933 if (dma_mapping_error(tx_ring->dev, dma))
7934 goto dma_error;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007935
Alexander Duyckec718252012-10-30 06:01:55 +00007936 /* record length, and DMA address */
7937 dma_unmap_len_set(tx_buffer, len, size);
7938 dma_unmap_addr_set(tx_buffer, dma, dma);
7939
7940 tx_desc->read.buffer_addr = cpu_to_le64(dma);
7941
Alexander Duyck729739b2012-02-08 07:51:06 +00007942 while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
Alexander Duyckd3d00232011-07-15 02:31:25 +00007943 tx_desc->read.cmd_type_len =
Alexander Duyck472148c2012-11-07 02:34:28 +00007944 cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007945
Alexander Duyckd3d00232011-07-15 02:31:25 +00007946 i++;
Alexander Duyck729739b2012-02-08 07:51:06 +00007947 tx_desc++;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007948 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00007949 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007950 i = 0;
7951 }
Alexander Duyckec718252012-10-30 06:01:55 +00007952 tx_desc->read.olinfo_status = 0;
Alexander Duyck729739b2012-02-08 07:51:06 +00007953
7954 dma += IXGBE_MAX_DATA_PER_TXD;
7955 size -= IXGBE_MAX_DATA_PER_TXD;
7956
7957 tx_desc->read.buffer_addr = cpu_to_le64(dma);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007958 }
7959
Alexander Duyck729739b2012-02-08 07:51:06 +00007960 if (likely(!data_len))
7961 break;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007962
Alexander Duyck472148c2012-11-07 02:34:28 +00007963 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007964
Alexander Duyck729739b2012-02-08 07:51:06 +00007965 i++;
7966 tx_desc++;
7967 if (i == tx_ring->count) {
7968 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
7969 i = 0;
7970 }
Alexander Duyckec718252012-10-30 06:01:55 +00007971 tx_desc->read.olinfo_status = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07007972
Alexander Duyckd3d00232011-07-15 02:31:25 +00007973#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00007974 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00007975#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00007976 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007977#endif
7978 data_len -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07007979
Alexander Duyck729739b2012-02-08 07:51:06 +00007980 dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
7981 DMA_TO_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07007982
Alexander Duyck729739b2012-02-08 07:51:06 +00007983 tx_buffer = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -07007984 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00007985
Alexander Duyck729739b2012-02-08 07:51:06 +00007986 /* write last descriptor with RS and EOP bits */
Alexander Duyck472148c2012-11-07 02:34:28 +00007987 cmd_type |= size | IXGBE_TXD_CMD;
7988 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
Alexander Duyckd3d00232011-07-15 02:31:25 +00007989
Alexander Duyck091a6242012-02-08 07:51:01 +00007990 netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
Alexander Duyckb2d96e02012-02-07 08:14:33 +00007991
Alexander Duyckd3d00232011-07-15 02:31:25 +00007992 /* set the timestamp */
7993 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07007994
7995 /*
Alexander Duyck729739b2012-02-08 07:51:06 +00007996 * Force memory writes to complete before letting h/w know there
7997 * are new descriptors to fetch. (Only applicable for weak-ordered
7998 * memory model archs, such as IA-64).
7999 *
8000 * We also need this memory barrier to make certain all of the
8001 * status bits have been updated before next_to_watch is written.
Auke Kok9a799d72007-09-15 14:07:45 -07008002 */
8003 wmb();
8004
Alexander Duyckd3d00232011-07-15 02:31:25 +00008005 /* set next_to_watch value indicating a packet is present */
8006 first->next_to_watch = tx_desc;
8007
Alexander Duyck729739b2012-02-08 07:51:06 +00008008 i++;
8009 if (i == tx_ring->count)
8010 i = 0;
8011
8012 tx_ring->next_to_use = i;
8013
Daniel Borkmann2367a172014-08-26 19:34:18 +02008014 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
8015
8016 if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
Alexander Duyckad435ec2014-11-14 00:56:35 +00008017 writel(i, tx_ring->tail);
8018
8019 /* we need this if more than one processor can write to our tail
8020 * at a time, it synchronizes IO on IA64/Altix systems
8021 */
8022 mmiowb();
Daniel Borkmann9c938cd2014-08-24 15:42:16 +02008023 }
Daniel Borkmann2367a172014-08-26 19:34:18 +02008024
Jacob Keller5fef1242017-05-03 10:28:56 -07008025 return 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008026dma_error:
Alexander Duyck729739b2012-02-08 07:51:06 +00008027 dev_err(tx_ring->dev, "TX DMA map failed\n");
Alexander Duyckd3d00232011-07-15 02:31:25 +00008028
8029 /* clear dma mappings for failed tx_buffer_info map */
Alexander Duyck069db9c2017-10-19 17:07:13 -04008030 for (;;) {
8031 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duyckffed21b2017-01-17 08:37:29 -08008032 if (dma_unmap_len(tx_buffer, len))
8033 dma_unmap_page(tx_ring->dev,
8034 dma_unmap_addr(tx_buffer, dma),
8035 dma_unmap_len(tx_buffer, len),
8036 DMA_TO_DEVICE);
8037 dma_unmap_len_set(tx_buffer, len, 0);
Alexander Duyck069db9c2017-10-19 17:07:13 -04008038 if (tx_buffer == first)
8039 break;
8040 if (i == 0)
Alexander Duyckffed21b2017-01-17 08:37:29 -08008041 i += tx_ring->count;
Alexander Duyck069db9c2017-10-19 17:07:13 -04008042 i--;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008043 }
8044
Alexander Duyckffed21b2017-01-17 08:37:29 -08008045 dev_kfree_skb_any(first->skb);
8046 first->skb = NULL;
8047
Alexander Duyckd3d00232011-07-15 02:31:25 +00008048 tx_ring->next_to_use = i;
Jacob Keller5fef1242017-05-03 10:28:56 -07008049
8050 return -1;
Auke Kok9a799d72007-09-15 14:07:45 -07008051}
8052
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008053static void ixgbe_atr(struct ixgbe_ring *ring,
Alexander Duyck244e27a2012-02-08 07:51:11 +00008054 struct ixgbe_tx_buffer *first)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008055{
Alexander Duyck69830522011-01-06 14:29:58 +00008056 struct ixgbe_q_vector *q_vector = ring->q_vector;
8057 union ixgbe_atr_hash_dword input = { .dword = 0 };
8058 union ixgbe_atr_hash_dword common = { .dword = 0 };
8059 union {
8060 unsigned char *network;
8061 struct iphdr *ipv4;
8062 struct ipv6hdr *ipv6;
8063 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08008064 struct tcphdr *th;
Alexander Duycke2873d42016-01-25 19:39:40 -08008065 unsigned int hlen;
Mark Rustad67359c32015-06-15 11:33:25 -07008066 struct sk_buff *skb;
Alexander Duyck905e4a42011-01-06 14:29:57 +00008067 __be16 vlan_id;
Alexander Duycke2873d42016-01-25 19:39:40 -08008068 int l4_proto;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008069
Alexander Duyck69830522011-01-06 14:29:58 +00008070 /* if ring doesn't have a interrupt vector, cannot perform ATR */
8071 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00008072 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008073
Alexander Duyck69830522011-01-06 14:29:58 +00008074 /* do nothing if sampling is disabled */
8075 if (!ring->atr_sample_rate)
8076 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008077
Alexander Duyck69830522011-01-06 14:29:58 +00008078 ring->atr_count++;
8079
Alexander Duycke2873d42016-01-25 19:39:40 -08008080 /* currently only IPv4/IPv6 with TCP is supported */
8081 if ((first->protocol != htons(ETH_P_IP)) &&
8082 (first->protocol != htons(ETH_P_IPV6)))
8083 return;
8084
Alexander Duyck69830522011-01-06 14:29:58 +00008085 /* snag network header to get L4 type and address */
Mark Rustad67359c32015-06-15 11:33:25 -07008086 skb = first->skb;
8087 hdr.network = skb_network_header(skb);
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008088 if (unlikely(hdr.network <= skb->data))
8089 return;
Alexander Duyck9f12df92016-01-25 19:36:29 -08008090 if (skb->encapsulation &&
8091 first->protocol == htons(ETH_P_IP) &&
Sowmini Varadhan52028822016-10-24 15:36:38 -07008092 hdr.ipv4->protocol == IPPROTO_UDP) {
Mark Rustad67359c32015-06-15 11:33:25 -07008093 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck69830522011-01-06 14:29:58 +00008094
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008095 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8096 VXLAN_HEADROOM))
8097 return;
8098
Alexander Duyck9f12df92016-01-25 19:36:29 -08008099 /* verify the port is recognized as VXLAN */
8100 if (adapter->vxlan_port &&
Alexander Duycke2873d42016-01-25 19:39:40 -08008101 udp_hdr(skb)->dest == adapter->vxlan_port)
Alexander Duyck9f12df92016-01-25 19:36:29 -08008102 hdr.network = skb_inner_network_header(skb);
Emil Tantilova21d0822016-08-10 11:19:23 -07008103
8104 if (adapter->geneve_port &&
8105 udp_hdr(skb)->dest == adapter->geneve_port)
8106 hdr.network = skb_inner_network_header(skb);
Mark Rustade19dcde2015-12-09 14:55:37 -08008107 }
8108
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008109 /* Make sure we have at least [minimum IPv4 header + TCP]
8110 * or [IPv6 header] bytes
8111 */
8112 if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
8113 return;
8114
Mark Rustade19dcde2015-12-09 14:55:37 -08008115 /* Currently only IPv4/IPv6 with TCP is supported */
8116 switch (hdr.ipv4->version) {
8117 case IPVERSION:
Alexander Duycke2873d42016-01-25 19:39:40 -08008118 /* access ihl as u8 to avoid unaligned access on ia64 */
8119 hlen = (hdr.network[0] & 0x0F) << 2;
8120 l4_proto = hdr.ipv4->protocol;
Mark Rustade19dcde2015-12-09 14:55:37 -08008121 break;
8122 case 6:
Alexander Duycke2873d42016-01-25 19:39:40 -08008123 hlen = hdr.network - skb->data;
8124 l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
8125 hlen -= hdr.network - skb->data;
Mark Rustade19dcde2015-12-09 14:55:37 -08008126 break;
8127 default:
8128 return;
Mark Rustad67359c32015-06-15 11:33:25 -07008129 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008130
Alexander Duycke2873d42016-01-25 19:39:40 -08008131 if (l4_proto != IPPROTO_TCP)
8132 return;
8133
Sowmini Varadhan9f3c7502016-10-24 15:36:39 -07008134 if (unlikely(skb_tail_pointer(skb) < hdr.network +
8135 hlen + sizeof(struct tcphdr)))
8136 return;
8137
Alexander Duycke2873d42016-01-25 19:39:40 -08008138 th = (struct tcphdr *)(hdr.network + hlen);
8139
8140 /* skip this packet since the socket is closing */
8141 if (th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00008142 return;
8143
8144 /* sample on all syn packets or once every atr sample count */
8145 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
8146 return;
8147
8148 /* reset sample count */
8149 ring->atr_count = 0;
8150
Alexander Duyck244e27a2012-02-08 07:51:11 +00008151 vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
Alexander Duyck69830522011-01-06 14:29:58 +00008152
8153 /*
8154 * src and dst are inverted, think how the receiver sees them
8155 *
8156 * The input is broken into two sections, a non-compressed section
8157 * containing vm_pool, vlan_id, and flow_type. The rest of the data
8158 * is XORed together and stored in the compressed dword.
8159 */
8160 input.formatted.vlan_id = vlan_id;
8161
8162 /*
8163 * since src port and flex bytes occupy the same word XOR them together
8164 * and write the value to source port portion of compressed dword
8165 */
Alexander Duyck244e27a2012-02-08 07:51:11 +00008166 if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Joe Perchesa1108ff2014-03-13 05:19:25 +00008167 common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
Alexander Duyck69830522011-01-06 14:29:58 +00008168 else
Alexander Duyck244e27a2012-02-08 07:51:11 +00008169 common.port.src ^= th->dest ^ first->protocol;
Alexander Duyck69830522011-01-06 14:29:58 +00008170 common.port.dst ^= th->source;
8171
Mark Rustade19dcde2015-12-09 14:55:37 -08008172 switch (hdr.ipv4->version) {
8173 case IPVERSION:
Alexander Duyck69830522011-01-06 14:29:58 +00008174 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
8175 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
Mark Rustade19dcde2015-12-09 14:55:37 -08008176 break;
8177 case 6:
Alexander Duyck69830522011-01-06 14:29:58 +00008178 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
8179 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
8180 hdr.ipv6->saddr.s6_addr32[1] ^
8181 hdr.ipv6->saddr.s6_addr32[2] ^
8182 hdr.ipv6->saddr.s6_addr32[3] ^
8183 hdr.ipv6->daddr.s6_addr32[0] ^
8184 hdr.ipv6->daddr.s6_addr32[1] ^
8185 hdr.ipv6->daddr.s6_addr32[2] ^
8186 hdr.ipv6->daddr.s6_addr32[3];
Mark Rustade19dcde2015-12-09 14:55:37 -08008187 break;
8188 default:
8189 break;
Alexander Duyck69830522011-01-06 14:29:58 +00008190 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008191
Alexander Duyck9f12df92016-01-25 19:36:29 -08008192 if (hdr.network != skb_network_header(skb))
Mark Rustad67359c32015-06-15 11:33:25 -07008193 input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
Mark Rustad67359c32015-06-15 11:33:25 -07008194
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008195 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00008196 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
8197 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008198}
8199
Jason Wangf663dd92014-01-10 16:18:26 +08008200static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
Daniel Borkmann99932d42014-02-16 15:55:20 +01008201 void *accel_priv, select_queue_fallback_t fallback)
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008202{
Jason Wangf663dd92014-01-10 16:18:26 +08008203 struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
Alexander Duyck97488bd2013-01-12 06:33:37 +00008204 struct ixgbe_adapter *adapter;
Alexander Duyck97488bd2013-01-12 06:33:37 +00008205 int txq;
Alexander Duyck16be45b2017-11-22 10:57:23 -08008206#ifdef IXGBE_FCOE
8207 struct ixgbe_ring_feature *f;
Jason Wangf663dd92014-01-10 16:18:26 +08008208#endif
8209
Alexander Duyck16be45b2017-11-22 10:57:23 -08008210 if (fwd_adapter) {
8211 adapter = netdev_priv(dev);
8212 txq = reciprocal_scale(skb_get_hash(skb),
8213 adapter->num_rx_queues_per_pool);
8214
8215 return txq + fwd_adapter->tx_base_queue;
8216 }
Jason Wangf663dd92014-01-10 16:18:26 +08008217
8218#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00008219
Alexander Duyck97488bd2013-01-12 06:33:37 +00008220 /*
8221 * only execute the code below if protocol is FCoE
8222 * or FIP and we have FCoE enabled on the adapter
8223 */
8224 switch (vlan_get_protocol(skb)) {
Joe Perchesa1108ff2014-03-13 05:19:25 +00008225 case htons(ETH_P_FCOE):
8226 case htons(ETH_P_FIP):
Alexander Duyck97488bd2013-01-12 06:33:37 +00008227 adapter = netdev_priv(dev);
Alexander Duyckc0876632012-05-10 00:01:46 +00008228
Alexander Duyck97488bd2013-01-12 06:33:37 +00008229 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8230 break;
Tony Nguyen93df9462017-05-31 04:43:47 -07008231 /* fall through */
Alexander Duyck97488bd2013-01-12 06:33:37 +00008232 default:
Daniel Borkmann99932d42014-02-16 15:55:20 +01008233 return fallback(dev, skb);
Krishna Kumarfdd3d632010-02-03 13:13:10 +00008234 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00008235
Alexander Duyck97488bd2013-01-12 06:33:37 +00008236 f = &adapter->ring_feature[RING_F_FCOE];
8237
8238 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
8239 smp_processor_id();
8240
8241 while (txq >= f->indices)
8242 txq -= f->indices;
8243
8244 return txq + f->offset;
Jason Wangf663dd92014-01-10 16:18:26 +08008245#else
Daniel Borkmann99932d42014-02-16 15:55:20 +01008246 return fallback(dev, skb);
Jason Wangf663dd92014-01-10 16:18:26 +08008247#endif
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07008248}
8249
John Fastabend33fdc822017-04-24 03:30:18 -07008250static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
Jesper Dangaard Brouer44fa2db2018-04-17 16:46:37 +02008251 struct xdp_frame *xdpf)
John Fastabend33fdc822017-04-24 03:30:18 -07008252{
8253 struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
8254 struct ixgbe_tx_buffer *tx_buffer;
8255 union ixgbe_adv_tx_desc *tx_desc;
8256 u32 len, cmd_type;
8257 dma_addr_t dma;
8258 u16 i;
8259
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02008260 len = xdpf->len;
John Fastabend33fdc822017-04-24 03:30:18 -07008261
8262 if (unlikely(!ixgbe_desc_unused(ring)))
8263 return IXGBE_XDP_CONSUMED;
8264
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02008265 dma = dma_map_single(ring->dev, xdpf->data, len, DMA_TO_DEVICE);
John Fastabend33fdc822017-04-24 03:30:18 -07008266 if (dma_mapping_error(ring->dev, dma))
8267 return IXGBE_XDP_CONSUMED;
8268
8269 /* record the location of the first descriptor for this packet */
8270 tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
8271 tx_buffer->bytecount = len;
8272 tx_buffer->gso_segs = 1;
8273 tx_buffer->protocol = 0;
8274
8275 i = ring->next_to_use;
8276 tx_desc = IXGBE_TX_DESC(ring, i);
8277
8278 dma_unmap_len_set(tx_buffer, len, len);
8279 dma_unmap_addr_set(tx_buffer, dma, dma);
Jesper Dangaard Brouer03993092018-04-17 16:46:32 +02008280 tx_buffer->xdpf = xdpf;
Jesper Dangaard Brouer189ead82018-04-17 16:45:32 +02008281
John Fastabend33fdc822017-04-24 03:30:18 -07008282 tx_desc->read.buffer_addr = cpu_to_le64(dma);
8283
8284 /* put descriptor type bits */
8285 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
8286 IXGBE_ADVTXD_DCMD_DEXT |
8287 IXGBE_ADVTXD_DCMD_IFCS;
8288 cmd_type |= len | IXGBE_TXD_CMD;
8289 tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
8290 tx_desc->read.olinfo_status =
8291 cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
8292
John Fastabend7379f972017-03-28 09:47:03 -07008293 /* Avoid any potential race with xdp_xmit and cleanup */
8294 smp_wmb();
John Fastabend33fdc822017-04-24 03:30:18 -07008295
8296 /* set next_to_watch value indicating a packet is present */
8297 i++;
8298 if (i == ring->count)
8299 i = 0;
8300
8301 tx_buffer->next_to_watch = tx_desc;
8302 ring->next_to_use = i;
8303
John Fastabend33fdc822017-04-24 03:30:18 -07008304 return IXGBE_XDP_TX;
8305}
8306
Alexander Duyckfc77dc32010-11-16 19:26:51 -08008307netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00008308 struct ixgbe_adapter *adapter,
8309 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008310{
Alexander Duyckd3d00232011-07-15 02:31:25 +00008311 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00008312 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008313 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00008314 unsigned short f;
Alexander Duycka535c302011-05-27 05:31:52 +00008315 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Shannon Nelson59259472017-12-19 16:00:00 -08008316 struct ixgbe_ipsec_tx_data ipsec_tx = { 0 };
Alexander Duyck66f32a82011-06-29 05:43:22 +00008317 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00008318 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00008319
Alexander Duycka535c302011-05-27 05:31:52 +00008320 /*
8321 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00008322 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00008323 * + 2 desc gap to keep tail from touching head,
8324 * + 1 desc for context descriptor,
8325 * otherwise try next time
8326 */
Alexander Duycka535c302011-05-27 05:31:52 +00008327 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
8328 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
Alexander Duyck7f661622013-02-09 01:19:55 +00008329
Alexander Duycka535c302011-05-27 05:31:52 +00008330 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
8331 tx_ring->tx_stats.tx_busy++;
8332 return NETDEV_TX_BUSY;
8333 }
8334
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008335 /* record the location of the first descriptor for this packet */
8336 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
8337 first->skb = skb;
Alexander Duyck091a6242012-02-08 07:51:01 +00008338 first->bytecount = skb->len;
8339 first->gso_segs = 1;
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008340
Alexander Duyck66f32a82011-06-29 05:43:22 +00008341 /* if we have a HW VLAN tag being added default to the HW one */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +01008342 if (skb_vlan_tag_present(skb)) {
8343 tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008344 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8345 /* else if it is a SW VLAN check the next protocol and store the tag */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008346 } else if (protocol == htons(ETH_P_8021Q)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008347 struct vlan_hdr *vhdr, _vhdr;
8348 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
8349 if (!vhdr)
8350 goto out_drop;
8351
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008352 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
8353 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008354 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07008355 }
Toshiaki Makita02136682015-01-29 20:37:09 +09008356 protocol = vlan_get_protocol(skb);
Yi Zoueacd73f2009-05-13 13:11:06 +00008357
Mark Rustadd5234932014-08-09 07:02:09 +00008358 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
Jacob Keller4cc74c02017-05-03 10:29:00 -07008359 adapter->ptp_clock) {
8360 if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
8361 &adapter->state)) {
8362 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
8363 tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
Jacob Keller891dc082012-12-05 07:24:46 +00008364
Jacob Keller4cc74c02017-05-03 10:29:00 -07008365 /* schedule check for Tx timestamp */
8366 adapter->ptp_tx_skb = skb_get(skb);
8367 adapter->ptp_tx_start = jiffies;
8368 schedule_work(&adapter->ptp_tx_work);
8369 } else {
8370 adapter->tx_hwtstamp_skipped++;
8371 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008372 }
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008373
Jakub Kicinskiff29a862014-03-15 14:55:16 +00008374 skb_tx_timestamp(skb);
8375
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008376#ifdef CONFIG_PCI_IOV
8377 /*
8378 * Use the l2switch_enable flag - would be false if the DMA
8379 * Tx switch had been disabled.
8380 */
8381 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
Alexander Duyck472148c2012-11-07 02:34:28 +00008382 tx_flags |= IXGBE_TX_FLAGS_CC;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00008383
8384#endif
John Fastabend32701dc2011-09-27 03:51:56 +00008385 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00008386 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00008387 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
8388 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00008389 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00008390 tx_flags |= (skb->priority & 0x7) <<
8391 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00008392 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
8393 struct vlan_ethhdr *vhdr;
Francois Romieu2049e1f2014-03-30 03:14:27 +00008394
8395 if (skb_cow_head(skb, 0))
Alexander Duyck66f32a82011-06-29 05:43:22 +00008396 goto out_drop;
8397 vhdr = (struct vlan_ethhdr *)skb->data;
8398 vhdr->h_vlan_TCI = htons(tx_flags >>
8399 IXGBE_TX_FLAGS_VLAN_SHIFT);
8400 } else {
8401 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
8402 }
8403 }
Alexander Duycka535c302011-05-27 05:31:52 +00008404
Alexander Duyck244e27a2012-02-08 07:51:11 +00008405 /* record initial flags and protocol */
8406 first->tx_flags = tx_flags;
8407 first->protocol = protocol;
8408
Yi Zoueacd73f2009-05-13 13:11:06 +00008409#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00008410 /* setup tx offload for FCoE */
Joe Perchesa1108ff2014-03-13 05:19:25 +00008411 if ((protocol == htons(ETH_P_FCOE)) &&
Alexander Duycka58915c2012-05-25 06:38:18 +00008412 (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
Alexander Duyck244e27a2012-02-08 07:51:11 +00008413 tso = ixgbe_fso(tx_ring, first, &hdr_len);
Alexander Duyck897ab152011-05-27 05:31:47 +00008414 if (tso < 0)
8415 goto out_drop;
Auke Kok9a799d72007-09-15 14:07:45 -07008416
Alexander Duyck66f32a82011-06-29 05:43:22 +00008417 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00008418 }
Auke Kok9a799d72007-09-15 14:07:45 -07008419
Auke Kok9a799d72007-09-15 14:07:45 -07008420#endif /* IXGBE_FCOE */
Shannon Nelson59259472017-12-19 16:00:00 -08008421
8422#ifdef CONFIG_XFRM_OFFLOAD
8423 if (skb->sp && !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx))
8424 goto out_drop;
8425#endif
Shannon Nelson70da6822018-03-16 11:09:07 -07008426 tso = ixgbe_tso(tx_ring, first, &hdr_len, &ipsec_tx);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008427 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07008428 goto out_drop;
Alexander Duyck244e27a2012-02-08 07:51:11 +00008429 else if (!tso)
Shannon Nelson59259472017-12-19 16:00:00 -08008430 ixgbe_tx_csum(tx_ring, first, &ipsec_tx);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008431
8432 /* add the ATR filter if ATR is on */
8433 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
Alexander Duyck244e27a2012-02-08 07:51:11 +00008434 ixgbe_atr(tx_ring, first);
Alexander Duyck66f32a82011-06-29 05:43:22 +00008435
8436#ifdef IXGBE_FCOE
8437xmit_fcoe:
8438#endif /* IXGBE_FCOE */
Jacob Keller5fef1242017-05-03 10:28:56 -07008439 if (ixgbe_tx_map(tx_ring, first, hdr_len))
8440 goto cleanup_tx_timestamp;
Alexander Duyckd3d00232011-07-15 02:31:25 +00008441
Auke Kok9a799d72007-09-15 14:07:45 -07008442 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00008443
8444out_drop:
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008445 dev_kfree_skb_any(first->skb);
8446 first->skb = NULL;
Jacob Keller5fef1242017-05-03 10:28:56 -07008447cleanup_tx_timestamp:
8448 if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
8449 dev_kfree_skb_any(adapter->ptp_tx_skb);
8450 adapter->ptp_tx_skb = NULL;
8451 cancel_work_sync(&adapter->ptp_tx_work);
8452 clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
8453 }
Alexander Duyckfd0db0e2012-02-08 07:50:56 +00008454
Alexander Duyck897ab152011-05-27 05:31:47 +00008455 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07008456}
8457
John Fastabend2a47fa42013-11-06 09:54:52 -08008458static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
8459 struct net_device *netdev,
8460 struct ixgbe_ring *ring)
Auke Kok9a799d72007-09-15 14:07:45 -07008461{
8462 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008463 struct ixgbe_ring *tx_ring;
Auke Kok9a799d72007-09-15 14:07:45 -07008464
Alexander Duycka50c29d2012-02-08 07:50:40 +00008465 /*
8466 * The minimum packet size for olinfo paylen is 17 so pad the skb
8467 * in order to meet this minimum size requirement.
8468 */
Alexander Duycka94d9e22014-12-03 08:17:39 -08008469 if (skb_put_padto(skb, 17))
8470 return NETDEV_TX_OK;
Alexander Duycka50c29d2012-02-08 07:50:40 +00008471
John Fastabend2a47fa42013-11-06 09:54:52 -08008472 tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
8473
Auke Kok9a799d72007-09-15 14:07:45 -07008474 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
8475}
8476
John Fastabend2a47fa42013-11-06 09:54:52 -08008477static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
8478 struct net_device *netdev)
8479{
8480 return __ixgbe_xmit_frame(skb, netdev, NULL);
8481}
8482
Auke Kok9a799d72007-09-15 14:07:45 -07008483/**
8484 * ixgbe_set_mac - Change the Ethernet Address of the NIC
8485 * @netdev: network interface device structure
8486 * @p: pointer to an address structure
8487 *
8488 * Returns 0 on success, negative on failure
8489 **/
8490static int ixgbe_set_mac(struct net_device *netdev, void *p)
8491{
8492 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8493 struct ixgbe_hw *hw = &adapter->hw;
8494 struct sockaddr *addr = p;
8495
8496 if (!is_valid_ether_addr(addr->sa_data))
8497 return -EADDRNOTAVAIL;
8498
8499 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008500 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07008501
Alexander Duyckc9f53e62015-10-22 16:26:30 -07008502 ixgbe_mac_set_default_filter(adapter);
8503
8504 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07008505}
8506
Ben Hutchings6b73e102009-04-29 08:08:58 +00008507static int
8508ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
8509{
8510 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8511 struct ixgbe_hw *hw = &adapter->hw;
8512 u16 value;
8513 int rc;
8514
8515 if (prtad != hw->phy.mdio.prtad)
8516 return -EINVAL;
8517 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
8518 if (!rc)
8519 rc = value;
8520 return rc;
8521}
8522
8523static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
8524 u16 addr, u16 value)
8525{
8526 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8527 struct ixgbe_hw *hw = &adapter->hw;
8528
8529 if (prtad != hw->phy.mdio.prtad)
8530 return -EINVAL;
8531 return hw->phy.ops.write_reg(hw, addr, devad, value);
8532}
8533
8534static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
8535{
8536 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8537
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008538 switch (cmd) {
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008539 case SIOCSHWTSTAMP:
Jacob Keller93501d42014-02-28 15:48:58 -08008540 return ixgbe_ptp_set_ts_config(adapter, req);
8541 case SIOCGHWTSTAMP:
8542 return ixgbe_ptp_get_ts_config(adapter, req);
Mark D Rustade0f06bb2016-08-31 10:34:28 -07008543 case SIOCGMIIPHY:
8544 if (!adapter->hw.phy.ops.read_reg)
8545 return -EOPNOTSUPP;
8546 /* fall through */
Jacob Keller3a6a4ed2012-05-01 05:24:58 +00008547 default:
8548 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
8549 }
Ben Hutchings6b73e102009-04-29 08:08:58 +00008550}
8551
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008552/**
8553 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008554 * netdev->dev_addrs
Tony Nguyen5ba643c2017-12-04 11:28:30 -08008555 * @dev: network interface device structure
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008556 *
8557 * Returns non-zero on failure
8558 **/
8559static int ixgbe_add_sanmac_netdev(struct net_device *dev)
8560{
8561 int err = 0;
8562 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008563 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008564
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008565 if (is_valid_ether_addr(hw->mac.san_addr)) {
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008566 rtnl_lock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008567 err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008568 rtnl_unlock();
Alexander Duyck7fa7c9d2012-05-05 05:32:52 +00008569
8570 /* update SAN MAC vmdq pool selection */
8571 hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008572 }
8573 return err;
8574}
8575
8576/**
8577 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00008578 * netdev->dev_addrs
Tony Nguyen5ba643c2017-12-04 11:28:30 -08008579 * @dev: network interface device structure
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008580 *
8581 * Returns non-zero on failure
8582 **/
8583static int ixgbe_del_sanmac_netdev(struct net_device *dev)
8584{
8585 int err = 0;
8586 struct ixgbe_adapter *adapter = netdev_priv(dev);
8587 struct ixgbe_mac_info *mac = &adapter->hw.mac;
8588
8589 if (is_valid_ether_addr(mac->san_addr)) {
8590 rtnl_lock();
8591 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
8592 rtnl_unlock();
8593 }
8594 return err;
8595}
8596
Auke Kok9a799d72007-09-15 14:07:45 -07008597#ifdef CONFIG_NET_POLL_CONTROLLER
8598/*
8599 * Polling 'interrupt' - used by things like netconsole to send skbs
8600 * without having to re-enable interrupts. It's not called while
8601 * the interrupt routine is executing.
8602 */
8603static void ixgbe_netpoll(struct net_device *netdev)
8604{
8605 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00008606 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07008607
Alexander Duyck1a647bd2010-01-13 01:49:13 +00008608 /* if interface is down do nothing */
8609 if (test_bit(__IXGBE_DOWN, &adapter->state))
8610 return;
8611
Alexander Duyck856f6062015-02-25 17:45:54 +00008612 /* loop through and schedule all active queues */
8613 for (i = 0; i < adapter->num_q_vectors; i++)
8614 ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07008615}
Auke Kok9a799d72007-09-15 14:07:45 -07008616
Alexander Duyck581330b2012-02-08 07:51:47 +00008617#endif
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008618
John Fastabend33fdc822017-04-24 03:30:18 -07008619static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
8620 struct ixgbe_ring *ring)
8621{
8622 u64 bytes, packets;
8623 unsigned int start;
8624
8625 if (ring) {
8626 do {
8627 start = u64_stats_fetch_begin_irq(&ring->syncp);
8628 packets = ring->stats.packets;
8629 bytes = ring->stats.bytes;
8630 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
8631 stats->tx_packets += packets;
8632 stats->tx_bytes += bytes;
8633 }
8634}
8635
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008636static void ixgbe_get_stats64(struct net_device *netdev,
8637 struct rtnl_link_stats64 *stats)
Eric Dumazetde1036b2010-10-20 23:00:04 +00008638{
8639 struct ixgbe_adapter *adapter = netdev_priv(netdev);
8640 int i;
8641
Eric Dumazet1a515022010-11-16 19:26:42 -08008642 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00008643 for (i = 0; i < adapter->num_rx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008644 struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00008645 u64 bytes, packets;
8646 unsigned int start;
8647
Eric Dumazet1a515022010-11-16 19:26:42 -08008648 if (ring) {
8649 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07008650 start = u64_stats_fetch_begin_irq(&ring->syncp);
Eric Dumazet1a515022010-11-16 19:26:42 -08008651 packets = ring->stats.packets;
8652 bytes = ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07008653 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
Eric Dumazet1a515022010-11-16 19:26:42 -08008654 stats->rx_packets += packets;
8655 stats->rx_bytes += bytes;
8656 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00008657 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008658
8659 for (i = 0; i < adapter->num_tx_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008660 struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008661
John Fastabend33fdc822017-04-24 03:30:18 -07008662 ixgbe_get_ring_stats64(stats, ring);
8663 }
8664 for (i = 0; i < adapter->num_xdp_queues; i++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07008665 struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
John Fastabend33fdc822017-04-24 03:30:18 -07008666
8667 ixgbe_get_ring_stats64(stats, ring);
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00008668 }
Eric Dumazet1a515022010-11-16 19:26:42 -08008669 rcu_read_unlock();
stephen hemmingerbc1f4472017-01-06 19:12:52 -08008670
Eric Dumazetde1036b2010-10-20 23:00:04 +00008671 /* following stats updated by ixgbe_watchdog_task() */
8672 stats->multicast = netdev->stats.multicast;
8673 stats->rx_errors = netdev->stats.rx_errors;
8674 stats->rx_length_errors = netdev->stats.rx_length_errors;
8675 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
8676 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
Eric Dumazetde1036b2010-10-20 23:00:04 +00008677}
8678
Jeff Kirsher8af3c332012-02-18 07:08:14 +00008679#ifdef CONFIG_IXGBE_DCB
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008680/**
8681 * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
8682 * @adapter: pointer to ixgbe_adapter
John Fastabend8b1c0b22011-05-03 02:26:48 +00008683 * @tc: number of traffic classes currently enabled
8684 *
8685 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
8686 * 802.1Q priority maps to a packet buffer that exists.
8687 */
8688static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
8689{
8690 struct ixgbe_hw *hw = &adapter->hw;
8691 u32 reg, rsave;
8692 int i;
8693
8694 /* 82598 have a static priority to TC mapping that can not
8695 * be changed so no validation is needed.
8696 */
8697 if (hw->mac.type == ixgbe_mac_82598EB)
8698 return;
8699
8700 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
8701 rsave = reg;
8702
8703 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
8704 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
8705
8706 /* If up2tc is out of bounds default to zero */
8707 if (up2tc > tc)
8708 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
8709 }
8710
8711 if (reg != rsave)
8712 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
8713
8714 return;
8715}
8716
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008717/**
Alexander Duyck02debdc2012-05-18 06:33:31 +00008718 * ixgbe_set_prio_tc_map - Configure netdev prio tc map
8719 * @adapter: Pointer to adapter struct
8720 *
8721 * Populate the netdev user priority to tc map
8722 */
8723static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
8724{
8725 struct net_device *dev = adapter->netdev;
8726 struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
8727 struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
8728 u8 prio;
8729
8730 for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
8731 u8 tc = 0;
8732
8733 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
8734 tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
8735 else if (ets)
8736 tc = ets->prio_tc[prio];
8737
8738 netdev_set_prio_tc_map(dev, prio, tc);
8739 }
8740}
8741
Alexander Duyckcca73c52013-01-12 06:33:44 +00008742#endif /* CONFIG_IXGBE_DCB */
Alexander Duyck8315ef62018-04-03 17:16:45 -04008743static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data)
8744{
8745 struct ixgbe_adapter *adapter = data;
8746 struct ixgbe_fwd_adapter *accel;
8747 int pool;
8748
8749 /* we only care about macvlans... */
8750 if (!netif_is_macvlan(vdev))
8751 return 0;
8752
8753 /* that have hardware offload enabled... */
8754 accel = macvlan_accel_priv(vdev);
8755 if (!accel)
8756 return 0;
8757
8758 /* If we can relocate to a different bit do so */
8759 pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
8760 if (pool < adapter->num_rx_pools) {
8761 set_bit(pool, adapter->fwd_bitmask);
8762 accel->pool = pool;
8763 return 0;
8764 }
8765
8766 /* if we cannot find a free pool then disable the offload */
8767 netdev_err(vdev, "L2FW offload disabled due to lack of queue resources\n");
8768 macvlan_release_l2fw_offload(vdev);
8769 kfree(accel);
8770
8771 return 0;
8772}
8773
8774static void ixgbe_defrag_macvlan_pools(struct net_device *dev)
8775{
8776 struct ixgbe_adapter *adapter = netdev_priv(dev);
8777
8778 /* flush any stale bits out of the fwd bitmask */
8779 bitmap_clear(adapter->fwd_bitmask, 1, 63);
8780
8781 /* walk through upper devices reassigning pools */
8782 netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool,
8783 adapter);
8784}
8785
Alexander Duyck02debdc2012-05-18 06:33:31 +00008786/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00008787 * ixgbe_setup_tc - configure net_device for multiple traffic classes
John Fastabend8b1c0b22011-05-03 02:26:48 +00008788 *
Tony Nguyen5ba643c2017-12-04 11:28:30 -08008789 * @dev: net device to configure
John Fastabend8b1c0b22011-05-03 02:26:48 +00008790 * @tc: number of traffic classes to enable
8791 */
8792int ixgbe_setup_tc(struct net_device *dev, u8 tc)
8793{
John Fastabend8b1c0b22011-05-03 02:26:48 +00008794 struct ixgbe_adapter *adapter = netdev_priv(dev);
8795 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00008796
John Fastabend8b1c0b22011-05-03 02:26:48 +00008797 /* Hardware supports up to 8 traffic classes */
Emil Tantilov7e3f5c82015-07-09 12:28:59 -07008798 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
8799 return -EINVAL;
8800
8801 if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
John Fastabend8b1c0b22011-05-03 02:26:48 +00008802 return -EINVAL;
8803
8804 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00008805 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00008806 * hardware is not flexible enough to do this dynamically.
8807 */
8808 if (netif_running(dev))
8809 ixgbe_close(dev);
Alexander Duyckbf4d67d2015-10-20 13:28:17 -07008810 else
8811 ixgbe_reset(adapter);
8812
John Fastabend8b1c0b22011-05-03 02:26:48 +00008813 ixgbe_clear_interrupt_scheme(adapter);
8814
Alexander Duyckcca73c52013-01-12 06:33:44 +00008815#ifdef CONFIG_IXGBE_DCB
John Fastabende7589ea2011-07-18 22:38:36 +00008816 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008817 netdev_set_num_tc(dev, tc);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008818 ixgbe_set_prio_tc_map(adapter);
8819
Alexander Duyck0efbf122017-11-22 10:57:11 -08008820 adapter->hw_tcs = tc;
John Fastabende7589ea2011-07-18 22:38:36 +00008821 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
John Fastabende7589ea2011-07-18 22:38:36 +00008822
Alexander Duyck943561d2012-05-09 22:14:44 -07008823 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
8824 adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008825 adapter->hw.fc.requested_mode = ixgbe_fc_none;
Alexander Duyck943561d2012-05-09 22:14:44 -07008826 }
John Fastabende7589ea2011-07-18 22:38:36 +00008827 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00008828 netdev_reset_tc(dev);
Alexander Duyck02debdc2012-05-18 06:33:31 +00008829
Alexander Duyck943561d2012-05-09 22:14:44 -07008830 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
8831 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
John Fastabende7589ea2011-07-18 22:38:36 +00008832
8833 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Alexander Duyck0efbf122017-11-22 10:57:11 -08008834 adapter->hw_tcs = tc;
John Fastabende7589ea2011-07-18 22:38:36 +00008835
8836 adapter->temp_dcb_cfg.pfc_mode_enable = false;
8837 adapter->dcb_cfg.pfc_mode_enable = false;
8838 }
8839
John Fastabend8b1c0b22011-05-03 02:26:48 +00008840 ixgbe_validate_rtr(adapter, tc);
Alexander Duyckcca73c52013-01-12 06:33:44 +00008841
8842#endif /* CONFIG_IXGBE_DCB */
8843 ixgbe_init_interrupt_scheme(adapter);
8844
Alexander Duyck8315ef62018-04-03 17:16:45 -04008845 ixgbe_defrag_macvlan_pools(dev);
8846
John Fastabend8b1c0b22011-05-03 02:26:48 +00008847 if (netif_running(dev))
Alexander Duyckcca73c52013-01-12 06:33:44 +00008848 return ixgbe_open(dev);
John Fastabend8b1c0b22011-05-03 02:26:48 +00008849
8850 return 0;
8851}
Eric Dumazetde1036b2010-10-20 23:00:04 +00008852
John Fastabendb82b17d2016-02-16 21:18:53 -08008853static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
8854 struct tc_cls_u32_offload *cls)
8855{
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008856 u32 hdl = cls->knode.handle;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008857 u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008858 u32 loc = cls->knode.handle & 0xfffff;
8859 int err = 0, i, j;
8860 struct ixgbe_jump_table *jump = NULL;
8861
8862 if (loc > IXGBE_MAX_HW_ENTRIES)
8863 return -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08008864
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008865 if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
8866 return -EINVAL;
8867
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008868 /* Clear this filter in the link data it is associated with */
8869 if (uhtid != 0x800) {
8870 jump = adapter->jump_tables[uhtid];
Amritha Nambiar12746fd2016-05-16 18:33:20 -07008871 if (!jump)
8872 return -EINVAL;
8873 if (!test_bit(loc - 1, jump->child_loc_map))
8874 return -EINVAL;
8875 clear_bit(loc - 1, jump->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07008876 }
8877
8878 /* Check if the filter being deleted is a link */
8879 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
8880 jump = adapter->jump_tables[i];
8881 if (jump && jump->link_hdl == hdl) {
8882 /* Delete filters in the hardware in the child hash
8883 * table associated with this link
8884 */
8885 for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
8886 if (!test_bit(j, jump->child_loc_map))
8887 continue;
8888 spin_lock(&adapter->fdir_perfect_lock);
8889 err = ixgbe_update_ethtool_fdir_entry(adapter,
8890 NULL,
8891 j + 1);
8892 spin_unlock(&adapter->fdir_perfect_lock);
8893 clear_bit(j, jump->child_loc_map);
8894 }
8895 /* Remove resources for this link */
8896 kfree(jump->input);
8897 kfree(jump->mask);
8898 kfree(jump);
8899 adapter->jump_tables[i] = NULL;
8900 return err;
8901 }
8902 }
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008903
John Fastabendb82b17d2016-02-16 21:18:53 -08008904 spin_lock(&adapter->fdir_perfect_lock);
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008905 err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
John Fastabendb82b17d2016-02-16 21:18:53 -08008906 spin_unlock(&adapter->fdir_perfect_lock);
8907 return err;
8908}
8909
John Fastabenddb956ae2016-02-16 21:19:19 -08008910static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
John Fastabenddb956ae2016-02-16 21:19:19 -08008911 struct tc_cls_u32_offload *cls)
8912{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008913 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8914
8915 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8916 return -EINVAL;
8917
John Fastabenddb956ae2016-02-16 21:19:19 -08008918 /* This ixgbe devices do not support hash tables at the moment
8919 * so abort when given hash tables.
8920 */
8921 if (cls->hnode.divisor > 0)
8922 return -EINVAL;
8923
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008924 set_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008925 return 0;
8926}
8927
8928static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
8929 struct tc_cls_u32_offload *cls)
8930{
Sridhar Samudrala176621c2016-03-07 09:41:47 -08008931 u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
8932
8933 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
8934 return -EINVAL;
8935
8936 clear_bit(uhtid - 1, &adapter->tables);
John Fastabenddb956ae2016-02-16 21:19:19 -08008937 return 0;
8938}
8939
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008940#ifdef CONFIG_NET_CLS_ACT
David Ahern1cd127f2016-10-17 19:15:48 -07008941struct upper_walk_data {
8942 struct ixgbe_adapter *adapter;
8943 u64 action;
8944 int ifindex;
8945 u8 queue;
8946};
8947
8948static int get_macvlan_queue(struct net_device *upper, void *_data)
8949{
8950 if (netif_is_macvlan(upper)) {
Alexander Duyck7d775f62018-04-03 17:16:03 -04008951 struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper);
David Ahern1cd127f2016-10-17 19:15:48 -07008952 struct upper_walk_data *data = _data;
8953 struct ixgbe_adapter *adapter = data->adapter;
8954 int ifindex = data->ifindex;
8955
Alexander Duyck7d775f62018-04-03 17:16:03 -04008956 if (vadapter && upper->ifindex == ifindex) {
David Ahern1cd127f2016-10-17 19:15:48 -07008957 data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
8958 data->action = data->queue;
8959 return 1;
8960 }
8961 }
8962
8963 return 0;
8964}
8965
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008966static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
8967 u8 *queue, u64 *action)
8968{
Alexander Duyck361b5342017-11-22 10:56:16 -08008969 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008970 unsigned int num_vfs = adapter->num_vfs, vf;
David Ahern1cd127f2016-10-17 19:15:48 -07008971 struct upper_walk_data data;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008972 struct net_device *upper;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008973
8974 /* redirect to a SRIOV VF */
8975 for (vf = 0; vf < num_vfs; ++vf) {
8976 upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
8977 if (upper->ifindex == ifindex) {
Alexander Duyck361b5342017-11-22 10:56:16 -08008978 *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008979 *action = vf + 1;
8980 *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
8981 return 0;
8982 }
8983 }
8984
8985 /* redirect to a offloaded macvlan netdev */
David Ahern1cd127f2016-10-17 19:15:48 -07008986 data.adapter = adapter;
8987 data.ifindex = ifindex;
8988 data.action = 0;
8989 data.queue = 0;
8990 if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
8991 get_macvlan_queue, &data)) {
8992 *action = data.action;
8993 *queue = data.queue;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008994
David Ahern1cd127f2016-10-17 19:15:48 -07008995 return 0;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07008996 }
8997
8998 return -EINVAL;
8999}
9000
9001static int parse_tc_actions(struct ixgbe_adapter *adapter,
9002 struct tcf_exts *exts, u64 *action, u8 *queue)
9003{
9004 const struct tc_action *a;
WANG Cong22dc13c2016-08-13 22:35:00 -07009005 LIST_HEAD(actions);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009006
Jiri Pirko3bcc0ce2017-08-04 14:28:58 +02009007 if (!tcf_exts_has_actions(exts))
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009008 return -EINVAL;
9009
WANG Cong22dc13c2016-08-13 22:35:00 -07009010 tcf_exts_to_list(exts, &actions);
9011 list_for_each_entry(a, &actions, list) {
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009012
9013 /* Drop action */
9014 if (is_tcf_gact_shot(a)) {
9015 *action = IXGBE_FDIR_DROP_QUEUE;
9016 *queue = IXGBE_FDIR_DROP_QUEUE;
9017 return 0;
9018 }
9019
9020 /* Redirect to a VF or a offloaded macvlan */
Shmulik Ladkani5724b8b2016-10-13 09:06:43 +03009021 if (is_tcf_mirred_egress_redirect(a)) {
Cong Wang9f8a7392017-12-05 16:17:26 -08009022 struct net_device *dev = tcf_mirred_dev(a);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009023
Cong Wang9f8a7392017-12-05 16:17:26 -08009024 if (!dev)
9025 return -EINVAL;
Ondřej Hlavatý16e66532018-05-31 23:21:04 +02009026 return handle_redirect_action(adapter, dev->ifindex,
9027 queue, action);
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009028 }
Ondřej Hlavatý16e66532018-05-31 23:21:04 +02009029
9030 return -EINVAL;
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009031 }
9032
9033 return -EINVAL;
9034}
9035#else
9036static int parse_tc_actions(struct ixgbe_adapter *adapter,
9037 struct tcf_exts *exts, u64 *action, u8 *queue)
9038{
9039 return -EINVAL;
9040}
9041#endif /* CONFIG_NET_CLS_ACT */
9042
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009043static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
9044 union ixgbe_atr_input *mask,
9045 struct tc_cls_u32_offload *cls,
9046 struct ixgbe_mat_field *field_ptr,
9047 struct ixgbe_nexthdr *nexthdr)
9048{
9049 int i, j, off;
9050 __be32 val, m;
9051 bool found_entry = false, found_jump_field = false;
9052
9053 for (i = 0; i < cls->knode.sel->nkeys; i++) {
9054 off = cls->knode.sel->keys[i].off;
9055 val = cls->knode.sel->keys[i].val;
9056 m = cls->knode.sel->keys[i].mask;
9057
9058 for (j = 0; field_ptr[j].val; j++) {
9059 if (field_ptr[j].off == off) {
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009060 field_ptr[j].val(input, mask, (__force u32)val,
9061 (__force u32)m);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009062 input->filter.formatted.flow_type |=
9063 field_ptr[j].type;
9064 found_entry = true;
9065 break;
9066 }
9067 }
9068 if (nexthdr) {
9069 if (nexthdr->off == cls->knode.sel->keys[i].off &&
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009070 nexthdr->val ==
9071 (__force u32)cls->knode.sel->keys[i].val &&
9072 nexthdr->mask ==
9073 (__force u32)cls->knode.sel->keys[i].mask)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009074 found_jump_field = true;
9075 else
9076 continue;
9077 }
9078 }
9079
9080 if (nexthdr && !found_jump_field)
9081 return -EINVAL;
9082
9083 if (!found_entry)
9084 return 0;
9085
9086 mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
9087 IXGBE_ATR_L4TYPE_MASK;
9088
9089 if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
9090 mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
9091
9092 return 0;
9093}
9094
John Fastabendb82b17d2016-02-16 21:18:53 -08009095static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
John Fastabendb82b17d2016-02-16 21:18:53 -08009096 struct tc_cls_u32_offload *cls)
9097{
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009098 __be16 protocol = cls->common.protocol;
John Fastabendb82b17d2016-02-16 21:18:53 -08009099 u32 loc = cls->knode.handle & 0xfffff;
9100 struct ixgbe_hw *hw = &adapter->hw;
9101 struct ixgbe_mat_field *field_ptr;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009102 struct ixgbe_fdir_filter *input = NULL;
9103 union ixgbe_atr_input *mask = NULL;
9104 struct ixgbe_jump_table *jump = NULL;
9105 int i, err = -EINVAL;
John Fastabendb82b17d2016-02-16 21:18:53 -08009106 u8 queue;
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009107 u32 uhtid, link_uhtid;
John Fastabendb82b17d2016-02-16 21:18:53 -08009108
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009109 uhtid = TC_U32_USERHTID(cls->knode.handle);
9110 link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
John Fastabendb82b17d2016-02-16 21:18:53 -08009111
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009112 /* At the moment cls_u32 jumps to network layer and skips past
John Fastabendb82b17d2016-02-16 21:18:53 -08009113 * L2 headers. The canonical method to match L2 frames is to use
9114 * negative values. However this is error prone at best but really
9115 * just broken because there is no way to "know" what sort of hdr
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009116 * is in front of the network layer. Fix cls_u32 to support L2
John Fastabendb82b17d2016-02-16 21:18:53 -08009117 * headers when needed.
9118 */
9119 if (protocol != htons(ETH_P_IP))
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009120 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009121
9122 if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
9123 e_err(drv, "Location out of range\n");
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009124 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009125 }
9126
9127 /* cls u32 is a graph starting at root node 0x800. The driver tracks
9128 * links and also the fields used to advance the parser across each
9129 * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
9130 * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
9131 * To add support for new nodes update ixgbe_model.h parse structures
9132 * this function _should_ be generic try not to hardcode values here.
9133 */
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009134 if (uhtid == 0x800) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009135 field_ptr = (adapter->jump_tables[0])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009136 } else {
Sridhar Samudrala176621c2016-03-07 09:41:47 -08009137 if (uhtid >= IXGBE_MAX_LINK_HANDLE)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009138 return err;
9139 if (!adapter->jump_tables[uhtid])
9140 return err;
9141 field_ptr = (adapter->jump_tables[uhtid])->mat;
John Fastabendb82b17d2016-02-16 21:18:53 -08009142 }
9143
9144 if (!field_ptr)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009145 return err;
9146
9147 /* At this point we know the field_ptr is valid and need to either
9148 * build cls_u32 link or attach filter. Because adding a link to
9149 * a handle that does not exist is invalid and the same for adding
9150 * rules to handles that don't exist.
9151 */
9152
9153 if (link_uhtid) {
9154 struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
9155
9156 if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
9157 return err;
9158
9159 if (!test_bit(link_uhtid - 1, &adapter->tables))
9160 return err;
9161
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009162 /* Multiple filters as links to the same hash table are not
9163 * supported. To add a new filter with the same next header
9164 * but different match/jump conditions, create a new hash table
9165 * and link to it.
9166 */
9167 if (adapter->jump_tables[link_uhtid] &&
9168 (adapter->jump_tables[link_uhtid])->link_hdl) {
9169 e_err(drv, "Link filter exists for link: %x\n",
9170 link_uhtid);
9171 return err;
9172 }
9173
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009174 for (i = 0; nexthdr[i].jump; i++) {
9175 if (nexthdr[i].o != cls->knode.sel->offoff ||
9176 nexthdr[i].s != cls->knode.sel->offshift ||
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009177 nexthdr[i].m !=
9178 (__force u32)cls->knode.sel->offmask)
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009179 return err;
9180
9181 jump = kzalloc(sizeof(*jump), GFP_KERNEL);
9182 if (!jump)
9183 return -ENOMEM;
9184 input = kzalloc(sizeof(*input), GFP_KERNEL);
9185 if (!input) {
9186 err = -ENOMEM;
9187 goto free_jump;
9188 }
9189 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9190 if (!mask) {
9191 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009192 goto free_input;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009193 }
9194 jump->input = input;
9195 jump->mask = mask;
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009196 jump->link_hdl = cls->knode.handle;
9197
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009198 err = ixgbe_clsu32_build_input(input, mask, cls,
9199 field_ptr, &nexthdr[i]);
9200 if (!err) {
9201 jump->mat = nexthdr[i].jump;
9202 adapter->jump_tables[link_uhtid] = jump;
9203 break;
9204 }
9205 }
9206 return 0;
9207 }
John Fastabendb82b17d2016-02-16 21:18:53 -08009208
9209 input = kzalloc(sizeof(*input), GFP_KERNEL);
9210 if (!input)
9211 return -ENOMEM;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009212 mask = kzalloc(sizeof(*mask), GFP_KERNEL);
9213 if (!mask) {
9214 err = -ENOMEM;
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009215 goto free_input;
John Fastabendb82b17d2016-02-16 21:18:53 -08009216 }
9217
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009218 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
9219 if ((adapter->jump_tables[uhtid])->input)
9220 memcpy(input, (adapter->jump_tables[uhtid])->input,
9221 sizeof(*input));
9222 if ((adapter->jump_tables[uhtid])->mask)
9223 memcpy(mask, (adapter->jump_tables[uhtid])->mask,
9224 sizeof(*mask));
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009225
9226 /* Lookup in all child hash tables if this location is already
9227 * filled with a filter
9228 */
9229 for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
9230 struct ixgbe_jump_table *link = adapter->jump_tables[i];
9231
9232 if (link && (test_bit(loc - 1, link->child_loc_map))) {
9233 e_err(drv, "Filter exists in location: %x\n",
9234 loc);
9235 err = -EINVAL;
9236 goto err_out;
9237 }
9238 }
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009239 }
9240 err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
9241 if (err)
John Fastabendb82b17d2016-02-16 21:18:53 -08009242 goto err_out;
9243
Sridhar Samudrala947f8a42016-04-05 10:39:07 -07009244 err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
9245 &queue);
9246 if (err < 0)
John Fastabendb82b17d2016-02-16 21:18:53 -08009247 goto err_out;
John Fastabendb82b17d2016-02-16 21:18:53 -08009248
John Fastabendb82b17d2016-02-16 21:18:53 -08009249 input->sw_idx = loc;
9250
9251 spin_lock(&adapter->fdir_perfect_lock);
9252
9253 if (hlist_empty(&adapter->fdir_filter_list)) {
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009254 memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
9255 err = ixgbe_fdir_set_input_mask_82599(hw, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009256 if (err)
9257 goto err_out_w_lock;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009258 } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
John Fastabendb82b17d2016-02-16 21:18:53 -08009259 err = -EINVAL;
9260 goto err_out_w_lock;
9261 }
9262
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009263 ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009264 err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
9265 input->sw_idx, queue);
9266 if (!err)
9267 ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
9268 spin_unlock(&adapter->fdir_perfect_lock);
9269
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009270 if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
9271 set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009272
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009273 kfree(mask);
John Fastabendb82b17d2016-02-16 21:18:53 -08009274 return err;
9275err_out_w_lock:
9276 spin_unlock(&adapter->fdir_perfect_lock);
9277err_out:
Amritha Nambiar1ecedc92016-05-06 19:09:51 -07009278 kfree(mask);
Amritha Nambiar12746fd2016-05-16 18:33:20 -07009279free_input:
9280 kfree(input);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -04009281free_jump:
9282 kfree(jump);
9283 return err;
John Fastabendb82b17d2016-02-16 21:18:53 -08009284}
9285
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009286static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009287 struct tc_cls_u32_offload *cls_u32)
9288{
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009289 switch (cls_u32->command) {
9290 case TC_CLSU32_NEW_KNODE:
9291 case TC_CLSU32_REPLACE_KNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009292 return ixgbe_configure_clsu32(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009293 case TC_CLSU32_DELETE_KNODE:
9294 return ixgbe_delete_clsu32(adapter, cls_u32);
9295 case TC_CLSU32_NEW_HNODE:
9296 case TC_CLSU32_REPLACE_HNODE:
Jiri Pirko5fd9fc42017-08-07 10:15:29 +02009297 return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009298 case TC_CLSU32_DELETE_HNODE:
9299 return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
9300 default:
9301 return -EOPNOTSUPP;
9302 }
9303}
9304
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009305static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
9306 void *cb_priv)
9307{
9308 struct ixgbe_adapter *adapter = cb_priv;
9309
Jakub Kicinskia60c3fd2018-01-25 14:00:49 -08009310 if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
Jiri Pirko44ae12a2017-11-01 11:47:39 +01009311 return -EOPNOTSUPP;
9312
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009313 switch (type) {
9314 case TC_SETUP_CLSU32:
9315 return ixgbe_setup_tc_cls_u32(adapter, type_data);
9316 default:
9317 return -EOPNOTSUPP;
9318 }
9319}
9320
9321static int ixgbe_setup_tc_block(struct net_device *dev,
9322 struct tc_block_offload *f)
9323{
9324 struct ixgbe_adapter *adapter = netdev_priv(dev);
9325
9326 if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9327 return -EOPNOTSUPP;
9328
9329 switch (f->command) {
9330 case TC_BLOCK_BIND:
9331 return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
9332 adapter, adapter);
9333 case TC_BLOCK_UNBIND:
9334 tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
9335 adapter);
9336 return 0;
9337 default:
9338 return -EOPNOTSUPP;
9339 }
9340}
9341
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009342static int ixgbe_setup_tc_mqprio(struct net_device *dev,
9343 struct tc_mqprio_qopt *mqprio)
9344{
9345 mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
9346 return ixgbe_setup_tc(dev, mqprio->num_tc);
9347}
9348
Jiri Pirko2572ac52017-08-07 10:15:17 +02009349static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
Jiri Pirkode4784c2017-08-07 10:15:32 +02009350 void *type_data)
John Fastabende4c67342016-02-16 21:16:15 -08009351{
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009352 switch (type) {
Jiri Pirko6ea30f82017-10-19 15:50:41 +02009353 case TC_SETUP_BLOCK:
9354 return ixgbe_setup_tc_block(dev, type_data);
Nogah Frankel575ed7d2017-11-06 07:23:42 +01009355 case TC_SETUP_QDISC_MQPRIO:
Jiri Pirkode4784c2017-08-07 10:15:32 +02009356 return ixgbe_setup_tc_mqprio(dev, type_data);
Jiri Pirkobc32afd2017-08-07 10:15:21 +02009357 default:
Jiri Pirkoa5fcf8a2017-06-06 17:00:16 +02009358 return -EOPNOTSUPP;
John Fastabendb82b17d2016-02-16 21:18:53 -08009359 }
John Fastabende4c67342016-02-16 21:16:15 -08009360}
9361
Greg Roseda36b642012-12-11 08:26:43 +00009362#ifdef CONFIG_PCI_IOV
9363void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
9364{
9365 struct net_device *netdev = adapter->netdev;
9366
9367 rtnl_lock();
Alexander Duyck0efbf122017-11-22 10:57:11 -08009368 ixgbe_setup_tc(netdev, adapter->hw_tcs);
Greg Roseda36b642012-12-11 08:26:43 +00009369 rtnl_unlock();
9370}
9371
9372#endif
Don Skidmore082757a2011-07-21 05:55:00 +00009373void ixgbe_do_reset(struct net_device *netdev)
9374{
9375 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9376
9377 if (netif_running(netdev))
9378 ixgbe_reinit_locked(adapter);
9379 else
9380 ixgbe_reset(adapter);
9381}
9382
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009383static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009384 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009385{
9386 struct ixgbe_adapter *adapter = netdev_priv(netdev);
9387
Don Skidmore082757a2011-07-21 05:55:00 +00009388 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009389 if (!(features & NETIF_F_RXCSUM))
9390 features &= ~NETIF_F_LRO;
Don Skidmore082757a2011-07-21 05:55:00 +00009391
Alexander Duyck567d2de2012-02-11 07:18:57 +00009392 /* Turn off LRO if not RSC capable */
9393 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
9394 features &= ~NETIF_F_LRO;
Jacob Keller8e2813f2012-04-21 06:05:40 +00009395
Alexander Duyck567d2de2012-02-11 07:18:57 +00009396 return features;
Don Skidmore082757a2011-07-21 05:55:00 +00009397}
9398
Alexander Duyck8315ef62018-04-03 17:16:45 -04009399static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter *adapter)
9400{
9401 int rss = min_t(int, ixgbe_max_rss_indices(adapter),
9402 num_online_cpus());
9403
9404 /* go back to full RSS if we're not running SR-IOV */
9405 if (!adapter->ring_feature[RING_F_VMDQ].offset)
9406 adapter->flags &= ~(IXGBE_FLAG_VMDQ_ENABLED |
9407 IXGBE_FLAG_SRIOV_ENABLED);
9408
9409 adapter->ring_feature[RING_F_RSS].limit = rss;
9410 adapter->ring_feature[RING_F_VMDQ].limit = 1;
9411
9412 ixgbe_setup_tc(adapter->netdev, adapter->hw_tcs);
9413}
9414
Michał Mirosławc8f44af2011-11-15 15:29:55 +00009415static int ixgbe_set_features(struct net_device *netdev,
Alexander Duyck567d2de2012-02-11 07:18:57 +00009416 netdev_features_t features)
Don Skidmore082757a2011-07-21 05:55:00 +00009417{
9418 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Alexander Duyck567d2de2012-02-11 07:18:57 +00009419 netdev_features_t changed = netdev->features ^ features;
Don Skidmore082757a2011-07-21 05:55:00 +00009420 bool need_reset = false;
9421
Don Skidmore082757a2011-07-21 05:55:00 +00009422 /* Make sure RSC matches LRO, reset if change */
Alexander Duyck567d2de2012-02-11 07:18:57 +00009423 if (!(features & NETIF_F_LRO)) {
9424 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Don Skidmore082757a2011-07-21 05:55:00 +00009425 need_reset = true;
Alexander Duyck567d2de2012-02-11 07:18:57 +00009426 adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
9427 } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
9428 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
9429 if (adapter->rx_itr_setting == 1 ||
9430 adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
9431 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
9432 need_reset = true;
9433 } else if ((changed ^ features) & NETIF_F_LRO) {
9434 e_info(probe, "rx-usecs set too low, "
9435 "disabling RSC\n");
Don Skidmore082757a2011-07-21 05:55:00 +00009436 }
9437 }
9438
9439 /*
John Fastabendb82b17d2016-02-16 21:18:53 -08009440 * Check if Flow Director n-tuple support or hw_tc support was
9441 * enabled or disabled. If the state changed, we need to reset.
Don Skidmore082757a2011-07-21 05:55:00 +00009442 */
John Fastabendb82b17d2016-02-16 21:18:53 -08009443 if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
Alexander Duyck567d2de2012-02-11 07:18:57 +00009444 /* turn off ATR, enable perfect filters and reset */
Alexander Duyck39cb6812012-06-06 05:38:20 +00009445 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
9446 need_reset = true;
9447
Alexander Duyck567d2de2012-02-11 07:18:57 +00009448 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
9449 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
John Fastabendb82b17d2016-02-16 21:18:53 -08009450 } else {
Alexander Duyck39cb6812012-06-06 05:38:20 +00009451 /* turn off perfect filters, enable ATR and reset */
9452 if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
9453 need_reset = true;
9454
9455 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
9456
9457 /* We cannot enable ATR if SR-IOV is enabled */
John Fastabendb82b17d2016-02-16 21:18:53 -08009458 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
9459 /* We cannot enable ATR if we have 2 or more tcs */
Alexander Duyck0efbf122017-11-22 10:57:11 -08009460 (adapter->hw_tcs > 1) ||
John Fastabendb82b17d2016-02-16 21:18:53 -08009461 /* We cannot enable ATR if RSS is disabled */
9462 (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
9463 /* A sample rate of 0 indicates ATR disabled */
9464 (!adapter->atr_sample_rate))
9465 ; /* do nothing not supported */
9466 else /* otherwise supported and set the flag */
9467 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
Don Skidmore082757a2011-07-21 05:55:00 +00009468 }
9469
Ben Greear3f2d1c02012-03-08 08:28:41 +00009470 if (changed & NETIF_F_RXALL)
9471 need_reset = true;
9472
Alexander Duyck567d2de2012-02-11 07:18:57 +00009473 netdev->features = features;
Mark Rustad67359c32015-06-15 11:33:25 -07009474
Mark Rustad67359c32015-06-15 11:33:25 -07009475 if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
Emil Tantilova21d0822016-08-10 11:19:23 -07009476 if (features & NETIF_F_RXCSUM) {
9477 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9478 } else {
9479 u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9480
9481 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9482 }
9483 }
9484
9485 if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
9486 if (features & NETIF_F_RXCSUM) {
9487 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
9488 } else {
9489 u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9490
9491 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9492 }
Mark Rustad67359c32015-06-15 11:33:25 -07009493 }
Mark Rustad67359c32015-06-15 11:33:25 -07009494
Alexander Duyck8315ef62018-04-03 17:16:45 -04009495 if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
9496 ixgbe_reset_l2fw_offload(adapter);
9497 else if (need_reset)
Don Skidmore082757a2011-07-21 05:55:00 +00009498 ixgbe_do_reset(netdev);
Alexander Duyck0c5a6162016-03-10 10:01:10 -08009499 else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
9500 NETIF_F_HW_VLAN_CTAG_FILTER))
9501 ixgbe_set_rx_mode(netdev);
Don Skidmore082757a2011-07-21 05:55:00 +00009502
9503 return 0;
Don Skidmore082757a2011-07-21 05:55:00 +00009504}
9505
Don Skidmore3f207802014-12-23 07:40:34 +00009506/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009507 * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009508 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009509 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009510 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009511static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
9512 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009513{
9514 struct ixgbe_adapter *adapter = netdev_priv(dev);
9515 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckb3a49552016-06-16 12:22:19 -07009516 __be16 port = ti->port;
Emil Tantilova21d0822016-08-10 11:19:23 -07009517 u32 port_shift = 0;
9518 u32 reg;
Mark Rustad67359c32015-06-15 11:33:25 -07009519
Alexander Duyckb3a49552016-06-16 12:22:19 -07009520 if (ti->sa_family != AF_INET)
9521 return;
9522
Emil Tantilova21d0822016-08-10 11:19:23 -07009523 switch (ti->type) {
9524 case UDP_TUNNEL_TYPE_VXLAN:
9525 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9526 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009527
Emil Tantilova21d0822016-08-10 11:19:23 -07009528 if (adapter->vxlan_port == port)
9529 return;
Don Skidmore3f207802014-12-23 07:40:34 +00009530
Emil Tantilova21d0822016-08-10 11:19:23 -07009531 if (adapter->vxlan_port) {
9532 netdev_info(dev,
9533 "VXLAN port %d set, not adding port %d\n",
9534 ntohs(adapter->vxlan_port),
9535 ntohs(port));
9536 return;
9537 }
9538
9539 adapter->vxlan_port = port;
9540 break;
9541 case UDP_TUNNEL_TYPE_GENEVE:
9542 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9543 return;
9544
9545 if (adapter->geneve_port == port)
9546 return;
9547
9548 if (adapter->geneve_port) {
9549 netdev_info(dev,
9550 "GENEVE port %d set, not adding port %d\n",
9551 ntohs(adapter->geneve_port),
9552 ntohs(port));
9553 return;
9554 }
9555
9556 port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
9557 adapter->geneve_port = port;
9558 break;
9559 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009560 return;
9561 }
9562
Emil Tantilova21d0822016-08-10 11:19:23 -07009563 reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
9564 IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
Don Skidmore3f207802014-12-23 07:40:34 +00009565}
9566
9567/**
Emil Tantilova21d0822016-08-10 11:19:23 -07009568 * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
Don Skidmore3f207802014-12-23 07:40:34 +00009569 * @dev: The port's netdev
Sabrina Dubrocae5de25d2016-07-11 13:12:28 +02009570 * @ti: Tunnel endpoint information
Don Skidmore3f207802014-12-23 07:40:34 +00009571 **/
Emil Tantilova21d0822016-08-10 11:19:23 -07009572static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
9573 struct udp_tunnel_info *ti)
Don Skidmore3f207802014-12-23 07:40:34 +00009574{
9575 struct ixgbe_adapter *adapter = netdev_priv(dev);
Emil Tantilova21d0822016-08-10 11:19:23 -07009576 u32 port_mask;
Don Skidmore3f207802014-12-23 07:40:34 +00009577
Emil Tantilova21d0822016-08-10 11:19:23 -07009578 if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
9579 ti->type != UDP_TUNNEL_TYPE_GENEVE)
Alexander Duyckb3a49552016-06-16 12:22:19 -07009580 return;
9581
9582 if (ti->sa_family != AF_INET)
9583 return;
9584
Emil Tantilova21d0822016-08-10 11:19:23 -07009585 switch (ti->type) {
9586 case UDP_TUNNEL_TYPE_VXLAN:
9587 if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
9588 return;
Mark Rustad67359c32015-06-15 11:33:25 -07009589
Emil Tantilova21d0822016-08-10 11:19:23 -07009590 if (adapter->vxlan_port != ti->port) {
9591 netdev_info(dev, "VXLAN port %d not found\n",
9592 ntohs(ti->port));
9593 return;
9594 }
9595
9596 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
9597 break;
9598 case UDP_TUNNEL_TYPE_GENEVE:
9599 if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
9600 return;
9601
9602 if (adapter->geneve_port != ti->port) {
9603 netdev_info(dev, "GENEVE port %d not found\n",
9604 ntohs(ti->port));
9605 return;
9606 }
9607
9608 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
9609 break;
9610 default:
Don Skidmore3f207802014-12-23 07:40:34 +00009611 return;
9612 }
9613
Emil Tantilova21d0822016-08-10 11:19:23 -07009614 ixgbe_clear_udp_tunnel_port(adapter, port_mask);
9615 adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
Don Skidmore3f207802014-12-23 07:40:34 +00009616}
9617
stephen hemmingeredc7d572012-10-01 12:32:33 +00009618static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009619 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +01009620 const unsigned char *addr, u16 vid,
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009621 u16 flags)
9622{
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009623 /* guarantee we can provide a unique filter for the unicast address */
Ben Hutchings46acc462012-11-01 09:11:11 +00009624 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
Alexander Duyck2f9be162015-10-22 16:26:42 -07009625 struct ixgbe_adapter *adapter = netdev_priv(dev);
9626 u16 pool = VMDQ_P(0);
9627
9628 if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
Alexander Duyckbcfd3432014-07-17 02:11:22 +00009629 return -ENOMEM;
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009630 }
9631
Jiri Pirkof6f64242014-11-28 14:34:15 +01009632 return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
John Fastabend0f4b0ad2012-04-15 06:44:19 +00009633}
9634
Don Skidmore219efe92015-04-09 22:03:22 -07009635/**
9636 * ixgbe_configure_bridge_mode - set various bridge modes
Tony Nguyen5ba643c2017-12-04 11:28:30 -08009637 * @adapter: the private structure
9638 * @mode: requested bridge mode
Don Skidmore219efe92015-04-09 22:03:22 -07009639 *
9640 * Configure some settings require for various bridge modes.
9641 **/
9642static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
9643 __u16 mode)
9644{
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009645 struct ixgbe_hw *hw = &adapter->hw;
9646 unsigned int p, num_pools;
9647 u32 vmdctl;
9648
Don Skidmore219efe92015-04-09 22:03:22 -07009649 switch (mode) {
9650 case BRIDGE_MODE_VEPA:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009651 /* disable Tx loopback, rely on switch hairpin mode */
Don Skidmore219efe92015-04-09 22:03:22 -07009652 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009653
9654 /* must enable Rx switching replication to allow multicast
9655 * packet reception on all VFs, and to enable source address
9656 * pruning.
9657 */
9658 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9659 vmdctl |= IXGBE_VT_CTL_REPLEN;
9660 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9661
9662 /* enable Rx source address pruning. Note, this requires
9663 * replication to be enabled or else it does nothing.
9664 */
9665 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9666 for (p = 0; p < num_pools; p++) {
9667 if (hw->mac.ops.set_source_address_pruning)
9668 hw->mac.ops.set_source_address_pruning(hw,
9669 true,
9670 p);
9671 }
Don Skidmore219efe92015-04-09 22:03:22 -07009672 break;
9673 case BRIDGE_MODE_VEB:
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009674 /* enable Tx loopback for internal VF/PF communication */
Don Skidmore219efe92015-04-09 22:03:22 -07009675 IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
9676 IXGBE_PFDTXGSWC_VT_LBEN);
Don Skidmore6d4c96a2015-04-09 22:03:23 -07009677
9678 /* disable Rx switching replication unless we have SR-IOV
9679 * virtual functions
9680 */
9681 vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
9682 if (!adapter->num_vfs)
9683 vmdctl &= ~IXGBE_VT_CTL_REPLEN;
9684 IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
9685
9686 /* disable Rx source address pruning, since we don't expect to
9687 * be receiving external loopback of our transmitted frames.
9688 */
9689 num_pools = adapter->num_vfs + adapter->num_rx_pools;
9690 for (p = 0; p < num_pools; p++) {
9691 if (hw->mac.ops.set_source_address_pruning)
9692 hw->mac.ops.set_source_address_pruning(hw,
9693 false,
9694 p);
9695 }
Don Skidmore219efe92015-04-09 22:03:22 -07009696 break;
9697 default:
9698 return -EINVAL;
9699 }
9700
9701 adapter->bridge_mode = mode;
9702
9703 e_info(drv, "enabling bridge mode: %s\n",
9704 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
9705
9706 return 0;
9707}
9708
John Fastabend815cccb2012-10-24 08:13:09 +00009709static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
Roopa Prabhuadd511b2015-01-29 22:40:12 -08009710 struct nlmsghdr *nlh, u16 flags)
John Fastabend815cccb2012-10-24 08:13:09 +00009711{
9712 struct ixgbe_adapter *adapter = netdev_priv(dev);
9713 struct nlattr *attr, *br_spec;
9714 int rem;
9715
9716 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9717 return -EOPNOTSUPP;
9718
9719 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
Thomas Graf4ea85e82014-11-26 13:42:18 +01009720 if (!br_spec)
9721 return -EINVAL;
John Fastabend815cccb2012-10-24 08:13:09 +00009722
9723 nla_for_each_nested(attr, br_spec, rem) {
Mark Rustada1e869d2015-04-10 10:36:36 -07009724 int status;
John Fastabend815cccb2012-10-24 08:13:09 +00009725 __u16 mode;
John Fastabend815cccb2012-10-24 08:13:09 +00009726
9727 if (nla_type(attr) != IFLA_BRIDGE_MODE)
9728 continue;
9729
Thomas Grafb7c1a312014-11-26 13:42:17 +01009730 if (nla_len(attr) < sizeof(mode))
9731 return -EINVAL;
9732
John Fastabend815cccb2012-10-24 08:13:09 +00009733 mode = nla_get_u16(attr);
Don Skidmore219efe92015-04-09 22:03:22 -07009734 status = ixgbe_configure_bridge_mode(adapter, mode);
9735 if (status)
9736 return status;
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009737
9738 break;
John Fastabend815cccb2012-10-24 08:13:09 +00009739 }
9740
9741 return 0;
9742}
9743
9744static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +00009745 struct net_device *dev,
Nicolas Dichtel46c264d2015-04-28 18:33:49 +02009746 u32 filter_mask, int nlflags)
John Fastabend815cccb2012-10-24 08:13:09 +00009747{
9748 struct ixgbe_adapter *adapter = netdev_priv(dev);
John Fastabend815cccb2012-10-24 08:13:09 +00009749
9750 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
9751 return 0;
9752
Don Skidmoreaa2bacb2015-04-09 22:03:22 -07009753 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
Scott Feldman7d4f8d82015-06-22 00:27:17 -07009754 adapter->bridge_mode, 0, 0, nlflags,
9755 filter_mask, NULL);
John Fastabend815cccb2012-10-24 08:13:09 +00009756}
9757
John Fastabend2a47fa42013-11-06 09:54:52 -08009758static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
9759{
John Fastabend2a47fa42013-11-06 09:54:52 -08009760 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Alexander Duyck8315ef62018-04-03 17:16:45 -04009761 struct ixgbe_fwd_adapter *accel;
Alexander Duyck0efbf122017-11-22 10:57:11 -08009762 int tcs = adapter->hw_tcs ? : 1;
John Fastabend2a47fa42013-11-06 09:54:52 -08009763 int pool, err;
9764
Alexander Duyck33359152018-04-03 17:16:35 -04009765 /* The hardware supported by ixgbe only filters on the destination MAC
9766 * address. In order to avoid issues we only support offloading modes
9767 * where the hardware can actually provide the functionality.
9768 */
9769 if (!macvlan_supports_dest_filter(vdev))
9770 return ERR_PTR(-EMEDIUMTYPE);
9771
Alexander Duyck8315ef62018-04-03 17:16:45 -04009772 pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
9773 if (pool == adapter->num_rx_pools) {
9774 u16 used_pools = adapter->num_vfs + adapter->num_rx_pools;
9775 u16 reserved_pools;
Jacob Kelleraac2f1b2014-08-21 06:17:59 +00009776
Alexander Duyck8315ef62018-04-03 17:16:45 -04009777 if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
9778 adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) ||
9779 adapter->num_rx_pools > IXGBE_MAX_MACVLANS)
9780 return ERR_PTR(-EBUSY);
John Fastabend2a47fa42013-11-06 09:54:52 -08009781
Alexander Duyck8315ef62018-04-03 17:16:45 -04009782 /* Hardware has a limited number of available pools. Each VF,
9783 * and the PF require a pool. Check to ensure we don't
9784 * attempt to use more then the available number of pools.
9785 */
9786 if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
9787 return ERR_PTR(-EBUSY);
9788
9789 /* Enable VMDq flag so device will be set in VM mode */
9790 adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED |
9791 IXGBE_FLAG_SRIOV_ENABLED;
9792
9793 /* Try to reserve as many queues per pool as possible,
9794 * we start with the configurations that support 4 queues
9795 * per pools, followed by 2, and then by just 1 per pool.
9796 */
9797 if (used_pools < 32 && adapter->num_rx_pools < 16)
9798 reserved_pools = min_t(u16,
9799 32 - used_pools,
9800 16 - adapter->num_rx_pools);
9801 else if (adapter->num_rx_pools < 32)
9802 reserved_pools = min_t(u16,
9803 64 - used_pools,
9804 32 - adapter->num_rx_pools);
9805 else
9806 reserved_pools = 64 - used_pools;
9807
9808
9809 if (!reserved_pools)
9810 return ERR_PTR(-EBUSY);
9811
9812 adapter->ring_feature[RING_F_VMDQ].limit += reserved_pools;
9813
9814 /* Force reinit of ring allocation with VMDQ enabled */
9815 err = ixgbe_setup_tc(pdev, adapter->hw_tcs);
9816 if (err)
9817 return ERR_PTR(err);
9818
9819 if (pool >= adapter->num_rx_pools)
9820 return ERR_PTR(-ENOMEM);
9821 }
9822
9823 accel = kzalloc(sizeof(*accel), GFP_KERNEL);
9824 if (!accel)
John Fastabend2a47fa42013-11-06 09:54:52 -08009825 return ERR_PTR(-ENOMEM);
9826
Alexander Duyck4e039c12017-11-22 10:56:40 -08009827 set_bit(pool, adapter->fwd_bitmask);
Alexander Duyck8315ef62018-04-03 17:16:45 -04009828 accel->pool = pool;
9829 accel->netdev = vdev;
John Fastabend2a47fa42013-11-06 09:54:52 -08009830
Alexander Duyck8315ef62018-04-03 17:16:45 -04009831 if (!netif_running(pdev))
9832 return accel;
John Fastabend2a47fa42013-11-06 09:54:52 -08009833
Alexander Duyck8315ef62018-04-03 17:16:45 -04009834 err = ixgbe_fwd_ring_up(adapter, accel);
9835 if (err)
9836 return ERR_PTR(err);
Emil Tantilova3b8cb12016-09-22 15:06:52 -07009837
Alexander Duyck8315ef62018-04-03 17:16:45 -04009838 return accel;
John Fastabend2a47fa42013-11-06 09:54:52 -08009839}
9840
9841static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
9842{
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009843 struct ixgbe_fwd_adapter *accel = priv;
Alexander Duyck865255b2018-04-03 17:16:40 -04009844 struct ixgbe_adapter *adapter = netdev_priv(pdev);
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009845 unsigned int rxbase = accel->rx_base_queue;
Alexander Duyck8315ef62018-04-03 17:16:45 -04009846 unsigned int i;
John Fastabend2a47fa42013-11-06 09:54:52 -08009847
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009848 /* delete unicast filter associated with offloaded interface */
9849 ixgbe_del_mac_filter(adapter, accel->netdev->dev_addr,
9850 VMDQ_P(accel->pool));
John Fastabend2a47fa42013-11-06 09:54:52 -08009851
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009852 /* Allow remaining Rx packets to get flushed out of the
9853 * Rx FIFO before we drop the netdev for the ring.
9854 */
9855 usleep_range(10000, 20000);
9856
9857 for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
9858 struct ixgbe_ring *ring = adapter->rx_ring[rxbase + i];
9859 struct ixgbe_q_vector *qv = ring->q_vector;
9860
9861 /* Make sure we aren't processing any packets and clear
9862 * netdev to shut down the ring.
9863 */
9864 if (netif_running(adapter->netdev))
9865 napi_synchronize(&qv->napi);
9866 ring->netdev = NULL;
9867 }
9868
9869 clear_bit(accel->pool, adapter->fwd_bitmask);
Alexander Duyckb5f69cc2017-11-22 10:57:29 -08009870 kfree(accel);
John Fastabend2a47fa42013-11-06 09:54:52 -08009871}
9872
Alexander Duyckb83e3012016-04-14 17:19:31 -04009873#define IXGBE_MAX_MAC_HDR_LEN 127
9874#define IXGBE_MAX_NETWORK_HDR_LEN 511
9875
Mark Rustadf467bc02015-06-15 11:33:20 -07009876static netdev_features_t
9877ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
9878 netdev_features_t features)
9879{
Alexander Duyckb83e3012016-04-14 17:19:31 -04009880 unsigned int network_hdr_len, mac_hdr_len;
Mark Rustadf467bc02015-06-15 11:33:20 -07009881
Alexander Duyckb83e3012016-04-14 17:19:31 -04009882 /* Make certain the headers can be described by a context descriptor */
9883 mac_hdr_len = skb_network_header(skb) - skb->data;
9884 if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
9885 return features & ~(NETIF_F_HW_CSUM |
9886 NETIF_F_SCTP_CRC |
9887 NETIF_F_HW_VLAN_CTAG_TX |
9888 NETIF_F_TSO |
9889 NETIF_F_TSO6);
9890
9891 network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
9892 if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
9893 return features & ~(NETIF_F_HW_CSUM |
9894 NETIF_F_SCTP_CRC |
9895 NETIF_F_TSO |
9896 NETIF_F_TSO6);
9897
9898 /* We can only support IPV4 TSO in tunnels if we can mangle the
9899 * inner IP ID field, so strip TSO if MANGLEID is not supported.
Shannon Nelson70da6822018-03-16 11:09:07 -07009900 * IPsec offoad sets skb->encapsulation but still can handle
9901 * the TSO, so it's the exception.
Alexander Duyckb83e3012016-04-14 17:19:31 -04009902 */
Shannon Nelson70da6822018-03-16 11:09:07 -07009903 if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) {
Alexander Duycke433f3a2018-06-04 16:51:20 -04009904#ifdef CONFIG_XFRM_OFFLOAD
Shannon Nelson70da6822018-03-16 11:09:07 -07009905 if (!skb->sp)
9906#endif
9907 features &= ~NETIF_F_TSO;
9908 }
Mark Rustadf467bc02015-06-15 11:33:20 -07009909
9910 return features;
9911}
9912
John Fastabend92470802017-04-24 03:30:17 -07009913static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
9914{
9915 int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
9916 struct ixgbe_adapter *adapter = netdev_priv(dev);
9917 struct bpf_prog *old_prog;
9918
9919 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
9920 return -EINVAL;
9921
9922 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
9923 return -EINVAL;
9924
9925 /* verify ixgbe ring attributes are sufficient for XDP */
9926 for (i = 0; i < adapter->num_rx_queues; i++) {
9927 struct ixgbe_ring *ring = adapter->rx_ring[i];
9928
9929 if (ring_is_rsc_enabled(ring))
9930 return -EINVAL;
9931
9932 if (frame_size > ixgbe_rx_bufsz(ring))
9933 return -EINVAL;
9934 }
9935
John Fastabend33fdc822017-04-24 03:30:18 -07009936 if (nr_cpu_ids > MAX_XDP_QUEUES)
9937 return -ENOMEM;
9938
John Fastabend92470802017-04-24 03:30:17 -07009939 old_prog = xchg(&adapter->xdp_prog, prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009940
9941 /* If transitioning XDP modes reconfigure rings */
9942 if (!!prog != !!old_prog) {
Alexander Duyck0efbf122017-11-22 10:57:11 -08009943 int err = ixgbe_setup_tc(dev, adapter->hw_tcs);
John Fastabend33fdc822017-04-24 03:30:18 -07009944
9945 if (err) {
9946 rcu_assign_pointer(adapter->xdp_prog, old_prog);
9947 return -EINVAL;
9948 }
9949 } else {
9950 for (i = 0; i < adapter->num_rx_queues; i++)
Cathy Zhou9cfbfa72018-04-13 11:28:37 -07009951 (void)xchg(&adapter->rx_ring[i]->xdp_prog,
9952 adapter->xdp_prog);
John Fastabend33fdc822017-04-24 03:30:18 -07009953 }
John Fastabend92470802017-04-24 03:30:17 -07009954
9955 if (old_prog)
9956 bpf_prog_put(old_prog);
9957
9958 return 0;
9959}
9960
Jakub Kicinskif4e63522017-11-03 13:56:16 -07009961static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
John Fastabend92470802017-04-24 03:30:17 -07009962{
9963 struct ixgbe_adapter *adapter = netdev_priv(dev);
9964
9965 switch (xdp->command) {
9966 case XDP_SETUP_PROG:
9967 return ixgbe_xdp_setup(dev, xdp->prog);
9968 case XDP_QUERY_PROG:
9969 xdp->prog_attached = !!(adapter->xdp_prog);
Martin KaFai Lau47920932017-06-15 17:29:15 -07009970 xdp->prog_id = adapter->xdp_prog ?
9971 adapter->xdp_prog->aux->id : 0;
John Fastabend92470802017-04-24 03:30:17 -07009972 return 0;
9973 default:
9974 return -EINVAL;
9975 }
9976}
9977
Jesper Dangaard Brouer5e2e6092018-05-31 10:59:57 +02009978static void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring)
9979{
9980 /* Force memory writes to complete before letting h/w know there
9981 * are new descriptors to fetch.
9982 */
9983 wmb();
9984 writel(ring->next_to_use, ring->tail);
9985}
9986
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +02009987static int ixgbe_xdp_xmit(struct net_device *dev, int n,
Jesper Dangaard Brouer42b33462018-05-31 10:59:47 +02009988 struct xdp_frame **frames, u32 flags)
John Fastabend64530732017-07-17 09:28:12 -07009989{
9990 struct ixgbe_adapter *adapter = netdev_priv(dev);
9991 struct ixgbe_ring *ring;
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +02009992 int drops = 0;
9993 int i;
John Fastabend64530732017-07-17 09:28:12 -07009994
9995 if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +02009996 return -ENETDOWN;
John Fastabend64530732017-07-17 09:28:12 -07009997
Jesper Dangaard Brouer5e2e6092018-05-31 10:59:57 +02009998 if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
Jesper Dangaard Brouer42b33462018-05-31 10:59:47 +02009999 return -EINVAL;
10000
John Fastabend64530732017-07-17 09:28:12 -070010001 /* During program transitions its possible adapter->xdp_prog is assigned
10002 * but ring has not been configured yet. In this case simply abort xmit.
10003 */
10004 ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
10005 if (unlikely(!ring))
Jesper Dangaard Brouer28864472017-08-24 12:33:13 +020010006 return -ENXIO;
John Fastabend64530732017-07-17 09:28:12 -070010007
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +020010008 for (i = 0; i < n; i++) {
10009 struct xdp_frame *xdpf = frames[i];
10010 int err;
John Fastabend64530732017-07-17 09:28:12 -070010011
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +020010012 err = ixgbe_xmit_xdp_ring(adapter, xdpf);
10013 if (err != IXGBE_XDP_TX) {
10014 xdp_return_frame_rx_napi(xdpf);
10015 drops++;
10016 }
10017 }
10018
Jesper Dangaard Brouer5e2e6092018-05-31 10:59:57 +020010019 if (unlikely(flags & XDP_XMIT_FLUSH))
10020 ixgbe_xdp_ring_update_tail(ring);
10021
Jesper Dangaard Brouer735fc402018-05-24 16:46:12 +020010022 return n - drops;
John Fastabend11393cc2017-07-17 09:29:40 -070010023}
10024
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010025static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +000010026 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010027 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -080010028 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -070010029 .ndo_select_queue = ixgbe_select_queue,
Alexander Duyck581330b2012-02-08 07:51:47 +000010030 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010031 .ndo_validate_addr = eth_validate_addr,
10032 .ndo_set_mac_address = ixgbe_set_mac,
10033 .ndo_change_mtu = ixgbe_change_mtu,
10034 .ndo_tx_timeout = ixgbe_tx_timeout,
Rostislav Pehlivanovc04f90e2016-01-27 18:33:30 +000010035 .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010036 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
10037 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +000010038 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +000010039 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
10040 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
Sucheta Chakrabortyed616682014-05-22 09:59:05 -040010041 .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
Alexander Duyck581330b2012-02-08 07:51:47 +000010042 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Vlad Zolotarove65ce0d2015-03-30 21:35:24 +030010043 .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
Hiroshi Shimamoto54011e42015-08-28 06:58:33 +000010044 .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
Greg Rose7f016482010-05-04 22:12:06 +000010045 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +000010046 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabende4c67342016-02-16 21:16:15 -080010047 .ndo_setup_tc = __ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010048#ifdef CONFIG_NET_POLL_CONTROLLER
10049 .ndo_poll_controller = ixgbe_netpoll,
10050#endif
Yi Zou332d4a72009-05-13 13:11:53 +000010051#ifdef IXGBE_FCOE
10052 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +000010053 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +000010054 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +000010055 .ndo_fcoe_enable = ixgbe_fcoe_enable,
10056 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +000010057 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +000010058 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +000010059#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +000010060 .ndo_set_features = ixgbe_set_features,
10061 .ndo_fix_features = ixgbe_fix_features,
John Fastabend0f4b0ad2012-04-15 06:44:19 +000010062 .ndo_fdb_add = ixgbe_ndo_fdb_add,
John Fastabend815cccb2012-10-24 08:13:09 +000010063 .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
10064 .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
John Fastabend2a47fa42013-11-06 09:54:52 -080010065 .ndo_dfwd_add_station = ixgbe_fwd_add,
10066 .ndo_dfwd_del_station = ixgbe_fwd_del,
Emil Tantilova21d0822016-08-10 11:19:23 -070010067 .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
10068 .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
Mark Rustadf467bc02015-06-15 11:33:20 -070010069 .ndo_features_check = ixgbe_features_check,
Jakub Kicinskif4e63522017-11-03 13:56:16 -070010070 .ndo_bpf = ixgbe_xdp,
John Fastabend64530732017-07-17 09:28:12 -070010071 .ndo_xdp_xmit = ixgbe_xdp_xmit,
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010072};
10073
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010074/**
Jacob Kellere027d1a2013-07-31 06:53:31 +000010075 * ixgbe_enumerate_functions - Get the number of ports this device has
10076 * @adapter: adapter structure
10077 *
10078 * This function enumerates the phsyical functions co-located on a single slot,
10079 * in order to determine how many ports a device has. This is most useful in
10080 * determining the required GT/s of PCIe bandwidth necessary for optimal
10081 * performance.
10082 **/
10083static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
10084{
Jacob Kellercaafb952014-07-19 07:17:17 +000010085 struct pci_dev *entry, *pdev = adapter->pdev;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010086 int physfns = 0;
10087
Jacob Kellerf1f96572013-08-31 02:45:38 +000010088 /* Some cards can not use the generic count PCIe functions method,
10089 * because they are behind a parent switch, so we hardcode these with
10090 * the correct number of functions.
Jacob Kellere027d1a2013-07-31 06:53:31 +000010091 */
Jacob Keller88189702014-07-19 07:17:16 +000010092 if (ixgbe_pcie_from_parent(&adapter->hw))
Jacob Kellere027d1a2013-07-31 06:53:31 +000010093 physfns = 4;
Jacob Keller88189702014-07-19 07:17:16 +000010094
10095 list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
10096 /* don't count virtual functions */
Jacob Kellercaafb952014-07-19 07:17:17 +000010097 if (entry->is_virtfn)
10098 continue;
10099
10100 /* When the devices on the bus don't all match our device ID,
10101 * we can't reliably determine the correct number of
10102 * functions. This can occur if a function has been direct
10103 * attached to a virtual machine using VT-d, for example. In
10104 * this case, simply return -1 to indicate this.
10105 */
10106 if ((entry->vendor != pdev->vendor) ||
10107 (entry->device != pdev->device))
10108 return -1;
10109
10110 physfns++;
Jacob Kellere027d1a2013-07-31 06:53:31 +000010111 }
10112
10113 return physfns;
10114}
10115
10116/**
Jacob Keller8e2813f2012-04-21 06:05:40 +000010117 * ixgbe_wol_supported - Check whether device supports WoL
Emil Tantilov740234f2016-04-21 11:37:12 -070010118 * @adapter: the adapter private structure
Jacob Keller8e2813f2012-04-21 06:05:40 +000010119 * @device_id: the device ID
Tony Nguyen5ba643c2017-12-04 11:28:30 -080010120 * @subdevice_id: the subsystem device ID
Jacob Keller8e2813f2012-04-21 06:05:40 +000010121 *
10122 * This function is used by probe and ethtool to determine
10123 * which devices have WoL support
10124 *
10125 **/
Emil Tantilov740234f2016-04-21 11:37:12 -070010126bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
10127 u16 subdevice_id)
Jacob Keller8e2813f2012-04-21 06:05:40 +000010128{
10129 struct ixgbe_hw *hw = &adapter->hw;
10130 u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010131
Emil Tantilov740234f2016-04-21 11:37:12 -070010132 /* WOL not supported on 82598 */
10133 if (hw->mac.type == ixgbe_mac_82598EB)
10134 return false;
10135
10136 /* check eeprom to see if WOL is enabled for X540 and newer */
10137 if (hw->mac.type >= ixgbe_mac_X540) {
10138 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
10139 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
10140 (hw->bus.func == 0)))
10141 return true;
10142 }
10143
10144 /* WOL is determined based on device IDs for 82599 MACs */
Jacob Keller8e2813f2012-04-21 06:05:40 +000010145 switch (device_id) {
10146 case IXGBE_DEV_ID_82599_SFP:
10147 /* Only these subdevices could supports WOL */
10148 switch (subdevice_id) {
10149 case IXGBE_SUBDEV_ID_82599_560FLR:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010150 case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
10151 case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
10152 case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010153 /* only support first port */
10154 if (hw->bus.func != 0)
10155 break;
Tony Nguyen93df9462017-05-31 04:43:47 -070010156 /* fall through */
Emil Tantilov5700ff22013-04-18 08:18:55 +000010157 case IXGBE_SUBDEV_ID_82599_SP_560FLR:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010158 case IXGBE_SUBDEV_ID_82599_SFP:
Don Skidmoreb6dfd932012-07-11 07:17:42 +000010159 case IXGBE_SUBDEV_ID_82599_RNDC:
Emil Tantilovf8a06c22012-08-16 08:13:07 +000010160 case IXGBE_SUBDEV_ID_82599_ECNA_DP:
Emil Tantilov00103a6c2016-04-21 11:37:06 -070010161 case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
10162 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
10163 case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
Emil Tantilov740234f2016-04-21 11:37:12 -070010164 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010165 }
10166 break;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010167 case IXGBE_DEV_ID_82599EN_SFP:
Emil Tantilov740234f2016-04-21 11:37:12 -070010168 /* Only these subdevices support WOL */
Don Skidmore5daebbb2013-04-05 05:49:34 +000010169 switch (subdevice_id) {
10170 case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
Emil Tantilov740234f2016-04-21 11:37:12 -070010171 return true;
Don Skidmore5daebbb2013-04-05 05:49:34 +000010172 }
10173 break;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010174 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
10175 /* All except this subdevice support WOL */
10176 if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Emil Tantilov740234f2016-04-21 11:37:12 -070010177 return true;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010178 break;
10179 case IXGBE_DEV_ID_82599_KX4:
Emil Tantilov740234f2016-04-21 11:37:12 -070010180 return true;
10181 default:
Jacob Keller8e2813f2012-04-21 06:05:40 +000010182 break;
10183 }
10184
Emil Tantilov740234f2016-04-21 11:37:12 -070010185 return false;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010186}
10187
10188/**
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010189 * ixgbe_set_fw_version - Set FW version
10190 * @adapter: the adapter private structure
10191 *
10192 * This function is used by probe and ethtool to determine the FW version to
10193 * format to display. The FW version is taken from the EEPROM/NVM.
10194 */
10195static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
10196{
10197 struct ixgbe_hw *hw = &adapter->hw;
10198 struct ixgbe_nvm_version nvm_ver;
10199
10200 ixgbe_get_oem_prod_version(hw, &nvm_ver);
10201 if (nvm_ver.oem_valid) {
10202 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10203 "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
10204 nvm_ver.oem_release);
10205 return;
10206 }
10207
10208 ixgbe_get_etk_id(hw, &nvm_ver);
10209 ixgbe_get_orom_version(hw, &nvm_ver);
10210
10211 if (nvm_ver.or_valid) {
10212 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10213 "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
10214 nvm_ver.or_build, nvm_ver.or_patch);
10215 return;
10216 }
10217
10218 /* Set ETrack ID format */
10219 snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
10220 "0x%08x", nvm_ver.etk_id);
10221}
10222
10223/**
Auke Kok9a799d72007-09-15 14:07:45 -070010224 * ixgbe_probe - Device Initialization Routine
10225 * @pdev: PCI device information struct
10226 * @ent: entry in ixgbe_pci_tbl
10227 *
10228 * Returns 0 on success, negative on failure
10229 *
10230 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
10231 * The OS initialization, configuring of the adapter private structure,
10232 * and a hardware reset occur.
10233 **/
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000010234static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -070010235{
10236 struct net_device *netdev;
10237 struct ixgbe_adapter *adapter = NULL;
10238 struct ixgbe_hw *hw;
10239 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Jacob Kellere027d1a2013-07-31 06:53:31 +000010240 int i, err, pci_using_dac, expected_gts;
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010241 unsigned int indices = MAX_TX_QUEUES;
Don Skidmore289700db2010-12-03 03:32:58 +000010242 u8 part_str[IXGBE_PBANUM_LENGTH];
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010243 bool disable_dev = false;
Yi Zoueacd73f2009-05-13 13:11:06 +000010244#ifdef IXGBE_FCOE
10245 u16 device_caps;
10246#endif
Don Skidmore289700db2010-12-03 03:32:58 +000010247 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -070010248
Andy Gospodarekbded64a2010-07-21 06:40:31 +000010249 /* Catch broken hardware that put the wrong VF device ID in
10250 * the PCIe SR-IOV capability.
10251 */
10252 if (pdev->is_virtfn) {
10253 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
10254 pci_name(pdev), pdev->vendor, pdev->device);
10255 return -EINVAL;
10256 }
10257
gouji-new9ce77662009-05-06 10:44:45 +000010258 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010259 if (err)
10260 return err;
10261
Russell Kingf5f2eda2013-06-10 12:47:42 +010010262 if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -070010263 pci_using_dac = 1;
10264 } else {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010265 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -070010266 if (err) {
Russell Kingf5f2eda2013-06-10 12:47:42 +010010267 dev_err(&pdev->dev,
10268 "No usable DMA configuration, aborting\n");
10269 goto err_dma;
Auke Kok9a799d72007-09-15 14:07:45 -070010270 }
10271 pci_using_dac = 0;
10272 }
10273
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010274 err = pci_request_mem_regions(pdev, ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -070010275 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +000010276 dev_err(&pdev->dev,
10277 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -070010278 goto err_pci_reg;
10279 }
10280
Frans Pop19d5afd2009-10-02 10:04:12 -070010281 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010282
Auke Kok9a799d72007-09-15 14:07:45 -070010283 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -070010284 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010285
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010286 if (ii->mac == ixgbe_mac_82598EB) {
John Fastabende901acd2011-04-26 07:26:08 +000010287#ifdef CONFIG_IXGBE_DCB
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010288 /* 8 TC w/ 4 queues per TC */
10289 indices = 4 * MAX_TRAFFIC_CLASS;
10290#else
10291 indices = IXGBE_MAX_RSS_INDICES;
John Fastabende901acd2011-04-26 07:26:08 +000010292#endif
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010293 }
John Fastabende901acd2011-04-26 07:26:08 +000010294
John Fastabendc85a2612010-02-25 23:15:21 +000010295 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -070010296 if (!netdev) {
10297 err = -ENOMEM;
10298 goto err_alloc_etherdev;
10299 }
10300
Auke Kok9a799d72007-09-15 14:07:45 -070010301 SET_NETDEV_DEV(netdev, &pdev->dev);
10302
Auke Kok9a799d72007-09-15 14:07:45 -070010303 adapter = netdev_priv(netdev);
10304
10305 adapter->netdev = netdev;
10306 adapter->pdev = pdev;
10307 hw = &adapter->hw;
10308 hw->back = adapter;
stephen hemmingerb3f4d592012-03-13 06:04:20 +000010309 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
Auke Kok9a799d72007-09-15 14:07:45 -070010310
Jeff Kirsher05857982008-09-11 19:57:00 -070010311 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +000010312 pci_resource_len(pdev, 0));
Mark Rustad2a1a0912014-01-14 18:53:15 -080010313 adapter->io_addr = hw->hw_addr;
Auke Kok9a799d72007-09-15 14:07:45 -070010314 if (!hw->hw_addr) {
10315 err = -EIO;
10316 goto err_ioremap;
10317 }
10318
Stephen Hemminger0edc3522008-11-19 22:24:29 -080010319 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010320 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010321 netdev->watchdog_timeo = 5 * HZ;
Mark Rustad339de302014-06-06 01:57:06 +000010322 strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
Auke Kok9a799d72007-09-15 14:07:45 -070010323
Auke Kok9a799d72007-09-15 14:07:45 -070010324 /* Setup hw api */
Mark Rustad37689012016-01-07 10:13:03 -080010325 hw->mac.ops = *ii->mac_ops;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010326 hw->mac.type = ii->mac;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010327 hw->mvals = ii->mvals;
Emil Tantilovb71f6c42016-10-10 14:54:03 -070010328 if (ii->link_ops)
10329 hw->link.ops = *ii->link_ops;
Auke Kok9a799d72007-09-15 14:07:45 -070010330
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010331 /* EEPROM */
Mark Rustad37689012016-01-07 10:13:03 -080010332 hw->eeprom.ops = *ii->eeprom_ops;
Don Skidmore9a900ec2015-06-09 17:15:01 -070010333 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
Mark Rustad58cf6632014-03-12 00:38:40 +000010334 if (ixgbe_removed(hw->hw_addr)) {
10335 err = -EIO;
10336 goto err_ioremap;
10337 }
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010338 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
Jacob Kellerb4f47a42016-04-13 16:08:22 -070010339 if (!(eec & BIT(8)))
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010340 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
10341
10342 /* PHY */
Mark Rustad37689012016-01-07 10:13:03 -080010343 hw->phy.ops = *ii->phy_ops;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010344 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +000010345 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
10346 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
10347 hw->phy.mdio.mmds = 0;
10348 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
10349 hw->phy.mdio.dev = netdev;
10350 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
10351 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -080010352
Auke Kok9a799d72007-09-15 14:07:45 -070010353 /* setup the private structure */
Emil Tantilov55570b62016-10-12 12:34:25 -070010354 err = ixgbe_sw_init(adapter, ii);
Auke Kok9a799d72007-09-15 14:07:45 -070010355 if (err)
10356 goto err_sw_init;
10357
Don Skidmoredbd15b82016-03-09 16:45:00 -050010358 /* Make sure the SWFW semaphore is in a valid state */
10359 if (hw->mac.ops.init_swfw_sync)
10360 hw->mac.ops.init_swfw_sync(hw);
10361
Don Skidmoree86bff02010-02-11 04:14:08 +000010362 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -080010363 switch (adapter->hw.mac.type) {
10364 case ixgbe_mac_82599EB:
10365 case ixgbe_mac_X540:
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010366 case ixgbe_mac_X550:
10367 case ixgbe_mac_X550EM_x:
Mark Rustad49425df2016-04-01 12:18:09 -070010368 case ixgbe_mac_x550em_a:
Don Skidmoree86bff02010-02-11 04:14:08 +000010369 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -080010370 break;
10371 default:
10372 break;
10373 }
Don Skidmoree86bff02010-02-11 04:14:08 +000010374
Don Skidmorebf069c92009-05-07 10:39:54 +000010375 /*
10376 * If there is a fan on this device and it has failed log the
10377 * failure.
10378 */
10379 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
10380 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
10381 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +000010382 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +000010383 }
10384
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +000010385 if (allow_unsupported_sfp)
10386 hw->allow_unsupported_sfp = allow_unsupported_sfp;
10387
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010388 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010389 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010390 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -070010391 hw->phy.reset_if_overtemp = false;
Mark Rustadb3eb4e12016-12-14 11:02:16 -080010392 ixgbe_set_eee_capable(adapter);
Mark Rustad29a8dca2015-08-08 16:17:46 -070010393 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
Don Skidmore8ca783a2009-05-26 20:40:47 -070010394 err = 0;
10395 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Don Skidmore1b1bf312013-07-31 05:27:04 +000010396 e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
10397 e_dev_err("Reload the driver after installing a supported module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010398 goto err_sw_init;
10399 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010400 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010401 goto err_sw_init;
10402 }
10403
Alexander Duyck99d74482012-05-09 08:09:25 +000010404#ifdef CONFIG_PCI_IOV
Greg Rose60a1a682012-12-11 08:26:33 +000010405 /* SR-IOV not supported on the 82598 */
10406 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
10407 goto skip_sriov;
10408 /* Mailbox */
10409 ixgbe_init_mbx_params_pf(hw);
Mark Rustad37689012016-01-07 10:13:03 -080010410 hw->mbx.ops = ii->mbx_ops;
ethan.zhaodcc23e32014-01-16 19:41:04 -080010411 pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
Emil Tantilov5c11f002017-01-20 14:11:56 -080010412 ixgbe_enable_sriov(adapter, max_vfs);
Greg Rose60a1a682012-12-11 08:26:33 +000010413skip_sriov:
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010414
Alexander Duyck99d74482012-05-09 08:09:25 +000010415#endif
Emil Tantilov396e7992010-07-01 20:05:12 +000010416 netdev->features = NETIF_F_SG |
Don Skidmore082757a2011-07-21 05:55:00 +000010417 NETIF_F_TSO |
10418 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +000010419 NETIF_F_RXHASH |
Alexander Duyck49763de2016-01-13 07:31:11 -080010420 NETIF_F_RXCSUM |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010421 NETIF_F_HW_CSUM;
10422
10423#define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
10424 NETIF_F_GSO_GRE_CSUM | \
Tom Herbert7e133182016-05-18 09:06:10 -070010425 NETIF_F_GSO_IPXIP4 | \
Alexander Duyckbf2d1df2016-05-18 10:44:53 -070010426 NETIF_F_GSO_IPXIP6 | \
Alexander Duyckb83e3012016-04-14 17:19:31 -040010427 NETIF_F_GSO_UDP_TUNNEL | \
10428 NETIF_F_GSO_UDP_TUNNEL_CSUM)
10429
10430 netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
10431 netdev->features |= NETIF_F_GSO_PARTIAL |
10432 IXGBE_GSO_PARTIAL_FEATURES;
Auke Kok9a799d72007-09-15 14:07:45 -070010433
Alexander Duyck49763de2016-01-13 07:31:11 -080010434 if (hw->mac.type >= ixgbe_mac_82599EB)
Tom Herbert53692b12015-12-14 11:19:41 -080010435 netdev->features |= NETIF_F_SCTP_CRC;
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +000010436
Alexander Duyckde7a7e32018-06-04 16:51:25 -040010437#ifdef CONFIG_XFRM_OFFLOAD
10438#define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \
10439 NETIF_F_HW_ESP_TX_CSUM | \
10440 NETIF_F_GSO_ESP)
10441
10442 if (adapter->ipsec)
10443 netdev->features |= IXGBE_ESP_FEATURES;
10444#endif
Alexander Duyck49763de2016-01-13 07:31:11 -080010445 /* copy netdev features into list of user selectable features */
Alexander Duyckb83e3012016-04-14 17:19:31 -040010446 netdev->hw_features |= netdev->features |
Alexander Duyck3d951822016-08-12 09:53:39 -070010447 NETIF_F_HW_VLAN_CTAG_FILTER |
Alexander Duyckb83e3012016-04-14 17:19:31 -040010448 NETIF_F_HW_VLAN_CTAG_RX |
10449 NETIF_F_HW_VLAN_CTAG_TX |
10450 NETIF_F_RXALL |
Alexander Duyck49763de2016-01-13 07:31:11 -080010451 NETIF_F_HW_L2FW_DOFFLOAD;
10452
10453 if (hw->mac.type >= ixgbe_mac_82599EB)
10454 netdev->hw_features |= NETIF_F_NTUPLE |
10455 NETIF_F_HW_TC;
10456
Alexander Duyckb83e3012016-04-14 17:19:31 -040010457 if (pci_using_dac)
10458 netdev->features |= NETIF_F_HIGHDMA;
Jeff Kirsherad31c402008-06-05 04:05:30 -070010459
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010460 netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
10461 netdev->hw_enc_features |= netdev->vlan_features;
Scott Peterson2a205252016-11-18 11:25:42 -080010462 netdev->mpls_features |= NETIF_F_SG |
10463 NETIF_F_TSO |
10464 NETIF_F_TSO6 |
10465 NETIF_F_HW_CSUM;
10466 netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
Alexander Duyck5eee87c2016-05-11 13:23:34 -070010467
Alexander Duyckb83e3012016-04-14 17:19:31 -040010468 /* set this bit last since it cannot be part of vlan_features */
10469 netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
10470 NETIF_F_HW_VLAN_CTAG_RX |
10471 NETIF_F_HW_VLAN_CTAG_TX;
10472
Jiri Pirko01789342011-08-16 06:29:00 +000010473 netdev->priv_flags |= IFF_UNICAST_FLT;
Ben Greearf43f3132012-03-06 09:42:04 +000010474 netdev->priv_flags |= IFF_SUPP_NOFCS;
Jiri Pirko01789342011-08-16 06:29:00 +000010475
Jarod Wilson91c527a2016-10-17 15:54:05 -040010476 /* MTU range: 68 - 9710 */
10477 netdev->min_mtu = ETH_MIN_MTU;
10478 netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
10479
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080010480#ifdef CONFIG_IXGBE_DCB
Usha Ketineni88290092016-04-26 05:00:26 -070010481 if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
Stephen Hemminger3f40c742016-11-21 09:52:40 -080010482 netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
Alexander Duyck2f90b862008-11-20 20:52:10 -080010483#endif
10484
Yi Zoueacd73f2009-05-13 13:11:06 +000010485#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +000010486 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010487 unsigned int fcoe_l;
10488
Yi Zoueacd73f2009-05-13 13:11:06 +000010489 if (hw->mac.ops.get_device_caps) {
10490 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +000010491 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
10492 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +000010493 }
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010494
Alexander Duyckd3cb9862013-01-16 01:35:35 +000010495
10496 fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
10497 adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010498
Alexander Duycka58915c2012-05-25 06:38:18 +000010499 netdev->features |= NETIF_F_FSO |
10500 NETIF_F_FCOE_CRC;
10501
Alexander Duyck7c8ae652012-05-05 05:32:47 +000010502 netdev->vlan_features |= NETIF_F_FSO |
10503 NETIF_F_FCOE_CRC |
10504 NETIF_F_FCOE_MTU;
Yi Zou5e09d7f2010-07-19 13:59:52 +000010505 }
Yi Zoueacd73f2009-05-13 13:11:06 +000010506#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +000010507 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
10508 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +000010509 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +000010510 netdev->features |= NETIF_F_LRO;
10511
Auke Kok9a799d72007-09-15 14:07:45 -070010512 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -070010513 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010514 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010515 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010516 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010517 }
10518
Sowmini Varadhanc7374b52016-01-12 19:32:30 -080010519 eth_platform_get_mac_address(&adapter->pdev->dev,
10520 adapter->hw.mac.perm_addr);
Martin K Petersenc762dff2014-11-15 14:24:51 +000010521
Auke Kok9a799d72007-09-15 14:07:45 -070010522 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -070010523
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +000010524 if (!is_valid_ether_addr(netdev->dev_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010525 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -070010526 err = -EIO;
Alexander Duyck35937c02012-02-08 07:51:37 +000010527 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010528 }
10529
Tushar Dave56768042016-01-07 14:17:03 -080010530 /* Set hw->mac.addr to permanent MAC address */
10531 ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
Alexander Duyckc9f53e62015-10-22 16:26:30 -070010532 ixgbe_mac_set_default_filter(adapter);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010533
Kees Cook26566ea2017-10-16 17:29:35 -070010534 timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
Auke Kok9a799d72007-09-15 14:07:45 -070010535
Mark Rustad58cf6632014-03-12 00:38:40 +000010536 if (ixgbe_removed(hw->hw_addr)) {
10537 err = -EIO;
10538 goto err_sw_init;
10539 }
Alexander Duyck70864002011-04-27 09:13:56 +000010540 INIT_WORK(&adapter->service_task, ixgbe_service_task);
Mark Rustad58cf6632014-03-12 00:38:40 +000010541 set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010542 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010543
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010544 err = ixgbe_init_interrupt_scheme(adapter);
10545 if (err)
10546 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -070010547
Liwei Songb09457e2016-12-04 22:40:44 -050010548 for (i = 0; i < adapter->num_rx_queues; i++)
10549 u64_stats_init(&adapter->rx_ring[i]->syncp);
10550 for (i = 0; i < adapter->num_tx_queues; i++)
10551 u64_stats_init(&adapter->tx_ring[i]->syncp);
John Fastabend33fdc822017-04-24 03:30:18 -070010552 for (i = 0; i < adapter->num_xdp_queues; i++)
10553 u64_stats_init(&adapter->xdp_ring[i]->syncp);
10554
Jacob Keller8e2813f2012-04-21 06:05:40 +000010555 /* WOL not supported for all devices */
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010556 adapter->wol = 0;
Jacob Keller8e2813f2012-04-21 06:05:40 +000010557 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010558 hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
Don Skidmoreb8f83632013-02-28 08:08:44 +000010559 pdev->subsystem_device);
Jacob Keller6b92b0b2013-04-13 05:40:37 +000010560 if (hw->wol_enabled)
Andy Gospodarek9417c462011-07-16 07:31:33 +000010561 adapter->wol = IXGBE_WUFC_MAG;
Emil Tantilovc23f5b62011-08-16 07:34:18 +000010562
PJ Waskiewicze8e26352009-02-27 15:45:05 +000010563 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
10564
Emil Tantilov15e52092011-09-29 05:01:29 +000010565 /* save off EEPROM version number */
Paul Greenwalt73834ae2017-10-27 10:32:40 -040010566 ixgbe_set_fw_version(adapter);
Emil Tantilov15e52092011-09-29 05:01:29 +000010567
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010568 /* pick up the PCI bus settings for reporting later */
Jacob Kellere027d1a2013-07-31 06:53:31 +000010569 if (ixgbe_pcie_from_parent(hw))
Jacob Kellerb8e82002013-04-09 07:20:09 +000010570 ixgbe_get_parent_bus_info(adapter);
Don Skidmoref9328bc2015-06-18 13:24:06 -040010571 else
10572 hw->mac.ops.get_bus_info(hw);
PJ Waskiewicz04f165e2009-04-09 22:27:57 +000010573
Jacob Kellere027d1a2013-07-31 06:53:31 +000010574 /* calculate the expected PCIe bandwidth required for optimal
10575 * performance. Note that some older parts will never have enough
10576 * bandwidth due to being older generation PCIe parts. We clamp these
10577 * parts to ensure no warning is displayed if it can't be fixed.
10578 */
10579 switch (hw->mac.type) {
10580 case ixgbe_mac_82598EB:
10581 expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
10582 break;
10583 default:
10584 expected_gts = ixgbe_enumerate_functions(adapter) * 10;
10585 break;
Auke Kok0c254d82008-02-11 09:25:56 -080010586 }
Jacob Kellercaafb952014-07-19 07:17:17 +000010587
10588 /* don't check link if we failed to enumerate functions */
10589 if (expected_gts > 0)
10590 ixgbe_check_minimum_link(adapter, expected_gts);
Auke Kok0c254d82008-02-11 09:25:56 -080010591
Mark Rustad339de302014-06-06 01:57:06 +000010592 err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010593 if (err)
Mark Rustad339de302014-06-06 01:57:06 +000010594 strlcpy(part_str, "Unknown", sizeof(part_str));
Jacob Keller6a2aae52013-10-18 05:09:24 +000010595 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
10596 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
10597 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Jacob Kellere7cf7452014-04-09 06:03:10 +000010598 part_str);
Jacob Keller6a2aae52013-10-18 05:09:24 +000010599 else
10600 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
10601 hw->mac.type, hw->phy.type, part_str);
10602
10603 e_dev_info("%pM\n", netdev->dev_addr);
10604
Auke Kok9a799d72007-09-15 14:07:45 -070010605 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010606 err = hw->mac.ops.start_hw(hw);
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010607 if (err == IXGBE_ERR_EEPROM_VERSION) {
10608 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +000010609 e_dev_warn("This device is a pre-production adapter/LOM. "
10610 "Please be aware there may be issues associated "
10611 "with your hardware. If you are experiencing "
10612 "problems please contact your Intel or hardware "
10613 "representative who provided you with this "
10614 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +000010615 }
Auke Kok9a799d72007-09-15 14:07:45 -070010616 strcpy(netdev->name, "eth%d");
Jeff Mahoneya09c0fc2017-06-03 18:01:17 -040010617 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010618 err = register_netdev(netdev);
10619 if (err)
10620 goto err_register;
10621
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010622
Emil Tantilovec74a472012-09-20 03:33:56 +000010623 /* power down the optics for 82599 SFP+ fiber */
10624 if (hw->mac.ops.disable_tx_laser)
Emil Tantilov93d3ce82011-10-19 07:59:55 +000010625 hw->mac.ops.disable_tx_laser(hw);
10626
Jesse Brandeburg54386462009-04-17 20:44:27 +000010627 /* carrier off reporting is important to ethtool even BEFORE open */
10628 netif_carrier_off(netdev);
10629
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010630#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +030010631 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010632 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010633 ixgbe_setup_dca(adapter);
10634 }
10635#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010636 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010637 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +000010638 for (i = 0; i < adapter->num_vfs; i++)
10639 ixgbe_vf_configuration(pdev, (i | 0x10000000));
10640 }
10641
Jacob Keller2466dd92011-09-08 03:50:54 +000010642 /* firmware requires driver version to be 0xFFFFFFFF
10643 * since os does not support feature
10644 */
Emil Tantilov9612de92011-05-07 07:40:20 +000010645 if (hw->mac.ops.set_fw_drv_ver)
Tony Nguyencb8e0512016-10-26 16:25:18 -070010646 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
10647 sizeof(ixgbe_driver_version) - 1,
10648 ixgbe_driver_version);
Emil Tantilov9612de92011-05-07 07:40:20 +000010649
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010650 /* add san mac addr to netdev */
10651 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010652
Neerav Parikhea818752012-01-04 20:23:40 +000010653 e_dev_info("%s\n", ixgbe_default_device_descr);
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010654
Don Skidmore12109822012-05-04 06:07:08 +000010655#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010656 if (ixgbe_sysfs_init(adapter))
10657 e_err(probe, "failed to allocate sysfs resources\n");
Don Skidmore12109822012-05-04 06:07:08 +000010658#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010659
Catherine Sullivan00949162012-08-10 01:59:10 +000010660 ixgbe_dbg_adapter_init(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010661
Emil Tantilovd1a35ee2014-05-13 08:24:00 +000010662 /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
10663 if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
Don Skidmore0b2679d2013-02-21 03:00:04 +000010664 hw->mac.ops.setup_link(hw,
10665 IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
10666 true);
10667
Auke Kok9a799d72007-09-15 14:07:45 -070010668 return 0;
10669
10670err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010671 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010672 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010673err_sw_init:
Alexander Duyck99d74482012-05-09 08:09:25 +000010674 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +000010675 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Mark Rustad2a1a0912014-01-14 18:53:15 -080010676 iounmap(adapter->io_addr);
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010677 kfree(adapter->jump_tables[0]);
Jacob Keller5d7daa32014-03-29 06:51:25 +000010678 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010679 kfree(adapter->rss_key);
Auke Kok9a799d72007-09-15 14:07:45 -070010680err_ioremap:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010681 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010682 free_netdev(netdev);
10683err_alloc_etherdev:
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010684 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010685err_pci_reg:
10686err_dma:
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010687 if (!adapter || disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010688 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010689 return err;
10690}
10691
10692/**
10693 * ixgbe_remove - Device Removal Routine
10694 * @pdev: PCI device information struct
10695 *
10696 * ixgbe_remove is called by the PCI subsystem to alert the driver
10697 * that it should release a PCI device. The could be caused by a
10698 * Hot-Plug event, or because the driver is going to be removed from
10699 * memory.
10700 **/
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010701static void ixgbe_remove(struct pci_dev *pdev)
Auke Kok9a799d72007-09-15 14:07:45 -070010702{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010703 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010704 struct net_device *netdev;
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010705 bool disable_dev;
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010706 int i;
Auke Kok9a799d72007-09-15 14:07:45 -070010707
Emil Tantilov0fb6a552014-12-04 03:03:38 +000010708 /* if !adapter then we already cleaned up in probe */
10709 if (!adapter)
10710 return;
10711
10712 netdev = adapter->netdev;
Catherine Sullivan00949162012-08-10 01:59:10 +000010713 ixgbe_dbg_adapter_exit(adapter);
Catherine Sullivan00949162012-08-10 01:59:10 +000010714
Mark Rustad09f40ae2014-01-14 18:53:11 -080010715 set_bit(__IXGBE_REMOVING, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +000010716 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -070010717
Jacob Keller3a6a4ed2012-05-01 05:24:58 +000010718
Jeff Garzik5dd2d332008-10-16 05:09:31 -040010719#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010720 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
10721 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
10722 dca_remove_requester(&pdev->dev);
Mark Rustad9de76052015-08-08 16:27:41 -070010723 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
10724 IXGBE_DCA_CTRL_DCA_DISABLE);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080010725 }
10726
10727#endif
Don Skidmore12109822012-05-04 06:07:08 +000010728#ifdef CONFIG_IXGBE_HWMON
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010729 ixgbe_sysfs_exit(adapter);
Don Skidmore12109822012-05-04 06:07:08 +000010730#endif /* CONFIG_IXGBE_HWMON */
Don Skidmore3ca8bc62012-04-12 00:33:31 +000010731
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +000010732 /* remove the added san mac */
10733 ixgbe_del_sanmac_netdev(netdev);
10734
Greg Roseda36b642012-12-11 08:26:43 +000010735#ifdef CONFIG_PCI_IOV
Alex Williamson7837e282015-07-10 15:31:34 -060010736 ixgbe_disable_sriov(adapter);
Greg Roseda36b642012-12-11 08:26:43 +000010737#endif
Alex Williamson6b010e92015-07-29 14:38:21 -060010738 if (netdev->reg_state == NETREG_REGISTERED)
10739 unregister_netdev(netdev);
10740
Shannon Nelson63a67fe2017-12-19 15:59:57 -080010741 ixgbe_stop_ipsec_offload(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +000010742 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -080010743
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010744 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -070010745
Alexander Duyck2b1588c2012-03-17 02:39:16 +000010746#ifdef CONFIG_DCB
10747 kfree(adapter->ixgbe_ieee_pfc);
10748 kfree(adapter->ixgbe_ieee_ets);
10749
10750#endif
Mark Rustad2a1a0912014-01-14 18:53:15 -080010751 iounmap(adapter->io_addr);
Johannes Thumshirn56d766d2016-06-07 09:44:05 +020010752 pci_release_mem_regions(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010753
Emil Tantilov849c4542010-06-03 16:53:41 +000010754 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -080010755
Amritha Nambiar1cdaaf52016-04-14 19:08:53 -040010756 for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
10757 if (adapter->jump_tables[i]) {
10758 kfree(adapter->jump_tables[i]->input);
10759 kfree(adapter->jump_tables[i]->mask);
10760 }
10761 kfree(adapter->jump_tables[i]);
10762 }
10763
Jacob Keller5d7daa32014-03-29 06:51:25 +000010764 kfree(adapter->mac_table);
Tony Nguyen3dfbfc72017-04-13 07:26:05 -070010765 kfree(adapter->rss_key);
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010766 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -070010767 free_netdev(netdev);
10768
Frans Pop19d5afd2009-10-02 10:04:12 -070010769 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010770
Daniel Borkmannb5b2ffc2014-11-21 23:52:53 -080010771 if (disable_dev)
Mark Rustad41c62842014-03-12 00:38:35 +000010772 pci_disable_device(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010773}
10774
10775/**
10776 * ixgbe_io_error_detected - called when PCI error is detected
10777 * @pdev: Pointer to PCI device
10778 * @state: The current pci connection state
10779 *
10780 * This function is called after a PCI bus error affecting
10781 * this device has been detected.
10782 */
10783static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +000010784 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -070010785{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010786 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10787 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010788
Greg Rose83c61fa2011-09-07 05:59:35 +000010789#ifdef CONFIG_PCI_IOV
Mark Rustad14438462014-02-28 15:48:57 -080010790 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose83c61fa2011-09-07 05:59:35 +000010791 struct pci_dev *bdev, *vfdev;
10792 u32 dw0, dw1, dw2, dw3;
10793 int vf, pos;
10794 u16 req_id, pf_func;
10795
10796 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
10797 adapter->num_vfs == 0)
10798 goto skip_bad_vf_detection;
10799
10800 bdev = pdev->bus->self;
Yijing Wang62f87c02012-07-24 17:20:03 +080010801 while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
Greg Rose83c61fa2011-09-07 05:59:35 +000010802 bdev = bdev->bus->self;
10803
10804 if (!bdev)
10805 goto skip_bad_vf_detection;
10806
10807 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
10808 if (!pos)
10809 goto skip_bad_vf_detection;
10810
Mark Rustad14438462014-02-28 15:48:57 -080010811 dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
10812 dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
10813 dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
10814 dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
10815 if (ixgbe_removed(hw->hw_addr))
10816 goto skip_bad_vf_detection;
Greg Rose83c61fa2011-09-07 05:59:35 +000010817
10818 req_id = dw1 >> 16;
10819 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
10820 if (!(req_id & 0x0080))
10821 goto skip_bad_vf_detection;
10822
10823 pf_func = req_id & 0x01;
10824 if ((pf_func & 1) == (pdev->devfn & 1)) {
10825 unsigned int device_id;
10826
10827 vf = (req_id & 0x7F) >> 1;
10828 e_dev_err("VF %d has caused a PCIe error\n", vf);
10829 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
10830 "%8.8x\tdw3: %8.8x\n",
10831 dw0, dw1, dw2, dw3);
10832 switch (adapter->hw.mac.type) {
10833 case ixgbe_mac_82599EB:
10834 device_id = IXGBE_82599_VF_DEVICE_ID;
10835 break;
10836 case ixgbe_mac_X540:
10837 device_id = IXGBE_X540_VF_DEVICE_ID;
10838 break;
Don Skidmore9a75a1a2014-11-07 03:53:35 +000010839 case ixgbe_mac_X550:
10840 device_id = IXGBE_DEV_ID_X550_VF;
10841 break;
10842 case ixgbe_mac_X550EM_x:
10843 device_id = IXGBE_DEV_ID_X550EM_X_VF;
10844 break;
Mark Rustad49425df2016-04-01 12:18:09 -070010845 case ixgbe_mac_x550em_a:
10846 device_id = IXGBE_DEV_ID_X550EM_A_VF;
10847 break;
Greg Rose83c61fa2011-09-07 05:59:35 +000010848 default:
10849 device_id = 0;
10850 break;
10851 }
10852
10853 /* Find the pci device of the offending VF */
Jon Mason36e90312012-07-19 21:02:09 +000010854 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
Greg Rose83c61fa2011-09-07 05:59:35 +000010855 while (vfdev) {
10856 if (vfdev->devfn == (req_id & 0xFF))
10857 break;
Jon Mason36e90312012-07-19 21:02:09 +000010858 vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
Greg Rose83c61fa2011-09-07 05:59:35 +000010859 device_id, vfdev);
10860 }
10861 /*
10862 * There's a slim chance the VF could have been hot plugged,
10863 * so if it is no longer present we don't need to issue the
10864 * VFLR. Just clean up the AER in that case.
10865 */
10866 if (vfdev) {
Christoph Hellwig63af8f72017-04-14 21:11:28 +020010867 pcie_flr(vfdev);
Greg Roseb4fafbe2012-12-13 01:14:06 +000010868 /* Free device reference count */
10869 pci_dev_put(vfdev);
Greg Rose83c61fa2011-09-07 05:59:35 +000010870 }
10871
10872 pci_cleanup_aer_uncorrect_error_status(pdev);
10873 }
10874
10875 /*
10876 * Even though the error may have occurred on the other port
10877 * we still need to increment the vf error reference count for
10878 * both ports because the I/O resume function will be called
10879 * for both of them.
10880 */
10881 adapter->vferr_refcount++;
10882
10883 return PCI_ERS_RESULT_RECOVERED;
10884
10885skip_bad_vf_detection:
10886#endif /* CONFIG_PCI_IOV */
Mark Rustad58cf6632014-03-12 00:38:40 +000010887 if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
10888 return PCI_ERS_RESULT_DISCONNECT;
10889
Emil Tantilovb64666a2017-09-29 10:55:42 -070010890 if (!netif_device_present(netdev))
10891 return PCI_ERS_RESULT_DISCONNECT;
10892
Mark Rustad41c62842014-03-12 00:38:35 +000010893 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -070010894 netif_device_detach(netdev);
10895
Mauro S M Rodriguesb212d812018-05-02 17:26:28 -030010896 if (netif_running(netdev))
10897 ixgbe_close_suspend(adapter);
10898
Mark Rustad41c62842014-03-12 00:38:35 +000010899 if (state == pci_channel_io_perm_failure) {
10900 rtnl_unlock();
Breno Leitao3044b8d2009-05-06 10:44:26 +000010901 return PCI_ERS_RESULT_DISCONNECT;
Mark Rustad41c62842014-03-12 00:38:35 +000010902 }
Breno Leitao3044b8d2009-05-06 10:44:26 +000010903
Mark Rustad41c62842014-03-12 00:38:35 +000010904 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
10905 pci_disable_device(pdev);
10906 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010907
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070010908 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -070010909 return PCI_ERS_RESULT_NEED_RESET;
10910}
10911
10912/**
10913 * ixgbe_io_slot_reset - called after the pci bus has been reset.
10914 * @pdev: Pointer to PCI device
10915 *
10916 * Restart the card from scratch, as if from a cold-boot.
10917 */
10918static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
10919{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010920 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010921 pci_ers_result_t result;
10922 int err;
Auke Kok9a799d72007-09-15 14:07:45 -070010923
gouji-new9ce77662009-05-06 10:44:45 +000010924 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +000010925 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010926 result = PCI_ERS_RESULT_DISCONNECT;
10927 } else {
Peter Zijlstra4e857c52014-03-17 18:06:10 +010010928 smp_mb__before_atomic();
Mark Rustad41c62842014-03-12 00:38:35 +000010929 clear_bit(__IXGBE_DISABLED, &adapter->state);
Mark Rustad0391bbe2014-02-28 15:48:55 -080010930 adapter->hw.hw_addr = adapter->io_addr;
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010931 pci_set_master(pdev);
10932 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +000010933 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010934
Don Skidmoredd4d8ca2009-04-29 00:22:31 -070010935 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010936
10937 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +000010938 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010939 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -070010940 }
Auke Kok9a799d72007-09-15 14:07:45 -070010941
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010942 err = pci_cleanup_aer_uncorrect_error_status(pdev);
10943 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +000010944 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
10945 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010946 /* non-fatal, continue */
10947 }
Auke Kok9a799d72007-09-15 14:07:45 -070010948
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -080010949 return result;
Auke Kok9a799d72007-09-15 14:07:45 -070010950}
10951
10952/**
10953 * ixgbe_io_resume - called when traffic can start flowing again.
10954 * @pdev: Pointer to PCI device
10955 *
10956 * This callback is called when the error recovery driver tells us that
10957 * its OK to resume normal operation.
10958 */
10959static void ixgbe_io_resume(struct pci_dev *pdev)
10960{
Alexander Duyckc60fbb02010-11-16 19:26:54 -080010961 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
10962 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -070010963
Greg Rose83c61fa2011-09-07 05:59:35 +000010964#ifdef CONFIG_PCI_IOV
10965 if (adapter->vferr_refcount) {
10966 e_info(drv, "Resuming after VF err\n");
10967 adapter->vferr_refcount--;
10968 return;
10969 }
10970
10971#endif
Emil Tantilov126db132016-11-16 09:48:02 -080010972 rtnl_lock();
Alexander Duyckc7ccde02011-07-21 00:40:40 +000010973 if (netif_running(netdev))
Emil Tantilov126db132016-11-16 09:48:02 -080010974 ixgbe_open(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -070010975
10976 netif_device_attach(netdev);
Emil Tantilov126db132016-11-16 09:48:02 -080010977 rtnl_unlock();
Auke Kok9a799d72007-09-15 14:07:45 -070010978}
10979
Stephen Hemminger3646f0e2012-09-07 09:33:15 -070010980static const struct pci_error_handlers ixgbe_err_handler = {
Auke Kok9a799d72007-09-15 14:07:45 -070010981 .error_detected = ixgbe_io_error_detected,
10982 .slot_reset = ixgbe_io_slot_reset,
10983 .resume = ixgbe_io_resume,
10984};
10985
10986static struct pci_driver ixgbe_driver = {
10987 .name = ixgbe_driver_name,
10988 .id_table = ixgbe_pci_tbl,
10989 .probe = ixgbe_probe,
Bill Pemberton9f9a12f2012-12-03 09:24:25 -050010990 .remove = ixgbe_remove,
Auke Kok9a799d72007-09-15 14:07:45 -070010991#ifdef CONFIG_PM
10992 .suspend = ixgbe_suspend,
10993 .resume = ixgbe_resume,
10994#endif
10995 .shutdown = ixgbe_shutdown,
Greg Roseda36b642012-12-11 08:26:43 +000010996 .sriov_configure = ixgbe_pci_sriov_configure,
Auke Kok9a799d72007-09-15 14:07:45 -070010997 .err_handler = &ixgbe_err_handler
10998};
10999
11000/**
11001 * ixgbe_init_module - Driver Registration Routine
11002 *
11003 * ixgbe_init_module is the first routine called when the driver is
11004 * loaded. All it does is register with the PCI subsystem.
11005 **/
11006static int __init ixgbe_init_module(void)
11007{
11008 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +000011009 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +000011010 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -070011011
Mark Rustad780484d2015-10-21 17:21:10 -070011012 ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
11013 if (!ixgbe_wq) {
11014 pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
11015 return -ENOMEM;
11016 }
11017
Catherine Sullivan00949162012-08-10 01:59:10 +000011018 ixgbe_dbg_init();
Catherine Sullivan00949162012-08-10 01:59:10 +000011019
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011020 ret = pci_register_driver(&ixgbe_driver);
11021 if (ret) {
Wei Yongjun6b836872016-07-12 15:17:02 +000011022 destroy_workqueue(ixgbe_wq);
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011023 ixgbe_dbg_exit();
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011024 return ret;
11025 }
11026
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011027#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011028 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011029#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011030
Jakub Kicinskif01fc1a2013-04-03 16:50:54 +000011031 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -070011032}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070011033
Auke Kok9a799d72007-09-15 14:07:45 -070011034module_init(ixgbe_init_module);
11035
11036/**
11037 * ixgbe_exit_module - Driver Exit Cleanup Routine
11038 *
11039 * ixgbe_exit_module is called just before the driver is removed
11040 * from memory.
11041 **/
11042static void __exit ixgbe_exit_module(void)
11043{
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011044#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011045 dca_unregister_notify(&dca_notifier);
11046#endif
Auke Kok9a799d72007-09-15 14:07:45 -070011047 pci_unregister_driver(&ixgbe_driver);
Catherine Sullivan00949162012-08-10 01:59:10 +000011048
Catherine Sullivan00949162012-08-10 01:59:10 +000011049 ixgbe_dbg_exit();
Mark Rustad780484d2015-10-21 17:21:10 -070011050 if (ixgbe_wq) {
11051 destroy_workqueue(ixgbe_wq);
11052 ixgbe_wq = NULL;
11053 }
Auke Kok9a799d72007-09-15 14:07:45 -070011054}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011055
Jeff Garzik5dd2d332008-10-16 05:09:31 -040011056#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011057static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011058 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011059{
11060 int ret_val;
11061
11062 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +000011063 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011064
11065 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
11066}
Jeb Cramerbd0362d2008-03-03 15:04:02 -080011067
Alexander Duyckb4533682009-03-31 21:32:42 +000011068#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +000011069
Auke Kok9a799d72007-09-15 14:07:45 -070011070module_exit(ixgbe_exit_module);
11071
11072/* ixgbe_main.c */