blob: de5dad7ff34077ef6a20b7fee60f87c1f1ed86d4 [file] [log] [blame]
Jeff Kirsherae06c702018-03-22 10:08:48 -07001// SPDX-License-Identifier: GPL-2.0
Jeff Kirsher51dce242018-04-26 08:08:09 -07002/* Copyright(c) 2013 - 2018 Intel Corporation. */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003
4/* ethtool support for i40e */
5
6#include "i40e.h"
7#include "i40e_diag.h"
8
9struct i40e_stats {
10 char stat_string[ETH_GSTRING_LEN];
11 int sizeof_stat;
12 int stat_offset;
13};
14
15#define I40E_STAT(_type, _name, _stat) { \
16 .stat_string = _name, \
17 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
18 .stat_offset = offsetof(_type, _stat) \
19}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000020
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000021#define I40E_NETDEV_STAT(_net_stat) \
Jacob Keller132ee002018-05-10 05:59:43 -070022 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000023#define I40E_PF_STAT(_name, _stat) \
Jacob Keller132ee002018-05-10 05:59:43 -070024 I40E_STAT(struct i40e_pf, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000025#define I40E_VSI_STAT(_name, _stat) \
Jacob Keller132ee002018-05-10 05:59:43 -070026 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000027#define I40E_VEB_STAT(_name, _stat) \
Jacob Keller132ee002018-05-10 05:59:43 -070028 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000029
30static const struct i40e_stats i40e_gstrings_net_stats[] = {
31 I40E_NETDEV_STAT(rx_packets),
32 I40E_NETDEV_STAT(tx_packets),
33 I40E_NETDEV_STAT(rx_bytes),
34 I40E_NETDEV_STAT(tx_bytes),
35 I40E_NETDEV_STAT(rx_errors),
36 I40E_NETDEV_STAT(tx_errors),
37 I40E_NETDEV_STAT(rx_dropped),
38 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000039 I40E_NETDEV_STAT(collisions),
40 I40E_NETDEV_STAT(rx_length_errors),
41 I40E_NETDEV_STAT(rx_crc_errors),
42};
43
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000044static const struct i40e_stats i40e_gstrings_veb_stats[] = {
45 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
46 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
47 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
48 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
49 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
50 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
51 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
52 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
53 I40E_VEB_STAT("rx_discards", stats.rx_discards),
54 I40E_VEB_STAT("tx_discards", stats.tx_discards),
55 I40E_VEB_STAT("tx_errors", stats.tx_errors),
56 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
57};
58
Shannon Nelson41a9e552014-04-23 04:50:20 +000059static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000060 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
61 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
62 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
63 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000064 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
65 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000066 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040067 I40E_VSI_STAT("tx_linearize", tx_linearize),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040068 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Harshitha Ramamurthy3f76d012018-05-10 05:59:45 -070069 I40E_VSI_STAT("tx_busy", tx_busy),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080070 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
71 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000072};
73
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000074/* These PF_STATs might look like duplicates of some NETDEV_STATs,
75 * but they are separate. This device supports Virtualization, and
76 * as such might have several netdevs supporting VMDq and FCoE going
77 * through a single port. The NETDEV_STATs are for individual netdevs
78 * seen at the top of the stack, and the PF_STATs are for the physical
79 * function at the bottom of the stack hosting those netdevs.
80 *
81 * The PF_STATs are appended to the netdev stats only when ethtool -S
82 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
83 */
Joe Perchesfe180a52016-09-26 20:17:01 -070084static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000085 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
86 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +000087 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
88 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
89 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
90 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
91 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
92 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000093 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
94 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000095 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -040096 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000097 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
98 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
99 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000100 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000101 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000102 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
103 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
104 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
105 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
106 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
107 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
108 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
109 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
110 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
111 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
112 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
113 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
114 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
115 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
116 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
117 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
118 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
119 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
120 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
121 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
122 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
123 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
124 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
125 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800126 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000127 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jacob Keller2955fac2017-05-03 10:28:58 -0700128 I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000129 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000130 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400131 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400132 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000133 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400134 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000135
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000136 /* LPI stats */
137 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
138 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
139 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
140 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000141};
142
143#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000144 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
145 * 2 /* Tx and Rx together */ \
146 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000147#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
Jacob Keller132ee002018-05-10 05:59:43 -0700148#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000149#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jacob Keller132ee002018-05-10 05:59:43 -0700150#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000151 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000152 I40E_QUEUE_STATS_LEN((n)))
153#define I40E_PFC_STATS_LEN ( \
154 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
155 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
156 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
157 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
158 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
159 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400160#define I40E_VEB_TC_STATS_LEN ( \
161 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
162 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
163 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
164 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
165 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000166#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400167#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000168#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
169 I40E_PFC_STATS_LEN + \
170 I40E_VSI_STATS_LEN((n)))
171
172enum i40e_ethtool_test_id {
173 I40E_ETH_TEST_REG = 0,
174 I40E_ETH_TEST_EEPROM,
175 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176 I40E_ETH_TEST_LINK,
177};
178
179static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
180 "Register test (offline)",
181 "Eeprom test (offline)",
182 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000183 "Link test (on/offline)"
184};
185
186#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
187
Alexander Duyckaca955d2017-03-10 12:22:01 -0800188struct i40e_priv_flags {
189 char flag_string[ETH_GSTRING_LEN];
190 u64 flag;
191 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000192};
193
Alexander Duyckaca955d2017-03-10 12:22:01 -0800194#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
195 .flag_string = _name, \
196 .flag = _flag, \
197 .read_only = _read_only, \
198}
199
200static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
201 /* NOTE: MFP setting cannot be changed */
202 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
203 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
204 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
205 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700206 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Mariusz Stachurac3880bd2017-11-14 07:00:50 -0500207 I40E_PRIV_FLAG("link-down-on-close",
208 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700209 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400210 I40E_PRIV_FLAG("disable-source-pruning",
211 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Dave Ertmanc61c8fe2017-12-27 08:18:21 -0500212 I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800213};
214
215#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000216
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700217/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800218static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
219 I40E_PRIV_FLAG("vf-true-promisc-support",
220 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700221};
222
Alexander Duyckaca955d2017-03-10 12:22:01 -0800223#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700224
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000225/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000226 * i40e_partition_setting_complaint - generic complaint for MFP restriction
227 * @pf: the PF struct
228 **/
229static void i40e_partition_setting_complaint(struct i40e_pf *pf)
230{
231 dev_info(&pf->pdev->dev,
232 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
233}
234
235/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700236 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
Alan Brady52e2d022017-10-05 14:53:35 -0700237 * @pf: PF struct with phy_types
Alan Brady1eaae512017-10-05 14:53:41 -0700238 * @ks: ethtool link ksettings struct to fill out
Catherine Sullivan06566e52016-05-03 15:13:14 -0700239 *
240 **/
Alan Brady1eaae512017-10-05 14:53:41 -0700241static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
242 struct ethtool_link_ksettings *ks)
Catherine Sullivan06566e52016-05-03 15:13:14 -0700243{
Avinash Dayanand28537042016-06-20 09:10:33 -0700244 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800245 u64 phy_types = pf->hw.phy.phy_types;
246
Alan Brady1eaae512017-10-05 14:53:41 -0700247 ethtool_link_ksettings_zero_link_mode(ks, supported);
248 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700249
250 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
Alan Brady1eaae512017-10-05 14:53:41 -0700251 ethtool_link_ksettings_add_link_mode(ks, supported,
252 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700253 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700254 ethtool_link_ksettings_add_link_mode(ks, advertising,
255 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400256 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady1eaae512017-10-05 14:53:41 -0700257 ethtool_link_ksettings_add_link_mode(ks, supported,
258 100baseT_Full);
259 ethtool_link_ksettings_add_link_mode(ks, advertising,
260 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700261 }
262 }
263 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
264 phy_types & I40E_CAP_PHY_TYPE_XFI ||
265 phy_types & I40E_CAP_PHY_TYPE_SFI ||
266 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
Alan Brady1eaae512017-10-05 14:53:41 -0700267 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
268 ethtool_link_ksettings_add_link_mode(ks, supported,
269 10000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700270 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700271 ethtool_link_ksettings_add_link_mode(ks, advertising,
272 10000baseT_Full);
273 }
274 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
275 ethtool_link_ksettings_add_link_mode(ks, supported,
276 10000baseT_Full);
277 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
278 ethtool_link_ksettings_add_link_mode(ks, advertising,
279 10000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700280 }
281 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
282 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
283 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
Alan Brady1eaae512017-10-05 14:53:41 -0700284 ethtool_link_ksettings_add_link_mode(ks, supported,
285 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700286 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
287 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700288 ethtool_link_ksettings_add_link_mode(ks, supported,
289 40000baseCR4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700290 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700291 ethtool_link_ksettings_add_link_mode(ks, advertising,
292 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700293 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700294 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700295 ethtool_link_ksettings_add_link_mode(ks, supported,
296 100baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700297 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady1eaae512017-10-05 14:53:41 -0700298 ethtool_link_ksettings_add_link_mode(ks, advertising,
299 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700300 }
Alan Brady1eaae512017-10-05 14:53:41 -0700301 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
302 ethtool_link_ksettings_add_link_mode(ks, supported,
303 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700305 ethtool_link_ksettings_add_link_mode(ks, advertising,
306 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700307 }
308 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700309 ethtool_link_ksettings_add_link_mode(ks, supported,
310 40000baseSR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700311 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700312 ethtool_link_ksettings_add_link_mode(ks, supported,
313 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700314 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700315 ethtool_link_ksettings_add_link_mode(ks, supported,
316 40000baseLR4_Full);
317 ethtool_link_ksettings_add_link_mode(ks, advertising,
318 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700319 }
320 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
Alan Brady1eaae512017-10-05 14:53:41 -0700321 ethtool_link_ksettings_add_link_mode(ks, supported,
322 20000baseKR2_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700324 ethtool_link_ksettings_add_link_mode(ks, advertising,
325 20000baseKR2_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700326 }
327 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700328 ethtool_link_ksettings_add_link_mode(ks, supported,
329 10000baseKX4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700330 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700331 ethtool_link_ksettings_add_link_mode(ks, advertising,
332 10000baseKX4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700333 }
Alan Brady6987bd252017-10-05 14:53:38 -0700334 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
335 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700336 ethtool_link_ksettings_add_link_mode(ks, supported,
337 10000baseKR_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700338 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700339 ethtool_link_ksettings_add_link_mode(ks, advertising,
340 10000baseKR_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700341 }
Alan Brady6987bd252017-10-05 14:53:38 -0700342 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
343 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700344 ethtool_link_ksettings_add_link_mode(ks, supported,
345 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700346 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700347 ethtool_link_ksettings_add_link_mode(ks, advertising,
348 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700349 }
Alan Brady1eaae512017-10-05 14:53:41 -0700350 /* need to add 25G PHY types */
351 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
352 ethtool_link_ksettings_add_link_mode(ks, supported,
353 25000baseKR_Full);
354 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
355 ethtool_link_ksettings_add_link_mode(ks, advertising,
356 25000baseKR_Full);
357 }
358 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
359 ethtool_link_ksettings_add_link_mode(ks, supported,
360 25000baseCR_Full);
361 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
362 ethtool_link_ksettings_add_link_mode(ks, advertising,
363 25000baseCR_Full);
364 }
365 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800366 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
Alan Brady1eaae512017-10-05 14:53:41 -0700367 ethtool_link_ksettings_add_link_mode(ks, supported,
368 25000baseSR_Full);
369 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
370 ethtool_link_ksettings_add_link_mode(ks, advertising,
371 25000baseSR_Full);
372 }
373 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
374 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
375 ethtool_link_ksettings_add_link_mode(ks, supported,
376 25000baseCR_Full);
377 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
378 ethtool_link_ksettings_add_link_mode(ks, advertising,
379 25000baseCR_Full);
380 }
381 /* need to add new 10G PHY types */
382 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
383 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
384 ethtool_link_ksettings_add_link_mode(ks, supported,
385 10000baseCR_Full);
386 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
387 ethtool_link_ksettings_add_link_mode(ks, advertising,
388 10000baseCR_Full);
389 }
390 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
391 ethtool_link_ksettings_add_link_mode(ks, supported,
392 10000baseSR_Full);
393 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
394 ethtool_link_ksettings_add_link_mode(ks, advertising,
395 10000baseSR_Full);
396 }
397 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
398 ethtool_link_ksettings_add_link_mode(ks, supported,
399 10000baseLR_Full);
400 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
401 ethtool_link_ksettings_add_link_mode(ks, advertising,
402 10000baseLR_Full);
403 }
404 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
405 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
406 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
407 ethtool_link_ksettings_add_link_mode(ks, supported,
408 1000baseX_Full);
409 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
410 ethtool_link_ksettings_add_link_mode(ks, advertising,
411 1000baseX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700412 }
413 /* Autoneg PHY types */
414 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
415 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
416 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
417 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800418 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700419 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
420 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
421 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
422 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
423 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
424 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
425 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
426 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
427 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
430 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
431 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
432 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
433 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
434 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
435 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700436 ethtool_link_ksettings_add_link_mode(ks, supported,
437 Autoneg);
438 ethtool_link_ksettings_add_link_mode(ks, advertising,
439 Autoneg);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800440 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700441}
442
443/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000444 * i40e_get_settings_link_up - Get the Link settings for when link is up
445 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700446 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000447 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700448 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000449 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000450static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700451 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400452 struct net_device *netdev,
453 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000454{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000455 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Alan Brady1eaae512017-10-05 14:53:41 -0700456 struct ethtool_link_ksettings cap_ksettings;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000457 u32 link_speed = hw_link_info->link_speed;
458
Catherine Sullivane8278452015-02-06 08:52:08 +0000459 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000460 switch (hw_link_info->phy_type) {
461 case I40E_PHY_TYPE_40GBASE_CR4:
462 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Alan Brady79f04a32017-10-05 14:53:42 -0700463 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
464 ethtool_link_ksettings_add_link_mode(ks, supported,
465 40000baseCR4_Full);
466 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
467 ethtool_link_ksettings_add_link_mode(ks, advertising,
468 40000baseCR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000469 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000470 case I40E_PHY_TYPE_XLAUI:
471 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000472 case I40E_PHY_TYPE_40GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700473 ethtool_link_ksettings_add_link_mode(ks, supported,
474 40000baseCR4_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000475 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000476 case I40E_PHY_TYPE_40GBASE_SR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700477 ethtool_link_ksettings_add_link_mode(ks, supported,
478 40000baseSR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000479 break;
480 case I40E_PHY_TYPE_40GBASE_LR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700481 ethtool_link_ksettings_add_link_mode(ks, supported,
482 40000baseLR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 break;
Alan Brady79f04a32017-10-05 14:53:42 -0700484 case I40E_PHY_TYPE_25GBASE_SR:
485 case I40E_PHY_TYPE_25GBASE_LR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000486 case I40E_PHY_TYPE_10GBASE_SR:
487 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000488 case I40E_PHY_TYPE_1000BASE_SX:
489 case I40E_PHY_TYPE_1000BASE_LX:
Alan Brady79f04a32017-10-05 14:53:42 -0700490 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
491 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
492 ethtool_link_ksettings_add_link_mode(ks, supported,
493 25000baseSR_Full);
494 ethtool_link_ksettings_add_link_mode(ks, advertising,
495 25000baseSR_Full);
496 ethtool_link_ksettings_add_link_mode(ks, supported,
497 10000baseSR_Full);
498 ethtool_link_ksettings_add_link_mode(ks, advertising,
499 10000baseSR_Full);
500 ethtool_link_ksettings_add_link_mode(ks, supported,
501 10000baseLR_Full);
502 ethtool_link_ksettings_add_link_mode(ks, advertising,
503 10000baseLR_Full);
504 ethtool_link_ksettings_add_link_mode(ks, supported,
505 1000baseX_Full);
506 ethtool_link_ksettings_add_link_mode(ks, advertising,
507 1000baseX_Full);
508 ethtool_link_ksettings_add_link_mode(ks, supported,
509 10000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400510 if (hw_link_info->module_type[2] &
511 I40E_MODULE_TYPE_1000BASE_SX ||
512 hw_link_info->module_type[2] &
513 I40E_MODULE_TYPE_1000BASE_LX) {
Alan Brady79f04a32017-10-05 14:53:42 -0700514 ethtool_link_ksettings_add_link_mode(ks, supported,
515 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400516 if (hw_link_info->requested_speeds &
517 I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700518 ethtool_link_ksettings_add_link_mode(
519 ks, advertising, 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400520 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000521 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700522 ethtool_link_ksettings_add_link_mode(ks, advertising,
523 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000524 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000525 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000526 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700527 case I40E_PHY_TYPE_100BASE_TX:
Alan Brady79f04a32017-10-05 14:53:42 -0700528 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
529 ethtool_link_ksettings_add_link_mode(ks, supported,
530 10000baseT_Full);
531 ethtool_link_ksettings_add_link_mode(ks, supported,
532 1000baseT_Full);
533 ethtool_link_ksettings_add_link_mode(ks, supported,
534 100baseT_Full);
535 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivane8278452015-02-06 08:52:08 +0000536 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700537 ethtool_link_ksettings_add_link_mode(ks, advertising,
538 10000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000539 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700540 ethtool_link_ksettings_add_link_mode(ks, advertising,
541 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700542 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700543 ethtool_link_ksettings_add_link_mode(ks, advertising,
544 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400545 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400546 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Alan Brady79f04a32017-10-05 14:53:42 -0700547 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
548 ethtool_link_ksettings_add_link_mode(ks, supported,
549 1000baseT_Full);
550 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
551 ethtool_link_ksettings_add_link_mode(ks, advertising,
552 1000baseT_Full);
Catherine Sullivan48becae2015-09-28 14:12:41 -0400553 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000554 case I40E_PHY_TYPE_10GBASE_CR1_CU:
555 case I40E_PHY_TYPE_10GBASE_CR1:
Alan Brady79f04a32017-10-05 14:53:42 -0700556 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
557 ethtool_link_ksettings_add_link_mode(ks, supported,
558 10000baseT_Full);
559 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
560 ethtool_link_ksettings_add_link_mode(ks, advertising,
561 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000562 break;
563 case I40E_PHY_TYPE_XAUI:
564 case I40E_PHY_TYPE_XFI:
565 case I40E_PHY_TYPE_SFI:
566 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000567 case I40E_PHY_TYPE_10GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700568 ethtool_link_ksettings_add_link_mode(ks, supported,
569 10000baseT_Full);
570 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
571 ethtool_link_ksettings_add_link_mode(ks, advertising,
572 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000573 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000574 case I40E_PHY_TYPE_SGMII:
Alan Brady79f04a32017-10-05 14:53:42 -0700575 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
576 ethtool_link_ksettings_add_link_mode(ks, supported,
577 1000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000578 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700579 ethtool_link_ksettings_add_link_mode(ks, advertising,
580 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400581 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady79f04a32017-10-05 14:53:42 -0700582 ethtool_link_ksettings_add_link_mode(ks, supported,
583 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400584 if (hw_link_info->requested_speeds &
585 I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700586 ethtool_link_ksettings_add_link_mode(
587 ks, advertising, 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400588 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000589 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400590 case I40E_PHY_TYPE_40GBASE_KR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700591 case I40E_PHY_TYPE_25GBASE_KR:
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400592 case I40E_PHY_TYPE_20GBASE_KR2:
593 case I40E_PHY_TYPE_10GBASE_KR:
594 case I40E_PHY_TYPE_10GBASE_KX4:
595 case I40E_PHY_TYPE_1000BASE_KX:
Alan Brady79f04a32017-10-05 14:53:42 -0700596 ethtool_link_ksettings_add_link_mode(ks, supported,
597 40000baseKR4_Full);
598 ethtool_link_ksettings_add_link_mode(ks, supported,
599 25000baseKR_Full);
600 ethtool_link_ksettings_add_link_mode(ks, supported,
601 20000baseKR2_Full);
602 ethtool_link_ksettings_add_link_mode(ks, supported,
603 10000baseKR_Full);
604 ethtool_link_ksettings_add_link_mode(ks, supported,
605 10000baseKX4_Full);
606 ethtool_link_ksettings_add_link_mode(ks, supported,
607 1000baseKX_Full);
608 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
609 ethtool_link_ksettings_add_link_mode(ks, advertising,
610 40000baseKR4_Full);
611 ethtool_link_ksettings_add_link_mode(ks, advertising,
612 25000baseKR_Full);
613 ethtool_link_ksettings_add_link_mode(ks, advertising,
614 20000baseKR2_Full);
615 ethtool_link_ksettings_add_link_mode(ks, advertising,
616 10000baseKR_Full);
617 ethtool_link_ksettings_add_link_mode(ks, advertising,
618 10000baseKX4_Full);
619 ethtool_link_ksettings_add_link_mode(ks, advertising,
620 1000baseKX_Full);
621 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400622 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800623 case I40E_PHY_TYPE_25GBASE_CR:
Alan Brady79f04a32017-10-05 14:53:42 -0700624 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
625 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
626 ethtool_link_ksettings_add_link_mode(ks, supported,
627 25000baseCR_Full);
628 ethtool_link_ksettings_add_link_mode(ks, advertising,
629 25000baseCR_Full);
630 break;
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700631 case I40E_PHY_TYPE_25GBASE_AOC:
632 case I40E_PHY_TYPE_25GBASE_ACC:
Alan Brady79f04a32017-10-05 14:53:42 -0700633 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
634 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
635 ethtool_link_ksettings_add_link_mode(ks, supported,
636 25000baseCR_Full);
637
638 ethtool_link_ksettings_add_link_mode(ks, advertising,
639 25000baseCR_Full);
640 ethtool_link_ksettings_add_link_mode(ks, supported,
641 10000baseCR_Full);
642 ethtool_link_ksettings_add_link_mode(ks, advertising,
643 10000baseCR_Full);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800644 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000645 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000646 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700647 netdev_info(netdev,
648 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000649 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000650 }
651
Catherine Sullivan06566e52016-05-03 15:13:14 -0700652 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700653 * current PHY type, get what is supported by the NVM and intersect
654 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700655 */
Alan Brady1eaae512017-10-05 14:53:41 -0700656 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
657 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
658 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700659
Catherine Sullivane8278452015-02-06 08:52:08 +0000660 /* Set speed and duplex */
661 switch (link_speed) {
662 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700663 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000664 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800665 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700666 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800667 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700668 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700669 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700670 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000671 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700672 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000673 break;
674 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700675 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000676 break;
677 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700678 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000679 break;
680 default:
681 break;
682 }
Alan Brady1c142e12017-10-05 14:53:31 -0700683 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000684}
685
686/**
687 * i40e_get_settings_link_down - Get the Link settings for when link is down
688 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700689 * @ks: ethtool ksettings to fill in
690 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000691 *
692 * Reports link settings that can be determined when link is down
693 **/
694static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700695 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400696 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000697{
Catherine Sullivane8278452015-02-06 08:52:08 +0000698 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400699 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000700 */
Alan Brady1eaae512017-10-05 14:53:41 -0700701 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000702
703 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700704 ks->base.speed = SPEED_UNKNOWN;
705 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000706}
707
708/**
Alan Brady1c142e12017-10-05 14:53:31 -0700709 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000710 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700711 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000712 *
713 * Reports speed/duplex settings based on media_type
714 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100715static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700716 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000717{
718 struct i40e_netdev_priv *np = netdev_priv(netdev);
719 struct i40e_pf *pf = np->vsi->back;
720 struct i40e_hw *hw = &pf->hw;
721 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
722 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700723
724 ethtool_link_ksettings_zero_link_mode(ks, supported);
725 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000726
727 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700728 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000729 else
Alan Brady1c142e12017-10-05 14:53:31 -0700730 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000731
732 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000733 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700734 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
735 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000736
Alan Bradya03af692017-10-05 14:53:37 -0700737 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000738 switch (hw->phy.media_type) {
739 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700740 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
741 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
742 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700743 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100744 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700745 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000746 break;
747 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700748 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
749 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
750 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000751 break;
752 case I40E_MEDIA_TYPE_DA:
753 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700754 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
755 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
756 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000757 break;
758 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700759 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
760 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000761 break;
762 case I40E_MEDIA_TYPE_UNKNOWN:
763 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700764 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000765 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000766 }
767
Catherine Sullivane8278452015-02-06 08:52:08 +0000768 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700769 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000770
Catherine Sullivane8278452015-02-06 08:52:08 +0000771 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000772 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700773 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000774 break;
775 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700776 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100777 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000778 break;
779 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700780 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700781 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100782 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000783 break;
784 default:
Alan Brady5f434992017-10-05 14:53:34 -0700785 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
786 ethtool_link_ksettings_del_link_mode(ks, advertising,
787 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000788 break;
789 }
790
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000791 return 0;
792}
793
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000794/**
Alan Brady1c142e12017-10-05 14:53:31 -0700795 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000796 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700797 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000798 *
799 * Set speed/duplex per media_types advertised/forced
800 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100801static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700802 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000803{
804 struct i40e_netdev_priv *np = netdev_priv(netdev);
805 struct i40e_aq_get_phy_abilities_resp abilities;
Alan Brady636b62d2017-10-05 14:53:43 -0700806 struct ethtool_link_ksettings safe_ks;
807 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000808 struct i40e_aq_set_phy_config config;
809 struct i40e_pf *pf = np->vsi->back;
810 struct i40e_vsi *vsi = np->vsi;
811 struct i40e_hw *hw = &pf->hw;
Alan Brady636b62d2017-10-05 14:53:43 -0700812 bool autoneg_changed = false;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000813 i40e_status status = 0;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400814 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000815 int err = 0;
Alan Bradycee91992017-10-05 14:53:44 -0700816 u8 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000817
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000818 /* Changing port settings is not supported if this isn't the
819 * port's controlling PF
820 */
821 if (hw->partition_id != 1) {
822 i40e_partition_setting_complaint(pf);
823 return -EOPNOTSUPP;
824 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000825 if (vsi != pf->vsi[pf->lan_vsi])
826 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000827 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
828 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000829 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700830 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000831 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000832 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400833 if (hw->device_id == I40E_DEV_ID_KX_B ||
834 hw->device_id == I40E_DEV_ID_KX_C ||
835 hw->device_id == I40E_DEV_ID_20G_KR2 ||
Patryk Małek88244a42018-03-19 09:28:03 -0700836 hw->device_id == I40E_DEV_ID_20G_KR2_A ||
Patryk Małek3f8c84372018-03-19 09:28:04 -0700837 hw->device_id == I40E_DEV_ID_25G_B ||
Patryk Małek88244a42018-03-19 09:28:03 -0700838 hw->device_id == I40E_DEV_ID_KX_X722) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400839 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
840 return -EOPNOTSUPP;
841 }
842
Alan Brady1c142e12017-10-05 14:53:31 -0700843 /* copy the ksettings to copy_ks to avoid modifying the origin */
844 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000845
Alan Bradycee91992017-10-05 14:53:44 -0700846 /* save autoneg out of ksettings */
847 autoneg = copy_ks.base.autoneg;
848
Philippe Reynesa7f90942017-02-04 22:05:06 +0100849 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700850 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
Alan Bradycee91992017-10-05 14:53:44 -0700851 safe_ks.base.cmd = copy_ks.base.cmd;
852 safe_ks.base.link_mode_masks_nwords =
853 copy_ks.base.link_mode_masks_nwords;
Alan Brady1c142e12017-10-05 14:53:31 -0700854 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100855
Jan Sokolowski32c23b42018-03-19 09:28:03 -0700856 /* Get link modes supported by hardware and check against modes
857 * requested by the user. Return an error if unsupported mode was set.
858 */
859 if (!bitmap_subset(copy_ks.link_modes.advertising,
860 safe_ks.link_modes.supported,
861 __ETHTOOL_LINK_MODE_MASK_NBITS))
862 return -EINVAL;
863
Alan Bradycee91992017-10-05 14:53:44 -0700864 /* set autoneg back to what it currently is */
Alan Brady1c142e12017-10-05 14:53:31 -0700865 copy_ks.base.autoneg = safe_ks.base.autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000866
Alan Bradycee91992017-10-05 14:53:44 -0700867 /* If copy_ks.base and safe_ks.base are not the same now, then they are
868 * trying to set something that we do not support.
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000869 */
Alan Bradycee91992017-10-05 14:53:44 -0700870 if (memcmp(&copy_ks.base, &safe_ks.base,
871 sizeof(struct ethtool_link_settings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000872 return -EOPNOTSUPP;
873
Jacob Keller0da36b92017-04-19 09:25:55 -0400874 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400875 timeout--;
876 if (!timeout)
877 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000878 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400879 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000880
881 /* Get the current phy config */
882 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
883 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400884 if (status) {
885 err = -EAGAIN;
886 goto done;
887 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000888
Catherine Sullivan124ed152014-07-12 07:28:12 +0000889 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000890 * set below
891 */
892 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000893 config.abilities = abilities.abilities;
894
895 /* Check autoneg */
896 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000897 /* If autoneg was not already enabled */
898 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400899 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700900 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
901 supported,
902 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400903 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400904 err = -EINVAL;
905 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400906 }
907 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000908 config.abilities = abilities.abilities |
909 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700910 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000911 }
912 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000913 /* If autoneg is currently enabled */
914 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400915 /* If autoneg is supported 10GBASE_T is the only PHY
916 * that can disable it, so otherwise return error
917 */
Alan Brady1c142e12017-10-05 14:53:31 -0700918 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
919 supported,
920 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400921 hw->phy.link_info.phy_type !=
922 I40E_PHY_TYPE_10GBASE_T) {
923 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400924 err = -EINVAL;
925 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400926 }
927 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000928 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000929 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700930 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000931 }
932 }
933
Alan Bradycee91992017-10-05 14:53:44 -0700934 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
935 100baseT_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000936 config.link_speed |= I40E_LINK_SPEED_100MB;
Alan Bradycee91992017-10-05 14:53:44 -0700937 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
938 1000baseT_Full) ||
939 ethtool_link_ksettings_test_link_mode(ks, advertising,
940 1000baseX_Full) ||
941 ethtool_link_ksettings_test_link_mode(ks, advertising,
942 1000baseKX_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000943 config.link_speed |= I40E_LINK_SPEED_1GB;
Alan Bradycee91992017-10-05 14:53:44 -0700944 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
945 10000baseT_Full) ||
946 ethtool_link_ksettings_test_link_mode(ks, advertising,
947 10000baseKX4_Full) ||
948 ethtool_link_ksettings_test_link_mode(ks, advertising,
949 10000baseKR_Full) ||
950 ethtool_link_ksettings_test_link_mode(ks, advertising,
951 10000baseCR_Full) ||
952 ethtool_link_ksettings_test_link_mode(ks, advertising,
Jakub Pawlak6ee4d322018-04-20 01:41:35 -0700953 10000baseSR_Full) ||
954 ethtool_link_ksettings_test_link_mode(ks, advertising,
955 10000baseLR_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000956 config.link_speed |= I40E_LINK_SPEED_10GB;
Alan Bradycee91992017-10-05 14:53:44 -0700957 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
958 20000baseKR2_Full))
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700959 config.link_speed |= I40E_LINK_SPEED_20GB;
Alan Bradycee91992017-10-05 14:53:44 -0700960 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
961 25000baseCR_Full) ||
962 ethtool_link_ksettings_test_link_mode(ks, advertising,
963 25000baseKR_Full) ||
964 ethtool_link_ksettings_test_link_mode(ks, advertising,
965 25000baseSR_Full))
966 config.link_speed |= I40E_LINK_SPEED_25GB;
967 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
968 40000baseKR4_Full) ||
969 ethtool_link_ksettings_test_link_mode(ks, advertising,
970 40000baseCR4_Full) ||
971 ethtool_link_ksettings_test_link_mode(ks, advertising,
972 40000baseSR4_Full) ||
973 ethtool_link_ksettings_test_link_mode(ks, advertising,
974 40000baseLR4_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000975 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000976
Catherine Sullivan0002e112015-08-26 15:14:16 -0400977 /* If speed didn't get set, set it to what it currently is.
978 * This is needed because if advertise is 0 (as it is when autoneg
979 * is disabled) then speed won't get set.
980 */
981 if (!config.link_speed)
982 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -0700983 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000984 /* copy over the rest of the abilities */
985 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800986 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000987 config.eee_capability = abilities.eee_capability;
988 config.eeer = abilities.eeer_val;
989 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800990 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
991 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000992
Catherine Sullivane8278452015-02-06 08:52:08 +0000993 /* save the requested speeds */
994 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000995 /* set link and auto negotiation so changes take effect */
996 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
997 /* If link is up put link down */
998 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
999 /* Tell the OS link is going down, the link will go
1000 * back up when fw says it is ready asynchronously
1001 */
Matt Jaredc156f852015-08-27 11:42:39 -04001002 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001003 netif_carrier_off(netdev);
1004 netif_tx_stop_all_queues(netdev);
1005 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001006
1007 /* make the aq call */
1008 status = i40e_aq_set_phy_config(hw, &config, NULL);
1009 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001010 netdev_info(netdev,
1011 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001012 i40e_stat_str(hw, status),
1013 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001014 err = -EAGAIN;
1015 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001016 }
1017
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001018 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001019 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001020 netdev_dbg(netdev,
1021 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001022 i40e_stat_str(hw, status),
1023 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001024
1025 } else {
1026 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1027 }
1028
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001029done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001030 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001031
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001032 return err;
1033}
1034
Jesse Brandeburga6599722014-06-04 08:45:25 +00001035static int i40e_nway_reset(struct net_device *netdev)
1036{
1037 /* restart autonegotiation */
1038 struct i40e_netdev_priv *np = netdev_priv(netdev);
1039 struct i40e_pf *pf = np->vsi->back;
1040 struct i40e_hw *hw = &pf->hw;
1041 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1042 i40e_status ret = 0;
1043
1044 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1045 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001046 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1047 i40e_stat_str(hw, ret),
1048 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001049 return -EIO;
1050 }
1051
1052 return 0;
1053}
1054
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001055/**
1056 * i40e_get_pauseparam - Get Flow Control status
Jacob Kellerf5254422018-04-20 01:41:33 -07001057 * @netdev: netdevice structure
1058 * @pause: buffer to return pause parameters
1059 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001060 * Return tx/rx-pause status
1061 **/
1062static void i40e_get_pauseparam(struct net_device *netdev,
1063 struct ethtool_pauseparam *pause)
1064{
1065 struct i40e_netdev_priv *np = netdev_priv(netdev);
1066 struct i40e_pf *pf = np->vsi->back;
1067 struct i40e_hw *hw = &pf->hw;
1068 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001069 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001070
1071 pause->autoneg =
1072 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1073 AUTONEG_ENABLE : AUTONEG_DISABLE);
1074
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001075 /* PFC enabled so report LFC as off */
1076 if (dcbx_cfg->pfc.pfcenable) {
1077 pause->rx_pause = 0;
1078 pause->tx_pause = 0;
1079 return;
1080 }
1081
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001082 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001083 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001084 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001086 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1087 pause->rx_pause = 1;
1088 pause->tx_pause = 1;
1089 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001090}
1091
Catherine Sullivan2becc352014-06-04 08:45:27 +00001092/**
1093 * i40e_set_pauseparam - Set Flow Control parameter
1094 * @netdev: network interface device structure
1095 * @pause: return tx/rx flow control status
1096 **/
1097static int i40e_set_pauseparam(struct net_device *netdev,
1098 struct ethtool_pauseparam *pause)
1099{
1100 struct i40e_netdev_priv *np = netdev_priv(netdev);
1101 struct i40e_pf *pf = np->vsi->back;
1102 struct i40e_vsi *vsi = np->vsi;
1103 struct i40e_hw *hw = &pf->hw;
1104 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001105 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001106 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1107 i40e_status status;
1108 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001109 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001110
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001111 /* Changing the port's flow control is not supported if this isn't the
1112 * port's controlling PF
1113 */
1114 if (hw->partition_id != 1) {
1115 i40e_partition_setting_complaint(pf);
1116 return -EOPNOTSUPP;
1117 }
1118
Catherine Sullivan2becc352014-06-04 08:45:27 +00001119 if (vsi != pf->vsi[pf->lan_vsi])
1120 return -EOPNOTSUPP;
1121
1122 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1123 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1124 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1125 return -EOPNOTSUPP;
1126 }
1127
1128 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001129 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001130 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1131 /* Send message that it might not necessarily work*/
1132 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1133 }
1134
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001135 if (dcbx_cfg->pfc.pfcenable) {
1136 netdev_info(netdev,
1137 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001138 return -EOPNOTSUPP;
1139 }
1140
1141 if (pause->rx_pause && pause->tx_pause)
1142 hw->fc.requested_mode = I40E_FC_FULL;
1143 else if (pause->rx_pause && !pause->tx_pause)
1144 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1145 else if (!pause->rx_pause && pause->tx_pause)
1146 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1147 else if (!pause->rx_pause && !pause->tx_pause)
1148 hw->fc.requested_mode = I40E_FC_NONE;
1149 else
1150 return -EINVAL;
1151
Catherine Sullivan94128512014-07-12 07:28:16 +00001152 /* Tell the OS link is going down, the link will go back up when fw
1153 * says it is ready asynchronously
1154 */
Matt Jaredc156f852015-08-27 11:42:39 -04001155 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001156 netif_carrier_off(netdev);
1157 netif_tx_stop_all_queues(netdev);
1158
Catherine Sullivan2becc352014-06-04 08:45:27 +00001159 /* Set the fc mode and only restart an if link is up*/
1160 status = i40e_set_fc(hw, &aq_failures, link_up);
1161
1162 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001163 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1164 i40e_stat_str(hw, status),
1165 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001166 err = -EAGAIN;
1167 }
1168 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001169 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1170 i40e_stat_str(hw, status),
1171 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001172 err = -EAGAIN;
1173 }
1174 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001175 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1176 i40e_stat_str(hw, status),
1177 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001178 err = -EAGAIN;
1179 }
1180
Jacob Keller0da36b92017-04-19 09:25:55 -04001181 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001182 /* Give it a little more time to try to come back */
1183 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001184 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001185 return i40e_nway_reset(netdev);
1186 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001187
1188 return err;
1189}
1190
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001191static u32 i40e_get_msglevel(struct net_device *netdev)
1192{
1193 struct i40e_netdev_priv *np = netdev_priv(netdev);
1194 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001195 u32 debug_mask = pf->hw.debug_mask;
1196
1197 if (debug_mask)
1198 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001199
1200 return pf->msg_enable;
1201}
1202
1203static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1204{
1205 struct i40e_netdev_priv *np = netdev_priv(netdev);
1206 struct i40e_pf *pf = np->vsi->back;
1207
1208 if (I40E_DEBUG_USER & data)
1209 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001210 else
1211 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001212}
1213
1214static int i40e_get_regs_len(struct net_device *netdev)
1215{
1216 int reg_count = 0;
1217 int i;
1218
1219 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1220 reg_count += i40e_reg_list[i].elements;
1221
1222 return reg_count * sizeof(u32);
1223}
1224
1225static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1226 void *p)
1227{
1228 struct i40e_netdev_priv *np = netdev_priv(netdev);
1229 struct i40e_pf *pf = np->vsi->back;
1230 struct i40e_hw *hw = &pf->hw;
1231 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001232 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001233 u32 reg;
1234
1235 /* Tell ethtool which driver-version-specific regs output we have.
1236 *
1237 * At some point, if we have ethtool doing special formatting of
1238 * this data, it will rely on this version number to know how to
1239 * interpret things. Hence, this needs to be updated if/when the
1240 * diags register table is changed.
1241 */
1242 regs->version = 1;
1243
1244 /* loop through the diags reg table for what to print */
1245 ri = 0;
1246 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1247 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1248 reg = i40e_reg_list[i].offset
1249 + (j * i40e_reg_list[i].stride);
1250 reg_buf[ri++] = rd32(hw, reg);
1251 }
1252 }
1253
1254}
1255
1256static int i40e_get_eeprom(struct net_device *netdev,
1257 struct ethtool_eeprom *eeprom, u8 *bytes)
1258{
1259 struct i40e_netdev_priv *np = netdev_priv(netdev);
1260 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001261 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001262 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001263 u8 *eeprom_buff;
1264 u16 i, sectors;
1265 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001266 u32 magic;
1267
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001268#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 if (eeprom->len == 0)
1270 return -EINVAL;
1271
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001272 /* check for NVMUpdate access method */
1273 magic = hw->vendor_id | (hw->device_id << 16);
1274 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001275 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1276 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001277
1278 /* make sure it is the right magic for NVMUpdate */
1279 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001280 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001281 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1282 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001283 errno = -EBUSY;
1284 else
1285 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001286
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001287 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001288 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001289 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1290 ret_val, hw->aq.asq_last_status, errno,
1291 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1292 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001293
1294 return errno;
1295 }
1296
1297 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001298 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1299
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001300 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301 if (!eeprom_buff)
1302 return -ENOMEM;
1303
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001304 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1305 if (ret_val) {
1306 dev_info(&pf->pdev->dev,
1307 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1308 ret_val, hw->aq.asq_last_status);
1309 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001310 }
1311
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001312 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1313 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1314 len = I40E_NVM_SECTOR_SIZE;
1315 last = false;
1316 for (i = 0; i < sectors; i++) {
1317 if (i == (sectors - 1)) {
1318 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1319 last = true;
1320 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001321 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1322 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001323 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001324 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001325 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001326 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001327 "read NVM failed, invalid offset 0x%x\n",
1328 offset);
1329 break;
1330 } else if (ret_val &&
1331 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1332 dev_info(&pf->pdev->dev,
1333 "read NVM failed, access, offset 0x%x\n",
1334 offset);
1335 break;
1336 } else if (ret_val) {
1337 dev_info(&pf->pdev->dev,
1338 "read NVM failed offset %d err=%d status=0x%x\n",
1339 offset, ret_val, hw->aq.asq_last_status);
1340 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001341 }
1342 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001343
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001344 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001345 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001346free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001347 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 return ret_val;
1349}
1350
1351static int i40e_get_eeprom_len(struct net_device *netdev)
1352{
1353 struct i40e_netdev_priv *np = netdev_priv(netdev);
1354 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001355 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001356
Lihong Yangc271dd62017-01-30 12:29:32 -08001357#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1358 if (hw->mac.type == I40E_MAC_X722) {
1359 val = X722_EEPROM_SCOPE_LIMIT + 1;
1360 return val;
1361 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001362 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1363 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1364 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1365 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001366 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001367 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001368}
1369
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001370static int i40e_set_eeprom(struct net_device *netdev,
1371 struct ethtool_eeprom *eeprom, u8 *bytes)
1372{
1373 struct i40e_netdev_priv *np = netdev_priv(netdev);
1374 struct i40e_hw *hw = &np->vsi->back->hw;
1375 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001376 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001377 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001378 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001379 u32 magic;
1380
1381 /* normal ethtool set_eeprom is not supported */
1382 magic = hw->vendor_id | (hw->device_id << 16);
1383 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001384 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001385 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001386 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1387 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001388 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1389 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001390 errno = -EBUSY;
1391 else
1392 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001393
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001394 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001395 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001396 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1397 ret_val, hw->aq.asq_last_status, errno,
1398 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1399 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001400
1401 return errno;
1402}
1403
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001404static void i40e_get_drvinfo(struct net_device *netdev,
1405 struct ethtool_drvinfo *drvinfo)
1406{
1407 struct i40e_netdev_priv *np = netdev_priv(netdev);
1408 struct i40e_vsi *vsi = np->vsi;
1409 struct i40e_pf *pf = vsi->back;
1410
1411 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1412 strlcpy(drvinfo->version, i40e_driver_version_str,
1413 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001414 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001415 sizeof(drvinfo->fw_version));
1416 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1417 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001418 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001419 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001420 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421}
1422
1423static void i40e_get_ringparam(struct net_device *netdev,
1424 struct ethtool_ringparam *ring)
1425{
1426 struct i40e_netdev_priv *np = netdev_priv(netdev);
1427 struct i40e_pf *pf = np->vsi->back;
1428 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1429
1430 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1431 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1432 ring->rx_mini_max_pending = 0;
1433 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001434 ring->rx_pending = vsi->rx_rings[0]->count;
1435 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001436 ring->rx_mini_pending = 0;
1437 ring->rx_jumbo_pending = 0;
1438}
1439
Björn Töpel74608d12017-05-24 07:55:35 +02001440static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1441{
1442 if (i40e_enabled_xdp_vsi(vsi)) {
1443 return index < vsi->num_queue_pairs ||
1444 (index >= vsi->alloc_queue_pairs &&
1445 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1446 }
1447
1448 return index < vsi->num_queue_pairs;
1449}
1450
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001451static int i40e_set_ringparam(struct net_device *netdev,
1452 struct ethtool_ringparam *ring)
1453{
1454 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1455 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001456 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 struct i40e_vsi *vsi = np->vsi;
1458 struct i40e_pf *pf = vsi->back;
1459 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001460 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001461 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001462 int i, err = 0;
1463
1464 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1465 return -EINVAL;
1466
Shannon Nelson1fa18372013-11-20 10:03:08 +00001467 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1468 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1469 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1470 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1471 netdev_info(netdev,
1472 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1473 ring->tx_pending, ring->rx_pending,
1474 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1475 return -EINVAL;
1476 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477
Shannon Nelson1fa18372013-11-20 10:03:08 +00001478 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1479 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480
1481 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001482 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1483 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001484 return 0;
1485
Jacob Keller0da36b92017-04-19 09:25:55 -04001486 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001487 timeout--;
1488 if (!timeout)
1489 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001490 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001491 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001492
1493 if (!netif_running(vsi->netdev)) {
1494 /* simple case - set for the next time the netdev is started */
1495 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001496 vsi->tx_rings[i]->count = new_tx_count;
1497 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001498 if (i40e_enabled_xdp_vsi(vsi))
1499 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500 }
1501 goto done;
1502 }
1503
1504 /* We can't just free everything and then setup again,
1505 * because the ISRs in MSI-X mode get passed pointers
1506 * to the Tx and Rx ring structs.
1507 */
1508
Björn Töpel74608d12017-05-24 07:55:35 +02001509 /* alloc updated Tx and XDP Tx resources */
1510 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1511 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001512 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513 netdev_info(netdev,
1514 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001515 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001516 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001517 sizeof(struct i40e_ring), GFP_KERNEL);
1518 if (!tx_rings) {
1519 err = -ENOMEM;
1520 goto done;
1521 }
1522
Björn Töpel74608d12017-05-24 07:55:35 +02001523 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1524 if (!i40e_active_tx_ring_index(vsi, i))
1525 continue;
1526
Alexander Duyck9f65e152013-09-28 06:00:58 +00001527 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001528 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001529 /* the desc and bi pointers will be reallocated in the
1530 * setup call
1531 */
1532 tx_rings[i].desc = NULL;
1533 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1535 if (err) {
1536 while (i) {
1537 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001538 if (!i40e_active_tx_ring_index(vsi, i))
1539 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001540 i40e_free_tx_resources(&tx_rings[i]);
1541 }
1542 kfree(tx_rings);
1543 tx_rings = NULL;
1544
1545 goto done;
1546 }
1547 }
1548 }
1549
1550 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001551 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001552 netdev_info(netdev,
1553 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001554 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1556 sizeof(struct i40e_ring), GFP_KERNEL);
1557 if (!rx_rings) {
1558 err = -ENOMEM;
1559 goto free_tx;
1560 }
1561
1562 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001563 struct i40e_ring *ring;
1564 u16 unused;
1565
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001567 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001569 /* the desc and bi pointers will be reallocated in the
1570 * setup call
1571 */
1572 rx_rings[i].desc = NULL;
1573 rx_rings[i].rx_bi = NULL;
Jesper Dangaard Brouer87128822018-01-03 11:25:23 +01001574 /* Clear cloned XDP RX-queue info before setup call */
1575 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
Tushar Dave2f7679e2016-10-26 10:49:27 -07001576 /* this is to allow wr32 to have something to write to
1577 * during early allocation of Rx buffers
1578 */
1579 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001581 if (err)
1582 goto rx_unwind;
1583
1584 /* now allocate the Rx buffers to make sure the OS
1585 * has enough memory, any failure here means abort
1586 */
1587 ring = &rx_rings[i];
1588 unused = I40E_DESC_UNUSED(ring);
1589 err = i40e_alloc_rx_buffers(ring, unused);
1590rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001591 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001592 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001594 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595 kfree(rx_rings);
1596 rx_rings = NULL;
1597
1598 goto free_tx;
1599 }
1600 }
1601 }
1602
1603 /* Bring interface down, copy in the new ring info,
1604 * then restore the interface
1605 */
1606 i40e_down(vsi);
1607
1608 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001609 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1610 if (i40e_active_tx_ring_index(vsi, i)) {
1611 i40e_free_tx_resources(vsi->tx_rings[i]);
1612 *vsi->tx_rings[i] = tx_rings[i];
1613 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614 }
1615 kfree(tx_rings);
1616 tx_rings = NULL;
1617 }
1618
1619 if (rx_rings) {
1620 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001621 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001622 /* get the real tail offset */
1623 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1624 /* this is to fake out the allocation routine
1625 * into thinking it has to realloc everything
1626 * but the recycling logic will let us re-use
1627 * the buffers allocated above
1628 */
1629 rx_rings[i].next_to_use = 0;
1630 rx_rings[i].next_to_clean = 0;
1631 rx_rings[i].next_to_alloc = 0;
1632 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001633 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001634 }
1635 kfree(rx_rings);
1636 rx_rings = NULL;
1637 }
1638
1639 i40e_up(vsi);
1640
1641free_tx:
1642 /* error cleanup if the Rx allocations failed after getting Tx */
1643 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001644 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1645 if (i40e_active_tx_ring_index(vsi, i))
1646 i40e_free_tx_resources(vsi->tx_rings[i]);
1647 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001648 kfree(tx_rings);
1649 tx_rings = NULL;
1650 }
1651
1652done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001653 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001654
1655 return err;
1656}
1657
Jacob Keller0ded9c62018-05-10 05:59:41 -07001658static int i40e_get_stats_count(struct net_device *netdev)
1659{
1660 struct i40e_netdev_priv *np = netdev_priv(netdev);
1661 struct i40e_vsi *vsi = np->vsi;
1662 struct i40e_pf *pf = vsi->back;
1663
Jacob Keller9955d492018-05-17 01:08:33 -07001664 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1)
1665 return I40E_PF_STATS_LEN(netdev) + I40E_VEB_STATS_TOTAL;
1666 else
Jacob Keller0ded9c62018-05-10 05:59:41 -07001667 return I40E_VSI_STATS_LEN(netdev);
Jacob Keller0ded9c62018-05-10 05:59:41 -07001668}
1669
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001670static int i40e_get_sset_count(struct net_device *netdev, int sset)
1671{
1672 struct i40e_netdev_priv *np = netdev_priv(netdev);
1673 struct i40e_vsi *vsi = np->vsi;
1674 struct i40e_pf *pf = vsi->back;
1675
1676 switch (sset) {
1677 case ETH_SS_TEST:
1678 return I40E_TEST_LEN;
1679 case ETH_SS_STATS:
Jacob Keller0ded9c62018-05-10 05:59:41 -07001680 return i40e_get_stats_count(netdev);
Greg Rose7e45ab42015-02-06 08:52:19 +00001681 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001682 return I40E_PRIV_FLAGS_STR_LEN +
1683 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001684 default:
1685 return -EOPNOTSUPP;
1686 }
1687}
1688
1689static void i40e_get_ethtool_stats(struct net_device *netdev,
1690 struct ethtool_stats *stats, u64 *data)
1691{
1692 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001693 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694 struct i40e_vsi *vsi = np->vsi;
1695 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001696 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697 int i = 0;
1698 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001699 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001700 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001701
1702 i40e_update_stats(vsi);
1703
1704 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1705 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1706 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1707 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1708 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001709 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1710 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1711 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1712 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1713 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001714 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001715 for (j = 0; j < vsi->num_queue_pairs; j++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07001716 tx_ring = READ_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001717
1718 if (!tx_ring)
1719 continue;
1720
1721 /* process Tx ring statistics */
1722 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001723 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001724 data[i] = tx_ring->stats.packets;
1725 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001726 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001727 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001728
1729 /* Rx ring is the 2nd half of the queue pair */
1730 rx_ring = &tx_ring[1];
1731 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001732 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001733 data[i] = rx_ring->stats.packets;
1734 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001735 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001736 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001737 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001738 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001739 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001740 return;
1741
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001742 if ((pf->lan_veb != I40E_NO_VEB) &&
1743 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001744 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001745
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001746 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1747 p = (char *)veb;
1748 p += i40e_gstrings_veb_stats[j].stat_offset;
1749 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1750 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001751 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001752 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1753 data[i++] = veb->tc_stats.tc_tx_packets[j];
1754 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1755 data[i++] = veb->tc_stats.tc_rx_packets[j];
1756 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1757 }
Jacob Keller9955d492018-05-17 01:08:33 -07001758 } else {
1759 i += I40E_VEB_STATS_TOTAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001760 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001761 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1762 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1763 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1764 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1765 }
1766 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1767 data[i++] = pf->stats.priority_xon_tx[j];
1768 data[i++] = pf->stats.priority_xoff_tx[j];
1769 }
1770 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1771 data[i++] = pf->stats.priority_xon_rx[j];
1772 data[i++] = pf->stats.priority_xoff_rx[j];
1773 }
1774 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1775 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001776}
1777
1778static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1779 u8 *data)
1780{
1781 struct i40e_netdev_priv *np = netdev_priv(netdev);
1782 struct i40e_vsi *vsi = np->vsi;
1783 struct i40e_pf *pf = vsi->back;
1784 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001785 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001786
1787 switch (stringset) {
1788 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001789 memcpy(data, i40e_gstrings_test,
1790 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791 break;
1792 case ETH_SS_STATS:
1793 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1794 snprintf(p, ETH_GSTRING_LEN, "%s",
1795 i40e_gstrings_net_stats[i].stat_string);
1796 p += ETH_GSTRING_LEN;
1797 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001798 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1799 snprintf(p, ETH_GSTRING_LEN, "%s",
1800 i40e_gstrings_misc_stats[i].stat_string);
1801 p += ETH_GSTRING_LEN;
1802 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001803 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001804 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001805 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001806 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001808 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001809 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001810 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811 p += ETH_GSTRING_LEN;
1812 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001813 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001814 return;
1815
Jacob Keller9955d492018-05-17 01:08:33 -07001816 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1817 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1818 i40e_gstrings_veb_stats[i].stat_string);
1819 p += ETH_GSTRING_LEN;
1820 }
1821 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1822 snprintf(p, ETH_GSTRING_LEN,
1823 "veb.tc_%u_tx_packets", i);
1824 p += ETH_GSTRING_LEN;
1825 snprintf(p, ETH_GSTRING_LEN,
1826 "veb.tc_%u_tx_bytes", i);
1827 p += ETH_GSTRING_LEN;
1828 snprintf(p, ETH_GSTRING_LEN,
1829 "veb.tc_%u_rx_packets", i);
1830 p += ETH_GSTRING_LEN;
1831 snprintf(p, ETH_GSTRING_LEN,
1832 "veb.tc_%u_rx_bytes", i);
1833 p += ETH_GSTRING_LEN;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001834 }
1835 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1836 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1837 i40e_gstrings_stats[i].stat_string);
1838 p += ETH_GSTRING_LEN;
1839 }
1840 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1841 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001842 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001843 p += ETH_GSTRING_LEN;
1844 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001845 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001846 p += ETH_GSTRING_LEN;
1847 }
1848 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1849 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001850 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001851 p += ETH_GSTRING_LEN;
1852 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001853 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001854 p += ETH_GSTRING_LEN;
1855 }
1856 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1857 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001858 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001859 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001860 }
1861 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1862 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001863 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001864 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1865 snprintf(p, ETH_GSTRING_LEN, "%s",
1866 i40e_gstrings_priv_flags[i].flag_string);
1867 p += ETH_GSTRING_LEN;
1868 }
1869 if (pf->hw.pf_id != 0)
1870 break;
1871 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1872 snprintf(p, ETH_GSTRING_LEN, "%s",
1873 i40e_gl_gstrings_priv_flags[i].flag_string);
1874 p += ETH_GSTRING_LEN;
1875 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001876 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001877 default:
1878 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879 }
1880}
1881
1882static int i40e_get_ts_info(struct net_device *dev,
1883 struct ethtool_ts_info *info)
1884{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001885 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1886
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001887 /* only report HW timestamping if PTP is enabled */
1888 if (!(pf->flags & I40E_FLAG_PTP))
1889 return ethtool_op_get_ts_info(dev, info);
1890
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001891 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1892 SOF_TIMESTAMPING_RX_SOFTWARE |
1893 SOF_TIMESTAMPING_SOFTWARE |
1894 SOF_TIMESTAMPING_TX_HARDWARE |
1895 SOF_TIMESTAMPING_RX_HARDWARE |
1896 SOF_TIMESTAMPING_RAW_HARDWARE;
1897
1898 if (pf->ptp_clock)
1899 info->phc_index = ptp_clock_index(pf->ptp_clock);
1900 else
1901 info->phc_index = -1;
1902
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001903 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001904
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001905 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001906 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1907 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1908 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1909
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001910 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001911 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1912 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1913 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1914 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1915 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1916 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1917 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1918 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001919
1920 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001921}
1922
Shannon Nelson7b086392013-11-20 10:02:59 +00001923static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001924{
Shannon Nelson7b086392013-11-20 10:02:59 +00001925 struct i40e_netdev_priv *np = netdev_priv(netdev);
1926 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001927 i40e_status status;
1928 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001929
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001930 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001931 status = i40e_get_link_status(&pf->hw, &link_up);
1932 if (status) {
1933 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1934 *data = 1;
1935 return *data;
1936 }
1937
1938 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939 *data = 0;
1940 else
1941 *data = 1;
1942
1943 return *data;
1944}
1945
Shannon Nelson7b086392013-11-20 10:02:59 +00001946static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001947{
Shannon Nelson7b086392013-11-20 10:02:59 +00001948 struct i40e_netdev_priv *np = netdev_priv(netdev);
1949 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001950
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001951 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001952 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953
Shannon Nelson7b086392013-11-20 10:02:59 +00001954 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001955}
1956
Shannon Nelson7b086392013-11-20 10:02:59 +00001957static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958{
Shannon Nelson7b086392013-11-20 10:02:59 +00001959 struct i40e_netdev_priv *np = netdev_priv(netdev);
1960 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001961
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001962 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001963 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001964
Shannon Nelson4443ec92014-11-13 08:23:12 +00001965 /* forcebly clear the NVM Update state machine */
1966 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1967
Shannon Nelson7b086392013-11-20 10:02:59 +00001968 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001969}
1970
Shannon Nelson7b086392013-11-20 10:02:59 +00001971static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001972{
Shannon Nelson7b086392013-11-20 10:02:59 +00001973 struct i40e_netdev_priv *np = netdev_priv(netdev);
1974 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001975 u16 swc_old = pf->sw_int_count;
1976
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001977 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001978 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1979 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001980 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1981 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1982 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1983 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001984 usleep_range(1000, 2000);
1985 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001986
1987 return *data;
1988}
1989
Greg Rosee17bc412015-04-16 20:05:59 -04001990static inline bool i40e_active_vfs(struct i40e_pf *pf)
1991{
1992 struct i40e_vf *vfs = pf->vf;
1993 int i;
1994
1995 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001996 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001997 return true;
1998 return false;
1999}
2000
Greg Rose510efb22015-07-10 19:36:01 -04002001static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2002{
Alexander Duyck4b816442016-10-11 15:26:53 -07002003 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04002004}
2005
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002006static void i40e_diag_test(struct net_device *netdev,
2007 struct ethtool_test *eth_test, u64 *data)
2008{
2009 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002010 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002011 struct i40e_pf *pf = np->vsi->back;
2012
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002013 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2014 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002015 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002016
Jacob Keller0da36b92017-04-19 09:25:55 -04002017 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002018
Greg Rose510efb22015-07-10 19:36:01 -04002019 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002020 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002021 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002022 data[I40E_ETH_TEST_REG] = 1;
2023 data[I40E_ETH_TEST_EEPROM] = 1;
2024 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002025 data[I40E_ETH_TEST_LINK] = 1;
2026 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002027 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002028 goto skip_ol_tests;
2029 }
2030
Greg Rose5b86c5c2015-02-26 16:14:35 +00002031 /* If the device is online then take it offline */
2032 if (if_running)
2033 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002034 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002035 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002036 /* This reset does not affect link - if it is
2037 * changed to a type of reset that does affect
2038 * link then the following link test would have
2039 * to be moved to before the reset
2040 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002041 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002042
Shannon Nelson7b086392013-11-20 10:02:59 +00002043 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002044 eth_test->flags |= ETH_TEST_FL_FAILED;
2045
Shannon Nelson7b086392013-11-20 10:02:59 +00002046 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002047 eth_test->flags |= ETH_TEST_FL_FAILED;
2048
Shannon Nelson7b086392013-11-20 10:02:59 +00002049 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002050 eth_test->flags |= ETH_TEST_FL_FAILED;
2051
Shannon Nelsonf551b432013-11-26 10:49:12 +00002052 /* run reg test last, a reset is required after it */
2053 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2054 eth_test->flags |= ETH_TEST_FL_FAILED;
2055
Jacob Keller0da36b92017-04-19 09:25:55 -04002056 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002057 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002058
2059 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002060 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002061 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002063 netif_info(pf, drv, netdev, "online testing starting\n");
2064
Shannon Nelson7b086392013-11-20 10:02:59 +00002065 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002066 eth_test->flags |= ETH_TEST_FL_FAILED;
2067
2068 /* Offline only tests, not run in online; pass by default */
2069 data[I40E_ETH_TEST_REG] = 0;
2070 data[I40E_ETH_TEST_EEPROM] = 0;
2071 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002072 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002073
Greg Rosee17bc412015-04-16 20:05:59 -04002074skip_ol_tests:
2075
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002076 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002077}
2078
2079static void i40e_get_wol(struct net_device *netdev,
2080 struct ethtool_wolinfo *wol)
2081{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002082 struct i40e_netdev_priv *np = netdev_priv(netdev);
2083 struct i40e_pf *pf = np->vsi->back;
2084 struct i40e_hw *hw = &pf->hw;
2085 u16 wol_nvm_bits;
2086
2087 /* NVM bit on means WoL disabled for the port */
2088 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002089 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002090 wol->supported = 0;
2091 wol->wolopts = 0;
2092 } else {
2093 wol->supported = WAKE_MAGIC;
2094 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2095 }
2096}
2097
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002098/**
2099 * i40e_set_wol - set the WakeOnLAN configuration
2100 * @netdev: the netdev in question
2101 * @wol: the ethtool WoL setting data
2102 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002103static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2104{
2105 struct i40e_netdev_priv *np = netdev_priv(netdev);
2106 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002107 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002108 struct i40e_hw *hw = &pf->hw;
2109 u16 wol_nvm_bits;
2110
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002111 /* WoL not supported if this isn't the controlling PF on the port */
2112 if (hw->partition_id != 1) {
2113 i40e_partition_setting_complaint(pf);
2114 return -EOPNOTSUPP;
2115 }
2116
2117 if (vsi != pf->vsi[pf->lan_vsi])
2118 return -EOPNOTSUPP;
2119
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002120 /* NVM bit on means WoL disabled for the port */
2121 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002122 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002123 return -EOPNOTSUPP;
2124
2125 /* only magic packet is supported */
2126 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2127 return -EOPNOTSUPP;
2128
2129 /* is this a new value? */
2130 if (pf->wol_en != !!wol->wolopts) {
2131 pf->wol_en = !!wol->wolopts;
2132 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2133 }
2134
2135 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002136}
2137
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002138static int i40e_set_phys_id(struct net_device *netdev,
2139 enum ethtool_phys_id_state state)
2140{
2141 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002142 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002143 struct i40e_pf *pf = np->vsi->back;
2144 struct i40e_hw *hw = &pf->hw;
2145 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002146 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002147
2148 switch (state) {
2149 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002150 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002151 pf->led_status = i40e_led_get(hw);
2152 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002153 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2154 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2155 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002156 ret = i40e_led_get_phy(hw, &temp_status,
2157 &pf->phy_led_val);
2158 pf->led_status = temp_status;
2159 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002160 return blink_freq;
2161 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002162 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002163 i40e_led_set(hw, 0xf, false);
2164 else
2165 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002166 break;
2167 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002168 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002169 i40e_led_set(hw, 0x0, false);
2170 else
2171 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 break;
2173 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002174 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002175 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002176 } else {
2177 ret = i40e_led_set_phy(hw, false, pf->led_status,
2178 (pf->phy_led_val |
2179 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002180 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2181 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002182 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002183 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002184 default:
2185 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002186 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002187 if (ret)
2188 return -ENOENT;
2189 else
2190 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002191}
2192
2193/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2194 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2195 * 125us (8000 interrupts per second) == ITR(62)
2196 */
2197
Jacob Keller65e87c02016-09-12 14:18:44 -07002198/**
2199 * __i40e_get_coalesce - get per-queue coalesce settings
2200 * @netdev: the netdev to check
2201 * @ec: ethtool coalesce data structure
2202 * @queue: which queue to pick
2203 *
2204 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2205 * are per queue. If queue is <0 then we default to queue 0 as the
2206 * representative value.
2207 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002208static int __i40e_get_coalesce(struct net_device *netdev,
2209 struct ethtool_coalesce *ec,
2210 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002211{
2212 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002213 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002214 struct i40e_vsi *vsi = np->vsi;
2215
2216 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2217 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2218
Alan Bradya03af692017-10-05 14:53:37 -07002219 /* rx and tx usecs has per queue value. If user doesn't specify the
2220 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002221 */
Alan Bradya03af692017-10-05 14:53:37 -07002222 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002223 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002224 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002225 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002226
Jacob Keller65e87c02016-09-12 14:18:44 -07002227 rx_ring = vsi->rx_rings[queue];
2228 tx_ring = vsi->tx_rings[queue];
2229
Alexander Duyck40588ca2017-12-29 08:49:28 -05002230 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002231 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232
Alexander Duyck40588ca2017-12-29 08:49:28 -05002233 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002234 ec->use_adaptive_tx_coalesce = 1;
2235
Alexander Duyck40588ca2017-12-29 08:49:28 -05002236 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2237 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
Jacob Keller65e87c02016-09-12 14:18:44 -07002238
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002239 /* we use the _usecs_high to store/set the interrupt rate limit
2240 * that the hardware supports, that almost but not quite
2241 * fits the original intent of the ethtool variable,
2242 * the rx_coalesce_usecs_high limits total interrupts
2243 * per second from both tx/rx sources.
2244 */
2245 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2246 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002247
2248 return 0;
2249}
2250
Jacob Keller65e87c02016-09-12 14:18:44 -07002251/**
2252 * i40e_get_coalesce - get a netdev's coalesce settings
2253 * @netdev: the netdev to check
2254 * @ec: ethtool coalesce data structure
2255 *
2256 * Gets the coalesce settings for a particular netdev. Note that if user has
2257 * modified per-queue settings, this only guarantees to represent queue 0. See
2258 * __i40e_get_coalesce for more details.
2259 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002260static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002261 struct ethtool_coalesce *ec)
2262{
Kan Lianga75e8002016-02-19 09:24:04 -05002263 return __i40e_get_coalesce(netdev, ec, -1);
2264}
2265
Jacob Keller65e87c02016-09-12 14:18:44 -07002266/**
2267 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2268 * @netdev: netdev structure
2269 * @ec: ethtool's coalesce settings
2270 * @queue: the particular queue to read
2271 *
2272 * Will read a specific queue's coalesce settings
2273 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002274static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2275 struct ethtool_coalesce *ec)
2276{
2277 return __i40e_get_coalesce(netdev, ec, queue);
2278}
2279
Jacob Keller65e87c02016-09-12 14:18:44 -07002280/**
2281 * i40e_set_itr_per_queue - set ITR values for specific queue
2282 * @vsi: the VSI to set values for
2283 * @ec: coalesce settings from ethtool
2284 * @queue: the queue to modify
2285 *
2286 * Change the ITR settings for a specific queue.
2287 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002288static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2289 struct ethtool_coalesce *ec,
2290 int queue)
2291{
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002292 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2293 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002294 struct i40e_pf *pf = vsi->back;
2295 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002296 struct i40e_q_vector *q_vector;
Alexander Duyck8b99b112017-12-29 08:50:44 -05002297 u16 intrl;
Kan Lianga75e8002016-02-19 09:24:04 -05002298
Alan Brady1c0e6a32016-11-28 16:06:02 -08002299 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002300
Alexander Duyck92418fb2017-12-29 08:51:08 -05002301 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2302 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
Kan Lianga75e8002016-02-19 09:24:04 -05002303
2304 if (ec->use_adaptive_rx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002305 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002306 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002307 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002308
2309 if (ec->use_adaptive_tx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002310 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002311 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002312 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002313
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002314 q_vector = rx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002315 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
Kan Lianga75e8002016-02-19 09:24:04 -05002316
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002317 q_vector = tx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002318 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2319
2320 /* The interrupt handler itself will take care of programming
2321 * the Tx and Rx ITR values based on the values we have entered
2322 * into the q_vector, no need to write the values now.
2323 */
Kan Lianga75e8002016-02-19 09:24:04 -05002324
Alexander Duyck8b99b112017-12-29 08:50:44 -05002325 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
Kan Lianga75e8002016-02-19 09:24:04 -05002326 i40e_flush(hw);
2327}
2328
Jacob Keller65e87c02016-09-12 14:18:44 -07002329/**
2330 * __i40e_set_coalesce - set coalesce settings for particular queue
2331 * @netdev: the netdev to change
2332 * @ec: ethtool coalesce settings
2333 * @queue: the queue to change
2334 *
2335 * Sets the coalesce settings for a particular queue.
2336 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002337static int __i40e_set_coalesce(struct net_device *netdev,
2338 struct ethtool_coalesce *ec,
2339 int queue)
2340{
2341 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002342 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002343 struct i40e_vsi *vsi = np->vsi;
2344 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002345 int i;
2346
2347 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2348 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2349
Alan Brady06b2dec2017-07-12 05:46:06 -04002350 if (queue < 0) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002351 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2352 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002353 } else if (queue < vsi->num_queue_pairs) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002354 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2355 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002356 } else {
2357 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2358 vsi->num_queue_pairs - 1);
2359 return -EINVAL;
2360 }
2361
2362 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2363 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2364
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002365 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2366 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2367 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2368 return -EINVAL;
2369 }
2370
Alan Brady33084062016-11-28 16:06:03 -08002371 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2372 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2373 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002374 return -EINVAL;
2375 }
2376
Alan Brady06b2dec2017-07-12 05:46:06 -04002377 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2378 ec->use_adaptive_rx_coalesce) {
2379 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2380 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002381 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002382
Alexander Duyck92418fb2017-12-29 08:51:08 -05002383 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002384 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2385 return -EINVAL;
2386 }
2387
2388 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2389 ec->use_adaptive_tx_coalesce) {
2390 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2391 return -EINVAL;
2392 }
2393
Alexander Duyck92418fb2017-12-29 08:51:08 -05002394 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002395 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2396 return -EINVAL;
2397 }
2398
2399 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002400 ec->rx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002401
2402 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002403 ec->tx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002404
Alan Brady33084062016-11-28 16:06:03 -08002405 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2406 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2407 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2408 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2409 vsi->int_rate_limit);
2410 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002411
Alan Bradya03af692017-10-05 14:53:37 -07002412 /* rx and tx usecs has per queue value. If user doesn't specify the
2413 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002414 */
2415 if (queue < 0) {
2416 for (i = 0; i < vsi->num_queue_pairs; i++)
2417 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002418 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002419 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002420 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002421
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002422 return 0;
2423}
2424
Jacob Keller65e87c02016-09-12 14:18:44 -07002425/**
2426 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2427 * @netdev: the netdev to change
2428 * @ec: ethtool coalesce settings
2429 *
2430 * This will set each queue to the same coalesce settings.
2431 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002432static int i40e_set_coalesce(struct net_device *netdev,
2433 struct ethtool_coalesce *ec)
2434{
2435 return __i40e_set_coalesce(netdev, ec, -1);
2436}
2437
Jacob Keller65e87c02016-09-12 14:18:44 -07002438/**
2439 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2440 * @netdev: the netdev to change
2441 * @ec: ethtool's coalesce settings
2442 * @queue: the queue to change
2443 *
2444 * Sets the specified queue's coalesce settings.
2445 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002446static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2447 struct ethtool_coalesce *ec)
2448{
2449 return __i40e_set_coalesce(netdev, ec, queue);
2450}
2451
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002452/**
2453 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2454 * @pf: pointer to the physical function struct
2455 * @cmd: ethtool rxnfc command
2456 *
2457 * Returns Success if the flow is supported, else Invalid Input.
2458 **/
2459static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2460{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002461 struct i40e_hw *hw = &pf->hw;
2462 u8 flow_pctype = 0;
2463 u64 i_set = 0;
2464
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002465 cmd->data = 0;
2466
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002467 switch (cmd->flow_type) {
2468 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002469 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2470 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002471 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002472 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2473 break;
2474 case TCP_V6_FLOW:
2475 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2476 break;
2477 case UDP_V6_FLOW:
2478 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2479 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002480 case SCTP_V4_FLOW:
2481 case AH_ESP_V4_FLOW:
2482 case AH_V4_FLOW:
2483 case ESP_V4_FLOW:
2484 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002485 case SCTP_V6_FLOW:
2486 case AH_ESP_V6_FLOW:
2487 case AH_V6_FLOW:
2488 case ESP_V6_FLOW:
2489 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002490 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002491 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2492 break;
2493 default:
2494 return -EINVAL;
2495 }
2496
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002497 /* Read flow based hash input set register */
2498 if (flow_pctype) {
2499 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2500 flow_pctype)) |
2501 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2502 flow_pctype)) << 32);
2503 }
2504
2505 /* Process bits of hash input set */
2506 if (i_set) {
2507 if (i_set & I40E_L4_SRC_MASK)
2508 cmd->data |= RXH_L4_B_0_1;
2509 if (i_set & I40E_L4_DST_MASK)
2510 cmd->data |= RXH_L4_B_2_3;
2511
2512 if (cmd->flow_type == TCP_V4_FLOW ||
2513 cmd->flow_type == UDP_V4_FLOW) {
2514 if (i_set & I40E_L3_SRC_MASK)
2515 cmd->data |= RXH_IP_SRC;
2516 if (i_set & I40E_L3_DST_MASK)
2517 cmd->data |= RXH_IP_DST;
2518 } else if (cmd->flow_type == TCP_V6_FLOW ||
2519 cmd->flow_type == UDP_V6_FLOW) {
2520 if (i_set & I40E_L3_V6_SRC_MASK)
2521 cmd->data |= RXH_IP_SRC;
2522 if (i_set & I40E_L3_V6_DST_MASK)
2523 cmd->data |= RXH_IP_DST;
2524 }
2525 }
2526
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002527 return 0;
2528}
2529
2530/**
Jacob Kellere7930952017-02-06 14:38:49 -08002531 * i40e_check_mask - Check whether a mask field is set
2532 * @mask: the full mask value
Jacob Kellerf5254422018-04-20 01:41:33 -07002533 * @field: mask of the field to check
Jacob Kellere7930952017-02-06 14:38:49 -08002534 *
2535 * If the given mask is fully set, return positive value. If the mask for the
2536 * field is fully unset, return zero. Otherwise return a negative error code.
2537 **/
2538static int i40e_check_mask(u64 mask, u64 field)
2539{
2540 u64 value = mask & field;
2541
2542 if (value == field)
2543 return 1;
2544 else if (!value)
2545 return 0;
2546 else
2547 return -1;
2548}
2549
2550/**
2551 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2552 * @fsp: pointer to rx flow specification
2553 * @data: pointer to userdef data structure for storage
2554 *
2555 * Read the user-defined data and deconstruct the value into a structure. No
2556 * other code should read the user-defined data, so as to ensure that every
2557 * place consistently reads the value correctly.
2558 *
2559 * The user-defined field is a 64bit Big Endian format value, which we
2560 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2561 * be defined starting from the highest bits, while small bit field values
2562 * shall be defined starting from the lowest bits.
2563 *
2564 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2565 * and the filter should be rejected. The data structure will always be
2566 * modified even if FLOW_EXT is not set.
2567 *
2568 **/
2569static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2570 struct i40e_rx_flow_userdef *data)
2571{
2572 u64 value, mask;
2573 int valid;
2574
2575 /* Zero memory first so it's always consistent. */
2576 memset(data, 0, sizeof(*data));
2577
2578 if (!(fsp->flow_type & FLOW_EXT))
2579 return 0;
2580
2581 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2582 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2583
2584#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2585#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2586#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2587
2588 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2589 if (valid < 0) {
2590 return -EINVAL;
2591 } else if (valid) {
2592 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2593 data->flex_offset =
2594 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2595 data->flex_filter = true;
2596 }
2597
2598 return 0;
2599}
2600
2601/**
2602 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2603 * @fsp: pointer to rx_flow specification
Jacob Kellerf5254422018-04-20 01:41:33 -07002604 * @data: pointer to return userdef data
Jacob Kellere7930952017-02-06 14:38:49 -08002605 *
2606 * Reads the userdef data structure and properly fills in the user defined
2607 * fields of the rx_flow_spec.
2608 **/
2609static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2610 struct i40e_rx_flow_userdef *data)
2611{
2612 u64 value = 0, mask = 0;
2613
2614 if (data->flex_filter) {
2615 value |= data->flex_word;
2616 value |= (u64)data->flex_offset << 16;
2617 mask |= I40E_USERDEF_FLEX_FILTER;
2618 }
2619
2620 if (value || mask)
2621 fsp->flow_type |= FLOW_EXT;
2622
2623 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2624 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2625}
2626
2627/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002628 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2629 * @pf: Pointer to the physical function struct
2630 * @cmd: The command to get or set Rx flow classification rules
2631 * @rule_locs: Array of used rule locations
2632 *
2633 * This function populates both the total and actual rule count of
2634 * the ethtool flow classification command
2635 *
2636 * Returns 0 on success or -EMSGSIZE if entry not found
2637 **/
2638static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2639 struct ethtool_rxnfc *cmd,
2640 u32 *rule_locs)
2641{
2642 struct i40e_fdir_filter *rule;
2643 struct hlist_node *node2;
2644 int cnt = 0;
2645
2646 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002647 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002648
2649 hlist_for_each_entry_safe(rule, node2,
2650 &pf->fdir_filter_list, fdir_node) {
2651 if (cnt == cmd->rule_cnt)
2652 return -EMSGSIZE;
2653
2654 rule_locs[cnt] = rule->fd_id;
2655 cnt++;
2656 }
2657
2658 cmd->rule_cnt = cnt;
2659
2660 return 0;
2661}
2662
2663/**
2664 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2665 * @pf: Pointer to the physical function struct
2666 * @cmd: The command to get or set Rx flow classification rules
2667 *
2668 * This function looks up a filter based on the Rx flow classification
2669 * command and fills the flow spec info for it if found
2670 *
2671 * Returns 0 on success or -EINVAL if filter not found
2672 **/
2673static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2674 struct ethtool_rxnfc *cmd)
2675{
2676 struct ethtool_rx_flow_spec *fsp =
2677 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002678 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002679 struct i40e_fdir_filter *rule = NULL;
2680 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002681 u64 input_set;
2682 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002683
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002684 hlist_for_each_entry_safe(rule, node2,
2685 &pf->fdir_filter_list, fdir_node) {
2686 if (fsp->location <= rule->fd_id)
2687 break;
2688 }
2689
2690 if (!rule || fsp->location != rule->fd_id)
2691 return -EINVAL;
2692
2693 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002694 if (fsp->flow_type == IP_USER_FLOW) {
2695 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2696 fsp->h_u.usr_ip4_spec.proto = 0;
2697 fsp->m_u.usr_ip4_spec.proto = 0;
2698 }
2699
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002700 /* Reverse the src and dest notion, since the HW views them from
2701 * Tx perspective where as the user expects it from Rx filter view.
2702 */
2703 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2704 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002705 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2706 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002707
Jacob Keller36777d92017-03-07 15:05:23 -08002708 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002709 case SCTP_V4_FLOW:
2710 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2711 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002712 case TCP_V4_FLOW:
2713 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2714 break;
2715 case UDP_V4_FLOW:
2716 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2717 break;
2718 case IP_USER_FLOW:
2719 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2720 break;
2721 default:
2722 /* If we have stored a filter with a flow type not listed here
2723 * it is almost certainly a driver bug. WARN(), and then
2724 * assign the input_set as if all fields are enabled to avoid
2725 * reading unassigned memory.
2726 */
2727 WARN(1, "Missing input set index for flow_type %d\n",
2728 rule->flow_type);
2729 input_set = 0xFFFFFFFFFFFFFFFFULL;
2730 goto no_input_set;
2731 }
2732
2733 input_set = i40e_read_fd_input_set(pf, index);
2734
2735no_input_set:
2736 if (input_set & I40E_L3_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002737 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002738
2739 if (input_set & I40E_L3_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002740 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002741
2742 if (input_set & I40E_L4_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002743 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002744
2745 if (input_set & I40E_L4_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002746 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002747
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002748 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2749 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2750 else
2751 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002752
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002753 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2754 struct i40e_vsi *vsi;
2755
2756 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2757 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002758 /* VFs are zero-indexed by the driver, but ethtool
2759 * expects them to be one-indexed, so add one here
2760 */
2761 u64 ring_vf = vsi->vf_id + 1;
2762
2763 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2764 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002765 }
2766 }
2767
Jacob Keller0e588de2017-02-06 14:38:50 -08002768 if (rule->flex_filter) {
2769 userdef.flex_filter = true;
2770 userdef.flex_word = be16_to_cpu(rule->flex_word);
2771 userdef.flex_offset = rule->flex_offset;
2772 }
2773
Jacob Kellere7930952017-02-06 14:38:49 -08002774 i40e_fill_rx_flow_user_data(fsp, &userdef);
2775
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002776 return 0;
2777}
2778
2779/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002780 * i40e_get_rxnfc - command to get RX flow classification rules
2781 * @netdev: network interface device structure
2782 * @cmd: ethtool rxnfc command
Jacob Kellerf5254422018-04-20 01:41:33 -07002783 * @rule_locs: pointer to store rule data
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002784 *
2785 * Returns Success if the command is supported.
2786 **/
2787static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2788 u32 *rule_locs)
2789{
2790 struct i40e_netdev_priv *np = netdev_priv(netdev);
2791 struct i40e_vsi *vsi = np->vsi;
2792 struct i40e_pf *pf = vsi->back;
2793 int ret = -EOPNOTSUPP;
2794
2795 switch (cmd->cmd) {
2796 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002797 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002798 ret = 0;
2799 break;
2800 case ETHTOOL_GRXFH:
2801 ret = i40e_get_rss_hash_opts(pf, cmd);
2802 break;
2803 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002804 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002805 /* report total rule count */
2806 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002807 ret = 0;
2808 break;
2809 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002810 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002811 break;
2812 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002813 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2814 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002815 default:
2816 break;
2817 }
2818
2819 return ret;
2820}
2821
2822/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002823 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2824 * @nfc: pointer to user request
Jacob Kellerf5254422018-04-20 01:41:33 -07002825 * @i_setc: bits currently set
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002826 *
2827 * Returns value of bits to be set per user request
2828 **/
2829static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2830{
2831 u64 i_set = i_setc;
2832 u64 src_l3 = 0, dst_l3 = 0;
2833
2834 if (nfc->data & RXH_L4_B_0_1)
2835 i_set |= I40E_L4_SRC_MASK;
2836 else
2837 i_set &= ~I40E_L4_SRC_MASK;
2838 if (nfc->data & RXH_L4_B_2_3)
2839 i_set |= I40E_L4_DST_MASK;
2840 else
2841 i_set &= ~I40E_L4_DST_MASK;
2842
2843 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2844 src_l3 = I40E_L3_V6_SRC_MASK;
2845 dst_l3 = I40E_L3_V6_DST_MASK;
2846 } else if (nfc->flow_type == TCP_V4_FLOW ||
2847 nfc->flow_type == UDP_V4_FLOW) {
2848 src_l3 = I40E_L3_SRC_MASK;
2849 dst_l3 = I40E_L3_DST_MASK;
2850 } else {
2851 /* Any other flow type are not supported here */
2852 return i_set;
2853 }
2854
2855 if (nfc->data & RXH_IP_SRC)
2856 i_set |= src_l3;
2857 else
2858 i_set &= ~src_l3;
2859 if (nfc->data & RXH_IP_DST)
2860 i_set |= dst_l3;
2861 else
2862 i_set &= ~dst_l3;
2863
2864 return i_set;
2865}
2866
2867/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002868 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2869 * @pf: pointer to the physical function struct
Jacob Kellerf5254422018-04-20 01:41:33 -07002870 * @nfc: ethtool rxnfc command
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002871 *
2872 * Returns Success if the flow input set is supported.
2873 **/
2874static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2875{
2876 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002877 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2878 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002879 u8 flow_pctype = 0;
2880 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002881
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002882 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2883 dev_err(&pf->pdev->dev,
2884 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2885 return -EOPNOTSUPP;
2886 }
2887
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002888 /* RSS does not support anything other than hashing
2889 * to queues on src and dst IPs and ports
2890 */
2891 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2892 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2893 return -EINVAL;
2894
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002895 switch (nfc->flow_type) {
2896 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002897 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002898 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002899 hena |=
2900 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002901 break;
2902 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002903 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002904 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002905 hena |=
2906 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002907 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002908 hena |=
2909 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002910 break;
2911 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002912 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002913 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002914 hena |=
2915 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2916 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002917
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002918 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002919 break;
2920 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002921 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002922 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002923 hena |=
2924 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2925 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002926
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002927 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002928 break;
2929 case AH_ESP_V4_FLOW:
2930 case AH_V4_FLOW:
2931 case ESP_V4_FLOW:
2932 case SCTP_V4_FLOW:
2933 if ((nfc->data & RXH_L4_B_0_1) ||
2934 (nfc->data & RXH_L4_B_2_3))
2935 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002936 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002937 break;
2938 case AH_ESP_V6_FLOW:
2939 case AH_V6_FLOW:
2940 case ESP_V6_FLOW:
2941 case SCTP_V6_FLOW:
2942 if ((nfc->data & RXH_L4_B_0_1) ||
2943 (nfc->data & RXH_L4_B_2_3))
2944 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002945 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002946 break;
2947 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002948 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2949 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002950 break;
2951 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002952 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2953 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002954 break;
2955 default:
2956 return -EINVAL;
2957 }
2958
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002959 if (flow_pctype) {
2960 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2961 flow_pctype)) |
2962 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2963 flow_pctype)) << 32);
2964 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2965 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2966 (u32)i_set);
2967 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2968 (u32)(i_set >> 32));
2969 hena |= BIT_ULL(flow_pctype);
2970 }
2971
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002972 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2973 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002974 i40e_flush(hw);
2975
2976 return 0;
2977}
2978
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002979/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002980 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2981 * @vsi: Pointer to the targeted VSI
2982 * @input: The filter to update or NULL to indicate deletion
2983 * @sw_idx: Software index to the filter
2984 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002985 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002986 * This function updates (or deletes) a Flow Director entry from
2987 * the hlist of the corresponding PF
2988 *
2989 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002990 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002991static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2992 struct i40e_fdir_filter *input,
2993 u16 sw_idx,
2994 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002995{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002996 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002997 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002998 struct hlist_node *node2;
2999 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003000
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003001 parent = NULL;
3002 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003003
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003004 hlist_for_each_entry_safe(rule, node2,
3005 &pf->fdir_filter_list, fdir_node) {
3006 /* hash found, or no matching entry */
3007 if (rule->fd_id >= sw_idx)
3008 break;
3009 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003010 }
3011
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003012 /* if there is an old rule occupying our place remove it */
3013 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08003014 /* Remove this rule, since we're either deleting it, or
3015 * replacing it.
3016 */
3017 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003018 hlist_del(&rule->fdir_node);
3019 kfree(rule);
3020 pf->fdir_pf_active_filters--;
3021 }
3022
Jacob Kellerc6da5252017-02-06 14:39:13 -08003023 /* If we weren't given an input, this is a delete, so just return the
3024 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003025 */
3026 if (!input)
3027 return err;
3028
Jacob Kellerc6da5252017-02-06 14:39:13 -08003029 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003030 INIT_HLIST_NODE(&input->fdir_node);
3031
3032 /* add filter to the list */
3033 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003034 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003035 else
3036 hlist_add_head(&input->fdir_node,
3037 &pf->fdir_filter_list);
3038
3039 /* update counts */
3040 pf->fdir_pf_active_filters++;
3041
3042 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003043}
3044
3045/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003046 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3047 * @pf: pointer to PF structure
3048 *
3049 * This function searches the list of filters and determines which FLX_PIT
3050 * entries are still required. It will prune any entries which are no longer
3051 * in use after the deletion.
3052 **/
3053static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3054{
3055 struct i40e_flex_pit *entry, *tmp;
3056 struct i40e_fdir_filter *rule;
3057
3058 /* First, we'll check the l3 table */
3059 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3060 bool found = false;
3061
3062 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3063 if (rule->flow_type != IP_USER_FLOW)
3064 continue;
3065 if (rule->flex_filter &&
3066 rule->flex_offset == entry->src_offset) {
3067 found = true;
3068 break;
3069 }
3070 }
3071
3072 /* If we didn't find the filter, then we can prune this entry
3073 * from the list.
3074 */
3075 if (!found) {
3076 list_del(&entry->list);
3077 kfree(entry);
3078 }
3079 }
3080
3081 /* Followed by the L4 table */
3082 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3083 bool found = false;
3084
3085 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3086 /* Skip this filter if it's L3, since we already
3087 * checked those in the above loop
3088 */
3089 if (rule->flow_type == IP_USER_FLOW)
3090 continue;
3091 if (rule->flex_filter &&
3092 rule->flex_offset == entry->src_offset) {
3093 found = true;
3094 break;
3095 }
3096 }
3097
3098 /* If we didn't find the filter, then we can prune this entry
3099 * from the list.
3100 */
3101 if (!found) {
3102 list_del(&entry->list);
3103 kfree(entry);
3104 }
3105 }
3106}
3107
3108/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003109 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3110 * @vsi: Pointer to the targeted VSI
3111 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003112 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003113 * The function removes a Flow Director filter entry from the
3114 * hlist of the corresponding PF
3115 *
3116 * Returns 0 on success
3117 */
3118static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3119 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003120{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003121 struct ethtool_rx_flow_spec *fsp =
3122 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003123 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003124 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003125
Jacob Keller0da36b92017-04-19 09:25:55 -04003126 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3127 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003128 return -EBUSY;
3129
Jacob Keller0da36b92017-04-19 09:25:55 -04003130 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003131 return -EBUSY;
3132
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003133 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003134
Jacob Keller0e588de2017-02-06 14:38:50 -08003135 i40e_prune_flex_pit_list(pf);
3136
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003137 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003138 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003139}
3140
3141/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003142 * i40e_unused_pit_index - Find an unused PIT index for given list
3143 * @pf: the PF data structure
3144 *
3145 * Find the first unused flexible PIT index entry. We search both the L3 and
3146 * L4 flexible PIT lists so that the returned index is unique and unused by
3147 * either currently programmed L3 or L4 filters. We use a bit field as storage
3148 * to track which indexes are already used.
3149 **/
3150static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3151{
3152 unsigned long available_index = 0xFF;
3153 struct i40e_flex_pit *entry;
3154
3155 /* We need to make sure that the new index isn't in use by either L3
3156 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3157 * L4 to use the same index.
3158 */
3159
3160 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3161 clear_bit(entry->pit_index, &available_index);
3162
3163 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3164 clear_bit(entry->pit_index, &available_index);
3165
3166 return find_first_bit(&available_index, 8);
3167}
3168
3169/**
3170 * i40e_find_flex_offset - Find an existing flex src_offset
3171 * @flex_pit_list: L3 or L4 flex PIT list
3172 * @src_offset: new src_offset to find
3173 *
3174 * Searches the flex_pit_list for an existing offset. If no offset is
3175 * currently programmed, then this will return an ERR_PTR if there is no space
3176 * to add a new offset, otherwise it returns NULL.
3177 **/
3178static
3179struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3180 u16 src_offset)
3181{
3182 struct i40e_flex_pit *entry;
3183 int size = 0;
3184
3185 /* Search for the src_offset first. If we find a matching entry
3186 * already programmed, we can simply re-use it.
3187 */
3188 list_for_each_entry(entry, flex_pit_list, list) {
3189 size++;
3190 if (entry->src_offset == src_offset)
3191 return entry;
3192 }
3193
3194 /* If we haven't found an entry yet, then the provided src offset has
3195 * not yet been programmed. We will program the src offset later on,
3196 * but we need to indicate whether there is enough space to do so
3197 * here. We'll make use of ERR_PTR for this purpose.
3198 */
3199 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3200 return ERR_PTR(-ENOSPC);
3201
3202 return NULL;
3203}
3204
3205/**
3206 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3207 * @flex_pit_list: L3 or L4 flex PIT list
3208 * @src_offset: new src_offset to add
3209 * @pit_index: the PIT index to program
3210 *
3211 * This function programs the new src_offset to the list. It is expected that
3212 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3213 * that this offset is not programmed, and that the list has enough space to
3214 * store another offset.
3215 *
3216 * Returns 0 on success, and negative value on error.
3217 **/
3218static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3219 u16 src_offset,
3220 u8 pit_index)
3221{
3222 struct i40e_flex_pit *new_pit, *entry;
3223
3224 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3225 if (!new_pit)
3226 return -ENOMEM;
3227
3228 new_pit->src_offset = src_offset;
3229 new_pit->pit_index = pit_index;
3230
3231 /* We need to insert this item such that the list is sorted by
3232 * src_offset in ascending order.
3233 */
3234 list_for_each_entry(entry, flex_pit_list, list) {
3235 if (new_pit->src_offset < entry->src_offset) {
3236 list_add_tail(&new_pit->list, &entry->list);
3237 return 0;
3238 }
3239
3240 /* If we found an entry with our offset already programmed we
3241 * can simply return here, after freeing the memory. However,
3242 * if the pit_index does not match we need to report an error.
3243 */
3244 if (new_pit->src_offset == entry->src_offset) {
3245 int err = 0;
3246
3247 /* If the PIT index is not the same we can't re-use
3248 * the entry, so we must report an error.
3249 */
3250 if (new_pit->pit_index != entry->pit_index)
3251 err = -EINVAL;
3252
3253 kfree(new_pit);
3254 return err;
3255 }
3256 }
3257
3258 /* If we reached here, then we haven't yet added the item. This means
3259 * that we should add the item at the end of the list.
3260 */
3261 list_add_tail(&new_pit->list, flex_pit_list);
3262 return 0;
3263}
3264
3265/**
3266 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3267 * @pf: Pointer to the PF structure
3268 * @flex_pit_list: list of flexible src offsets in use
Jacob Kellerf5254422018-04-20 01:41:33 -07003269 * @flex_pit_start: index to first entry for this section of the table
Jacob Keller0e588de2017-02-06 14:38:50 -08003270 *
3271 * In order to handle flexible data, the hardware uses a table of values
3272 * called the FLX_PIT table. This table is used to indicate which sections of
3273 * the input correspond to what PIT index values. Unfortunately, hardware is
3274 * very restrictive about programming this table. Entries must be ordered by
3275 * src_offset in ascending order, without duplicates. Additionally, unused
3276 * entries must be set to the unused index value, and must have valid size and
3277 * length according to the src_offset ordering.
3278 *
3279 * This function will reprogram the FLX_PIT register from a book-keeping
3280 * structure that we guarantee is already ordered correctly, and has no more
3281 * than 3 entries.
3282 *
3283 * To make things easier, we only support flexible values of one word length,
3284 * rather than allowing variable length flexible values.
3285 **/
3286static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3287 struct list_head *flex_pit_list,
3288 int flex_pit_start)
3289{
3290 struct i40e_flex_pit *entry = NULL;
3291 u16 last_offset = 0;
3292 int i = 0, j = 0;
3293
3294 /* First, loop over the list of flex PIT entries, and reprogram the
3295 * registers.
3296 */
3297 list_for_each_entry(entry, flex_pit_list, list) {
3298 /* We have to be careful when programming values for the
3299 * largest SRC_OFFSET value. It is possible that adding
3300 * additional empty values at the end would overflow the space
3301 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3302 * we check here and add the empty values prior to adding the
3303 * largest value.
3304 *
3305 * To determine this, we will use a loop from i+1 to 3, which
3306 * will determine whether the unused entries would have valid
3307 * SRC_OFFSET. Note that there cannot be extra entries past
3308 * this value, because the only valid values would have been
3309 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3310 * have been added to the list in the first place.
3311 */
3312 for (j = i + 1; j < 3; j++) {
3313 u16 offset = entry->src_offset + j;
3314 int index = flex_pit_start + i;
3315 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3316 1,
3317 offset - 3);
3318
3319 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3320 i40e_write_rx_ctl(&pf->hw,
3321 I40E_PRTQF_FLX_PIT(index),
3322 value);
3323 i++;
3324 }
3325 }
3326
3327 /* Now, we can program the actual value into the table */
3328 i40e_write_rx_ctl(&pf->hw,
3329 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3330 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3331 1,
3332 entry->src_offset));
3333 i++;
3334 }
3335
3336 /* In order to program the last entries in the table, we need to
3337 * determine the valid offset. If the list is empty, we'll just start
3338 * with 0. Otherwise, we'll start with the last item offset and add 1.
3339 * This ensures that all entries have valid sizes. If we don't do this
3340 * correctly, the hardware will disable flexible field parsing.
3341 */
3342 if (!list_empty(flex_pit_list))
3343 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3344
3345 for (; i < 3; i++, last_offset++) {
3346 i40e_write_rx_ctl(&pf->hw,
3347 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3348 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3349 1,
3350 last_offset));
3351 }
3352}
3353
3354/**
3355 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3356 * @pf: pointer to the PF structure
3357 *
3358 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3359 * internal helper function for implementation details.
3360 **/
3361static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3362{
3363 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3364 I40E_FLEX_PIT_IDX_START_L3);
3365
3366 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3367 I40E_FLEX_PIT_IDX_START_L4);
3368
3369 /* We also need to program the L3 and L4 GLQF ORT register */
3370 i40e_write_rx_ctl(&pf->hw,
3371 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3372 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3373 3, 1));
3374
3375 i40e_write_rx_ctl(&pf->hw,
3376 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3377 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3378 3, 1));
3379}
3380
3381/**
Jacob Keller9229e992017-02-06 14:38:47 -08003382 * i40e_flow_str - Converts a flow_type into a human readable string
Jacob Kellerf5254422018-04-20 01:41:33 -07003383 * @fsp: the flow specification
Jacob Keller9229e992017-02-06 14:38:47 -08003384 *
3385 * Currently only flow types we support are included here, and the string
3386 * value attempts to match what ethtool would use to configure this flow type.
3387 **/
3388static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3389{
3390 switch (fsp->flow_type & ~FLOW_EXT) {
3391 case TCP_V4_FLOW:
3392 return "tcp4";
3393 case UDP_V4_FLOW:
3394 return "udp4";
3395 case SCTP_V4_FLOW:
3396 return "sctp4";
3397 case IP_USER_FLOW:
3398 return "ip4";
3399 default:
3400 return "unknown";
3401 }
3402}
3403
3404/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003405 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3406 * @pit_index: PIT index to convert
3407 *
3408 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3409 * of range.
3410 **/
3411static u64 i40e_pit_index_to_mask(int pit_index)
3412{
3413 switch (pit_index) {
3414 case 0:
3415 return I40E_FLEX_50_MASK;
3416 case 1:
3417 return I40E_FLEX_51_MASK;
3418 case 2:
3419 return I40E_FLEX_52_MASK;
3420 case 3:
3421 return I40E_FLEX_53_MASK;
3422 case 4:
3423 return I40E_FLEX_54_MASK;
3424 case 5:
3425 return I40E_FLEX_55_MASK;
3426 case 6:
3427 return I40E_FLEX_56_MASK;
3428 case 7:
3429 return I40E_FLEX_57_MASK;
3430 default:
3431 return 0;
3432 }
3433}
3434
3435/**
Jacob Keller9229e992017-02-06 14:38:47 -08003436 * i40e_print_input_set - Show changes between two input sets
3437 * @vsi: the vsi being configured
3438 * @old: the old input set
3439 * @new: the new input set
3440 *
3441 * Print the difference between old and new input sets by showing which series
3442 * of words are toggled on or off. Only displays the bits we actually support
3443 * changing.
3444 **/
3445static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3446{
3447 struct i40e_pf *pf = vsi->back;
3448 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003449 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003450
3451 old_value = !!(old & I40E_L3_SRC_MASK);
3452 new_value = !!(new & I40E_L3_SRC_MASK);
3453 if (old_value != new_value)
3454 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3455 old_value ? "ON" : "OFF",
3456 new_value ? "ON" : "OFF");
3457
3458 old_value = !!(old & I40E_L3_DST_MASK);
3459 new_value = !!(new & I40E_L3_DST_MASK);
3460 if (old_value != new_value)
3461 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3462 old_value ? "ON" : "OFF",
3463 new_value ? "ON" : "OFF");
3464
3465 old_value = !!(old & I40E_L4_SRC_MASK);
3466 new_value = !!(new & I40E_L4_SRC_MASK);
3467 if (old_value != new_value)
3468 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3469 old_value ? "ON" : "OFF",
3470 new_value ? "ON" : "OFF");
3471
3472 old_value = !!(old & I40E_L4_DST_MASK);
3473 new_value = !!(new & I40E_L4_DST_MASK);
3474 if (old_value != new_value)
3475 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3476 old_value ? "ON" : "OFF",
3477 new_value ? "ON" : "OFF");
3478
3479 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3480 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3481 if (old_value != new_value)
3482 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3483 old_value ? "ON" : "OFF",
3484 new_value ? "ON" : "OFF");
3485
Jacob Keller0e588de2017-02-06 14:38:50 -08003486 /* Show change of flexible filter entries */
3487 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3488 u64 flex_mask = i40e_pit_index_to_mask(i);
3489
3490 old_value = !!(old & flex_mask);
3491 new_value = !!(new & flex_mask);
3492 if (old_value != new_value)
3493 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3494 i,
3495 old_value ? "ON" : "OFF",
3496 new_value ? "ON" : "OFF");
3497 }
3498
Jacob Keller9229e992017-02-06 14:38:47 -08003499 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3500 old);
3501 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3502 new);
3503}
3504
3505/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003506 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003507 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003508 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003509 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003510 *
Jacob Keller9229e992017-02-06 14:38:47 -08003511 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3512 * for partial matches exists with a few limitations. First, hardware only
3513 * supports masking by word boundary (2 bytes) and not per individual bit.
3514 * Second, hardware is limited to using one mask for a flow type and cannot
3515 * use a separate mask for each filter.
3516 *
3517 * To support these limitations, if we already have a configured filter for
3518 * the specified type, this function enforces that new filters of the type
3519 * match the configured input set. Otherwise, if we do not have a filter of
3520 * the specified type, we allow the input set to be updated to match the
3521 * desired filter.
3522 *
3523 * To help ensure that administrators understand why filters weren't displayed
3524 * as supported, we print a diagnostic message displaying how the input set
3525 * would change and warning to delete the preexisting filters if required.
3526 *
3527 * Returns 0 on successful input set match, and a negative return code on
3528 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003529 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003530static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003531 struct ethtool_rx_flow_spec *fsp,
3532 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003533{
Jacob Keller36777d92017-03-07 15:05:23 -08003534 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003535 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3536 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003537 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003538 bool new_flex_offset = false;
3539 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003540 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003541 u16 index, src_offset = 0;
3542 u8 pit_index = 0;
3543 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003544
3545 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003546 case SCTP_V4_FLOW:
3547 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3548 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3549 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003550 case TCP_V4_FLOW:
3551 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003552 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003553 break;
3554 case UDP_V4_FLOW:
3555 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003556 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003557 break;
3558 case IP_USER_FLOW:
3559 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003560 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003561 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003562 break;
3563 default:
3564 return -EOPNOTSUPP;
3565 }
3566
3567 /* Read the current input set from register memory. */
3568 current_mask = i40e_read_fd_input_set(pf, index);
3569 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003570
Jacob Keller9229e992017-02-06 14:38:47 -08003571 /* Determine, if any, the required changes to the input set in order
3572 * to support the provided mask.
3573 *
3574 * Hardware only supports masking at word (2 byte) granularity and does
3575 * not support full bitwise masking. This implementation simplifies
3576 * even further and only supports fully enabled or fully disabled
3577 * masks for each field, even though we could split the ip4src and
3578 * ip4dst fields.
3579 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003580 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003581 case SCTP_V4_FLOW:
3582 new_mask &= ~I40E_VERIFY_TAG_MASK;
3583 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003584 case TCP_V4_FLOW:
3585 case UDP_V4_FLOW:
3586 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3587
3588 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003589 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3590 new_mask |= I40E_L3_SRC_MASK;
3591 else if (!tcp_ip4_spec->ip4src)
3592 new_mask &= ~I40E_L3_SRC_MASK;
3593 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003594 return -EOPNOTSUPP;
3595
3596 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003597 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3598 new_mask |= I40E_L3_DST_MASK;
3599 else if (!tcp_ip4_spec->ip4dst)
3600 new_mask &= ~I40E_L3_DST_MASK;
3601 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003602 return -EOPNOTSUPP;
3603
3604 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003605 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3606 new_mask |= I40E_L4_SRC_MASK;
3607 else if (!tcp_ip4_spec->psrc)
3608 new_mask &= ~I40E_L4_SRC_MASK;
3609 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003610 return -EOPNOTSUPP;
3611
3612 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003613 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3614 new_mask |= I40E_L4_DST_MASK;
3615 else if (!tcp_ip4_spec->pdst)
3616 new_mask &= ~I40E_L4_DST_MASK;
3617 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003618 return -EOPNOTSUPP;
3619
3620 /* Filtering on Type of Service is not supported. */
3621 if (tcp_ip4_spec->tos)
3622 return -EOPNOTSUPP;
3623
3624 break;
3625 case IP_USER_FLOW:
3626 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3627
3628 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003629 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3630 new_mask |= I40E_L3_SRC_MASK;
3631 else if (!usr_ip4_spec->ip4src)
3632 new_mask &= ~I40E_L3_SRC_MASK;
3633 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003634 return -EOPNOTSUPP;
3635
3636 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003637 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3638 new_mask |= I40E_L3_DST_MASK;
3639 else if (!usr_ip4_spec->ip4dst)
3640 new_mask &= ~I40E_L3_DST_MASK;
3641 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003642 return -EOPNOTSUPP;
3643
3644 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003645 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3646 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3647 else if (!usr_ip4_spec->l4_4_bytes)
3648 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3649 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003650 return -EOPNOTSUPP;
3651
3652 /* Filtering on Type of Service is not supported. */
3653 if (usr_ip4_spec->tos)
3654 return -EOPNOTSUPP;
3655
Jacob Keller0e588de2017-02-06 14:38:50 -08003656 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003657 if (usr_ip4_spec->ip_ver)
3658 return -EINVAL;
3659
Jacob Keller0e588de2017-02-06 14:38:50 -08003660 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003661 if (usr_ip4_spec->proto)
3662 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003663
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003664 break;
3665 default:
3666 return -EOPNOTSUPP;
3667 }
3668
Jacob Keller0e588de2017-02-06 14:38:50 -08003669 /* First, clear all flexible filter entries */
3670 new_mask &= ~I40E_FLEX_INPUT_MASK;
3671
3672 /* If we have a flexible filter, try to add this offset to the correct
3673 * flexible filter PIT list. Once finished, we can update the mask.
3674 * If the src_offset changed, we will get a new mask value which will
3675 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003676 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003677 if (userdef->flex_filter) {
3678 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3679
3680 /* Flexible offset must be even, since the flexible payload
3681 * must be aligned on 2-byte boundary.
3682 */
3683 if (userdef->flex_offset & 0x1) {
3684 dev_warn(&pf->pdev->dev,
3685 "Flexible data offset must be 2-byte aligned\n");
3686 return -EINVAL;
3687 }
3688
3689 src_offset = userdef->flex_offset >> 1;
3690
3691 /* FLX_PIT source offset value is only so large */
3692 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3693 dev_warn(&pf->pdev->dev,
3694 "Flexible data must reside within first 64 bytes of the packet payload\n");
3695 return -EINVAL;
3696 }
3697
3698 /* See if this offset has already been programmed. If we get
3699 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3700 * if we get a NULL pointer, this means we will need to add
3701 * the offset.
3702 */
3703 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3704 src_offset);
3705 if (IS_ERR(flex_pit))
3706 return PTR_ERR(flex_pit);
3707
3708 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3709 * packet types, and thus we need to program both L3 and L4
3710 * flexible values. These must have identical flexible index,
3711 * as otherwise we can't correctly program the input set. So
3712 * we'll find both an L3 and L4 index and make sure they are
3713 * the same.
3714 */
3715 if (flex_l3) {
3716 l3_flex_pit =
3717 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3718 src_offset);
3719 if (IS_ERR(l3_flex_pit))
3720 return PTR_ERR(l3_flex_pit);
3721
3722 if (flex_pit) {
3723 /* If we already had a matching L4 entry, we
3724 * need to make sure that the L3 entry we
3725 * obtained uses the same index.
3726 */
3727 if (l3_flex_pit) {
3728 if (l3_flex_pit->pit_index !=
3729 flex_pit->pit_index) {
3730 return -EINVAL;
3731 }
3732 } else {
3733 new_flex_offset = true;
3734 }
3735 } else {
3736 flex_pit = l3_flex_pit;
3737 }
3738 }
3739
3740 /* If we didn't find an existing flex offset, we need to
3741 * program a new one. However, we don't immediately program it
3742 * here because we will wait to program until after we check
3743 * that it is safe to change the input set.
3744 */
3745 if (!flex_pit) {
3746 new_flex_offset = true;
3747 pit_index = i40e_unused_pit_index(pf);
3748 } else {
3749 pit_index = flex_pit->pit_index;
3750 }
3751
3752 /* Update the mask with the new offset */
3753 new_mask |= i40e_pit_index_to_mask(pit_index);
3754 }
3755
3756 /* If the mask and flexible filter offsets for this filter match the
3757 * currently programmed values we don't need any input set change, so
3758 * this filter is safe to install.
3759 */
3760 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003761 return 0;
3762
3763 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3764 i40e_flow_str(fsp));
3765 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003766 if (new_flex_offset) {
3767 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3768 pit_index, src_offset);
3769 }
Jacob Keller9229e992017-02-06 14:38:47 -08003770
3771 /* Hardware input sets are global across multiple ports, so even the
3772 * main port cannot change them when in MFP mode as this would impact
3773 * any filters on the other ports.
3774 */
3775 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3776 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003777 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003778 }
3779
3780 /* This filter requires us to update the input set. However, hardware
3781 * only supports one input set per flow type, and does not support
3782 * separate masks for each filter. This means that we can only support
3783 * a single mask for all filters of a specific type.
3784 *
3785 * If we have preexisting filters, they obviously depend on the
3786 * current programmed input set. Display a diagnostic message in this
3787 * case explaining why the filter could not be accepted.
3788 */
3789 if (*fdir_filter_count) {
3790 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3791 i40e_flow_str(fsp),
3792 *fdir_filter_count);
3793 return -EOPNOTSUPP;
3794 }
3795
3796 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003797
Jacob Keller02b40162017-12-27 08:24:12 -05003798 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
3799 * frames. If we're programming the input set for IPv4/Other, we also
3800 * need to program the IPv4/Fragmented input set. Since we don't have
3801 * separate support, we'll always assume and enforce that the two flow
3802 * types must have matching input sets.
3803 */
3804 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
3805 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
3806 new_mask);
3807
Jacob Keller0e588de2017-02-06 14:38:50 -08003808 /* Add the new offset and update table, if necessary */
3809 if (new_flex_offset) {
3810 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3811 pit_index);
3812 if (err)
3813 return err;
3814
3815 if (flex_l3) {
3816 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3817 src_offset,
3818 pit_index);
3819 if (err)
3820 return err;
3821 }
3822
3823 i40e_reprogram_flex_pit(pf);
3824 }
3825
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003826 return 0;
3827}
3828
3829/**
Jacob Keller443ee712017-12-27 08:25:32 -05003830 * i40e_match_fdir_filter - Return true of two filters match
3831 * @a: pointer to filter struct
3832 * @b: pointer to filter struct
3833 *
3834 * Returns true if the two filters match exactly the same criteria. I.e. they
3835 * match the same flow type and have the same parameters. We don't need to
3836 * check any input-set since all filters of the same flow type must use the
3837 * same input set.
3838 **/
3839static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
3840 struct i40e_fdir_filter *b)
3841{
3842 /* The filters do not much if any of these criteria differ. */
3843 if (a->dst_ip != b->dst_ip ||
3844 a->src_ip != b->src_ip ||
3845 a->dst_port != b->dst_port ||
3846 a->src_port != b->src_port ||
3847 a->flow_type != b->flow_type ||
3848 a->ip4_proto != b->ip4_proto)
3849 return false;
3850
3851 return true;
3852}
3853
3854/**
3855 * i40e_disallow_matching_filters - Check that new filters differ
3856 * @vsi: pointer to the targeted VSI
3857 * @input: new filter to check
3858 *
3859 * Due to hardware limitations, it is not possible for two filters that match
3860 * similar criteria to be programmed at the same time. This is true for a few
3861 * reasons:
3862 *
3863 * (a) all filters matching a particular flow type must use the same input
3864 * set, that is they must match the same criteria.
3865 * (b) different flow types will never match the same packet, as the flow type
3866 * is decided by hardware before checking which rules apply.
3867 * (c) hardware has no way to distinguish which order filters apply in.
3868 *
3869 * Due to this, we can't really support using the location data to order
3870 * filters in the hardware parsing. It is technically possible for the user to
3871 * request two filters matching the same criteria but which select different
3872 * queues. In this case, rather than keep both filters in the list, we reject
3873 * the 2nd filter when the user requests adding it.
3874 *
3875 * This avoids needing to track location for programming the filter to
3876 * hardware, and ensures that we avoid some strange scenarios involving
3877 * deleting filters which match the same criteria.
3878 **/
3879static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
3880 struct i40e_fdir_filter *input)
3881{
3882 struct i40e_pf *pf = vsi->back;
3883 struct i40e_fdir_filter *rule;
3884 struct hlist_node *node2;
3885
3886 /* Loop through every filter, and check that it doesn't match */
3887 hlist_for_each_entry_safe(rule, node2,
3888 &pf->fdir_filter_list, fdir_node) {
3889 /* Don't check the filters match if they share the same fd_id,
3890 * since the new filter is actually just updating the target
3891 * of the old filter.
3892 */
3893 if (rule->fd_id == input->fd_id)
3894 continue;
3895
3896 /* If any filters match, then print a warning message to the
3897 * kernel message buffer and bail out.
3898 */
3899 if (i40e_match_fdir_filter(rule, input)) {
3900 dev_warn(&pf->pdev->dev,
3901 "Existing user defined filter %d already matches this flow.\n",
3902 rule->fd_id);
3903 return -EINVAL;
3904 }
3905 }
3906
3907 return 0;
3908}
3909
3910/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003911 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003912 * @vsi: pointer to the targeted VSI
3913 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003914 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003915 * Add Flow Director filters for a specific flow spec based on their
3916 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003917 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003918static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3919 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003920{
Jacob Kellere7930952017-02-06 14:38:49 -08003921 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003922 struct ethtool_rx_flow_spec *fsp;
3923 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003924 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003925 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003926 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003927 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003928
3929 if (!vsi)
3930 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003931 pf = vsi->back;
3932
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003933 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3934 return -EOPNOTSUPP;
3935
Jacob Keller134201a2018-03-16 01:26:32 -07003936 if (test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003937 return -ENOSPC;
3938
Jacob Keller0da36b92017-04-19 09:25:55 -04003939 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3940 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003941 return -EBUSY;
3942
Jacob Keller0da36b92017-04-19 09:25:55 -04003943 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003944 return -EBUSY;
3945
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003946 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3947
Jacob Kellere7930952017-02-06 14:38:49 -08003948 /* Parse the user-defined field */
3949 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3950 return -EINVAL;
3951
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003952 /* Extended MAC field is not supported */
3953 if (fsp->flow_type & FLOW_MAC_EXT)
3954 return -EINVAL;
3955
Jacob Keller0e588de2017-02-06 14:38:50 -08003956 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003957 if (ret)
3958 return ret;
3959
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003960 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3961 pf->hw.func_caps.fd_filters_guaranteed)) {
3962 return -EINVAL;
3963 }
3964
Jacob Keller43b15692017-02-06 14:38:48 -08003965 /* ring_cookie is either the drop index, or is a mask of the queue
3966 * index and VF id we wish to target.
3967 */
3968 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3969 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3970 } else {
3971 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3972 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3973
3974 if (!vf) {
3975 if (ring >= vsi->num_queue_pairs)
3976 return -EINVAL;
3977 dest_vsi = vsi->id;
3978 } else {
3979 /* VFs are zero-indexed, so we subtract one here */
3980 vf--;
3981
3982 if (vf >= pf->num_alloc_vfs)
3983 return -EINVAL;
3984 if (ring >= pf->vf[vf].num_queue_pairs)
3985 return -EINVAL;
3986 dest_vsi = pf->vf[vf].lan_vsi_id;
3987 }
3988 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3989 q_index = ring;
3990 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003991
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003992 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003993
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003994 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003995 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003996
3997 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003998 input->q_index = q_index;
3999 input->dest_vsi = dest_vsi;
4000 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004001 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04004002 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08004003 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4004 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08004005 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004006 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00004007
4008 /* Reverse the src and dest notion, since the HW expects them to be from
4009 * Tx perspective where as the input from user is from Rx filter view.
4010 */
4011 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4012 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08004013 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4014 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004015
Jacob Keller0e588de2017-02-06 14:38:50 -08004016 if (userdef.flex_filter) {
4017 input->flex_filter = true;
4018 input->flex_word = cpu_to_be16(userdef.flex_word);
4019 input->flex_offset = userdef.flex_offset;
4020 }
4021
Jacob Keller443ee712017-12-27 08:25:32 -05004022 /* Avoid programming two filters with identical match criteria. */
4023 ret = i40e_disallow_matching_filters(vsi, input);
4024 if (ret)
4025 goto free_filter_memory;
4026
Jacob Keller01016da2017-02-06 14:38:40 -08004027 /* Add the input filter to the fdir_input_list, possibly replacing
4028 * a previous filter. Do not free the input structure after adding it
4029 * to the list as this would cause a use-after-free bug.
4030 */
4031 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Patryk Małekca6e1d02017-12-27 07:32:31 -05004032 ret = i40e_add_del_fdir(vsi, input, true);
4033 if (ret)
4034 goto remove_sw_rule;
Jacob Keller01016da2017-02-06 14:38:40 -08004035 return 0;
4036
Patryk Małekca6e1d02017-12-27 07:32:31 -05004037remove_sw_rule:
4038 hlist_del(&input->fdir_node);
4039 pf->fdir_pf_active_filters--;
Jacob Keller443ee712017-12-27 08:25:32 -05004040free_filter_memory:
Jacob Keller01016da2017-02-06 14:38:40 -08004041 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004042 return ret;
4043}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08004044
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004045/**
4046 * i40e_set_rxnfc - command to set RX flow classification rules
4047 * @netdev: network interface device structure
4048 * @cmd: ethtool rxnfc command
4049 *
4050 * Returns Success if the command is supported.
4051 **/
4052static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4053{
4054 struct i40e_netdev_priv *np = netdev_priv(netdev);
4055 struct i40e_vsi *vsi = np->vsi;
4056 struct i40e_pf *pf = vsi->back;
4057 int ret = -EOPNOTSUPP;
4058
4059 switch (cmd->cmd) {
4060 case ETHTOOL_SRXFH:
4061 ret = i40e_set_rss_hash_opt(pf, cmd);
4062 break;
4063 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00004064 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004065 break;
4066 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004067 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004068 break;
4069 default:
4070 break;
4071 }
4072
4073 return ret;
4074}
4075
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004076/**
4077 * i40e_max_channels - get Max number of combined channels supported
4078 * @vsi: vsi pointer
4079 **/
4080static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4081{
4082 /* TODO: This code assumes DCB and FD is disabled for now. */
4083 return vsi->alloc_queue_pairs;
4084}
4085
4086/**
4087 * i40e_get_channels - Get the current channels enabled and max supported etc.
Jacob Kellerf5254422018-04-20 01:41:33 -07004088 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004089 * @ch: ethtool channels structure
4090 *
4091 * We don't support separate tx and rx queues as channels. The other count
4092 * represents how many queues are being used for control. max_combined counts
4093 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4094 * q_vectors since we support a lot more queue pairs than q_vectors.
4095 **/
4096static void i40e_get_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004097 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004098{
4099 struct i40e_netdev_priv *np = netdev_priv(dev);
4100 struct i40e_vsi *vsi = np->vsi;
4101 struct i40e_pf *pf = vsi->back;
4102
4103 /* report maximum channels */
4104 ch->max_combined = i40e_max_channels(vsi);
4105
4106 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004107 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004108 ch->max_other = ch->other_count;
4109
4110 /* Note: This code assumes DCB is disabled for now. */
4111 ch->combined_count = vsi->num_queue_pairs;
4112}
4113
4114/**
4115 * i40e_set_channels - Set the new channels count.
Jacob Kellerf5254422018-04-20 01:41:33 -07004116 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004117 * @ch: ethtool channels structure
4118 *
4119 * The new channels count may not be the same as requested by the user
4120 * since it gets rounded down to a power of 2 value.
4121 **/
4122static int i40e_set_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004123 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004124{
Jacob Keller59826d92016-07-27 12:02:35 -07004125 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004126 struct i40e_netdev_priv *np = netdev_priv(dev);
4127 unsigned int count = ch->combined_count;
4128 struct i40e_vsi *vsi = np->vsi;
4129 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004130 struct i40e_fdir_filter *rule;
4131 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004132 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004133 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004134
4135 /* We do not support setting channels for any other VSI at present */
4136 if (vsi->type != I40E_VSI_MAIN)
4137 return -EINVAL;
4138
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004139 /* We do not support setting channels via ethtool when TCs are
4140 * configured through mqprio
4141 */
4142 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4143 return -EINVAL;
4144
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004145 /* verify they are not requesting separate vectors */
4146 if (!count || ch->rx_count || ch->tx_count)
4147 return -EINVAL;
4148
4149 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004150 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004151 return -EINVAL;
4152
4153 /* verify the number of channels does not exceed hardware limits */
4154 if (count > i40e_max_channels(vsi))
4155 return -EINVAL;
4156
Jacob Keller59826d92016-07-27 12:02:35 -07004157 /* verify that the number of channels does not invalidate any current
4158 * flow director rules
4159 */
4160 hlist_for_each_entry_safe(rule, node2,
4161 &pf->fdir_filter_list, fdir_node) {
4162 if (rule->dest_ctl != drop && count <= rule->q_index) {
4163 dev_warn(&pf->pdev->dev,
4164 "Existing user defined filter %d assigns flow to queue %d\n",
4165 rule->fd_id, rule->q_index);
4166 err = -EINVAL;
4167 }
4168 }
4169
4170 if (err) {
4171 dev_err(&pf->pdev->dev,
4172 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4173 count);
4174 return err;
4175 }
4176
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004177 /* update feature limits from largest to smallest supported values */
4178 /* TODO: Flow director limit, DCB etc */
4179
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004180 /* use rss_reconfig to rebuild with new queue count and update traffic
4181 * class queue mapping
4182 */
4183 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004184 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004185 return 0;
4186 else
4187 return -EINVAL;
4188}
4189
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004190/**
4191 * i40e_get_rxfh_key_size - get the RSS hash key size
4192 * @netdev: network interface device structure
4193 *
4194 * Returns the table size.
4195 **/
4196static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4197{
4198 return I40E_HKEY_ARRAY_SIZE;
4199}
4200
4201/**
4202 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4203 * @netdev: network interface device structure
4204 *
4205 * Returns the table size.
4206 **/
4207static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4208{
4209 return I40E_HLUT_ARRAY_SIZE;
4210}
4211
Alan Brady21675bd2017-10-05 14:53:33 -07004212/**
4213 * i40e_get_rxfh - get the rx flow hash indirection table
4214 * @netdev: network interface device structure
4215 * @indir: indirection table
4216 * @key: hash key
4217 * @hfunc: hash function
4218 *
4219 * Reads the indirection table directly from the hardware. Returns 0 on
4220 * success.
4221 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004222static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4223 u8 *hfunc)
4224{
4225 struct i40e_netdev_priv *np = netdev_priv(netdev);
4226 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004227 u8 *lut, *seed = NULL;
4228 int ret;
4229 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004230
4231 if (hfunc)
4232 *hfunc = ETH_RSS_HASH_TOP;
4233
4234 if (!indir)
4235 return 0;
4236
Helin Zhang043dd652015-10-21 19:56:23 -04004237 seed = key;
4238 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4239 if (!lut)
4240 return -ENOMEM;
4241 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4242 if (ret)
4243 goto out;
4244 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4245 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004246
Helin Zhang043dd652015-10-21 19:56:23 -04004247out:
4248 kfree(lut);
4249
4250 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004251}
4252
4253/**
4254 * i40e_set_rxfh - set the rx flow hash indirection table
4255 * @netdev: network interface device structure
4256 * @indir: indirection table
4257 * @key: hash key
Jacob Kellerf5254422018-04-20 01:41:33 -07004258 * @hfunc: hash function to use
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004259 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004260 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004261 * returns 0 after programming the table.
4262 **/
4263static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4264 const u8 *key, const u8 hfunc)
4265{
4266 struct i40e_netdev_priv *np = netdev_priv(netdev);
4267 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004268 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004269 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004270 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004271
4272 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4273 return -EOPNOTSUPP;
4274
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004275 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004276 if (!vsi->rss_hkey_user) {
4277 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4278 GFP_KERNEL);
4279 if (!vsi->rss_hkey_user)
4280 return -ENOMEM;
4281 }
4282 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4283 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004284 }
Helin Zhang28c58692015-10-26 19:44:27 -04004285 if (!vsi->rss_lut_user) {
4286 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4287 if (!vsi->rss_lut_user)
4288 return -ENOMEM;
4289 }
Helin Zhang043dd652015-10-21 19:56:23 -04004290
Helin Zhang28c58692015-10-26 19:44:27 -04004291 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004292 if (indir)
4293 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4294 vsi->rss_lut_user[i] = (u8)(indir[i]);
4295 else
4296 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4297 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004298
4299 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4300 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004301}
4302
Greg Rose7e45ab42015-02-06 08:52:19 +00004303/**
4304 * i40e_get_priv_flags - report device private flags
4305 * @dev: network interface device structure
4306 *
4307 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004308 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004309 * array.
4310 *
4311 * Returns a u32 bitmap of flags.
4312 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004313static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004314{
4315 struct i40e_netdev_priv *np = netdev_priv(dev);
4316 struct i40e_vsi *vsi = np->vsi;
4317 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004318 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004319
Alexander Duyckaca955d2017-03-10 12:22:01 -08004320 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4321 const struct i40e_priv_flags *priv_flags;
4322
4323 priv_flags = &i40e_gstrings_priv_flags[i];
4324
4325 if (priv_flags->flag & pf->flags)
4326 ret_flags |= BIT(i);
4327 }
4328
4329 if (pf->hw.pf_id != 0)
4330 return ret_flags;
4331
4332 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4333 const struct i40e_priv_flags *priv_flags;
4334
4335 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4336
4337 if (priv_flags->flag & pf->flags)
4338 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004339 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004340
4341 return ret_flags;
4342}
4343
Shannon Nelson9ac77262015-08-27 11:42:40 -04004344/**
4345 * i40e_set_priv_flags - set private flags
4346 * @dev: network interface device structure
4347 * @flags: bit flags to be set
4348 **/
4349static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4350{
4351 struct i40e_netdev_priv *np = netdev_priv(dev);
4352 struct i40e_vsi *vsi = np->vsi;
4353 struct i40e_pf *pf = vsi->back;
Alice Michael60f481b2017-12-27 08:17:50 -05004354 u64 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004355 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004356
Jacob Keller841c9502017-06-23 04:24:50 -04004357 orig_flags = READ_ONCE(pf->flags);
4358 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004359
Alexander Duyckaca955d2017-03-10 12:22:01 -08004360 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4361 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004362
Alexander Duyckaca955d2017-03-10 12:22:01 -08004363 priv_flags = &i40e_gstrings_priv_flags[i];
4364
Alexander Duyckaca955d2017-03-10 12:22:01 -08004365 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004366 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004367 else
Jacob Keller841c9502017-06-23 04:24:50 -04004368 new_flags &= ~(priv_flags->flag);
4369
4370 /* If this is a read-only flag, it can't be changed */
4371 if (priv_flags->read_only &&
4372 ((orig_flags ^ new_flags) & ~BIT(i)))
4373 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004374 }
4375
4376 if (pf->hw.pf_id != 0)
4377 goto flags_complete;
4378
4379 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4380 const struct i40e_priv_flags *priv_flags;
4381
4382 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4383
Alexander Duyckaca955d2017-03-10 12:22:01 -08004384 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004385 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004386 else
Jacob Keller841c9502017-06-23 04:24:50 -04004387 new_flags &= ~(priv_flags->flag);
4388
4389 /* If this is a read-only flag, it can't be changed */
4390 if (priv_flags->read_only &&
4391 ((orig_flags ^ new_flags) & ~BIT(i)))
4392 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004393 }
4394
4395flags_complete:
Alan Bradyfe09ed02017-12-29 08:50:34 -05004396 changed_flags = orig_flags ^ new_flags;
4397
Jacob Keller841c9502017-06-23 04:24:50 -04004398 /* Before we finalize any flag changes, we need to perform some
4399 * checks to ensure that the changes are supported and safe.
4400 */
4401
4402 /* ATR eviction is not supported on all devices */
4403 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4404 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4405 return -EOPNOTSUPP;
4406
Alan Bradyfe09ed02017-12-29 08:50:34 -05004407 /* If the driver detected FW LLDP was disabled on init, this flag could
4408 * be set, however we do not support _changing_ the flag if NPAR is
4409 * enabled or FW API version < 1.7. There are situations where older
4410 * FW versions/NPAR enabled PFs could disable LLDP, however we _must_
4411 * not allow the user to enable/disable LLDP with this flag on
4412 * unsupported FW versions.
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004413 */
Alan Bradyfe09ed02017-12-29 08:50:34 -05004414 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
Dave Ertman7b634352018-01-22 12:00:37 -05004415 if (!(pf->hw_features & I40E_HW_STOPPABLE_FW_LLDP)) {
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004416 dev_warn(&pf->pdev->dev,
Dave Ertman7b634352018-01-22 12:00:37 -05004417 "Device does not support changing FW LLDP\n");
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004418 return -EOPNOTSUPP;
4419 }
4420 }
4421
Jacob Keller886ff142018-03-16 01:26:36 -07004422 /* Now that we've checked to ensure that the new flags are valid, load
4423 * them into place. Since we only modify flags either (a) during
4424 * initialization or (b) while holding the RTNL lock, we don't need
4425 * anything fancy here.
Jacob Keller841c9502017-06-23 04:24:50 -04004426 */
Jacob Keller886ff142018-03-16 01:26:36 -07004427 pf->flags = new_flags;
Jacob Keller841c9502017-06-23 04:24:50 -04004428
Alexander Duyckaca955d2017-03-10 12:22:01 -08004429 /* Process any additional changes needed as a result of flag changes.
4430 * The changed_flags value reflects the list of bits that were
4431 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004432 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004433
Alexander Duyckaca955d2017-03-10 12:22:01 -08004434 /* Flush current ATR settings if ATR was disabled */
4435 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4436 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller134201a2018-03-16 01:26:32 -07004437 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
Jacob Keller0da36b92017-04-19 09:25:55 -04004438 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004439 }
4440
Alexander Duyckaca955d2017-03-10 12:22:01 -08004441 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4442 u16 sw_flags = 0, valid_flags = 0;
4443 int ret;
4444
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004445 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4446 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4447 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4448 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07004449 0, NULL);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004450 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4451 dev_info(&pf->pdev->dev,
4452 "couldn't set switch config bits, err %s aq_err %s\n",
4453 i40e_stat_str(&pf->hw, ret),
4454 i40e_aq_str(&pf->hw,
4455 pf->hw.aq.asq_last_status));
4456 /* not a fatal problem, just keep going */
4457 }
4458 }
4459
Paweł Jabłoński17b4d252017-12-29 08:50:20 -05004460 if ((changed_flags & pf->flags &
4461 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4462 (pf->flags & I40E_FLAG_MFP_ENABLED))
4463 dev_warn(&pf->pdev->dev,
4464 "Turning on link-down-on-close flag may affect other partitions\n");
4465
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004466 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4467 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4468 struct i40e_dcbx_config *dcbcfg;
4469 int i;
4470
4471 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4472 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4473 /* reset local_dcbx_config to default */
4474 dcbcfg = &pf->hw.local_dcbx_config;
4475 dcbcfg->etscfg.willing = 1;
4476 dcbcfg->etscfg.maxtcs = 0;
4477 dcbcfg->etscfg.tcbwtable[0] = 100;
4478 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4479 dcbcfg->etscfg.tcbwtable[i] = 0;
4480 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4481 dcbcfg->etscfg.prioritytable[i] = 0;
4482 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4483 dcbcfg->pfc.willing = 1;
4484 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4485 } else {
4486 i40e_aq_start_lldp(&pf->hw, NULL);
4487 }
4488 }
4489
Alexander Duyckaca955d2017-03-10 12:22:01 -08004490 /* Issue reset to cause things to take effect, as additional bits
4491 * are added we will need to create a mask of bits requiring reset
4492 */
Mitch Williams64615b52017-08-29 05:32:30 -04004493 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4494 I40E_FLAG_LEGACY_RX |
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004495 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4496 I40E_FLAG_DISABLE_FW_LLDP))
Maciej Sosin373149f2017-04-05 07:50:55 -04004497 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004498
Shannon Nelson9ac77262015-08-27 11:42:40 -04004499 return 0;
4500}
4501
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004502/**
4503 * i40e_get_module_info - get (Q)SFP+ module type info
4504 * @netdev: network interface device structure
4505 * @modinfo: module EEPROM size and layout information structure
4506 **/
4507static int i40e_get_module_info(struct net_device *netdev,
4508 struct ethtool_modinfo *modinfo)
4509{
4510 struct i40e_netdev_priv *np = netdev_priv(netdev);
4511 struct i40e_vsi *vsi = np->vsi;
4512 struct i40e_pf *pf = vsi->back;
4513 struct i40e_hw *hw = &pf->hw;
4514 u32 sff8472_comp = 0;
4515 u32 sff8472_swap = 0;
4516 u32 sff8636_rev = 0;
4517 i40e_status status;
4518 u32 type = 0;
4519
4520 /* Check if firmware supports reading module EEPROM. */
4521 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4522 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4523 return -EINVAL;
4524 }
4525
4526 status = i40e_update_link_info(hw);
4527 if (status)
4528 return -EIO;
4529
4530 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4531 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4532 return -EINVAL;
4533 }
4534
4535 type = hw->phy.link_info.module_type[0];
4536
4537 switch (type) {
4538 case I40E_MODULE_TYPE_SFP:
4539 status = i40e_aq_get_phy_register(hw,
4540 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4541 I40E_I2C_EEPROM_DEV_ADDR,
4542 I40E_MODULE_SFF_8472_COMP,
4543 &sff8472_comp, NULL);
4544 if (status)
4545 return -EIO;
4546
4547 status = i40e_aq_get_phy_register(hw,
4548 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4549 I40E_I2C_EEPROM_DEV_ADDR,
4550 I40E_MODULE_SFF_8472_SWAP,
4551 &sff8472_swap, NULL);
4552 if (status)
4553 return -EIO;
4554
4555 /* Check if the module requires address swap to access
4556 * the other EEPROM memory page.
4557 */
4558 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4559 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4560 modinfo->type = ETH_MODULE_SFF_8079;
4561 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4562 } else if (sff8472_comp == 0x00) {
4563 /* Module is not SFF-8472 compliant */
4564 modinfo->type = ETH_MODULE_SFF_8079;
4565 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4566 } else {
4567 modinfo->type = ETH_MODULE_SFF_8472;
4568 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4569 }
4570 break;
4571 case I40E_MODULE_TYPE_QSFP_PLUS:
4572 /* Read from memory page 0. */
4573 status = i40e_aq_get_phy_register(hw,
4574 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4575 0,
4576 I40E_MODULE_REVISION_ADDR,
4577 &sff8636_rev, NULL);
4578 if (status)
4579 return -EIO;
4580 /* Determine revision compliance byte */
4581 if (sff8636_rev > 0x02) {
4582 /* Module is SFF-8636 compliant */
4583 modinfo->type = ETH_MODULE_SFF_8636;
4584 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4585 } else {
4586 modinfo->type = ETH_MODULE_SFF_8436;
4587 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4588 }
4589 break;
4590 case I40E_MODULE_TYPE_QSFP28:
4591 modinfo->type = ETH_MODULE_SFF_8636;
4592 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4593 break;
4594 default:
4595 netdev_err(vsi->netdev, "Module type unrecognized\n");
4596 return -EINVAL;
4597 }
4598 return 0;
4599}
4600
4601/**
4602 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4603 * @netdev: network interface device structure
4604 * @ee: EEPROM dump request structure
4605 * @data: buffer to be filled with EEPROM contents
4606 **/
4607static int i40e_get_module_eeprom(struct net_device *netdev,
4608 struct ethtool_eeprom *ee,
4609 u8 *data)
4610{
4611 struct i40e_netdev_priv *np = netdev_priv(netdev);
4612 struct i40e_vsi *vsi = np->vsi;
4613 struct i40e_pf *pf = vsi->back;
4614 struct i40e_hw *hw = &pf->hw;
4615 bool is_sfp = false;
4616 i40e_status status;
4617 u32 value = 0;
4618 int i;
4619
4620 if (!ee || !ee->len || !data)
4621 return -EINVAL;
4622
4623 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4624 is_sfp = true;
4625
4626 for (i = 0; i < ee->len; i++) {
4627 u32 offset = i + ee->offset;
4628 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4629
4630 /* Check if we need to access the other memory page */
4631 if (is_sfp) {
4632 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4633 offset -= ETH_MODULE_SFF_8079_LEN;
4634 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4635 }
4636 } else {
4637 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4638 /* Compute memory page number and offset. */
4639 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4640 addr++;
4641 }
4642 }
4643
4644 status = i40e_aq_get_phy_register(hw,
4645 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4646 addr, offset, &value, NULL);
4647 if (status)
4648 return -EIO;
4649 data[i] = value;
4650 }
4651 return 0;
4652}
4653
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004654static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004655 .get_drvinfo = i40e_get_drvinfo,
4656 .get_regs_len = i40e_get_regs_len,
4657 .get_regs = i40e_get_regs,
4658 .nway_reset = i40e_nway_reset,
4659 .get_link = ethtool_op_get_link,
4660 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004661 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004662 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004663 .get_eeprom_len = i40e_get_eeprom_len,
4664 .get_eeprom = i40e_get_eeprom,
4665 .get_ringparam = i40e_get_ringparam,
4666 .set_ringparam = i40e_set_ringparam,
4667 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004668 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004669 .get_msglevel = i40e_get_msglevel,
4670 .set_msglevel = i40e_set_msglevel,
4671 .get_rxnfc = i40e_get_rxnfc,
4672 .set_rxnfc = i40e_set_rxnfc,
4673 .self_test = i40e_diag_test,
4674 .get_strings = i40e_get_strings,
4675 .set_phys_id = i40e_set_phys_id,
4676 .get_sset_count = i40e_get_sset_count,
4677 .get_ethtool_stats = i40e_get_ethtool_stats,
4678 .get_coalesce = i40e_get_coalesce,
4679 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004680 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4681 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4682 .get_rxfh = i40e_get_rxfh,
4683 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004684 .get_channels = i40e_get_channels,
4685 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004686 .get_module_info = i40e_get_module_info,
4687 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004688 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004689 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004690 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004691 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004692 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004693 .get_link_ksettings = i40e_get_link_ksettings,
4694 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004695};
4696
4697void i40e_set_ethtool_ops(struct net_device *netdev)
4698{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004699 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004700}