blob: 89807e32a8983e587a1a4c67a7ad51460ca0668b [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Shannon Nelson66fc3602016-01-13 16:51:42 -08004 * Copyright(c) 2013 - 2016 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040091 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080092 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
93 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000094};
95
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096/* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
102 *
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
105 */
Joe Perchesfe180a52016-09-26 20:17:01 -0700106static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
Alice Michaeldbd668e2017-10-27 11:06:48 -0400129 I40E_PF_STAT("priority_xon_rx", stats.priority_xon_rx),
130 I40E_PF_STAT("priority_xoff_rx", stats.priority_xoff_rx),
131 I40E_PF_STAT("priority_xon_tx", stats.priority_xon_tx),
132 I40E_PF_STAT("priority_xoff_tx", stats.priority_xoff_tx),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000133 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
134 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
135 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
136 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
137 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
138 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
139 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
140 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
141 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
142 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
143 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
144 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
145 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
146 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
147 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
148 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
149 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
150 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
151 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800152 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000153 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jacob Keller2955fac2017-05-03 10:28:58 -0700154 I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000155 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000156 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400157 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400158 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000159 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400160 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000161
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000162 /* LPI stats */
163 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
164 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
165 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
166 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000167};
168
169#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000170 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
171 * 2 /* Tx and Rx together */ \
172 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000173#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
174#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000175#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000177 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000178 I40E_QUEUE_STATS_LEN((n)))
179#define I40E_PFC_STATS_LEN ( \
180 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
181 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
182 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
183 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
184 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
185 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400186#define I40E_VEB_TC_STATS_LEN ( \
187 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
188 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
189 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
190 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
191 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000192#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400193#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
195 I40E_PFC_STATS_LEN + \
196 I40E_VSI_STATS_LEN((n)))
197
198enum i40e_ethtool_test_id {
199 I40E_ETH_TEST_REG = 0,
200 I40E_ETH_TEST_EEPROM,
201 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000202 I40E_ETH_TEST_LINK,
203};
204
205static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
206 "Register test (offline)",
207 "Eeprom test (offline)",
208 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000209 "Link test (on/offline)"
210};
211
212#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
213
Alexander Duyckaca955d2017-03-10 12:22:01 -0800214struct i40e_priv_flags {
215 char flag_string[ETH_GSTRING_LEN];
216 u64 flag;
217 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000218};
219
Alexander Duyckaca955d2017-03-10 12:22:01 -0800220#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
221 .flag_string = _name, \
222 .flag = _flag, \
223 .read_only = _read_only, \
224}
225
226static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
227 /* NOTE: MFP setting cannot be changed */
228 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
229 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
230 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
231 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700232 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Mariusz Stachurac3880bd2017-11-14 07:00:50 -0500233 I40E_PRIV_FLAG("link-down-on-close",
234 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700235 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400236 I40E_PRIV_FLAG("disable-source-pruning",
237 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Dave Ertmanc61c8fe2017-12-27 08:18:21 -0500238 I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800239};
240
241#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000242
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700243/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800244static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
245 I40E_PRIV_FLAG("vf-true-promisc-support",
246 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700247};
248
Alexander Duyckaca955d2017-03-10 12:22:01 -0800249#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700250
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000252 * i40e_partition_setting_complaint - generic complaint for MFP restriction
253 * @pf: the PF struct
254 **/
255static void i40e_partition_setting_complaint(struct i40e_pf *pf)
256{
257 dev_info(&pf->pdev->dev,
258 "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");
259}
260
261/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700262 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
Alan Brady52e2d022017-10-05 14:53:35 -0700263 * @pf: PF struct with phy_types
Alan Brady1eaae512017-10-05 14:53:41 -0700264 * @ks: ethtool link ksettings struct to fill out
Catherine Sullivan06566e52016-05-03 15:13:14 -0700265 *
266 **/
Alan Brady1eaae512017-10-05 14:53:41 -0700267static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
268 struct ethtool_link_ksettings *ks)
Catherine Sullivan06566e52016-05-03 15:13:14 -0700269{
Avinash Dayanand28537042016-06-20 09:10:33 -0700270 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800271 u64 phy_types = pf->hw.phy.phy_types;
272
Alan Brady1eaae512017-10-05 14:53:41 -0700273 ethtool_link_ksettings_zero_link_mode(ks, supported);
274 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700275
276 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
Alan Brady1eaae512017-10-05 14:53:41 -0700277 ethtool_link_ksettings_add_link_mode(ks, supported,
278 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700279 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700280 ethtool_link_ksettings_add_link_mode(ks, advertising,
281 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400282 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady1eaae512017-10-05 14:53:41 -0700283 ethtool_link_ksettings_add_link_mode(ks, supported,
284 100baseT_Full);
285 ethtool_link_ksettings_add_link_mode(ks, advertising,
286 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700287 }
288 }
289 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
290 phy_types & I40E_CAP_PHY_TYPE_XFI ||
291 phy_types & I40E_CAP_PHY_TYPE_SFI ||
292 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
Alan Brady1eaae512017-10-05 14:53:41 -0700293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
294 ethtool_link_ksettings_add_link_mode(ks, supported,
295 10000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700296 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700297 ethtool_link_ksettings_add_link_mode(ks, advertising,
298 10000baseT_Full);
299 }
300 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
301 ethtool_link_ksettings_add_link_mode(ks, supported,
302 10000baseT_Full);
303 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
304 ethtool_link_ksettings_add_link_mode(ks, advertising,
305 10000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700306 }
307 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
308 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
309 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
Alan Brady1eaae512017-10-05 14:53:41 -0700310 ethtool_link_ksettings_add_link_mode(ks, supported,
311 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700312 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
313 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700314 ethtool_link_ksettings_add_link_mode(ks, supported,
315 40000baseCR4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700316 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700317 ethtool_link_ksettings_add_link_mode(ks, advertising,
318 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700319 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700320 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700321 ethtool_link_ksettings_add_link_mode(ks, supported,
322 100baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady1eaae512017-10-05 14:53:41 -0700324 ethtool_link_ksettings_add_link_mode(ks, advertising,
325 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700326 }
Alan Brady1eaae512017-10-05 14:53:41 -0700327 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
328 ethtool_link_ksettings_add_link_mode(ks, supported,
329 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700330 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700331 ethtool_link_ksettings_add_link_mode(ks, advertising,
332 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700333 }
334 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700335 ethtool_link_ksettings_add_link_mode(ks, supported,
336 40000baseSR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700337 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700338 ethtool_link_ksettings_add_link_mode(ks, supported,
339 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700340 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700341 ethtool_link_ksettings_add_link_mode(ks, supported,
342 40000baseLR4_Full);
343 ethtool_link_ksettings_add_link_mode(ks, advertising,
344 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700345 }
346 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
Alan Brady1eaae512017-10-05 14:53:41 -0700347 ethtool_link_ksettings_add_link_mode(ks, supported,
348 20000baseKR2_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700349 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700350 ethtool_link_ksettings_add_link_mode(ks, advertising,
351 20000baseKR2_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700352 }
353 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700354 ethtool_link_ksettings_add_link_mode(ks, supported,
355 10000baseKX4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700356 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700357 ethtool_link_ksettings_add_link_mode(ks, advertising,
358 10000baseKX4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700359 }
Alan Brady6987bd252017-10-05 14:53:38 -0700360 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
361 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700362 ethtool_link_ksettings_add_link_mode(ks, supported,
363 10000baseKR_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700364 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700365 ethtool_link_ksettings_add_link_mode(ks, advertising,
366 10000baseKR_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700367 }
Alan Brady6987bd252017-10-05 14:53:38 -0700368 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
369 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700370 ethtool_link_ksettings_add_link_mode(ks, supported,
371 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700372 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700373 ethtool_link_ksettings_add_link_mode(ks, advertising,
374 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700375 }
Alan Brady1eaae512017-10-05 14:53:41 -0700376 /* need to add 25G PHY types */
377 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
378 ethtool_link_ksettings_add_link_mode(ks, supported,
379 25000baseKR_Full);
380 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
381 ethtool_link_ksettings_add_link_mode(ks, advertising,
382 25000baseKR_Full);
383 }
384 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
385 ethtool_link_ksettings_add_link_mode(ks, supported,
386 25000baseCR_Full);
387 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
388 ethtool_link_ksettings_add_link_mode(ks, advertising,
389 25000baseCR_Full);
390 }
391 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800392 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
Alan Brady1eaae512017-10-05 14:53:41 -0700393 ethtool_link_ksettings_add_link_mode(ks, supported,
394 25000baseSR_Full);
395 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
396 ethtool_link_ksettings_add_link_mode(ks, advertising,
397 25000baseSR_Full);
398 }
399 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
400 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
401 ethtool_link_ksettings_add_link_mode(ks, supported,
402 25000baseCR_Full);
403 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
404 ethtool_link_ksettings_add_link_mode(ks, advertising,
405 25000baseCR_Full);
406 }
407 /* need to add new 10G PHY types */
408 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
409 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
410 ethtool_link_ksettings_add_link_mode(ks, supported,
411 10000baseCR_Full);
412 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
413 ethtool_link_ksettings_add_link_mode(ks, advertising,
414 10000baseCR_Full);
415 }
416 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
417 ethtool_link_ksettings_add_link_mode(ks, supported,
418 10000baseSR_Full);
419 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
420 ethtool_link_ksettings_add_link_mode(ks, advertising,
421 10000baseSR_Full);
422 }
423 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
424 ethtool_link_ksettings_add_link_mode(ks, supported,
425 10000baseLR_Full);
426 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
427 ethtool_link_ksettings_add_link_mode(ks, advertising,
428 10000baseLR_Full);
429 }
430 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
431 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
432 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
433 ethtool_link_ksettings_add_link_mode(ks, supported,
434 1000baseX_Full);
435 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
436 ethtool_link_ksettings_add_link_mode(ks, advertising,
437 1000baseX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700438 }
439 /* Autoneg PHY types */
440 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
441 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
442 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
443 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800444 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700445 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
446 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
447 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
448 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
449 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
450 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
451 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
452 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
453 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
454 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
455 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
456 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
457 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
458 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
459 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
460 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
461 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700462 ethtool_link_ksettings_add_link_mode(ks, supported,
463 Autoneg);
464 ethtool_link_ksettings_add_link_mode(ks, advertising,
465 Autoneg);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800466 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700467}
468
469/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000470 * i40e_get_settings_link_up - Get the Link settings for when link is up
471 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700472 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000473 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700474 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000475 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000476static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700477 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400478 struct net_device *netdev,
479 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000480{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000481 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Alan Brady1eaae512017-10-05 14:53:41 -0700482 struct ethtool_link_ksettings cap_ksettings;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 u32 link_speed = hw_link_info->link_speed;
484
Catherine Sullivane8278452015-02-06 08:52:08 +0000485 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000486 switch (hw_link_info->phy_type) {
487 case I40E_PHY_TYPE_40GBASE_CR4:
488 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Alan Brady79f04a32017-10-05 14:53:42 -0700489 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
490 ethtool_link_ksettings_add_link_mode(ks, supported,
491 40000baseCR4_Full);
492 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
493 ethtool_link_ksettings_add_link_mode(ks, advertising,
494 40000baseCR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000495 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000496 case I40E_PHY_TYPE_XLAUI:
497 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000498 case I40E_PHY_TYPE_40GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700499 ethtool_link_ksettings_add_link_mode(ks, supported,
500 40000baseCR4_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000501 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000502 case I40E_PHY_TYPE_40GBASE_SR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700503 ethtool_link_ksettings_add_link_mode(ks, supported,
504 40000baseSR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000505 break;
506 case I40E_PHY_TYPE_40GBASE_LR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700507 ethtool_link_ksettings_add_link_mode(ks, supported,
508 40000baseLR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000509 break;
Alan Brady79f04a32017-10-05 14:53:42 -0700510 case I40E_PHY_TYPE_25GBASE_SR:
511 case I40E_PHY_TYPE_25GBASE_LR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000512 case I40E_PHY_TYPE_10GBASE_SR:
513 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000514 case I40E_PHY_TYPE_1000BASE_SX:
515 case I40E_PHY_TYPE_1000BASE_LX:
Alan Brady79f04a32017-10-05 14:53:42 -0700516 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
517 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
518 ethtool_link_ksettings_add_link_mode(ks, supported,
519 25000baseSR_Full);
520 ethtool_link_ksettings_add_link_mode(ks, advertising,
521 25000baseSR_Full);
522 ethtool_link_ksettings_add_link_mode(ks, supported,
523 10000baseSR_Full);
524 ethtool_link_ksettings_add_link_mode(ks, advertising,
525 10000baseSR_Full);
526 ethtool_link_ksettings_add_link_mode(ks, supported,
527 10000baseLR_Full);
528 ethtool_link_ksettings_add_link_mode(ks, advertising,
529 10000baseLR_Full);
530 ethtool_link_ksettings_add_link_mode(ks, supported,
531 1000baseX_Full);
532 ethtool_link_ksettings_add_link_mode(ks, advertising,
533 1000baseX_Full);
534 ethtool_link_ksettings_add_link_mode(ks, supported,
535 10000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400536 if (hw_link_info->module_type[2] &
537 I40E_MODULE_TYPE_1000BASE_SX ||
538 hw_link_info->module_type[2] &
539 I40E_MODULE_TYPE_1000BASE_LX) {
Alan Brady79f04a32017-10-05 14:53:42 -0700540 ethtool_link_ksettings_add_link_mode(ks, supported,
541 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400542 if (hw_link_info->requested_speeds &
543 I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700544 ethtool_link_ksettings_add_link_mode(
545 ks, advertising, 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400546 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000547 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700548 ethtool_link_ksettings_add_link_mode(ks, advertising,
549 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000550 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000551 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000552 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700553 case I40E_PHY_TYPE_100BASE_TX:
Alan Brady79f04a32017-10-05 14:53:42 -0700554 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
555 ethtool_link_ksettings_add_link_mode(ks, supported,
556 10000baseT_Full);
557 ethtool_link_ksettings_add_link_mode(ks, supported,
558 1000baseT_Full);
559 ethtool_link_ksettings_add_link_mode(ks, supported,
560 100baseT_Full);
561 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivane8278452015-02-06 08:52:08 +0000562 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700563 ethtool_link_ksettings_add_link_mode(ks, advertising,
564 10000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000565 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700566 ethtool_link_ksettings_add_link_mode(ks, advertising,
567 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700568 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700569 ethtool_link_ksettings_add_link_mode(ks, advertising,
570 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400571 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400572 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Alan Brady79f04a32017-10-05 14:53:42 -0700573 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
574 ethtool_link_ksettings_add_link_mode(ks, supported,
575 1000baseT_Full);
576 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
577 ethtool_link_ksettings_add_link_mode(ks, advertising,
578 1000baseT_Full);
Catherine Sullivan48becae2015-09-28 14:12:41 -0400579 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000580 case I40E_PHY_TYPE_10GBASE_CR1_CU:
581 case I40E_PHY_TYPE_10GBASE_CR1:
Alan Brady79f04a32017-10-05 14:53:42 -0700582 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
583 ethtool_link_ksettings_add_link_mode(ks, supported,
584 10000baseT_Full);
585 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
586 ethtool_link_ksettings_add_link_mode(ks, advertising,
587 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000588 break;
589 case I40E_PHY_TYPE_XAUI:
590 case I40E_PHY_TYPE_XFI:
591 case I40E_PHY_TYPE_SFI:
592 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000593 case I40E_PHY_TYPE_10GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700594 ethtool_link_ksettings_add_link_mode(ks, supported,
595 10000baseT_Full);
596 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
597 ethtool_link_ksettings_add_link_mode(ks, advertising,
598 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000599 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000600 case I40E_PHY_TYPE_SGMII:
Alan Brady79f04a32017-10-05 14:53:42 -0700601 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
602 ethtool_link_ksettings_add_link_mode(ks, supported,
603 1000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000604 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700605 ethtool_link_ksettings_add_link_mode(ks, advertising,
606 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400607 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady79f04a32017-10-05 14:53:42 -0700608 ethtool_link_ksettings_add_link_mode(ks, supported,
609 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400610 if (hw_link_info->requested_speeds &
611 I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700612 ethtool_link_ksettings_add_link_mode(
613 ks, advertising, 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400614 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000615 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400616 case I40E_PHY_TYPE_40GBASE_KR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700617 case I40E_PHY_TYPE_25GBASE_KR:
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400618 case I40E_PHY_TYPE_20GBASE_KR2:
619 case I40E_PHY_TYPE_10GBASE_KR:
620 case I40E_PHY_TYPE_10GBASE_KX4:
621 case I40E_PHY_TYPE_1000BASE_KX:
Alan Brady79f04a32017-10-05 14:53:42 -0700622 ethtool_link_ksettings_add_link_mode(ks, supported,
623 40000baseKR4_Full);
624 ethtool_link_ksettings_add_link_mode(ks, supported,
625 25000baseKR_Full);
626 ethtool_link_ksettings_add_link_mode(ks, supported,
627 20000baseKR2_Full);
628 ethtool_link_ksettings_add_link_mode(ks, supported,
629 10000baseKR_Full);
630 ethtool_link_ksettings_add_link_mode(ks, supported,
631 10000baseKX4_Full);
632 ethtool_link_ksettings_add_link_mode(ks, supported,
633 1000baseKX_Full);
634 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
635 ethtool_link_ksettings_add_link_mode(ks, advertising,
636 40000baseKR4_Full);
637 ethtool_link_ksettings_add_link_mode(ks, advertising,
638 25000baseKR_Full);
639 ethtool_link_ksettings_add_link_mode(ks, advertising,
640 20000baseKR2_Full);
641 ethtool_link_ksettings_add_link_mode(ks, advertising,
642 10000baseKR_Full);
643 ethtool_link_ksettings_add_link_mode(ks, advertising,
644 10000baseKX4_Full);
645 ethtool_link_ksettings_add_link_mode(ks, advertising,
646 1000baseKX_Full);
647 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400648 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800649 case I40E_PHY_TYPE_25GBASE_CR:
Alan Brady79f04a32017-10-05 14:53:42 -0700650 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
651 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
652 ethtool_link_ksettings_add_link_mode(ks, supported,
653 25000baseCR_Full);
654 ethtool_link_ksettings_add_link_mode(ks, advertising,
655 25000baseCR_Full);
656 break;
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700657 case I40E_PHY_TYPE_25GBASE_AOC:
658 case I40E_PHY_TYPE_25GBASE_ACC:
Alan Brady79f04a32017-10-05 14:53:42 -0700659 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
660 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
661 ethtool_link_ksettings_add_link_mode(ks, supported,
662 25000baseCR_Full);
663
664 ethtool_link_ksettings_add_link_mode(ks, advertising,
665 25000baseCR_Full);
666 ethtool_link_ksettings_add_link_mode(ks, supported,
667 10000baseCR_Full);
668 ethtool_link_ksettings_add_link_mode(ks, advertising,
669 10000baseCR_Full);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800670 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000671 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000672 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700673 netdev_info(netdev,
674 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000675 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000676 }
677
Catherine Sullivan06566e52016-05-03 15:13:14 -0700678 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700679 * current PHY type, get what is supported by the NVM and intersect
680 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700681 */
Alan Brady1eaae512017-10-05 14:53:41 -0700682 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
683 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
684 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700685
Catherine Sullivane8278452015-02-06 08:52:08 +0000686 /* Set speed and duplex */
687 switch (link_speed) {
688 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700689 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000690 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800691 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700692 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800693 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700694 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700695 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700696 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000697 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700698 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000699 break;
700 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700701 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000702 break;
703 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700704 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000705 break;
706 default:
707 break;
708 }
Alan Brady1c142e12017-10-05 14:53:31 -0700709 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000710}
711
712/**
713 * i40e_get_settings_link_down - Get the Link settings for when link is down
714 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700715 * @ks: ethtool ksettings to fill in
716 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000717 *
718 * Reports link settings that can be determined when link is down
719 **/
720static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700721 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400722 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000723{
Catherine Sullivane8278452015-02-06 08:52:08 +0000724 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400725 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000726 */
Alan Brady1eaae512017-10-05 14:53:41 -0700727 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000728
729 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700730 ks->base.speed = SPEED_UNKNOWN;
731 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000732}
733
734/**
Alan Brady1c142e12017-10-05 14:53:31 -0700735 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000736 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700737 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000738 *
739 * Reports speed/duplex settings based on media_type
740 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100741static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700742 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000743{
744 struct i40e_netdev_priv *np = netdev_priv(netdev);
745 struct i40e_pf *pf = np->vsi->back;
746 struct i40e_hw *hw = &pf->hw;
747 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
748 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700749
750 ethtool_link_ksettings_zero_link_mode(ks, supported);
751 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000752
753 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700754 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000755 else
Alan Brady1c142e12017-10-05 14:53:31 -0700756 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000757
758 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000759 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700760 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
761 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000762
Alan Bradya03af692017-10-05 14:53:37 -0700763 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000764 switch (hw->phy.media_type) {
765 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700766 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
767 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
768 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700769 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100770 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700771 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000772 break;
773 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700774 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
775 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
776 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000777 break;
778 case I40E_MEDIA_TYPE_DA:
779 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700780 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
781 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
782 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000783 break;
784 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700785 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
786 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000787 break;
788 case I40E_MEDIA_TYPE_UNKNOWN:
789 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700790 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000791 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000792 }
793
Catherine Sullivane8278452015-02-06 08:52:08 +0000794 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700795 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000796
Catherine Sullivane8278452015-02-06 08:52:08 +0000797 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000798 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700799 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000800 break;
801 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700802 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100803 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000804 break;
805 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700806 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700807 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100808 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000809 break;
810 default:
Alan Brady5f434992017-10-05 14:53:34 -0700811 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
812 ethtool_link_ksettings_del_link_mode(ks, advertising,
813 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000814 break;
815 }
816
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000817 return 0;
818}
819
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000820/**
Alan Brady1c142e12017-10-05 14:53:31 -0700821 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000822 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700823 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000824 *
825 * Set speed/duplex per media_types advertised/forced
826 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100827static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700828 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000829{
830 struct i40e_netdev_priv *np = netdev_priv(netdev);
831 struct i40e_aq_get_phy_abilities_resp abilities;
Alan Brady636b62d2017-10-05 14:53:43 -0700832 struct ethtool_link_ksettings safe_ks;
833 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000834 struct i40e_aq_set_phy_config config;
835 struct i40e_pf *pf = np->vsi->back;
836 struct i40e_vsi *vsi = np->vsi;
837 struct i40e_hw *hw = &pf->hw;
Alan Brady636b62d2017-10-05 14:53:43 -0700838 bool autoneg_changed = false;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000839 i40e_status status = 0;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400840 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000841 int err = 0;
Alan Bradycee91992017-10-05 14:53:44 -0700842 u8 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000843
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000844 /* Changing port settings is not supported if this isn't the
845 * port's controlling PF
846 */
847 if (hw->partition_id != 1) {
848 i40e_partition_setting_complaint(pf);
849 return -EOPNOTSUPP;
850 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000851 if (vsi != pf->vsi[pf->lan_vsi])
852 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000853 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
854 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000855 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700856 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000857 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000858 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400859 if (hw->device_id == I40E_DEV_ID_KX_B ||
860 hw->device_id == I40E_DEV_ID_KX_C ||
861 hw->device_id == I40E_DEV_ID_20G_KR2 ||
862 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
863 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
864 return -EOPNOTSUPP;
865 }
866
Alan Brady1c142e12017-10-05 14:53:31 -0700867 /* copy the ksettings to copy_ks to avoid modifying the origin */
868 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000869
Alan Bradycee91992017-10-05 14:53:44 -0700870 /* save autoneg out of ksettings */
871 autoneg = copy_ks.base.autoneg;
872
873 memset(&safe_ks, 0, sizeof(safe_ks));
874 /* Get link modes supported by hardware and check against modes
875 * requested by the user. Return an error if unsupported mode was set.
876 */
877 i40e_phy_type_to_ethtool(pf, &safe_ks);
878 if (!bitmap_subset(copy_ks.link_modes.advertising,
879 safe_ks.link_modes.supported,
880 __ETHTOOL_LINK_MODE_MASK_NBITS))
881 return -EINVAL;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000882
Philippe Reynesa7f90942017-02-04 22:05:06 +0100883 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700884 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
Alan Bradycee91992017-10-05 14:53:44 -0700885 safe_ks.base.cmd = copy_ks.base.cmd;
886 safe_ks.base.link_mode_masks_nwords =
887 copy_ks.base.link_mode_masks_nwords;
Alan Brady1c142e12017-10-05 14:53:31 -0700888 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100889
Alan Bradycee91992017-10-05 14:53:44 -0700890 /* set autoneg back to what it currently is */
Alan Brady1c142e12017-10-05 14:53:31 -0700891 copy_ks.base.autoneg = safe_ks.base.autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000892
Alan Bradycee91992017-10-05 14:53:44 -0700893 /* If copy_ks.base and safe_ks.base are not the same now, then they are
894 * trying to set something that we do not support.
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000895 */
Alan Bradycee91992017-10-05 14:53:44 -0700896 if (memcmp(&copy_ks.base, &safe_ks.base,
897 sizeof(struct ethtool_link_settings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000898 return -EOPNOTSUPP;
899
Jacob Keller0da36b92017-04-19 09:25:55 -0400900 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400901 timeout--;
902 if (!timeout)
903 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000904 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400905 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000906
907 /* Get the current phy config */
908 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
909 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400910 if (status) {
911 err = -EAGAIN;
912 goto done;
913 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000914
Catherine Sullivan124ed152014-07-12 07:28:12 +0000915 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000916 * set below
917 */
918 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000919 config.abilities = abilities.abilities;
920
921 /* Check autoneg */
922 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000923 /* If autoneg was not already enabled */
924 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400925 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700926 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
927 supported,
928 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400929 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400930 err = -EINVAL;
931 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400932 }
933 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000934 config.abilities = abilities.abilities |
935 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700936 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000937 }
938 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000939 /* If autoneg is currently enabled */
940 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400941 /* If autoneg is supported 10GBASE_T is the only PHY
942 * that can disable it, so otherwise return error
943 */
Alan Brady1c142e12017-10-05 14:53:31 -0700944 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
945 supported,
946 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400947 hw->phy.link_info.phy_type !=
948 I40E_PHY_TYPE_10GBASE_T) {
949 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400950 err = -EINVAL;
951 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400952 }
953 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000954 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000955 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700956 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000957 }
958 }
959
Alan Bradycee91992017-10-05 14:53:44 -0700960 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
961 100baseT_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000962 config.link_speed |= I40E_LINK_SPEED_100MB;
Alan Bradycee91992017-10-05 14:53:44 -0700963 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
964 1000baseT_Full) ||
965 ethtool_link_ksettings_test_link_mode(ks, advertising,
966 1000baseX_Full) ||
967 ethtool_link_ksettings_test_link_mode(ks, advertising,
968 1000baseKX_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000969 config.link_speed |= I40E_LINK_SPEED_1GB;
Alan Bradycee91992017-10-05 14:53:44 -0700970 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
971 10000baseT_Full) ||
972 ethtool_link_ksettings_test_link_mode(ks, advertising,
973 10000baseKX4_Full) ||
974 ethtool_link_ksettings_test_link_mode(ks, advertising,
975 10000baseKR_Full) ||
976 ethtool_link_ksettings_test_link_mode(ks, advertising,
977 10000baseCR_Full) ||
978 ethtool_link_ksettings_test_link_mode(ks, advertising,
979 10000baseSR_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000980 config.link_speed |= I40E_LINK_SPEED_10GB;
Alan Bradycee91992017-10-05 14:53:44 -0700981 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
982 20000baseKR2_Full))
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700983 config.link_speed |= I40E_LINK_SPEED_20GB;
Alan Bradycee91992017-10-05 14:53:44 -0700984 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
985 25000baseCR_Full) ||
986 ethtool_link_ksettings_test_link_mode(ks, advertising,
987 25000baseKR_Full) ||
988 ethtool_link_ksettings_test_link_mode(ks, advertising,
989 25000baseSR_Full))
990 config.link_speed |= I40E_LINK_SPEED_25GB;
991 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
992 40000baseKR4_Full) ||
993 ethtool_link_ksettings_test_link_mode(ks, advertising,
994 40000baseCR4_Full) ||
995 ethtool_link_ksettings_test_link_mode(ks, advertising,
996 40000baseSR4_Full) ||
997 ethtool_link_ksettings_test_link_mode(ks, advertising,
998 40000baseLR4_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000999 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001000
Catherine Sullivan0002e112015-08-26 15:14:16 -04001001 /* If speed didn't get set, set it to what it currently is.
1002 * This is needed because if advertise is 0 (as it is when autoneg
1003 * is disabled) then speed won't get set.
1004 */
1005 if (!config.link_speed)
1006 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -07001007 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001008 /* copy over the rest of the abilities */
1009 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -08001010 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001011 config.eee_capability = abilities.eee_capability;
1012 config.eeer = abilities.eeer_val;
1013 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -08001014 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1015 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001016
Catherine Sullivane8278452015-02-06 08:52:08 +00001017 /* save the requested speeds */
1018 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +00001019 /* set link and auto negotiation so changes take effect */
1020 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1021 /* If link is up put link down */
1022 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
1023 /* Tell the OS link is going down, the link will go
1024 * back up when fw says it is ready asynchronously
1025 */
Matt Jaredc156f852015-08-27 11:42:39 -04001026 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001027 netif_carrier_off(netdev);
1028 netif_tx_stop_all_queues(netdev);
1029 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001030
1031 /* make the aq call */
1032 status = i40e_aq_set_phy_config(hw, &config, NULL);
1033 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001034 netdev_info(netdev,
1035 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001036 i40e_stat_str(hw, status),
1037 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001038 err = -EAGAIN;
1039 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001040 }
1041
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001042 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001043 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001044 netdev_dbg(netdev,
1045 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001046 i40e_stat_str(hw, status),
1047 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001048
1049 } else {
1050 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1051 }
1052
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001053done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001054 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001055
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001056 return err;
1057}
1058
Jesse Brandeburga6599722014-06-04 08:45:25 +00001059static int i40e_nway_reset(struct net_device *netdev)
1060{
1061 /* restart autonegotiation */
1062 struct i40e_netdev_priv *np = netdev_priv(netdev);
1063 struct i40e_pf *pf = np->vsi->back;
1064 struct i40e_hw *hw = &pf->hw;
1065 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1066 i40e_status ret = 0;
1067
1068 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1069 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001070 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1071 i40e_stat_str(hw, ret),
1072 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001073 return -EIO;
1074 }
1075
1076 return 0;
1077}
1078
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001079/**
1080 * i40e_get_pauseparam - Get Flow Control status
1081 * Return tx/rx-pause status
1082 **/
1083static void i40e_get_pauseparam(struct net_device *netdev,
1084 struct ethtool_pauseparam *pause)
1085{
1086 struct i40e_netdev_priv *np = netdev_priv(netdev);
1087 struct i40e_pf *pf = np->vsi->back;
1088 struct i40e_hw *hw = &pf->hw;
1089 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001090 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001091
1092 pause->autoneg =
1093 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1094 AUTONEG_ENABLE : AUTONEG_DISABLE);
1095
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001096 /* PFC enabled so report LFC as off */
1097 if (dcbx_cfg->pfc.pfcenable) {
1098 pause->rx_pause = 0;
1099 pause->tx_pause = 0;
1100 return;
1101 }
1102
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001103 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001104 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001105 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001106 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001107 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1108 pause->rx_pause = 1;
1109 pause->tx_pause = 1;
1110 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001111}
1112
Catherine Sullivan2becc352014-06-04 08:45:27 +00001113/**
1114 * i40e_set_pauseparam - Set Flow Control parameter
1115 * @netdev: network interface device structure
1116 * @pause: return tx/rx flow control status
1117 **/
1118static int i40e_set_pauseparam(struct net_device *netdev,
1119 struct ethtool_pauseparam *pause)
1120{
1121 struct i40e_netdev_priv *np = netdev_priv(netdev);
1122 struct i40e_pf *pf = np->vsi->back;
1123 struct i40e_vsi *vsi = np->vsi;
1124 struct i40e_hw *hw = &pf->hw;
1125 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001126 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001127 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1128 i40e_status status;
1129 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001130 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001131
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001132 /* Changing the port's flow control is not supported if this isn't the
1133 * port's controlling PF
1134 */
1135 if (hw->partition_id != 1) {
1136 i40e_partition_setting_complaint(pf);
1137 return -EOPNOTSUPP;
1138 }
1139
Catherine Sullivan2becc352014-06-04 08:45:27 +00001140 if (vsi != pf->vsi[pf->lan_vsi])
1141 return -EOPNOTSUPP;
1142
1143 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1144 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1145 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1146 return -EOPNOTSUPP;
1147 }
1148
1149 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001150 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001151 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1152 /* Send message that it might not necessarily work*/
1153 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1154 }
1155
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001156 if (dcbx_cfg->pfc.pfcenable) {
1157 netdev_info(netdev,
1158 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001159 return -EOPNOTSUPP;
1160 }
1161
1162 if (pause->rx_pause && pause->tx_pause)
1163 hw->fc.requested_mode = I40E_FC_FULL;
1164 else if (pause->rx_pause && !pause->tx_pause)
1165 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1166 else if (!pause->rx_pause && pause->tx_pause)
1167 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1168 else if (!pause->rx_pause && !pause->tx_pause)
1169 hw->fc.requested_mode = I40E_FC_NONE;
1170 else
1171 return -EINVAL;
1172
Catherine Sullivan94128512014-07-12 07:28:16 +00001173 /* Tell the OS link is going down, the link will go back up when fw
1174 * says it is ready asynchronously
1175 */
Matt Jaredc156f852015-08-27 11:42:39 -04001176 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001177 netif_carrier_off(netdev);
1178 netif_tx_stop_all_queues(netdev);
1179
Catherine Sullivan2becc352014-06-04 08:45:27 +00001180 /* Set the fc mode and only restart an if link is up*/
1181 status = i40e_set_fc(hw, &aq_failures, link_up);
1182
1183 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001184 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1185 i40e_stat_str(hw, status),
1186 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001187 err = -EAGAIN;
1188 }
1189 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001190 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1191 i40e_stat_str(hw, status),
1192 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001193 err = -EAGAIN;
1194 }
1195 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001196 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1197 i40e_stat_str(hw, status),
1198 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001199 err = -EAGAIN;
1200 }
1201
Jacob Keller0da36b92017-04-19 09:25:55 -04001202 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001203 /* Give it a little more time to try to come back */
1204 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001205 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001206 return i40e_nway_reset(netdev);
1207 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001208
1209 return err;
1210}
1211
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001212static u32 i40e_get_msglevel(struct net_device *netdev)
1213{
1214 struct i40e_netdev_priv *np = netdev_priv(netdev);
1215 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001216 u32 debug_mask = pf->hw.debug_mask;
1217
1218 if (debug_mask)
1219 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220
1221 return pf->msg_enable;
1222}
1223
1224static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1225{
1226 struct i40e_netdev_priv *np = netdev_priv(netdev);
1227 struct i40e_pf *pf = np->vsi->back;
1228
1229 if (I40E_DEBUG_USER & data)
1230 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001231 else
1232 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001233}
1234
1235static int i40e_get_regs_len(struct net_device *netdev)
1236{
1237 int reg_count = 0;
1238 int i;
1239
1240 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1241 reg_count += i40e_reg_list[i].elements;
1242
1243 return reg_count * sizeof(u32);
1244}
1245
1246static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1247 void *p)
1248{
1249 struct i40e_netdev_priv *np = netdev_priv(netdev);
1250 struct i40e_pf *pf = np->vsi->back;
1251 struct i40e_hw *hw = &pf->hw;
1252 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001253 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001254 u32 reg;
1255
1256 /* Tell ethtool which driver-version-specific regs output we have.
1257 *
1258 * At some point, if we have ethtool doing special formatting of
1259 * this data, it will rely on this version number to know how to
1260 * interpret things. Hence, this needs to be updated if/when the
1261 * diags register table is changed.
1262 */
1263 regs->version = 1;
1264
1265 /* loop through the diags reg table for what to print */
1266 ri = 0;
1267 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1268 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1269 reg = i40e_reg_list[i].offset
1270 + (j * i40e_reg_list[i].stride);
1271 reg_buf[ri++] = rd32(hw, reg);
1272 }
1273 }
1274
1275}
1276
1277static int i40e_get_eeprom(struct net_device *netdev,
1278 struct ethtool_eeprom *eeprom, u8 *bytes)
1279{
1280 struct i40e_netdev_priv *np = netdev_priv(netdev);
1281 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001282 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001283 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001284 u8 *eeprom_buff;
1285 u16 i, sectors;
1286 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001287 u32 magic;
1288
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001289#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001290 if (eeprom->len == 0)
1291 return -EINVAL;
1292
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001293 /* check for NVMUpdate access method */
1294 magic = hw->vendor_id | (hw->device_id << 16);
1295 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001296 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1297 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001298
1299 /* make sure it is the right magic for NVMUpdate */
1300 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001301 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001302 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1303 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001304 errno = -EBUSY;
1305 else
1306 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001307
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001308 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001309 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001310 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1311 ret_val, hw->aq.asq_last_status, errno,
1312 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1313 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001314
1315 return errno;
1316 }
1317
1318 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1320
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001321 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001322 if (!eeprom_buff)
1323 return -ENOMEM;
1324
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001325 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1326 if (ret_val) {
1327 dev_info(&pf->pdev->dev,
1328 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1329 ret_val, hw->aq.asq_last_status);
1330 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 }
1332
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001333 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1334 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1335 len = I40E_NVM_SECTOR_SIZE;
1336 last = false;
1337 for (i = 0; i < sectors; i++) {
1338 if (i == (sectors - 1)) {
1339 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1340 last = true;
1341 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001342 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1343 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001344 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001345 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001346 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001347 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001348 "read NVM failed, invalid offset 0x%x\n",
1349 offset);
1350 break;
1351 } else if (ret_val &&
1352 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1353 dev_info(&pf->pdev->dev,
1354 "read NVM failed, access, offset 0x%x\n",
1355 offset);
1356 break;
1357 } else if (ret_val) {
1358 dev_info(&pf->pdev->dev,
1359 "read NVM failed offset %d err=%d status=0x%x\n",
1360 offset, ret_val, hw->aq.asq_last_status);
1361 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001362 }
1363 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001365 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001366 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001367free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001368 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001369 return ret_val;
1370}
1371
1372static int i40e_get_eeprom_len(struct net_device *netdev)
1373{
1374 struct i40e_netdev_priv *np = netdev_priv(netdev);
1375 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001376 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001377
Lihong Yangc271dd62017-01-30 12:29:32 -08001378#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1379 if (hw->mac.type == I40E_MAC_X722) {
1380 val = X722_EEPROM_SCOPE_LIMIT + 1;
1381 return val;
1382 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001383 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1384 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1385 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1386 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001387 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001388 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001389}
1390
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001391static int i40e_set_eeprom(struct net_device *netdev,
1392 struct ethtool_eeprom *eeprom, u8 *bytes)
1393{
1394 struct i40e_netdev_priv *np = netdev_priv(netdev);
1395 struct i40e_hw *hw = &np->vsi->back->hw;
1396 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001397 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001398 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001399 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001400 u32 magic;
1401
1402 /* normal ethtool set_eeprom is not supported */
1403 magic = hw->vendor_id | (hw->device_id << 16);
1404 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001405 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001406 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001407 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1408 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001409 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1410 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001411 errno = -EBUSY;
1412 else
1413 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001414
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001415 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001416 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001417 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1418 ret_val, hw->aq.asq_last_status, errno,
1419 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1420 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001421
1422 return errno;
1423}
1424
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001425static void i40e_get_drvinfo(struct net_device *netdev,
1426 struct ethtool_drvinfo *drvinfo)
1427{
1428 struct i40e_netdev_priv *np = netdev_priv(netdev);
1429 struct i40e_vsi *vsi = np->vsi;
1430 struct i40e_pf *pf = vsi->back;
1431
1432 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1433 strlcpy(drvinfo->version, i40e_driver_version_str,
1434 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001435 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001436 sizeof(drvinfo->fw_version));
1437 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1438 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001439 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001440 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001441 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001442}
1443
1444static void i40e_get_ringparam(struct net_device *netdev,
1445 struct ethtool_ringparam *ring)
1446{
1447 struct i40e_netdev_priv *np = netdev_priv(netdev);
1448 struct i40e_pf *pf = np->vsi->back;
1449 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1450
1451 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1452 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1453 ring->rx_mini_max_pending = 0;
1454 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001455 ring->rx_pending = vsi->rx_rings[0]->count;
1456 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 ring->rx_mini_pending = 0;
1458 ring->rx_jumbo_pending = 0;
1459}
1460
Björn Töpel74608d12017-05-24 07:55:35 +02001461static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1462{
1463 if (i40e_enabled_xdp_vsi(vsi)) {
1464 return index < vsi->num_queue_pairs ||
1465 (index >= vsi->alloc_queue_pairs &&
1466 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1467 }
1468
1469 return index < vsi->num_queue_pairs;
1470}
1471
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001472static int i40e_set_ringparam(struct net_device *netdev,
1473 struct ethtool_ringparam *ring)
1474{
1475 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1476 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001477 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478 struct i40e_vsi *vsi = np->vsi;
1479 struct i40e_pf *pf = vsi->back;
1480 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001481 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001482 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483 int i, err = 0;
1484
1485 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1486 return -EINVAL;
1487
Shannon Nelson1fa18372013-11-20 10:03:08 +00001488 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1489 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1490 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1491 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1492 netdev_info(netdev,
1493 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1494 ring->tx_pending, ring->rx_pending,
1495 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1496 return -EINVAL;
1497 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001498
Shannon Nelson1fa18372013-11-20 10:03:08 +00001499 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1500 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001501
1502 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001503 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1504 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505 return 0;
1506
Jacob Keller0da36b92017-04-19 09:25:55 -04001507 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001508 timeout--;
1509 if (!timeout)
1510 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001511 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001512 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513
1514 if (!netif_running(vsi->netdev)) {
1515 /* simple case - set for the next time the netdev is started */
1516 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001517 vsi->tx_rings[i]->count = new_tx_count;
1518 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001519 if (i40e_enabled_xdp_vsi(vsi))
1520 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001521 }
1522 goto done;
1523 }
1524
1525 /* We can't just free everything and then setup again,
1526 * because the ISRs in MSI-X mode get passed pointers
1527 * to the Tx and Rx ring structs.
1528 */
1529
Björn Töpel74608d12017-05-24 07:55:35 +02001530 /* alloc updated Tx and XDP Tx resources */
1531 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1532 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001533 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534 netdev_info(netdev,
1535 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001536 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001537 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001538 sizeof(struct i40e_ring), GFP_KERNEL);
1539 if (!tx_rings) {
1540 err = -ENOMEM;
1541 goto done;
1542 }
1543
Björn Töpel74608d12017-05-24 07:55:35 +02001544 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1545 if (!i40e_active_tx_ring_index(vsi, i))
1546 continue;
1547
Alexander Duyck9f65e152013-09-28 06:00:58 +00001548 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001549 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001550 /* the desc and bi pointers will be reallocated in the
1551 * setup call
1552 */
1553 tx_rings[i].desc = NULL;
1554 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1556 if (err) {
1557 while (i) {
1558 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001559 if (!i40e_active_tx_ring_index(vsi, i))
1560 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001561 i40e_free_tx_resources(&tx_rings[i]);
1562 }
1563 kfree(tx_rings);
1564 tx_rings = NULL;
1565
1566 goto done;
1567 }
1568 }
1569 }
1570
1571 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001572 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573 netdev_info(netdev,
1574 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001575 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001576 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1577 sizeof(struct i40e_ring), GFP_KERNEL);
1578 if (!rx_rings) {
1579 err = -ENOMEM;
1580 goto free_tx;
1581 }
1582
1583 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001584 struct i40e_ring *ring;
1585 u16 unused;
1586
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001587 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001588 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001589 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001590 /* the desc and bi pointers will be reallocated in the
1591 * setup call
1592 */
1593 rx_rings[i].desc = NULL;
1594 rx_rings[i].rx_bi = NULL;
Jesper Dangaard Brouer87128822018-01-03 11:25:23 +01001595 /* Clear cloned XDP RX-queue info before setup call */
1596 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
Tushar Dave2f7679e2016-10-26 10:49:27 -07001597 /* this is to allow wr32 to have something to write to
1598 * during early allocation of Rx buffers
1599 */
1600 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001601 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001602 if (err)
1603 goto rx_unwind;
1604
1605 /* now allocate the Rx buffers to make sure the OS
1606 * has enough memory, any failure here means abort
1607 */
1608 ring = &rx_rings[i];
1609 unused = I40E_DESC_UNUSED(ring);
1610 err = i40e_alloc_rx_buffers(ring, unused);
1611rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001612 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001613 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001615 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001616 kfree(rx_rings);
1617 rx_rings = NULL;
1618
1619 goto free_tx;
1620 }
1621 }
1622 }
1623
1624 /* Bring interface down, copy in the new ring info,
1625 * then restore the interface
1626 */
1627 i40e_down(vsi);
1628
1629 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001630 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1631 if (i40e_active_tx_ring_index(vsi, i)) {
1632 i40e_free_tx_resources(vsi->tx_rings[i]);
1633 *vsi->tx_rings[i] = tx_rings[i];
1634 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001635 }
1636 kfree(tx_rings);
1637 tx_rings = NULL;
1638 }
1639
1640 if (rx_rings) {
1641 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001642 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001643 /* get the real tail offset */
1644 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1645 /* this is to fake out the allocation routine
1646 * into thinking it has to realloc everything
1647 * but the recycling logic will let us re-use
1648 * the buffers allocated above
1649 */
1650 rx_rings[i].next_to_use = 0;
1651 rx_rings[i].next_to_clean = 0;
1652 rx_rings[i].next_to_alloc = 0;
1653 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001654 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001655 }
1656 kfree(rx_rings);
1657 rx_rings = NULL;
1658 }
1659
1660 i40e_up(vsi);
1661
1662free_tx:
1663 /* error cleanup if the Rx allocations failed after getting Tx */
1664 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001665 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1666 if (i40e_active_tx_ring_index(vsi, i))
1667 i40e_free_tx_resources(vsi->tx_rings[i]);
1668 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001669 kfree(tx_rings);
1670 tx_rings = NULL;
1671 }
1672
1673done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001674 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001675
1676 return err;
1677}
1678
1679static int i40e_get_sset_count(struct net_device *netdev, int sset)
1680{
1681 struct i40e_netdev_priv *np = netdev_priv(netdev);
1682 struct i40e_vsi *vsi = np->vsi;
1683 struct i40e_pf *pf = vsi->back;
1684
1685 switch (sset) {
1686 case ETH_SS_TEST:
1687 return I40E_TEST_LEN;
1688 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001689 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001690 int len = I40E_PF_STATS_LEN(netdev);
1691
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001692 if ((pf->lan_veb != I40E_NO_VEB) &&
1693 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001694 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001695 return len;
1696 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001698 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001699 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001700 return I40E_PRIV_FLAGS_STR_LEN +
1701 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001702 default:
1703 return -EOPNOTSUPP;
1704 }
1705}
1706
1707static void i40e_get_ethtool_stats(struct net_device *netdev,
1708 struct ethtool_stats *stats, u64 *data)
1709{
1710 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001711 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712 struct i40e_vsi *vsi = np->vsi;
1713 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001714 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715 int i = 0;
1716 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001717 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001718 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001719
1720 i40e_update_stats(vsi);
1721
1722 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1723 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1724 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1725 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1726 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001727 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1728 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1729 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1730 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1731 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001732 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001733 for (j = 0; j < vsi->num_queue_pairs; j++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07001734 tx_ring = READ_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001735
1736 if (!tx_ring)
1737 continue;
1738
1739 /* process Tx ring statistics */
1740 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001741 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001742 data[i] = tx_ring->stats.packets;
1743 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001744 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001745 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001746
1747 /* Rx ring is the 2nd half of the queue pair */
1748 rx_ring = &tx_ring[1];
1749 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001750 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001751 data[i] = rx_ring->stats.packets;
1752 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001753 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001754 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001755 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001756 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001757 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001758 return;
1759
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001760 if ((pf->lan_veb != I40E_NO_VEB) &&
1761 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001762 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001763
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001764 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1765 p = (char *)veb;
1766 p += i40e_gstrings_veb_stats[j].stat_offset;
1767 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1768 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001769 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001770 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1771 data[i++] = veb->tc_stats.tc_tx_packets[j];
1772 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1773 data[i++] = veb->tc_stats.tc_rx_packets[j];
1774 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1775 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001776 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001777 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1778 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1779 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1780 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1781 }
1782 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1783 data[i++] = pf->stats.priority_xon_tx[j];
1784 data[i++] = pf->stats.priority_xoff_tx[j];
1785 }
1786 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1787 data[i++] = pf->stats.priority_xon_rx[j];
1788 data[i++] = pf->stats.priority_xoff_rx[j];
1789 }
1790 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1791 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001792}
1793
1794static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1795 u8 *data)
1796{
1797 struct i40e_netdev_priv *np = netdev_priv(netdev);
1798 struct i40e_vsi *vsi = np->vsi;
1799 struct i40e_pf *pf = vsi->back;
1800 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001801 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001802
1803 switch (stringset) {
1804 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001805 memcpy(data, i40e_gstrings_test,
1806 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807 break;
1808 case ETH_SS_STATS:
1809 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1810 snprintf(p, ETH_GSTRING_LEN, "%s",
1811 i40e_gstrings_net_stats[i].stat_string);
1812 p += ETH_GSTRING_LEN;
1813 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001814 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1815 snprintf(p, ETH_GSTRING_LEN, "%s",
1816 i40e_gstrings_misc_stats[i].stat_string);
1817 p += ETH_GSTRING_LEN;
1818 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001820 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001821 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001822 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001824 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001825 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001826 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001827 p += ETH_GSTRING_LEN;
1828 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001829 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001830 return;
1831
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001832 if ((pf->lan_veb != I40E_NO_VEB) &&
1833 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001834 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1835 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1836 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001837 p += ETH_GSTRING_LEN;
1838 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001839 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1840 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001841 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001842 p += ETH_GSTRING_LEN;
1843 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001844 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001845 p += ETH_GSTRING_LEN;
1846 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001847 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001848 p += ETH_GSTRING_LEN;
1849 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001850 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001851 p += ETH_GSTRING_LEN;
1852 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001853 }
1854 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1855 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1856 i40e_gstrings_stats[i].stat_string);
1857 p += ETH_GSTRING_LEN;
1858 }
1859 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1860 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001861 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001862 p += ETH_GSTRING_LEN;
1863 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001864 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001865 p += ETH_GSTRING_LEN;
1866 }
1867 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1868 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001869 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001870 p += ETH_GSTRING_LEN;
1871 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001872 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001873 p += ETH_GSTRING_LEN;
1874 }
1875 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1876 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001877 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001878 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879 }
1880 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1881 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001882 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001883 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1884 snprintf(p, ETH_GSTRING_LEN, "%s",
1885 i40e_gstrings_priv_flags[i].flag_string);
1886 p += ETH_GSTRING_LEN;
1887 }
1888 if (pf->hw.pf_id != 0)
1889 break;
1890 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1891 snprintf(p, ETH_GSTRING_LEN, "%s",
1892 i40e_gl_gstrings_priv_flags[i].flag_string);
1893 p += ETH_GSTRING_LEN;
1894 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001895 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001896 default:
1897 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001898 }
1899}
1900
1901static int i40e_get_ts_info(struct net_device *dev,
1902 struct ethtool_ts_info *info)
1903{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001904 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1905
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001906 /* only report HW timestamping if PTP is enabled */
1907 if (!(pf->flags & I40E_FLAG_PTP))
1908 return ethtool_op_get_ts_info(dev, info);
1909
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001910 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1911 SOF_TIMESTAMPING_RX_SOFTWARE |
1912 SOF_TIMESTAMPING_SOFTWARE |
1913 SOF_TIMESTAMPING_TX_HARDWARE |
1914 SOF_TIMESTAMPING_RX_HARDWARE |
1915 SOF_TIMESTAMPING_RAW_HARDWARE;
1916
1917 if (pf->ptp_clock)
1918 info->phc_index = ptp_clock_index(pf->ptp_clock);
1919 else
1920 info->phc_index = -1;
1921
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001922 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001923
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001924 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001925 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1926 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1927 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1928
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001929 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001930 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1931 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1932 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1933 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1934 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1935 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1936 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1937 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001938
1939 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001940}
1941
Shannon Nelson7b086392013-11-20 10:02:59 +00001942static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001943{
Shannon Nelson7b086392013-11-20 10:02:59 +00001944 struct i40e_netdev_priv *np = netdev_priv(netdev);
1945 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001946 i40e_status status;
1947 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001948
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001949 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001950 status = i40e_get_link_status(&pf->hw, &link_up);
1951 if (status) {
1952 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1953 *data = 1;
1954 return *data;
1955 }
1956
1957 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958 *data = 0;
1959 else
1960 *data = 1;
1961
1962 return *data;
1963}
1964
Shannon Nelson7b086392013-11-20 10:02:59 +00001965static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001966{
Shannon Nelson7b086392013-11-20 10:02:59 +00001967 struct i40e_netdev_priv *np = netdev_priv(netdev);
1968 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001969
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001970 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001971 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001972
Shannon Nelson7b086392013-11-20 10:02:59 +00001973 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001974}
1975
Shannon Nelson7b086392013-11-20 10:02:59 +00001976static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001977{
Shannon Nelson7b086392013-11-20 10:02:59 +00001978 struct i40e_netdev_priv *np = netdev_priv(netdev);
1979 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001980
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001981 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001982 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001983
Shannon Nelson4443ec92014-11-13 08:23:12 +00001984 /* forcebly clear the NVM Update state machine */
1985 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1986
Shannon Nelson7b086392013-11-20 10:02:59 +00001987 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001988}
1989
Shannon Nelson7b086392013-11-20 10:02:59 +00001990static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001991{
Shannon Nelson7b086392013-11-20 10:02:59 +00001992 struct i40e_netdev_priv *np = netdev_priv(netdev);
1993 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001994 u16 swc_old = pf->sw_int_count;
1995
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001996 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001997 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1998 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001999 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
2000 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
2001 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
2002 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00002003 usleep_range(1000, 2000);
2004 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002005
2006 return *data;
2007}
2008
Greg Rosee17bc412015-04-16 20:05:59 -04002009static inline bool i40e_active_vfs(struct i40e_pf *pf)
2010{
2011 struct i40e_vf *vfs = pf->vf;
2012 int i;
2013
2014 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04002015 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04002016 return true;
2017 return false;
2018}
2019
Greg Rose510efb22015-07-10 19:36:01 -04002020static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2021{
Alexander Duyck4b816442016-10-11 15:26:53 -07002022 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04002023}
2024
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002025static void i40e_diag_test(struct net_device *netdev,
2026 struct ethtool_test *eth_test, u64 *data)
2027{
2028 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002029 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002030 struct i40e_pf *pf = np->vsi->back;
2031
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002032 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2033 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002034 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002035
Jacob Keller0da36b92017-04-19 09:25:55 -04002036 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002037
Greg Rose510efb22015-07-10 19:36:01 -04002038 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002039 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002040 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002041 data[I40E_ETH_TEST_REG] = 1;
2042 data[I40E_ETH_TEST_EEPROM] = 1;
2043 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002044 data[I40E_ETH_TEST_LINK] = 1;
2045 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002046 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002047 goto skip_ol_tests;
2048 }
2049
Greg Rose5b86c5c2015-02-26 16:14:35 +00002050 /* If the device is online then take it offline */
2051 if (if_running)
2052 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002053 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002054 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002055 /* This reset does not affect link - if it is
2056 * changed to a type of reset that does affect
2057 * link then the following link test would have
2058 * to be moved to before the reset
2059 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002060 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002061
Shannon Nelson7b086392013-11-20 10:02:59 +00002062 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002063 eth_test->flags |= ETH_TEST_FL_FAILED;
2064
Shannon Nelson7b086392013-11-20 10:02:59 +00002065 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002066 eth_test->flags |= ETH_TEST_FL_FAILED;
2067
Shannon Nelson7b086392013-11-20 10:02:59 +00002068 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002069 eth_test->flags |= ETH_TEST_FL_FAILED;
2070
Shannon Nelsonf551b432013-11-26 10:49:12 +00002071 /* run reg test last, a reset is required after it */
2072 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2073 eth_test->flags |= ETH_TEST_FL_FAILED;
2074
Jacob Keller0da36b92017-04-19 09:25:55 -04002075 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002076 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002077
2078 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002079 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002080 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002081 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002082 netif_info(pf, drv, netdev, "online testing starting\n");
2083
Shannon Nelson7b086392013-11-20 10:02:59 +00002084 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002085 eth_test->flags |= ETH_TEST_FL_FAILED;
2086
2087 /* Offline only tests, not run in online; pass by default */
2088 data[I40E_ETH_TEST_REG] = 0;
2089 data[I40E_ETH_TEST_EEPROM] = 0;
2090 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002091 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002092
Greg Rosee17bc412015-04-16 20:05:59 -04002093skip_ol_tests:
2094
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002095 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002096}
2097
2098static void i40e_get_wol(struct net_device *netdev,
2099 struct ethtool_wolinfo *wol)
2100{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002101 struct i40e_netdev_priv *np = netdev_priv(netdev);
2102 struct i40e_pf *pf = np->vsi->back;
2103 struct i40e_hw *hw = &pf->hw;
2104 u16 wol_nvm_bits;
2105
2106 /* NVM bit on means WoL disabled for the port */
2107 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002108 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002109 wol->supported = 0;
2110 wol->wolopts = 0;
2111 } else {
2112 wol->supported = WAKE_MAGIC;
2113 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2114 }
2115}
2116
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002117/**
2118 * i40e_set_wol - set the WakeOnLAN configuration
2119 * @netdev: the netdev in question
2120 * @wol: the ethtool WoL setting data
2121 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002122static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2123{
2124 struct i40e_netdev_priv *np = netdev_priv(netdev);
2125 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002126 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002127 struct i40e_hw *hw = &pf->hw;
2128 u16 wol_nvm_bits;
2129
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002130 /* WoL not supported if this isn't the controlling PF on the port */
2131 if (hw->partition_id != 1) {
2132 i40e_partition_setting_complaint(pf);
2133 return -EOPNOTSUPP;
2134 }
2135
2136 if (vsi != pf->vsi[pf->lan_vsi])
2137 return -EOPNOTSUPP;
2138
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002139 /* NVM bit on means WoL disabled for the port */
2140 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002141 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002142 return -EOPNOTSUPP;
2143
2144 /* only magic packet is supported */
2145 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2146 return -EOPNOTSUPP;
2147
2148 /* is this a new value? */
2149 if (pf->wol_en != !!wol->wolopts) {
2150 pf->wol_en = !!wol->wolopts;
2151 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2152 }
2153
2154 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155}
2156
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002157static int i40e_set_phys_id(struct net_device *netdev,
2158 enum ethtool_phys_id_state state)
2159{
2160 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002161 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002162 struct i40e_pf *pf = np->vsi->back;
2163 struct i40e_hw *hw = &pf->hw;
2164 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002165 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002166
2167 switch (state) {
2168 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002169 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002170 pf->led_status = i40e_led_get(hw);
2171 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002172 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2173 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2174 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002175 ret = i40e_led_get_phy(hw, &temp_status,
2176 &pf->phy_led_val);
2177 pf->led_status = temp_status;
2178 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002179 return blink_freq;
2180 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002181 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002182 i40e_led_set(hw, 0xf, false);
2183 else
2184 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002185 break;
2186 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002187 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002188 i40e_led_set(hw, 0x0, false);
2189 else
2190 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002191 break;
2192 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002193 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002194 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002195 } else {
2196 ret = i40e_led_set_phy(hw, false, pf->led_status,
2197 (pf->phy_led_val |
2198 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002199 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2200 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002201 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002202 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002203 default:
2204 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002206 if (ret)
2207 return -ENOENT;
2208 else
2209 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002210}
2211
2212/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2213 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2214 * 125us (8000 interrupts per second) == ITR(62)
2215 */
2216
Jacob Keller65e87c02016-09-12 14:18:44 -07002217/**
2218 * __i40e_get_coalesce - get per-queue coalesce settings
2219 * @netdev: the netdev to check
2220 * @ec: ethtool coalesce data structure
2221 * @queue: which queue to pick
2222 *
2223 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2224 * are per queue. If queue is <0 then we default to queue 0 as the
2225 * representative value.
2226 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002227static int __i40e_get_coalesce(struct net_device *netdev,
2228 struct ethtool_coalesce *ec,
2229 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002230{
2231 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002232 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002233 struct i40e_vsi *vsi = np->vsi;
2234
2235 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2236 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2237
Alan Bradya03af692017-10-05 14:53:37 -07002238 /* rx and tx usecs has per queue value. If user doesn't specify the
2239 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002240 */
Alan Bradya03af692017-10-05 14:53:37 -07002241 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002242 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002243 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002244 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002245
Jacob Keller65e87c02016-09-12 14:18:44 -07002246 rx_ring = vsi->rx_rings[queue];
2247 tx_ring = vsi->tx_rings[queue];
2248
Alexander Duyck40588ca2017-12-29 08:49:28 -05002249 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002250 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002251
Alexander Duyck40588ca2017-12-29 08:49:28 -05002252 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002253 ec->use_adaptive_tx_coalesce = 1;
2254
Alexander Duyck40588ca2017-12-29 08:49:28 -05002255 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2256 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
Jacob Keller65e87c02016-09-12 14:18:44 -07002257
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002258 /* we use the _usecs_high to store/set the interrupt rate limit
2259 * that the hardware supports, that almost but not quite
2260 * fits the original intent of the ethtool variable,
2261 * the rx_coalesce_usecs_high limits total interrupts
2262 * per second from both tx/rx sources.
2263 */
2264 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2265 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002266
2267 return 0;
2268}
2269
Jacob Keller65e87c02016-09-12 14:18:44 -07002270/**
2271 * i40e_get_coalesce - get a netdev's coalesce settings
2272 * @netdev: the netdev to check
2273 * @ec: ethtool coalesce data structure
2274 *
2275 * Gets the coalesce settings for a particular netdev. Note that if user has
2276 * modified per-queue settings, this only guarantees to represent queue 0. See
2277 * __i40e_get_coalesce for more details.
2278 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002279static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002280 struct ethtool_coalesce *ec)
2281{
Kan Lianga75e8002016-02-19 09:24:04 -05002282 return __i40e_get_coalesce(netdev, ec, -1);
2283}
2284
Jacob Keller65e87c02016-09-12 14:18:44 -07002285/**
2286 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2287 * @netdev: netdev structure
2288 * @ec: ethtool's coalesce settings
2289 * @queue: the particular queue to read
2290 *
2291 * Will read a specific queue's coalesce settings
2292 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002293static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2294 struct ethtool_coalesce *ec)
2295{
2296 return __i40e_get_coalesce(netdev, ec, queue);
2297}
2298
Jacob Keller65e87c02016-09-12 14:18:44 -07002299/**
2300 * i40e_set_itr_per_queue - set ITR values for specific queue
2301 * @vsi: the VSI to set values for
2302 * @ec: coalesce settings from ethtool
2303 * @queue: the queue to modify
2304 *
2305 * Change the ITR settings for a specific queue.
2306 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002307static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2308 struct ethtool_coalesce *ec,
2309 int queue)
2310{
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002311 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2312 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002313 struct i40e_pf *pf = vsi->back;
2314 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002315 struct i40e_q_vector *q_vector;
Alexander Duyck8b99b112017-12-29 08:50:44 -05002316 u16 intrl;
Kan Lianga75e8002016-02-19 09:24:04 -05002317
Alan Brady1c0e6a32016-11-28 16:06:02 -08002318 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002319
Alexander Duyck92418fb2017-12-29 08:51:08 -05002320 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2321 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
Kan Lianga75e8002016-02-19 09:24:04 -05002322
2323 if (ec->use_adaptive_rx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002324 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002325 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002326 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002327
2328 if (ec->use_adaptive_tx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002329 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002330 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002331 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002332
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002333 q_vector = rx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002334 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
Kan Lianga75e8002016-02-19 09:24:04 -05002335
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002336 q_vector = tx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002337 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2338
2339 /* The interrupt handler itself will take care of programming
2340 * the Tx and Rx ITR values based on the values we have entered
2341 * into the q_vector, no need to write the values now.
2342 */
Kan Lianga75e8002016-02-19 09:24:04 -05002343
Alexander Duyck8b99b112017-12-29 08:50:44 -05002344 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
Kan Lianga75e8002016-02-19 09:24:04 -05002345 i40e_flush(hw);
2346}
2347
Jacob Keller65e87c02016-09-12 14:18:44 -07002348/**
2349 * __i40e_set_coalesce - set coalesce settings for particular queue
2350 * @netdev: the netdev to change
2351 * @ec: ethtool coalesce settings
2352 * @queue: the queue to change
2353 *
2354 * Sets the coalesce settings for a particular queue.
2355 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002356static int __i40e_set_coalesce(struct net_device *netdev,
2357 struct ethtool_coalesce *ec,
2358 int queue)
2359{
2360 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002361 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002362 struct i40e_vsi *vsi = np->vsi;
2363 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002364 int i;
2365
2366 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2367 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2368
Alan Brady06b2dec2017-07-12 05:46:06 -04002369 if (queue < 0) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002370 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2371 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002372 } else if (queue < vsi->num_queue_pairs) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002373 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2374 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002375 } else {
2376 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2377 vsi->num_queue_pairs - 1);
2378 return -EINVAL;
2379 }
2380
2381 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2382 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2383
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002384 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2385 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2386 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2387 return -EINVAL;
2388 }
2389
Alan Brady33084062016-11-28 16:06:03 -08002390 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2391 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2392 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002393 return -EINVAL;
2394 }
2395
Alan Brady06b2dec2017-07-12 05:46:06 -04002396 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2397 ec->use_adaptive_rx_coalesce) {
2398 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2399 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002400 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002401
Alexander Duyck92418fb2017-12-29 08:51:08 -05002402 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002403 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2404 return -EINVAL;
2405 }
2406
2407 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2408 ec->use_adaptive_tx_coalesce) {
2409 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2410 return -EINVAL;
2411 }
2412
Alexander Duyck92418fb2017-12-29 08:51:08 -05002413 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002414 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2415 return -EINVAL;
2416 }
2417
2418 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002419 ec->rx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002420
2421 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002422 ec->tx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002423
Alan Brady33084062016-11-28 16:06:03 -08002424 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2425 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2426 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2427 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2428 vsi->int_rate_limit);
2429 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002430
Alan Bradya03af692017-10-05 14:53:37 -07002431 /* rx and tx usecs has per queue value. If user doesn't specify the
2432 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002433 */
2434 if (queue < 0) {
2435 for (i = 0; i < vsi->num_queue_pairs; i++)
2436 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002437 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002438 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002439 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002440
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002441 return 0;
2442}
2443
Jacob Keller65e87c02016-09-12 14:18:44 -07002444/**
2445 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2446 * @netdev: the netdev to change
2447 * @ec: ethtool coalesce settings
2448 *
2449 * This will set each queue to the same coalesce settings.
2450 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002451static int i40e_set_coalesce(struct net_device *netdev,
2452 struct ethtool_coalesce *ec)
2453{
2454 return __i40e_set_coalesce(netdev, ec, -1);
2455}
2456
Jacob Keller65e87c02016-09-12 14:18:44 -07002457/**
2458 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2459 * @netdev: the netdev to change
2460 * @ec: ethtool's coalesce settings
2461 * @queue: the queue to change
2462 *
2463 * Sets the specified queue's coalesce settings.
2464 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002465static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2466 struct ethtool_coalesce *ec)
2467{
2468 return __i40e_set_coalesce(netdev, ec, queue);
2469}
2470
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002471/**
2472 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2473 * @pf: pointer to the physical function struct
2474 * @cmd: ethtool rxnfc command
2475 *
2476 * Returns Success if the flow is supported, else Invalid Input.
2477 **/
2478static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2479{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002480 struct i40e_hw *hw = &pf->hw;
2481 u8 flow_pctype = 0;
2482 u64 i_set = 0;
2483
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002484 cmd->data = 0;
2485
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002486 switch (cmd->flow_type) {
2487 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002488 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2489 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002490 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002491 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2492 break;
2493 case TCP_V6_FLOW:
2494 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2495 break;
2496 case UDP_V6_FLOW:
2497 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2498 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002499 case SCTP_V4_FLOW:
2500 case AH_ESP_V4_FLOW:
2501 case AH_V4_FLOW:
2502 case ESP_V4_FLOW:
2503 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002504 case SCTP_V6_FLOW:
2505 case AH_ESP_V6_FLOW:
2506 case AH_V6_FLOW:
2507 case ESP_V6_FLOW:
2508 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002509 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002510 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2511 break;
2512 default:
2513 return -EINVAL;
2514 }
2515
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002516 /* Read flow based hash input set register */
2517 if (flow_pctype) {
2518 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2519 flow_pctype)) |
2520 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2521 flow_pctype)) << 32);
2522 }
2523
2524 /* Process bits of hash input set */
2525 if (i_set) {
2526 if (i_set & I40E_L4_SRC_MASK)
2527 cmd->data |= RXH_L4_B_0_1;
2528 if (i_set & I40E_L4_DST_MASK)
2529 cmd->data |= RXH_L4_B_2_3;
2530
2531 if (cmd->flow_type == TCP_V4_FLOW ||
2532 cmd->flow_type == UDP_V4_FLOW) {
2533 if (i_set & I40E_L3_SRC_MASK)
2534 cmd->data |= RXH_IP_SRC;
2535 if (i_set & I40E_L3_DST_MASK)
2536 cmd->data |= RXH_IP_DST;
2537 } else if (cmd->flow_type == TCP_V6_FLOW ||
2538 cmd->flow_type == UDP_V6_FLOW) {
2539 if (i_set & I40E_L3_V6_SRC_MASK)
2540 cmd->data |= RXH_IP_SRC;
2541 if (i_set & I40E_L3_V6_DST_MASK)
2542 cmd->data |= RXH_IP_DST;
2543 }
2544 }
2545
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002546 return 0;
2547}
2548
2549/**
Jacob Kellere7930952017-02-06 14:38:49 -08002550 * i40e_check_mask - Check whether a mask field is set
2551 * @mask: the full mask value
2552 * @field; mask of the field to check
2553 *
2554 * If the given mask is fully set, return positive value. If the mask for the
2555 * field is fully unset, return zero. Otherwise return a negative error code.
2556 **/
2557static int i40e_check_mask(u64 mask, u64 field)
2558{
2559 u64 value = mask & field;
2560
2561 if (value == field)
2562 return 1;
2563 else if (!value)
2564 return 0;
2565 else
2566 return -1;
2567}
2568
2569/**
2570 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2571 * @fsp: pointer to rx flow specification
2572 * @data: pointer to userdef data structure for storage
2573 *
2574 * Read the user-defined data and deconstruct the value into a structure. No
2575 * other code should read the user-defined data, so as to ensure that every
2576 * place consistently reads the value correctly.
2577 *
2578 * The user-defined field is a 64bit Big Endian format value, which we
2579 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2580 * be defined starting from the highest bits, while small bit field values
2581 * shall be defined starting from the lowest bits.
2582 *
2583 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2584 * and the filter should be rejected. The data structure will always be
2585 * modified even if FLOW_EXT is not set.
2586 *
2587 **/
2588static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2589 struct i40e_rx_flow_userdef *data)
2590{
2591 u64 value, mask;
2592 int valid;
2593
2594 /* Zero memory first so it's always consistent. */
2595 memset(data, 0, sizeof(*data));
2596
2597 if (!(fsp->flow_type & FLOW_EXT))
2598 return 0;
2599
2600 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2601 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2602
2603#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2604#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2605#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2606
2607 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2608 if (valid < 0) {
2609 return -EINVAL;
2610 } else if (valid) {
2611 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2612 data->flex_offset =
2613 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2614 data->flex_filter = true;
2615 }
2616
2617 return 0;
2618}
2619
2620/**
2621 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2622 * @fsp: pointer to rx_flow specification
2623 *
2624 * Reads the userdef data structure and properly fills in the user defined
2625 * fields of the rx_flow_spec.
2626 **/
2627static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2628 struct i40e_rx_flow_userdef *data)
2629{
2630 u64 value = 0, mask = 0;
2631
2632 if (data->flex_filter) {
2633 value |= data->flex_word;
2634 value |= (u64)data->flex_offset << 16;
2635 mask |= I40E_USERDEF_FLEX_FILTER;
2636 }
2637
2638 if (value || mask)
2639 fsp->flow_type |= FLOW_EXT;
2640
2641 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2642 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2643}
2644
2645/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002646 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2647 * @pf: Pointer to the physical function struct
2648 * @cmd: The command to get or set Rx flow classification rules
2649 * @rule_locs: Array of used rule locations
2650 *
2651 * This function populates both the total and actual rule count of
2652 * the ethtool flow classification command
2653 *
2654 * Returns 0 on success or -EMSGSIZE if entry not found
2655 **/
2656static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2657 struct ethtool_rxnfc *cmd,
2658 u32 *rule_locs)
2659{
2660 struct i40e_fdir_filter *rule;
2661 struct hlist_node *node2;
2662 int cnt = 0;
2663
2664 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002665 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002666
2667 hlist_for_each_entry_safe(rule, node2,
2668 &pf->fdir_filter_list, fdir_node) {
2669 if (cnt == cmd->rule_cnt)
2670 return -EMSGSIZE;
2671
2672 rule_locs[cnt] = rule->fd_id;
2673 cnt++;
2674 }
2675
2676 cmd->rule_cnt = cnt;
2677
2678 return 0;
2679}
2680
2681/**
2682 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2683 * @pf: Pointer to the physical function struct
2684 * @cmd: The command to get or set Rx flow classification rules
2685 *
2686 * This function looks up a filter based on the Rx flow classification
2687 * command and fills the flow spec info for it if found
2688 *
2689 * Returns 0 on success or -EINVAL if filter not found
2690 **/
2691static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2692 struct ethtool_rxnfc *cmd)
2693{
2694 struct ethtool_rx_flow_spec *fsp =
2695 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002696 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002697 struct i40e_fdir_filter *rule = NULL;
2698 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002699 u64 input_set;
2700 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002701
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002702 hlist_for_each_entry_safe(rule, node2,
2703 &pf->fdir_filter_list, fdir_node) {
2704 if (fsp->location <= rule->fd_id)
2705 break;
2706 }
2707
2708 if (!rule || fsp->location != rule->fd_id)
2709 return -EINVAL;
2710
2711 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002712 if (fsp->flow_type == IP_USER_FLOW) {
2713 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2714 fsp->h_u.usr_ip4_spec.proto = 0;
2715 fsp->m_u.usr_ip4_spec.proto = 0;
2716 }
2717
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002718 /* Reverse the src and dest notion, since the HW views them from
2719 * Tx perspective where as the user expects it from Rx filter view.
2720 */
2721 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2722 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002723 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2724 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002725
Jacob Keller36777d92017-03-07 15:05:23 -08002726 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002727 case SCTP_V4_FLOW:
2728 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2729 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002730 case TCP_V4_FLOW:
2731 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2732 break;
2733 case UDP_V4_FLOW:
2734 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2735 break;
2736 case IP_USER_FLOW:
2737 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2738 break;
2739 default:
2740 /* If we have stored a filter with a flow type not listed here
2741 * it is almost certainly a driver bug. WARN(), and then
2742 * assign the input_set as if all fields are enabled to avoid
2743 * reading unassigned memory.
2744 */
2745 WARN(1, "Missing input set index for flow_type %d\n",
2746 rule->flow_type);
2747 input_set = 0xFFFFFFFFFFFFFFFFULL;
2748 goto no_input_set;
2749 }
2750
2751 input_set = i40e_read_fd_input_set(pf, index);
2752
2753no_input_set:
2754 if (input_set & I40E_L3_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002755 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002756
2757 if (input_set & I40E_L3_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002758 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002759
2760 if (input_set & I40E_L4_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002761 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002762
2763 if (input_set & I40E_L4_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002764 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002765
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002766 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2767 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2768 else
2769 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002770
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002771 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2772 struct i40e_vsi *vsi;
2773
2774 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2775 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002776 /* VFs are zero-indexed by the driver, but ethtool
2777 * expects them to be one-indexed, so add one here
2778 */
2779 u64 ring_vf = vsi->vf_id + 1;
2780
2781 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2782 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002783 }
2784 }
2785
Jacob Keller0e588de2017-02-06 14:38:50 -08002786 if (rule->flex_filter) {
2787 userdef.flex_filter = true;
2788 userdef.flex_word = be16_to_cpu(rule->flex_word);
2789 userdef.flex_offset = rule->flex_offset;
2790 }
2791
Jacob Kellere7930952017-02-06 14:38:49 -08002792 i40e_fill_rx_flow_user_data(fsp, &userdef);
2793
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002794 return 0;
2795}
2796
2797/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002798 * i40e_get_rxnfc - command to get RX flow classification rules
2799 * @netdev: network interface device structure
2800 * @cmd: ethtool rxnfc command
2801 *
2802 * Returns Success if the command is supported.
2803 **/
2804static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2805 u32 *rule_locs)
2806{
2807 struct i40e_netdev_priv *np = netdev_priv(netdev);
2808 struct i40e_vsi *vsi = np->vsi;
2809 struct i40e_pf *pf = vsi->back;
2810 int ret = -EOPNOTSUPP;
2811
2812 switch (cmd->cmd) {
2813 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002814 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002815 ret = 0;
2816 break;
2817 case ETHTOOL_GRXFH:
2818 ret = i40e_get_rss_hash_opts(pf, cmd);
2819 break;
2820 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002821 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002822 /* report total rule count */
2823 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002824 ret = 0;
2825 break;
2826 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002827 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002828 break;
2829 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002830 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2831 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002832 default:
2833 break;
2834 }
2835
2836 return ret;
2837}
2838
2839/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002840 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2841 * @nfc: pointer to user request
2842 * @i_setc bits currently set
2843 *
2844 * Returns value of bits to be set per user request
2845 **/
2846static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2847{
2848 u64 i_set = i_setc;
2849 u64 src_l3 = 0, dst_l3 = 0;
2850
2851 if (nfc->data & RXH_L4_B_0_1)
2852 i_set |= I40E_L4_SRC_MASK;
2853 else
2854 i_set &= ~I40E_L4_SRC_MASK;
2855 if (nfc->data & RXH_L4_B_2_3)
2856 i_set |= I40E_L4_DST_MASK;
2857 else
2858 i_set &= ~I40E_L4_DST_MASK;
2859
2860 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2861 src_l3 = I40E_L3_V6_SRC_MASK;
2862 dst_l3 = I40E_L3_V6_DST_MASK;
2863 } else if (nfc->flow_type == TCP_V4_FLOW ||
2864 nfc->flow_type == UDP_V4_FLOW) {
2865 src_l3 = I40E_L3_SRC_MASK;
2866 dst_l3 = I40E_L3_DST_MASK;
2867 } else {
2868 /* Any other flow type are not supported here */
2869 return i_set;
2870 }
2871
2872 if (nfc->data & RXH_IP_SRC)
2873 i_set |= src_l3;
2874 else
2875 i_set &= ~src_l3;
2876 if (nfc->data & RXH_IP_DST)
2877 i_set |= dst_l3;
2878 else
2879 i_set &= ~dst_l3;
2880
2881 return i_set;
2882}
2883
2884/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002885 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2886 * @pf: pointer to the physical function struct
2887 * @cmd: ethtool rxnfc command
2888 *
2889 * Returns Success if the flow input set is supported.
2890 **/
2891static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2892{
2893 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002894 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2895 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002896 u8 flow_pctype = 0;
2897 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002898
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002899 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2900 dev_err(&pf->pdev->dev,
2901 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2902 return -EOPNOTSUPP;
2903 }
2904
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002905 /* RSS does not support anything other than hashing
2906 * to queues on src and dst IPs and ports
2907 */
2908 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2909 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2910 return -EINVAL;
2911
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002912 switch (nfc->flow_type) {
2913 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002914 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002915 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002916 hena |=
2917 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002918 break;
2919 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002920 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002921 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002922 hena |=
2923 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002924 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002925 hena |=
2926 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002927 break;
2928 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002929 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002930 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002931 hena |=
2932 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2933 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002934
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002935 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002936 break;
2937 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002938 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002939 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002940 hena |=
2941 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2942 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002943
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002944 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002945 break;
2946 case AH_ESP_V4_FLOW:
2947 case AH_V4_FLOW:
2948 case ESP_V4_FLOW:
2949 case SCTP_V4_FLOW:
2950 if ((nfc->data & RXH_L4_B_0_1) ||
2951 (nfc->data & RXH_L4_B_2_3))
2952 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002953 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002954 break;
2955 case AH_ESP_V6_FLOW:
2956 case AH_V6_FLOW:
2957 case ESP_V6_FLOW:
2958 case SCTP_V6_FLOW:
2959 if ((nfc->data & RXH_L4_B_0_1) ||
2960 (nfc->data & RXH_L4_B_2_3))
2961 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002962 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002963 break;
2964 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002965 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2966 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002967 break;
2968 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002969 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2970 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002971 break;
2972 default:
2973 return -EINVAL;
2974 }
2975
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002976 if (flow_pctype) {
2977 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2978 flow_pctype)) |
2979 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2980 flow_pctype)) << 32);
2981 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2982 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2983 (u32)i_set);
2984 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2985 (u32)(i_set >> 32));
2986 hena |= BIT_ULL(flow_pctype);
2987 }
2988
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002989 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2990 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002991 i40e_flush(hw);
2992
2993 return 0;
2994}
2995
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002996/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002997 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2998 * @vsi: Pointer to the targeted VSI
2999 * @input: The filter to update or NULL to indicate deletion
3000 * @sw_idx: Software index to the filter
3001 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003002 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003003 * This function updates (or deletes) a Flow Director entry from
3004 * the hlist of the corresponding PF
3005 *
3006 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003007 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003008static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
3009 struct i40e_fdir_filter *input,
3010 u16 sw_idx,
3011 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003012{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003013 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003014 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003015 struct hlist_node *node2;
3016 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003017
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003018 parent = NULL;
3019 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003020
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003021 hlist_for_each_entry_safe(rule, node2,
3022 &pf->fdir_filter_list, fdir_node) {
3023 /* hash found, or no matching entry */
3024 if (rule->fd_id >= sw_idx)
3025 break;
3026 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003027 }
3028
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003029 /* if there is an old rule occupying our place remove it */
3030 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08003031 /* Remove this rule, since we're either deleting it, or
3032 * replacing it.
3033 */
3034 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003035 hlist_del(&rule->fdir_node);
3036 kfree(rule);
3037 pf->fdir_pf_active_filters--;
3038 }
3039
Jacob Kellerc6da5252017-02-06 14:39:13 -08003040 /* If we weren't given an input, this is a delete, so just return the
3041 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003042 */
3043 if (!input)
3044 return err;
3045
Jacob Kellerc6da5252017-02-06 14:39:13 -08003046 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003047 INIT_HLIST_NODE(&input->fdir_node);
3048
3049 /* add filter to the list */
3050 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003051 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003052 else
3053 hlist_add_head(&input->fdir_node,
3054 &pf->fdir_filter_list);
3055
3056 /* update counts */
3057 pf->fdir_pf_active_filters++;
3058
3059 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003060}
3061
3062/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003063 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3064 * @pf: pointer to PF structure
3065 *
3066 * This function searches the list of filters and determines which FLX_PIT
3067 * entries are still required. It will prune any entries which are no longer
3068 * in use after the deletion.
3069 **/
3070static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3071{
3072 struct i40e_flex_pit *entry, *tmp;
3073 struct i40e_fdir_filter *rule;
3074
3075 /* First, we'll check the l3 table */
3076 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3077 bool found = false;
3078
3079 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3080 if (rule->flow_type != IP_USER_FLOW)
3081 continue;
3082 if (rule->flex_filter &&
3083 rule->flex_offset == entry->src_offset) {
3084 found = true;
3085 break;
3086 }
3087 }
3088
3089 /* If we didn't find the filter, then we can prune this entry
3090 * from the list.
3091 */
3092 if (!found) {
3093 list_del(&entry->list);
3094 kfree(entry);
3095 }
3096 }
3097
3098 /* Followed by the L4 table */
3099 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3100 bool found = false;
3101
3102 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3103 /* Skip this filter if it's L3, since we already
3104 * checked those in the above loop
3105 */
3106 if (rule->flow_type == IP_USER_FLOW)
3107 continue;
3108 if (rule->flex_filter &&
3109 rule->flex_offset == entry->src_offset) {
3110 found = true;
3111 break;
3112 }
3113 }
3114
3115 /* If we didn't find the filter, then we can prune this entry
3116 * from the list.
3117 */
3118 if (!found) {
3119 list_del(&entry->list);
3120 kfree(entry);
3121 }
3122 }
3123}
3124
3125/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003126 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3127 * @vsi: Pointer to the targeted VSI
3128 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003129 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003130 * The function removes a Flow Director filter entry from the
3131 * hlist of the corresponding PF
3132 *
3133 * Returns 0 on success
3134 */
3135static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3136 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003137{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003138 struct ethtool_rx_flow_spec *fsp =
3139 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003140 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003141 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003142
Jacob Keller0da36b92017-04-19 09:25:55 -04003143 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3144 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003145 return -EBUSY;
3146
Jacob Keller0da36b92017-04-19 09:25:55 -04003147 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003148 return -EBUSY;
3149
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003150 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003151
Jacob Keller0e588de2017-02-06 14:38:50 -08003152 i40e_prune_flex_pit_list(pf);
3153
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003154 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003155 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003156}
3157
3158/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003159 * i40e_unused_pit_index - Find an unused PIT index for given list
3160 * @pf: the PF data structure
3161 *
3162 * Find the first unused flexible PIT index entry. We search both the L3 and
3163 * L4 flexible PIT lists so that the returned index is unique and unused by
3164 * either currently programmed L3 or L4 filters. We use a bit field as storage
3165 * to track which indexes are already used.
3166 **/
3167static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3168{
3169 unsigned long available_index = 0xFF;
3170 struct i40e_flex_pit *entry;
3171
3172 /* We need to make sure that the new index isn't in use by either L3
3173 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3174 * L4 to use the same index.
3175 */
3176
3177 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3178 clear_bit(entry->pit_index, &available_index);
3179
3180 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3181 clear_bit(entry->pit_index, &available_index);
3182
3183 return find_first_bit(&available_index, 8);
3184}
3185
3186/**
3187 * i40e_find_flex_offset - Find an existing flex src_offset
3188 * @flex_pit_list: L3 or L4 flex PIT list
3189 * @src_offset: new src_offset to find
3190 *
3191 * Searches the flex_pit_list for an existing offset. If no offset is
3192 * currently programmed, then this will return an ERR_PTR if there is no space
3193 * to add a new offset, otherwise it returns NULL.
3194 **/
3195static
3196struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3197 u16 src_offset)
3198{
3199 struct i40e_flex_pit *entry;
3200 int size = 0;
3201
3202 /* Search for the src_offset first. If we find a matching entry
3203 * already programmed, we can simply re-use it.
3204 */
3205 list_for_each_entry(entry, flex_pit_list, list) {
3206 size++;
3207 if (entry->src_offset == src_offset)
3208 return entry;
3209 }
3210
3211 /* If we haven't found an entry yet, then the provided src offset has
3212 * not yet been programmed. We will program the src offset later on,
3213 * but we need to indicate whether there is enough space to do so
3214 * here. We'll make use of ERR_PTR for this purpose.
3215 */
3216 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3217 return ERR_PTR(-ENOSPC);
3218
3219 return NULL;
3220}
3221
3222/**
3223 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3224 * @flex_pit_list: L3 or L4 flex PIT list
3225 * @src_offset: new src_offset to add
3226 * @pit_index: the PIT index to program
3227 *
3228 * This function programs the new src_offset to the list. It is expected that
3229 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3230 * that this offset is not programmed, and that the list has enough space to
3231 * store another offset.
3232 *
3233 * Returns 0 on success, and negative value on error.
3234 **/
3235static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3236 u16 src_offset,
3237 u8 pit_index)
3238{
3239 struct i40e_flex_pit *new_pit, *entry;
3240
3241 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3242 if (!new_pit)
3243 return -ENOMEM;
3244
3245 new_pit->src_offset = src_offset;
3246 new_pit->pit_index = pit_index;
3247
3248 /* We need to insert this item such that the list is sorted by
3249 * src_offset in ascending order.
3250 */
3251 list_for_each_entry(entry, flex_pit_list, list) {
3252 if (new_pit->src_offset < entry->src_offset) {
3253 list_add_tail(&new_pit->list, &entry->list);
3254 return 0;
3255 }
3256
3257 /* If we found an entry with our offset already programmed we
3258 * can simply return here, after freeing the memory. However,
3259 * if the pit_index does not match we need to report an error.
3260 */
3261 if (new_pit->src_offset == entry->src_offset) {
3262 int err = 0;
3263
3264 /* If the PIT index is not the same we can't re-use
3265 * the entry, so we must report an error.
3266 */
3267 if (new_pit->pit_index != entry->pit_index)
3268 err = -EINVAL;
3269
3270 kfree(new_pit);
3271 return err;
3272 }
3273 }
3274
3275 /* If we reached here, then we haven't yet added the item. This means
3276 * that we should add the item at the end of the list.
3277 */
3278 list_add_tail(&new_pit->list, flex_pit_list);
3279 return 0;
3280}
3281
3282/**
3283 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3284 * @pf: Pointer to the PF structure
3285 * @flex_pit_list: list of flexible src offsets in use
3286 * #flex_pit_start: index to first entry for this section of the table
3287 *
3288 * In order to handle flexible data, the hardware uses a table of values
3289 * called the FLX_PIT table. This table is used to indicate which sections of
3290 * the input correspond to what PIT index values. Unfortunately, hardware is
3291 * very restrictive about programming this table. Entries must be ordered by
3292 * src_offset in ascending order, without duplicates. Additionally, unused
3293 * entries must be set to the unused index value, and must have valid size and
3294 * length according to the src_offset ordering.
3295 *
3296 * This function will reprogram the FLX_PIT register from a book-keeping
3297 * structure that we guarantee is already ordered correctly, and has no more
3298 * than 3 entries.
3299 *
3300 * To make things easier, we only support flexible values of one word length,
3301 * rather than allowing variable length flexible values.
3302 **/
3303static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3304 struct list_head *flex_pit_list,
3305 int flex_pit_start)
3306{
3307 struct i40e_flex_pit *entry = NULL;
3308 u16 last_offset = 0;
3309 int i = 0, j = 0;
3310
3311 /* First, loop over the list of flex PIT entries, and reprogram the
3312 * registers.
3313 */
3314 list_for_each_entry(entry, flex_pit_list, list) {
3315 /* We have to be careful when programming values for the
3316 * largest SRC_OFFSET value. It is possible that adding
3317 * additional empty values at the end would overflow the space
3318 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3319 * we check here and add the empty values prior to adding the
3320 * largest value.
3321 *
3322 * To determine this, we will use a loop from i+1 to 3, which
3323 * will determine whether the unused entries would have valid
3324 * SRC_OFFSET. Note that there cannot be extra entries past
3325 * this value, because the only valid values would have been
3326 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3327 * have been added to the list in the first place.
3328 */
3329 for (j = i + 1; j < 3; j++) {
3330 u16 offset = entry->src_offset + j;
3331 int index = flex_pit_start + i;
3332 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3333 1,
3334 offset - 3);
3335
3336 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3337 i40e_write_rx_ctl(&pf->hw,
3338 I40E_PRTQF_FLX_PIT(index),
3339 value);
3340 i++;
3341 }
3342 }
3343
3344 /* Now, we can program the actual value into the table */
3345 i40e_write_rx_ctl(&pf->hw,
3346 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3347 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3348 1,
3349 entry->src_offset));
3350 i++;
3351 }
3352
3353 /* In order to program the last entries in the table, we need to
3354 * determine the valid offset. If the list is empty, we'll just start
3355 * with 0. Otherwise, we'll start with the last item offset and add 1.
3356 * This ensures that all entries have valid sizes. If we don't do this
3357 * correctly, the hardware will disable flexible field parsing.
3358 */
3359 if (!list_empty(flex_pit_list))
3360 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3361
3362 for (; i < 3; i++, last_offset++) {
3363 i40e_write_rx_ctl(&pf->hw,
3364 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3365 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3366 1,
3367 last_offset));
3368 }
3369}
3370
3371/**
3372 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3373 * @pf: pointer to the PF structure
3374 *
3375 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3376 * internal helper function for implementation details.
3377 **/
3378static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3379{
3380 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3381 I40E_FLEX_PIT_IDX_START_L3);
3382
3383 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3384 I40E_FLEX_PIT_IDX_START_L4);
3385
3386 /* We also need to program the L3 and L4 GLQF ORT register */
3387 i40e_write_rx_ctl(&pf->hw,
3388 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3389 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3390 3, 1));
3391
3392 i40e_write_rx_ctl(&pf->hw,
3393 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3394 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3395 3, 1));
3396}
3397
3398/**
Jacob Keller9229e992017-02-06 14:38:47 -08003399 * i40e_flow_str - Converts a flow_type into a human readable string
3400 * @flow_type: the flow type from a flow specification
3401 *
3402 * Currently only flow types we support are included here, and the string
3403 * value attempts to match what ethtool would use to configure this flow type.
3404 **/
3405static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3406{
3407 switch (fsp->flow_type & ~FLOW_EXT) {
3408 case TCP_V4_FLOW:
3409 return "tcp4";
3410 case UDP_V4_FLOW:
3411 return "udp4";
3412 case SCTP_V4_FLOW:
3413 return "sctp4";
3414 case IP_USER_FLOW:
3415 return "ip4";
3416 default:
3417 return "unknown";
3418 }
3419}
3420
3421/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003422 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3423 * @pit_index: PIT index to convert
3424 *
3425 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3426 * of range.
3427 **/
3428static u64 i40e_pit_index_to_mask(int pit_index)
3429{
3430 switch (pit_index) {
3431 case 0:
3432 return I40E_FLEX_50_MASK;
3433 case 1:
3434 return I40E_FLEX_51_MASK;
3435 case 2:
3436 return I40E_FLEX_52_MASK;
3437 case 3:
3438 return I40E_FLEX_53_MASK;
3439 case 4:
3440 return I40E_FLEX_54_MASK;
3441 case 5:
3442 return I40E_FLEX_55_MASK;
3443 case 6:
3444 return I40E_FLEX_56_MASK;
3445 case 7:
3446 return I40E_FLEX_57_MASK;
3447 default:
3448 return 0;
3449 }
3450}
3451
3452/**
Jacob Keller9229e992017-02-06 14:38:47 -08003453 * i40e_print_input_set - Show changes between two input sets
3454 * @vsi: the vsi being configured
3455 * @old: the old input set
3456 * @new: the new input set
3457 *
3458 * Print the difference between old and new input sets by showing which series
3459 * of words are toggled on or off. Only displays the bits we actually support
3460 * changing.
3461 **/
3462static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3463{
3464 struct i40e_pf *pf = vsi->back;
3465 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003466 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003467
3468 old_value = !!(old & I40E_L3_SRC_MASK);
3469 new_value = !!(new & I40E_L3_SRC_MASK);
3470 if (old_value != new_value)
3471 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3472 old_value ? "ON" : "OFF",
3473 new_value ? "ON" : "OFF");
3474
3475 old_value = !!(old & I40E_L3_DST_MASK);
3476 new_value = !!(new & I40E_L3_DST_MASK);
3477 if (old_value != new_value)
3478 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3479 old_value ? "ON" : "OFF",
3480 new_value ? "ON" : "OFF");
3481
3482 old_value = !!(old & I40E_L4_SRC_MASK);
3483 new_value = !!(new & I40E_L4_SRC_MASK);
3484 if (old_value != new_value)
3485 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3486 old_value ? "ON" : "OFF",
3487 new_value ? "ON" : "OFF");
3488
3489 old_value = !!(old & I40E_L4_DST_MASK);
3490 new_value = !!(new & I40E_L4_DST_MASK);
3491 if (old_value != new_value)
3492 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3493 old_value ? "ON" : "OFF",
3494 new_value ? "ON" : "OFF");
3495
3496 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3497 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3498 if (old_value != new_value)
3499 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3500 old_value ? "ON" : "OFF",
3501 new_value ? "ON" : "OFF");
3502
Jacob Keller0e588de2017-02-06 14:38:50 -08003503 /* Show change of flexible filter entries */
3504 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3505 u64 flex_mask = i40e_pit_index_to_mask(i);
3506
3507 old_value = !!(old & flex_mask);
3508 new_value = !!(new & flex_mask);
3509 if (old_value != new_value)
3510 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3511 i,
3512 old_value ? "ON" : "OFF",
3513 new_value ? "ON" : "OFF");
3514 }
3515
Jacob Keller9229e992017-02-06 14:38:47 -08003516 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3517 old);
3518 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3519 new);
3520}
3521
3522/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003523 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003524 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003525 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003526 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003527 *
Jacob Keller9229e992017-02-06 14:38:47 -08003528 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3529 * for partial matches exists with a few limitations. First, hardware only
3530 * supports masking by word boundary (2 bytes) and not per individual bit.
3531 * Second, hardware is limited to using one mask for a flow type and cannot
3532 * use a separate mask for each filter.
3533 *
3534 * To support these limitations, if we already have a configured filter for
3535 * the specified type, this function enforces that new filters of the type
3536 * match the configured input set. Otherwise, if we do not have a filter of
3537 * the specified type, we allow the input set to be updated to match the
3538 * desired filter.
3539 *
3540 * To help ensure that administrators understand why filters weren't displayed
3541 * as supported, we print a diagnostic message displaying how the input set
3542 * would change and warning to delete the preexisting filters if required.
3543 *
3544 * Returns 0 on successful input set match, and a negative return code on
3545 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003546 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003547static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003548 struct ethtool_rx_flow_spec *fsp,
3549 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003550{
Jacob Keller36777d92017-03-07 15:05:23 -08003551 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003552 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3553 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003554 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003555 bool new_flex_offset = false;
3556 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003557 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003558 u16 index, src_offset = 0;
3559 u8 pit_index = 0;
3560 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003561
3562 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003563 case SCTP_V4_FLOW:
3564 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3565 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3566 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003567 case TCP_V4_FLOW:
3568 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003569 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003570 break;
3571 case UDP_V4_FLOW:
3572 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003573 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003574 break;
3575 case IP_USER_FLOW:
3576 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003577 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003578 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003579 break;
3580 default:
3581 return -EOPNOTSUPP;
3582 }
3583
3584 /* Read the current input set from register memory. */
3585 current_mask = i40e_read_fd_input_set(pf, index);
3586 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003587
Jacob Keller9229e992017-02-06 14:38:47 -08003588 /* Determine, if any, the required changes to the input set in order
3589 * to support the provided mask.
3590 *
3591 * Hardware only supports masking at word (2 byte) granularity and does
3592 * not support full bitwise masking. This implementation simplifies
3593 * even further and only supports fully enabled or fully disabled
3594 * masks for each field, even though we could split the ip4src and
3595 * ip4dst fields.
3596 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003597 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003598 case SCTP_V4_FLOW:
3599 new_mask &= ~I40E_VERIFY_TAG_MASK;
3600 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003601 case TCP_V4_FLOW:
3602 case UDP_V4_FLOW:
3603 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3604
3605 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003606 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3607 new_mask |= I40E_L3_SRC_MASK;
3608 else if (!tcp_ip4_spec->ip4src)
3609 new_mask &= ~I40E_L3_SRC_MASK;
3610 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003611 return -EOPNOTSUPP;
3612
3613 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003614 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3615 new_mask |= I40E_L3_DST_MASK;
3616 else if (!tcp_ip4_spec->ip4dst)
3617 new_mask &= ~I40E_L3_DST_MASK;
3618 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003619 return -EOPNOTSUPP;
3620
3621 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003622 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3623 new_mask |= I40E_L4_SRC_MASK;
3624 else if (!tcp_ip4_spec->psrc)
3625 new_mask &= ~I40E_L4_SRC_MASK;
3626 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003627 return -EOPNOTSUPP;
3628
3629 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003630 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3631 new_mask |= I40E_L4_DST_MASK;
3632 else if (!tcp_ip4_spec->pdst)
3633 new_mask &= ~I40E_L4_DST_MASK;
3634 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003635 return -EOPNOTSUPP;
3636
3637 /* Filtering on Type of Service is not supported. */
3638 if (tcp_ip4_spec->tos)
3639 return -EOPNOTSUPP;
3640
3641 break;
3642 case IP_USER_FLOW:
3643 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3644
3645 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003646 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3647 new_mask |= I40E_L3_SRC_MASK;
3648 else if (!usr_ip4_spec->ip4src)
3649 new_mask &= ~I40E_L3_SRC_MASK;
3650 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003651 return -EOPNOTSUPP;
3652
3653 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003654 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3655 new_mask |= I40E_L3_DST_MASK;
3656 else if (!usr_ip4_spec->ip4dst)
3657 new_mask &= ~I40E_L3_DST_MASK;
3658 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003659 return -EOPNOTSUPP;
3660
3661 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003662 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3663 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3664 else if (!usr_ip4_spec->l4_4_bytes)
3665 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3666 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003667 return -EOPNOTSUPP;
3668
3669 /* Filtering on Type of Service is not supported. */
3670 if (usr_ip4_spec->tos)
3671 return -EOPNOTSUPP;
3672
Jacob Keller0e588de2017-02-06 14:38:50 -08003673 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003674 if (usr_ip4_spec->ip_ver)
3675 return -EINVAL;
3676
Jacob Keller0e588de2017-02-06 14:38:50 -08003677 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003678 if (usr_ip4_spec->proto)
3679 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003680
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003681 break;
3682 default:
3683 return -EOPNOTSUPP;
3684 }
3685
Jacob Keller0e588de2017-02-06 14:38:50 -08003686 /* First, clear all flexible filter entries */
3687 new_mask &= ~I40E_FLEX_INPUT_MASK;
3688
3689 /* If we have a flexible filter, try to add this offset to the correct
3690 * flexible filter PIT list. Once finished, we can update the mask.
3691 * If the src_offset changed, we will get a new mask value which will
3692 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003693 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003694 if (userdef->flex_filter) {
3695 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3696
3697 /* Flexible offset must be even, since the flexible payload
3698 * must be aligned on 2-byte boundary.
3699 */
3700 if (userdef->flex_offset & 0x1) {
3701 dev_warn(&pf->pdev->dev,
3702 "Flexible data offset must be 2-byte aligned\n");
3703 return -EINVAL;
3704 }
3705
3706 src_offset = userdef->flex_offset >> 1;
3707
3708 /* FLX_PIT source offset value is only so large */
3709 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3710 dev_warn(&pf->pdev->dev,
3711 "Flexible data must reside within first 64 bytes of the packet payload\n");
3712 return -EINVAL;
3713 }
3714
3715 /* See if this offset has already been programmed. If we get
3716 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3717 * if we get a NULL pointer, this means we will need to add
3718 * the offset.
3719 */
3720 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3721 src_offset);
3722 if (IS_ERR(flex_pit))
3723 return PTR_ERR(flex_pit);
3724
3725 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3726 * packet types, and thus we need to program both L3 and L4
3727 * flexible values. These must have identical flexible index,
3728 * as otherwise we can't correctly program the input set. So
3729 * we'll find both an L3 and L4 index and make sure they are
3730 * the same.
3731 */
3732 if (flex_l3) {
3733 l3_flex_pit =
3734 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3735 src_offset);
3736 if (IS_ERR(l3_flex_pit))
3737 return PTR_ERR(l3_flex_pit);
3738
3739 if (flex_pit) {
3740 /* If we already had a matching L4 entry, we
3741 * need to make sure that the L3 entry we
3742 * obtained uses the same index.
3743 */
3744 if (l3_flex_pit) {
3745 if (l3_flex_pit->pit_index !=
3746 flex_pit->pit_index) {
3747 return -EINVAL;
3748 }
3749 } else {
3750 new_flex_offset = true;
3751 }
3752 } else {
3753 flex_pit = l3_flex_pit;
3754 }
3755 }
3756
3757 /* If we didn't find an existing flex offset, we need to
3758 * program a new one. However, we don't immediately program it
3759 * here because we will wait to program until after we check
3760 * that it is safe to change the input set.
3761 */
3762 if (!flex_pit) {
3763 new_flex_offset = true;
3764 pit_index = i40e_unused_pit_index(pf);
3765 } else {
3766 pit_index = flex_pit->pit_index;
3767 }
3768
3769 /* Update the mask with the new offset */
3770 new_mask |= i40e_pit_index_to_mask(pit_index);
3771 }
3772
3773 /* If the mask and flexible filter offsets for this filter match the
3774 * currently programmed values we don't need any input set change, so
3775 * this filter is safe to install.
3776 */
3777 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003778 return 0;
3779
3780 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3781 i40e_flow_str(fsp));
3782 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003783 if (new_flex_offset) {
3784 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3785 pit_index, src_offset);
3786 }
Jacob Keller9229e992017-02-06 14:38:47 -08003787
3788 /* Hardware input sets are global across multiple ports, so even the
3789 * main port cannot change them when in MFP mode as this would impact
3790 * any filters on the other ports.
3791 */
3792 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3793 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003794 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003795 }
3796
3797 /* This filter requires us to update the input set. However, hardware
3798 * only supports one input set per flow type, and does not support
3799 * separate masks for each filter. This means that we can only support
3800 * a single mask for all filters of a specific type.
3801 *
3802 * If we have preexisting filters, they obviously depend on the
3803 * current programmed input set. Display a diagnostic message in this
3804 * case explaining why the filter could not be accepted.
3805 */
3806 if (*fdir_filter_count) {
3807 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3808 i40e_flow_str(fsp),
3809 *fdir_filter_count);
3810 return -EOPNOTSUPP;
3811 }
3812
3813 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003814
Jacob Keller02b40162017-12-27 08:24:12 -05003815 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
3816 * frames. If we're programming the input set for IPv4/Other, we also
3817 * need to program the IPv4/Fragmented input set. Since we don't have
3818 * separate support, we'll always assume and enforce that the two flow
3819 * types must have matching input sets.
3820 */
3821 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
3822 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
3823 new_mask);
3824
Jacob Keller0e588de2017-02-06 14:38:50 -08003825 /* Add the new offset and update table, if necessary */
3826 if (new_flex_offset) {
3827 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3828 pit_index);
3829 if (err)
3830 return err;
3831
3832 if (flex_l3) {
3833 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3834 src_offset,
3835 pit_index);
3836 if (err)
3837 return err;
3838 }
3839
3840 i40e_reprogram_flex_pit(pf);
3841 }
3842
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003843 return 0;
3844}
3845
3846/**
Jacob Keller443ee712017-12-27 08:25:32 -05003847 * i40e_match_fdir_filter - Return true of two filters match
3848 * @a: pointer to filter struct
3849 * @b: pointer to filter struct
3850 *
3851 * Returns true if the two filters match exactly the same criteria. I.e. they
3852 * match the same flow type and have the same parameters. We don't need to
3853 * check any input-set since all filters of the same flow type must use the
3854 * same input set.
3855 **/
3856static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
3857 struct i40e_fdir_filter *b)
3858{
3859 /* The filters do not much if any of these criteria differ. */
3860 if (a->dst_ip != b->dst_ip ||
3861 a->src_ip != b->src_ip ||
3862 a->dst_port != b->dst_port ||
3863 a->src_port != b->src_port ||
3864 a->flow_type != b->flow_type ||
3865 a->ip4_proto != b->ip4_proto)
3866 return false;
3867
3868 return true;
3869}
3870
3871/**
3872 * i40e_disallow_matching_filters - Check that new filters differ
3873 * @vsi: pointer to the targeted VSI
3874 * @input: new filter to check
3875 *
3876 * Due to hardware limitations, it is not possible for two filters that match
3877 * similar criteria to be programmed at the same time. This is true for a few
3878 * reasons:
3879 *
3880 * (a) all filters matching a particular flow type must use the same input
3881 * set, that is they must match the same criteria.
3882 * (b) different flow types will never match the same packet, as the flow type
3883 * is decided by hardware before checking which rules apply.
3884 * (c) hardware has no way to distinguish which order filters apply in.
3885 *
3886 * Due to this, we can't really support using the location data to order
3887 * filters in the hardware parsing. It is technically possible for the user to
3888 * request two filters matching the same criteria but which select different
3889 * queues. In this case, rather than keep both filters in the list, we reject
3890 * the 2nd filter when the user requests adding it.
3891 *
3892 * This avoids needing to track location for programming the filter to
3893 * hardware, and ensures that we avoid some strange scenarios involving
3894 * deleting filters which match the same criteria.
3895 **/
3896static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
3897 struct i40e_fdir_filter *input)
3898{
3899 struct i40e_pf *pf = vsi->back;
3900 struct i40e_fdir_filter *rule;
3901 struct hlist_node *node2;
3902
3903 /* Loop through every filter, and check that it doesn't match */
3904 hlist_for_each_entry_safe(rule, node2,
3905 &pf->fdir_filter_list, fdir_node) {
3906 /* Don't check the filters match if they share the same fd_id,
3907 * since the new filter is actually just updating the target
3908 * of the old filter.
3909 */
3910 if (rule->fd_id == input->fd_id)
3911 continue;
3912
3913 /* If any filters match, then print a warning message to the
3914 * kernel message buffer and bail out.
3915 */
3916 if (i40e_match_fdir_filter(rule, input)) {
3917 dev_warn(&pf->pdev->dev,
3918 "Existing user defined filter %d already matches this flow.\n",
3919 rule->fd_id);
3920 return -EINVAL;
3921 }
3922 }
3923
3924 return 0;
3925}
3926
3927/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003928 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003929 * @vsi: pointer to the targeted VSI
3930 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003931 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003932 * Add Flow Director filters for a specific flow spec based on their
3933 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003934 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003935static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3936 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003937{
Jacob Kellere7930952017-02-06 14:38:49 -08003938 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003939 struct ethtool_rx_flow_spec *fsp;
3940 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003941 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003942 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003943 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003944 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003945
3946 if (!vsi)
3947 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003948 pf = vsi->back;
3949
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003950 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3951 return -EOPNOTSUPP;
3952
Jacob Keller47994c12017-04-19 09:25:57 -04003953 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003954 return -ENOSPC;
3955
Jacob Keller0da36b92017-04-19 09:25:55 -04003956 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3957 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003958 return -EBUSY;
3959
Jacob Keller0da36b92017-04-19 09:25:55 -04003960 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003961 return -EBUSY;
3962
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003963 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3964
Jacob Kellere7930952017-02-06 14:38:49 -08003965 /* Parse the user-defined field */
3966 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3967 return -EINVAL;
3968
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003969 /* Extended MAC field is not supported */
3970 if (fsp->flow_type & FLOW_MAC_EXT)
3971 return -EINVAL;
3972
Jacob Keller0e588de2017-02-06 14:38:50 -08003973 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003974 if (ret)
3975 return ret;
3976
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003977 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3978 pf->hw.func_caps.fd_filters_guaranteed)) {
3979 return -EINVAL;
3980 }
3981
Jacob Keller43b15692017-02-06 14:38:48 -08003982 /* ring_cookie is either the drop index, or is a mask of the queue
3983 * index and VF id we wish to target.
3984 */
3985 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3986 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3987 } else {
3988 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3989 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3990
3991 if (!vf) {
3992 if (ring >= vsi->num_queue_pairs)
3993 return -EINVAL;
3994 dest_vsi = vsi->id;
3995 } else {
3996 /* VFs are zero-indexed, so we subtract one here */
3997 vf--;
3998
3999 if (vf >= pf->num_alloc_vfs)
4000 return -EINVAL;
4001 if (ring >= pf->vf[vf].num_queue_pairs)
4002 return -EINVAL;
4003 dest_vsi = pf->vf[vf].lan_vsi_id;
4004 }
4005 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
4006 q_index = ring;
4007 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004008
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004009 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004010
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004011 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004012 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004013
4014 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08004015 input->q_index = q_index;
4016 input->dest_vsi = dest_vsi;
4017 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004018 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04004019 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08004020 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4021 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08004022 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004023 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00004024
4025 /* Reverse the src and dest notion, since the HW expects them to be from
4026 * Tx perspective where as the input from user is from Rx filter view.
4027 */
4028 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4029 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08004030 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4031 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004032
Jacob Keller0e588de2017-02-06 14:38:50 -08004033 if (userdef.flex_filter) {
4034 input->flex_filter = true;
4035 input->flex_word = cpu_to_be16(userdef.flex_word);
4036 input->flex_offset = userdef.flex_offset;
4037 }
4038
Jacob Keller443ee712017-12-27 08:25:32 -05004039 /* Avoid programming two filters with identical match criteria. */
4040 ret = i40e_disallow_matching_filters(vsi, input);
4041 if (ret)
4042 goto free_filter_memory;
4043
Jacob Keller01016da2017-02-06 14:38:40 -08004044 /* Add the input filter to the fdir_input_list, possibly replacing
4045 * a previous filter. Do not free the input structure after adding it
4046 * to the list as this would cause a use-after-free bug.
4047 */
4048 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Patryk Małekca6e1d02017-12-27 07:32:31 -05004049 ret = i40e_add_del_fdir(vsi, input, true);
4050 if (ret)
4051 goto remove_sw_rule;
Jacob Keller01016da2017-02-06 14:38:40 -08004052 return 0;
4053
Patryk Małekca6e1d02017-12-27 07:32:31 -05004054remove_sw_rule:
4055 hlist_del(&input->fdir_node);
4056 pf->fdir_pf_active_filters--;
Jacob Keller443ee712017-12-27 08:25:32 -05004057free_filter_memory:
Jacob Keller01016da2017-02-06 14:38:40 -08004058 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004059 return ret;
4060}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08004061
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004062/**
4063 * i40e_set_rxnfc - command to set RX flow classification rules
4064 * @netdev: network interface device structure
4065 * @cmd: ethtool rxnfc command
4066 *
4067 * Returns Success if the command is supported.
4068 **/
4069static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4070{
4071 struct i40e_netdev_priv *np = netdev_priv(netdev);
4072 struct i40e_vsi *vsi = np->vsi;
4073 struct i40e_pf *pf = vsi->back;
4074 int ret = -EOPNOTSUPP;
4075
4076 switch (cmd->cmd) {
4077 case ETHTOOL_SRXFH:
4078 ret = i40e_set_rss_hash_opt(pf, cmd);
4079 break;
4080 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00004081 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004082 break;
4083 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004084 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004085 break;
4086 default:
4087 break;
4088 }
4089
4090 return ret;
4091}
4092
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004093/**
4094 * i40e_max_channels - get Max number of combined channels supported
4095 * @vsi: vsi pointer
4096 **/
4097static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4098{
4099 /* TODO: This code assumes DCB and FD is disabled for now. */
4100 return vsi->alloc_queue_pairs;
4101}
4102
4103/**
4104 * i40e_get_channels - Get the current channels enabled and max supported etc.
4105 * @netdev: network interface device structure
4106 * @ch: ethtool channels structure
4107 *
4108 * We don't support separate tx and rx queues as channels. The other count
4109 * represents how many queues are being used for control. max_combined counts
4110 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4111 * q_vectors since we support a lot more queue pairs than q_vectors.
4112 **/
4113static void i40e_get_channels(struct net_device *dev,
4114 struct ethtool_channels *ch)
4115{
4116 struct i40e_netdev_priv *np = netdev_priv(dev);
4117 struct i40e_vsi *vsi = np->vsi;
4118 struct i40e_pf *pf = vsi->back;
4119
4120 /* report maximum channels */
4121 ch->max_combined = i40e_max_channels(vsi);
4122
4123 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004124 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004125 ch->max_other = ch->other_count;
4126
4127 /* Note: This code assumes DCB is disabled for now. */
4128 ch->combined_count = vsi->num_queue_pairs;
4129}
4130
4131/**
4132 * i40e_set_channels - Set the new channels count.
4133 * @netdev: network interface device structure
4134 * @ch: ethtool channels structure
4135 *
4136 * The new channels count may not be the same as requested by the user
4137 * since it gets rounded down to a power of 2 value.
4138 **/
4139static int i40e_set_channels(struct net_device *dev,
4140 struct ethtool_channels *ch)
4141{
Jacob Keller59826d92016-07-27 12:02:35 -07004142 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004143 struct i40e_netdev_priv *np = netdev_priv(dev);
4144 unsigned int count = ch->combined_count;
4145 struct i40e_vsi *vsi = np->vsi;
4146 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004147 struct i40e_fdir_filter *rule;
4148 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004149 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004150 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004151
4152 /* We do not support setting channels for any other VSI at present */
4153 if (vsi->type != I40E_VSI_MAIN)
4154 return -EINVAL;
4155
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004156 /* We do not support setting channels via ethtool when TCs are
4157 * configured through mqprio
4158 */
4159 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4160 return -EINVAL;
4161
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004162 /* verify they are not requesting separate vectors */
4163 if (!count || ch->rx_count || ch->tx_count)
4164 return -EINVAL;
4165
4166 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004167 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004168 return -EINVAL;
4169
4170 /* verify the number of channels does not exceed hardware limits */
4171 if (count > i40e_max_channels(vsi))
4172 return -EINVAL;
4173
Jacob Keller59826d92016-07-27 12:02:35 -07004174 /* verify that the number of channels does not invalidate any current
4175 * flow director rules
4176 */
4177 hlist_for_each_entry_safe(rule, node2,
4178 &pf->fdir_filter_list, fdir_node) {
4179 if (rule->dest_ctl != drop && count <= rule->q_index) {
4180 dev_warn(&pf->pdev->dev,
4181 "Existing user defined filter %d assigns flow to queue %d\n",
4182 rule->fd_id, rule->q_index);
4183 err = -EINVAL;
4184 }
4185 }
4186
4187 if (err) {
4188 dev_err(&pf->pdev->dev,
4189 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4190 count);
4191 return err;
4192 }
4193
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004194 /* update feature limits from largest to smallest supported values */
4195 /* TODO: Flow director limit, DCB etc */
4196
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004197 /* use rss_reconfig to rebuild with new queue count and update traffic
4198 * class queue mapping
4199 */
4200 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004201 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004202 return 0;
4203 else
4204 return -EINVAL;
4205}
4206
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004207/**
4208 * i40e_get_rxfh_key_size - get the RSS hash key size
4209 * @netdev: network interface device structure
4210 *
4211 * Returns the table size.
4212 **/
4213static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4214{
4215 return I40E_HKEY_ARRAY_SIZE;
4216}
4217
4218/**
4219 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4220 * @netdev: network interface device structure
4221 *
4222 * Returns the table size.
4223 **/
4224static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4225{
4226 return I40E_HLUT_ARRAY_SIZE;
4227}
4228
Alan Brady21675bd2017-10-05 14:53:33 -07004229/**
4230 * i40e_get_rxfh - get the rx flow hash indirection table
4231 * @netdev: network interface device structure
4232 * @indir: indirection table
4233 * @key: hash key
4234 * @hfunc: hash function
4235 *
4236 * Reads the indirection table directly from the hardware. Returns 0 on
4237 * success.
4238 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004239static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4240 u8 *hfunc)
4241{
4242 struct i40e_netdev_priv *np = netdev_priv(netdev);
4243 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004244 u8 *lut, *seed = NULL;
4245 int ret;
4246 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004247
4248 if (hfunc)
4249 *hfunc = ETH_RSS_HASH_TOP;
4250
4251 if (!indir)
4252 return 0;
4253
Helin Zhang043dd652015-10-21 19:56:23 -04004254 seed = key;
4255 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4256 if (!lut)
4257 return -ENOMEM;
4258 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4259 if (ret)
4260 goto out;
4261 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4262 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004263
Helin Zhang043dd652015-10-21 19:56:23 -04004264out:
4265 kfree(lut);
4266
4267 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004268}
4269
4270/**
4271 * i40e_set_rxfh - set the rx flow hash indirection table
4272 * @netdev: network interface device structure
4273 * @indir: indirection table
4274 * @key: hash key
4275 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004276 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004277 * returns 0 after programming the table.
4278 **/
4279static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4280 const u8 *key, const u8 hfunc)
4281{
4282 struct i40e_netdev_priv *np = netdev_priv(netdev);
4283 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004284 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004285 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004286 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004287
4288 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4289 return -EOPNOTSUPP;
4290
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004291 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004292 if (!vsi->rss_hkey_user) {
4293 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4294 GFP_KERNEL);
4295 if (!vsi->rss_hkey_user)
4296 return -ENOMEM;
4297 }
4298 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4299 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004300 }
Helin Zhang28c58692015-10-26 19:44:27 -04004301 if (!vsi->rss_lut_user) {
4302 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4303 if (!vsi->rss_lut_user)
4304 return -ENOMEM;
4305 }
Helin Zhang043dd652015-10-21 19:56:23 -04004306
Helin Zhang28c58692015-10-26 19:44:27 -04004307 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004308 if (indir)
4309 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4310 vsi->rss_lut_user[i] = (u8)(indir[i]);
4311 else
4312 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4313 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004314
4315 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4316 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004317}
4318
Greg Rose7e45ab42015-02-06 08:52:19 +00004319/**
4320 * i40e_get_priv_flags - report device private flags
4321 * @dev: network interface device structure
4322 *
4323 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004324 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004325 * array.
4326 *
4327 * Returns a u32 bitmap of flags.
4328 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004329static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004330{
4331 struct i40e_netdev_priv *np = netdev_priv(dev);
4332 struct i40e_vsi *vsi = np->vsi;
4333 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004334 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004335
Alexander Duyckaca955d2017-03-10 12:22:01 -08004336 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4337 const struct i40e_priv_flags *priv_flags;
4338
4339 priv_flags = &i40e_gstrings_priv_flags[i];
4340
4341 if (priv_flags->flag & pf->flags)
4342 ret_flags |= BIT(i);
4343 }
4344
4345 if (pf->hw.pf_id != 0)
4346 return ret_flags;
4347
4348 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4349 const struct i40e_priv_flags *priv_flags;
4350
4351 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4352
4353 if (priv_flags->flag & pf->flags)
4354 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004355 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004356
4357 return ret_flags;
4358}
4359
Shannon Nelson9ac77262015-08-27 11:42:40 -04004360/**
4361 * i40e_set_priv_flags - set private flags
4362 * @dev: network interface device structure
4363 * @flags: bit flags to be set
4364 **/
4365static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4366{
4367 struct i40e_netdev_priv *np = netdev_priv(dev);
4368 struct i40e_vsi *vsi = np->vsi;
4369 struct i40e_pf *pf = vsi->back;
Alice Michael60f481b2017-12-27 08:17:50 -05004370 u64 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004371 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004372
Jacob Keller841c9502017-06-23 04:24:50 -04004373 orig_flags = READ_ONCE(pf->flags);
4374 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004375
Alexander Duyckaca955d2017-03-10 12:22:01 -08004376 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4377 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004378
Alexander Duyckaca955d2017-03-10 12:22:01 -08004379 priv_flags = &i40e_gstrings_priv_flags[i];
4380
Alexander Duyckaca955d2017-03-10 12:22:01 -08004381 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004382 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004383 else
Jacob Keller841c9502017-06-23 04:24:50 -04004384 new_flags &= ~(priv_flags->flag);
4385
4386 /* If this is a read-only flag, it can't be changed */
4387 if (priv_flags->read_only &&
4388 ((orig_flags ^ new_flags) & ~BIT(i)))
4389 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004390 }
4391
4392 if (pf->hw.pf_id != 0)
4393 goto flags_complete;
4394
4395 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4396 const struct i40e_priv_flags *priv_flags;
4397
4398 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4399
Alexander Duyckaca955d2017-03-10 12:22:01 -08004400 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004401 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004402 else
Jacob Keller841c9502017-06-23 04:24:50 -04004403 new_flags &= ~(priv_flags->flag);
4404
4405 /* If this is a read-only flag, it can't be changed */
4406 if (priv_flags->read_only &&
4407 ((orig_flags ^ new_flags) & ~BIT(i)))
4408 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004409 }
4410
4411flags_complete:
Alan Bradyfe09ed02017-12-29 08:50:34 -05004412 changed_flags = orig_flags ^ new_flags;
4413
Jacob Keller841c9502017-06-23 04:24:50 -04004414 /* Before we finalize any flag changes, we need to perform some
4415 * checks to ensure that the changes are supported and safe.
4416 */
4417
4418 /* ATR eviction is not supported on all devices */
4419 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4420 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4421 return -EOPNOTSUPP;
4422
Alan Bradyfe09ed02017-12-29 08:50:34 -05004423 /* If the driver detected FW LLDP was disabled on init, this flag could
4424 * be set, however we do not support _changing_ the flag if NPAR is
4425 * enabled or FW API version < 1.7. There are situations where older
4426 * FW versions/NPAR enabled PFs could disable LLDP, however we _must_
4427 * not allow the user to enable/disable LLDP with this flag on
4428 * unsupported FW versions.
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004429 */
Alan Bradyfe09ed02017-12-29 08:50:34 -05004430 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
Dave Ertman7b634352018-01-22 12:00:37 -05004431 if (!(pf->hw_features & I40E_HW_STOPPABLE_FW_LLDP)) {
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004432 dev_warn(&pf->pdev->dev,
Dave Ertman7b634352018-01-22 12:00:37 -05004433 "Device does not support changing FW LLDP\n");
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004434 return -EOPNOTSUPP;
4435 }
4436 }
4437
Jacob Keller841c9502017-06-23 04:24:50 -04004438 /* Compare and exchange the new flags into place. If we failed, that
Jacob Kellerb74f5712017-09-01 13:54:07 -07004439 * is if cmpxchg returns anything but the old value, this means that
Jacob Keller841c9502017-06-23 04:24:50 -04004440 * something else has modified the flags variable since we copied it
4441 * originally. We'll just punt with an error and log something in the
4442 * message buffer.
Alan Bradyfe09ed02017-12-29 08:50:34 -05004443 *
4444 * This is the point of no return for this function. We need to have
4445 * checked any discrepancies or misconfigurations and returned
4446 * EOPNOTSUPP before updating pf->flags here.
Jacob Keller841c9502017-06-23 04:24:50 -04004447 */
Alice Michael60f481b2017-12-27 08:17:50 -05004448 if (cmpxchg64(&pf->flags, orig_flags, new_flags) != orig_flags) {
Jacob Keller841c9502017-06-23 04:24:50 -04004449 dev_warn(&pf->pdev->dev,
4450 "Unable to update pf->flags as it was modified by another thread...\n");
4451 return -EAGAIN;
4452 }
4453
Alexander Duyckaca955d2017-03-10 12:22:01 -08004454 /* Process any additional changes needed as a result of flag changes.
4455 * The changed_flags value reflects the list of bits that were
4456 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004457 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004458
Alexander Duyckaca955d2017-03-10 12:22:01 -08004459 /* Flush current ATR settings if ATR was disabled */
4460 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4461 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004462 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004463 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004464 }
4465
Alexander Duyckaca955d2017-03-10 12:22:01 -08004466 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4467 u16 sw_flags = 0, valid_flags = 0;
4468 int ret;
4469
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004470 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4471 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4472 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4473 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07004474 0, NULL);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004475 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4476 dev_info(&pf->pdev->dev,
4477 "couldn't set switch config bits, err %s aq_err %s\n",
4478 i40e_stat_str(&pf->hw, ret),
4479 i40e_aq_str(&pf->hw,
4480 pf->hw.aq.asq_last_status));
4481 /* not a fatal problem, just keep going */
4482 }
4483 }
4484
Paweł Jabłoński17b4d252017-12-29 08:50:20 -05004485 if ((changed_flags & pf->flags &
4486 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4487 (pf->flags & I40E_FLAG_MFP_ENABLED))
4488 dev_warn(&pf->pdev->dev,
4489 "Turning on link-down-on-close flag may affect other partitions\n");
4490
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004491 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4492 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4493 struct i40e_dcbx_config *dcbcfg;
4494 int i;
4495
4496 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4497 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4498 /* reset local_dcbx_config to default */
4499 dcbcfg = &pf->hw.local_dcbx_config;
4500 dcbcfg->etscfg.willing = 1;
4501 dcbcfg->etscfg.maxtcs = 0;
4502 dcbcfg->etscfg.tcbwtable[0] = 100;
4503 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4504 dcbcfg->etscfg.tcbwtable[i] = 0;
4505 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4506 dcbcfg->etscfg.prioritytable[i] = 0;
4507 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4508 dcbcfg->pfc.willing = 1;
4509 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4510 } else {
4511 i40e_aq_start_lldp(&pf->hw, NULL);
4512 }
4513 }
4514
Alexander Duyckaca955d2017-03-10 12:22:01 -08004515 /* Issue reset to cause things to take effect, as additional bits
4516 * are added we will need to create a mask of bits requiring reset
4517 */
Mitch Williams64615b52017-08-29 05:32:30 -04004518 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4519 I40E_FLAG_LEGACY_RX |
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004520 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4521 I40E_FLAG_DISABLE_FW_LLDP))
Maciej Sosin373149f2017-04-05 07:50:55 -04004522 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004523
Shannon Nelson9ac77262015-08-27 11:42:40 -04004524 return 0;
4525}
4526
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004527/**
4528 * i40e_get_module_info - get (Q)SFP+ module type info
4529 * @netdev: network interface device structure
4530 * @modinfo: module EEPROM size and layout information structure
4531 **/
4532static int i40e_get_module_info(struct net_device *netdev,
4533 struct ethtool_modinfo *modinfo)
4534{
4535 struct i40e_netdev_priv *np = netdev_priv(netdev);
4536 struct i40e_vsi *vsi = np->vsi;
4537 struct i40e_pf *pf = vsi->back;
4538 struct i40e_hw *hw = &pf->hw;
4539 u32 sff8472_comp = 0;
4540 u32 sff8472_swap = 0;
4541 u32 sff8636_rev = 0;
4542 i40e_status status;
4543 u32 type = 0;
4544
4545 /* Check if firmware supports reading module EEPROM. */
4546 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4547 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4548 return -EINVAL;
4549 }
4550
4551 status = i40e_update_link_info(hw);
4552 if (status)
4553 return -EIO;
4554
4555 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4556 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4557 return -EINVAL;
4558 }
4559
4560 type = hw->phy.link_info.module_type[0];
4561
4562 switch (type) {
4563 case I40E_MODULE_TYPE_SFP:
4564 status = i40e_aq_get_phy_register(hw,
4565 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4566 I40E_I2C_EEPROM_DEV_ADDR,
4567 I40E_MODULE_SFF_8472_COMP,
4568 &sff8472_comp, NULL);
4569 if (status)
4570 return -EIO;
4571
4572 status = i40e_aq_get_phy_register(hw,
4573 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4574 I40E_I2C_EEPROM_DEV_ADDR,
4575 I40E_MODULE_SFF_8472_SWAP,
4576 &sff8472_swap, NULL);
4577 if (status)
4578 return -EIO;
4579
4580 /* Check if the module requires address swap to access
4581 * the other EEPROM memory page.
4582 */
4583 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4584 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4585 modinfo->type = ETH_MODULE_SFF_8079;
4586 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4587 } else if (sff8472_comp == 0x00) {
4588 /* Module is not SFF-8472 compliant */
4589 modinfo->type = ETH_MODULE_SFF_8079;
4590 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4591 } else {
4592 modinfo->type = ETH_MODULE_SFF_8472;
4593 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4594 }
4595 break;
4596 case I40E_MODULE_TYPE_QSFP_PLUS:
4597 /* Read from memory page 0. */
4598 status = i40e_aq_get_phy_register(hw,
4599 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4600 0,
4601 I40E_MODULE_REVISION_ADDR,
4602 &sff8636_rev, NULL);
4603 if (status)
4604 return -EIO;
4605 /* Determine revision compliance byte */
4606 if (sff8636_rev > 0x02) {
4607 /* Module is SFF-8636 compliant */
4608 modinfo->type = ETH_MODULE_SFF_8636;
4609 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4610 } else {
4611 modinfo->type = ETH_MODULE_SFF_8436;
4612 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4613 }
4614 break;
4615 case I40E_MODULE_TYPE_QSFP28:
4616 modinfo->type = ETH_MODULE_SFF_8636;
4617 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4618 break;
4619 default:
4620 netdev_err(vsi->netdev, "Module type unrecognized\n");
4621 return -EINVAL;
4622 }
4623 return 0;
4624}
4625
4626/**
4627 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4628 * @netdev: network interface device structure
4629 * @ee: EEPROM dump request structure
4630 * @data: buffer to be filled with EEPROM contents
4631 **/
4632static int i40e_get_module_eeprom(struct net_device *netdev,
4633 struct ethtool_eeprom *ee,
4634 u8 *data)
4635{
4636 struct i40e_netdev_priv *np = netdev_priv(netdev);
4637 struct i40e_vsi *vsi = np->vsi;
4638 struct i40e_pf *pf = vsi->back;
4639 struct i40e_hw *hw = &pf->hw;
4640 bool is_sfp = false;
4641 i40e_status status;
4642 u32 value = 0;
4643 int i;
4644
4645 if (!ee || !ee->len || !data)
4646 return -EINVAL;
4647
4648 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4649 is_sfp = true;
4650
4651 for (i = 0; i < ee->len; i++) {
4652 u32 offset = i + ee->offset;
4653 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4654
4655 /* Check if we need to access the other memory page */
4656 if (is_sfp) {
4657 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4658 offset -= ETH_MODULE_SFF_8079_LEN;
4659 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4660 }
4661 } else {
4662 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4663 /* Compute memory page number and offset. */
4664 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4665 addr++;
4666 }
4667 }
4668
4669 status = i40e_aq_get_phy_register(hw,
4670 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4671 addr, offset, &value, NULL);
4672 if (status)
4673 return -EIO;
4674 data[i] = value;
4675 }
4676 return 0;
4677}
4678
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004679static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004680 .get_drvinfo = i40e_get_drvinfo,
4681 .get_regs_len = i40e_get_regs_len,
4682 .get_regs = i40e_get_regs,
4683 .nway_reset = i40e_nway_reset,
4684 .get_link = ethtool_op_get_link,
4685 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004686 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004687 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004688 .get_eeprom_len = i40e_get_eeprom_len,
4689 .get_eeprom = i40e_get_eeprom,
4690 .get_ringparam = i40e_get_ringparam,
4691 .set_ringparam = i40e_set_ringparam,
4692 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004693 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004694 .get_msglevel = i40e_get_msglevel,
4695 .set_msglevel = i40e_set_msglevel,
4696 .get_rxnfc = i40e_get_rxnfc,
4697 .set_rxnfc = i40e_set_rxnfc,
4698 .self_test = i40e_diag_test,
4699 .get_strings = i40e_get_strings,
4700 .set_phys_id = i40e_set_phys_id,
4701 .get_sset_count = i40e_get_sset_count,
4702 .get_ethtool_stats = i40e_get_ethtool_stats,
4703 .get_coalesce = i40e_get_coalesce,
4704 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004705 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4706 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4707 .get_rxfh = i40e_get_rxfh,
4708 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004709 .get_channels = i40e_get_channels,
4710 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004711 .get_module_info = i40e_get_module_info,
4712 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004713 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004714 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004715 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004716 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004717 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004718 .get_link_ksettings = i40e_get_link_ksettings,
4719 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004720};
4721
4722void i40e_set_ethtool_ops(struct net_device *netdev)
4723{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004724 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004725}