blob: 9c70555bf49c3d6720fa1ecdcdb6a1932731c173 [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),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800148 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000149 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jacob Keller2955fac2017-05-03 10:28:58 -0700150 I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400153 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400156 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000157
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000158 /* LPI stats */
159 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
160 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
161 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
162 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000163};
164
165#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000166 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
167 * 2 /* Tx and Rx together */ \
168 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000169#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
170#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000171#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000173 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000174 I40E_QUEUE_STATS_LEN((n)))
175#define I40E_PFC_STATS_LEN ( \
176 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
177 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
178 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
179 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
180 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
181 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400182#define I40E_VEB_TC_STATS_LEN ( \
183 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
184 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
185 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
186 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
187 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000188#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400189#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
191 I40E_PFC_STATS_LEN + \
192 I40E_VSI_STATS_LEN((n)))
193
194enum i40e_ethtool_test_id {
195 I40E_ETH_TEST_REG = 0,
196 I40E_ETH_TEST_EEPROM,
197 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198 I40E_ETH_TEST_LINK,
199};
200
201static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
202 "Register test (offline)",
203 "Eeprom test (offline)",
204 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000205 "Link test (on/offline)"
206};
207
208#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
209
Alexander Duyckaca955d2017-03-10 12:22:01 -0800210struct i40e_priv_flags {
211 char flag_string[ETH_GSTRING_LEN];
212 u64 flag;
213 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000214};
215
Alexander Duyckaca955d2017-03-10 12:22:01 -0800216#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
217 .flag_string = _name, \
218 .flag = _flag, \
219 .read_only = _read_only, \
220}
221
222static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
223 /* NOTE: MFP setting cannot be changed */
224 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
225 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
226 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
227 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700228 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700229 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400230 I40E_PRIV_FLAG("disable-source-pruning",
231 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800232};
233
234#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000235
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700236/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800237static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
238 I40E_PRIV_FLAG("vf-true-promisc-support",
239 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700240};
241
Alexander Duyckaca955d2017-03-10 12:22:01 -0800242#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700243
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000244/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000245 * i40e_partition_setting_complaint - generic complaint for MFP restriction
246 * @pf: the PF struct
247 **/
248static void i40e_partition_setting_complaint(struct i40e_pf *pf)
249{
250 dev_info(&pf->pdev->dev,
251 "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");
252}
253
254/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700255 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
Alan Brady52e2d022017-10-05 14:53:35 -0700256 * @pf: PF struct with phy_types
Alan Brady1eaae512017-10-05 14:53:41 -0700257 * @ks: ethtool link ksettings struct to fill out
Catherine Sullivan06566e52016-05-03 15:13:14 -0700258 *
259 **/
Alan Brady1eaae512017-10-05 14:53:41 -0700260static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
261 struct ethtool_link_ksettings *ks)
Catherine Sullivan06566e52016-05-03 15:13:14 -0700262{
Avinash Dayanand28537042016-06-20 09:10:33 -0700263 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800264 u64 phy_types = pf->hw.phy.phy_types;
265
Alan Brady1eaae512017-10-05 14:53:41 -0700266 ethtool_link_ksettings_zero_link_mode(ks, supported);
267 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700268
269 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
Alan Brady1eaae512017-10-05 14:53:41 -0700270 ethtool_link_ksettings_add_link_mode(ks, supported,
271 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700272 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700273 ethtool_link_ksettings_add_link_mode(ks, advertising,
274 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400275 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady1eaae512017-10-05 14:53:41 -0700276 ethtool_link_ksettings_add_link_mode(ks, supported,
277 100baseT_Full);
278 ethtool_link_ksettings_add_link_mode(ks, advertising,
279 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700280 }
281 }
282 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
283 phy_types & I40E_CAP_PHY_TYPE_XFI ||
284 phy_types & I40E_CAP_PHY_TYPE_SFI ||
285 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
Alan Brady1eaae512017-10-05 14:53:41 -0700286 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
287 ethtool_link_ksettings_add_link_mode(ks, supported,
288 10000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700289 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700290 ethtool_link_ksettings_add_link_mode(ks, advertising,
291 10000baseT_Full);
292 }
293 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
294 ethtool_link_ksettings_add_link_mode(ks, supported,
295 10000baseT_Full);
296 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
297 ethtool_link_ksettings_add_link_mode(ks, advertising,
298 10000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700299 }
300 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
301 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
302 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
Alan Brady1eaae512017-10-05 14:53:41 -0700303 ethtool_link_ksettings_add_link_mode(ks, supported,
304 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700305 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
306 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700307 ethtool_link_ksettings_add_link_mode(ks, supported,
308 40000baseCR4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700309 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700310 ethtool_link_ksettings_add_link_mode(ks, advertising,
311 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700312 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700313 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700314 ethtool_link_ksettings_add_link_mode(ks, supported,
315 100baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700316 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady1eaae512017-10-05 14:53:41 -0700317 ethtool_link_ksettings_add_link_mode(ks, advertising,
318 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700319 }
Alan Brady1eaae512017-10-05 14:53:41 -0700320 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
321 ethtool_link_ksettings_add_link_mode(ks, supported,
322 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700324 ethtool_link_ksettings_add_link_mode(ks, advertising,
325 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700326 }
327 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700328 ethtool_link_ksettings_add_link_mode(ks, supported,
329 40000baseSR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700330 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700331 ethtool_link_ksettings_add_link_mode(ks, supported,
332 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700333 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700334 ethtool_link_ksettings_add_link_mode(ks, supported,
335 40000baseLR4_Full);
336 ethtool_link_ksettings_add_link_mode(ks, advertising,
337 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700338 }
339 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
Alan Brady1eaae512017-10-05 14:53:41 -0700340 ethtool_link_ksettings_add_link_mode(ks, supported,
341 20000baseKR2_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700342 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700343 ethtool_link_ksettings_add_link_mode(ks, advertising,
344 20000baseKR2_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700345 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700346 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700347 ethtool_link_ksettings_add_link_mode(ks, supported,
348 10000baseKX4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700349 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700350 ethtool_link_ksettings_add_link_mode(ks, advertising,
351 10000baseKX4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700352 }
Alan Brady6987bd252017-10-05 14:53:38 -0700353 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
354 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700355 ethtool_link_ksettings_add_link_mode(ks, supported,
356 10000baseKR_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700357 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700358 ethtool_link_ksettings_add_link_mode(ks, advertising,
359 10000baseKR_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700360 }
Alan Brady6987bd252017-10-05 14:53:38 -0700361 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
362 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700363 ethtool_link_ksettings_add_link_mode(ks, supported,
364 1000baseKX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700365 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700366 ethtool_link_ksettings_add_link_mode(ks, advertising,
367 1000baseKX_Full);
368 }
369 /* need to add 25G PHY types */
370 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
371 ethtool_link_ksettings_add_link_mode(ks, supported,
372 25000baseKR_Full);
373 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
374 ethtool_link_ksettings_add_link_mode(ks, advertising,
375 25000baseKR_Full);
376 }
377 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
378 ethtool_link_ksettings_add_link_mode(ks, supported,
379 25000baseCR_Full);
380 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
381 ethtool_link_ksettings_add_link_mode(ks, advertising,
382 25000baseCR_Full);
383 }
384 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
385 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
386 ethtool_link_ksettings_add_link_mode(ks, supported,
387 25000baseSR_Full);
388 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
389 ethtool_link_ksettings_add_link_mode(ks, advertising,
390 25000baseSR_Full);
391 }
392 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
393 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
394 ethtool_link_ksettings_add_link_mode(ks, supported,
395 25000baseCR_Full);
396 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
397 ethtool_link_ksettings_add_link_mode(ks, advertising,
398 25000baseCR_Full);
399 }
400 /* need to add new 10G PHY types */
401 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
402 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
403 ethtool_link_ksettings_add_link_mode(ks, supported,
404 10000baseCR_Full);
405 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
406 ethtool_link_ksettings_add_link_mode(ks, advertising,
407 10000baseCR_Full);
408 }
409 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
410 ethtool_link_ksettings_add_link_mode(ks, supported,
411 10000baseSR_Full);
412 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
413 ethtool_link_ksettings_add_link_mode(ks, advertising,
414 10000baseSR_Full);
415 }
416 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
417 ethtool_link_ksettings_add_link_mode(ks, supported,
418 10000baseLR_Full);
419 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
420 ethtool_link_ksettings_add_link_mode(ks, advertising,
421 10000baseLR_Full);
422 }
423 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
424 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
425 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
426 ethtool_link_ksettings_add_link_mode(ks, supported,
427 1000baseX_Full);
428 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
429 ethtool_link_ksettings_add_link_mode(ks, advertising,
430 1000baseX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700431 }
432 /* Autoneg PHY types */
433 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
434 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
435 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
436 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800437 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700438 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
439 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
440 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
441 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
442 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
443 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
444 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
445 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
446 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
447 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
448 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
449 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
450 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
451 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
452 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
453 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
454 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700455 ethtool_link_ksettings_add_link_mode(ks, supported,
456 Autoneg);
457 ethtool_link_ksettings_add_link_mode(ks, advertising,
458 Autoneg);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800459 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700460}
461
462/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000463 * i40e_get_settings_link_up - Get the Link settings for when link is up
464 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700465 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000466 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700467 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000468 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000469static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700470 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400471 struct net_device *netdev,
472 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000473{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000474 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Alan Brady1eaae512017-10-05 14:53:41 -0700475 struct ethtool_link_ksettings cap_ksettings;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000476 u32 link_speed = hw_link_info->link_speed;
477
Catherine Sullivane8278452015-02-06 08:52:08 +0000478 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000479 switch (hw_link_info->phy_type) {
480 case I40E_PHY_TYPE_40GBASE_CR4:
481 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Alan Brady79f04a32017-10-05 14:53:42 -0700482 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
483 ethtool_link_ksettings_add_link_mode(ks, supported,
484 40000baseCR4_Full);
485 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
486 ethtool_link_ksettings_add_link_mode(ks, advertising,
487 40000baseCR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000488 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000489 case I40E_PHY_TYPE_XLAUI:
490 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000491 case I40E_PHY_TYPE_40GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700492 ethtool_link_ksettings_add_link_mode(ks, supported,
493 40000baseCR4_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000494 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000495 case I40E_PHY_TYPE_40GBASE_SR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700496 ethtool_link_ksettings_add_link_mode(ks, supported,
497 40000baseSR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 break;
499 case I40E_PHY_TYPE_40GBASE_LR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700500 ethtool_link_ksettings_add_link_mode(ks, supported,
501 40000baseLR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000502 break;
Alan Brady79f04a32017-10-05 14:53:42 -0700503 case I40E_PHY_TYPE_25GBASE_SR:
504 case I40E_PHY_TYPE_25GBASE_LR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000505 case I40E_PHY_TYPE_10GBASE_SR:
506 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000507 case I40E_PHY_TYPE_1000BASE_SX:
508 case I40E_PHY_TYPE_1000BASE_LX:
Alan Brady79f04a32017-10-05 14:53:42 -0700509 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
510 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
511 ethtool_link_ksettings_add_link_mode(ks, supported,
512 25000baseSR_Full);
513 ethtool_link_ksettings_add_link_mode(ks, advertising,
514 25000baseSR_Full);
515 ethtool_link_ksettings_add_link_mode(ks, supported,
516 10000baseSR_Full);
517 ethtool_link_ksettings_add_link_mode(ks, advertising,
518 10000baseSR_Full);
519 ethtool_link_ksettings_add_link_mode(ks, supported,
520 10000baseLR_Full);
521 ethtool_link_ksettings_add_link_mode(ks, advertising,
522 10000baseLR_Full);
523 ethtool_link_ksettings_add_link_mode(ks, supported,
524 1000baseX_Full);
525 ethtool_link_ksettings_add_link_mode(ks, advertising,
526 1000baseX_Full);
527 ethtool_link_ksettings_add_link_mode(ks, supported,
528 10000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400529 if (hw_link_info->module_type[2] &
530 I40E_MODULE_TYPE_1000BASE_SX ||
531 hw_link_info->module_type[2] &
532 I40E_MODULE_TYPE_1000BASE_LX) {
Alan Brady79f04a32017-10-05 14:53:42 -0700533 ethtool_link_ksettings_add_link_mode(ks, supported,
534 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400535 if (hw_link_info->requested_speeds &
536 I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700537 ethtool_link_ksettings_add_link_mode(
538 ks, advertising, 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400539 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000540 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700541 ethtool_link_ksettings_add_link_mode(ks, advertising,
542 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000543 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000544 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000545 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700546 case I40E_PHY_TYPE_100BASE_TX:
Alan Brady79f04a32017-10-05 14:53:42 -0700547 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
548 ethtool_link_ksettings_add_link_mode(ks, supported,
549 10000baseT_Full);
550 ethtool_link_ksettings_add_link_mode(ks, supported,
551 1000baseT_Full);
552 ethtool_link_ksettings_add_link_mode(ks, supported,
553 100baseT_Full);
554 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivane8278452015-02-06 08:52:08 +0000555 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700556 ethtool_link_ksettings_add_link_mode(ks, advertising,
557 10000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000558 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700559 ethtool_link_ksettings_add_link_mode(ks, advertising,
560 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700561 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700562 ethtool_link_ksettings_add_link_mode(ks, advertising,
563 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400564 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400565 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Alan Brady79f04a32017-10-05 14:53:42 -0700566 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
567 ethtool_link_ksettings_add_link_mode(ks, supported,
568 1000baseT_Full);
569 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
570 ethtool_link_ksettings_add_link_mode(ks, advertising,
571 1000baseT_Full);
Catherine Sullivan48becae2015-09-28 14:12:41 -0400572 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000573 case I40E_PHY_TYPE_10GBASE_CR1_CU:
574 case I40E_PHY_TYPE_10GBASE_CR1:
Alan Brady79f04a32017-10-05 14:53:42 -0700575 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
576 ethtool_link_ksettings_add_link_mode(ks, supported,
577 10000baseT_Full);
578 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
579 ethtool_link_ksettings_add_link_mode(ks, advertising,
580 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000581 break;
582 case I40E_PHY_TYPE_XAUI:
583 case I40E_PHY_TYPE_XFI:
584 case I40E_PHY_TYPE_SFI:
585 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000586 case I40E_PHY_TYPE_10GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700587 ethtool_link_ksettings_add_link_mode(ks, supported,
588 10000baseT_Full);
589 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
590 ethtool_link_ksettings_add_link_mode(ks, advertising,
591 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000592 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000593 case I40E_PHY_TYPE_SGMII:
Alan Brady79f04a32017-10-05 14:53:42 -0700594 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
595 ethtool_link_ksettings_add_link_mode(ks, supported,
596 1000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000597 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700598 ethtool_link_ksettings_add_link_mode(ks, advertising,
599 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400600 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady79f04a32017-10-05 14:53:42 -0700601 ethtool_link_ksettings_add_link_mode(ks, supported,
602 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400603 if (hw_link_info->requested_speeds &
604 I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700605 ethtool_link_ksettings_add_link_mode(
606 ks, advertising, 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400607 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000608 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400609 case I40E_PHY_TYPE_40GBASE_KR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700610 case I40E_PHY_TYPE_25GBASE_KR:
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400611 case I40E_PHY_TYPE_20GBASE_KR2:
612 case I40E_PHY_TYPE_10GBASE_KR:
613 case I40E_PHY_TYPE_10GBASE_KX4:
614 case I40E_PHY_TYPE_1000BASE_KX:
Alan Brady79f04a32017-10-05 14:53:42 -0700615 ethtool_link_ksettings_add_link_mode(ks, supported,
616 40000baseKR4_Full);
617 ethtool_link_ksettings_add_link_mode(ks, supported,
618 25000baseKR_Full);
619 ethtool_link_ksettings_add_link_mode(ks, supported,
620 20000baseKR2_Full);
621 ethtool_link_ksettings_add_link_mode(ks, supported,
622 10000baseKR_Full);
623 ethtool_link_ksettings_add_link_mode(ks, supported,
624 10000baseKX4_Full);
625 ethtool_link_ksettings_add_link_mode(ks, supported,
626 1000baseKX_Full);
627 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
628 ethtool_link_ksettings_add_link_mode(ks, advertising,
629 40000baseKR4_Full);
630 ethtool_link_ksettings_add_link_mode(ks, advertising,
631 25000baseKR_Full);
632 ethtool_link_ksettings_add_link_mode(ks, advertising,
633 20000baseKR2_Full);
634 ethtool_link_ksettings_add_link_mode(ks, advertising,
635 10000baseKR_Full);
636 ethtool_link_ksettings_add_link_mode(ks, advertising,
637 10000baseKX4_Full);
638 ethtool_link_ksettings_add_link_mode(ks, advertising,
639 1000baseKX_Full);
640 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400641 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800642 case I40E_PHY_TYPE_25GBASE_CR:
Alan Brady79f04a32017-10-05 14:53:42 -0700643 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
644 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
645 ethtool_link_ksettings_add_link_mode(ks, supported,
646 25000baseCR_Full);
647 ethtool_link_ksettings_add_link_mode(ks, advertising,
648 25000baseCR_Full);
649 break;
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700650 case I40E_PHY_TYPE_25GBASE_AOC:
651 case I40E_PHY_TYPE_25GBASE_ACC:
Alan Brady79f04a32017-10-05 14:53:42 -0700652 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
653 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
654 ethtool_link_ksettings_add_link_mode(ks, supported,
655 25000baseCR_Full);
656
657 ethtool_link_ksettings_add_link_mode(ks, advertising,
658 25000baseCR_Full);
659 ethtool_link_ksettings_add_link_mode(ks, supported,
660 10000baseCR_Full);
661 ethtool_link_ksettings_add_link_mode(ks, advertising,
662 10000baseCR_Full);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800663 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000664 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000665 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700666 netdev_info(netdev,
667 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000668 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000669 }
670
Catherine Sullivan06566e52016-05-03 15:13:14 -0700671 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700672 * current PHY type, get what is supported by the NVM and intersect
673 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700674 */
Alan Brady1eaae512017-10-05 14:53:41 -0700675 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
676 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
677 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700678
Catherine Sullivane8278452015-02-06 08:52:08 +0000679 /* Set speed and duplex */
680 switch (link_speed) {
681 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700682 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000683 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800684 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700685 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800686 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700687 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700688 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700689 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000690 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700691 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000692 break;
693 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700694 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000695 break;
696 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700697 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000698 break;
699 default:
700 break;
701 }
Alan Brady1c142e12017-10-05 14:53:31 -0700702 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000703}
704
705/**
706 * i40e_get_settings_link_down - Get the Link settings for when link is down
707 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700708 * @ks: ethtool ksettings to fill in
709 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000710 *
711 * Reports link settings that can be determined when link is down
712 **/
713static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700714 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400715 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000716{
Catherine Sullivane8278452015-02-06 08:52:08 +0000717 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400718 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000719 */
Alan Brady1eaae512017-10-05 14:53:41 -0700720 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000721
722 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700723 ks->base.speed = SPEED_UNKNOWN;
724 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000725}
726
727/**
Alan Brady1c142e12017-10-05 14:53:31 -0700728 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000729 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700730 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000731 *
732 * Reports speed/duplex settings based on media_type
733 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100734static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700735 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000736{
737 struct i40e_netdev_priv *np = netdev_priv(netdev);
738 struct i40e_pf *pf = np->vsi->back;
739 struct i40e_hw *hw = &pf->hw;
740 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
741 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700742
743 ethtool_link_ksettings_zero_link_mode(ks, supported);
744 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000745
746 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700747 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000748 else
Alan Brady1c142e12017-10-05 14:53:31 -0700749 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000750
751 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000752 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700753 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
754 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000755
Alan Bradya03af692017-10-05 14:53:37 -0700756 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000757 switch (hw->phy.media_type) {
758 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700759 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
760 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
761 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700762 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100763 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700764 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000765 break;
766 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700767 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
768 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
769 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000770 break;
771 case I40E_MEDIA_TYPE_DA:
772 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700773 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
774 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
775 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000776 break;
777 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700778 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
779 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000780 break;
781 case I40E_MEDIA_TYPE_UNKNOWN:
782 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700783 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000784 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000785 }
786
Catherine Sullivane8278452015-02-06 08:52:08 +0000787 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700788 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000789
Catherine Sullivane8278452015-02-06 08:52:08 +0000790 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000791 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700792 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000793 break;
794 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700795 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100796 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000797 break;
798 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700799 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700800 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100801 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000802 break;
803 default:
Alan Brady5f434992017-10-05 14:53:34 -0700804 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
805 ethtool_link_ksettings_del_link_mode(ks, advertising,
806 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000807 break;
808 }
809
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000810 return 0;
811}
812
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000813/**
Alan Brady1c142e12017-10-05 14:53:31 -0700814 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000815 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700816 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000817 *
818 * Set speed/duplex per media_types advertised/forced
819 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100820static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700821 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000822{
823 struct i40e_netdev_priv *np = netdev_priv(netdev);
824 struct i40e_aq_get_phy_abilities_resp abilities;
Alan Brady636b62d2017-10-05 14:53:43 -0700825 struct ethtool_link_ksettings safe_ks;
826 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000827 struct i40e_aq_set_phy_config config;
828 struct i40e_pf *pf = np->vsi->back;
829 struct i40e_vsi *vsi = np->vsi;
830 struct i40e_hw *hw = &pf->hw;
Alan Brady636b62d2017-10-05 14:53:43 -0700831 bool autoneg_changed = false;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000832 i40e_status status = 0;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400833 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000834 int err = 0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100835 u32 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000836 u32 advertise;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100837 u32 tmp;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000838
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000839 /* Changing port settings is not supported if this isn't the
840 * port's controlling PF
841 */
842 if (hw->partition_id != 1) {
843 i40e_partition_setting_complaint(pf);
844 return -EOPNOTSUPP;
845 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000846 if (vsi != pf->vsi[pf->lan_vsi])
847 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000848 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
849 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000850 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700851 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000852 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000853 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400854 if (hw->device_id == I40E_DEV_ID_KX_B ||
855 hw->device_id == I40E_DEV_ID_KX_C ||
856 hw->device_id == I40E_DEV_ID_20G_KR2 ||
857 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
858 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
859 return -EOPNOTSUPP;
860 }
861
Alan Brady1c142e12017-10-05 14:53:31 -0700862 /* copy the ksettings to copy_ks to avoid modifying the origin */
863 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000864
Philippe Reynesa7f90942017-02-04 22:05:06 +0100865 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700866 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
867 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100868
Alan Brady1c142e12017-10-05 14:53:31 -0700869 /* save autoneg and speed out of ksettings */
870 autoneg = ks->base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100871 ethtool_convert_link_mode_to_legacy_u32(&advertise,
Alan Brady1c142e12017-10-05 14:53:31 -0700872 ks->link_modes.advertising);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000873
874 /* set autoneg and speed back to what they currently are */
Alan Brady1c142e12017-10-05 14:53:31 -0700875 copy_ks.base.autoneg = safe_ks.base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100876 ethtool_convert_link_mode_to_legacy_u32(
Alan Brady1c142e12017-10-05 14:53:31 -0700877 &tmp, safe_ks.link_modes.advertising);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100878 ethtool_convert_legacy_u32_to_link_mode(
Alan Brady1c142e12017-10-05 14:53:31 -0700879 copy_ks.link_modes.advertising, tmp);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000880
Alan Brady1c142e12017-10-05 14:53:31 -0700881 copy_ks.base.cmd = safe_ks.base.cmd;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100882
Alan Brady1c142e12017-10-05 14:53:31 -0700883 /* If copy_ks and safe_ks are not the same now, then they are
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000884 * trying to set something that we do not support
885 */
Alan Brady1c142e12017-10-05 14:53:31 -0700886 if (memcmp(&copy_ks, &safe_ks, sizeof(struct ethtool_link_ksettings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000887 return -EOPNOTSUPP;
888
Jacob Keller0da36b92017-04-19 09:25:55 -0400889 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400890 timeout--;
891 if (!timeout)
892 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000893 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400894 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000895
896 /* Get the current phy config */
897 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
898 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400899 if (status) {
900 err = -EAGAIN;
901 goto done;
902 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000903
Catherine Sullivan124ed152014-07-12 07:28:12 +0000904 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000905 * set below
906 */
907 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000908 config.abilities = abilities.abilities;
909
910 /* Check autoneg */
911 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000912 /* If autoneg was not already enabled */
913 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400914 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700915 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
916 supported,
917 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400918 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400919 err = -EINVAL;
920 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400921 }
922 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000923 config.abilities = abilities.abilities |
924 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700925 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000926 }
927 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000928 /* If autoneg is currently enabled */
929 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400930 /* If autoneg is supported 10GBASE_T is the only PHY
931 * that can disable it, so otherwise return error
932 */
Alan Brady1c142e12017-10-05 14:53:31 -0700933 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
934 supported,
935 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400936 hw->phy.link_info.phy_type !=
937 I40E_PHY_TYPE_10GBASE_T) {
938 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400939 err = -EINVAL;
940 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400941 }
942 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000943 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000944 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700945 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000946 }
947 }
948
Philippe Reynesa7f90942017-02-04 22:05:06 +0100949 ethtool_convert_link_mode_to_legacy_u32(&tmp,
Alan Brady1c142e12017-10-05 14:53:31 -0700950 safe_ks.link_modes.supported);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400951 if (advertise & ~tmp) {
952 err = -EINVAL;
953 goto done;
954 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000955
956 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000957 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000958 if (advertise & ADVERTISED_1000baseT_Full ||
959 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000960 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000961 if (advertise & ADVERTISED_10000baseT_Full ||
962 advertise & ADVERTISED_10000baseKX4_Full ||
963 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000964 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700965 if (advertise & ADVERTISED_20000baseKR2_Full)
966 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000967 if (advertise & ADVERTISED_40000baseKR4_Full ||
968 advertise & ADVERTISED_40000baseCR4_Full ||
969 advertise & ADVERTISED_40000baseSR4_Full ||
970 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000971 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000972
Catherine Sullivan0002e112015-08-26 15:14:16 -0400973 /* If speed didn't get set, set it to what it currently is.
974 * This is needed because if advertise is 0 (as it is when autoneg
975 * is disabled) then speed won't get set.
976 */
977 if (!config.link_speed)
978 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -0700979 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000980 /* copy over the rest of the abilities */
981 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800982 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000983 config.eee_capability = abilities.eee_capability;
984 config.eeer = abilities.eeer_val;
985 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800986 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
987 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000988
Catherine Sullivane8278452015-02-06 08:52:08 +0000989 /* save the requested speeds */
990 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000991 /* set link and auto negotiation so changes take effect */
992 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
993 /* If link is up put link down */
994 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
995 /* Tell the OS link is going down, the link will go
996 * back up when fw says it is ready asynchronously
997 */
Matt Jaredc156f852015-08-27 11:42:39 -0400998 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000999 netif_carrier_off(netdev);
1000 netif_tx_stop_all_queues(netdev);
1001 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001002
1003 /* make the aq call */
1004 status = i40e_aq_set_phy_config(hw, &config, NULL);
1005 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001006 netdev_info(netdev,
1007 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001008 i40e_stat_str(hw, status),
1009 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001010 err = -EAGAIN;
1011 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001012 }
1013
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001014 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001015 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001016 netdev_dbg(netdev,
1017 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001018 i40e_stat_str(hw, status),
1019 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001020
1021 } else {
1022 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1023 }
1024
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001025done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001026 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001027
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001028 return err;
1029}
1030
Jesse Brandeburga6599722014-06-04 08:45:25 +00001031static int i40e_nway_reset(struct net_device *netdev)
1032{
1033 /* restart autonegotiation */
1034 struct i40e_netdev_priv *np = netdev_priv(netdev);
1035 struct i40e_pf *pf = np->vsi->back;
1036 struct i40e_hw *hw = &pf->hw;
1037 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1038 i40e_status ret = 0;
1039
1040 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1041 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001042 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1043 i40e_stat_str(hw, ret),
1044 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001045 return -EIO;
1046 }
1047
1048 return 0;
1049}
1050
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001051/**
1052 * i40e_get_pauseparam - Get Flow Control status
1053 * Return tx/rx-pause status
1054 **/
1055static void i40e_get_pauseparam(struct net_device *netdev,
1056 struct ethtool_pauseparam *pause)
1057{
1058 struct i40e_netdev_priv *np = netdev_priv(netdev);
1059 struct i40e_pf *pf = np->vsi->back;
1060 struct i40e_hw *hw = &pf->hw;
1061 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001062 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063
1064 pause->autoneg =
1065 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1066 AUTONEG_ENABLE : AUTONEG_DISABLE);
1067
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001068 /* PFC enabled so report LFC as off */
1069 if (dcbx_cfg->pfc.pfcenable) {
1070 pause->rx_pause = 0;
1071 pause->tx_pause = 0;
1072 return;
1073 }
1074
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001075 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001076 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001077 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001078 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001079 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1080 pause->rx_pause = 1;
1081 pause->tx_pause = 1;
1082 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001083}
1084
Catherine Sullivan2becc352014-06-04 08:45:27 +00001085/**
1086 * i40e_set_pauseparam - Set Flow Control parameter
1087 * @netdev: network interface device structure
1088 * @pause: return tx/rx flow control status
1089 **/
1090static int i40e_set_pauseparam(struct net_device *netdev,
1091 struct ethtool_pauseparam *pause)
1092{
1093 struct i40e_netdev_priv *np = netdev_priv(netdev);
1094 struct i40e_pf *pf = np->vsi->back;
1095 struct i40e_vsi *vsi = np->vsi;
1096 struct i40e_hw *hw = &pf->hw;
1097 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001098 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001099 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1100 i40e_status status;
1101 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001102 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001103
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001104 /* Changing the port's flow control is not supported if this isn't the
1105 * port's controlling PF
1106 */
1107 if (hw->partition_id != 1) {
1108 i40e_partition_setting_complaint(pf);
1109 return -EOPNOTSUPP;
1110 }
1111
Catherine Sullivan2becc352014-06-04 08:45:27 +00001112 if (vsi != pf->vsi[pf->lan_vsi])
1113 return -EOPNOTSUPP;
1114
1115 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1116 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1117 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1118 return -EOPNOTSUPP;
1119 }
1120
1121 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001122 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001123 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1124 /* Send message that it might not necessarily work*/
1125 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1126 }
1127
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001128 if (dcbx_cfg->pfc.pfcenable) {
1129 netdev_info(netdev,
1130 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001131 return -EOPNOTSUPP;
1132 }
1133
1134 if (pause->rx_pause && pause->tx_pause)
1135 hw->fc.requested_mode = I40E_FC_FULL;
1136 else if (pause->rx_pause && !pause->tx_pause)
1137 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1138 else if (!pause->rx_pause && pause->tx_pause)
1139 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1140 else if (!pause->rx_pause && !pause->tx_pause)
1141 hw->fc.requested_mode = I40E_FC_NONE;
1142 else
1143 return -EINVAL;
1144
Catherine Sullivan94128512014-07-12 07:28:16 +00001145 /* Tell the OS link is going down, the link will go back up when fw
1146 * says it is ready asynchronously
1147 */
Matt Jaredc156f852015-08-27 11:42:39 -04001148 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001149 netif_carrier_off(netdev);
1150 netif_tx_stop_all_queues(netdev);
1151
Catherine Sullivan2becc352014-06-04 08:45:27 +00001152 /* Set the fc mode and only restart an if link is up*/
1153 status = i40e_set_fc(hw, &aq_failures, link_up);
1154
1155 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001156 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1157 i40e_stat_str(hw, status),
1158 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001159 err = -EAGAIN;
1160 }
1161 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001162 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1163 i40e_stat_str(hw, status),
1164 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001165 err = -EAGAIN;
1166 }
1167 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001168 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1169 i40e_stat_str(hw, status),
1170 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001171 err = -EAGAIN;
1172 }
1173
Jacob Keller0da36b92017-04-19 09:25:55 -04001174 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001175 /* Give it a little more time to try to come back */
1176 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001177 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001178 return i40e_nway_reset(netdev);
1179 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001180
1181 return err;
1182}
1183
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001184static u32 i40e_get_msglevel(struct net_device *netdev)
1185{
1186 struct i40e_netdev_priv *np = netdev_priv(netdev);
1187 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001188 u32 debug_mask = pf->hw.debug_mask;
1189
1190 if (debug_mask)
1191 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001192
1193 return pf->msg_enable;
1194}
1195
1196static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1197{
1198 struct i40e_netdev_priv *np = netdev_priv(netdev);
1199 struct i40e_pf *pf = np->vsi->back;
1200
1201 if (I40E_DEBUG_USER & data)
1202 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001203 else
1204 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001205}
1206
1207static int i40e_get_regs_len(struct net_device *netdev)
1208{
1209 int reg_count = 0;
1210 int i;
1211
1212 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1213 reg_count += i40e_reg_list[i].elements;
1214
1215 return reg_count * sizeof(u32);
1216}
1217
1218static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1219 void *p)
1220{
1221 struct i40e_netdev_priv *np = netdev_priv(netdev);
1222 struct i40e_pf *pf = np->vsi->back;
1223 struct i40e_hw *hw = &pf->hw;
1224 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001225 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001226 u32 reg;
1227
1228 /* Tell ethtool which driver-version-specific regs output we have.
1229 *
1230 * At some point, if we have ethtool doing special formatting of
1231 * this data, it will rely on this version number to know how to
1232 * interpret things. Hence, this needs to be updated if/when the
1233 * diags register table is changed.
1234 */
1235 regs->version = 1;
1236
1237 /* loop through the diags reg table for what to print */
1238 ri = 0;
1239 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1240 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1241 reg = i40e_reg_list[i].offset
1242 + (j * i40e_reg_list[i].stride);
1243 reg_buf[ri++] = rd32(hw, reg);
1244 }
1245 }
1246
1247}
1248
1249static int i40e_get_eeprom(struct net_device *netdev,
1250 struct ethtool_eeprom *eeprom, u8 *bytes)
1251{
1252 struct i40e_netdev_priv *np = netdev_priv(netdev);
1253 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001254 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001255 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001256 u8 *eeprom_buff;
1257 u16 i, sectors;
1258 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001259 u32 magic;
1260
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001261#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001262 if (eeprom->len == 0)
1263 return -EINVAL;
1264
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001265 /* check for NVMUpdate access method */
1266 magic = hw->vendor_id | (hw->device_id << 16);
1267 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001268 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1269 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001270
1271 /* make sure it is the right magic for NVMUpdate */
1272 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001273 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001274 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1275 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001276 errno = -EBUSY;
1277 else
1278 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001279
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001280 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001281 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001282 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1283 ret_val, hw->aq.asq_last_status, errno,
1284 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1285 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001286
1287 return errno;
1288 }
1289
1290 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001291 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1292
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001293 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001294 if (!eeprom_buff)
1295 return -ENOMEM;
1296
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001297 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1298 if (ret_val) {
1299 dev_info(&pf->pdev->dev,
1300 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1301 ret_val, hw->aq.asq_last_status);
1302 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001303 }
1304
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001305 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1306 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1307 len = I40E_NVM_SECTOR_SIZE;
1308 last = false;
1309 for (i = 0; i < sectors; i++) {
1310 if (i == (sectors - 1)) {
1311 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1312 last = true;
1313 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001314 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1315 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001316 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001317 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001318 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001319 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001320 "read NVM failed, invalid offset 0x%x\n",
1321 offset);
1322 break;
1323 } else if (ret_val &&
1324 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1325 dev_info(&pf->pdev->dev,
1326 "read NVM failed, access, offset 0x%x\n",
1327 offset);
1328 break;
1329 } else if (ret_val) {
1330 dev_info(&pf->pdev->dev,
1331 "read NVM failed offset %d err=%d status=0x%x\n",
1332 offset, ret_val, hw->aq.asq_last_status);
1333 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001334 }
1335 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001336
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001337 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001338 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001339free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001340 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341 return ret_val;
1342}
1343
1344static int i40e_get_eeprom_len(struct net_device *netdev)
1345{
1346 struct i40e_netdev_priv *np = netdev_priv(netdev);
1347 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001348 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001349
Lihong Yangc271dd62017-01-30 12:29:32 -08001350#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1351 if (hw->mac.type == I40E_MAC_X722) {
1352 val = X722_EEPROM_SCOPE_LIMIT + 1;
1353 return val;
1354 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001355 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1356 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1357 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1358 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001359 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001360 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361}
1362
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001363static int i40e_set_eeprom(struct net_device *netdev,
1364 struct ethtool_eeprom *eeprom, u8 *bytes)
1365{
1366 struct i40e_netdev_priv *np = netdev_priv(netdev);
1367 struct i40e_hw *hw = &np->vsi->back->hw;
1368 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001369 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001370 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001371 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001372 u32 magic;
1373
1374 /* normal ethtool set_eeprom is not supported */
1375 magic = hw->vendor_id | (hw->device_id << 16);
1376 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001377 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001378 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001379 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1380 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001381 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1382 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001383 errno = -EBUSY;
1384 else
1385 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001386
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001387 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001388 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001389 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1390 ret_val, hw->aq.asq_last_status, errno,
1391 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1392 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001393
1394 return errno;
1395}
1396
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001397static void i40e_get_drvinfo(struct net_device *netdev,
1398 struct ethtool_drvinfo *drvinfo)
1399{
1400 struct i40e_netdev_priv *np = netdev_priv(netdev);
1401 struct i40e_vsi *vsi = np->vsi;
1402 struct i40e_pf *pf = vsi->back;
1403
1404 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1405 strlcpy(drvinfo->version, i40e_driver_version_str,
1406 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001407 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001408 sizeof(drvinfo->fw_version));
1409 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1410 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001411 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001412 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001413 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001414}
1415
1416static void i40e_get_ringparam(struct net_device *netdev,
1417 struct ethtool_ringparam *ring)
1418{
1419 struct i40e_netdev_priv *np = netdev_priv(netdev);
1420 struct i40e_pf *pf = np->vsi->back;
1421 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1422
1423 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1424 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1425 ring->rx_mini_max_pending = 0;
1426 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001427 ring->rx_pending = vsi->rx_rings[0]->count;
1428 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 ring->rx_mini_pending = 0;
1430 ring->rx_jumbo_pending = 0;
1431}
1432
Björn Töpel74608d12017-05-24 07:55:35 +02001433static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1434{
1435 if (i40e_enabled_xdp_vsi(vsi)) {
1436 return index < vsi->num_queue_pairs ||
1437 (index >= vsi->alloc_queue_pairs &&
1438 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1439 }
1440
1441 return index < vsi->num_queue_pairs;
1442}
1443
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001444static int i40e_set_ringparam(struct net_device *netdev,
1445 struct ethtool_ringparam *ring)
1446{
1447 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1448 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001449 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001450 struct i40e_vsi *vsi = np->vsi;
1451 struct i40e_pf *pf = vsi->back;
1452 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001453 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001454 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001455 int i, err = 0;
1456
1457 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1458 return -EINVAL;
1459
Shannon Nelson1fa18372013-11-20 10:03:08 +00001460 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1461 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1462 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1463 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1464 netdev_info(netdev,
1465 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1466 ring->tx_pending, ring->rx_pending,
1467 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1468 return -EINVAL;
1469 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470
Shannon Nelson1fa18372013-11-20 10:03:08 +00001471 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1472 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001473
1474 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001475 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1476 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477 return 0;
1478
Jacob Keller0da36b92017-04-19 09:25:55 -04001479 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001480 timeout--;
1481 if (!timeout)
1482 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001484 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001485
1486 if (!netif_running(vsi->netdev)) {
1487 /* simple case - set for the next time the netdev is started */
1488 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001489 vsi->tx_rings[i]->count = new_tx_count;
1490 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001491 if (i40e_enabled_xdp_vsi(vsi))
1492 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001493 }
1494 goto done;
1495 }
1496
1497 /* We can't just free everything and then setup again,
1498 * because the ISRs in MSI-X mode get passed pointers
1499 * to the Tx and Rx ring structs.
1500 */
1501
Björn Töpel74608d12017-05-24 07:55:35 +02001502 /* alloc updated Tx and XDP Tx resources */
1503 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1504 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001505 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506 netdev_info(netdev,
1507 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001508 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001509 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001510 sizeof(struct i40e_ring), GFP_KERNEL);
1511 if (!tx_rings) {
1512 err = -ENOMEM;
1513 goto done;
1514 }
1515
Björn Töpel74608d12017-05-24 07:55:35 +02001516 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1517 if (!i40e_active_tx_ring_index(vsi, i))
1518 continue;
1519
Alexander Duyck9f65e152013-09-28 06:00:58 +00001520 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001521 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001522 /* the desc and bi pointers will be reallocated in the
1523 * setup call
1524 */
1525 tx_rings[i].desc = NULL;
1526 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001527 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1528 if (err) {
1529 while (i) {
1530 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001531 if (!i40e_active_tx_ring_index(vsi, i))
1532 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001533 i40e_free_tx_resources(&tx_rings[i]);
1534 }
1535 kfree(tx_rings);
1536 tx_rings = NULL;
1537
1538 goto done;
1539 }
1540 }
1541 }
1542
1543 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001544 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545 netdev_info(netdev,
1546 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001547 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1549 sizeof(struct i40e_ring), GFP_KERNEL);
1550 if (!rx_rings) {
1551 err = -ENOMEM;
1552 goto free_tx;
1553 }
1554
1555 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001556 struct i40e_ring *ring;
1557 u16 unused;
1558
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001559 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001560 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001561 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001562 /* the desc and bi pointers will be reallocated in the
1563 * setup call
1564 */
1565 rx_rings[i].desc = NULL;
1566 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001567 /* this is to allow wr32 to have something to write to
1568 * during early allocation of Rx buffers
1569 */
1570 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001572 if (err)
1573 goto rx_unwind;
1574
1575 /* now allocate the Rx buffers to make sure the OS
1576 * has enough memory, any failure here means abort
1577 */
1578 ring = &rx_rings[i];
1579 unused = I40E_DESC_UNUSED(ring);
1580 err = i40e_alloc_rx_buffers(ring, unused);
1581rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001582 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001583 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001585 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001586 kfree(rx_rings);
1587 rx_rings = NULL;
1588
1589 goto free_tx;
1590 }
1591 }
1592 }
1593
1594 /* Bring interface down, copy in the new ring info,
1595 * then restore the interface
1596 */
1597 i40e_down(vsi);
1598
1599 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001600 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1601 if (i40e_active_tx_ring_index(vsi, i)) {
1602 i40e_free_tx_resources(vsi->tx_rings[i]);
1603 *vsi->tx_rings[i] = tx_rings[i];
1604 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001605 }
1606 kfree(tx_rings);
1607 tx_rings = NULL;
1608 }
1609
1610 if (rx_rings) {
1611 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001612 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001613 /* get the real tail offset */
1614 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1615 /* this is to fake out the allocation routine
1616 * into thinking it has to realloc everything
1617 * but the recycling logic will let us re-use
1618 * the buffers allocated above
1619 */
1620 rx_rings[i].next_to_use = 0;
1621 rx_rings[i].next_to_clean = 0;
1622 rx_rings[i].next_to_alloc = 0;
1623 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001624 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001625 }
1626 kfree(rx_rings);
1627 rx_rings = NULL;
1628 }
1629
1630 i40e_up(vsi);
1631
1632free_tx:
1633 /* error cleanup if the Rx allocations failed after getting Tx */
1634 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001635 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1636 if (i40e_active_tx_ring_index(vsi, i))
1637 i40e_free_tx_resources(vsi->tx_rings[i]);
1638 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001639 kfree(tx_rings);
1640 tx_rings = NULL;
1641 }
1642
1643done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001644 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001645
1646 return err;
1647}
1648
1649static int i40e_get_sset_count(struct net_device *netdev, int sset)
1650{
1651 struct i40e_netdev_priv *np = netdev_priv(netdev);
1652 struct i40e_vsi *vsi = np->vsi;
1653 struct i40e_pf *pf = vsi->back;
1654
1655 switch (sset) {
1656 case ETH_SS_TEST:
1657 return I40E_TEST_LEN;
1658 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001659 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001660 int len = I40E_PF_STATS_LEN(netdev);
1661
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001662 if ((pf->lan_veb != I40E_NO_VEB) &&
1663 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001664 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001665 return len;
1666 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001668 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001669 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001670 return I40E_PRIV_FLAGS_STR_LEN +
1671 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001672 default:
1673 return -EOPNOTSUPP;
1674 }
1675}
1676
1677static void i40e_get_ethtool_stats(struct net_device *netdev,
1678 struct ethtool_stats *stats, u64 *data)
1679{
1680 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001681 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001682 struct i40e_vsi *vsi = np->vsi;
1683 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001684 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001685 int i = 0;
1686 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001687 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001688 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001689
1690 i40e_update_stats(vsi);
1691
1692 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1693 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1694 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1695 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1696 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001697 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1698 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1699 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1700 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1701 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001702 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001703 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001704 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001705
1706 if (!tx_ring)
1707 continue;
1708
1709 /* process Tx ring statistics */
1710 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001711 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001712 data[i] = tx_ring->stats.packets;
1713 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001714 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001715 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001716
1717 /* Rx ring is the 2nd half of the queue pair */
1718 rx_ring = &tx_ring[1];
1719 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001720 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001721 data[i] = rx_ring->stats.packets;
1722 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001723 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001724 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001725 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001726 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001727 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001728 return;
1729
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001730 if ((pf->lan_veb != I40E_NO_VEB) &&
1731 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001732 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001733
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001734 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1735 p = (char *)veb;
1736 p += i40e_gstrings_veb_stats[j].stat_offset;
1737 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1738 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001739 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001740 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1741 data[i++] = veb->tc_stats.tc_tx_packets[j];
1742 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1743 data[i++] = veb->tc_stats.tc_rx_packets[j];
1744 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1745 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001746 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001747 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1748 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1749 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1750 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1751 }
1752 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1753 data[i++] = pf->stats.priority_xon_tx[j];
1754 data[i++] = pf->stats.priority_xoff_tx[j];
1755 }
1756 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1757 data[i++] = pf->stats.priority_xon_rx[j];
1758 data[i++] = pf->stats.priority_xoff_rx[j];
1759 }
1760 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1761 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001762}
1763
1764static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1765 u8 *data)
1766{
1767 struct i40e_netdev_priv *np = netdev_priv(netdev);
1768 struct i40e_vsi *vsi = np->vsi;
1769 struct i40e_pf *pf = vsi->back;
1770 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001771 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001772
1773 switch (stringset) {
1774 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001775 memcpy(data, i40e_gstrings_test,
1776 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001777 break;
1778 case ETH_SS_STATS:
1779 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1780 snprintf(p, ETH_GSTRING_LEN, "%s",
1781 i40e_gstrings_net_stats[i].stat_string);
1782 p += ETH_GSTRING_LEN;
1783 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001784 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1785 snprintf(p, ETH_GSTRING_LEN, "%s",
1786 i40e_gstrings_misc_stats[i].stat_string);
1787 p += ETH_GSTRING_LEN;
1788 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001789 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001790 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001792 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001793 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001794 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001795 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001796 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797 p += ETH_GSTRING_LEN;
1798 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001799 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001800 return;
1801
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001802 if ((pf->lan_veb != I40E_NO_VEB) &&
1803 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001804 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1805 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1806 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807 p += ETH_GSTRING_LEN;
1808 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001809 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1810 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001811 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001812 p += ETH_GSTRING_LEN;
1813 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001814 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001815 p += ETH_GSTRING_LEN;
1816 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001817 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001818 p += ETH_GSTRING_LEN;
1819 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001820 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001821 p += ETH_GSTRING_LEN;
1822 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001823 }
1824 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1825 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1826 i40e_gstrings_stats[i].stat_string);
1827 p += ETH_GSTRING_LEN;
1828 }
1829 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1830 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001831 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001832 p += ETH_GSTRING_LEN;
1833 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001834 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001835 p += ETH_GSTRING_LEN;
1836 }
1837 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1838 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001839 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001840 p += ETH_GSTRING_LEN;
1841 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001842 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001843 p += ETH_GSTRING_LEN;
1844 }
1845 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1846 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001847 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001848 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001849 }
1850 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1851 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001852 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001853 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1854 snprintf(p, ETH_GSTRING_LEN, "%s",
1855 i40e_gstrings_priv_flags[i].flag_string);
1856 p += ETH_GSTRING_LEN;
1857 }
1858 if (pf->hw.pf_id != 0)
1859 break;
1860 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1861 snprintf(p, ETH_GSTRING_LEN, "%s",
1862 i40e_gl_gstrings_priv_flags[i].flag_string);
1863 p += ETH_GSTRING_LEN;
1864 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001865 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001866 default:
1867 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001868 }
1869}
1870
1871static int i40e_get_ts_info(struct net_device *dev,
1872 struct ethtool_ts_info *info)
1873{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001874 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1875
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001876 /* only report HW timestamping if PTP is enabled */
1877 if (!(pf->flags & I40E_FLAG_PTP))
1878 return ethtool_op_get_ts_info(dev, info);
1879
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001880 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1881 SOF_TIMESTAMPING_RX_SOFTWARE |
1882 SOF_TIMESTAMPING_SOFTWARE |
1883 SOF_TIMESTAMPING_TX_HARDWARE |
1884 SOF_TIMESTAMPING_RX_HARDWARE |
1885 SOF_TIMESTAMPING_RAW_HARDWARE;
1886
1887 if (pf->ptp_clock)
1888 info->phc_index = ptp_clock_index(pf->ptp_clock);
1889 else
1890 info->phc_index = -1;
1891
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001892 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001893
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001894 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001895 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1896 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1897 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1898
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001899 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001900 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1901 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1902 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1903 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1904 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1905 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1906 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1907 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001908
1909 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001910}
1911
Shannon Nelson7b086392013-11-20 10:02:59 +00001912static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001913{
Shannon Nelson7b086392013-11-20 10:02:59 +00001914 struct i40e_netdev_priv *np = netdev_priv(netdev);
1915 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001916 i40e_status status;
1917 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001918
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001919 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001920 status = i40e_get_link_status(&pf->hw, &link_up);
1921 if (status) {
1922 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1923 *data = 1;
1924 return *data;
1925 }
1926
1927 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001928 *data = 0;
1929 else
1930 *data = 1;
1931
1932 return *data;
1933}
1934
Shannon Nelson7b086392013-11-20 10:02:59 +00001935static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001936{
Shannon Nelson7b086392013-11-20 10:02:59 +00001937 struct i40e_netdev_priv *np = netdev_priv(netdev);
1938 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001940 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001941 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001942
Shannon Nelson7b086392013-11-20 10:02:59 +00001943 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001944}
1945
Shannon Nelson7b086392013-11-20 10:02:59 +00001946static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001947{
Shannon Nelson7b086392013-11-20 10:02:59 +00001948 struct i40e_netdev_priv *np = netdev_priv(netdev);
1949 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001950
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001951 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001952 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953
Shannon Nelson4443ec92014-11-13 08:23:12 +00001954 /* forcebly clear the NVM Update state machine */
1955 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1956
Shannon Nelson7b086392013-11-20 10:02:59 +00001957 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958}
1959
Shannon Nelson7b086392013-11-20 10:02:59 +00001960static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001961{
Shannon Nelson7b086392013-11-20 10:02:59 +00001962 struct i40e_netdev_priv *np = netdev_priv(netdev);
1963 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001964 u16 swc_old = pf->sw_int_count;
1965
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001966 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001967 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1968 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001969 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1970 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1971 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1972 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001973 usleep_range(1000, 2000);
1974 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001975
1976 return *data;
1977}
1978
Greg Rosee17bc412015-04-16 20:05:59 -04001979static inline bool i40e_active_vfs(struct i40e_pf *pf)
1980{
1981 struct i40e_vf *vfs = pf->vf;
1982 int i;
1983
1984 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001985 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001986 return true;
1987 return false;
1988}
1989
Greg Rose510efb22015-07-10 19:36:01 -04001990static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1991{
Alexander Duyck4b816442016-10-11 15:26:53 -07001992 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001993}
1994
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001995static void i40e_diag_test(struct net_device *netdev,
1996 struct ethtool_test *eth_test, u64 *data)
1997{
1998 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001999 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002000 struct i40e_pf *pf = np->vsi->back;
2001
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002002 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2003 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002004 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002005
Jacob Keller0da36b92017-04-19 09:25:55 -04002006 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002007
Greg Rose510efb22015-07-10 19:36:01 -04002008 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002009 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002010 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002011 data[I40E_ETH_TEST_REG] = 1;
2012 data[I40E_ETH_TEST_EEPROM] = 1;
2013 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002014 data[I40E_ETH_TEST_LINK] = 1;
2015 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002016 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002017 goto skip_ol_tests;
2018 }
2019
Greg Rose5b86c5c2015-02-26 16:14:35 +00002020 /* If the device is online then take it offline */
2021 if (if_running)
2022 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002023 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002024 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002025 /* This reset does not affect link - if it is
2026 * changed to a type of reset that does affect
2027 * link then the following link test would have
2028 * to be moved to before the reset
2029 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002030 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002031
Shannon Nelson7b086392013-11-20 10:02:59 +00002032 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002033 eth_test->flags |= ETH_TEST_FL_FAILED;
2034
Shannon Nelson7b086392013-11-20 10:02:59 +00002035 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002036 eth_test->flags |= ETH_TEST_FL_FAILED;
2037
Shannon Nelson7b086392013-11-20 10:02:59 +00002038 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002039 eth_test->flags |= ETH_TEST_FL_FAILED;
2040
Shannon Nelsonf551b432013-11-26 10:49:12 +00002041 /* run reg test last, a reset is required after it */
2042 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2043 eth_test->flags |= ETH_TEST_FL_FAILED;
2044
Jacob Keller0da36b92017-04-19 09:25:55 -04002045 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002046 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002047
2048 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002049 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002050 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002051 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002052 netif_info(pf, drv, netdev, "online testing starting\n");
2053
Shannon Nelson7b086392013-11-20 10:02:59 +00002054 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002055 eth_test->flags |= ETH_TEST_FL_FAILED;
2056
2057 /* Offline only tests, not run in online; pass by default */
2058 data[I40E_ETH_TEST_REG] = 0;
2059 data[I40E_ETH_TEST_EEPROM] = 0;
2060 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002061 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002062
Greg Rosee17bc412015-04-16 20:05:59 -04002063skip_ol_tests:
2064
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002065 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002066}
2067
2068static void i40e_get_wol(struct net_device *netdev,
2069 struct ethtool_wolinfo *wol)
2070{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002071 struct i40e_netdev_priv *np = netdev_priv(netdev);
2072 struct i40e_pf *pf = np->vsi->back;
2073 struct i40e_hw *hw = &pf->hw;
2074 u16 wol_nvm_bits;
2075
2076 /* NVM bit on means WoL disabled for the port */
2077 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002078 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002079 wol->supported = 0;
2080 wol->wolopts = 0;
2081 } else {
2082 wol->supported = WAKE_MAGIC;
2083 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2084 }
2085}
2086
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002087/**
2088 * i40e_set_wol - set the WakeOnLAN configuration
2089 * @netdev: the netdev in question
2090 * @wol: the ethtool WoL setting data
2091 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002092static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2093{
2094 struct i40e_netdev_priv *np = netdev_priv(netdev);
2095 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002096 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002097 struct i40e_hw *hw = &pf->hw;
2098 u16 wol_nvm_bits;
2099
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002100 /* WoL not supported if this isn't the controlling PF on the port */
2101 if (hw->partition_id != 1) {
2102 i40e_partition_setting_complaint(pf);
2103 return -EOPNOTSUPP;
2104 }
2105
2106 if (vsi != pf->vsi[pf->lan_vsi])
2107 return -EOPNOTSUPP;
2108
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002109 /* NVM bit on means WoL disabled for the port */
2110 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002111 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002112 return -EOPNOTSUPP;
2113
2114 /* only magic packet is supported */
2115 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2116 return -EOPNOTSUPP;
2117
2118 /* is this a new value? */
2119 if (pf->wol_en != !!wol->wolopts) {
2120 pf->wol_en = !!wol->wolopts;
2121 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2122 }
2123
2124 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002125}
2126
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002127static int i40e_set_phys_id(struct net_device *netdev,
2128 enum ethtool_phys_id_state state)
2129{
2130 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002131 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002132 struct i40e_pf *pf = np->vsi->back;
2133 struct i40e_hw *hw = &pf->hw;
2134 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002135 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002136
2137 switch (state) {
2138 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002139 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002140 pf->led_status = i40e_led_get(hw);
2141 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002142 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2143 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2144 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002145 ret = i40e_led_get_phy(hw, &temp_status,
2146 &pf->phy_led_val);
2147 pf->led_status = temp_status;
2148 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002149 return blink_freq;
2150 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002151 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002152 i40e_led_set(hw, 0xf, false);
2153 else
2154 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155 break;
2156 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002157 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002158 i40e_led_set(hw, 0x0, false);
2159 else
2160 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002161 break;
2162 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002163 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002164 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002165 } else {
2166 ret = i40e_led_set_phy(hw, false, pf->led_status,
2167 (pf->phy_led_val |
2168 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002169 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2170 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002171 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002173 default:
2174 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002175 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002176 if (ret)
2177 return -ENOENT;
2178 else
2179 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002180}
2181
2182/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2183 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2184 * 125us (8000 interrupts per second) == ITR(62)
2185 */
2186
Jacob Keller65e87c02016-09-12 14:18:44 -07002187/**
2188 * __i40e_get_coalesce - get per-queue coalesce settings
2189 * @netdev: the netdev to check
2190 * @ec: ethtool coalesce data structure
2191 * @queue: which queue to pick
2192 *
2193 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2194 * are per queue. If queue is <0 then we default to queue 0 as the
2195 * representative value.
2196 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002197static int __i40e_get_coalesce(struct net_device *netdev,
2198 struct ethtool_coalesce *ec,
2199 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200{
2201 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002202 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002203 struct i40e_vsi *vsi = np->vsi;
2204
2205 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2206 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2207
Alan Bradya03af692017-10-05 14:53:37 -07002208 /* rx and tx usecs has per queue value. If user doesn't specify the
2209 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002210 */
Alan Bradya03af692017-10-05 14:53:37 -07002211 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002212 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002213 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002214 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002215
Jacob Keller65e87c02016-09-12 14:18:44 -07002216 rx_ring = vsi->rx_rings[queue];
2217 tx_ring = vsi->tx_rings[queue];
2218
2219 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002220 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002221
Jacob Keller65e87c02016-09-12 14:18:44 -07002222 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002223 ec->use_adaptive_tx_coalesce = 1;
2224
Jacob Keller65e87c02016-09-12 14:18:44 -07002225 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2226 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2227
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002228 /* we use the _usecs_high to store/set the interrupt rate limit
2229 * that the hardware supports, that almost but not quite
2230 * fits the original intent of the ethtool variable,
2231 * the rx_coalesce_usecs_high limits total interrupts
2232 * per second from both tx/rx sources.
2233 */
2234 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2235 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002236
2237 return 0;
2238}
2239
Jacob Keller65e87c02016-09-12 14:18:44 -07002240/**
2241 * i40e_get_coalesce - get a netdev's coalesce settings
2242 * @netdev: the netdev to check
2243 * @ec: ethtool coalesce data structure
2244 *
2245 * Gets the coalesce settings for a particular netdev. Note that if user has
2246 * modified per-queue settings, this only guarantees to represent queue 0. See
2247 * __i40e_get_coalesce for more details.
2248 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002249static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002250 struct ethtool_coalesce *ec)
2251{
Kan Lianga75e8002016-02-19 09:24:04 -05002252 return __i40e_get_coalesce(netdev, ec, -1);
2253}
2254
Jacob Keller65e87c02016-09-12 14:18:44 -07002255/**
2256 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2257 * @netdev: netdev structure
2258 * @ec: ethtool's coalesce settings
2259 * @queue: the particular queue to read
2260 *
2261 * Will read a specific queue's coalesce settings
2262 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002263static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2264 struct ethtool_coalesce *ec)
2265{
2266 return __i40e_get_coalesce(netdev, ec, queue);
2267}
2268
Jacob Keller65e87c02016-09-12 14:18:44 -07002269/**
2270 * i40e_set_itr_per_queue - set ITR values for specific queue
2271 * @vsi: the VSI to set values for
2272 * @ec: coalesce settings from ethtool
2273 * @queue: the queue to modify
2274 *
2275 * Change the ITR settings for a specific queue.
2276 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002277static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2278 struct ethtool_coalesce *ec,
2279 int queue)
2280{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 struct i40e_pf *pf = vsi->back;
2282 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002283 struct i40e_q_vector *q_vector;
2284 u16 vector, intrl;
2285
Alan Brady1c0e6a32016-11-28 16:06:02 -08002286 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002287
2288 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2289 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2290
2291 if (ec->use_adaptive_rx_coalesce)
2292 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2293 else
2294 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2295
2296 if (ec->use_adaptive_tx_coalesce)
2297 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2298 else
2299 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2300
2301 q_vector = vsi->rx_rings[queue]->q_vector;
2302 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2303 vector = vsi->base_vector + q_vector->v_idx;
2304 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2305
2306 q_vector = vsi->tx_rings[queue]->q_vector;
2307 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2308 vector = vsi->base_vector + q_vector->v_idx;
2309 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2310
2311 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2312 i40e_flush(hw);
2313}
2314
Jacob Keller65e87c02016-09-12 14:18:44 -07002315/**
2316 * __i40e_set_coalesce - set coalesce settings for particular queue
2317 * @netdev: the netdev to change
2318 * @ec: ethtool coalesce settings
2319 * @queue: the queue to change
2320 *
2321 * Sets the coalesce settings for a particular queue.
2322 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002323static int __i40e_set_coalesce(struct net_device *netdev,
2324 struct ethtool_coalesce *ec,
2325 int queue)
2326{
2327 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002328 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002329 struct i40e_vsi *vsi = np->vsi;
2330 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002331 int i;
2332
2333 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2334 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2335
Alan Brady06b2dec2017-07-12 05:46:06 -04002336 if (queue < 0) {
2337 cur_rx_itr = vsi->rx_rings[0]->rx_itr_setting;
2338 cur_tx_itr = vsi->tx_rings[0]->tx_itr_setting;
2339 } else if (queue < vsi->num_queue_pairs) {
2340 cur_rx_itr = vsi->rx_rings[queue]->rx_itr_setting;
2341 cur_tx_itr = vsi->tx_rings[queue]->tx_itr_setting;
2342 } else {
2343 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2344 vsi->num_queue_pairs - 1);
2345 return -EINVAL;
2346 }
2347
2348 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2349 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2350
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002351 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2352 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2353 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2354 return -EINVAL;
2355 }
2356
Alan Brady33084062016-11-28 16:06:03 -08002357 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2358 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2359 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002360 return -EINVAL;
2361 }
2362
Alan Brady06b2dec2017-07-12 05:46:06 -04002363 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2364 ec->use_adaptive_rx_coalesce) {
2365 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2366 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002367 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002368
Alan Brady06b2dec2017-07-12 05:46:06 -04002369 if (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2370 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2371 return -EINVAL;
2372 }
2373
2374 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2375 ec->use_adaptive_tx_coalesce) {
2376 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2377 return -EINVAL;
2378 }
2379
2380 if (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2381 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2382 return -EINVAL;
2383 }
2384
2385 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2386 ec->rx_coalesce_usecs = I40E_MIN_ITR << 1;
2387
2388 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2389 ec->tx_coalesce_usecs = I40E_MIN_ITR << 1;
2390
Alan Brady33084062016-11-28 16:06:03 -08002391 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2392 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2393 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2394 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2395 vsi->int_rate_limit);
2396 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002397
Alan Bradya03af692017-10-05 14:53:37 -07002398 /* rx and tx usecs has per queue value. If user doesn't specify the
2399 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002400 */
2401 if (queue < 0) {
2402 for (i = 0; i < vsi->num_queue_pairs; i++)
2403 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002404 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002405 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002406 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002407
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002408 return 0;
2409}
2410
Jacob Keller65e87c02016-09-12 14:18:44 -07002411/**
2412 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2413 * @netdev: the netdev to change
2414 * @ec: ethtool coalesce settings
2415 *
2416 * This will set each queue to the same coalesce settings.
2417 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002418static int i40e_set_coalesce(struct net_device *netdev,
2419 struct ethtool_coalesce *ec)
2420{
2421 return __i40e_set_coalesce(netdev, ec, -1);
2422}
2423
Jacob Keller65e87c02016-09-12 14:18:44 -07002424/**
2425 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2426 * @netdev: the netdev to change
2427 * @ec: ethtool's coalesce settings
2428 * @queue: the queue to change
2429 *
2430 * Sets the specified queue's coalesce settings.
2431 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002432static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2433 struct ethtool_coalesce *ec)
2434{
2435 return __i40e_set_coalesce(netdev, ec, queue);
2436}
2437
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002438/**
2439 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2440 * @pf: pointer to the physical function struct
2441 * @cmd: ethtool rxnfc command
2442 *
2443 * Returns Success if the flow is supported, else Invalid Input.
2444 **/
2445static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2446{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002447 struct i40e_hw *hw = &pf->hw;
2448 u8 flow_pctype = 0;
2449 u64 i_set = 0;
2450
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002451 cmd->data = 0;
2452
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002453 switch (cmd->flow_type) {
2454 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002455 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2456 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002457 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002458 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2459 break;
2460 case TCP_V6_FLOW:
2461 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2462 break;
2463 case UDP_V6_FLOW:
2464 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2465 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002466 case SCTP_V4_FLOW:
2467 case AH_ESP_V4_FLOW:
2468 case AH_V4_FLOW:
2469 case ESP_V4_FLOW:
2470 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002471 case SCTP_V6_FLOW:
2472 case AH_ESP_V6_FLOW:
2473 case AH_V6_FLOW:
2474 case ESP_V6_FLOW:
2475 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002476 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002477 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2478 break;
2479 default:
2480 return -EINVAL;
2481 }
2482
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002483 /* Read flow based hash input set register */
2484 if (flow_pctype) {
2485 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2486 flow_pctype)) |
2487 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2488 flow_pctype)) << 32);
2489 }
2490
2491 /* Process bits of hash input set */
2492 if (i_set) {
2493 if (i_set & I40E_L4_SRC_MASK)
2494 cmd->data |= RXH_L4_B_0_1;
2495 if (i_set & I40E_L4_DST_MASK)
2496 cmd->data |= RXH_L4_B_2_3;
2497
2498 if (cmd->flow_type == TCP_V4_FLOW ||
2499 cmd->flow_type == UDP_V4_FLOW) {
2500 if (i_set & I40E_L3_SRC_MASK)
2501 cmd->data |= RXH_IP_SRC;
2502 if (i_set & I40E_L3_DST_MASK)
2503 cmd->data |= RXH_IP_DST;
2504 } else if (cmd->flow_type == TCP_V6_FLOW ||
2505 cmd->flow_type == UDP_V6_FLOW) {
2506 if (i_set & I40E_L3_V6_SRC_MASK)
2507 cmd->data |= RXH_IP_SRC;
2508 if (i_set & I40E_L3_V6_DST_MASK)
2509 cmd->data |= RXH_IP_DST;
2510 }
2511 }
2512
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002513 return 0;
2514}
2515
2516/**
Jacob Kellere7930952017-02-06 14:38:49 -08002517 * i40e_check_mask - Check whether a mask field is set
2518 * @mask: the full mask value
2519 * @field; mask of the field to check
2520 *
2521 * If the given mask is fully set, return positive value. If the mask for the
2522 * field is fully unset, return zero. Otherwise return a negative error code.
2523 **/
2524static int i40e_check_mask(u64 mask, u64 field)
2525{
2526 u64 value = mask & field;
2527
2528 if (value == field)
2529 return 1;
2530 else if (!value)
2531 return 0;
2532 else
2533 return -1;
2534}
2535
2536/**
2537 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2538 * @fsp: pointer to rx flow specification
2539 * @data: pointer to userdef data structure for storage
2540 *
2541 * Read the user-defined data and deconstruct the value into a structure. No
2542 * other code should read the user-defined data, so as to ensure that every
2543 * place consistently reads the value correctly.
2544 *
2545 * The user-defined field is a 64bit Big Endian format value, which we
2546 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2547 * be defined starting from the highest bits, while small bit field values
2548 * shall be defined starting from the lowest bits.
2549 *
2550 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2551 * and the filter should be rejected. The data structure will always be
2552 * modified even if FLOW_EXT is not set.
2553 *
2554 **/
2555static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2556 struct i40e_rx_flow_userdef *data)
2557{
2558 u64 value, mask;
2559 int valid;
2560
2561 /* Zero memory first so it's always consistent. */
2562 memset(data, 0, sizeof(*data));
2563
2564 if (!(fsp->flow_type & FLOW_EXT))
2565 return 0;
2566
2567 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2568 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2569
2570#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2571#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2572#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2573
2574 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2575 if (valid < 0) {
2576 return -EINVAL;
2577 } else if (valid) {
2578 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2579 data->flex_offset =
2580 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2581 data->flex_filter = true;
2582 }
2583
2584 return 0;
2585}
2586
2587/**
2588 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2589 * @fsp: pointer to rx_flow specification
2590 *
2591 * Reads the userdef data structure and properly fills in the user defined
2592 * fields of the rx_flow_spec.
2593 **/
2594static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2595 struct i40e_rx_flow_userdef *data)
2596{
2597 u64 value = 0, mask = 0;
2598
2599 if (data->flex_filter) {
2600 value |= data->flex_word;
2601 value |= (u64)data->flex_offset << 16;
2602 mask |= I40E_USERDEF_FLEX_FILTER;
2603 }
2604
2605 if (value || mask)
2606 fsp->flow_type |= FLOW_EXT;
2607
2608 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2609 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2610}
2611
2612/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002613 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2614 * @pf: Pointer to the physical function struct
2615 * @cmd: The command to get or set Rx flow classification rules
2616 * @rule_locs: Array of used rule locations
2617 *
2618 * This function populates both the total and actual rule count of
2619 * the ethtool flow classification command
2620 *
2621 * Returns 0 on success or -EMSGSIZE if entry not found
2622 **/
2623static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2624 struct ethtool_rxnfc *cmd,
2625 u32 *rule_locs)
2626{
2627 struct i40e_fdir_filter *rule;
2628 struct hlist_node *node2;
2629 int cnt = 0;
2630
2631 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002632 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002633
2634 hlist_for_each_entry_safe(rule, node2,
2635 &pf->fdir_filter_list, fdir_node) {
2636 if (cnt == cmd->rule_cnt)
2637 return -EMSGSIZE;
2638
2639 rule_locs[cnt] = rule->fd_id;
2640 cnt++;
2641 }
2642
2643 cmd->rule_cnt = cnt;
2644
2645 return 0;
2646}
2647
2648/**
2649 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2650 * @pf: Pointer to the physical function struct
2651 * @cmd: The command to get or set Rx flow classification rules
2652 *
2653 * This function looks up a filter based on the Rx flow classification
2654 * command and fills the flow spec info for it if found
2655 *
2656 * Returns 0 on success or -EINVAL if filter not found
2657 **/
2658static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2659 struct ethtool_rxnfc *cmd)
2660{
2661 struct ethtool_rx_flow_spec *fsp =
2662 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002663 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002664 struct i40e_fdir_filter *rule = NULL;
2665 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002666 u64 input_set;
2667 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002668
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002669 hlist_for_each_entry_safe(rule, node2,
2670 &pf->fdir_filter_list, fdir_node) {
2671 if (fsp->location <= rule->fd_id)
2672 break;
2673 }
2674
2675 if (!rule || fsp->location != rule->fd_id)
2676 return -EINVAL;
2677
2678 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002679 if (fsp->flow_type == IP_USER_FLOW) {
2680 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2681 fsp->h_u.usr_ip4_spec.proto = 0;
2682 fsp->m_u.usr_ip4_spec.proto = 0;
2683 }
2684
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002685 /* Reverse the src and dest notion, since the HW views them from
2686 * Tx perspective where as the user expects it from Rx filter view.
2687 */
2688 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2689 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002690 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2691 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002692
Jacob Keller36777d92017-03-07 15:05:23 -08002693 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002694 case SCTP_V4_FLOW:
2695 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2696 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002697 case TCP_V4_FLOW:
2698 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2699 break;
2700 case UDP_V4_FLOW:
2701 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2702 break;
2703 case IP_USER_FLOW:
2704 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2705 break;
2706 default:
2707 /* If we have stored a filter with a flow type not listed here
2708 * it is almost certainly a driver bug. WARN(), and then
2709 * assign the input_set as if all fields are enabled to avoid
2710 * reading unassigned memory.
2711 */
2712 WARN(1, "Missing input set index for flow_type %d\n",
2713 rule->flow_type);
2714 input_set = 0xFFFFFFFFFFFFFFFFULL;
2715 goto no_input_set;
2716 }
2717
2718 input_set = i40e_read_fd_input_set(pf, index);
2719
2720no_input_set:
2721 if (input_set & I40E_L3_SRC_MASK)
2722 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
2723
2724 if (input_set & I40E_L3_DST_MASK)
2725 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
2726
2727 if (input_set & I40E_L4_SRC_MASK)
2728 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
2729
2730 if (input_set & I40E_L4_DST_MASK)
2731 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002732
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002733 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2734 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2735 else
2736 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002737
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002738 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2739 struct i40e_vsi *vsi;
2740
2741 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2742 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002743 /* VFs are zero-indexed by the driver, but ethtool
2744 * expects them to be one-indexed, so add one here
2745 */
2746 u64 ring_vf = vsi->vf_id + 1;
2747
2748 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2749 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002750 }
2751 }
2752
Jacob Keller0e588de2017-02-06 14:38:50 -08002753 if (rule->flex_filter) {
2754 userdef.flex_filter = true;
2755 userdef.flex_word = be16_to_cpu(rule->flex_word);
2756 userdef.flex_offset = rule->flex_offset;
2757 }
2758
Jacob Kellere7930952017-02-06 14:38:49 -08002759 i40e_fill_rx_flow_user_data(fsp, &userdef);
2760
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002761 return 0;
2762}
2763
2764/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002765 * i40e_get_rxnfc - command to get RX flow classification rules
2766 * @netdev: network interface device structure
2767 * @cmd: ethtool rxnfc command
2768 *
2769 * Returns Success if the command is supported.
2770 **/
2771static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2772 u32 *rule_locs)
2773{
2774 struct i40e_netdev_priv *np = netdev_priv(netdev);
2775 struct i40e_vsi *vsi = np->vsi;
2776 struct i40e_pf *pf = vsi->back;
2777 int ret = -EOPNOTSUPP;
2778
2779 switch (cmd->cmd) {
2780 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002781 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002782 ret = 0;
2783 break;
2784 case ETHTOOL_GRXFH:
2785 ret = i40e_get_rss_hash_opts(pf, cmd);
2786 break;
2787 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002788 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002789 /* report total rule count */
2790 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002791 ret = 0;
2792 break;
2793 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002794 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002795 break;
2796 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002797 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2798 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002799 default:
2800 break;
2801 }
2802
2803 return ret;
2804}
2805
2806/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002807 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2808 * @nfc: pointer to user request
2809 * @i_setc bits currently set
2810 *
2811 * Returns value of bits to be set per user request
2812 **/
2813static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2814{
2815 u64 i_set = i_setc;
2816 u64 src_l3 = 0, dst_l3 = 0;
2817
2818 if (nfc->data & RXH_L4_B_0_1)
2819 i_set |= I40E_L4_SRC_MASK;
2820 else
2821 i_set &= ~I40E_L4_SRC_MASK;
2822 if (nfc->data & RXH_L4_B_2_3)
2823 i_set |= I40E_L4_DST_MASK;
2824 else
2825 i_set &= ~I40E_L4_DST_MASK;
2826
2827 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2828 src_l3 = I40E_L3_V6_SRC_MASK;
2829 dst_l3 = I40E_L3_V6_DST_MASK;
2830 } else if (nfc->flow_type == TCP_V4_FLOW ||
2831 nfc->flow_type == UDP_V4_FLOW) {
2832 src_l3 = I40E_L3_SRC_MASK;
2833 dst_l3 = I40E_L3_DST_MASK;
2834 } else {
2835 /* Any other flow type are not supported here */
2836 return i_set;
2837 }
2838
2839 if (nfc->data & RXH_IP_SRC)
2840 i_set |= src_l3;
2841 else
2842 i_set &= ~src_l3;
2843 if (nfc->data & RXH_IP_DST)
2844 i_set |= dst_l3;
2845 else
2846 i_set &= ~dst_l3;
2847
2848 return i_set;
2849}
2850
2851/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002852 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2853 * @pf: pointer to the physical function struct
2854 * @cmd: ethtool rxnfc command
2855 *
2856 * Returns Success if the flow input set is supported.
2857 **/
2858static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2859{
2860 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002861 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2862 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002863 u8 flow_pctype = 0;
2864 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002865
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002866 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2867 dev_err(&pf->pdev->dev,
2868 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2869 return -EOPNOTSUPP;
2870 }
2871
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002872 /* RSS does not support anything other than hashing
2873 * to queues on src and dst IPs and ports
2874 */
2875 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2876 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2877 return -EINVAL;
2878
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002879 switch (nfc->flow_type) {
2880 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002881 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002882 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002883 hena |=
2884 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002885 break;
2886 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002887 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002888 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002889 hena |=
2890 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002891 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002892 hena |=
2893 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002894 break;
2895 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002896 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002897 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002898 hena |=
2899 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2900 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002901
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002902 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002903 break;
2904 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002905 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002906 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002907 hena |=
2908 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2909 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002910
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002911 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002912 break;
2913 case AH_ESP_V4_FLOW:
2914 case AH_V4_FLOW:
2915 case ESP_V4_FLOW:
2916 case SCTP_V4_FLOW:
2917 if ((nfc->data & RXH_L4_B_0_1) ||
2918 (nfc->data & RXH_L4_B_2_3))
2919 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002920 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002921 break;
2922 case AH_ESP_V6_FLOW:
2923 case AH_V6_FLOW:
2924 case ESP_V6_FLOW:
2925 case SCTP_V6_FLOW:
2926 if ((nfc->data & RXH_L4_B_0_1) ||
2927 (nfc->data & RXH_L4_B_2_3))
2928 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002929 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002930 break;
2931 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002932 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2933 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002934 break;
2935 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002936 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2937 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002938 break;
2939 default:
2940 return -EINVAL;
2941 }
2942
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002943 if (flow_pctype) {
2944 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2945 flow_pctype)) |
2946 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2947 flow_pctype)) << 32);
2948 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2949 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2950 (u32)i_set);
2951 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2952 (u32)(i_set >> 32));
2953 hena |= BIT_ULL(flow_pctype);
2954 }
2955
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002956 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2957 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002958 i40e_flush(hw);
2959
2960 return 0;
2961}
2962
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002963/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002964 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2965 * @vsi: Pointer to the targeted VSI
2966 * @input: The filter to update or NULL to indicate deletion
2967 * @sw_idx: Software index to the filter
2968 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002969 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002970 * This function updates (or deletes) a Flow Director entry from
2971 * the hlist of the corresponding PF
2972 *
2973 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002974 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002975static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2976 struct i40e_fdir_filter *input,
2977 u16 sw_idx,
2978 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002979{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002980 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002981 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002982 struct hlist_node *node2;
2983 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002984
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002985 parent = NULL;
2986 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002987
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002988 hlist_for_each_entry_safe(rule, node2,
2989 &pf->fdir_filter_list, fdir_node) {
2990 /* hash found, or no matching entry */
2991 if (rule->fd_id >= sw_idx)
2992 break;
2993 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002994 }
2995
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002996 /* if there is an old rule occupying our place remove it */
2997 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08002998 /* Remove this rule, since we're either deleting it, or
2999 * replacing it.
3000 */
3001 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003002 hlist_del(&rule->fdir_node);
3003 kfree(rule);
3004 pf->fdir_pf_active_filters--;
3005 }
3006
Jacob Kellerc6da5252017-02-06 14:39:13 -08003007 /* If we weren't given an input, this is a delete, so just return the
3008 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003009 */
3010 if (!input)
3011 return err;
3012
Jacob Kellerc6da5252017-02-06 14:39:13 -08003013 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003014 INIT_HLIST_NODE(&input->fdir_node);
3015
3016 /* add filter to the list */
3017 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003018 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003019 else
3020 hlist_add_head(&input->fdir_node,
3021 &pf->fdir_filter_list);
3022
3023 /* update counts */
3024 pf->fdir_pf_active_filters++;
3025
3026 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003027}
3028
3029/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003030 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3031 * @pf: pointer to PF structure
3032 *
3033 * This function searches the list of filters and determines which FLX_PIT
3034 * entries are still required. It will prune any entries which are no longer
3035 * in use after the deletion.
3036 **/
3037static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3038{
3039 struct i40e_flex_pit *entry, *tmp;
3040 struct i40e_fdir_filter *rule;
3041
3042 /* First, we'll check the l3 table */
3043 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3044 bool found = false;
3045
3046 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3047 if (rule->flow_type != IP_USER_FLOW)
3048 continue;
3049 if (rule->flex_filter &&
3050 rule->flex_offset == entry->src_offset) {
3051 found = true;
3052 break;
3053 }
3054 }
3055
3056 /* If we didn't find the filter, then we can prune this entry
3057 * from the list.
3058 */
3059 if (!found) {
3060 list_del(&entry->list);
3061 kfree(entry);
3062 }
3063 }
3064
3065 /* Followed by the L4 table */
3066 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3067 bool found = false;
3068
3069 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3070 /* Skip this filter if it's L3, since we already
3071 * checked those in the above loop
3072 */
3073 if (rule->flow_type == IP_USER_FLOW)
3074 continue;
3075 if (rule->flex_filter &&
3076 rule->flex_offset == entry->src_offset) {
3077 found = true;
3078 break;
3079 }
3080 }
3081
3082 /* If we didn't find the filter, then we can prune this entry
3083 * from the list.
3084 */
3085 if (!found) {
3086 list_del(&entry->list);
3087 kfree(entry);
3088 }
3089 }
3090}
3091
3092/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003093 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3094 * @vsi: Pointer to the targeted VSI
3095 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003096 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003097 * The function removes a Flow Director filter entry from the
3098 * hlist of the corresponding PF
3099 *
3100 * Returns 0 on success
3101 */
3102static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3103 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003104{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003105 struct ethtool_rx_flow_spec *fsp =
3106 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003107 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003108 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003109
Jacob Keller0da36b92017-04-19 09:25:55 -04003110 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3111 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003112 return -EBUSY;
3113
Jacob Keller0da36b92017-04-19 09:25:55 -04003114 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003115 return -EBUSY;
3116
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003117 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003118
Jacob Keller0e588de2017-02-06 14:38:50 -08003119 i40e_prune_flex_pit_list(pf);
3120
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003121 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003122 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003123}
3124
3125/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003126 * i40e_unused_pit_index - Find an unused PIT index for given list
3127 * @pf: the PF data structure
3128 *
3129 * Find the first unused flexible PIT index entry. We search both the L3 and
3130 * L4 flexible PIT lists so that the returned index is unique and unused by
3131 * either currently programmed L3 or L4 filters. We use a bit field as storage
3132 * to track which indexes are already used.
3133 **/
3134static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3135{
3136 unsigned long available_index = 0xFF;
3137 struct i40e_flex_pit *entry;
3138
3139 /* We need to make sure that the new index isn't in use by either L3
3140 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3141 * L4 to use the same index.
3142 */
3143
3144 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3145 clear_bit(entry->pit_index, &available_index);
3146
3147 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3148 clear_bit(entry->pit_index, &available_index);
3149
3150 return find_first_bit(&available_index, 8);
3151}
3152
3153/**
3154 * i40e_find_flex_offset - Find an existing flex src_offset
3155 * @flex_pit_list: L3 or L4 flex PIT list
3156 * @src_offset: new src_offset to find
3157 *
3158 * Searches the flex_pit_list for an existing offset. If no offset is
3159 * currently programmed, then this will return an ERR_PTR if there is no space
3160 * to add a new offset, otherwise it returns NULL.
3161 **/
3162static
3163struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3164 u16 src_offset)
3165{
3166 struct i40e_flex_pit *entry;
3167 int size = 0;
3168
3169 /* Search for the src_offset first. If we find a matching entry
3170 * already programmed, we can simply re-use it.
3171 */
3172 list_for_each_entry(entry, flex_pit_list, list) {
3173 size++;
3174 if (entry->src_offset == src_offset)
3175 return entry;
3176 }
3177
3178 /* If we haven't found an entry yet, then the provided src offset has
3179 * not yet been programmed. We will program the src offset later on,
3180 * but we need to indicate whether there is enough space to do so
3181 * here. We'll make use of ERR_PTR for this purpose.
3182 */
3183 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3184 return ERR_PTR(-ENOSPC);
3185
3186 return NULL;
3187}
3188
3189/**
3190 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3191 * @flex_pit_list: L3 or L4 flex PIT list
3192 * @src_offset: new src_offset to add
3193 * @pit_index: the PIT index to program
3194 *
3195 * This function programs the new src_offset to the list. It is expected that
3196 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3197 * that this offset is not programmed, and that the list has enough space to
3198 * store another offset.
3199 *
3200 * Returns 0 on success, and negative value on error.
3201 **/
3202static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3203 u16 src_offset,
3204 u8 pit_index)
3205{
3206 struct i40e_flex_pit *new_pit, *entry;
3207
3208 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3209 if (!new_pit)
3210 return -ENOMEM;
3211
3212 new_pit->src_offset = src_offset;
3213 new_pit->pit_index = pit_index;
3214
3215 /* We need to insert this item such that the list is sorted by
3216 * src_offset in ascending order.
3217 */
3218 list_for_each_entry(entry, flex_pit_list, list) {
3219 if (new_pit->src_offset < entry->src_offset) {
3220 list_add_tail(&new_pit->list, &entry->list);
3221 return 0;
3222 }
3223
3224 /* If we found an entry with our offset already programmed we
3225 * can simply return here, after freeing the memory. However,
3226 * if the pit_index does not match we need to report an error.
3227 */
3228 if (new_pit->src_offset == entry->src_offset) {
3229 int err = 0;
3230
3231 /* If the PIT index is not the same we can't re-use
3232 * the entry, so we must report an error.
3233 */
3234 if (new_pit->pit_index != entry->pit_index)
3235 err = -EINVAL;
3236
3237 kfree(new_pit);
3238 return err;
3239 }
3240 }
3241
3242 /* If we reached here, then we haven't yet added the item. This means
3243 * that we should add the item at the end of the list.
3244 */
3245 list_add_tail(&new_pit->list, flex_pit_list);
3246 return 0;
3247}
3248
3249/**
3250 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3251 * @pf: Pointer to the PF structure
3252 * @flex_pit_list: list of flexible src offsets in use
3253 * #flex_pit_start: index to first entry for this section of the table
3254 *
3255 * In order to handle flexible data, the hardware uses a table of values
3256 * called the FLX_PIT table. This table is used to indicate which sections of
3257 * the input correspond to what PIT index values. Unfortunately, hardware is
3258 * very restrictive about programming this table. Entries must be ordered by
3259 * src_offset in ascending order, without duplicates. Additionally, unused
3260 * entries must be set to the unused index value, and must have valid size and
3261 * length according to the src_offset ordering.
3262 *
3263 * This function will reprogram the FLX_PIT register from a book-keeping
3264 * structure that we guarantee is already ordered correctly, and has no more
3265 * than 3 entries.
3266 *
3267 * To make things easier, we only support flexible values of one word length,
3268 * rather than allowing variable length flexible values.
3269 **/
3270static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3271 struct list_head *flex_pit_list,
3272 int flex_pit_start)
3273{
3274 struct i40e_flex_pit *entry = NULL;
3275 u16 last_offset = 0;
3276 int i = 0, j = 0;
3277
3278 /* First, loop over the list of flex PIT entries, and reprogram the
3279 * registers.
3280 */
3281 list_for_each_entry(entry, flex_pit_list, list) {
3282 /* We have to be careful when programming values for the
3283 * largest SRC_OFFSET value. It is possible that adding
3284 * additional empty values at the end would overflow the space
3285 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3286 * we check here and add the empty values prior to adding the
3287 * largest value.
3288 *
3289 * To determine this, we will use a loop from i+1 to 3, which
3290 * will determine whether the unused entries would have valid
3291 * SRC_OFFSET. Note that there cannot be extra entries past
3292 * this value, because the only valid values would have been
3293 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3294 * have been added to the list in the first place.
3295 */
3296 for (j = i + 1; j < 3; j++) {
3297 u16 offset = entry->src_offset + j;
3298 int index = flex_pit_start + i;
3299 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3300 1,
3301 offset - 3);
3302
3303 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3304 i40e_write_rx_ctl(&pf->hw,
3305 I40E_PRTQF_FLX_PIT(index),
3306 value);
3307 i++;
3308 }
3309 }
3310
3311 /* Now, we can program the actual value into the table */
3312 i40e_write_rx_ctl(&pf->hw,
3313 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3314 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3315 1,
3316 entry->src_offset));
3317 i++;
3318 }
3319
3320 /* In order to program the last entries in the table, we need to
3321 * determine the valid offset. If the list is empty, we'll just start
3322 * with 0. Otherwise, we'll start with the last item offset and add 1.
3323 * This ensures that all entries have valid sizes. If we don't do this
3324 * correctly, the hardware will disable flexible field parsing.
3325 */
3326 if (!list_empty(flex_pit_list))
3327 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3328
3329 for (; i < 3; i++, last_offset++) {
3330 i40e_write_rx_ctl(&pf->hw,
3331 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3332 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3333 1,
3334 last_offset));
3335 }
3336}
3337
3338/**
3339 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3340 * @pf: pointer to the PF structure
3341 *
3342 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3343 * internal helper function for implementation details.
3344 **/
3345static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3346{
3347 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3348 I40E_FLEX_PIT_IDX_START_L3);
3349
3350 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3351 I40E_FLEX_PIT_IDX_START_L4);
3352
3353 /* We also need to program the L3 and L4 GLQF ORT register */
3354 i40e_write_rx_ctl(&pf->hw,
3355 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3356 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3357 3, 1));
3358
3359 i40e_write_rx_ctl(&pf->hw,
3360 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3361 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3362 3, 1));
3363}
3364
3365/**
Jacob Keller9229e992017-02-06 14:38:47 -08003366 * i40e_flow_str - Converts a flow_type into a human readable string
3367 * @flow_type: the flow type from a flow specification
3368 *
3369 * Currently only flow types we support are included here, and the string
3370 * value attempts to match what ethtool would use to configure this flow type.
3371 **/
3372static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3373{
3374 switch (fsp->flow_type & ~FLOW_EXT) {
3375 case TCP_V4_FLOW:
3376 return "tcp4";
3377 case UDP_V4_FLOW:
3378 return "udp4";
3379 case SCTP_V4_FLOW:
3380 return "sctp4";
3381 case IP_USER_FLOW:
3382 return "ip4";
3383 default:
3384 return "unknown";
3385 }
3386}
3387
3388/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003389 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3390 * @pit_index: PIT index to convert
3391 *
3392 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3393 * of range.
3394 **/
3395static u64 i40e_pit_index_to_mask(int pit_index)
3396{
3397 switch (pit_index) {
3398 case 0:
3399 return I40E_FLEX_50_MASK;
3400 case 1:
3401 return I40E_FLEX_51_MASK;
3402 case 2:
3403 return I40E_FLEX_52_MASK;
3404 case 3:
3405 return I40E_FLEX_53_MASK;
3406 case 4:
3407 return I40E_FLEX_54_MASK;
3408 case 5:
3409 return I40E_FLEX_55_MASK;
3410 case 6:
3411 return I40E_FLEX_56_MASK;
3412 case 7:
3413 return I40E_FLEX_57_MASK;
3414 default:
3415 return 0;
3416 }
3417}
3418
3419/**
Jacob Keller9229e992017-02-06 14:38:47 -08003420 * i40e_print_input_set - Show changes between two input sets
3421 * @vsi: the vsi being configured
3422 * @old: the old input set
3423 * @new: the new input set
3424 *
3425 * Print the difference between old and new input sets by showing which series
3426 * of words are toggled on or off. Only displays the bits we actually support
3427 * changing.
3428 **/
3429static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3430{
3431 struct i40e_pf *pf = vsi->back;
3432 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003433 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003434
3435 old_value = !!(old & I40E_L3_SRC_MASK);
3436 new_value = !!(new & I40E_L3_SRC_MASK);
3437 if (old_value != new_value)
3438 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3439 old_value ? "ON" : "OFF",
3440 new_value ? "ON" : "OFF");
3441
3442 old_value = !!(old & I40E_L3_DST_MASK);
3443 new_value = !!(new & I40E_L3_DST_MASK);
3444 if (old_value != new_value)
3445 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3446 old_value ? "ON" : "OFF",
3447 new_value ? "ON" : "OFF");
3448
3449 old_value = !!(old & I40E_L4_SRC_MASK);
3450 new_value = !!(new & I40E_L4_SRC_MASK);
3451 if (old_value != new_value)
3452 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3453 old_value ? "ON" : "OFF",
3454 new_value ? "ON" : "OFF");
3455
3456 old_value = !!(old & I40E_L4_DST_MASK);
3457 new_value = !!(new & I40E_L4_DST_MASK);
3458 if (old_value != new_value)
3459 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3460 old_value ? "ON" : "OFF",
3461 new_value ? "ON" : "OFF");
3462
3463 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3464 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3465 if (old_value != new_value)
3466 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3467 old_value ? "ON" : "OFF",
3468 new_value ? "ON" : "OFF");
3469
Jacob Keller0e588de2017-02-06 14:38:50 -08003470 /* Show change of flexible filter entries */
3471 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3472 u64 flex_mask = i40e_pit_index_to_mask(i);
3473
3474 old_value = !!(old & flex_mask);
3475 new_value = !!(new & flex_mask);
3476 if (old_value != new_value)
3477 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3478 i,
3479 old_value ? "ON" : "OFF",
3480 new_value ? "ON" : "OFF");
3481 }
3482
Jacob Keller9229e992017-02-06 14:38:47 -08003483 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3484 old);
3485 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3486 new);
3487}
3488
3489/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003490 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003491 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003492 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003493 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003494 *
Jacob Keller9229e992017-02-06 14:38:47 -08003495 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3496 * for partial matches exists with a few limitations. First, hardware only
3497 * supports masking by word boundary (2 bytes) and not per individual bit.
3498 * Second, hardware is limited to using one mask for a flow type and cannot
3499 * use a separate mask for each filter.
3500 *
3501 * To support these limitations, if we already have a configured filter for
3502 * the specified type, this function enforces that new filters of the type
3503 * match the configured input set. Otherwise, if we do not have a filter of
3504 * the specified type, we allow the input set to be updated to match the
3505 * desired filter.
3506 *
3507 * To help ensure that administrators understand why filters weren't displayed
3508 * as supported, we print a diagnostic message displaying how the input set
3509 * would change and warning to delete the preexisting filters if required.
3510 *
3511 * Returns 0 on successful input set match, and a negative return code on
3512 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003513 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003514static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003515 struct ethtool_rx_flow_spec *fsp,
3516 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003517{
Jacob Keller36777d92017-03-07 15:05:23 -08003518 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003519 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3520 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003521 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003522 bool new_flex_offset = false;
3523 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003524 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003525 u16 index, src_offset = 0;
3526 u8 pit_index = 0;
3527 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003528
3529 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003530 case SCTP_V4_FLOW:
3531 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3532 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3533 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003534 case TCP_V4_FLOW:
3535 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003536 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003537 break;
3538 case UDP_V4_FLOW:
3539 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003540 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003541 break;
3542 case IP_USER_FLOW:
3543 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003544 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003545 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003546 break;
3547 default:
3548 return -EOPNOTSUPP;
3549 }
3550
3551 /* Read the current input set from register memory. */
3552 current_mask = i40e_read_fd_input_set(pf, index);
3553 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003554
Jacob Keller9229e992017-02-06 14:38:47 -08003555 /* Determine, if any, the required changes to the input set in order
3556 * to support the provided mask.
3557 *
3558 * Hardware only supports masking at word (2 byte) granularity and does
3559 * not support full bitwise masking. This implementation simplifies
3560 * even further and only supports fully enabled or fully disabled
3561 * masks for each field, even though we could split the ip4src and
3562 * ip4dst fields.
3563 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003564 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003565 case SCTP_V4_FLOW:
3566 new_mask &= ~I40E_VERIFY_TAG_MASK;
3567 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003568 case TCP_V4_FLOW:
3569 case UDP_V4_FLOW:
3570 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3571
3572 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003573 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3574 new_mask |= I40E_L3_SRC_MASK;
3575 else if (!tcp_ip4_spec->ip4src)
3576 new_mask &= ~I40E_L3_SRC_MASK;
3577 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003578 return -EOPNOTSUPP;
3579
3580 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003581 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3582 new_mask |= I40E_L3_DST_MASK;
3583 else if (!tcp_ip4_spec->ip4dst)
3584 new_mask &= ~I40E_L3_DST_MASK;
3585 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003586 return -EOPNOTSUPP;
3587
3588 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003589 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3590 new_mask |= I40E_L4_SRC_MASK;
3591 else if (!tcp_ip4_spec->psrc)
3592 new_mask &= ~I40E_L4_SRC_MASK;
3593 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003594 return -EOPNOTSUPP;
3595
3596 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003597 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3598 new_mask |= I40E_L4_DST_MASK;
3599 else if (!tcp_ip4_spec->pdst)
3600 new_mask &= ~I40E_L4_DST_MASK;
3601 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003602 return -EOPNOTSUPP;
3603
3604 /* Filtering on Type of Service is not supported. */
3605 if (tcp_ip4_spec->tos)
3606 return -EOPNOTSUPP;
3607
3608 break;
3609 case IP_USER_FLOW:
3610 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3611
3612 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003613 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3614 new_mask |= I40E_L3_SRC_MASK;
3615 else if (!usr_ip4_spec->ip4src)
3616 new_mask &= ~I40E_L3_SRC_MASK;
3617 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003618 return -EOPNOTSUPP;
3619
3620 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003621 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3622 new_mask |= I40E_L3_DST_MASK;
3623 else if (!usr_ip4_spec->ip4dst)
3624 new_mask &= ~I40E_L3_DST_MASK;
3625 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003626 return -EOPNOTSUPP;
3627
3628 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003629 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3630 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3631 else if (!usr_ip4_spec->l4_4_bytes)
3632 new_mask &= ~(I40E_L4_SRC_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 (usr_ip4_spec->tos)
3638 return -EOPNOTSUPP;
3639
Jacob Keller0e588de2017-02-06 14:38:50 -08003640 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003641 if (usr_ip4_spec->ip_ver)
3642 return -EINVAL;
3643
Jacob Keller0e588de2017-02-06 14:38:50 -08003644 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003645 if (usr_ip4_spec->proto)
3646 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003647
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003648 break;
3649 default:
3650 return -EOPNOTSUPP;
3651 }
3652
Jacob Keller0e588de2017-02-06 14:38:50 -08003653 /* First, clear all flexible filter entries */
3654 new_mask &= ~I40E_FLEX_INPUT_MASK;
3655
3656 /* If we have a flexible filter, try to add this offset to the correct
3657 * flexible filter PIT list. Once finished, we can update the mask.
3658 * If the src_offset changed, we will get a new mask value which will
3659 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003660 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003661 if (userdef->flex_filter) {
3662 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3663
3664 /* Flexible offset must be even, since the flexible payload
3665 * must be aligned on 2-byte boundary.
3666 */
3667 if (userdef->flex_offset & 0x1) {
3668 dev_warn(&pf->pdev->dev,
3669 "Flexible data offset must be 2-byte aligned\n");
3670 return -EINVAL;
3671 }
3672
3673 src_offset = userdef->flex_offset >> 1;
3674
3675 /* FLX_PIT source offset value is only so large */
3676 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3677 dev_warn(&pf->pdev->dev,
3678 "Flexible data must reside within first 64 bytes of the packet payload\n");
3679 return -EINVAL;
3680 }
3681
3682 /* See if this offset has already been programmed. If we get
3683 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3684 * if we get a NULL pointer, this means we will need to add
3685 * the offset.
3686 */
3687 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3688 src_offset);
3689 if (IS_ERR(flex_pit))
3690 return PTR_ERR(flex_pit);
3691
3692 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3693 * packet types, and thus we need to program both L3 and L4
3694 * flexible values. These must have identical flexible index,
3695 * as otherwise we can't correctly program the input set. So
3696 * we'll find both an L3 and L4 index and make sure they are
3697 * the same.
3698 */
3699 if (flex_l3) {
3700 l3_flex_pit =
3701 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3702 src_offset);
3703 if (IS_ERR(l3_flex_pit))
3704 return PTR_ERR(l3_flex_pit);
3705
3706 if (flex_pit) {
3707 /* If we already had a matching L4 entry, we
3708 * need to make sure that the L3 entry we
3709 * obtained uses the same index.
3710 */
3711 if (l3_flex_pit) {
3712 if (l3_flex_pit->pit_index !=
3713 flex_pit->pit_index) {
3714 return -EINVAL;
3715 }
3716 } else {
3717 new_flex_offset = true;
3718 }
3719 } else {
3720 flex_pit = l3_flex_pit;
3721 }
3722 }
3723
3724 /* If we didn't find an existing flex offset, we need to
3725 * program a new one. However, we don't immediately program it
3726 * here because we will wait to program until after we check
3727 * that it is safe to change the input set.
3728 */
3729 if (!flex_pit) {
3730 new_flex_offset = true;
3731 pit_index = i40e_unused_pit_index(pf);
3732 } else {
3733 pit_index = flex_pit->pit_index;
3734 }
3735
3736 /* Update the mask with the new offset */
3737 new_mask |= i40e_pit_index_to_mask(pit_index);
3738 }
3739
3740 /* If the mask and flexible filter offsets for this filter match the
3741 * currently programmed values we don't need any input set change, so
3742 * this filter is safe to install.
3743 */
3744 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003745 return 0;
3746
3747 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3748 i40e_flow_str(fsp));
3749 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003750 if (new_flex_offset) {
3751 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3752 pit_index, src_offset);
3753 }
Jacob Keller9229e992017-02-06 14:38:47 -08003754
3755 /* Hardware input sets are global across multiple ports, so even the
3756 * main port cannot change them when in MFP mode as this would impact
3757 * any filters on the other ports.
3758 */
3759 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3760 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003761 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003762 }
3763
3764 /* This filter requires us to update the input set. However, hardware
3765 * only supports one input set per flow type, and does not support
3766 * separate masks for each filter. This means that we can only support
3767 * a single mask for all filters of a specific type.
3768 *
3769 * If we have preexisting filters, they obviously depend on the
3770 * current programmed input set. Display a diagnostic message in this
3771 * case explaining why the filter could not be accepted.
3772 */
3773 if (*fdir_filter_count) {
3774 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3775 i40e_flow_str(fsp),
3776 *fdir_filter_count);
3777 return -EOPNOTSUPP;
3778 }
3779
3780 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003781
Jacob Keller0e588de2017-02-06 14:38:50 -08003782 /* Add the new offset and update table, if necessary */
3783 if (new_flex_offset) {
3784 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3785 pit_index);
3786 if (err)
3787 return err;
3788
3789 if (flex_l3) {
3790 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3791 src_offset,
3792 pit_index);
3793 if (err)
3794 return err;
3795 }
3796
3797 i40e_reprogram_flex_pit(pf);
3798 }
3799
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003800 return 0;
3801}
3802
3803/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003804 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003805 * @vsi: pointer to the targeted VSI
3806 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003807 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003808 * Add Flow Director filters for a specific flow spec based on their
3809 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003810 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003811static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3812 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003813{
Jacob Kellere7930952017-02-06 14:38:49 -08003814 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003815 struct ethtool_rx_flow_spec *fsp;
3816 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003817 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003818 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003819 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003820 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003821
3822 if (!vsi)
3823 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003824 pf = vsi->back;
3825
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003826 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3827 return -EOPNOTSUPP;
3828
Jacob Keller47994c12017-04-19 09:25:57 -04003829 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003830 return -ENOSPC;
3831
Jacob Keller0da36b92017-04-19 09:25:55 -04003832 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3833 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003834 return -EBUSY;
3835
Jacob Keller0da36b92017-04-19 09:25:55 -04003836 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003837 return -EBUSY;
3838
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003839 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3840
Jacob Kellere7930952017-02-06 14:38:49 -08003841 /* Parse the user-defined field */
3842 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3843 return -EINVAL;
3844
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003845 /* Extended MAC field is not supported */
3846 if (fsp->flow_type & FLOW_MAC_EXT)
3847 return -EINVAL;
3848
Jacob Keller0e588de2017-02-06 14:38:50 -08003849 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003850 if (ret)
3851 return ret;
3852
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003853 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3854 pf->hw.func_caps.fd_filters_guaranteed)) {
3855 return -EINVAL;
3856 }
3857
Jacob Keller43b15692017-02-06 14:38:48 -08003858 /* ring_cookie is either the drop index, or is a mask of the queue
3859 * index and VF id we wish to target.
3860 */
3861 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3862 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3863 } else {
3864 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3865 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3866
3867 if (!vf) {
3868 if (ring >= vsi->num_queue_pairs)
3869 return -EINVAL;
3870 dest_vsi = vsi->id;
3871 } else {
3872 /* VFs are zero-indexed, so we subtract one here */
3873 vf--;
3874
3875 if (vf >= pf->num_alloc_vfs)
3876 return -EINVAL;
3877 if (ring >= pf->vf[vf].num_queue_pairs)
3878 return -EINVAL;
3879 dest_vsi = pf->vf[vf].lan_vsi_id;
3880 }
3881 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3882 q_index = ring;
3883 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003884
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003885 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003886
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003887 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003888 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003889
3890 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003891 input->q_index = q_index;
3892 input->dest_vsi = dest_vsi;
3893 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003894 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04003895 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08003896 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3897 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08003898 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003899 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00003900
3901 /* Reverse the src and dest notion, since the HW expects them to be from
3902 * Tx perspective where as the input from user is from Rx filter view.
3903 */
3904 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
3905 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08003906 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3907 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003908
Jacob Keller0e588de2017-02-06 14:38:50 -08003909 if (userdef.flex_filter) {
3910 input->flex_filter = true;
3911 input->flex_word = cpu_to_be16(userdef.flex_word);
3912 input->flex_offset = userdef.flex_offset;
3913 }
3914
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003915 ret = i40e_add_del_fdir(vsi, input, true);
3916 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08003917 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003918
Jacob Keller01016da2017-02-06 14:38:40 -08003919 /* Add the input filter to the fdir_input_list, possibly replacing
3920 * a previous filter. Do not free the input structure after adding it
3921 * to the list as this would cause a use-after-free bug.
3922 */
3923 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
3924
3925 return 0;
3926
3927free_input:
3928 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003929 return ret;
3930}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003931
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003932/**
3933 * i40e_set_rxnfc - command to set RX flow classification rules
3934 * @netdev: network interface device structure
3935 * @cmd: ethtool rxnfc command
3936 *
3937 * Returns Success if the command is supported.
3938 **/
3939static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3940{
3941 struct i40e_netdev_priv *np = netdev_priv(netdev);
3942 struct i40e_vsi *vsi = np->vsi;
3943 struct i40e_pf *pf = vsi->back;
3944 int ret = -EOPNOTSUPP;
3945
3946 switch (cmd->cmd) {
3947 case ETHTOOL_SRXFH:
3948 ret = i40e_set_rss_hash_opt(pf, cmd);
3949 break;
3950 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003951 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003952 break;
3953 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003954 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003955 break;
3956 default:
3957 break;
3958 }
3959
3960 return ret;
3961}
3962
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003963/**
3964 * i40e_max_channels - get Max number of combined channels supported
3965 * @vsi: vsi pointer
3966 **/
3967static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
3968{
3969 /* TODO: This code assumes DCB and FD is disabled for now. */
3970 return vsi->alloc_queue_pairs;
3971}
3972
3973/**
3974 * i40e_get_channels - Get the current channels enabled and max supported etc.
3975 * @netdev: network interface device structure
3976 * @ch: ethtool channels structure
3977 *
3978 * We don't support separate tx and rx queues as channels. The other count
3979 * represents how many queues are being used for control. max_combined counts
3980 * how many queue pairs we can support. They may not be mapped 1 to 1 with
3981 * q_vectors since we support a lot more queue pairs than q_vectors.
3982 **/
3983static void i40e_get_channels(struct net_device *dev,
3984 struct ethtool_channels *ch)
3985{
3986 struct i40e_netdev_priv *np = netdev_priv(dev);
3987 struct i40e_vsi *vsi = np->vsi;
3988 struct i40e_pf *pf = vsi->back;
3989
3990 /* report maximum channels */
3991 ch->max_combined = i40e_max_channels(vsi);
3992
3993 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003994 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003995 ch->max_other = ch->other_count;
3996
3997 /* Note: This code assumes DCB is disabled for now. */
3998 ch->combined_count = vsi->num_queue_pairs;
3999}
4000
4001/**
4002 * i40e_set_channels - Set the new channels count.
4003 * @netdev: network interface device structure
4004 * @ch: ethtool channels structure
4005 *
4006 * The new channels count may not be the same as requested by the user
4007 * since it gets rounded down to a power of 2 value.
4008 **/
4009static int i40e_set_channels(struct net_device *dev,
4010 struct ethtool_channels *ch)
4011{
Jacob Keller59826d92016-07-27 12:02:35 -07004012 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004013 struct i40e_netdev_priv *np = netdev_priv(dev);
4014 unsigned int count = ch->combined_count;
4015 struct i40e_vsi *vsi = np->vsi;
4016 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004017 struct i40e_fdir_filter *rule;
4018 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004019 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004020 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004021
4022 /* We do not support setting channels for any other VSI at present */
4023 if (vsi->type != I40E_VSI_MAIN)
4024 return -EINVAL;
4025
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004026 /* We do not support setting channels via ethtool when TCs are
4027 * configured through mqprio
4028 */
4029 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4030 return -EINVAL;
4031
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004032 /* verify they are not requesting separate vectors */
4033 if (!count || ch->rx_count || ch->tx_count)
4034 return -EINVAL;
4035
4036 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004037 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004038 return -EINVAL;
4039
4040 /* verify the number of channels does not exceed hardware limits */
4041 if (count > i40e_max_channels(vsi))
4042 return -EINVAL;
4043
Jacob Keller59826d92016-07-27 12:02:35 -07004044 /* verify that the number of channels does not invalidate any current
4045 * flow director rules
4046 */
4047 hlist_for_each_entry_safe(rule, node2,
4048 &pf->fdir_filter_list, fdir_node) {
4049 if (rule->dest_ctl != drop && count <= rule->q_index) {
4050 dev_warn(&pf->pdev->dev,
4051 "Existing user defined filter %d assigns flow to queue %d\n",
4052 rule->fd_id, rule->q_index);
4053 err = -EINVAL;
4054 }
4055 }
4056
4057 if (err) {
4058 dev_err(&pf->pdev->dev,
4059 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4060 count);
4061 return err;
4062 }
4063
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004064 /* update feature limits from largest to smallest supported values */
4065 /* TODO: Flow director limit, DCB etc */
4066
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004067 /* use rss_reconfig to rebuild with new queue count and update traffic
4068 * class queue mapping
4069 */
4070 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004071 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004072 return 0;
4073 else
4074 return -EINVAL;
4075}
4076
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004077/**
4078 * i40e_get_rxfh_key_size - get the RSS hash key size
4079 * @netdev: network interface device structure
4080 *
4081 * Returns the table size.
4082 **/
4083static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4084{
4085 return I40E_HKEY_ARRAY_SIZE;
4086}
4087
4088/**
4089 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4090 * @netdev: network interface device structure
4091 *
4092 * Returns the table size.
4093 **/
4094static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4095{
4096 return I40E_HLUT_ARRAY_SIZE;
4097}
4098
Alan Brady21675bd2017-10-05 14:53:33 -07004099/**
4100 * i40e_get_rxfh - get the rx flow hash indirection table
4101 * @netdev: network interface device structure
4102 * @indir: indirection table
4103 * @key: hash key
4104 * @hfunc: hash function
4105 *
4106 * Reads the indirection table directly from the hardware. Returns 0 on
4107 * success.
4108 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004109static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4110 u8 *hfunc)
4111{
4112 struct i40e_netdev_priv *np = netdev_priv(netdev);
4113 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004114 u8 *lut, *seed = NULL;
4115 int ret;
4116 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004117
4118 if (hfunc)
4119 *hfunc = ETH_RSS_HASH_TOP;
4120
4121 if (!indir)
4122 return 0;
4123
Helin Zhang043dd652015-10-21 19:56:23 -04004124 seed = key;
4125 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4126 if (!lut)
4127 return -ENOMEM;
4128 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4129 if (ret)
4130 goto out;
4131 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4132 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004133
Helin Zhang043dd652015-10-21 19:56:23 -04004134out:
4135 kfree(lut);
4136
4137 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004138}
4139
4140/**
4141 * i40e_set_rxfh - set the rx flow hash indirection table
4142 * @netdev: network interface device structure
4143 * @indir: indirection table
4144 * @key: hash key
4145 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004146 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004147 * returns 0 after programming the table.
4148 **/
4149static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4150 const u8 *key, const u8 hfunc)
4151{
4152 struct i40e_netdev_priv *np = netdev_priv(netdev);
4153 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004154 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004155 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004156 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004157
4158 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4159 return -EOPNOTSUPP;
4160
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004161 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004162 if (!vsi->rss_hkey_user) {
4163 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4164 GFP_KERNEL);
4165 if (!vsi->rss_hkey_user)
4166 return -ENOMEM;
4167 }
4168 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4169 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004170 }
Helin Zhang28c58692015-10-26 19:44:27 -04004171 if (!vsi->rss_lut_user) {
4172 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4173 if (!vsi->rss_lut_user)
4174 return -ENOMEM;
4175 }
Helin Zhang043dd652015-10-21 19:56:23 -04004176
Helin Zhang28c58692015-10-26 19:44:27 -04004177 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004178 if (indir)
4179 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4180 vsi->rss_lut_user[i] = (u8)(indir[i]);
4181 else
4182 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4183 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004184
4185 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4186 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004187}
4188
Greg Rose7e45ab42015-02-06 08:52:19 +00004189/**
4190 * i40e_get_priv_flags - report device private flags
4191 * @dev: network interface device structure
4192 *
4193 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004194 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004195 * array.
4196 *
4197 * Returns a u32 bitmap of flags.
4198 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004199static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004200{
4201 struct i40e_netdev_priv *np = netdev_priv(dev);
4202 struct i40e_vsi *vsi = np->vsi;
4203 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004204 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004205
Alexander Duyckaca955d2017-03-10 12:22:01 -08004206 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4207 const struct i40e_priv_flags *priv_flags;
4208
4209 priv_flags = &i40e_gstrings_priv_flags[i];
4210
4211 if (priv_flags->flag & pf->flags)
4212 ret_flags |= BIT(i);
4213 }
4214
4215 if (pf->hw.pf_id != 0)
4216 return ret_flags;
4217
4218 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4219 const struct i40e_priv_flags *priv_flags;
4220
4221 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4222
4223 if (priv_flags->flag & pf->flags)
4224 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004225 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004226
4227 return ret_flags;
4228}
4229
Shannon Nelson9ac77262015-08-27 11:42:40 -04004230/**
4231 * i40e_set_priv_flags - set private flags
4232 * @dev: network interface device structure
4233 * @flags: bit flags to be set
4234 **/
4235static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4236{
4237 struct i40e_netdev_priv *np = netdev_priv(dev);
4238 struct i40e_vsi *vsi = np->vsi;
4239 struct i40e_pf *pf = vsi->back;
Jacob Kellerb74f5712017-09-01 13:54:07 -07004240 u32 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004241 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004242
Jacob Keller841c9502017-06-23 04:24:50 -04004243 orig_flags = READ_ONCE(pf->flags);
4244 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004245
Alexander Duyckaca955d2017-03-10 12:22:01 -08004246 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4247 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004248
Alexander Duyckaca955d2017-03-10 12:22:01 -08004249 priv_flags = &i40e_gstrings_priv_flags[i];
4250
Alexander Duyckaca955d2017-03-10 12:22:01 -08004251 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004252 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004253 else
Jacob Keller841c9502017-06-23 04:24:50 -04004254 new_flags &= ~(priv_flags->flag);
4255
4256 /* If this is a read-only flag, it can't be changed */
4257 if (priv_flags->read_only &&
4258 ((orig_flags ^ new_flags) & ~BIT(i)))
4259 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004260 }
4261
4262 if (pf->hw.pf_id != 0)
4263 goto flags_complete;
4264
4265 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4266 const struct i40e_priv_flags *priv_flags;
4267
4268 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4269
Alexander Duyckaca955d2017-03-10 12:22:01 -08004270 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004271 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004272 else
Jacob Keller841c9502017-06-23 04:24:50 -04004273 new_flags &= ~(priv_flags->flag);
4274
4275 /* If this is a read-only flag, it can't be changed */
4276 if (priv_flags->read_only &&
4277 ((orig_flags ^ new_flags) & ~BIT(i)))
4278 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004279 }
4280
4281flags_complete:
Jacob Keller841c9502017-06-23 04:24:50 -04004282 /* Before we finalize any flag changes, we need to perform some
4283 * checks to ensure that the changes are supported and safe.
4284 */
4285
4286 /* ATR eviction is not supported on all devices */
4287 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4288 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4289 return -EOPNOTSUPP;
4290
4291 /* Compare and exchange the new flags into place. If we failed, that
Jacob Kellerb74f5712017-09-01 13:54:07 -07004292 * is if cmpxchg returns anything but the old value, this means that
Jacob Keller841c9502017-06-23 04:24:50 -04004293 * something else has modified the flags variable since we copied it
4294 * originally. We'll just punt with an error and log something in the
4295 * message buffer.
4296 */
Jacob Kellerb74f5712017-09-01 13:54:07 -07004297 if (cmpxchg(&pf->flags, orig_flags, new_flags) != orig_flags) {
Jacob Keller841c9502017-06-23 04:24:50 -04004298 dev_warn(&pf->pdev->dev,
4299 "Unable to update pf->flags as it was modified by another thread...\n");
4300 return -EAGAIN;
4301 }
4302
4303 changed_flags = orig_flags ^ new_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004304
4305 /* Process any additional changes needed as a result of flag changes.
4306 * The changed_flags value reflects the list of bits that were
4307 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004308 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004309
Alexander Duyckaca955d2017-03-10 12:22:01 -08004310 /* Flush current ATR settings if ATR was disabled */
4311 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4312 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004313 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004314 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004315 }
4316
Alexander Duyckaca955d2017-03-10 12:22:01 -08004317 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4318 u16 sw_flags = 0, valid_flags = 0;
4319 int ret;
4320
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004321 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4322 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4323 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4324 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4325 NULL);
4326 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4327 dev_info(&pf->pdev->dev,
4328 "couldn't set switch config bits, err %s aq_err %s\n",
4329 i40e_stat_str(&pf->hw, ret),
4330 i40e_aq_str(&pf->hw,
4331 pf->hw.aq.asq_last_status));
4332 /* not a fatal problem, just keep going */
4333 }
4334 }
4335
Alexander Duyckaca955d2017-03-10 12:22:01 -08004336 /* Issue reset to cause things to take effect, as additional bits
4337 * are added we will need to create a mask of bits requiring reset
4338 */
Mitch Williams64615b52017-08-29 05:32:30 -04004339 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4340 I40E_FLAG_LEGACY_RX |
4341 I40E_FLAG_SOURCE_PRUNING_DISABLED))
Maciej Sosin373149f2017-04-05 07:50:55 -04004342 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004343
Shannon Nelson9ac77262015-08-27 11:42:40 -04004344 return 0;
4345}
4346
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004347/**
4348 * i40e_get_module_info - get (Q)SFP+ module type info
4349 * @netdev: network interface device structure
4350 * @modinfo: module EEPROM size and layout information structure
4351 **/
4352static int i40e_get_module_info(struct net_device *netdev,
4353 struct ethtool_modinfo *modinfo)
4354{
4355 struct i40e_netdev_priv *np = netdev_priv(netdev);
4356 struct i40e_vsi *vsi = np->vsi;
4357 struct i40e_pf *pf = vsi->back;
4358 struct i40e_hw *hw = &pf->hw;
4359 u32 sff8472_comp = 0;
4360 u32 sff8472_swap = 0;
4361 u32 sff8636_rev = 0;
4362 i40e_status status;
4363 u32 type = 0;
4364
4365 /* Check if firmware supports reading module EEPROM. */
4366 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4367 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4368 return -EINVAL;
4369 }
4370
4371 status = i40e_update_link_info(hw);
4372 if (status)
4373 return -EIO;
4374
4375 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4376 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4377 return -EINVAL;
4378 }
4379
4380 type = hw->phy.link_info.module_type[0];
4381
4382 switch (type) {
4383 case I40E_MODULE_TYPE_SFP:
4384 status = i40e_aq_get_phy_register(hw,
4385 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4386 I40E_I2C_EEPROM_DEV_ADDR,
4387 I40E_MODULE_SFF_8472_COMP,
4388 &sff8472_comp, NULL);
4389 if (status)
4390 return -EIO;
4391
4392 status = i40e_aq_get_phy_register(hw,
4393 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4394 I40E_I2C_EEPROM_DEV_ADDR,
4395 I40E_MODULE_SFF_8472_SWAP,
4396 &sff8472_swap, NULL);
4397 if (status)
4398 return -EIO;
4399
4400 /* Check if the module requires address swap to access
4401 * the other EEPROM memory page.
4402 */
4403 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4404 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4405 modinfo->type = ETH_MODULE_SFF_8079;
4406 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4407 } else if (sff8472_comp == 0x00) {
4408 /* Module is not SFF-8472 compliant */
4409 modinfo->type = ETH_MODULE_SFF_8079;
4410 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4411 } else {
4412 modinfo->type = ETH_MODULE_SFF_8472;
4413 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4414 }
4415 break;
4416 case I40E_MODULE_TYPE_QSFP_PLUS:
4417 /* Read from memory page 0. */
4418 status = i40e_aq_get_phy_register(hw,
4419 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4420 0,
4421 I40E_MODULE_REVISION_ADDR,
4422 &sff8636_rev, NULL);
4423 if (status)
4424 return -EIO;
4425 /* Determine revision compliance byte */
4426 if (sff8636_rev > 0x02) {
4427 /* Module is SFF-8636 compliant */
4428 modinfo->type = ETH_MODULE_SFF_8636;
4429 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4430 } else {
4431 modinfo->type = ETH_MODULE_SFF_8436;
4432 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4433 }
4434 break;
4435 case I40E_MODULE_TYPE_QSFP28:
4436 modinfo->type = ETH_MODULE_SFF_8636;
4437 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4438 break;
4439 default:
4440 netdev_err(vsi->netdev, "Module type unrecognized\n");
4441 return -EINVAL;
4442 }
4443 return 0;
4444}
4445
4446/**
4447 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4448 * @netdev: network interface device structure
4449 * @ee: EEPROM dump request structure
4450 * @data: buffer to be filled with EEPROM contents
4451 **/
4452static int i40e_get_module_eeprom(struct net_device *netdev,
4453 struct ethtool_eeprom *ee,
4454 u8 *data)
4455{
4456 struct i40e_netdev_priv *np = netdev_priv(netdev);
4457 struct i40e_vsi *vsi = np->vsi;
4458 struct i40e_pf *pf = vsi->back;
4459 struct i40e_hw *hw = &pf->hw;
4460 bool is_sfp = false;
4461 i40e_status status;
4462 u32 value = 0;
4463 int i;
4464
4465 if (!ee || !ee->len || !data)
4466 return -EINVAL;
4467
4468 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4469 is_sfp = true;
4470
4471 for (i = 0; i < ee->len; i++) {
4472 u32 offset = i + ee->offset;
4473 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4474
4475 /* Check if we need to access the other memory page */
4476 if (is_sfp) {
4477 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4478 offset -= ETH_MODULE_SFF_8079_LEN;
4479 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4480 }
4481 } else {
4482 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4483 /* Compute memory page number and offset. */
4484 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4485 addr++;
4486 }
4487 }
4488
4489 status = i40e_aq_get_phy_register(hw,
4490 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4491 addr, offset, &value, NULL);
4492 if (status)
4493 return -EIO;
4494 data[i] = value;
4495 }
4496 return 0;
4497}
4498
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004499static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004500 .get_drvinfo = i40e_get_drvinfo,
4501 .get_regs_len = i40e_get_regs_len,
4502 .get_regs = i40e_get_regs,
4503 .nway_reset = i40e_nway_reset,
4504 .get_link = ethtool_op_get_link,
4505 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004506 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004507 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004508 .get_eeprom_len = i40e_get_eeprom_len,
4509 .get_eeprom = i40e_get_eeprom,
4510 .get_ringparam = i40e_get_ringparam,
4511 .set_ringparam = i40e_set_ringparam,
4512 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004513 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004514 .get_msglevel = i40e_get_msglevel,
4515 .set_msglevel = i40e_set_msglevel,
4516 .get_rxnfc = i40e_get_rxnfc,
4517 .set_rxnfc = i40e_set_rxnfc,
4518 .self_test = i40e_diag_test,
4519 .get_strings = i40e_get_strings,
4520 .set_phys_id = i40e_set_phys_id,
4521 .get_sset_count = i40e_get_sset_count,
4522 .get_ethtool_stats = i40e_get_ethtool_stats,
4523 .get_coalesce = i40e_get_coalesce,
4524 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004525 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4526 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4527 .get_rxfh = i40e_get_rxfh,
4528 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004529 .get_channels = i40e_get_channels,
4530 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004531 .get_module_info = i40e_get_module_info,
4532 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004533 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004534 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004535 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004536 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004537 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004538 .get_link_ksettings = i40e_get_link_ksettings,
4539 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004540};
4541
4542void i40e_set_ethtool_ops(struct net_device *netdev)
4543{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004544 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004545}