blob: d3d299ab9de3db246ecd8178fa719eb2354f1e21 [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 ||
Patryk Małek88244a42018-03-19 09:28:03 -0700862 hw->device_id == I40E_DEV_ID_20G_KR2_A ||
863 hw->device_id == I40E_DEV_ID_KX_X722) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400864 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
865 return -EOPNOTSUPP;
866 }
867
Alan Brady1c142e12017-10-05 14:53:31 -0700868 /* copy the ksettings to copy_ks to avoid modifying the origin */
869 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000870
Alan Bradycee91992017-10-05 14:53:44 -0700871 /* save autoneg out of ksettings */
872 autoneg = copy_ks.base.autoneg;
873
Philippe Reynesa7f90942017-02-04 22:05:06 +0100874 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700875 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
Alan Bradycee91992017-10-05 14:53:44 -0700876 safe_ks.base.cmd = copy_ks.base.cmd;
877 safe_ks.base.link_mode_masks_nwords =
878 copy_ks.base.link_mode_masks_nwords;
Alan Brady1c142e12017-10-05 14:53:31 -0700879 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100880
Jan Sokolowski32c23b42018-03-19 09:28:03 -0700881 /* Get link modes supported by hardware and check against modes
882 * requested by the user. Return an error if unsupported mode was set.
883 */
884 if (!bitmap_subset(copy_ks.link_modes.advertising,
885 safe_ks.link_modes.supported,
886 __ETHTOOL_LINK_MODE_MASK_NBITS))
887 return -EINVAL;
888
Alan Bradycee91992017-10-05 14:53:44 -0700889 /* set autoneg back to what it currently is */
Alan Brady1c142e12017-10-05 14:53:31 -0700890 copy_ks.base.autoneg = safe_ks.base.autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000891
Alan Bradycee91992017-10-05 14:53:44 -0700892 /* If copy_ks.base and safe_ks.base are not the same now, then they are
893 * trying to set something that we do not support.
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000894 */
Alan Bradycee91992017-10-05 14:53:44 -0700895 if (memcmp(&copy_ks.base, &safe_ks.base,
896 sizeof(struct ethtool_link_settings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000897 return -EOPNOTSUPP;
898
Jacob Keller0da36b92017-04-19 09:25:55 -0400899 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400900 timeout--;
901 if (!timeout)
902 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000903 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400904 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000905
906 /* Get the current phy config */
907 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
908 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400909 if (status) {
910 err = -EAGAIN;
911 goto done;
912 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000913
Catherine Sullivan124ed152014-07-12 07:28:12 +0000914 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000915 * set below
916 */
917 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000918 config.abilities = abilities.abilities;
919
920 /* Check autoneg */
921 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000922 /* If autoneg was not already enabled */
923 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400924 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700925 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
926 supported,
927 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400928 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400929 err = -EINVAL;
930 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400931 }
932 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000933 config.abilities = abilities.abilities |
934 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700935 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000936 }
937 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000938 /* If autoneg is currently enabled */
939 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400940 /* If autoneg is supported 10GBASE_T is the only PHY
941 * that can disable it, so otherwise return error
942 */
Alan Brady1c142e12017-10-05 14:53:31 -0700943 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
944 supported,
945 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400946 hw->phy.link_info.phy_type !=
947 I40E_PHY_TYPE_10GBASE_T) {
948 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400949 err = -EINVAL;
950 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400951 }
952 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000953 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000954 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700955 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000956 }
957 }
958
Alan Bradycee91992017-10-05 14:53:44 -0700959 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
960 100baseT_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000961 config.link_speed |= I40E_LINK_SPEED_100MB;
Alan Bradycee91992017-10-05 14:53:44 -0700962 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
963 1000baseT_Full) ||
964 ethtool_link_ksettings_test_link_mode(ks, advertising,
965 1000baseX_Full) ||
966 ethtool_link_ksettings_test_link_mode(ks, advertising,
967 1000baseKX_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000968 config.link_speed |= I40E_LINK_SPEED_1GB;
Alan Bradycee91992017-10-05 14:53:44 -0700969 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
970 10000baseT_Full) ||
971 ethtool_link_ksettings_test_link_mode(ks, advertising,
972 10000baseKX4_Full) ||
973 ethtool_link_ksettings_test_link_mode(ks, advertising,
974 10000baseKR_Full) ||
975 ethtool_link_ksettings_test_link_mode(ks, advertising,
976 10000baseCR_Full) ||
977 ethtool_link_ksettings_test_link_mode(ks, advertising,
978 10000baseSR_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000979 config.link_speed |= I40E_LINK_SPEED_10GB;
Alan Bradycee91992017-10-05 14:53:44 -0700980 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
981 20000baseKR2_Full))
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700982 config.link_speed |= I40E_LINK_SPEED_20GB;
Alan Bradycee91992017-10-05 14:53:44 -0700983 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
984 25000baseCR_Full) ||
985 ethtool_link_ksettings_test_link_mode(ks, advertising,
986 25000baseKR_Full) ||
987 ethtool_link_ksettings_test_link_mode(ks, advertising,
988 25000baseSR_Full))
989 config.link_speed |= I40E_LINK_SPEED_25GB;
990 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
991 40000baseKR4_Full) ||
992 ethtool_link_ksettings_test_link_mode(ks, advertising,
993 40000baseCR4_Full) ||
994 ethtool_link_ksettings_test_link_mode(ks, advertising,
995 40000baseSR4_Full) ||
996 ethtool_link_ksettings_test_link_mode(ks, advertising,
997 40000baseLR4_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000998 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000999
Catherine Sullivan0002e112015-08-26 15:14:16 -04001000 /* If speed didn't get set, set it to what it currently is.
1001 * This is needed because if advertise is 0 (as it is when autoneg
1002 * is disabled) then speed won't get set.
1003 */
1004 if (!config.link_speed)
1005 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -07001006 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001007 /* copy over the rest of the abilities */
1008 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -08001009 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001010 config.eee_capability = abilities.eee_capability;
1011 config.eeer = abilities.eeer_val;
1012 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -08001013 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1014 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001015
Catherine Sullivane8278452015-02-06 08:52:08 +00001016 /* save the requested speeds */
1017 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +00001018 /* set link and auto negotiation so changes take effect */
1019 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1020 /* If link is up put link down */
1021 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
1022 /* Tell the OS link is going down, the link will go
1023 * back up when fw says it is ready asynchronously
1024 */
Matt Jaredc156f852015-08-27 11:42:39 -04001025 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001026 netif_carrier_off(netdev);
1027 netif_tx_stop_all_queues(netdev);
1028 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001029
1030 /* make the aq call */
1031 status = i40e_aq_set_phy_config(hw, &config, NULL);
1032 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001033 netdev_info(netdev,
1034 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001035 i40e_stat_str(hw, status),
1036 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001037 err = -EAGAIN;
1038 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001039 }
1040
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001041 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001042 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001043 netdev_dbg(netdev,
1044 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001045 i40e_stat_str(hw, status),
1046 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001047
1048 } else {
1049 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1050 }
1051
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001052done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001053 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001054
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001055 return err;
1056}
1057
Jesse Brandeburga6599722014-06-04 08:45:25 +00001058static int i40e_nway_reset(struct net_device *netdev)
1059{
1060 /* restart autonegotiation */
1061 struct i40e_netdev_priv *np = netdev_priv(netdev);
1062 struct i40e_pf *pf = np->vsi->back;
1063 struct i40e_hw *hw = &pf->hw;
1064 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1065 i40e_status ret = 0;
1066
1067 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1068 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001069 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1070 i40e_stat_str(hw, ret),
1071 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001072 return -EIO;
1073 }
1074
1075 return 0;
1076}
1077
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001078/**
1079 * i40e_get_pauseparam - Get Flow Control status
1080 * Return tx/rx-pause status
1081 **/
1082static void i40e_get_pauseparam(struct net_device *netdev,
1083 struct ethtool_pauseparam *pause)
1084{
1085 struct i40e_netdev_priv *np = netdev_priv(netdev);
1086 struct i40e_pf *pf = np->vsi->back;
1087 struct i40e_hw *hw = &pf->hw;
1088 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001089 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001090
1091 pause->autoneg =
1092 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1093 AUTONEG_ENABLE : AUTONEG_DISABLE);
1094
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001095 /* PFC enabled so report LFC as off */
1096 if (dcbx_cfg->pfc.pfcenable) {
1097 pause->rx_pause = 0;
1098 pause->tx_pause = 0;
1099 return;
1100 }
1101
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001102 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001103 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001104 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001105 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001106 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1107 pause->rx_pause = 1;
1108 pause->tx_pause = 1;
1109 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001110}
1111
Catherine Sullivan2becc352014-06-04 08:45:27 +00001112/**
1113 * i40e_set_pauseparam - Set Flow Control parameter
1114 * @netdev: network interface device structure
1115 * @pause: return tx/rx flow control status
1116 **/
1117static int i40e_set_pauseparam(struct net_device *netdev,
1118 struct ethtool_pauseparam *pause)
1119{
1120 struct i40e_netdev_priv *np = netdev_priv(netdev);
1121 struct i40e_pf *pf = np->vsi->back;
1122 struct i40e_vsi *vsi = np->vsi;
1123 struct i40e_hw *hw = &pf->hw;
1124 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001125 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001126 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1127 i40e_status status;
1128 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001129 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001130
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001131 /* Changing the port's flow control is not supported if this isn't the
1132 * port's controlling PF
1133 */
1134 if (hw->partition_id != 1) {
1135 i40e_partition_setting_complaint(pf);
1136 return -EOPNOTSUPP;
1137 }
1138
Catherine Sullivan2becc352014-06-04 08:45:27 +00001139 if (vsi != pf->vsi[pf->lan_vsi])
1140 return -EOPNOTSUPP;
1141
1142 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1143 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1144 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1145 return -EOPNOTSUPP;
1146 }
1147
1148 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001149 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001150 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1151 /* Send message that it might not necessarily work*/
1152 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1153 }
1154
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001155 if (dcbx_cfg->pfc.pfcenable) {
1156 netdev_info(netdev,
1157 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001158 return -EOPNOTSUPP;
1159 }
1160
1161 if (pause->rx_pause && pause->tx_pause)
1162 hw->fc.requested_mode = I40E_FC_FULL;
1163 else if (pause->rx_pause && !pause->tx_pause)
1164 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1165 else if (!pause->rx_pause && pause->tx_pause)
1166 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1167 else if (!pause->rx_pause && !pause->tx_pause)
1168 hw->fc.requested_mode = I40E_FC_NONE;
1169 else
1170 return -EINVAL;
1171
Catherine Sullivan94128512014-07-12 07:28:16 +00001172 /* Tell the OS link is going down, the link will go back up when fw
1173 * says it is ready asynchronously
1174 */
Matt Jaredc156f852015-08-27 11:42:39 -04001175 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001176 netif_carrier_off(netdev);
1177 netif_tx_stop_all_queues(netdev);
1178
Catherine Sullivan2becc352014-06-04 08:45:27 +00001179 /* Set the fc mode and only restart an if link is up*/
1180 status = i40e_set_fc(hw, &aq_failures, link_up);
1181
1182 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001183 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1184 i40e_stat_str(hw, status),
1185 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001186 err = -EAGAIN;
1187 }
1188 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001189 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1190 i40e_stat_str(hw, status),
1191 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001192 err = -EAGAIN;
1193 }
1194 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001195 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1196 i40e_stat_str(hw, status),
1197 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001198 err = -EAGAIN;
1199 }
1200
Jacob Keller0da36b92017-04-19 09:25:55 -04001201 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001202 /* Give it a little more time to try to come back */
1203 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001204 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001205 return i40e_nway_reset(netdev);
1206 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001207
1208 return err;
1209}
1210
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001211static u32 i40e_get_msglevel(struct net_device *netdev)
1212{
1213 struct i40e_netdev_priv *np = netdev_priv(netdev);
1214 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001215 u32 debug_mask = pf->hw.debug_mask;
1216
1217 if (debug_mask)
1218 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001219
1220 return pf->msg_enable;
1221}
1222
1223static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1224{
1225 struct i40e_netdev_priv *np = netdev_priv(netdev);
1226 struct i40e_pf *pf = np->vsi->back;
1227
1228 if (I40E_DEBUG_USER & data)
1229 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001230 else
1231 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232}
1233
1234static int i40e_get_regs_len(struct net_device *netdev)
1235{
1236 int reg_count = 0;
1237 int i;
1238
1239 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1240 reg_count += i40e_reg_list[i].elements;
1241
1242 return reg_count * sizeof(u32);
1243}
1244
1245static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1246 void *p)
1247{
1248 struct i40e_netdev_priv *np = netdev_priv(netdev);
1249 struct i40e_pf *pf = np->vsi->back;
1250 struct i40e_hw *hw = &pf->hw;
1251 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001252 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001253 u32 reg;
1254
1255 /* Tell ethtool which driver-version-specific regs output we have.
1256 *
1257 * At some point, if we have ethtool doing special formatting of
1258 * this data, it will rely on this version number to know how to
1259 * interpret things. Hence, this needs to be updated if/when the
1260 * diags register table is changed.
1261 */
1262 regs->version = 1;
1263
1264 /* loop through the diags reg table for what to print */
1265 ri = 0;
1266 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1267 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1268 reg = i40e_reg_list[i].offset
1269 + (j * i40e_reg_list[i].stride);
1270 reg_buf[ri++] = rd32(hw, reg);
1271 }
1272 }
1273
1274}
1275
1276static int i40e_get_eeprom(struct net_device *netdev,
1277 struct ethtool_eeprom *eeprom, u8 *bytes)
1278{
1279 struct i40e_netdev_priv *np = netdev_priv(netdev);
1280 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001281 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001282 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001283 u8 *eeprom_buff;
1284 u16 i, sectors;
1285 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001286 u32 magic;
1287
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001288#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001289 if (eeprom->len == 0)
1290 return -EINVAL;
1291
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001292 /* check for NVMUpdate access method */
1293 magic = hw->vendor_id | (hw->device_id << 16);
1294 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001295 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1296 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001297
1298 /* make sure it is the right magic for NVMUpdate */
1299 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001300 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001301 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1302 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001303 errno = -EBUSY;
1304 else
1305 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001306
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001307 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001308 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001309 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1310 ret_val, hw->aq.asq_last_status, errno,
1311 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1312 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001313
1314 return errno;
1315 }
1316
1317 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001318 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1319
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001320 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001321 if (!eeprom_buff)
1322 return -ENOMEM;
1323
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001324 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1325 if (ret_val) {
1326 dev_info(&pf->pdev->dev,
1327 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1328 ret_val, hw->aq.asq_last_status);
1329 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001330 }
1331
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001332 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1333 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1334 len = I40E_NVM_SECTOR_SIZE;
1335 last = false;
1336 for (i = 0; i < sectors; i++) {
1337 if (i == (sectors - 1)) {
1338 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1339 last = true;
1340 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001341 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1342 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001343 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001344 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001345 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001346 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001347 "read NVM failed, invalid offset 0x%x\n",
1348 offset);
1349 break;
1350 } else if (ret_val &&
1351 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1352 dev_info(&pf->pdev->dev,
1353 "read NVM failed, access, offset 0x%x\n",
1354 offset);
1355 break;
1356 } else if (ret_val) {
1357 dev_info(&pf->pdev->dev,
1358 "read NVM failed offset %d err=%d status=0x%x\n",
1359 offset, ret_val, hw->aq.asq_last_status);
1360 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001361 }
1362 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001363
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001364 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001365 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001366free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001367 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001368 return ret_val;
1369}
1370
1371static int i40e_get_eeprom_len(struct net_device *netdev)
1372{
1373 struct i40e_netdev_priv *np = netdev_priv(netdev);
1374 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001375 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001376
Lihong Yangc271dd62017-01-30 12:29:32 -08001377#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1378 if (hw->mac.type == I40E_MAC_X722) {
1379 val = X722_EEPROM_SCOPE_LIMIT + 1;
1380 return val;
1381 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001382 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1383 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1384 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1385 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001386 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001387 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001388}
1389
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001390static int i40e_set_eeprom(struct net_device *netdev,
1391 struct ethtool_eeprom *eeprom, u8 *bytes)
1392{
1393 struct i40e_netdev_priv *np = netdev_priv(netdev);
1394 struct i40e_hw *hw = &np->vsi->back->hw;
1395 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001396 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001397 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001398 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001399 u32 magic;
1400
1401 /* normal ethtool set_eeprom is not supported */
1402 magic = hw->vendor_id | (hw->device_id << 16);
1403 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001404 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001405 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001406 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1407 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001408 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1409 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001410 errno = -EBUSY;
1411 else
1412 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001413
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001414 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001415 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001416 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1417 ret_val, hw->aq.asq_last_status, errno,
1418 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1419 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001420
1421 return errno;
1422}
1423
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001424static void i40e_get_drvinfo(struct net_device *netdev,
1425 struct ethtool_drvinfo *drvinfo)
1426{
1427 struct i40e_netdev_priv *np = netdev_priv(netdev);
1428 struct i40e_vsi *vsi = np->vsi;
1429 struct i40e_pf *pf = vsi->back;
1430
1431 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1432 strlcpy(drvinfo->version, i40e_driver_version_str,
1433 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001434 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001435 sizeof(drvinfo->fw_version));
1436 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1437 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001438 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001439 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001440 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441}
1442
1443static void i40e_get_ringparam(struct net_device *netdev,
1444 struct ethtool_ringparam *ring)
1445{
1446 struct i40e_netdev_priv *np = netdev_priv(netdev);
1447 struct i40e_pf *pf = np->vsi->back;
1448 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1449
1450 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1451 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1452 ring->rx_mini_max_pending = 0;
1453 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001454 ring->rx_pending = vsi->rx_rings[0]->count;
1455 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456 ring->rx_mini_pending = 0;
1457 ring->rx_jumbo_pending = 0;
1458}
1459
Björn Töpel74608d12017-05-24 07:55:35 +02001460static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1461{
1462 if (i40e_enabled_xdp_vsi(vsi)) {
1463 return index < vsi->num_queue_pairs ||
1464 (index >= vsi->alloc_queue_pairs &&
1465 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1466 }
1467
1468 return index < vsi->num_queue_pairs;
1469}
1470
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001471static int i40e_set_ringparam(struct net_device *netdev,
1472 struct ethtool_ringparam *ring)
1473{
1474 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1475 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001476 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477 struct i40e_vsi *vsi = np->vsi;
1478 struct i40e_pf *pf = vsi->back;
1479 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001480 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001481 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 int i, err = 0;
1483
1484 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1485 return -EINVAL;
1486
Shannon Nelson1fa18372013-11-20 10:03:08 +00001487 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1488 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1489 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1490 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1491 netdev_info(netdev,
1492 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1493 ring->tx_pending, ring->rx_pending,
1494 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1495 return -EINVAL;
1496 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497
Shannon Nelson1fa18372013-11-20 10:03:08 +00001498 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1499 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500
1501 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001502 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1503 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504 return 0;
1505
Jacob Keller0da36b92017-04-19 09:25:55 -04001506 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001507 timeout--;
1508 if (!timeout)
1509 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001510 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001511 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001512
1513 if (!netif_running(vsi->netdev)) {
1514 /* simple case - set for the next time the netdev is started */
1515 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001516 vsi->tx_rings[i]->count = new_tx_count;
1517 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001518 if (i40e_enabled_xdp_vsi(vsi))
1519 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520 }
1521 goto done;
1522 }
1523
1524 /* We can't just free everything and then setup again,
1525 * because the ISRs in MSI-X mode get passed pointers
1526 * to the Tx and Rx ring structs.
1527 */
1528
Björn Töpel74608d12017-05-24 07:55:35 +02001529 /* alloc updated Tx and XDP Tx resources */
1530 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1531 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001532 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001533 netdev_info(netdev,
1534 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001535 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001536 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537 sizeof(struct i40e_ring), GFP_KERNEL);
1538 if (!tx_rings) {
1539 err = -ENOMEM;
1540 goto done;
1541 }
1542
Björn Töpel74608d12017-05-24 07:55:35 +02001543 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1544 if (!i40e_active_tx_ring_index(vsi, i))
1545 continue;
1546
Alexander Duyck9f65e152013-09-28 06:00:58 +00001547 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001549 /* the desc and bi pointers will be reallocated in the
1550 * setup call
1551 */
1552 tx_rings[i].desc = NULL;
1553 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1555 if (err) {
1556 while (i) {
1557 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001558 if (!i40e_active_tx_ring_index(vsi, i))
1559 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001560 i40e_free_tx_resources(&tx_rings[i]);
1561 }
1562 kfree(tx_rings);
1563 tx_rings = NULL;
1564
1565 goto done;
1566 }
1567 }
1568 }
1569
1570 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001571 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001572 netdev_info(netdev,
1573 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001574 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001575 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1576 sizeof(struct i40e_ring), GFP_KERNEL);
1577 if (!rx_rings) {
1578 err = -ENOMEM;
1579 goto free_tx;
1580 }
1581
1582 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001583 struct i40e_ring *ring;
1584 u16 unused;
1585
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001586 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001587 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001588 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001589 /* the desc and bi pointers will be reallocated in the
1590 * setup call
1591 */
1592 rx_rings[i].desc = NULL;
1593 rx_rings[i].rx_bi = NULL;
Jesper Dangaard Brouer87128822018-01-03 11:25:23 +01001594 /* Clear cloned XDP RX-queue info before setup call */
1595 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
Tushar Dave2f7679e2016-10-26 10:49:27 -07001596 /* this is to allow wr32 to have something to write to
1597 * during early allocation of Rx buffers
1598 */
1599 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001601 if (err)
1602 goto rx_unwind;
1603
1604 /* now allocate the Rx buffers to make sure the OS
1605 * has enough memory, any failure here means abort
1606 */
1607 ring = &rx_rings[i];
1608 unused = I40E_DESC_UNUSED(ring);
1609 err = i40e_alloc_rx_buffers(ring, unused);
1610rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001611 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001612 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001613 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001614 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001615 kfree(rx_rings);
1616 rx_rings = NULL;
1617
1618 goto free_tx;
1619 }
1620 }
1621 }
1622
1623 /* Bring interface down, copy in the new ring info,
1624 * then restore the interface
1625 */
1626 i40e_down(vsi);
1627
1628 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001629 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1630 if (i40e_active_tx_ring_index(vsi, i)) {
1631 i40e_free_tx_resources(vsi->tx_rings[i]);
1632 *vsi->tx_rings[i] = tx_rings[i];
1633 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001634 }
1635 kfree(tx_rings);
1636 tx_rings = NULL;
1637 }
1638
1639 if (rx_rings) {
1640 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001641 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001642 /* get the real tail offset */
1643 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1644 /* this is to fake out the allocation routine
1645 * into thinking it has to realloc everything
1646 * but the recycling logic will let us re-use
1647 * the buffers allocated above
1648 */
1649 rx_rings[i].next_to_use = 0;
1650 rx_rings[i].next_to_clean = 0;
1651 rx_rings[i].next_to_alloc = 0;
1652 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001653 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001654 }
1655 kfree(rx_rings);
1656 rx_rings = NULL;
1657 }
1658
1659 i40e_up(vsi);
1660
1661free_tx:
1662 /* error cleanup if the Rx allocations failed after getting Tx */
1663 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001664 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1665 if (i40e_active_tx_ring_index(vsi, i))
1666 i40e_free_tx_resources(vsi->tx_rings[i]);
1667 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668 kfree(tx_rings);
1669 tx_rings = NULL;
1670 }
1671
1672done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001673 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001674
1675 return err;
1676}
1677
1678static int i40e_get_sset_count(struct net_device *netdev, int sset)
1679{
1680 struct i40e_netdev_priv *np = netdev_priv(netdev);
1681 struct i40e_vsi *vsi = np->vsi;
1682 struct i40e_pf *pf = vsi->back;
1683
1684 switch (sset) {
1685 case ETH_SS_TEST:
1686 return I40E_TEST_LEN;
1687 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001688 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001689 int len = I40E_PF_STATS_LEN(netdev);
1690
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001691 if ((pf->lan_veb != I40E_NO_VEB) &&
1692 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001693 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001694 return len;
1695 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001696 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001697 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001698 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001699 return I40E_PRIV_FLAGS_STR_LEN +
1700 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001701 default:
1702 return -EOPNOTSUPP;
1703 }
1704}
1705
1706static void i40e_get_ethtool_stats(struct net_device *netdev,
1707 struct ethtool_stats *stats, u64 *data)
1708{
1709 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001710 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001711 struct i40e_vsi *vsi = np->vsi;
1712 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001713 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714 int i = 0;
1715 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001716 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001717 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001718
1719 i40e_update_stats(vsi);
1720
1721 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1722 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1723 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1724 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1725 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001726 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1727 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1728 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1729 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1730 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001731 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001732 for (j = 0; j < vsi->num_queue_pairs; j++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07001733 tx_ring = READ_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001734
1735 if (!tx_ring)
1736 continue;
1737
1738 /* process Tx ring statistics */
1739 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001740 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001741 data[i] = tx_ring->stats.packets;
1742 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001743 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001744 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001745
1746 /* Rx ring is the 2nd half of the queue pair */
1747 rx_ring = &tx_ring[1];
1748 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001749 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001750 data[i] = rx_ring->stats.packets;
1751 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001752 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001753 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001754 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001755 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001756 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001757 return;
1758
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001759 if ((pf->lan_veb != I40E_NO_VEB) &&
1760 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001761 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001762
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001763 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1764 p = (char *)veb;
1765 p += i40e_gstrings_veb_stats[j].stat_offset;
1766 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1767 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001768 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001769 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1770 data[i++] = veb->tc_stats.tc_tx_packets[j];
1771 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1772 data[i++] = veb->tc_stats.tc_rx_packets[j];
1773 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1774 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001775 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001776 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1777 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1778 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1779 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1780 }
1781 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1782 data[i++] = pf->stats.priority_xon_tx[j];
1783 data[i++] = pf->stats.priority_xoff_tx[j];
1784 }
1785 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1786 data[i++] = pf->stats.priority_xon_rx[j];
1787 data[i++] = pf->stats.priority_xoff_rx[j];
1788 }
1789 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1790 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791}
1792
1793static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1794 u8 *data)
1795{
1796 struct i40e_netdev_priv *np = netdev_priv(netdev);
1797 struct i40e_vsi *vsi = np->vsi;
1798 struct i40e_pf *pf = vsi->back;
1799 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001800 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001801
1802 switch (stringset) {
1803 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001804 memcpy(data, i40e_gstrings_test,
1805 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001806 break;
1807 case ETH_SS_STATS:
1808 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1809 snprintf(p, ETH_GSTRING_LEN, "%s",
1810 i40e_gstrings_net_stats[i].stat_string);
1811 p += ETH_GSTRING_LEN;
1812 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001813 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1814 snprintf(p, ETH_GSTRING_LEN, "%s",
1815 i40e_gstrings_misc_stats[i].stat_string);
1816 p += ETH_GSTRING_LEN;
1817 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001819 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001821 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001822 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001823 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001824 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001825 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001826 p += ETH_GSTRING_LEN;
1827 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001828 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001829 return;
1830
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001831 if ((pf->lan_veb != I40E_NO_VEB) &&
1832 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001833 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1834 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1835 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001836 p += ETH_GSTRING_LEN;
1837 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001838 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1839 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001840 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001841 p += ETH_GSTRING_LEN;
1842 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001843 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001844 p += ETH_GSTRING_LEN;
1845 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001846 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001847 p += ETH_GSTRING_LEN;
1848 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001849 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001850 p += ETH_GSTRING_LEN;
1851 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001852 }
1853 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1854 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1855 i40e_gstrings_stats[i].stat_string);
1856 p += ETH_GSTRING_LEN;
1857 }
1858 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1859 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001860 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001861 p += ETH_GSTRING_LEN;
1862 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001863 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001864 p += ETH_GSTRING_LEN;
1865 }
1866 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1867 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001868 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001869 p += ETH_GSTRING_LEN;
1870 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001871 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001872 p += ETH_GSTRING_LEN;
1873 }
1874 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1875 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001876 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001877 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001878 }
1879 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1880 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001881 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001882 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1883 snprintf(p, ETH_GSTRING_LEN, "%s",
1884 i40e_gstrings_priv_flags[i].flag_string);
1885 p += ETH_GSTRING_LEN;
1886 }
1887 if (pf->hw.pf_id != 0)
1888 break;
1889 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1890 snprintf(p, ETH_GSTRING_LEN, "%s",
1891 i40e_gl_gstrings_priv_flags[i].flag_string);
1892 p += ETH_GSTRING_LEN;
1893 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001894 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001895 default:
1896 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001897 }
1898}
1899
1900static int i40e_get_ts_info(struct net_device *dev,
1901 struct ethtool_ts_info *info)
1902{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001903 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1904
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001905 /* only report HW timestamping if PTP is enabled */
1906 if (!(pf->flags & I40E_FLAG_PTP))
1907 return ethtool_op_get_ts_info(dev, info);
1908
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001909 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1910 SOF_TIMESTAMPING_RX_SOFTWARE |
1911 SOF_TIMESTAMPING_SOFTWARE |
1912 SOF_TIMESTAMPING_TX_HARDWARE |
1913 SOF_TIMESTAMPING_RX_HARDWARE |
1914 SOF_TIMESTAMPING_RAW_HARDWARE;
1915
1916 if (pf->ptp_clock)
1917 info->phc_index = ptp_clock_index(pf->ptp_clock);
1918 else
1919 info->phc_index = -1;
1920
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001921 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001922
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001923 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001924 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1925 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1926 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1927
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001928 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001929 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1930 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1931 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1932 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1933 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1934 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1935 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1936 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001937
1938 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939}
1940
Shannon Nelson7b086392013-11-20 10:02:59 +00001941static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001942{
Shannon Nelson7b086392013-11-20 10:02:59 +00001943 struct i40e_netdev_priv *np = netdev_priv(netdev);
1944 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001945 i40e_status status;
1946 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001947
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001948 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001949 status = i40e_get_link_status(&pf->hw, &link_up);
1950 if (status) {
1951 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1952 *data = 1;
1953 return *data;
1954 }
1955
1956 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001957 *data = 0;
1958 else
1959 *data = 1;
1960
1961 return *data;
1962}
1963
Shannon Nelson7b086392013-11-20 10:02:59 +00001964static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001965{
Shannon Nelson7b086392013-11-20 10:02:59 +00001966 struct i40e_netdev_priv *np = netdev_priv(netdev);
1967 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001968
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001969 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001970 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001971
Shannon Nelson7b086392013-11-20 10:02:59 +00001972 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001973}
1974
Shannon Nelson7b086392013-11-20 10:02:59 +00001975static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001976{
Shannon Nelson7b086392013-11-20 10:02:59 +00001977 struct i40e_netdev_priv *np = netdev_priv(netdev);
1978 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001979
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001980 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001981 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001982
Shannon Nelson4443ec92014-11-13 08:23:12 +00001983 /* forcebly clear the NVM Update state machine */
1984 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1985
Shannon Nelson7b086392013-11-20 10:02:59 +00001986 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001987}
1988
Shannon Nelson7b086392013-11-20 10:02:59 +00001989static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001990{
Shannon Nelson7b086392013-11-20 10:02:59 +00001991 struct i40e_netdev_priv *np = netdev_priv(netdev);
1992 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001993 u16 swc_old = pf->sw_int_count;
1994
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001995 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001996 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1997 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001998 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1999 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
2000 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
2001 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00002002 usleep_range(1000, 2000);
2003 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002004
2005 return *data;
2006}
2007
Greg Rosee17bc412015-04-16 20:05:59 -04002008static inline bool i40e_active_vfs(struct i40e_pf *pf)
2009{
2010 struct i40e_vf *vfs = pf->vf;
2011 int i;
2012
2013 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04002014 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04002015 return true;
2016 return false;
2017}
2018
Greg Rose510efb22015-07-10 19:36:01 -04002019static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2020{
Alexander Duyck4b816442016-10-11 15:26:53 -07002021 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04002022}
2023
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002024static void i40e_diag_test(struct net_device *netdev,
2025 struct ethtool_test *eth_test, u64 *data)
2026{
2027 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002028 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002029 struct i40e_pf *pf = np->vsi->back;
2030
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002031 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2032 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002033 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002034
Jacob Keller0da36b92017-04-19 09:25:55 -04002035 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002036
Greg Rose510efb22015-07-10 19:36:01 -04002037 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002038 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002039 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002040 data[I40E_ETH_TEST_REG] = 1;
2041 data[I40E_ETH_TEST_EEPROM] = 1;
2042 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002043 data[I40E_ETH_TEST_LINK] = 1;
2044 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002045 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002046 goto skip_ol_tests;
2047 }
2048
Greg Rose5b86c5c2015-02-26 16:14:35 +00002049 /* If the device is online then take it offline */
2050 if (if_running)
2051 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002052 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002053 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002054 /* This reset does not affect link - if it is
2055 * changed to a type of reset that does affect
2056 * link then the following link test would have
2057 * to be moved to before the reset
2058 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002059 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002060
Shannon Nelson7b086392013-11-20 10:02:59 +00002061 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062 eth_test->flags |= ETH_TEST_FL_FAILED;
2063
Shannon Nelson7b086392013-11-20 10:02:59 +00002064 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002065 eth_test->flags |= ETH_TEST_FL_FAILED;
2066
Shannon Nelson7b086392013-11-20 10:02:59 +00002067 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002068 eth_test->flags |= ETH_TEST_FL_FAILED;
2069
Shannon Nelsonf551b432013-11-26 10:49:12 +00002070 /* run reg test last, a reset is required after it */
2071 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2072 eth_test->flags |= ETH_TEST_FL_FAILED;
2073
Jacob Keller0da36b92017-04-19 09:25:55 -04002074 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002075 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002076
2077 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002078 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002079 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002080 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002081 netif_info(pf, drv, netdev, "online testing starting\n");
2082
Shannon Nelson7b086392013-11-20 10:02:59 +00002083 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002084 eth_test->flags |= ETH_TEST_FL_FAILED;
2085
2086 /* Offline only tests, not run in online; pass by default */
2087 data[I40E_ETH_TEST_REG] = 0;
2088 data[I40E_ETH_TEST_EEPROM] = 0;
2089 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002090 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002091
Greg Rosee17bc412015-04-16 20:05:59 -04002092skip_ol_tests:
2093
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002094 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002095}
2096
2097static void i40e_get_wol(struct net_device *netdev,
2098 struct ethtool_wolinfo *wol)
2099{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002100 struct i40e_netdev_priv *np = netdev_priv(netdev);
2101 struct i40e_pf *pf = np->vsi->back;
2102 struct i40e_hw *hw = &pf->hw;
2103 u16 wol_nvm_bits;
2104
2105 /* NVM bit on means WoL disabled for the port */
2106 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002107 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002108 wol->supported = 0;
2109 wol->wolopts = 0;
2110 } else {
2111 wol->supported = WAKE_MAGIC;
2112 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2113 }
2114}
2115
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002116/**
2117 * i40e_set_wol - set the WakeOnLAN configuration
2118 * @netdev: the netdev in question
2119 * @wol: the ethtool WoL setting data
2120 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002121static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2122{
2123 struct i40e_netdev_priv *np = netdev_priv(netdev);
2124 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002125 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002126 struct i40e_hw *hw = &pf->hw;
2127 u16 wol_nvm_bits;
2128
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002129 /* WoL not supported if this isn't the controlling PF on the port */
2130 if (hw->partition_id != 1) {
2131 i40e_partition_setting_complaint(pf);
2132 return -EOPNOTSUPP;
2133 }
2134
2135 if (vsi != pf->vsi[pf->lan_vsi])
2136 return -EOPNOTSUPP;
2137
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002138 /* NVM bit on means WoL disabled for the port */
2139 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002140 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002141 return -EOPNOTSUPP;
2142
2143 /* only magic packet is supported */
2144 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2145 return -EOPNOTSUPP;
2146
2147 /* is this a new value? */
2148 if (pf->wol_en != !!wol->wolopts) {
2149 pf->wol_en = !!wol->wolopts;
2150 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2151 }
2152
2153 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002154}
2155
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002156static int i40e_set_phys_id(struct net_device *netdev,
2157 enum ethtool_phys_id_state state)
2158{
2159 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002160 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002161 struct i40e_pf *pf = np->vsi->back;
2162 struct i40e_hw *hw = &pf->hw;
2163 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002164 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002165
2166 switch (state) {
2167 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002168 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002169 pf->led_status = i40e_led_get(hw);
2170 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002171 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2172 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2173 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002174 ret = i40e_led_get_phy(hw, &temp_status,
2175 &pf->phy_led_val);
2176 pf->led_status = temp_status;
2177 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178 return blink_freq;
2179 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002180 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002181 i40e_led_set(hw, 0xf, false);
2182 else
2183 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 break;
2185 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002186 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002187 i40e_led_set(hw, 0x0, false);
2188 else
2189 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002190 break;
2191 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002192 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002193 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002194 } else {
2195 ret = i40e_led_set_phy(hw, false, pf->led_status,
2196 (pf->phy_led_val |
2197 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002198 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2199 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002200 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002201 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002202 default:
2203 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002205 if (ret)
2206 return -ENOENT;
2207 else
2208 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002209}
2210
2211/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2212 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2213 * 125us (8000 interrupts per second) == ITR(62)
2214 */
2215
Jacob Keller65e87c02016-09-12 14:18:44 -07002216/**
2217 * __i40e_get_coalesce - get per-queue coalesce settings
2218 * @netdev: the netdev to check
2219 * @ec: ethtool coalesce data structure
2220 * @queue: which queue to pick
2221 *
2222 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2223 * are per queue. If queue is <0 then we default to queue 0 as the
2224 * representative value.
2225 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002226static int __i40e_get_coalesce(struct net_device *netdev,
2227 struct ethtool_coalesce *ec,
2228 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229{
2230 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002231 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232 struct i40e_vsi *vsi = np->vsi;
2233
2234 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2235 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2236
Alan Bradya03af692017-10-05 14:53:37 -07002237 /* rx and tx usecs has per queue value. If user doesn't specify the
2238 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002239 */
Alan Bradya03af692017-10-05 14:53:37 -07002240 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002241 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002242 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002243 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002244
Jacob Keller65e87c02016-09-12 14:18:44 -07002245 rx_ring = vsi->rx_rings[queue];
2246 tx_ring = vsi->tx_rings[queue];
2247
Alexander Duyck40588ca2017-12-29 08:49:28 -05002248 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002249 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002250
Alexander Duyck40588ca2017-12-29 08:49:28 -05002251 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002252 ec->use_adaptive_tx_coalesce = 1;
2253
Alexander Duyck40588ca2017-12-29 08:49:28 -05002254 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2255 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
Jacob Keller65e87c02016-09-12 14:18:44 -07002256
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002257 /* we use the _usecs_high to store/set the interrupt rate limit
2258 * that the hardware supports, that almost but not quite
2259 * fits the original intent of the ethtool variable,
2260 * the rx_coalesce_usecs_high limits total interrupts
2261 * per second from both tx/rx sources.
2262 */
2263 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2264 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002265
2266 return 0;
2267}
2268
Jacob Keller65e87c02016-09-12 14:18:44 -07002269/**
2270 * i40e_get_coalesce - get a netdev's coalesce settings
2271 * @netdev: the netdev to check
2272 * @ec: ethtool coalesce data structure
2273 *
2274 * Gets the coalesce settings for a particular netdev. Note that if user has
2275 * modified per-queue settings, this only guarantees to represent queue 0. See
2276 * __i40e_get_coalesce for more details.
2277 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002278static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002279 struct ethtool_coalesce *ec)
2280{
Kan Lianga75e8002016-02-19 09:24:04 -05002281 return __i40e_get_coalesce(netdev, ec, -1);
2282}
2283
Jacob Keller65e87c02016-09-12 14:18:44 -07002284/**
2285 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2286 * @netdev: netdev structure
2287 * @ec: ethtool's coalesce settings
2288 * @queue: the particular queue to read
2289 *
2290 * Will read a specific queue's coalesce settings
2291 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002292static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2293 struct ethtool_coalesce *ec)
2294{
2295 return __i40e_get_coalesce(netdev, ec, queue);
2296}
2297
Jacob Keller65e87c02016-09-12 14:18:44 -07002298/**
2299 * i40e_set_itr_per_queue - set ITR values for specific queue
2300 * @vsi: the VSI to set values for
2301 * @ec: coalesce settings from ethtool
2302 * @queue: the queue to modify
2303 *
2304 * Change the ITR settings for a specific queue.
2305 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002306static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2307 struct ethtool_coalesce *ec,
2308 int queue)
2309{
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002310 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2311 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002312 struct i40e_pf *pf = vsi->back;
2313 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002314 struct i40e_q_vector *q_vector;
Alexander Duyck8b99b112017-12-29 08:50:44 -05002315 u16 intrl;
Kan Lianga75e8002016-02-19 09:24:04 -05002316
Alan Brady1c0e6a32016-11-28 16:06:02 -08002317 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002318
Alexander Duyck92418fb2017-12-29 08:51:08 -05002319 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2320 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
Kan Lianga75e8002016-02-19 09:24:04 -05002321
2322 if (ec->use_adaptive_rx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002323 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002324 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002325 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002326
2327 if (ec->use_adaptive_tx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002328 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002329 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002330 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002331
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002332 q_vector = rx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002333 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
Kan Lianga75e8002016-02-19 09:24:04 -05002334
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002335 q_vector = tx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002336 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2337
2338 /* The interrupt handler itself will take care of programming
2339 * the Tx and Rx ITR values based on the values we have entered
2340 * into the q_vector, no need to write the values now.
2341 */
Kan Lianga75e8002016-02-19 09:24:04 -05002342
Alexander Duyck8b99b112017-12-29 08:50:44 -05002343 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
Kan Lianga75e8002016-02-19 09:24:04 -05002344 i40e_flush(hw);
2345}
2346
Jacob Keller65e87c02016-09-12 14:18:44 -07002347/**
2348 * __i40e_set_coalesce - set coalesce settings for particular queue
2349 * @netdev: the netdev to change
2350 * @ec: ethtool coalesce settings
2351 * @queue: the queue to change
2352 *
2353 * Sets the coalesce settings for a particular queue.
2354 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002355static int __i40e_set_coalesce(struct net_device *netdev,
2356 struct ethtool_coalesce *ec,
2357 int queue)
2358{
2359 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002360 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002361 struct i40e_vsi *vsi = np->vsi;
2362 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002363 int i;
2364
2365 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2366 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2367
Alan Brady06b2dec2017-07-12 05:46:06 -04002368 if (queue < 0) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002369 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2370 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002371 } else if (queue < vsi->num_queue_pairs) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002372 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2373 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002374 } else {
2375 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2376 vsi->num_queue_pairs - 1);
2377 return -EINVAL;
2378 }
2379
2380 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2381 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2382
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002383 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2384 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2385 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2386 return -EINVAL;
2387 }
2388
Alan Brady33084062016-11-28 16:06:03 -08002389 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2390 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2391 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002392 return -EINVAL;
2393 }
2394
Alan Brady06b2dec2017-07-12 05:46:06 -04002395 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2396 ec->use_adaptive_rx_coalesce) {
2397 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2398 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002399 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002400
Alexander Duyck92418fb2017-12-29 08:51:08 -05002401 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002402 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2403 return -EINVAL;
2404 }
2405
2406 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2407 ec->use_adaptive_tx_coalesce) {
2408 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2409 return -EINVAL;
2410 }
2411
Alexander Duyck92418fb2017-12-29 08:51:08 -05002412 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002413 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2414 return -EINVAL;
2415 }
2416
2417 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002418 ec->rx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002419
2420 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002421 ec->tx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002422
Alan Brady33084062016-11-28 16:06:03 -08002423 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2424 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2425 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2426 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2427 vsi->int_rate_limit);
2428 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002429
Alan Bradya03af692017-10-05 14:53:37 -07002430 /* rx and tx usecs has per queue value. If user doesn't specify the
2431 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002432 */
2433 if (queue < 0) {
2434 for (i = 0; i < vsi->num_queue_pairs; i++)
2435 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002436 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002437 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002438 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002439
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002440 return 0;
2441}
2442
Jacob Keller65e87c02016-09-12 14:18:44 -07002443/**
2444 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2445 * @netdev: the netdev to change
2446 * @ec: ethtool coalesce settings
2447 *
2448 * This will set each queue to the same coalesce settings.
2449 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002450static int i40e_set_coalesce(struct net_device *netdev,
2451 struct ethtool_coalesce *ec)
2452{
2453 return __i40e_set_coalesce(netdev, ec, -1);
2454}
2455
Jacob Keller65e87c02016-09-12 14:18:44 -07002456/**
2457 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2458 * @netdev: the netdev to change
2459 * @ec: ethtool's coalesce settings
2460 * @queue: the queue to change
2461 *
2462 * Sets the specified queue's coalesce settings.
2463 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002464static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2465 struct ethtool_coalesce *ec)
2466{
2467 return __i40e_set_coalesce(netdev, ec, queue);
2468}
2469
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002470/**
2471 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2472 * @pf: pointer to the physical function struct
2473 * @cmd: ethtool rxnfc command
2474 *
2475 * Returns Success if the flow is supported, else Invalid Input.
2476 **/
2477static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2478{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002479 struct i40e_hw *hw = &pf->hw;
2480 u8 flow_pctype = 0;
2481 u64 i_set = 0;
2482
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002483 cmd->data = 0;
2484
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002485 switch (cmd->flow_type) {
2486 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002487 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2488 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002489 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002490 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2491 break;
2492 case TCP_V6_FLOW:
2493 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2494 break;
2495 case UDP_V6_FLOW:
2496 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2497 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002498 case SCTP_V4_FLOW:
2499 case AH_ESP_V4_FLOW:
2500 case AH_V4_FLOW:
2501 case ESP_V4_FLOW:
2502 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002503 case SCTP_V6_FLOW:
2504 case AH_ESP_V6_FLOW:
2505 case AH_V6_FLOW:
2506 case ESP_V6_FLOW:
2507 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002508 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002509 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2510 break;
2511 default:
2512 return -EINVAL;
2513 }
2514
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002515 /* Read flow based hash input set register */
2516 if (flow_pctype) {
2517 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2518 flow_pctype)) |
2519 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2520 flow_pctype)) << 32);
2521 }
2522
2523 /* Process bits of hash input set */
2524 if (i_set) {
2525 if (i_set & I40E_L4_SRC_MASK)
2526 cmd->data |= RXH_L4_B_0_1;
2527 if (i_set & I40E_L4_DST_MASK)
2528 cmd->data |= RXH_L4_B_2_3;
2529
2530 if (cmd->flow_type == TCP_V4_FLOW ||
2531 cmd->flow_type == UDP_V4_FLOW) {
2532 if (i_set & I40E_L3_SRC_MASK)
2533 cmd->data |= RXH_IP_SRC;
2534 if (i_set & I40E_L3_DST_MASK)
2535 cmd->data |= RXH_IP_DST;
2536 } else if (cmd->flow_type == TCP_V6_FLOW ||
2537 cmd->flow_type == UDP_V6_FLOW) {
2538 if (i_set & I40E_L3_V6_SRC_MASK)
2539 cmd->data |= RXH_IP_SRC;
2540 if (i_set & I40E_L3_V6_DST_MASK)
2541 cmd->data |= RXH_IP_DST;
2542 }
2543 }
2544
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002545 return 0;
2546}
2547
2548/**
Jacob Kellere7930952017-02-06 14:38:49 -08002549 * i40e_check_mask - Check whether a mask field is set
2550 * @mask: the full mask value
2551 * @field; mask of the field to check
2552 *
2553 * If the given mask is fully set, return positive value. If the mask for the
2554 * field is fully unset, return zero. Otherwise return a negative error code.
2555 **/
2556static int i40e_check_mask(u64 mask, u64 field)
2557{
2558 u64 value = mask & field;
2559
2560 if (value == field)
2561 return 1;
2562 else if (!value)
2563 return 0;
2564 else
2565 return -1;
2566}
2567
2568/**
2569 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2570 * @fsp: pointer to rx flow specification
2571 * @data: pointer to userdef data structure for storage
2572 *
2573 * Read the user-defined data and deconstruct the value into a structure. No
2574 * other code should read the user-defined data, so as to ensure that every
2575 * place consistently reads the value correctly.
2576 *
2577 * The user-defined field is a 64bit Big Endian format value, which we
2578 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2579 * be defined starting from the highest bits, while small bit field values
2580 * shall be defined starting from the lowest bits.
2581 *
2582 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2583 * and the filter should be rejected. The data structure will always be
2584 * modified even if FLOW_EXT is not set.
2585 *
2586 **/
2587static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2588 struct i40e_rx_flow_userdef *data)
2589{
2590 u64 value, mask;
2591 int valid;
2592
2593 /* Zero memory first so it's always consistent. */
2594 memset(data, 0, sizeof(*data));
2595
2596 if (!(fsp->flow_type & FLOW_EXT))
2597 return 0;
2598
2599 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2600 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2601
2602#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2603#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2604#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2605
2606 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2607 if (valid < 0) {
2608 return -EINVAL;
2609 } else if (valid) {
2610 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2611 data->flex_offset =
2612 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2613 data->flex_filter = true;
2614 }
2615
2616 return 0;
2617}
2618
2619/**
2620 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2621 * @fsp: pointer to rx_flow specification
2622 *
2623 * Reads the userdef data structure and properly fills in the user defined
2624 * fields of the rx_flow_spec.
2625 **/
2626static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2627 struct i40e_rx_flow_userdef *data)
2628{
2629 u64 value = 0, mask = 0;
2630
2631 if (data->flex_filter) {
2632 value |= data->flex_word;
2633 value |= (u64)data->flex_offset << 16;
2634 mask |= I40E_USERDEF_FLEX_FILTER;
2635 }
2636
2637 if (value || mask)
2638 fsp->flow_type |= FLOW_EXT;
2639
2640 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2641 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2642}
2643
2644/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002645 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2646 * @pf: Pointer to the physical function struct
2647 * @cmd: The command to get or set Rx flow classification rules
2648 * @rule_locs: Array of used rule locations
2649 *
2650 * This function populates both the total and actual rule count of
2651 * the ethtool flow classification command
2652 *
2653 * Returns 0 on success or -EMSGSIZE if entry not found
2654 **/
2655static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2656 struct ethtool_rxnfc *cmd,
2657 u32 *rule_locs)
2658{
2659 struct i40e_fdir_filter *rule;
2660 struct hlist_node *node2;
2661 int cnt = 0;
2662
2663 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002664 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002665
2666 hlist_for_each_entry_safe(rule, node2,
2667 &pf->fdir_filter_list, fdir_node) {
2668 if (cnt == cmd->rule_cnt)
2669 return -EMSGSIZE;
2670
2671 rule_locs[cnt] = rule->fd_id;
2672 cnt++;
2673 }
2674
2675 cmd->rule_cnt = cnt;
2676
2677 return 0;
2678}
2679
2680/**
2681 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2682 * @pf: Pointer to the physical function struct
2683 * @cmd: The command to get or set Rx flow classification rules
2684 *
2685 * This function looks up a filter based on the Rx flow classification
2686 * command and fills the flow spec info for it if found
2687 *
2688 * Returns 0 on success or -EINVAL if filter not found
2689 **/
2690static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2691 struct ethtool_rxnfc *cmd)
2692{
2693 struct ethtool_rx_flow_spec *fsp =
2694 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002695 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002696 struct i40e_fdir_filter *rule = NULL;
2697 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002698 u64 input_set;
2699 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002700
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002701 hlist_for_each_entry_safe(rule, node2,
2702 &pf->fdir_filter_list, fdir_node) {
2703 if (fsp->location <= rule->fd_id)
2704 break;
2705 }
2706
2707 if (!rule || fsp->location != rule->fd_id)
2708 return -EINVAL;
2709
2710 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002711 if (fsp->flow_type == IP_USER_FLOW) {
2712 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2713 fsp->h_u.usr_ip4_spec.proto = 0;
2714 fsp->m_u.usr_ip4_spec.proto = 0;
2715 }
2716
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002717 /* Reverse the src and dest notion, since the HW views them from
2718 * Tx perspective where as the user expects it from Rx filter view.
2719 */
2720 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2721 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002722 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2723 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002724
Jacob Keller36777d92017-03-07 15:05:23 -08002725 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002726 case SCTP_V4_FLOW:
2727 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2728 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002729 case TCP_V4_FLOW:
2730 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2731 break;
2732 case UDP_V4_FLOW:
2733 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2734 break;
2735 case IP_USER_FLOW:
2736 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2737 break;
2738 default:
2739 /* If we have stored a filter with a flow type not listed here
2740 * it is almost certainly a driver bug. WARN(), and then
2741 * assign the input_set as if all fields are enabled to avoid
2742 * reading unassigned memory.
2743 */
2744 WARN(1, "Missing input set index for flow_type %d\n",
2745 rule->flow_type);
2746 input_set = 0xFFFFFFFFFFFFFFFFULL;
2747 goto no_input_set;
2748 }
2749
2750 input_set = i40e_read_fd_input_set(pf, index);
2751
2752no_input_set:
2753 if (input_set & I40E_L3_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002754 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002755
2756 if (input_set & I40E_L3_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002757 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002758
2759 if (input_set & I40E_L4_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002760 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002761
2762 if (input_set & I40E_L4_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002763 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002764
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002765 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2766 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2767 else
2768 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002769
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002770 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2771 struct i40e_vsi *vsi;
2772
2773 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2774 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002775 /* VFs are zero-indexed by the driver, but ethtool
2776 * expects them to be one-indexed, so add one here
2777 */
2778 u64 ring_vf = vsi->vf_id + 1;
2779
2780 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2781 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002782 }
2783 }
2784
Jacob Keller0e588de2017-02-06 14:38:50 -08002785 if (rule->flex_filter) {
2786 userdef.flex_filter = true;
2787 userdef.flex_word = be16_to_cpu(rule->flex_word);
2788 userdef.flex_offset = rule->flex_offset;
2789 }
2790
Jacob Kellere7930952017-02-06 14:38:49 -08002791 i40e_fill_rx_flow_user_data(fsp, &userdef);
2792
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002793 return 0;
2794}
2795
2796/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002797 * i40e_get_rxnfc - command to get RX flow classification rules
2798 * @netdev: network interface device structure
2799 * @cmd: ethtool rxnfc command
2800 *
2801 * Returns Success if the command is supported.
2802 **/
2803static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2804 u32 *rule_locs)
2805{
2806 struct i40e_netdev_priv *np = netdev_priv(netdev);
2807 struct i40e_vsi *vsi = np->vsi;
2808 struct i40e_pf *pf = vsi->back;
2809 int ret = -EOPNOTSUPP;
2810
2811 switch (cmd->cmd) {
2812 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002813 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002814 ret = 0;
2815 break;
2816 case ETHTOOL_GRXFH:
2817 ret = i40e_get_rss_hash_opts(pf, cmd);
2818 break;
2819 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002820 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002821 /* report total rule count */
2822 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002823 ret = 0;
2824 break;
2825 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002826 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002827 break;
2828 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002829 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2830 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002831 default:
2832 break;
2833 }
2834
2835 return ret;
2836}
2837
2838/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002839 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2840 * @nfc: pointer to user request
2841 * @i_setc bits currently set
2842 *
2843 * Returns value of bits to be set per user request
2844 **/
2845static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2846{
2847 u64 i_set = i_setc;
2848 u64 src_l3 = 0, dst_l3 = 0;
2849
2850 if (nfc->data & RXH_L4_B_0_1)
2851 i_set |= I40E_L4_SRC_MASK;
2852 else
2853 i_set &= ~I40E_L4_SRC_MASK;
2854 if (nfc->data & RXH_L4_B_2_3)
2855 i_set |= I40E_L4_DST_MASK;
2856 else
2857 i_set &= ~I40E_L4_DST_MASK;
2858
2859 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2860 src_l3 = I40E_L3_V6_SRC_MASK;
2861 dst_l3 = I40E_L3_V6_DST_MASK;
2862 } else if (nfc->flow_type == TCP_V4_FLOW ||
2863 nfc->flow_type == UDP_V4_FLOW) {
2864 src_l3 = I40E_L3_SRC_MASK;
2865 dst_l3 = I40E_L3_DST_MASK;
2866 } else {
2867 /* Any other flow type are not supported here */
2868 return i_set;
2869 }
2870
2871 if (nfc->data & RXH_IP_SRC)
2872 i_set |= src_l3;
2873 else
2874 i_set &= ~src_l3;
2875 if (nfc->data & RXH_IP_DST)
2876 i_set |= dst_l3;
2877 else
2878 i_set &= ~dst_l3;
2879
2880 return i_set;
2881}
2882
2883/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002884 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2885 * @pf: pointer to the physical function struct
2886 * @cmd: ethtool rxnfc command
2887 *
2888 * Returns Success if the flow input set is supported.
2889 **/
2890static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2891{
2892 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002893 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2894 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002895 u8 flow_pctype = 0;
2896 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002897
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002898 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2899 dev_err(&pf->pdev->dev,
2900 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2901 return -EOPNOTSUPP;
2902 }
2903
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002904 /* RSS does not support anything other than hashing
2905 * to queues on src and dst IPs and ports
2906 */
2907 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2908 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2909 return -EINVAL;
2910
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002911 switch (nfc->flow_type) {
2912 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002913 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002914 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002915 hena |=
2916 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002917 break;
2918 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002919 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002920 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002921 hena |=
2922 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002923 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002924 hena |=
2925 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002926 break;
2927 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002928 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002929 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002930 hena |=
2931 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2932 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002933
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002934 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002935 break;
2936 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002937 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002938 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002939 hena |=
2940 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2941 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002942
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002943 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002944 break;
2945 case AH_ESP_V4_FLOW:
2946 case AH_V4_FLOW:
2947 case ESP_V4_FLOW:
2948 case SCTP_V4_FLOW:
2949 if ((nfc->data & RXH_L4_B_0_1) ||
2950 (nfc->data & RXH_L4_B_2_3))
2951 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002952 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002953 break;
2954 case AH_ESP_V6_FLOW:
2955 case AH_V6_FLOW:
2956 case ESP_V6_FLOW:
2957 case SCTP_V6_FLOW:
2958 if ((nfc->data & RXH_L4_B_0_1) ||
2959 (nfc->data & RXH_L4_B_2_3))
2960 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002961 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002962 break;
2963 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002964 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2965 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002966 break;
2967 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002968 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2969 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002970 break;
2971 default:
2972 return -EINVAL;
2973 }
2974
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002975 if (flow_pctype) {
2976 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2977 flow_pctype)) |
2978 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2979 flow_pctype)) << 32);
2980 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2981 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2982 (u32)i_set);
2983 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2984 (u32)(i_set >> 32));
2985 hena |= BIT_ULL(flow_pctype);
2986 }
2987
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002988 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2989 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002990 i40e_flush(hw);
2991
2992 return 0;
2993}
2994
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002995/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002996 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2997 * @vsi: Pointer to the targeted VSI
2998 * @input: The filter to update or NULL to indicate deletion
2999 * @sw_idx: Software index to the filter
3000 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003001 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003002 * This function updates (or deletes) a Flow Director entry from
3003 * the hlist of the corresponding PF
3004 *
3005 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003006 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003007static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
3008 struct i40e_fdir_filter *input,
3009 u16 sw_idx,
3010 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003011{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003012 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003013 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003014 struct hlist_node *node2;
3015 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003016
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003017 parent = NULL;
3018 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003019
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003020 hlist_for_each_entry_safe(rule, node2,
3021 &pf->fdir_filter_list, fdir_node) {
3022 /* hash found, or no matching entry */
3023 if (rule->fd_id >= sw_idx)
3024 break;
3025 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003026 }
3027
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003028 /* if there is an old rule occupying our place remove it */
3029 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08003030 /* Remove this rule, since we're either deleting it, or
3031 * replacing it.
3032 */
3033 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003034 hlist_del(&rule->fdir_node);
3035 kfree(rule);
3036 pf->fdir_pf_active_filters--;
3037 }
3038
Jacob Kellerc6da5252017-02-06 14:39:13 -08003039 /* If we weren't given an input, this is a delete, so just return the
3040 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003041 */
3042 if (!input)
3043 return err;
3044
Jacob Kellerc6da5252017-02-06 14:39:13 -08003045 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003046 INIT_HLIST_NODE(&input->fdir_node);
3047
3048 /* add filter to the list */
3049 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003050 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003051 else
3052 hlist_add_head(&input->fdir_node,
3053 &pf->fdir_filter_list);
3054
3055 /* update counts */
3056 pf->fdir_pf_active_filters++;
3057
3058 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003059}
3060
3061/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003062 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3063 * @pf: pointer to PF structure
3064 *
3065 * This function searches the list of filters and determines which FLX_PIT
3066 * entries are still required. It will prune any entries which are no longer
3067 * in use after the deletion.
3068 **/
3069static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3070{
3071 struct i40e_flex_pit *entry, *tmp;
3072 struct i40e_fdir_filter *rule;
3073
3074 /* First, we'll check the l3 table */
3075 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3076 bool found = false;
3077
3078 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3079 if (rule->flow_type != IP_USER_FLOW)
3080 continue;
3081 if (rule->flex_filter &&
3082 rule->flex_offset == entry->src_offset) {
3083 found = true;
3084 break;
3085 }
3086 }
3087
3088 /* If we didn't find the filter, then we can prune this entry
3089 * from the list.
3090 */
3091 if (!found) {
3092 list_del(&entry->list);
3093 kfree(entry);
3094 }
3095 }
3096
3097 /* Followed by the L4 table */
3098 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3099 bool found = false;
3100
3101 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3102 /* Skip this filter if it's L3, since we already
3103 * checked those in the above loop
3104 */
3105 if (rule->flow_type == IP_USER_FLOW)
3106 continue;
3107 if (rule->flex_filter &&
3108 rule->flex_offset == entry->src_offset) {
3109 found = true;
3110 break;
3111 }
3112 }
3113
3114 /* If we didn't find the filter, then we can prune this entry
3115 * from the list.
3116 */
3117 if (!found) {
3118 list_del(&entry->list);
3119 kfree(entry);
3120 }
3121 }
3122}
3123
3124/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003125 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3126 * @vsi: Pointer to the targeted VSI
3127 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003128 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003129 * The function removes a Flow Director filter entry from the
3130 * hlist of the corresponding PF
3131 *
3132 * Returns 0 on success
3133 */
3134static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3135 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003136{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003137 struct ethtool_rx_flow_spec *fsp =
3138 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003139 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003140 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003141
Jacob Keller0da36b92017-04-19 09:25:55 -04003142 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3143 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003144 return -EBUSY;
3145
Jacob Keller0da36b92017-04-19 09:25:55 -04003146 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003147 return -EBUSY;
3148
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003149 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003150
Jacob Keller0e588de2017-02-06 14:38:50 -08003151 i40e_prune_flex_pit_list(pf);
3152
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003153 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003154 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003155}
3156
3157/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003158 * i40e_unused_pit_index - Find an unused PIT index for given list
3159 * @pf: the PF data structure
3160 *
3161 * Find the first unused flexible PIT index entry. We search both the L3 and
3162 * L4 flexible PIT lists so that the returned index is unique and unused by
3163 * either currently programmed L3 or L4 filters. We use a bit field as storage
3164 * to track which indexes are already used.
3165 **/
3166static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3167{
3168 unsigned long available_index = 0xFF;
3169 struct i40e_flex_pit *entry;
3170
3171 /* We need to make sure that the new index isn't in use by either L3
3172 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3173 * L4 to use the same index.
3174 */
3175
3176 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3177 clear_bit(entry->pit_index, &available_index);
3178
3179 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3180 clear_bit(entry->pit_index, &available_index);
3181
3182 return find_first_bit(&available_index, 8);
3183}
3184
3185/**
3186 * i40e_find_flex_offset - Find an existing flex src_offset
3187 * @flex_pit_list: L3 or L4 flex PIT list
3188 * @src_offset: new src_offset to find
3189 *
3190 * Searches the flex_pit_list for an existing offset. If no offset is
3191 * currently programmed, then this will return an ERR_PTR if there is no space
3192 * to add a new offset, otherwise it returns NULL.
3193 **/
3194static
3195struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3196 u16 src_offset)
3197{
3198 struct i40e_flex_pit *entry;
3199 int size = 0;
3200
3201 /* Search for the src_offset first. If we find a matching entry
3202 * already programmed, we can simply re-use it.
3203 */
3204 list_for_each_entry(entry, flex_pit_list, list) {
3205 size++;
3206 if (entry->src_offset == src_offset)
3207 return entry;
3208 }
3209
3210 /* If we haven't found an entry yet, then the provided src offset has
3211 * not yet been programmed. We will program the src offset later on,
3212 * but we need to indicate whether there is enough space to do so
3213 * here. We'll make use of ERR_PTR for this purpose.
3214 */
3215 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3216 return ERR_PTR(-ENOSPC);
3217
3218 return NULL;
3219}
3220
3221/**
3222 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3223 * @flex_pit_list: L3 or L4 flex PIT list
3224 * @src_offset: new src_offset to add
3225 * @pit_index: the PIT index to program
3226 *
3227 * This function programs the new src_offset to the list. It is expected that
3228 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3229 * that this offset is not programmed, and that the list has enough space to
3230 * store another offset.
3231 *
3232 * Returns 0 on success, and negative value on error.
3233 **/
3234static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3235 u16 src_offset,
3236 u8 pit_index)
3237{
3238 struct i40e_flex_pit *new_pit, *entry;
3239
3240 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3241 if (!new_pit)
3242 return -ENOMEM;
3243
3244 new_pit->src_offset = src_offset;
3245 new_pit->pit_index = pit_index;
3246
3247 /* We need to insert this item such that the list is sorted by
3248 * src_offset in ascending order.
3249 */
3250 list_for_each_entry(entry, flex_pit_list, list) {
3251 if (new_pit->src_offset < entry->src_offset) {
3252 list_add_tail(&new_pit->list, &entry->list);
3253 return 0;
3254 }
3255
3256 /* If we found an entry with our offset already programmed we
3257 * can simply return here, after freeing the memory. However,
3258 * if the pit_index does not match we need to report an error.
3259 */
3260 if (new_pit->src_offset == entry->src_offset) {
3261 int err = 0;
3262
3263 /* If the PIT index is not the same we can't re-use
3264 * the entry, so we must report an error.
3265 */
3266 if (new_pit->pit_index != entry->pit_index)
3267 err = -EINVAL;
3268
3269 kfree(new_pit);
3270 return err;
3271 }
3272 }
3273
3274 /* If we reached here, then we haven't yet added the item. This means
3275 * that we should add the item at the end of the list.
3276 */
3277 list_add_tail(&new_pit->list, flex_pit_list);
3278 return 0;
3279}
3280
3281/**
3282 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3283 * @pf: Pointer to the PF structure
3284 * @flex_pit_list: list of flexible src offsets in use
3285 * #flex_pit_start: index to first entry for this section of the table
3286 *
3287 * In order to handle flexible data, the hardware uses a table of values
3288 * called the FLX_PIT table. This table is used to indicate which sections of
3289 * the input correspond to what PIT index values. Unfortunately, hardware is
3290 * very restrictive about programming this table. Entries must be ordered by
3291 * src_offset in ascending order, without duplicates. Additionally, unused
3292 * entries must be set to the unused index value, and must have valid size and
3293 * length according to the src_offset ordering.
3294 *
3295 * This function will reprogram the FLX_PIT register from a book-keeping
3296 * structure that we guarantee is already ordered correctly, and has no more
3297 * than 3 entries.
3298 *
3299 * To make things easier, we only support flexible values of one word length,
3300 * rather than allowing variable length flexible values.
3301 **/
3302static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3303 struct list_head *flex_pit_list,
3304 int flex_pit_start)
3305{
3306 struct i40e_flex_pit *entry = NULL;
3307 u16 last_offset = 0;
3308 int i = 0, j = 0;
3309
3310 /* First, loop over the list of flex PIT entries, and reprogram the
3311 * registers.
3312 */
3313 list_for_each_entry(entry, flex_pit_list, list) {
3314 /* We have to be careful when programming values for the
3315 * largest SRC_OFFSET value. It is possible that adding
3316 * additional empty values at the end would overflow the space
3317 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3318 * we check here and add the empty values prior to adding the
3319 * largest value.
3320 *
3321 * To determine this, we will use a loop from i+1 to 3, which
3322 * will determine whether the unused entries would have valid
3323 * SRC_OFFSET. Note that there cannot be extra entries past
3324 * this value, because the only valid values would have been
3325 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3326 * have been added to the list in the first place.
3327 */
3328 for (j = i + 1; j < 3; j++) {
3329 u16 offset = entry->src_offset + j;
3330 int index = flex_pit_start + i;
3331 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3332 1,
3333 offset - 3);
3334
3335 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3336 i40e_write_rx_ctl(&pf->hw,
3337 I40E_PRTQF_FLX_PIT(index),
3338 value);
3339 i++;
3340 }
3341 }
3342
3343 /* Now, we can program the actual value into the table */
3344 i40e_write_rx_ctl(&pf->hw,
3345 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3346 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3347 1,
3348 entry->src_offset));
3349 i++;
3350 }
3351
3352 /* In order to program the last entries in the table, we need to
3353 * determine the valid offset. If the list is empty, we'll just start
3354 * with 0. Otherwise, we'll start with the last item offset and add 1.
3355 * This ensures that all entries have valid sizes. If we don't do this
3356 * correctly, the hardware will disable flexible field parsing.
3357 */
3358 if (!list_empty(flex_pit_list))
3359 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3360
3361 for (; i < 3; i++, last_offset++) {
3362 i40e_write_rx_ctl(&pf->hw,
3363 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3364 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3365 1,
3366 last_offset));
3367 }
3368}
3369
3370/**
3371 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3372 * @pf: pointer to the PF structure
3373 *
3374 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3375 * internal helper function for implementation details.
3376 **/
3377static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3378{
3379 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3380 I40E_FLEX_PIT_IDX_START_L3);
3381
3382 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3383 I40E_FLEX_PIT_IDX_START_L4);
3384
3385 /* We also need to program the L3 and L4 GLQF ORT register */
3386 i40e_write_rx_ctl(&pf->hw,
3387 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3388 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3389 3, 1));
3390
3391 i40e_write_rx_ctl(&pf->hw,
3392 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3393 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3394 3, 1));
3395}
3396
3397/**
Jacob Keller9229e992017-02-06 14:38:47 -08003398 * i40e_flow_str - Converts a flow_type into a human readable string
3399 * @flow_type: the flow type from a flow specification
3400 *
3401 * Currently only flow types we support are included here, and the string
3402 * value attempts to match what ethtool would use to configure this flow type.
3403 **/
3404static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3405{
3406 switch (fsp->flow_type & ~FLOW_EXT) {
3407 case TCP_V4_FLOW:
3408 return "tcp4";
3409 case UDP_V4_FLOW:
3410 return "udp4";
3411 case SCTP_V4_FLOW:
3412 return "sctp4";
3413 case IP_USER_FLOW:
3414 return "ip4";
3415 default:
3416 return "unknown";
3417 }
3418}
3419
3420/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003421 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3422 * @pit_index: PIT index to convert
3423 *
3424 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3425 * of range.
3426 **/
3427static u64 i40e_pit_index_to_mask(int pit_index)
3428{
3429 switch (pit_index) {
3430 case 0:
3431 return I40E_FLEX_50_MASK;
3432 case 1:
3433 return I40E_FLEX_51_MASK;
3434 case 2:
3435 return I40E_FLEX_52_MASK;
3436 case 3:
3437 return I40E_FLEX_53_MASK;
3438 case 4:
3439 return I40E_FLEX_54_MASK;
3440 case 5:
3441 return I40E_FLEX_55_MASK;
3442 case 6:
3443 return I40E_FLEX_56_MASK;
3444 case 7:
3445 return I40E_FLEX_57_MASK;
3446 default:
3447 return 0;
3448 }
3449}
3450
3451/**
Jacob Keller9229e992017-02-06 14:38:47 -08003452 * i40e_print_input_set - Show changes between two input sets
3453 * @vsi: the vsi being configured
3454 * @old: the old input set
3455 * @new: the new input set
3456 *
3457 * Print the difference between old and new input sets by showing which series
3458 * of words are toggled on or off. Only displays the bits we actually support
3459 * changing.
3460 **/
3461static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3462{
3463 struct i40e_pf *pf = vsi->back;
3464 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003465 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003466
3467 old_value = !!(old & I40E_L3_SRC_MASK);
3468 new_value = !!(new & I40E_L3_SRC_MASK);
3469 if (old_value != new_value)
3470 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3471 old_value ? "ON" : "OFF",
3472 new_value ? "ON" : "OFF");
3473
3474 old_value = !!(old & I40E_L3_DST_MASK);
3475 new_value = !!(new & I40E_L3_DST_MASK);
3476 if (old_value != new_value)
3477 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3478 old_value ? "ON" : "OFF",
3479 new_value ? "ON" : "OFF");
3480
3481 old_value = !!(old & I40E_L4_SRC_MASK);
3482 new_value = !!(new & I40E_L4_SRC_MASK);
3483 if (old_value != new_value)
3484 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3485 old_value ? "ON" : "OFF",
3486 new_value ? "ON" : "OFF");
3487
3488 old_value = !!(old & I40E_L4_DST_MASK);
3489 new_value = !!(new & I40E_L4_DST_MASK);
3490 if (old_value != new_value)
3491 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3492 old_value ? "ON" : "OFF",
3493 new_value ? "ON" : "OFF");
3494
3495 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3496 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3497 if (old_value != new_value)
3498 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3499 old_value ? "ON" : "OFF",
3500 new_value ? "ON" : "OFF");
3501
Jacob Keller0e588de2017-02-06 14:38:50 -08003502 /* Show change of flexible filter entries */
3503 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3504 u64 flex_mask = i40e_pit_index_to_mask(i);
3505
3506 old_value = !!(old & flex_mask);
3507 new_value = !!(new & flex_mask);
3508 if (old_value != new_value)
3509 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3510 i,
3511 old_value ? "ON" : "OFF",
3512 new_value ? "ON" : "OFF");
3513 }
3514
Jacob Keller9229e992017-02-06 14:38:47 -08003515 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3516 old);
3517 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3518 new);
3519}
3520
3521/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003522 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003523 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003524 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003525 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003526 *
Jacob Keller9229e992017-02-06 14:38:47 -08003527 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3528 * for partial matches exists with a few limitations. First, hardware only
3529 * supports masking by word boundary (2 bytes) and not per individual bit.
3530 * Second, hardware is limited to using one mask for a flow type and cannot
3531 * use a separate mask for each filter.
3532 *
3533 * To support these limitations, if we already have a configured filter for
3534 * the specified type, this function enforces that new filters of the type
3535 * match the configured input set. Otherwise, if we do not have a filter of
3536 * the specified type, we allow the input set to be updated to match the
3537 * desired filter.
3538 *
3539 * To help ensure that administrators understand why filters weren't displayed
3540 * as supported, we print a diagnostic message displaying how the input set
3541 * would change and warning to delete the preexisting filters if required.
3542 *
3543 * Returns 0 on successful input set match, and a negative return code on
3544 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003545 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003546static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003547 struct ethtool_rx_flow_spec *fsp,
3548 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003549{
Jacob Keller36777d92017-03-07 15:05:23 -08003550 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003551 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3552 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003553 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003554 bool new_flex_offset = false;
3555 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003556 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003557 u16 index, src_offset = 0;
3558 u8 pit_index = 0;
3559 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003560
3561 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003562 case SCTP_V4_FLOW:
3563 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3564 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3565 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003566 case TCP_V4_FLOW:
3567 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003568 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003569 break;
3570 case UDP_V4_FLOW:
3571 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003572 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003573 break;
3574 case IP_USER_FLOW:
3575 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003576 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003577 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003578 break;
3579 default:
3580 return -EOPNOTSUPP;
3581 }
3582
3583 /* Read the current input set from register memory. */
3584 current_mask = i40e_read_fd_input_set(pf, index);
3585 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003586
Jacob Keller9229e992017-02-06 14:38:47 -08003587 /* Determine, if any, the required changes to the input set in order
3588 * to support the provided mask.
3589 *
3590 * Hardware only supports masking at word (2 byte) granularity and does
3591 * not support full bitwise masking. This implementation simplifies
3592 * even further and only supports fully enabled or fully disabled
3593 * masks for each field, even though we could split the ip4src and
3594 * ip4dst fields.
3595 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003596 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003597 case SCTP_V4_FLOW:
3598 new_mask &= ~I40E_VERIFY_TAG_MASK;
3599 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003600 case TCP_V4_FLOW:
3601 case UDP_V4_FLOW:
3602 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3603
3604 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003605 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3606 new_mask |= I40E_L3_SRC_MASK;
3607 else if (!tcp_ip4_spec->ip4src)
3608 new_mask &= ~I40E_L3_SRC_MASK;
3609 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003610 return -EOPNOTSUPP;
3611
3612 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003613 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3614 new_mask |= I40E_L3_DST_MASK;
3615 else if (!tcp_ip4_spec->ip4dst)
3616 new_mask &= ~I40E_L3_DST_MASK;
3617 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003618 return -EOPNOTSUPP;
3619
3620 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003621 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3622 new_mask |= I40E_L4_SRC_MASK;
3623 else if (!tcp_ip4_spec->psrc)
3624 new_mask &= ~I40E_L4_SRC_MASK;
3625 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003626 return -EOPNOTSUPP;
3627
3628 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003629 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3630 new_mask |= I40E_L4_DST_MASK;
3631 else if (!tcp_ip4_spec->pdst)
3632 new_mask &= ~I40E_L4_DST_MASK;
3633 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003634 return -EOPNOTSUPP;
3635
3636 /* Filtering on Type of Service is not supported. */
3637 if (tcp_ip4_spec->tos)
3638 return -EOPNOTSUPP;
3639
3640 break;
3641 case IP_USER_FLOW:
3642 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3643
3644 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003645 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3646 new_mask |= I40E_L3_SRC_MASK;
3647 else if (!usr_ip4_spec->ip4src)
3648 new_mask &= ~I40E_L3_SRC_MASK;
3649 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003650 return -EOPNOTSUPP;
3651
3652 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003653 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3654 new_mask |= I40E_L3_DST_MASK;
3655 else if (!usr_ip4_spec->ip4dst)
3656 new_mask &= ~I40E_L3_DST_MASK;
3657 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003658 return -EOPNOTSUPP;
3659
3660 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003661 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3662 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3663 else if (!usr_ip4_spec->l4_4_bytes)
3664 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3665 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003666 return -EOPNOTSUPP;
3667
3668 /* Filtering on Type of Service is not supported. */
3669 if (usr_ip4_spec->tos)
3670 return -EOPNOTSUPP;
3671
Jacob Keller0e588de2017-02-06 14:38:50 -08003672 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003673 if (usr_ip4_spec->ip_ver)
3674 return -EINVAL;
3675
Jacob Keller0e588de2017-02-06 14:38:50 -08003676 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003677 if (usr_ip4_spec->proto)
3678 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003679
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003680 break;
3681 default:
3682 return -EOPNOTSUPP;
3683 }
3684
Jacob Keller0e588de2017-02-06 14:38:50 -08003685 /* First, clear all flexible filter entries */
3686 new_mask &= ~I40E_FLEX_INPUT_MASK;
3687
3688 /* If we have a flexible filter, try to add this offset to the correct
3689 * flexible filter PIT list. Once finished, we can update the mask.
3690 * If the src_offset changed, we will get a new mask value which will
3691 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003692 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003693 if (userdef->flex_filter) {
3694 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3695
3696 /* Flexible offset must be even, since the flexible payload
3697 * must be aligned on 2-byte boundary.
3698 */
3699 if (userdef->flex_offset & 0x1) {
3700 dev_warn(&pf->pdev->dev,
3701 "Flexible data offset must be 2-byte aligned\n");
3702 return -EINVAL;
3703 }
3704
3705 src_offset = userdef->flex_offset >> 1;
3706
3707 /* FLX_PIT source offset value is only so large */
3708 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3709 dev_warn(&pf->pdev->dev,
3710 "Flexible data must reside within first 64 bytes of the packet payload\n");
3711 return -EINVAL;
3712 }
3713
3714 /* See if this offset has already been programmed. If we get
3715 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3716 * if we get a NULL pointer, this means we will need to add
3717 * the offset.
3718 */
3719 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3720 src_offset);
3721 if (IS_ERR(flex_pit))
3722 return PTR_ERR(flex_pit);
3723
3724 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3725 * packet types, and thus we need to program both L3 and L4
3726 * flexible values. These must have identical flexible index,
3727 * as otherwise we can't correctly program the input set. So
3728 * we'll find both an L3 and L4 index and make sure they are
3729 * the same.
3730 */
3731 if (flex_l3) {
3732 l3_flex_pit =
3733 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3734 src_offset);
3735 if (IS_ERR(l3_flex_pit))
3736 return PTR_ERR(l3_flex_pit);
3737
3738 if (flex_pit) {
3739 /* If we already had a matching L4 entry, we
3740 * need to make sure that the L3 entry we
3741 * obtained uses the same index.
3742 */
3743 if (l3_flex_pit) {
3744 if (l3_flex_pit->pit_index !=
3745 flex_pit->pit_index) {
3746 return -EINVAL;
3747 }
3748 } else {
3749 new_flex_offset = true;
3750 }
3751 } else {
3752 flex_pit = l3_flex_pit;
3753 }
3754 }
3755
3756 /* If we didn't find an existing flex offset, we need to
3757 * program a new one. However, we don't immediately program it
3758 * here because we will wait to program until after we check
3759 * that it is safe to change the input set.
3760 */
3761 if (!flex_pit) {
3762 new_flex_offset = true;
3763 pit_index = i40e_unused_pit_index(pf);
3764 } else {
3765 pit_index = flex_pit->pit_index;
3766 }
3767
3768 /* Update the mask with the new offset */
3769 new_mask |= i40e_pit_index_to_mask(pit_index);
3770 }
3771
3772 /* If the mask and flexible filter offsets for this filter match the
3773 * currently programmed values we don't need any input set change, so
3774 * this filter is safe to install.
3775 */
3776 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003777 return 0;
3778
3779 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3780 i40e_flow_str(fsp));
3781 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003782 if (new_flex_offset) {
3783 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3784 pit_index, src_offset);
3785 }
Jacob Keller9229e992017-02-06 14:38:47 -08003786
3787 /* Hardware input sets are global across multiple ports, so even the
3788 * main port cannot change them when in MFP mode as this would impact
3789 * any filters on the other ports.
3790 */
3791 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3792 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003793 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003794 }
3795
3796 /* This filter requires us to update the input set. However, hardware
3797 * only supports one input set per flow type, and does not support
3798 * separate masks for each filter. This means that we can only support
3799 * a single mask for all filters of a specific type.
3800 *
3801 * If we have preexisting filters, they obviously depend on the
3802 * current programmed input set. Display a diagnostic message in this
3803 * case explaining why the filter could not be accepted.
3804 */
3805 if (*fdir_filter_count) {
3806 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3807 i40e_flow_str(fsp),
3808 *fdir_filter_count);
3809 return -EOPNOTSUPP;
3810 }
3811
3812 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003813
Jacob Keller02b40162017-12-27 08:24:12 -05003814 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
3815 * frames. If we're programming the input set for IPv4/Other, we also
3816 * need to program the IPv4/Fragmented input set. Since we don't have
3817 * separate support, we'll always assume and enforce that the two flow
3818 * types must have matching input sets.
3819 */
3820 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
3821 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
3822 new_mask);
3823
Jacob Keller0e588de2017-02-06 14:38:50 -08003824 /* Add the new offset and update table, if necessary */
3825 if (new_flex_offset) {
3826 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3827 pit_index);
3828 if (err)
3829 return err;
3830
3831 if (flex_l3) {
3832 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3833 src_offset,
3834 pit_index);
3835 if (err)
3836 return err;
3837 }
3838
3839 i40e_reprogram_flex_pit(pf);
3840 }
3841
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003842 return 0;
3843}
3844
3845/**
Jacob Keller443ee712017-12-27 08:25:32 -05003846 * i40e_match_fdir_filter - Return true of two filters match
3847 * @a: pointer to filter struct
3848 * @b: pointer to filter struct
3849 *
3850 * Returns true if the two filters match exactly the same criteria. I.e. they
3851 * match the same flow type and have the same parameters. We don't need to
3852 * check any input-set since all filters of the same flow type must use the
3853 * same input set.
3854 **/
3855static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
3856 struct i40e_fdir_filter *b)
3857{
3858 /* The filters do not much if any of these criteria differ. */
3859 if (a->dst_ip != b->dst_ip ||
3860 a->src_ip != b->src_ip ||
3861 a->dst_port != b->dst_port ||
3862 a->src_port != b->src_port ||
3863 a->flow_type != b->flow_type ||
3864 a->ip4_proto != b->ip4_proto)
3865 return false;
3866
3867 return true;
3868}
3869
3870/**
3871 * i40e_disallow_matching_filters - Check that new filters differ
3872 * @vsi: pointer to the targeted VSI
3873 * @input: new filter to check
3874 *
3875 * Due to hardware limitations, it is not possible for two filters that match
3876 * similar criteria to be programmed at the same time. This is true for a few
3877 * reasons:
3878 *
3879 * (a) all filters matching a particular flow type must use the same input
3880 * set, that is they must match the same criteria.
3881 * (b) different flow types will never match the same packet, as the flow type
3882 * is decided by hardware before checking which rules apply.
3883 * (c) hardware has no way to distinguish which order filters apply in.
3884 *
3885 * Due to this, we can't really support using the location data to order
3886 * filters in the hardware parsing. It is technically possible for the user to
3887 * request two filters matching the same criteria but which select different
3888 * queues. In this case, rather than keep both filters in the list, we reject
3889 * the 2nd filter when the user requests adding it.
3890 *
3891 * This avoids needing to track location for programming the filter to
3892 * hardware, and ensures that we avoid some strange scenarios involving
3893 * deleting filters which match the same criteria.
3894 **/
3895static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
3896 struct i40e_fdir_filter *input)
3897{
3898 struct i40e_pf *pf = vsi->back;
3899 struct i40e_fdir_filter *rule;
3900 struct hlist_node *node2;
3901
3902 /* Loop through every filter, and check that it doesn't match */
3903 hlist_for_each_entry_safe(rule, node2,
3904 &pf->fdir_filter_list, fdir_node) {
3905 /* Don't check the filters match if they share the same fd_id,
3906 * since the new filter is actually just updating the target
3907 * of the old filter.
3908 */
3909 if (rule->fd_id == input->fd_id)
3910 continue;
3911
3912 /* If any filters match, then print a warning message to the
3913 * kernel message buffer and bail out.
3914 */
3915 if (i40e_match_fdir_filter(rule, input)) {
3916 dev_warn(&pf->pdev->dev,
3917 "Existing user defined filter %d already matches this flow.\n",
3918 rule->fd_id);
3919 return -EINVAL;
3920 }
3921 }
3922
3923 return 0;
3924}
3925
3926/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003927 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003928 * @vsi: pointer to the targeted VSI
3929 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003930 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003931 * Add Flow Director filters for a specific flow spec based on their
3932 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003933 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003934static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3935 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003936{
Jacob Kellere7930952017-02-06 14:38:49 -08003937 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003938 struct ethtool_rx_flow_spec *fsp;
3939 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003940 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003941 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003942 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003943 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003944
3945 if (!vsi)
3946 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003947 pf = vsi->back;
3948
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003949 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3950 return -EOPNOTSUPP;
3951
Jacob Keller47994c12017-04-19 09:25:57 -04003952 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003953 return -ENOSPC;
3954
Jacob Keller0da36b92017-04-19 09:25:55 -04003955 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3956 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003957 return -EBUSY;
3958
Jacob Keller0da36b92017-04-19 09:25:55 -04003959 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003960 return -EBUSY;
3961
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003962 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3963
Jacob Kellere7930952017-02-06 14:38:49 -08003964 /* Parse the user-defined field */
3965 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3966 return -EINVAL;
3967
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003968 /* Extended MAC field is not supported */
3969 if (fsp->flow_type & FLOW_MAC_EXT)
3970 return -EINVAL;
3971
Jacob Keller0e588de2017-02-06 14:38:50 -08003972 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003973 if (ret)
3974 return ret;
3975
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003976 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3977 pf->hw.func_caps.fd_filters_guaranteed)) {
3978 return -EINVAL;
3979 }
3980
Jacob Keller43b15692017-02-06 14:38:48 -08003981 /* ring_cookie is either the drop index, or is a mask of the queue
3982 * index and VF id we wish to target.
3983 */
3984 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3985 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3986 } else {
3987 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3988 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3989
3990 if (!vf) {
3991 if (ring >= vsi->num_queue_pairs)
3992 return -EINVAL;
3993 dest_vsi = vsi->id;
3994 } else {
3995 /* VFs are zero-indexed, so we subtract one here */
3996 vf--;
3997
3998 if (vf >= pf->num_alloc_vfs)
3999 return -EINVAL;
4000 if (ring >= pf->vf[vf].num_queue_pairs)
4001 return -EINVAL;
4002 dest_vsi = pf->vf[vf].lan_vsi_id;
4003 }
4004 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
4005 q_index = ring;
4006 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004007
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004008 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004009
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004010 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004011 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004012
4013 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08004014 input->q_index = q_index;
4015 input->dest_vsi = dest_vsi;
4016 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004017 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04004018 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08004019 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4020 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08004021 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004022 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00004023
4024 /* Reverse the src and dest notion, since the HW expects them to be from
4025 * Tx perspective where as the input from user is from Rx filter view.
4026 */
4027 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4028 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08004029 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4030 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004031
Jacob Keller0e588de2017-02-06 14:38:50 -08004032 if (userdef.flex_filter) {
4033 input->flex_filter = true;
4034 input->flex_word = cpu_to_be16(userdef.flex_word);
4035 input->flex_offset = userdef.flex_offset;
4036 }
4037
Jacob Keller443ee712017-12-27 08:25:32 -05004038 /* Avoid programming two filters with identical match criteria. */
4039 ret = i40e_disallow_matching_filters(vsi, input);
4040 if (ret)
4041 goto free_filter_memory;
4042
Jacob Keller01016da2017-02-06 14:38:40 -08004043 /* Add the input filter to the fdir_input_list, possibly replacing
4044 * a previous filter. Do not free the input structure after adding it
4045 * to the list as this would cause a use-after-free bug.
4046 */
4047 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Patryk Małekca6e1d02017-12-27 07:32:31 -05004048 ret = i40e_add_del_fdir(vsi, input, true);
4049 if (ret)
4050 goto remove_sw_rule;
Jacob Keller01016da2017-02-06 14:38:40 -08004051 return 0;
4052
Patryk Małekca6e1d02017-12-27 07:32:31 -05004053remove_sw_rule:
4054 hlist_del(&input->fdir_node);
4055 pf->fdir_pf_active_filters--;
Jacob Keller443ee712017-12-27 08:25:32 -05004056free_filter_memory:
Jacob Keller01016da2017-02-06 14:38:40 -08004057 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004058 return ret;
4059}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08004060
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004061/**
4062 * i40e_set_rxnfc - command to set RX flow classification rules
4063 * @netdev: network interface device structure
4064 * @cmd: ethtool rxnfc command
4065 *
4066 * Returns Success if the command is supported.
4067 **/
4068static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4069{
4070 struct i40e_netdev_priv *np = netdev_priv(netdev);
4071 struct i40e_vsi *vsi = np->vsi;
4072 struct i40e_pf *pf = vsi->back;
4073 int ret = -EOPNOTSUPP;
4074
4075 switch (cmd->cmd) {
4076 case ETHTOOL_SRXFH:
4077 ret = i40e_set_rss_hash_opt(pf, cmd);
4078 break;
4079 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00004080 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004081 break;
4082 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004083 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004084 break;
4085 default:
4086 break;
4087 }
4088
4089 return ret;
4090}
4091
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004092/**
4093 * i40e_max_channels - get Max number of combined channels supported
4094 * @vsi: vsi pointer
4095 **/
4096static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4097{
4098 /* TODO: This code assumes DCB and FD is disabled for now. */
4099 return vsi->alloc_queue_pairs;
4100}
4101
4102/**
4103 * i40e_get_channels - Get the current channels enabled and max supported etc.
4104 * @netdev: network interface device structure
4105 * @ch: ethtool channels structure
4106 *
4107 * We don't support separate tx and rx queues as channels. The other count
4108 * represents how many queues are being used for control. max_combined counts
4109 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4110 * q_vectors since we support a lot more queue pairs than q_vectors.
4111 **/
4112static void i40e_get_channels(struct net_device *dev,
4113 struct ethtool_channels *ch)
4114{
4115 struct i40e_netdev_priv *np = netdev_priv(dev);
4116 struct i40e_vsi *vsi = np->vsi;
4117 struct i40e_pf *pf = vsi->back;
4118
4119 /* report maximum channels */
4120 ch->max_combined = i40e_max_channels(vsi);
4121
4122 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004123 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004124 ch->max_other = ch->other_count;
4125
4126 /* Note: This code assumes DCB is disabled for now. */
4127 ch->combined_count = vsi->num_queue_pairs;
4128}
4129
4130/**
4131 * i40e_set_channels - Set the new channels count.
4132 * @netdev: network interface device structure
4133 * @ch: ethtool channels structure
4134 *
4135 * The new channels count may not be the same as requested by the user
4136 * since it gets rounded down to a power of 2 value.
4137 **/
4138static int i40e_set_channels(struct net_device *dev,
4139 struct ethtool_channels *ch)
4140{
Jacob Keller59826d92016-07-27 12:02:35 -07004141 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004142 struct i40e_netdev_priv *np = netdev_priv(dev);
4143 unsigned int count = ch->combined_count;
4144 struct i40e_vsi *vsi = np->vsi;
4145 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004146 struct i40e_fdir_filter *rule;
4147 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004148 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004149 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004150
4151 /* We do not support setting channels for any other VSI at present */
4152 if (vsi->type != I40E_VSI_MAIN)
4153 return -EINVAL;
4154
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004155 /* We do not support setting channels via ethtool when TCs are
4156 * configured through mqprio
4157 */
4158 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4159 return -EINVAL;
4160
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004161 /* verify they are not requesting separate vectors */
4162 if (!count || ch->rx_count || ch->tx_count)
4163 return -EINVAL;
4164
4165 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004166 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004167 return -EINVAL;
4168
4169 /* verify the number of channels does not exceed hardware limits */
4170 if (count > i40e_max_channels(vsi))
4171 return -EINVAL;
4172
Jacob Keller59826d92016-07-27 12:02:35 -07004173 /* verify that the number of channels does not invalidate any current
4174 * flow director rules
4175 */
4176 hlist_for_each_entry_safe(rule, node2,
4177 &pf->fdir_filter_list, fdir_node) {
4178 if (rule->dest_ctl != drop && count <= rule->q_index) {
4179 dev_warn(&pf->pdev->dev,
4180 "Existing user defined filter %d assigns flow to queue %d\n",
4181 rule->fd_id, rule->q_index);
4182 err = -EINVAL;
4183 }
4184 }
4185
4186 if (err) {
4187 dev_err(&pf->pdev->dev,
4188 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4189 count);
4190 return err;
4191 }
4192
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004193 /* update feature limits from largest to smallest supported values */
4194 /* TODO: Flow director limit, DCB etc */
4195
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004196 /* use rss_reconfig to rebuild with new queue count and update traffic
4197 * class queue mapping
4198 */
4199 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004200 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004201 return 0;
4202 else
4203 return -EINVAL;
4204}
4205
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004206/**
4207 * i40e_get_rxfh_key_size - get the RSS hash key size
4208 * @netdev: network interface device structure
4209 *
4210 * Returns the table size.
4211 **/
4212static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4213{
4214 return I40E_HKEY_ARRAY_SIZE;
4215}
4216
4217/**
4218 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4219 * @netdev: network interface device structure
4220 *
4221 * Returns the table size.
4222 **/
4223static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4224{
4225 return I40E_HLUT_ARRAY_SIZE;
4226}
4227
Alan Brady21675bd2017-10-05 14:53:33 -07004228/**
4229 * i40e_get_rxfh - get the rx flow hash indirection table
4230 * @netdev: network interface device structure
4231 * @indir: indirection table
4232 * @key: hash key
4233 * @hfunc: hash function
4234 *
4235 * Reads the indirection table directly from the hardware. Returns 0 on
4236 * success.
4237 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004238static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4239 u8 *hfunc)
4240{
4241 struct i40e_netdev_priv *np = netdev_priv(netdev);
4242 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004243 u8 *lut, *seed = NULL;
4244 int ret;
4245 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004246
4247 if (hfunc)
4248 *hfunc = ETH_RSS_HASH_TOP;
4249
4250 if (!indir)
4251 return 0;
4252
Helin Zhang043dd652015-10-21 19:56:23 -04004253 seed = key;
4254 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4255 if (!lut)
4256 return -ENOMEM;
4257 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4258 if (ret)
4259 goto out;
4260 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4261 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004262
Helin Zhang043dd652015-10-21 19:56:23 -04004263out:
4264 kfree(lut);
4265
4266 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004267}
4268
4269/**
4270 * i40e_set_rxfh - set the rx flow hash indirection table
4271 * @netdev: network interface device structure
4272 * @indir: indirection table
4273 * @key: hash key
4274 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004275 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004276 * returns 0 after programming the table.
4277 **/
4278static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4279 const u8 *key, const u8 hfunc)
4280{
4281 struct i40e_netdev_priv *np = netdev_priv(netdev);
4282 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004283 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004284 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004285 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004286
4287 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4288 return -EOPNOTSUPP;
4289
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004290 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004291 if (!vsi->rss_hkey_user) {
4292 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4293 GFP_KERNEL);
4294 if (!vsi->rss_hkey_user)
4295 return -ENOMEM;
4296 }
4297 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4298 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004299 }
Helin Zhang28c58692015-10-26 19:44:27 -04004300 if (!vsi->rss_lut_user) {
4301 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4302 if (!vsi->rss_lut_user)
4303 return -ENOMEM;
4304 }
Helin Zhang043dd652015-10-21 19:56:23 -04004305
Helin Zhang28c58692015-10-26 19:44:27 -04004306 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004307 if (indir)
4308 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4309 vsi->rss_lut_user[i] = (u8)(indir[i]);
4310 else
4311 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4312 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004313
4314 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4315 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004316}
4317
Greg Rose7e45ab42015-02-06 08:52:19 +00004318/**
4319 * i40e_get_priv_flags - report device private flags
4320 * @dev: network interface device structure
4321 *
4322 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004323 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004324 * array.
4325 *
4326 * Returns a u32 bitmap of flags.
4327 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004328static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004329{
4330 struct i40e_netdev_priv *np = netdev_priv(dev);
4331 struct i40e_vsi *vsi = np->vsi;
4332 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004333 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004334
Alexander Duyckaca955d2017-03-10 12:22:01 -08004335 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4336 const struct i40e_priv_flags *priv_flags;
4337
4338 priv_flags = &i40e_gstrings_priv_flags[i];
4339
4340 if (priv_flags->flag & pf->flags)
4341 ret_flags |= BIT(i);
4342 }
4343
4344 if (pf->hw.pf_id != 0)
4345 return ret_flags;
4346
4347 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4348 const struct i40e_priv_flags *priv_flags;
4349
4350 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4351
4352 if (priv_flags->flag & pf->flags)
4353 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004354 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004355
4356 return ret_flags;
4357}
4358
Shannon Nelson9ac77262015-08-27 11:42:40 -04004359/**
4360 * i40e_set_priv_flags - set private flags
4361 * @dev: network interface device structure
4362 * @flags: bit flags to be set
4363 **/
4364static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4365{
4366 struct i40e_netdev_priv *np = netdev_priv(dev);
4367 struct i40e_vsi *vsi = np->vsi;
4368 struct i40e_pf *pf = vsi->back;
Alice Michael60f481b2017-12-27 08:17:50 -05004369 u64 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004370 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004371
Jacob Keller841c9502017-06-23 04:24:50 -04004372 orig_flags = READ_ONCE(pf->flags);
4373 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004374
Alexander Duyckaca955d2017-03-10 12:22:01 -08004375 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4376 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004377
Alexander Duyckaca955d2017-03-10 12:22:01 -08004378 priv_flags = &i40e_gstrings_priv_flags[i];
4379
Alexander Duyckaca955d2017-03-10 12:22:01 -08004380 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004381 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004382 else
Jacob Keller841c9502017-06-23 04:24:50 -04004383 new_flags &= ~(priv_flags->flag);
4384
4385 /* If this is a read-only flag, it can't be changed */
4386 if (priv_flags->read_only &&
4387 ((orig_flags ^ new_flags) & ~BIT(i)))
4388 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004389 }
4390
4391 if (pf->hw.pf_id != 0)
4392 goto flags_complete;
4393
4394 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4395 const struct i40e_priv_flags *priv_flags;
4396
4397 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4398
Alexander Duyckaca955d2017-03-10 12:22:01 -08004399 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004400 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004401 else
Jacob Keller841c9502017-06-23 04:24:50 -04004402 new_flags &= ~(priv_flags->flag);
4403
4404 /* If this is a read-only flag, it can't be changed */
4405 if (priv_flags->read_only &&
4406 ((orig_flags ^ new_flags) & ~BIT(i)))
4407 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004408 }
4409
4410flags_complete:
Alan Bradyfe09ed02017-12-29 08:50:34 -05004411 changed_flags = orig_flags ^ new_flags;
4412
Jacob Keller841c9502017-06-23 04:24:50 -04004413 /* Before we finalize any flag changes, we need to perform some
4414 * checks to ensure that the changes are supported and safe.
4415 */
4416
4417 /* ATR eviction is not supported on all devices */
4418 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4419 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4420 return -EOPNOTSUPP;
4421
Alan Bradyfe09ed02017-12-29 08:50:34 -05004422 /* If the driver detected FW LLDP was disabled on init, this flag could
4423 * be set, however we do not support _changing_ the flag if NPAR is
4424 * enabled or FW API version < 1.7. There are situations where older
4425 * FW versions/NPAR enabled PFs could disable LLDP, however we _must_
4426 * not allow the user to enable/disable LLDP with this flag on
4427 * unsupported FW versions.
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004428 */
Alan Bradyfe09ed02017-12-29 08:50:34 -05004429 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
Dave Ertman7b634352018-01-22 12:00:37 -05004430 if (!(pf->hw_features & I40E_HW_STOPPABLE_FW_LLDP)) {
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004431 dev_warn(&pf->pdev->dev,
Dave Ertman7b634352018-01-22 12:00:37 -05004432 "Device does not support changing FW LLDP\n");
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004433 return -EOPNOTSUPP;
4434 }
4435 }
4436
Jacob Keller841c9502017-06-23 04:24:50 -04004437 /* Compare and exchange the new flags into place. If we failed, that
Jacob Kellerb74f5712017-09-01 13:54:07 -07004438 * is if cmpxchg returns anything but the old value, this means that
Jacob Keller841c9502017-06-23 04:24:50 -04004439 * something else has modified the flags variable since we copied it
4440 * originally. We'll just punt with an error and log something in the
4441 * message buffer.
Alan Bradyfe09ed02017-12-29 08:50:34 -05004442 *
4443 * This is the point of no return for this function. We need to have
4444 * checked any discrepancies or misconfigurations and returned
4445 * EOPNOTSUPP before updating pf->flags here.
Jacob Keller841c9502017-06-23 04:24:50 -04004446 */
Alice Michael60f481b2017-12-27 08:17:50 -05004447 if (cmpxchg64(&pf->flags, orig_flags, new_flags) != orig_flags) {
Jacob Keller841c9502017-06-23 04:24:50 -04004448 dev_warn(&pf->pdev->dev,
4449 "Unable to update pf->flags as it was modified by another thread...\n");
4450 return -EAGAIN;
4451 }
4452
Alexander Duyckaca955d2017-03-10 12:22:01 -08004453 /* Process any additional changes needed as a result of flag changes.
4454 * The changed_flags value reflects the list of bits that were
4455 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004456 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004457
Alexander Duyckaca955d2017-03-10 12:22:01 -08004458 /* Flush current ATR settings if ATR was disabled */
4459 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4460 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004461 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004462 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004463 }
4464
Alexander Duyckaca955d2017-03-10 12:22:01 -08004465 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4466 u16 sw_flags = 0, valid_flags = 0;
4467 int ret;
4468
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004469 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4470 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4471 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4472 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07004473 0, NULL);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004474 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4475 dev_info(&pf->pdev->dev,
4476 "couldn't set switch config bits, err %s aq_err %s\n",
4477 i40e_stat_str(&pf->hw, ret),
4478 i40e_aq_str(&pf->hw,
4479 pf->hw.aq.asq_last_status));
4480 /* not a fatal problem, just keep going */
4481 }
4482 }
4483
Paweł Jabłoński17b4d252017-12-29 08:50:20 -05004484 if ((changed_flags & pf->flags &
4485 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4486 (pf->flags & I40E_FLAG_MFP_ENABLED))
4487 dev_warn(&pf->pdev->dev,
4488 "Turning on link-down-on-close flag may affect other partitions\n");
4489
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004490 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4491 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4492 struct i40e_dcbx_config *dcbcfg;
4493 int i;
4494
4495 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4496 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4497 /* reset local_dcbx_config to default */
4498 dcbcfg = &pf->hw.local_dcbx_config;
4499 dcbcfg->etscfg.willing = 1;
4500 dcbcfg->etscfg.maxtcs = 0;
4501 dcbcfg->etscfg.tcbwtable[0] = 100;
4502 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4503 dcbcfg->etscfg.tcbwtable[i] = 0;
4504 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4505 dcbcfg->etscfg.prioritytable[i] = 0;
4506 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4507 dcbcfg->pfc.willing = 1;
4508 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4509 } else {
4510 i40e_aq_start_lldp(&pf->hw, NULL);
4511 }
4512 }
4513
Alexander Duyckaca955d2017-03-10 12:22:01 -08004514 /* Issue reset to cause things to take effect, as additional bits
4515 * are added we will need to create a mask of bits requiring reset
4516 */
Mitch Williams64615b52017-08-29 05:32:30 -04004517 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4518 I40E_FLAG_LEGACY_RX |
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004519 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4520 I40E_FLAG_DISABLE_FW_LLDP))
Maciej Sosin373149f2017-04-05 07:50:55 -04004521 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004522
Shannon Nelson9ac77262015-08-27 11:42:40 -04004523 return 0;
4524}
4525
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004526/**
4527 * i40e_get_module_info - get (Q)SFP+ module type info
4528 * @netdev: network interface device structure
4529 * @modinfo: module EEPROM size and layout information structure
4530 **/
4531static int i40e_get_module_info(struct net_device *netdev,
4532 struct ethtool_modinfo *modinfo)
4533{
4534 struct i40e_netdev_priv *np = netdev_priv(netdev);
4535 struct i40e_vsi *vsi = np->vsi;
4536 struct i40e_pf *pf = vsi->back;
4537 struct i40e_hw *hw = &pf->hw;
4538 u32 sff8472_comp = 0;
4539 u32 sff8472_swap = 0;
4540 u32 sff8636_rev = 0;
4541 i40e_status status;
4542 u32 type = 0;
4543
4544 /* Check if firmware supports reading module EEPROM. */
4545 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4546 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4547 return -EINVAL;
4548 }
4549
4550 status = i40e_update_link_info(hw);
4551 if (status)
4552 return -EIO;
4553
4554 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4555 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4556 return -EINVAL;
4557 }
4558
4559 type = hw->phy.link_info.module_type[0];
4560
4561 switch (type) {
4562 case I40E_MODULE_TYPE_SFP:
4563 status = i40e_aq_get_phy_register(hw,
4564 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4565 I40E_I2C_EEPROM_DEV_ADDR,
4566 I40E_MODULE_SFF_8472_COMP,
4567 &sff8472_comp, NULL);
4568 if (status)
4569 return -EIO;
4570
4571 status = i40e_aq_get_phy_register(hw,
4572 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4573 I40E_I2C_EEPROM_DEV_ADDR,
4574 I40E_MODULE_SFF_8472_SWAP,
4575 &sff8472_swap, NULL);
4576 if (status)
4577 return -EIO;
4578
4579 /* Check if the module requires address swap to access
4580 * the other EEPROM memory page.
4581 */
4582 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4583 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4584 modinfo->type = ETH_MODULE_SFF_8079;
4585 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4586 } else if (sff8472_comp == 0x00) {
4587 /* Module is not SFF-8472 compliant */
4588 modinfo->type = ETH_MODULE_SFF_8079;
4589 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4590 } else {
4591 modinfo->type = ETH_MODULE_SFF_8472;
4592 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4593 }
4594 break;
4595 case I40E_MODULE_TYPE_QSFP_PLUS:
4596 /* Read from memory page 0. */
4597 status = i40e_aq_get_phy_register(hw,
4598 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4599 0,
4600 I40E_MODULE_REVISION_ADDR,
4601 &sff8636_rev, NULL);
4602 if (status)
4603 return -EIO;
4604 /* Determine revision compliance byte */
4605 if (sff8636_rev > 0x02) {
4606 /* Module is SFF-8636 compliant */
4607 modinfo->type = ETH_MODULE_SFF_8636;
4608 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4609 } else {
4610 modinfo->type = ETH_MODULE_SFF_8436;
4611 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4612 }
4613 break;
4614 case I40E_MODULE_TYPE_QSFP28:
4615 modinfo->type = ETH_MODULE_SFF_8636;
4616 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4617 break;
4618 default:
4619 netdev_err(vsi->netdev, "Module type unrecognized\n");
4620 return -EINVAL;
4621 }
4622 return 0;
4623}
4624
4625/**
4626 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4627 * @netdev: network interface device structure
4628 * @ee: EEPROM dump request structure
4629 * @data: buffer to be filled with EEPROM contents
4630 **/
4631static int i40e_get_module_eeprom(struct net_device *netdev,
4632 struct ethtool_eeprom *ee,
4633 u8 *data)
4634{
4635 struct i40e_netdev_priv *np = netdev_priv(netdev);
4636 struct i40e_vsi *vsi = np->vsi;
4637 struct i40e_pf *pf = vsi->back;
4638 struct i40e_hw *hw = &pf->hw;
4639 bool is_sfp = false;
4640 i40e_status status;
4641 u32 value = 0;
4642 int i;
4643
4644 if (!ee || !ee->len || !data)
4645 return -EINVAL;
4646
4647 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4648 is_sfp = true;
4649
4650 for (i = 0; i < ee->len; i++) {
4651 u32 offset = i + ee->offset;
4652 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4653
4654 /* Check if we need to access the other memory page */
4655 if (is_sfp) {
4656 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4657 offset -= ETH_MODULE_SFF_8079_LEN;
4658 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4659 }
4660 } else {
4661 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4662 /* Compute memory page number and offset. */
4663 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4664 addr++;
4665 }
4666 }
4667
4668 status = i40e_aq_get_phy_register(hw,
4669 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4670 addr, offset, &value, NULL);
4671 if (status)
4672 return -EIO;
4673 data[i] = value;
4674 }
4675 return 0;
4676}
4677
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004678static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004679 .get_drvinfo = i40e_get_drvinfo,
4680 .get_regs_len = i40e_get_regs_len,
4681 .get_regs = i40e_get_regs,
4682 .nway_reset = i40e_nway_reset,
4683 .get_link = ethtool_op_get_link,
4684 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004685 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004686 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004687 .get_eeprom_len = i40e_get_eeprom_len,
4688 .get_eeprom = i40e_get_eeprom,
4689 .get_ringparam = i40e_get_ringparam,
4690 .set_ringparam = i40e_set_ringparam,
4691 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004692 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004693 .get_msglevel = i40e_get_msglevel,
4694 .set_msglevel = i40e_set_msglevel,
4695 .get_rxnfc = i40e_get_rxnfc,
4696 .set_rxnfc = i40e_set_rxnfc,
4697 .self_test = i40e_diag_test,
4698 .get_strings = i40e_get_strings,
4699 .set_phys_id = i40e_set_phys_id,
4700 .get_sset_count = i40e_get_sset_count,
4701 .get_ethtool_stats = i40e_get_ethtool_stats,
4702 .get_coalesce = i40e_get_coalesce,
4703 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004704 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4705 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4706 .get_rxfh = i40e_get_rxfh,
4707 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004708 .get_channels = i40e_get_channels,
4709 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004710 .get_module_info = i40e_get_module_info,
4711 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004712 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004713 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004714 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004715 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004716 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004717 .get_link_ksettings = i40e_get_link_ksettings,
4718 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004719};
4720
4721void i40e_set_ethtool_ops(struct net_device *netdev)
4722{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004723 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004724}