blob: 0cef8aa85c1da9de1b9e5bfafef5b4b61ec063ba [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;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100477 u32 supported, advertising;
478
479 ethtool_convert_link_mode_to_legacy_u32(&supported,
Alan Brady1c142e12017-10-05 14:53:31 -0700480 ks->link_modes.supported);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100481 ethtool_convert_link_mode_to_legacy_u32(&advertising,
Alan Brady1c142e12017-10-05 14:53:31 -0700482 ks->link_modes.advertising);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483
Catherine Sullivane8278452015-02-06 08:52:08 +0000484 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485 switch (hw_link_info->phy_type) {
486 case I40E_PHY_TYPE_40GBASE_CR4:
487 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100488 supported = SUPPORTED_Autoneg |
489 SUPPORTED_40000baseCR4_Full;
490 advertising = ADVERTISED_Autoneg |
491 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000492 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000493 case I40E_PHY_TYPE_XLAUI:
494 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000495 case I40E_PHY_TYPE_40GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100496 supported = SUPPORTED_40000baseCR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000497 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 case I40E_PHY_TYPE_40GBASE_SR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100499 supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000500 break;
501 case I40E_PHY_TYPE_40GBASE_LR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100502 supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000503 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000504 case I40E_PHY_TYPE_10GBASE_SR:
505 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000506 case I40E_PHY_TYPE_1000BASE_SX:
507 case I40E_PHY_TYPE_1000BASE_LX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100508 supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400509 if (hw_link_info->module_type[2] &
510 I40E_MODULE_TYPE_1000BASE_SX ||
511 hw_link_info->module_type[2] &
512 I40E_MODULE_TYPE_1000BASE_LX) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100513 supported |= SUPPORTED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400514 if (hw_link_info->requested_speeds &
515 I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100516 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400517 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000518 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100519 advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000520 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000521 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000522 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700523 case I40E_PHY_TYPE_100BASE_TX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100524 supported = SUPPORTED_Autoneg |
525 SUPPORTED_10000baseT_Full |
526 SUPPORTED_1000baseT_Full |
527 SUPPORTED_100baseT_Full;
528 advertising = ADVERTISED_Autoneg;
Catherine Sullivane8278452015-02-06 08:52:08 +0000529 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100530 advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000531 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100532 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700533 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100534 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400535 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400536 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100537 supported = SUPPORTED_Autoneg |
538 SUPPORTED_1000baseT_Full;
539 advertising = ADVERTISED_Autoneg |
540 ADVERTISED_1000baseT_Full;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400541 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000542 case I40E_PHY_TYPE_10GBASE_CR1_CU:
543 case I40E_PHY_TYPE_10GBASE_CR1:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100544 supported = SUPPORTED_Autoneg |
545 SUPPORTED_10000baseT_Full;
546 advertising = ADVERTISED_Autoneg |
547 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000548 break;
549 case I40E_PHY_TYPE_XAUI:
550 case I40E_PHY_TYPE_XFI:
551 case I40E_PHY_TYPE_SFI:
552 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000553 case I40E_PHY_TYPE_10GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100554 supported = SUPPORTED_10000baseT_Full;
555 advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000556 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000557 case I40E_PHY_TYPE_SGMII:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100558 supported = SUPPORTED_Autoneg |
559 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000560 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100561 advertising |= ADVERTISED_1000baseT_Full;
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400562 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100563 supported |= SUPPORTED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400564 if (hw_link_info->requested_speeds &
565 I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100566 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400567 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000568 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400569 case I40E_PHY_TYPE_40GBASE_KR4:
570 case I40E_PHY_TYPE_20GBASE_KR2:
571 case I40E_PHY_TYPE_10GBASE_KR:
572 case I40E_PHY_TYPE_10GBASE_KX4:
573 case I40E_PHY_TYPE_1000BASE_KX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100574 supported |= SUPPORTED_40000baseKR4_Full |
575 SUPPORTED_20000baseKR2_Full |
576 SUPPORTED_10000baseKR_Full |
577 SUPPORTED_10000baseKX4_Full |
578 SUPPORTED_1000baseKX_Full |
579 SUPPORTED_Autoneg;
580 advertising |= ADVERTISED_40000baseKR4_Full |
581 ADVERTISED_20000baseKR2_Full |
582 ADVERTISED_10000baseKR_Full |
583 ADVERTISED_10000baseKX4_Full |
584 ADVERTISED_1000baseKX_Full |
585 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400586 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800587 case I40E_PHY_TYPE_25GBASE_KR:
588 case I40E_PHY_TYPE_25GBASE_CR:
589 case I40E_PHY_TYPE_25GBASE_SR:
590 case I40E_PHY_TYPE_25GBASE_LR:
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700591 case I40E_PHY_TYPE_25GBASE_AOC:
592 case I40E_PHY_TYPE_25GBASE_ACC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100593 supported = SUPPORTED_Autoneg;
594 advertising = ADVERTISED_Autoneg;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800595 /* TODO: add speeds when ethtool is ready to support*/
596 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000597 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000598 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700599 netdev_info(netdev,
600 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000601 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000602 }
603
Catherine Sullivan06566e52016-05-03 15:13:14 -0700604 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700605 * current PHY type, get what is supported by the NVM and intersect
606 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700607 */
Alan Brady1eaae512017-10-05 14:53:41 -0700608 ethtool_convert_legacy_u32_to_link_mode(ks->link_modes.supported,
609 supported);
610 ethtool_convert_legacy_u32_to_link_mode(ks->link_modes.advertising,
611 advertising);
612 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
613 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
614 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700615
Catherine Sullivane8278452015-02-06 08:52:08 +0000616 /* Set speed and duplex */
617 switch (link_speed) {
618 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700619 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000620 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800621 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700622 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800623 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700624 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700625 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700626 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000627 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700628 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000629 break;
630 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700631 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000632 break;
633 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700634 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000635 break;
636 default:
637 break;
638 }
Alan Brady1c142e12017-10-05 14:53:31 -0700639 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000640}
641
642/**
643 * i40e_get_settings_link_down - Get the Link settings for when link is down
644 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700645 * @ks: ethtool ksettings to fill in
646 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000647 *
648 * Reports link settings that can be determined when link is down
649 **/
650static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700651 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400652 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000653{
Catherine Sullivane8278452015-02-06 08:52:08 +0000654 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400655 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000656 */
Alan Brady1eaae512017-10-05 14:53:41 -0700657 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000658
659 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700660 ks->base.speed = SPEED_UNKNOWN;
661 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000662}
663
664/**
Alan Brady1c142e12017-10-05 14:53:31 -0700665 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000666 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700667 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000668 *
669 * Reports speed/duplex settings based on media_type
670 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100671static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700672 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000673{
674 struct i40e_netdev_priv *np = netdev_priv(netdev);
675 struct i40e_pf *pf = np->vsi->back;
676 struct i40e_hw *hw = &pf->hw;
677 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
678 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700679
680 ethtool_link_ksettings_zero_link_mode(ks, supported);
681 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000682
683 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700684 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000685 else
Alan Brady1c142e12017-10-05 14:53:31 -0700686 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000687
688 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000689 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700690 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
691 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000692
Alan Bradya03af692017-10-05 14:53:37 -0700693 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000694 switch (hw->phy.media_type) {
695 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700696 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
697 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
698 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700699 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100700 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700701 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000702 break;
703 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700704 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
705 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
706 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000707 break;
708 case I40E_MEDIA_TYPE_DA:
709 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700710 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
711 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
712 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000713 break;
714 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700715 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
716 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000717 break;
718 case I40E_MEDIA_TYPE_UNKNOWN:
719 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700720 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000721 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000722 }
723
Catherine Sullivane8278452015-02-06 08:52:08 +0000724 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700725 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000726
Catherine Sullivane8278452015-02-06 08:52:08 +0000727 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000728 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700729 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000730 break;
731 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700732 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100733 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000734 break;
735 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700736 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700737 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100738 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000739 break;
740 default:
Alan Brady5f434992017-10-05 14:53:34 -0700741 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
742 ethtool_link_ksettings_del_link_mode(ks, advertising,
743 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000744 break;
745 }
746
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000747 return 0;
748}
749
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750/**
Alan Brady1c142e12017-10-05 14:53:31 -0700751 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000752 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700753 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000754 *
755 * Set speed/duplex per media_types advertised/forced
756 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100757static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700758 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000759{
760 struct i40e_netdev_priv *np = netdev_priv(netdev);
761 struct i40e_aq_get_phy_abilities_resp abilities;
762 struct i40e_aq_set_phy_config config;
763 struct i40e_pf *pf = np->vsi->back;
764 struct i40e_vsi *vsi = np->vsi;
765 struct i40e_hw *hw = &pf->hw;
Alan Brady1c142e12017-10-05 14:53:31 -0700766 struct ethtool_link_ksettings safe_ks;
767 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000768 i40e_status status = 0;
769 bool change = false;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400770 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000771 int err = 0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100772 u32 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000773 u32 advertise;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100774 u32 tmp;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000775
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000776 /* Changing port settings is not supported if this isn't the
777 * port's controlling PF
778 */
779 if (hw->partition_id != 1) {
780 i40e_partition_setting_complaint(pf);
781 return -EOPNOTSUPP;
782 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000783 if (vsi != pf->vsi[pf->lan_vsi])
784 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000785 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
786 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000787 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700788 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000789 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000790 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400791 if (hw->device_id == I40E_DEV_ID_KX_B ||
792 hw->device_id == I40E_DEV_ID_KX_C ||
793 hw->device_id == I40E_DEV_ID_20G_KR2 ||
794 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
795 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
796 return -EOPNOTSUPP;
797 }
798
Alan Brady1c142e12017-10-05 14:53:31 -0700799 /* copy the ksettings to copy_ks to avoid modifying the origin */
800 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000801
Philippe Reynesa7f90942017-02-04 22:05:06 +0100802 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700803 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
804 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100805
Alan Brady1c142e12017-10-05 14:53:31 -0700806 /* save autoneg and speed out of ksettings */
807 autoneg = ks->base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100808 ethtool_convert_link_mode_to_legacy_u32(&advertise,
Alan Brady1c142e12017-10-05 14:53:31 -0700809 ks->link_modes.advertising);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000810
811 /* set autoneg and speed back to what they currently are */
Alan Brady1c142e12017-10-05 14:53:31 -0700812 copy_ks.base.autoneg = safe_ks.base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100813 ethtool_convert_link_mode_to_legacy_u32(
Alan Brady1c142e12017-10-05 14:53:31 -0700814 &tmp, safe_ks.link_modes.advertising);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100815 ethtool_convert_legacy_u32_to_link_mode(
Alan Brady1c142e12017-10-05 14:53:31 -0700816 copy_ks.link_modes.advertising, tmp);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000817
Alan Brady1c142e12017-10-05 14:53:31 -0700818 copy_ks.base.cmd = safe_ks.base.cmd;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100819
Alan Brady1c142e12017-10-05 14:53:31 -0700820 /* If copy_ks and safe_ks are not the same now, then they are
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000821 * trying to set something that we do not support
822 */
Alan Brady1c142e12017-10-05 14:53:31 -0700823 if (memcmp(&copy_ks, &safe_ks, sizeof(struct ethtool_link_ksettings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000824 return -EOPNOTSUPP;
825
Jacob Keller0da36b92017-04-19 09:25:55 -0400826 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400827 timeout--;
828 if (!timeout)
829 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000830 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400831 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000832
833 /* Get the current phy config */
834 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
835 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400836 if (status) {
837 err = -EAGAIN;
838 goto done;
839 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000840
Catherine Sullivan124ed152014-07-12 07:28:12 +0000841 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000842 * set below
843 */
844 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000845 config.abilities = abilities.abilities;
846
847 /* Check autoneg */
848 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000849 /* If autoneg was not already enabled */
850 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400851 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700852 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
853 supported,
854 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400855 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400856 err = -EINVAL;
857 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400858 }
859 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000860 config.abilities = abilities.abilities |
861 I40E_AQ_PHY_ENABLE_AN;
862 change = true;
863 }
864 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000865 /* If autoneg is currently enabled */
866 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400867 /* If autoneg is supported 10GBASE_T is the only PHY
868 * that can disable it, so otherwise return error
869 */
Alan Brady1c142e12017-10-05 14:53:31 -0700870 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
871 supported,
872 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400873 hw->phy.link_info.phy_type !=
874 I40E_PHY_TYPE_10GBASE_T) {
875 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400876 err = -EINVAL;
877 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400878 }
879 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000880 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000881 ~I40E_AQ_PHY_ENABLE_AN;
882 change = true;
883 }
884 }
885
Philippe Reynesa7f90942017-02-04 22:05:06 +0100886 ethtool_convert_link_mode_to_legacy_u32(&tmp,
Alan Brady1c142e12017-10-05 14:53:31 -0700887 safe_ks.link_modes.supported);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400888 if (advertise & ~tmp) {
889 err = -EINVAL;
890 goto done;
891 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000892
893 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000894 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000895 if (advertise & ADVERTISED_1000baseT_Full ||
896 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000897 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000898 if (advertise & ADVERTISED_10000baseT_Full ||
899 advertise & ADVERTISED_10000baseKX4_Full ||
900 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000901 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700902 if (advertise & ADVERTISED_20000baseKR2_Full)
903 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000904 if (advertise & ADVERTISED_40000baseKR4_Full ||
905 advertise & ADVERTISED_40000baseCR4_Full ||
906 advertise & ADVERTISED_40000baseSR4_Full ||
907 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000908 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000909
Catherine Sullivan0002e112015-08-26 15:14:16 -0400910 /* If speed didn't get set, set it to what it currently is.
911 * This is needed because if advertise is 0 (as it is when autoneg
912 * is disabled) then speed won't get set.
913 */
914 if (!config.link_speed)
915 config.link_speed = abilities.link_speed;
Catherine Sullivan124ed152014-07-12 07:28:12 +0000916 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000917 /* copy over the rest of the abilities */
918 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800919 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000920 config.eee_capability = abilities.eee_capability;
921 config.eeer = abilities.eeer_val;
922 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800923 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
924 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000925
Catherine Sullivane8278452015-02-06 08:52:08 +0000926 /* save the requested speeds */
927 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000928 /* set link and auto negotiation so changes take effect */
929 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
930 /* If link is up put link down */
931 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
932 /* Tell the OS link is going down, the link will go
933 * back up when fw says it is ready asynchronously
934 */
Matt Jaredc156f852015-08-27 11:42:39 -0400935 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000936 netif_carrier_off(netdev);
937 netif_tx_stop_all_queues(netdev);
938 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000939
940 /* make the aq call */
941 status = i40e_aq_set_phy_config(hw, &config, NULL);
942 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -0700943 netdev_info(netdev,
944 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400945 i40e_stat_str(hw, status),
946 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400947 err = -EAGAIN;
948 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000949 }
950
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400951 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000952 if (status)
Alan Bradya03af692017-10-05 14:53:37 -0700953 netdev_dbg(netdev,
954 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -0400955 i40e_stat_str(hw, status),
956 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000957
958 } else {
959 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
960 }
961
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400962done:
Jacob Keller0da36b92017-04-19 09:25:55 -0400963 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400964
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000965 return err;
966}
967
Jesse Brandeburga6599722014-06-04 08:45:25 +0000968static int i40e_nway_reset(struct net_device *netdev)
969{
970 /* restart autonegotiation */
971 struct i40e_netdev_priv *np = netdev_priv(netdev);
972 struct i40e_pf *pf = np->vsi->back;
973 struct i40e_hw *hw = &pf->hw;
974 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
975 i40e_status ret = 0;
976
977 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
978 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400979 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
980 i40e_stat_str(hw, ret),
981 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000982 return -EIO;
983 }
984
985 return 0;
986}
987
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000988/**
989 * i40e_get_pauseparam - Get Flow Control status
990 * Return tx/rx-pause status
991 **/
992static void i40e_get_pauseparam(struct net_device *netdev,
993 struct ethtool_pauseparam *pause)
994{
995 struct i40e_netdev_priv *np = netdev_priv(netdev);
996 struct i40e_pf *pf = np->vsi->back;
997 struct i40e_hw *hw = &pf->hw;
998 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000999 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001000
1001 pause->autoneg =
1002 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1003 AUTONEG_ENABLE : AUTONEG_DISABLE);
1004
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001005 /* PFC enabled so report LFC as off */
1006 if (dcbx_cfg->pfc.pfcenable) {
1007 pause->rx_pause = 0;
1008 pause->tx_pause = 0;
1009 return;
1010 }
1011
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001012 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001013 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001014 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001015 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001016 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1017 pause->rx_pause = 1;
1018 pause->tx_pause = 1;
1019 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001020}
1021
Catherine Sullivan2becc352014-06-04 08:45:27 +00001022/**
1023 * i40e_set_pauseparam - Set Flow Control parameter
1024 * @netdev: network interface device structure
1025 * @pause: return tx/rx flow control status
1026 **/
1027static int i40e_set_pauseparam(struct net_device *netdev,
1028 struct ethtool_pauseparam *pause)
1029{
1030 struct i40e_netdev_priv *np = netdev_priv(netdev);
1031 struct i40e_pf *pf = np->vsi->back;
1032 struct i40e_vsi *vsi = np->vsi;
1033 struct i40e_hw *hw = &pf->hw;
1034 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001035 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001036 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1037 i40e_status status;
1038 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001039 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001040
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001041 /* Changing the port's flow control is not supported if this isn't the
1042 * port's controlling PF
1043 */
1044 if (hw->partition_id != 1) {
1045 i40e_partition_setting_complaint(pf);
1046 return -EOPNOTSUPP;
1047 }
1048
Catherine Sullivan2becc352014-06-04 08:45:27 +00001049 if (vsi != pf->vsi[pf->lan_vsi])
1050 return -EOPNOTSUPP;
1051
1052 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1053 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1054 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1055 return -EOPNOTSUPP;
1056 }
1057
1058 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001059 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001060 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1061 /* Send message that it might not necessarily work*/
1062 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1063 }
1064
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001065 if (dcbx_cfg->pfc.pfcenable) {
1066 netdev_info(netdev,
1067 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001068 return -EOPNOTSUPP;
1069 }
1070
1071 if (pause->rx_pause && pause->tx_pause)
1072 hw->fc.requested_mode = I40E_FC_FULL;
1073 else if (pause->rx_pause && !pause->tx_pause)
1074 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1075 else if (!pause->rx_pause && pause->tx_pause)
1076 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1077 else if (!pause->rx_pause && !pause->tx_pause)
1078 hw->fc.requested_mode = I40E_FC_NONE;
1079 else
1080 return -EINVAL;
1081
Catherine Sullivan94128512014-07-12 07:28:16 +00001082 /* Tell the OS link is going down, the link will go back up when fw
1083 * says it is ready asynchronously
1084 */
Matt Jaredc156f852015-08-27 11:42:39 -04001085 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001086 netif_carrier_off(netdev);
1087 netif_tx_stop_all_queues(netdev);
1088
Catherine Sullivan2becc352014-06-04 08:45:27 +00001089 /* Set the fc mode and only restart an if link is up*/
1090 status = i40e_set_fc(hw, &aq_failures, link_up);
1091
1092 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001093 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1094 i40e_stat_str(hw, status),
1095 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001096 err = -EAGAIN;
1097 }
1098 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001099 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1100 i40e_stat_str(hw, status),
1101 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001102 err = -EAGAIN;
1103 }
1104 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001105 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1106 i40e_stat_str(hw, status),
1107 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001108 err = -EAGAIN;
1109 }
1110
Jacob Keller0da36b92017-04-19 09:25:55 -04001111 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001112 /* Give it a little more time to try to come back */
1113 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001114 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001115 return i40e_nway_reset(netdev);
1116 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001117
1118 return err;
1119}
1120
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001121static u32 i40e_get_msglevel(struct net_device *netdev)
1122{
1123 struct i40e_netdev_priv *np = netdev_priv(netdev);
1124 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001125 u32 debug_mask = pf->hw.debug_mask;
1126
1127 if (debug_mask)
1128 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001129
1130 return pf->msg_enable;
1131}
1132
1133static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1134{
1135 struct i40e_netdev_priv *np = netdev_priv(netdev);
1136 struct i40e_pf *pf = np->vsi->back;
1137
1138 if (I40E_DEBUG_USER & data)
1139 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001140 else
1141 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001142}
1143
1144static int i40e_get_regs_len(struct net_device *netdev)
1145{
1146 int reg_count = 0;
1147 int i;
1148
1149 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1150 reg_count += i40e_reg_list[i].elements;
1151
1152 return reg_count * sizeof(u32);
1153}
1154
1155static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1156 void *p)
1157{
1158 struct i40e_netdev_priv *np = netdev_priv(netdev);
1159 struct i40e_pf *pf = np->vsi->back;
1160 struct i40e_hw *hw = &pf->hw;
1161 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001162 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001163 u32 reg;
1164
1165 /* Tell ethtool which driver-version-specific regs output we have.
1166 *
1167 * At some point, if we have ethtool doing special formatting of
1168 * this data, it will rely on this version number to know how to
1169 * interpret things. Hence, this needs to be updated if/when the
1170 * diags register table is changed.
1171 */
1172 regs->version = 1;
1173
1174 /* loop through the diags reg table for what to print */
1175 ri = 0;
1176 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1177 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1178 reg = i40e_reg_list[i].offset
1179 + (j * i40e_reg_list[i].stride);
1180 reg_buf[ri++] = rd32(hw, reg);
1181 }
1182 }
1183
1184}
1185
1186static int i40e_get_eeprom(struct net_device *netdev,
1187 struct ethtool_eeprom *eeprom, u8 *bytes)
1188{
1189 struct i40e_netdev_priv *np = netdev_priv(netdev);
1190 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001191 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001192 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001193 u8 *eeprom_buff;
1194 u16 i, sectors;
1195 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001196 u32 magic;
1197
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001198#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001199 if (eeprom->len == 0)
1200 return -EINVAL;
1201
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001202 /* check for NVMUpdate access method */
1203 magic = hw->vendor_id | (hw->device_id << 16);
1204 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001205 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1206 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001207
1208 /* make sure it is the right magic for NVMUpdate */
1209 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001210 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001211 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1212 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001213 errno = -EBUSY;
1214 else
1215 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001216
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001217 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001218 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001219 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1220 ret_val, hw->aq.asq_last_status, errno,
1221 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1222 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001223
1224 return errno;
1225 }
1226
1227 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001228 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1229
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001230 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001231 if (!eeprom_buff)
1232 return -ENOMEM;
1233
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001234 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1235 if (ret_val) {
1236 dev_info(&pf->pdev->dev,
1237 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1238 ret_val, hw->aq.asq_last_status);
1239 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001240 }
1241
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001242 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1243 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1244 len = I40E_NVM_SECTOR_SIZE;
1245 last = false;
1246 for (i = 0; i < sectors; i++) {
1247 if (i == (sectors - 1)) {
1248 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1249 last = true;
1250 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001251 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1252 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001253 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001254 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001255 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001256 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001257 "read NVM failed, invalid offset 0x%x\n",
1258 offset);
1259 break;
1260 } else if (ret_val &&
1261 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1262 dev_info(&pf->pdev->dev,
1263 "read NVM failed, access, offset 0x%x\n",
1264 offset);
1265 break;
1266 } else if (ret_val) {
1267 dev_info(&pf->pdev->dev,
1268 "read NVM failed offset %d err=%d status=0x%x\n",
1269 offset, ret_val, hw->aq.asq_last_status);
1270 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001271 }
1272 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001273
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001274 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001275 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001276free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001278 return ret_val;
1279}
1280
1281static int i40e_get_eeprom_len(struct net_device *netdev)
1282{
1283 struct i40e_netdev_priv *np = netdev_priv(netdev);
1284 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001285 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001286
Lihong Yangc271dd62017-01-30 12:29:32 -08001287#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1288 if (hw->mac.type == I40E_MAC_X722) {
1289 val = X722_EEPROM_SCOPE_LIMIT + 1;
1290 return val;
1291 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001292 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1293 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1294 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1295 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001296 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001297 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001298}
1299
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001300static int i40e_set_eeprom(struct net_device *netdev,
1301 struct ethtool_eeprom *eeprom, u8 *bytes)
1302{
1303 struct i40e_netdev_priv *np = netdev_priv(netdev);
1304 struct i40e_hw *hw = &np->vsi->back->hw;
1305 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001306 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001307 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001308 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001309 u32 magic;
1310
1311 /* normal ethtool set_eeprom is not supported */
1312 magic = hw->vendor_id | (hw->device_id << 16);
1313 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001314 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001315 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001316 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1317 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001318 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1319 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001320 errno = -EBUSY;
1321 else
1322 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001323
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001324 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001325 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001326 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1327 ret_val, hw->aq.asq_last_status, errno,
1328 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1329 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001330
1331 return errno;
1332}
1333
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001334static void i40e_get_drvinfo(struct net_device *netdev,
1335 struct ethtool_drvinfo *drvinfo)
1336{
1337 struct i40e_netdev_priv *np = netdev_priv(netdev);
1338 struct i40e_vsi *vsi = np->vsi;
1339 struct i40e_pf *pf = vsi->back;
1340
1341 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1342 strlcpy(drvinfo->version, i40e_driver_version_str,
1343 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001344 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001345 sizeof(drvinfo->fw_version));
1346 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1347 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001348 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001349 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001350 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001351}
1352
1353static void i40e_get_ringparam(struct net_device *netdev,
1354 struct ethtool_ringparam *ring)
1355{
1356 struct i40e_netdev_priv *np = netdev_priv(netdev);
1357 struct i40e_pf *pf = np->vsi->back;
1358 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1359
1360 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1361 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1362 ring->rx_mini_max_pending = 0;
1363 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001364 ring->rx_pending = vsi->rx_rings[0]->count;
1365 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001366 ring->rx_mini_pending = 0;
1367 ring->rx_jumbo_pending = 0;
1368}
1369
Björn Töpel74608d12017-05-24 07:55:35 +02001370static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1371{
1372 if (i40e_enabled_xdp_vsi(vsi)) {
1373 return index < vsi->num_queue_pairs ||
1374 (index >= vsi->alloc_queue_pairs &&
1375 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1376 }
1377
1378 return index < vsi->num_queue_pairs;
1379}
1380
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001381static int i40e_set_ringparam(struct net_device *netdev,
1382 struct ethtool_ringparam *ring)
1383{
1384 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1385 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001386 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001387 struct i40e_vsi *vsi = np->vsi;
1388 struct i40e_pf *pf = vsi->back;
1389 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001390 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001391 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392 int i, err = 0;
1393
1394 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1395 return -EINVAL;
1396
Shannon Nelson1fa18372013-11-20 10:03:08 +00001397 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1398 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1399 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1400 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1401 netdev_info(netdev,
1402 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1403 ring->tx_pending, ring->rx_pending,
1404 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1405 return -EINVAL;
1406 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001407
Shannon Nelson1fa18372013-11-20 10:03:08 +00001408 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1409 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001410
1411 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001412 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1413 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001414 return 0;
1415
Jacob Keller0da36b92017-04-19 09:25:55 -04001416 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001417 timeout--;
1418 if (!timeout)
1419 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001421 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001422
1423 if (!netif_running(vsi->netdev)) {
1424 /* simple case - set for the next time the netdev is started */
1425 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001426 vsi->tx_rings[i]->count = new_tx_count;
1427 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001428 if (i40e_enabled_xdp_vsi(vsi))
1429 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001430 }
1431 goto done;
1432 }
1433
1434 /* We can't just free everything and then setup again,
1435 * because the ISRs in MSI-X mode get passed pointers
1436 * to the Tx and Rx ring structs.
1437 */
1438
Björn Töpel74608d12017-05-24 07:55:35 +02001439 /* alloc updated Tx and XDP Tx resources */
1440 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1441 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001442 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001443 netdev_info(netdev,
1444 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001445 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001446 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001447 sizeof(struct i40e_ring), GFP_KERNEL);
1448 if (!tx_rings) {
1449 err = -ENOMEM;
1450 goto done;
1451 }
1452
Björn Töpel74608d12017-05-24 07:55:35 +02001453 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1454 if (!i40e_active_tx_ring_index(vsi, i))
1455 continue;
1456
Alexander Duyck9f65e152013-09-28 06:00:58 +00001457 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001458 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001459 /* the desc and bi pointers will be reallocated in the
1460 * setup call
1461 */
1462 tx_rings[i].desc = NULL;
1463 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001464 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1465 if (err) {
1466 while (i) {
1467 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001468 if (!i40e_active_tx_ring_index(vsi, i))
1469 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470 i40e_free_tx_resources(&tx_rings[i]);
1471 }
1472 kfree(tx_rings);
1473 tx_rings = NULL;
1474
1475 goto done;
1476 }
1477 }
1478 }
1479
1480 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001481 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 netdev_info(netdev,
1483 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001484 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001485 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1486 sizeof(struct i40e_ring), GFP_KERNEL);
1487 if (!rx_rings) {
1488 err = -ENOMEM;
1489 goto free_tx;
1490 }
1491
1492 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001493 struct i40e_ring *ring;
1494 u16 unused;
1495
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001497 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001498 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001499 /* the desc and bi pointers will be reallocated in the
1500 * setup call
1501 */
1502 rx_rings[i].desc = NULL;
1503 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001504 /* this is to allow wr32 to have something to write to
1505 * during early allocation of Rx buffers
1506 */
1507 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001508 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001509 if (err)
1510 goto rx_unwind;
1511
1512 /* now allocate the Rx buffers to make sure the OS
1513 * has enough memory, any failure here means abort
1514 */
1515 ring = &rx_rings[i];
1516 unused = I40E_DESC_UNUSED(ring);
1517 err = i40e_alloc_rx_buffers(ring, unused);
1518rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001520 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001521 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001522 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523 kfree(rx_rings);
1524 rx_rings = NULL;
1525
1526 goto free_tx;
1527 }
1528 }
1529 }
1530
1531 /* Bring interface down, copy in the new ring info,
1532 * then restore the interface
1533 */
1534 i40e_down(vsi);
1535
1536 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001537 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1538 if (i40e_active_tx_ring_index(vsi, i)) {
1539 i40e_free_tx_resources(vsi->tx_rings[i]);
1540 *vsi->tx_rings[i] = tx_rings[i];
1541 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001542 }
1543 kfree(tx_rings);
1544 tx_rings = NULL;
1545 }
1546
1547 if (rx_rings) {
1548 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001549 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001550 /* get the real tail offset */
1551 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1552 /* this is to fake out the allocation routine
1553 * into thinking it has to realloc everything
1554 * but the recycling logic will let us re-use
1555 * the buffers allocated above
1556 */
1557 rx_rings[i].next_to_use = 0;
1558 rx_rings[i].next_to_clean = 0;
1559 rx_rings[i].next_to_alloc = 0;
1560 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001561 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562 }
1563 kfree(rx_rings);
1564 rx_rings = NULL;
1565 }
1566
1567 i40e_up(vsi);
1568
1569free_tx:
1570 /* error cleanup if the Rx allocations failed after getting Tx */
1571 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001572 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1573 if (i40e_active_tx_ring_index(vsi, i))
1574 i40e_free_tx_resources(vsi->tx_rings[i]);
1575 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001576 kfree(tx_rings);
1577 tx_rings = NULL;
1578 }
1579
1580done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001581 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001582
1583 return err;
1584}
1585
1586static int i40e_get_sset_count(struct net_device *netdev, int sset)
1587{
1588 struct i40e_netdev_priv *np = netdev_priv(netdev);
1589 struct i40e_vsi *vsi = np->vsi;
1590 struct i40e_pf *pf = vsi->back;
1591
1592 switch (sset) {
1593 case ETH_SS_TEST:
1594 return I40E_TEST_LEN;
1595 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001596 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001597 int len = I40E_PF_STATS_LEN(netdev);
1598
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001599 if ((pf->lan_veb != I40E_NO_VEB) &&
1600 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001601 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001602 return len;
1603 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001604 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001605 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001606 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001607 return I40E_PRIV_FLAGS_STR_LEN +
1608 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609 default:
1610 return -EOPNOTSUPP;
1611 }
1612}
1613
1614static void i40e_get_ethtool_stats(struct net_device *netdev,
1615 struct ethtool_stats *stats, u64 *data)
1616{
1617 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001618 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619 struct i40e_vsi *vsi = np->vsi;
1620 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001621 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001622 int i = 0;
1623 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001625 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001626
1627 i40e_update_stats(vsi);
1628
1629 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1630 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1631 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1632 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1633 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001634 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1635 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1636 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1637 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1638 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001639 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001640 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001641 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001642
1643 if (!tx_ring)
1644 continue;
1645
1646 /* process Tx ring statistics */
1647 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001648 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001649 data[i] = tx_ring->stats.packets;
1650 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001651 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001652 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001653
1654 /* Rx ring is the 2nd half of the queue pair */
1655 rx_ring = &tx_ring[1];
1656 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001657 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001658 data[i] = rx_ring->stats.packets;
1659 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001660 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001661 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001663 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001664 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001665 return;
1666
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001667 if ((pf->lan_veb != I40E_NO_VEB) &&
1668 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001669 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001670
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001671 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1672 p = (char *)veb;
1673 p += i40e_gstrings_veb_stats[j].stat_offset;
1674 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1675 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001676 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001677 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1678 data[i++] = veb->tc_stats.tc_tx_packets[j];
1679 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1680 data[i++] = veb->tc_stats.tc_rx_packets[j];
1681 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1682 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001683 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001684 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1685 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1686 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1687 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1688 }
1689 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1690 data[i++] = pf->stats.priority_xon_tx[j];
1691 data[i++] = pf->stats.priority_xoff_tx[j];
1692 }
1693 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1694 data[i++] = pf->stats.priority_xon_rx[j];
1695 data[i++] = pf->stats.priority_xoff_rx[j];
1696 }
1697 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1698 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001699}
1700
1701static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1702 u8 *data)
1703{
1704 struct i40e_netdev_priv *np = netdev_priv(netdev);
1705 struct i40e_vsi *vsi = np->vsi;
1706 struct i40e_pf *pf = vsi->back;
1707 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001708 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001709
1710 switch (stringset) {
1711 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001712 memcpy(data, i40e_gstrings_test,
1713 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714 break;
1715 case ETH_SS_STATS:
1716 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1717 snprintf(p, ETH_GSTRING_LEN, "%s",
1718 i40e_gstrings_net_stats[i].stat_string);
1719 p += ETH_GSTRING_LEN;
1720 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001721 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1722 snprintf(p, ETH_GSTRING_LEN, "%s",
1723 i40e_gstrings_misc_stats[i].stat_string);
1724 p += ETH_GSTRING_LEN;
1725 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001726 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001727 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001728 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001729 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001730 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001731 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001732 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001733 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001734 p += ETH_GSTRING_LEN;
1735 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001736 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001737 return;
1738
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001739 if ((pf->lan_veb != I40E_NO_VEB) &&
1740 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001741 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1742 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1743 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001744 p += ETH_GSTRING_LEN;
1745 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001746 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1747 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001748 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001749 p += ETH_GSTRING_LEN;
1750 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001751 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001752 p += ETH_GSTRING_LEN;
1753 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001754 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001755 p += ETH_GSTRING_LEN;
1756 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001757 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001758 p += ETH_GSTRING_LEN;
1759 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001760 }
1761 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1762 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1763 i40e_gstrings_stats[i].stat_string);
1764 p += ETH_GSTRING_LEN;
1765 }
1766 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1767 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001768 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001769 p += ETH_GSTRING_LEN;
1770 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001771 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001772 p += ETH_GSTRING_LEN;
1773 }
1774 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1775 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001776 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001777 p += ETH_GSTRING_LEN;
1778 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001779 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001780 p += ETH_GSTRING_LEN;
1781 }
1782 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1783 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001784 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001785 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001786 }
1787 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1788 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001789 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001790 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1791 snprintf(p, ETH_GSTRING_LEN, "%s",
1792 i40e_gstrings_priv_flags[i].flag_string);
1793 p += ETH_GSTRING_LEN;
1794 }
1795 if (pf->hw.pf_id != 0)
1796 break;
1797 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1798 snprintf(p, ETH_GSTRING_LEN, "%s",
1799 i40e_gl_gstrings_priv_flags[i].flag_string);
1800 p += ETH_GSTRING_LEN;
1801 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001802 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001803 default:
1804 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001805 }
1806}
1807
1808static int i40e_get_ts_info(struct net_device *dev,
1809 struct ethtool_ts_info *info)
1810{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001811 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1812
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001813 /* only report HW timestamping if PTP is enabled */
1814 if (!(pf->flags & I40E_FLAG_PTP))
1815 return ethtool_op_get_ts_info(dev, info);
1816
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001817 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1818 SOF_TIMESTAMPING_RX_SOFTWARE |
1819 SOF_TIMESTAMPING_SOFTWARE |
1820 SOF_TIMESTAMPING_TX_HARDWARE |
1821 SOF_TIMESTAMPING_RX_HARDWARE |
1822 SOF_TIMESTAMPING_RAW_HARDWARE;
1823
1824 if (pf->ptp_clock)
1825 info->phc_index = ptp_clock_index(pf->ptp_clock);
1826 else
1827 info->phc_index = -1;
1828
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001829 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001830
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001831 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001832 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1833 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1834 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1835
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001836 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001837 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1838 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1839 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1840 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1841 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1842 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1843 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1844 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001845
1846 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001847}
1848
Shannon Nelson7b086392013-11-20 10:02:59 +00001849static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001850{
Shannon Nelson7b086392013-11-20 10:02:59 +00001851 struct i40e_netdev_priv *np = netdev_priv(netdev);
1852 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001853 i40e_status status;
1854 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001855
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001856 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001857 status = i40e_get_link_status(&pf->hw, &link_up);
1858 if (status) {
1859 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1860 *data = 1;
1861 return *data;
1862 }
1863
1864 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001865 *data = 0;
1866 else
1867 *data = 1;
1868
1869 return *data;
1870}
1871
Shannon Nelson7b086392013-11-20 10:02:59 +00001872static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001873{
Shannon Nelson7b086392013-11-20 10:02:59 +00001874 struct i40e_netdev_priv *np = netdev_priv(netdev);
1875 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001876
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001877 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001878 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879
Shannon Nelson7b086392013-11-20 10:02:59 +00001880 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001881}
1882
Shannon Nelson7b086392013-11-20 10:02:59 +00001883static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001884{
Shannon Nelson7b086392013-11-20 10:02:59 +00001885 struct i40e_netdev_priv *np = netdev_priv(netdev);
1886 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001887
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001888 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001889 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001890
Shannon Nelson4443ec92014-11-13 08:23:12 +00001891 /* forcebly clear the NVM Update state machine */
1892 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1893
Shannon Nelson7b086392013-11-20 10:02:59 +00001894 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001895}
1896
Shannon Nelson7b086392013-11-20 10:02:59 +00001897static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001898{
Shannon Nelson7b086392013-11-20 10:02:59 +00001899 struct i40e_netdev_priv *np = netdev_priv(netdev);
1900 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001901 u16 swc_old = pf->sw_int_count;
1902
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001903 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001904 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1905 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001906 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1907 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1908 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1909 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001910 usleep_range(1000, 2000);
1911 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001912
1913 return *data;
1914}
1915
Greg Rosee17bc412015-04-16 20:05:59 -04001916static inline bool i40e_active_vfs(struct i40e_pf *pf)
1917{
1918 struct i40e_vf *vfs = pf->vf;
1919 int i;
1920
1921 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001922 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001923 return true;
1924 return false;
1925}
1926
Greg Rose510efb22015-07-10 19:36:01 -04001927static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1928{
Alexander Duyck4b816442016-10-11 15:26:53 -07001929 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001930}
1931
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001932static void i40e_diag_test(struct net_device *netdev,
1933 struct ethtool_test *eth_test, u64 *data)
1934{
1935 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001936 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001937 struct i40e_pf *pf = np->vsi->back;
1938
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1940 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001941 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001942
Jacob Keller0da36b92017-04-19 09:25:55 -04001943 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001944
Greg Rose510efb22015-07-10 19:36:01 -04001945 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001946 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001947 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001948 data[I40E_ETH_TEST_REG] = 1;
1949 data[I40E_ETH_TEST_EEPROM] = 1;
1950 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001951 data[I40E_ETH_TEST_LINK] = 1;
1952 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04001953 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001954 goto skip_ol_tests;
1955 }
1956
Greg Rose5b86c5c2015-02-26 16:14:35 +00001957 /* If the device is online then take it offline */
1958 if (if_running)
1959 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001960 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001961 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001962 /* This reset does not affect link - if it is
1963 * changed to a type of reset that does affect
1964 * link then the following link test would have
1965 * to be moved to before the reset
1966 */
Maciej Sosin373149f2017-04-05 07:50:55 -04001967 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00001968
Shannon Nelson7b086392013-11-20 10:02:59 +00001969 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001970 eth_test->flags |= ETH_TEST_FL_FAILED;
1971
Shannon Nelson7b086392013-11-20 10:02:59 +00001972 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001973 eth_test->flags |= ETH_TEST_FL_FAILED;
1974
Shannon Nelson7b086392013-11-20 10:02:59 +00001975 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001976 eth_test->flags |= ETH_TEST_FL_FAILED;
1977
Shannon Nelsonf551b432013-11-26 10:49:12 +00001978 /* run reg test last, a reset is required after it */
1979 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1980 eth_test->flags |= ETH_TEST_FL_FAILED;
1981
Jacob Keller0da36b92017-04-19 09:25:55 -04001982 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04001983 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001984
1985 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001986 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001987 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001988 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001989 netif_info(pf, drv, netdev, "online testing starting\n");
1990
Shannon Nelson7b086392013-11-20 10:02:59 +00001991 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992 eth_test->flags |= ETH_TEST_FL_FAILED;
1993
1994 /* Offline only tests, not run in online; pass by default */
1995 data[I40E_ETH_TEST_REG] = 0;
1996 data[I40E_ETH_TEST_EEPROM] = 0;
1997 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001999
Greg Rosee17bc412015-04-16 20:05:59 -04002000skip_ol_tests:
2001
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002002 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002003}
2004
2005static void i40e_get_wol(struct net_device *netdev,
2006 struct ethtool_wolinfo *wol)
2007{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002008 struct i40e_netdev_priv *np = netdev_priv(netdev);
2009 struct i40e_pf *pf = np->vsi->back;
2010 struct i40e_hw *hw = &pf->hw;
2011 u16 wol_nvm_bits;
2012
2013 /* NVM bit on means WoL disabled for the port */
2014 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002015 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002016 wol->supported = 0;
2017 wol->wolopts = 0;
2018 } else {
2019 wol->supported = WAKE_MAGIC;
2020 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2021 }
2022}
2023
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002024/**
2025 * i40e_set_wol - set the WakeOnLAN configuration
2026 * @netdev: the netdev in question
2027 * @wol: the ethtool WoL setting data
2028 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002029static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2030{
2031 struct i40e_netdev_priv *np = netdev_priv(netdev);
2032 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002033 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002034 struct i40e_hw *hw = &pf->hw;
2035 u16 wol_nvm_bits;
2036
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002037 /* WoL not supported if this isn't the controlling PF on the port */
2038 if (hw->partition_id != 1) {
2039 i40e_partition_setting_complaint(pf);
2040 return -EOPNOTSUPP;
2041 }
2042
2043 if (vsi != pf->vsi[pf->lan_vsi])
2044 return -EOPNOTSUPP;
2045
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002046 /* NVM bit on means WoL disabled for the port */
2047 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002048 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002049 return -EOPNOTSUPP;
2050
2051 /* only magic packet is supported */
2052 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2053 return -EOPNOTSUPP;
2054
2055 /* is this a new value? */
2056 if (pf->wol_en != !!wol->wolopts) {
2057 pf->wol_en = !!wol->wolopts;
2058 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2059 }
2060
2061 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062}
2063
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002064static int i40e_set_phys_id(struct net_device *netdev,
2065 enum ethtool_phys_id_state state)
2066{
2067 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002068 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002069 struct i40e_pf *pf = np->vsi->back;
2070 struct i40e_hw *hw = &pf->hw;
2071 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002072 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002073
2074 switch (state) {
2075 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002076 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002077 pf->led_status = i40e_led_get(hw);
2078 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002079 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2080 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2081 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002082 ret = i40e_led_get_phy(hw, &temp_status,
2083 &pf->phy_led_val);
2084 pf->led_status = temp_status;
2085 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002086 return blink_freq;
2087 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002088 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002089 i40e_led_set(hw, 0xf, false);
2090 else
2091 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002092 break;
2093 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002094 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002095 i40e_led_set(hw, 0x0, false);
2096 else
2097 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002098 break;
2099 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002100 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002101 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002102 } else {
2103 ret = i40e_led_set_phy(hw, false, pf->led_status,
2104 (pf->phy_led_val |
2105 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002106 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2107 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002108 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002109 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002110 default:
2111 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002112 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002113 if (ret)
2114 return -ENOENT;
2115 else
2116 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002117}
2118
2119/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2120 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2121 * 125us (8000 interrupts per second) == ITR(62)
2122 */
2123
Jacob Keller65e87c02016-09-12 14:18:44 -07002124/**
2125 * __i40e_get_coalesce - get per-queue coalesce settings
2126 * @netdev: the netdev to check
2127 * @ec: ethtool coalesce data structure
2128 * @queue: which queue to pick
2129 *
2130 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2131 * are per queue. If queue is <0 then we default to queue 0 as the
2132 * representative value.
2133 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002134static int __i40e_get_coalesce(struct net_device *netdev,
2135 struct ethtool_coalesce *ec,
2136 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002137{
2138 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002139 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140 struct i40e_vsi *vsi = np->vsi;
2141
2142 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2143 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2144
Alan Bradya03af692017-10-05 14:53:37 -07002145 /* rx and tx usecs has per queue value. If user doesn't specify the
2146 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002147 */
Alan Bradya03af692017-10-05 14:53:37 -07002148 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002149 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002150 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002151 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002152
Jacob Keller65e87c02016-09-12 14:18:44 -07002153 rx_ring = vsi->rx_rings[queue];
2154 tx_ring = vsi->tx_rings[queue];
2155
2156 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002157 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002158
Jacob Keller65e87c02016-09-12 14:18:44 -07002159 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002160 ec->use_adaptive_tx_coalesce = 1;
2161
Jacob Keller65e87c02016-09-12 14:18:44 -07002162 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2163 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2164
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002165 /* we use the _usecs_high to store/set the interrupt rate limit
2166 * that the hardware supports, that almost but not quite
2167 * fits the original intent of the ethtool variable,
2168 * the rx_coalesce_usecs_high limits total interrupts
2169 * per second from both tx/rx sources.
2170 */
2171 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2172 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002173
2174 return 0;
2175}
2176
Jacob Keller65e87c02016-09-12 14:18:44 -07002177/**
2178 * i40e_get_coalesce - get a netdev's coalesce settings
2179 * @netdev: the netdev to check
2180 * @ec: ethtool coalesce data structure
2181 *
2182 * Gets the coalesce settings for a particular netdev. Note that if user has
2183 * modified per-queue settings, this only guarantees to represent queue 0. See
2184 * __i40e_get_coalesce for more details.
2185 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002186static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187 struct ethtool_coalesce *ec)
2188{
Kan Lianga75e8002016-02-19 09:24:04 -05002189 return __i40e_get_coalesce(netdev, ec, -1);
2190}
2191
Jacob Keller65e87c02016-09-12 14:18:44 -07002192/**
2193 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2194 * @netdev: netdev structure
2195 * @ec: ethtool's coalesce settings
2196 * @queue: the particular queue to read
2197 *
2198 * Will read a specific queue's coalesce settings
2199 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002200static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2201 struct ethtool_coalesce *ec)
2202{
2203 return __i40e_get_coalesce(netdev, ec, queue);
2204}
2205
Jacob Keller65e87c02016-09-12 14:18:44 -07002206/**
2207 * i40e_set_itr_per_queue - set ITR values for specific queue
2208 * @vsi: the VSI to set values for
2209 * @ec: coalesce settings from ethtool
2210 * @queue: the queue to modify
2211 *
2212 * Change the ITR settings for a specific queue.
2213 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002214static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2215 struct ethtool_coalesce *ec,
2216 int queue)
2217{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002218 struct i40e_pf *pf = vsi->back;
2219 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002220 struct i40e_q_vector *q_vector;
2221 u16 vector, intrl;
2222
Alan Brady1c0e6a32016-11-28 16:06:02 -08002223 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002224
2225 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2226 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2227
2228 if (ec->use_adaptive_rx_coalesce)
2229 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2230 else
2231 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2232
2233 if (ec->use_adaptive_tx_coalesce)
2234 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2235 else
2236 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2237
2238 q_vector = vsi->rx_rings[queue]->q_vector;
2239 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2240 vector = vsi->base_vector + q_vector->v_idx;
2241 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2242
2243 q_vector = vsi->tx_rings[queue]->q_vector;
2244 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2245 vector = vsi->base_vector + q_vector->v_idx;
2246 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2247
2248 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2249 i40e_flush(hw);
2250}
2251
Jacob Keller65e87c02016-09-12 14:18:44 -07002252/**
2253 * __i40e_set_coalesce - set coalesce settings for particular queue
2254 * @netdev: the netdev to change
2255 * @ec: ethtool coalesce settings
2256 * @queue: the queue to change
2257 *
2258 * Sets the coalesce settings for a particular queue.
2259 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002260static int __i40e_set_coalesce(struct net_device *netdev,
2261 struct ethtool_coalesce *ec,
2262 int queue)
2263{
2264 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002265 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002266 struct i40e_vsi *vsi = np->vsi;
2267 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002268 int i;
2269
2270 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2271 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2272
Alan Brady06b2dec2017-07-12 05:46:06 -04002273 if (queue < 0) {
2274 cur_rx_itr = vsi->rx_rings[0]->rx_itr_setting;
2275 cur_tx_itr = vsi->tx_rings[0]->tx_itr_setting;
2276 } else if (queue < vsi->num_queue_pairs) {
2277 cur_rx_itr = vsi->rx_rings[queue]->rx_itr_setting;
2278 cur_tx_itr = vsi->tx_rings[queue]->tx_itr_setting;
2279 } else {
2280 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2281 vsi->num_queue_pairs - 1);
2282 return -EINVAL;
2283 }
2284
2285 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2286 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2287
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002288 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2289 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2290 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2291 return -EINVAL;
2292 }
2293
Alan Brady33084062016-11-28 16:06:03 -08002294 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2295 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2296 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002297 return -EINVAL;
2298 }
2299
Alan Brady06b2dec2017-07-12 05:46:06 -04002300 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2301 ec->use_adaptive_rx_coalesce) {
2302 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2303 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002304 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002305
Alan Brady06b2dec2017-07-12 05:46:06 -04002306 if (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2307 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2308 return -EINVAL;
2309 }
2310
2311 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2312 ec->use_adaptive_tx_coalesce) {
2313 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2314 return -EINVAL;
2315 }
2316
2317 if (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2318 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2319 return -EINVAL;
2320 }
2321
2322 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2323 ec->rx_coalesce_usecs = I40E_MIN_ITR << 1;
2324
2325 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2326 ec->tx_coalesce_usecs = I40E_MIN_ITR << 1;
2327
Alan Brady33084062016-11-28 16:06:03 -08002328 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2329 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2330 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2331 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2332 vsi->int_rate_limit);
2333 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002334
Alan Bradya03af692017-10-05 14:53:37 -07002335 /* rx and tx usecs has per queue value. If user doesn't specify the
2336 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002337 */
2338 if (queue < 0) {
2339 for (i = 0; i < vsi->num_queue_pairs; i++)
2340 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002341 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002342 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002343 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002344
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002345 return 0;
2346}
2347
Jacob Keller65e87c02016-09-12 14:18:44 -07002348/**
2349 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2350 * @netdev: the netdev to change
2351 * @ec: ethtool coalesce settings
2352 *
2353 * This will set each queue to the same coalesce settings.
2354 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002355static int i40e_set_coalesce(struct net_device *netdev,
2356 struct ethtool_coalesce *ec)
2357{
2358 return __i40e_set_coalesce(netdev, ec, -1);
2359}
2360
Jacob Keller65e87c02016-09-12 14:18:44 -07002361/**
2362 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2363 * @netdev: the netdev to change
2364 * @ec: ethtool's coalesce settings
2365 * @queue: the queue to change
2366 *
2367 * Sets the specified queue's coalesce settings.
2368 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002369static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2370 struct ethtool_coalesce *ec)
2371{
2372 return __i40e_set_coalesce(netdev, ec, queue);
2373}
2374
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002375/**
2376 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2377 * @pf: pointer to the physical function struct
2378 * @cmd: ethtool rxnfc command
2379 *
2380 * Returns Success if the flow is supported, else Invalid Input.
2381 **/
2382static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2383{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002384 struct i40e_hw *hw = &pf->hw;
2385 u8 flow_pctype = 0;
2386 u64 i_set = 0;
2387
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002388 cmd->data = 0;
2389
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002390 switch (cmd->flow_type) {
2391 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002392 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2393 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002394 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002395 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2396 break;
2397 case TCP_V6_FLOW:
2398 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2399 break;
2400 case UDP_V6_FLOW:
2401 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2402 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002403 case SCTP_V4_FLOW:
2404 case AH_ESP_V4_FLOW:
2405 case AH_V4_FLOW:
2406 case ESP_V4_FLOW:
2407 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002408 case SCTP_V6_FLOW:
2409 case AH_ESP_V6_FLOW:
2410 case AH_V6_FLOW:
2411 case ESP_V6_FLOW:
2412 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002413 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002414 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2415 break;
2416 default:
2417 return -EINVAL;
2418 }
2419
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002420 /* Read flow based hash input set register */
2421 if (flow_pctype) {
2422 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2423 flow_pctype)) |
2424 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2425 flow_pctype)) << 32);
2426 }
2427
2428 /* Process bits of hash input set */
2429 if (i_set) {
2430 if (i_set & I40E_L4_SRC_MASK)
2431 cmd->data |= RXH_L4_B_0_1;
2432 if (i_set & I40E_L4_DST_MASK)
2433 cmd->data |= RXH_L4_B_2_3;
2434
2435 if (cmd->flow_type == TCP_V4_FLOW ||
2436 cmd->flow_type == UDP_V4_FLOW) {
2437 if (i_set & I40E_L3_SRC_MASK)
2438 cmd->data |= RXH_IP_SRC;
2439 if (i_set & I40E_L3_DST_MASK)
2440 cmd->data |= RXH_IP_DST;
2441 } else if (cmd->flow_type == TCP_V6_FLOW ||
2442 cmd->flow_type == UDP_V6_FLOW) {
2443 if (i_set & I40E_L3_V6_SRC_MASK)
2444 cmd->data |= RXH_IP_SRC;
2445 if (i_set & I40E_L3_V6_DST_MASK)
2446 cmd->data |= RXH_IP_DST;
2447 }
2448 }
2449
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002450 return 0;
2451}
2452
2453/**
Jacob Kellere7930952017-02-06 14:38:49 -08002454 * i40e_check_mask - Check whether a mask field is set
2455 * @mask: the full mask value
2456 * @field; mask of the field to check
2457 *
2458 * If the given mask is fully set, return positive value. If the mask for the
2459 * field is fully unset, return zero. Otherwise return a negative error code.
2460 **/
2461static int i40e_check_mask(u64 mask, u64 field)
2462{
2463 u64 value = mask & field;
2464
2465 if (value == field)
2466 return 1;
2467 else if (!value)
2468 return 0;
2469 else
2470 return -1;
2471}
2472
2473/**
2474 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2475 * @fsp: pointer to rx flow specification
2476 * @data: pointer to userdef data structure for storage
2477 *
2478 * Read the user-defined data and deconstruct the value into a structure. No
2479 * other code should read the user-defined data, so as to ensure that every
2480 * place consistently reads the value correctly.
2481 *
2482 * The user-defined field is a 64bit Big Endian format value, which we
2483 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2484 * be defined starting from the highest bits, while small bit field values
2485 * shall be defined starting from the lowest bits.
2486 *
2487 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2488 * and the filter should be rejected. The data structure will always be
2489 * modified even if FLOW_EXT is not set.
2490 *
2491 **/
2492static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2493 struct i40e_rx_flow_userdef *data)
2494{
2495 u64 value, mask;
2496 int valid;
2497
2498 /* Zero memory first so it's always consistent. */
2499 memset(data, 0, sizeof(*data));
2500
2501 if (!(fsp->flow_type & FLOW_EXT))
2502 return 0;
2503
2504 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2505 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2506
2507#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2508#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2509#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2510
2511 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2512 if (valid < 0) {
2513 return -EINVAL;
2514 } else if (valid) {
2515 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2516 data->flex_offset =
2517 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2518 data->flex_filter = true;
2519 }
2520
2521 return 0;
2522}
2523
2524/**
2525 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2526 * @fsp: pointer to rx_flow specification
2527 *
2528 * Reads the userdef data structure and properly fills in the user defined
2529 * fields of the rx_flow_spec.
2530 **/
2531static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2532 struct i40e_rx_flow_userdef *data)
2533{
2534 u64 value = 0, mask = 0;
2535
2536 if (data->flex_filter) {
2537 value |= data->flex_word;
2538 value |= (u64)data->flex_offset << 16;
2539 mask |= I40E_USERDEF_FLEX_FILTER;
2540 }
2541
2542 if (value || mask)
2543 fsp->flow_type |= FLOW_EXT;
2544
2545 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2546 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2547}
2548
2549/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002550 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2551 * @pf: Pointer to the physical function struct
2552 * @cmd: The command to get or set Rx flow classification rules
2553 * @rule_locs: Array of used rule locations
2554 *
2555 * This function populates both the total and actual rule count of
2556 * the ethtool flow classification command
2557 *
2558 * Returns 0 on success or -EMSGSIZE if entry not found
2559 **/
2560static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2561 struct ethtool_rxnfc *cmd,
2562 u32 *rule_locs)
2563{
2564 struct i40e_fdir_filter *rule;
2565 struct hlist_node *node2;
2566 int cnt = 0;
2567
2568 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002569 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002570
2571 hlist_for_each_entry_safe(rule, node2,
2572 &pf->fdir_filter_list, fdir_node) {
2573 if (cnt == cmd->rule_cnt)
2574 return -EMSGSIZE;
2575
2576 rule_locs[cnt] = rule->fd_id;
2577 cnt++;
2578 }
2579
2580 cmd->rule_cnt = cnt;
2581
2582 return 0;
2583}
2584
2585/**
2586 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2587 * @pf: Pointer to the physical function struct
2588 * @cmd: The command to get or set Rx flow classification rules
2589 *
2590 * This function looks up a filter based on the Rx flow classification
2591 * command and fills the flow spec info for it if found
2592 *
2593 * Returns 0 on success or -EINVAL if filter not found
2594 **/
2595static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2596 struct ethtool_rxnfc *cmd)
2597{
2598 struct ethtool_rx_flow_spec *fsp =
2599 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002600 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002601 struct i40e_fdir_filter *rule = NULL;
2602 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002603 u64 input_set;
2604 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002605
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002606 hlist_for_each_entry_safe(rule, node2,
2607 &pf->fdir_filter_list, fdir_node) {
2608 if (fsp->location <= rule->fd_id)
2609 break;
2610 }
2611
2612 if (!rule || fsp->location != rule->fd_id)
2613 return -EINVAL;
2614
2615 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002616 if (fsp->flow_type == IP_USER_FLOW) {
2617 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2618 fsp->h_u.usr_ip4_spec.proto = 0;
2619 fsp->m_u.usr_ip4_spec.proto = 0;
2620 }
2621
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002622 /* Reverse the src and dest notion, since the HW views them from
2623 * Tx perspective where as the user expects it from Rx filter view.
2624 */
2625 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2626 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002627 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2628 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002629
Jacob Keller36777d92017-03-07 15:05:23 -08002630 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002631 case SCTP_V4_FLOW:
2632 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2633 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002634 case TCP_V4_FLOW:
2635 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2636 break;
2637 case UDP_V4_FLOW:
2638 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2639 break;
2640 case IP_USER_FLOW:
2641 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2642 break;
2643 default:
2644 /* If we have stored a filter with a flow type not listed here
2645 * it is almost certainly a driver bug. WARN(), and then
2646 * assign the input_set as if all fields are enabled to avoid
2647 * reading unassigned memory.
2648 */
2649 WARN(1, "Missing input set index for flow_type %d\n",
2650 rule->flow_type);
2651 input_set = 0xFFFFFFFFFFFFFFFFULL;
2652 goto no_input_set;
2653 }
2654
2655 input_set = i40e_read_fd_input_set(pf, index);
2656
2657no_input_set:
2658 if (input_set & I40E_L3_SRC_MASK)
2659 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
2660
2661 if (input_set & I40E_L3_DST_MASK)
2662 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
2663
2664 if (input_set & I40E_L4_SRC_MASK)
2665 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
2666
2667 if (input_set & I40E_L4_DST_MASK)
2668 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002669
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002670 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2671 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2672 else
2673 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002674
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002675 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2676 struct i40e_vsi *vsi;
2677
2678 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2679 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002680 /* VFs are zero-indexed by the driver, but ethtool
2681 * expects them to be one-indexed, so add one here
2682 */
2683 u64 ring_vf = vsi->vf_id + 1;
2684
2685 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2686 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002687 }
2688 }
2689
Jacob Keller0e588de2017-02-06 14:38:50 -08002690 if (rule->flex_filter) {
2691 userdef.flex_filter = true;
2692 userdef.flex_word = be16_to_cpu(rule->flex_word);
2693 userdef.flex_offset = rule->flex_offset;
2694 }
2695
Jacob Kellere7930952017-02-06 14:38:49 -08002696 i40e_fill_rx_flow_user_data(fsp, &userdef);
2697
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002698 return 0;
2699}
2700
2701/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002702 * i40e_get_rxnfc - command to get RX flow classification rules
2703 * @netdev: network interface device structure
2704 * @cmd: ethtool rxnfc command
2705 *
2706 * Returns Success if the command is supported.
2707 **/
2708static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2709 u32 *rule_locs)
2710{
2711 struct i40e_netdev_priv *np = netdev_priv(netdev);
2712 struct i40e_vsi *vsi = np->vsi;
2713 struct i40e_pf *pf = vsi->back;
2714 int ret = -EOPNOTSUPP;
2715
2716 switch (cmd->cmd) {
2717 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002718 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002719 ret = 0;
2720 break;
2721 case ETHTOOL_GRXFH:
2722 ret = i40e_get_rss_hash_opts(pf, cmd);
2723 break;
2724 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002725 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002726 /* report total rule count */
2727 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002728 ret = 0;
2729 break;
2730 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002731 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002732 break;
2733 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002734 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2735 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002736 default:
2737 break;
2738 }
2739
2740 return ret;
2741}
2742
2743/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002744 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2745 * @nfc: pointer to user request
2746 * @i_setc bits currently set
2747 *
2748 * Returns value of bits to be set per user request
2749 **/
2750static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2751{
2752 u64 i_set = i_setc;
2753 u64 src_l3 = 0, dst_l3 = 0;
2754
2755 if (nfc->data & RXH_L4_B_0_1)
2756 i_set |= I40E_L4_SRC_MASK;
2757 else
2758 i_set &= ~I40E_L4_SRC_MASK;
2759 if (nfc->data & RXH_L4_B_2_3)
2760 i_set |= I40E_L4_DST_MASK;
2761 else
2762 i_set &= ~I40E_L4_DST_MASK;
2763
2764 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2765 src_l3 = I40E_L3_V6_SRC_MASK;
2766 dst_l3 = I40E_L3_V6_DST_MASK;
2767 } else if (nfc->flow_type == TCP_V4_FLOW ||
2768 nfc->flow_type == UDP_V4_FLOW) {
2769 src_l3 = I40E_L3_SRC_MASK;
2770 dst_l3 = I40E_L3_DST_MASK;
2771 } else {
2772 /* Any other flow type are not supported here */
2773 return i_set;
2774 }
2775
2776 if (nfc->data & RXH_IP_SRC)
2777 i_set |= src_l3;
2778 else
2779 i_set &= ~src_l3;
2780 if (nfc->data & RXH_IP_DST)
2781 i_set |= dst_l3;
2782 else
2783 i_set &= ~dst_l3;
2784
2785 return i_set;
2786}
2787
2788/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002789 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2790 * @pf: pointer to the physical function struct
2791 * @cmd: ethtool rxnfc command
2792 *
2793 * Returns Success if the flow input set is supported.
2794 **/
2795static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2796{
2797 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002798 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2799 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002800 u8 flow_pctype = 0;
2801 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002802
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002803 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2804 dev_err(&pf->pdev->dev,
2805 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2806 return -EOPNOTSUPP;
2807 }
2808
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002809 /* RSS does not support anything other than hashing
2810 * to queues on src and dst IPs and ports
2811 */
2812 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2813 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2814 return -EINVAL;
2815
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002816 switch (nfc->flow_type) {
2817 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002818 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002819 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002820 hena |=
2821 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002822 break;
2823 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002824 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002825 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002826 hena |=
2827 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002828 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002829 hena |=
2830 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002831 break;
2832 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002833 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002834 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002835 hena |=
2836 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2837 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002838
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002839 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002840 break;
2841 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002842 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002843 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002844 hena |=
2845 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2846 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002847
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002848 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002849 break;
2850 case AH_ESP_V4_FLOW:
2851 case AH_V4_FLOW:
2852 case ESP_V4_FLOW:
2853 case SCTP_V4_FLOW:
2854 if ((nfc->data & RXH_L4_B_0_1) ||
2855 (nfc->data & RXH_L4_B_2_3))
2856 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002857 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002858 break;
2859 case AH_ESP_V6_FLOW:
2860 case AH_V6_FLOW:
2861 case ESP_V6_FLOW:
2862 case SCTP_V6_FLOW:
2863 if ((nfc->data & RXH_L4_B_0_1) ||
2864 (nfc->data & RXH_L4_B_2_3))
2865 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002866 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002867 break;
2868 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002869 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2870 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002871 break;
2872 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002873 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2874 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002875 break;
2876 default:
2877 return -EINVAL;
2878 }
2879
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002880 if (flow_pctype) {
2881 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2882 flow_pctype)) |
2883 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2884 flow_pctype)) << 32);
2885 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2886 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2887 (u32)i_set);
2888 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2889 (u32)(i_set >> 32));
2890 hena |= BIT_ULL(flow_pctype);
2891 }
2892
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002893 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2894 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002895 i40e_flush(hw);
2896
2897 return 0;
2898}
2899
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002900/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002901 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2902 * @vsi: Pointer to the targeted VSI
2903 * @input: The filter to update or NULL to indicate deletion
2904 * @sw_idx: Software index to the filter
2905 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002906 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002907 * This function updates (or deletes) a Flow Director entry from
2908 * the hlist of the corresponding PF
2909 *
2910 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002911 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002912static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2913 struct i40e_fdir_filter *input,
2914 u16 sw_idx,
2915 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002916{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002917 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002918 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002919 struct hlist_node *node2;
2920 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002921
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002922 parent = NULL;
2923 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002924
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002925 hlist_for_each_entry_safe(rule, node2,
2926 &pf->fdir_filter_list, fdir_node) {
2927 /* hash found, or no matching entry */
2928 if (rule->fd_id >= sw_idx)
2929 break;
2930 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002931 }
2932
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002933 /* if there is an old rule occupying our place remove it */
2934 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08002935 /* Remove this rule, since we're either deleting it, or
2936 * replacing it.
2937 */
2938 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002939 hlist_del(&rule->fdir_node);
2940 kfree(rule);
2941 pf->fdir_pf_active_filters--;
2942 }
2943
Jacob Kellerc6da5252017-02-06 14:39:13 -08002944 /* If we weren't given an input, this is a delete, so just return the
2945 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002946 */
2947 if (!input)
2948 return err;
2949
Jacob Kellerc6da5252017-02-06 14:39:13 -08002950 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002951 INIT_HLIST_NODE(&input->fdir_node);
2952
2953 /* add filter to the list */
2954 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002955 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002956 else
2957 hlist_add_head(&input->fdir_node,
2958 &pf->fdir_filter_list);
2959
2960 /* update counts */
2961 pf->fdir_pf_active_filters++;
2962
2963 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002964}
2965
2966/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002967 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
2968 * @pf: pointer to PF structure
2969 *
2970 * This function searches the list of filters and determines which FLX_PIT
2971 * entries are still required. It will prune any entries which are no longer
2972 * in use after the deletion.
2973 **/
2974static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
2975{
2976 struct i40e_flex_pit *entry, *tmp;
2977 struct i40e_fdir_filter *rule;
2978
2979 /* First, we'll check the l3 table */
2980 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
2981 bool found = false;
2982
2983 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2984 if (rule->flow_type != IP_USER_FLOW)
2985 continue;
2986 if (rule->flex_filter &&
2987 rule->flex_offset == entry->src_offset) {
2988 found = true;
2989 break;
2990 }
2991 }
2992
2993 /* If we didn't find the filter, then we can prune this entry
2994 * from the list.
2995 */
2996 if (!found) {
2997 list_del(&entry->list);
2998 kfree(entry);
2999 }
3000 }
3001
3002 /* Followed by the L4 table */
3003 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3004 bool found = false;
3005
3006 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3007 /* Skip this filter if it's L3, since we already
3008 * checked those in the above loop
3009 */
3010 if (rule->flow_type == IP_USER_FLOW)
3011 continue;
3012 if (rule->flex_filter &&
3013 rule->flex_offset == entry->src_offset) {
3014 found = true;
3015 break;
3016 }
3017 }
3018
3019 /* If we didn't find the filter, then we can prune this entry
3020 * from the list.
3021 */
3022 if (!found) {
3023 list_del(&entry->list);
3024 kfree(entry);
3025 }
3026 }
3027}
3028
3029/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003030 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3031 * @vsi: Pointer to the targeted VSI
3032 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003033 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003034 * The function removes a Flow Director filter entry from the
3035 * hlist of the corresponding PF
3036 *
3037 * Returns 0 on success
3038 */
3039static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3040 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003041{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003042 struct ethtool_rx_flow_spec *fsp =
3043 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003044 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003045 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003046
Jacob Keller0da36b92017-04-19 09:25:55 -04003047 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3048 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003049 return -EBUSY;
3050
Jacob Keller0da36b92017-04-19 09:25:55 -04003051 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003052 return -EBUSY;
3053
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003054 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003055
Jacob Keller0e588de2017-02-06 14:38:50 -08003056 i40e_prune_flex_pit_list(pf);
3057
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003058 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003059 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003060}
3061
3062/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003063 * i40e_unused_pit_index - Find an unused PIT index for given list
3064 * @pf: the PF data structure
3065 *
3066 * Find the first unused flexible PIT index entry. We search both the L3 and
3067 * L4 flexible PIT lists so that the returned index is unique and unused by
3068 * either currently programmed L3 or L4 filters. We use a bit field as storage
3069 * to track which indexes are already used.
3070 **/
3071static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3072{
3073 unsigned long available_index = 0xFF;
3074 struct i40e_flex_pit *entry;
3075
3076 /* We need to make sure that the new index isn't in use by either L3
3077 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3078 * L4 to use the same index.
3079 */
3080
3081 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3082 clear_bit(entry->pit_index, &available_index);
3083
3084 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3085 clear_bit(entry->pit_index, &available_index);
3086
3087 return find_first_bit(&available_index, 8);
3088}
3089
3090/**
3091 * i40e_find_flex_offset - Find an existing flex src_offset
3092 * @flex_pit_list: L3 or L4 flex PIT list
3093 * @src_offset: new src_offset to find
3094 *
3095 * Searches the flex_pit_list for an existing offset. If no offset is
3096 * currently programmed, then this will return an ERR_PTR if there is no space
3097 * to add a new offset, otherwise it returns NULL.
3098 **/
3099static
3100struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3101 u16 src_offset)
3102{
3103 struct i40e_flex_pit *entry;
3104 int size = 0;
3105
3106 /* Search for the src_offset first. If we find a matching entry
3107 * already programmed, we can simply re-use it.
3108 */
3109 list_for_each_entry(entry, flex_pit_list, list) {
3110 size++;
3111 if (entry->src_offset == src_offset)
3112 return entry;
3113 }
3114
3115 /* If we haven't found an entry yet, then the provided src offset has
3116 * not yet been programmed. We will program the src offset later on,
3117 * but we need to indicate whether there is enough space to do so
3118 * here. We'll make use of ERR_PTR for this purpose.
3119 */
3120 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3121 return ERR_PTR(-ENOSPC);
3122
3123 return NULL;
3124}
3125
3126/**
3127 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3128 * @flex_pit_list: L3 or L4 flex PIT list
3129 * @src_offset: new src_offset to add
3130 * @pit_index: the PIT index to program
3131 *
3132 * This function programs the new src_offset to the list. It is expected that
3133 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3134 * that this offset is not programmed, and that the list has enough space to
3135 * store another offset.
3136 *
3137 * Returns 0 on success, and negative value on error.
3138 **/
3139static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3140 u16 src_offset,
3141 u8 pit_index)
3142{
3143 struct i40e_flex_pit *new_pit, *entry;
3144
3145 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3146 if (!new_pit)
3147 return -ENOMEM;
3148
3149 new_pit->src_offset = src_offset;
3150 new_pit->pit_index = pit_index;
3151
3152 /* We need to insert this item such that the list is sorted by
3153 * src_offset in ascending order.
3154 */
3155 list_for_each_entry(entry, flex_pit_list, list) {
3156 if (new_pit->src_offset < entry->src_offset) {
3157 list_add_tail(&new_pit->list, &entry->list);
3158 return 0;
3159 }
3160
3161 /* If we found an entry with our offset already programmed we
3162 * can simply return here, after freeing the memory. However,
3163 * if the pit_index does not match we need to report an error.
3164 */
3165 if (new_pit->src_offset == entry->src_offset) {
3166 int err = 0;
3167
3168 /* If the PIT index is not the same we can't re-use
3169 * the entry, so we must report an error.
3170 */
3171 if (new_pit->pit_index != entry->pit_index)
3172 err = -EINVAL;
3173
3174 kfree(new_pit);
3175 return err;
3176 }
3177 }
3178
3179 /* If we reached here, then we haven't yet added the item. This means
3180 * that we should add the item at the end of the list.
3181 */
3182 list_add_tail(&new_pit->list, flex_pit_list);
3183 return 0;
3184}
3185
3186/**
3187 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3188 * @pf: Pointer to the PF structure
3189 * @flex_pit_list: list of flexible src offsets in use
3190 * #flex_pit_start: index to first entry for this section of the table
3191 *
3192 * In order to handle flexible data, the hardware uses a table of values
3193 * called the FLX_PIT table. This table is used to indicate which sections of
3194 * the input correspond to what PIT index values. Unfortunately, hardware is
3195 * very restrictive about programming this table. Entries must be ordered by
3196 * src_offset in ascending order, without duplicates. Additionally, unused
3197 * entries must be set to the unused index value, and must have valid size and
3198 * length according to the src_offset ordering.
3199 *
3200 * This function will reprogram the FLX_PIT register from a book-keeping
3201 * structure that we guarantee is already ordered correctly, and has no more
3202 * than 3 entries.
3203 *
3204 * To make things easier, we only support flexible values of one word length,
3205 * rather than allowing variable length flexible values.
3206 **/
3207static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3208 struct list_head *flex_pit_list,
3209 int flex_pit_start)
3210{
3211 struct i40e_flex_pit *entry = NULL;
3212 u16 last_offset = 0;
3213 int i = 0, j = 0;
3214
3215 /* First, loop over the list of flex PIT entries, and reprogram the
3216 * registers.
3217 */
3218 list_for_each_entry(entry, flex_pit_list, list) {
3219 /* We have to be careful when programming values for the
3220 * largest SRC_OFFSET value. It is possible that adding
3221 * additional empty values at the end would overflow the space
3222 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3223 * we check here and add the empty values prior to adding the
3224 * largest value.
3225 *
3226 * To determine this, we will use a loop from i+1 to 3, which
3227 * will determine whether the unused entries would have valid
3228 * SRC_OFFSET. Note that there cannot be extra entries past
3229 * this value, because the only valid values would have been
3230 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3231 * have been added to the list in the first place.
3232 */
3233 for (j = i + 1; j < 3; j++) {
3234 u16 offset = entry->src_offset + j;
3235 int index = flex_pit_start + i;
3236 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3237 1,
3238 offset - 3);
3239
3240 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3241 i40e_write_rx_ctl(&pf->hw,
3242 I40E_PRTQF_FLX_PIT(index),
3243 value);
3244 i++;
3245 }
3246 }
3247
3248 /* Now, we can program the actual value into the table */
3249 i40e_write_rx_ctl(&pf->hw,
3250 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3251 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3252 1,
3253 entry->src_offset));
3254 i++;
3255 }
3256
3257 /* In order to program the last entries in the table, we need to
3258 * determine the valid offset. If the list is empty, we'll just start
3259 * with 0. Otherwise, we'll start with the last item offset and add 1.
3260 * This ensures that all entries have valid sizes. If we don't do this
3261 * correctly, the hardware will disable flexible field parsing.
3262 */
3263 if (!list_empty(flex_pit_list))
3264 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3265
3266 for (; i < 3; i++, last_offset++) {
3267 i40e_write_rx_ctl(&pf->hw,
3268 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3269 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3270 1,
3271 last_offset));
3272 }
3273}
3274
3275/**
3276 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3277 * @pf: pointer to the PF structure
3278 *
3279 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3280 * internal helper function for implementation details.
3281 **/
3282static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3283{
3284 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3285 I40E_FLEX_PIT_IDX_START_L3);
3286
3287 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3288 I40E_FLEX_PIT_IDX_START_L4);
3289
3290 /* We also need to program the L3 and L4 GLQF ORT register */
3291 i40e_write_rx_ctl(&pf->hw,
3292 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3293 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3294 3, 1));
3295
3296 i40e_write_rx_ctl(&pf->hw,
3297 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3298 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3299 3, 1));
3300}
3301
3302/**
Jacob Keller9229e992017-02-06 14:38:47 -08003303 * i40e_flow_str - Converts a flow_type into a human readable string
3304 * @flow_type: the flow type from a flow specification
3305 *
3306 * Currently only flow types we support are included here, and the string
3307 * value attempts to match what ethtool would use to configure this flow type.
3308 **/
3309static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3310{
3311 switch (fsp->flow_type & ~FLOW_EXT) {
3312 case TCP_V4_FLOW:
3313 return "tcp4";
3314 case UDP_V4_FLOW:
3315 return "udp4";
3316 case SCTP_V4_FLOW:
3317 return "sctp4";
3318 case IP_USER_FLOW:
3319 return "ip4";
3320 default:
3321 return "unknown";
3322 }
3323}
3324
3325/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003326 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3327 * @pit_index: PIT index to convert
3328 *
3329 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3330 * of range.
3331 **/
3332static u64 i40e_pit_index_to_mask(int pit_index)
3333{
3334 switch (pit_index) {
3335 case 0:
3336 return I40E_FLEX_50_MASK;
3337 case 1:
3338 return I40E_FLEX_51_MASK;
3339 case 2:
3340 return I40E_FLEX_52_MASK;
3341 case 3:
3342 return I40E_FLEX_53_MASK;
3343 case 4:
3344 return I40E_FLEX_54_MASK;
3345 case 5:
3346 return I40E_FLEX_55_MASK;
3347 case 6:
3348 return I40E_FLEX_56_MASK;
3349 case 7:
3350 return I40E_FLEX_57_MASK;
3351 default:
3352 return 0;
3353 }
3354}
3355
3356/**
Jacob Keller9229e992017-02-06 14:38:47 -08003357 * i40e_print_input_set - Show changes between two input sets
3358 * @vsi: the vsi being configured
3359 * @old: the old input set
3360 * @new: the new input set
3361 *
3362 * Print the difference between old and new input sets by showing which series
3363 * of words are toggled on or off. Only displays the bits we actually support
3364 * changing.
3365 **/
3366static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3367{
3368 struct i40e_pf *pf = vsi->back;
3369 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003370 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003371
3372 old_value = !!(old & I40E_L3_SRC_MASK);
3373 new_value = !!(new & I40E_L3_SRC_MASK);
3374 if (old_value != new_value)
3375 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3376 old_value ? "ON" : "OFF",
3377 new_value ? "ON" : "OFF");
3378
3379 old_value = !!(old & I40E_L3_DST_MASK);
3380 new_value = !!(new & I40E_L3_DST_MASK);
3381 if (old_value != new_value)
3382 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3383 old_value ? "ON" : "OFF",
3384 new_value ? "ON" : "OFF");
3385
3386 old_value = !!(old & I40E_L4_SRC_MASK);
3387 new_value = !!(new & I40E_L4_SRC_MASK);
3388 if (old_value != new_value)
3389 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3390 old_value ? "ON" : "OFF",
3391 new_value ? "ON" : "OFF");
3392
3393 old_value = !!(old & I40E_L4_DST_MASK);
3394 new_value = !!(new & I40E_L4_DST_MASK);
3395 if (old_value != new_value)
3396 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3397 old_value ? "ON" : "OFF",
3398 new_value ? "ON" : "OFF");
3399
3400 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3401 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3402 if (old_value != new_value)
3403 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3404 old_value ? "ON" : "OFF",
3405 new_value ? "ON" : "OFF");
3406
Jacob Keller0e588de2017-02-06 14:38:50 -08003407 /* Show change of flexible filter entries */
3408 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3409 u64 flex_mask = i40e_pit_index_to_mask(i);
3410
3411 old_value = !!(old & flex_mask);
3412 new_value = !!(new & flex_mask);
3413 if (old_value != new_value)
3414 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3415 i,
3416 old_value ? "ON" : "OFF",
3417 new_value ? "ON" : "OFF");
3418 }
3419
Jacob Keller9229e992017-02-06 14:38:47 -08003420 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3421 old);
3422 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3423 new);
3424}
3425
3426/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003427 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003428 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003429 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003430 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003431 *
Jacob Keller9229e992017-02-06 14:38:47 -08003432 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3433 * for partial matches exists with a few limitations. First, hardware only
3434 * supports masking by word boundary (2 bytes) and not per individual bit.
3435 * Second, hardware is limited to using one mask for a flow type and cannot
3436 * use a separate mask for each filter.
3437 *
3438 * To support these limitations, if we already have a configured filter for
3439 * the specified type, this function enforces that new filters of the type
3440 * match the configured input set. Otherwise, if we do not have a filter of
3441 * the specified type, we allow the input set to be updated to match the
3442 * desired filter.
3443 *
3444 * To help ensure that administrators understand why filters weren't displayed
3445 * as supported, we print a diagnostic message displaying how the input set
3446 * would change and warning to delete the preexisting filters if required.
3447 *
3448 * Returns 0 on successful input set match, and a negative return code on
3449 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003450 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003451static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003452 struct ethtool_rx_flow_spec *fsp,
3453 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003454{
Jacob Keller36777d92017-03-07 15:05:23 -08003455 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003456 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3457 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003458 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003459 bool new_flex_offset = false;
3460 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003461 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003462 u16 index, src_offset = 0;
3463 u8 pit_index = 0;
3464 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003465
3466 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003467 case SCTP_V4_FLOW:
3468 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3469 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3470 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003471 case TCP_V4_FLOW:
3472 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003473 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003474 break;
3475 case UDP_V4_FLOW:
3476 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003477 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003478 break;
3479 case IP_USER_FLOW:
3480 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003481 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003482 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003483 break;
3484 default:
3485 return -EOPNOTSUPP;
3486 }
3487
3488 /* Read the current input set from register memory. */
3489 current_mask = i40e_read_fd_input_set(pf, index);
3490 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003491
Jacob Keller9229e992017-02-06 14:38:47 -08003492 /* Determine, if any, the required changes to the input set in order
3493 * to support the provided mask.
3494 *
3495 * Hardware only supports masking at word (2 byte) granularity and does
3496 * not support full bitwise masking. This implementation simplifies
3497 * even further and only supports fully enabled or fully disabled
3498 * masks for each field, even though we could split the ip4src and
3499 * ip4dst fields.
3500 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003501 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003502 case SCTP_V4_FLOW:
3503 new_mask &= ~I40E_VERIFY_TAG_MASK;
3504 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003505 case TCP_V4_FLOW:
3506 case UDP_V4_FLOW:
3507 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3508
3509 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003510 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3511 new_mask |= I40E_L3_SRC_MASK;
3512 else if (!tcp_ip4_spec->ip4src)
3513 new_mask &= ~I40E_L3_SRC_MASK;
3514 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003515 return -EOPNOTSUPP;
3516
3517 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003518 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3519 new_mask |= I40E_L3_DST_MASK;
3520 else if (!tcp_ip4_spec->ip4dst)
3521 new_mask &= ~I40E_L3_DST_MASK;
3522 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003523 return -EOPNOTSUPP;
3524
3525 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003526 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3527 new_mask |= I40E_L4_SRC_MASK;
3528 else if (!tcp_ip4_spec->psrc)
3529 new_mask &= ~I40E_L4_SRC_MASK;
3530 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003531 return -EOPNOTSUPP;
3532
3533 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003534 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3535 new_mask |= I40E_L4_DST_MASK;
3536 else if (!tcp_ip4_spec->pdst)
3537 new_mask &= ~I40E_L4_DST_MASK;
3538 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003539 return -EOPNOTSUPP;
3540
3541 /* Filtering on Type of Service is not supported. */
3542 if (tcp_ip4_spec->tos)
3543 return -EOPNOTSUPP;
3544
3545 break;
3546 case IP_USER_FLOW:
3547 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3548
3549 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003550 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3551 new_mask |= I40E_L3_SRC_MASK;
3552 else if (!usr_ip4_spec->ip4src)
3553 new_mask &= ~I40E_L3_SRC_MASK;
3554 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003555 return -EOPNOTSUPP;
3556
3557 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003558 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3559 new_mask |= I40E_L3_DST_MASK;
3560 else if (!usr_ip4_spec->ip4dst)
3561 new_mask &= ~I40E_L3_DST_MASK;
3562 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003563 return -EOPNOTSUPP;
3564
3565 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003566 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3567 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3568 else if (!usr_ip4_spec->l4_4_bytes)
3569 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3570 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003571 return -EOPNOTSUPP;
3572
3573 /* Filtering on Type of Service is not supported. */
3574 if (usr_ip4_spec->tos)
3575 return -EOPNOTSUPP;
3576
Jacob Keller0e588de2017-02-06 14:38:50 -08003577 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003578 if (usr_ip4_spec->ip_ver)
3579 return -EINVAL;
3580
Jacob Keller0e588de2017-02-06 14:38:50 -08003581 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003582 if (usr_ip4_spec->proto)
3583 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003584
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003585 break;
3586 default:
3587 return -EOPNOTSUPP;
3588 }
3589
Jacob Keller0e588de2017-02-06 14:38:50 -08003590 /* First, clear all flexible filter entries */
3591 new_mask &= ~I40E_FLEX_INPUT_MASK;
3592
3593 /* If we have a flexible filter, try to add this offset to the correct
3594 * flexible filter PIT list. Once finished, we can update the mask.
3595 * If the src_offset changed, we will get a new mask value which will
3596 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003597 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003598 if (userdef->flex_filter) {
3599 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3600
3601 /* Flexible offset must be even, since the flexible payload
3602 * must be aligned on 2-byte boundary.
3603 */
3604 if (userdef->flex_offset & 0x1) {
3605 dev_warn(&pf->pdev->dev,
3606 "Flexible data offset must be 2-byte aligned\n");
3607 return -EINVAL;
3608 }
3609
3610 src_offset = userdef->flex_offset >> 1;
3611
3612 /* FLX_PIT source offset value is only so large */
3613 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3614 dev_warn(&pf->pdev->dev,
3615 "Flexible data must reside within first 64 bytes of the packet payload\n");
3616 return -EINVAL;
3617 }
3618
3619 /* See if this offset has already been programmed. If we get
3620 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3621 * if we get a NULL pointer, this means we will need to add
3622 * the offset.
3623 */
3624 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3625 src_offset);
3626 if (IS_ERR(flex_pit))
3627 return PTR_ERR(flex_pit);
3628
3629 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3630 * packet types, and thus we need to program both L3 and L4
3631 * flexible values. These must have identical flexible index,
3632 * as otherwise we can't correctly program the input set. So
3633 * we'll find both an L3 and L4 index and make sure they are
3634 * the same.
3635 */
3636 if (flex_l3) {
3637 l3_flex_pit =
3638 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3639 src_offset);
3640 if (IS_ERR(l3_flex_pit))
3641 return PTR_ERR(l3_flex_pit);
3642
3643 if (flex_pit) {
3644 /* If we already had a matching L4 entry, we
3645 * need to make sure that the L3 entry we
3646 * obtained uses the same index.
3647 */
3648 if (l3_flex_pit) {
3649 if (l3_flex_pit->pit_index !=
3650 flex_pit->pit_index) {
3651 return -EINVAL;
3652 }
3653 } else {
3654 new_flex_offset = true;
3655 }
3656 } else {
3657 flex_pit = l3_flex_pit;
3658 }
3659 }
3660
3661 /* If we didn't find an existing flex offset, we need to
3662 * program a new one. However, we don't immediately program it
3663 * here because we will wait to program until after we check
3664 * that it is safe to change the input set.
3665 */
3666 if (!flex_pit) {
3667 new_flex_offset = true;
3668 pit_index = i40e_unused_pit_index(pf);
3669 } else {
3670 pit_index = flex_pit->pit_index;
3671 }
3672
3673 /* Update the mask with the new offset */
3674 new_mask |= i40e_pit_index_to_mask(pit_index);
3675 }
3676
3677 /* If the mask and flexible filter offsets for this filter match the
3678 * currently programmed values we don't need any input set change, so
3679 * this filter is safe to install.
3680 */
3681 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003682 return 0;
3683
3684 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3685 i40e_flow_str(fsp));
3686 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003687 if (new_flex_offset) {
3688 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3689 pit_index, src_offset);
3690 }
Jacob Keller9229e992017-02-06 14:38:47 -08003691
3692 /* Hardware input sets are global across multiple ports, so even the
3693 * main port cannot change them when in MFP mode as this would impact
3694 * any filters on the other ports.
3695 */
3696 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3697 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003698 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003699 }
3700
3701 /* This filter requires us to update the input set. However, hardware
3702 * only supports one input set per flow type, and does not support
3703 * separate masks for each filter. This means that we can only support
3704 * a single mask for all filters of a specific type.
3705 *
3706 * If we have preexisting filters, they obviously depend on the
3707 * current programmed input set. Display a diagnostic message in this
3708 * case explaining why the filter could not be accepted.
3709 */
3710 if (*fdir_filter_count) {
3711 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3712 i40e_flow_str(fsp),
3713 *fdir_filter_count);
3714 return -EOPNOTSUPP;
3715 }
3716
3717 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003718
Jacob Keller0e588de2017-02-06 14:38:50 -08003719 /* Add the new offset and update table, if necessary */
3720 if (new_flex_offset) {
3721 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3722 pit_index);
3723 if (err)
3724 return err;
3725
3726 if (flex_l3) {
3727 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3728 src_offset,
3729 pit_index);
3730 if (err)
3731 return err;
3732 }
3733
3734 i40e_reprogram_flex_pit(pf);
3735 }
3736
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003737 return 0;
3738}
3739
3740/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003741 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003742 * @vsi: pointer to the targeted VSI
3743 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003744 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003745 * Add Flow Director filters for a specific flow spec based on their
3746 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003747 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003748static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3749 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003750{
Jacob Kellere7930952017-02-06 14:38:49 -08003751 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003752 struct ethtool_rx_flow_spec *fsp;
3753 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003754 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003755 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003756 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003757 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003758
3759 if (!vsi)
3760 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003761 pf = vsi->back;
3762
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003763 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3764 return -EOPNOTSUPP;
3765
Jacob Keller47994c12017-04-19 09:25:57 -04003766 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003767 return -ENOSPC;
3768
Jacob Keller0da36b92017-04-19 09:25:55 -04003769 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3770 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003771 return -EBUSY;
3772
Jacob Keller0da36b92017-04-19 09:25:55 -04003773 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003774 return -EBUSY;
3775
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003776 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3777
Jacob Kellere7930952017-02-06 14:38:49 -08003778 /* Parse the user-defined field */
3779 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3780 return -EINVAL;
3781
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003782 /* Extended MAC field is not supported */
3783 if (fsp->flow_type & FLOW_MAC_EXT)
3784 return -EINVAL;
3785
Jacob Keller0e588de2017-02-06 14:38:50 -08003786 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003787 if (ret)
3788 return ret;
3789
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003790 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3791 pf->hw.func_caps.fd_filters_guaranteed)) {
3792 return -EINVAL;
3793 }
3794
Jacob Keller43b15692017-02-06 14:38:48 -08003795 /* ring_cookie is either the drop index, or is a mask of the queue
3796 * index and VF id we wish to target.
3797 */
3798 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3799 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3800 } else {
3801 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3802 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3803
3804 if (!vf) {
3805 if (ring >= vsi->num_queue_pairs)
3806 return -EINVAL;
3807 dest_vsi = vsi->id;
3808 } else {
3809 /* VFs are zero-indexed, so we subtract one here */
3810 vf--;
3811
3812 if (vf >= pf->num_alloc_vfs)
3813 return -EINVAL;
3814 if (ring >= pf->vf[vf].num_queue_pairs)
3815 return -EINVAL;
3816 dest_vsi = pf->vf[vf].lan_vsi_id;
3817 }
3818 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3819 q_index = ring;
3820 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003821
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003822 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003823
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003824 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003825 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003826
3827 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003828 input->q_index = q_index;
3829 input->dest_vsi = dest_vsi;
3830 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003831 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04003832 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08003833 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3834 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08003835 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003836 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00003837
3838 /* Reverse the src and dest notion, since the HW expects them to be from
3839 * Tx perspective where as the input from user is from Rx filter view.
3840 */
3841 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
3842 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08003843 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3844 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003845
Jacob Keller0e588de2017-02-06 14:38:50 -08003846 if (userdef.flex_filter) {
3847 input->flex_filter = true;
3848 input->flex_word = cpu_to_be16(userdef.flex_word);
3849 input->flex_offset = userdef.flex_offset;
3850 }
3851
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003852 ret = i40e_add_del_fdir(vsi, input, true);
3853 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08003854 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003855
Jacob Keller01016da2017-02-06 14:38:40 -08003856 /* Add the input filter to the fdir_input_list, possibly replacing
3857 * a previous filter. Do not free the input structure after adding it
3858 * to the list as this would cause a use-after-free bug.
3859 */
3860 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
3861
3862 return 0;
3863
3864free_input:
3865 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003866 return ret;
3867}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003868
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003869/**
3870 * i40e_set_rxnfc - command to set RX flow classification rules
3871 * @netdev: network interface device structure
3872 * @cmd: ethtool rxnfc command
3873 *
3874 * Returns Success if the command is supported.
3875 **/
3876static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3877{
3878 struct i40e_netdev_priv *np = netdev_priv(netdev);
3879 struct i40e_vsi *vsi = np->vsi;
3880 struct i40e_pf *pf = vsi->back;
3881 int ret = -EOPNOTSUPP;
3882
3883 switch (cmd->cmd) {
3884 case ETHTOOL_SRXFH:
3885 ret = i40e_set_rss_hash_opt(pf, cmd);
3886 break;
3887 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003888 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003889 break;
3890 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003891 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003892 break;
3893 default:
3894 break;
3895 }
3896
3897 return ret;
3898}
3899
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003900/**
3901 * i40e_max_channels - get Max number of combined channels supported
3902 * @vsi: vsi pointer
3903 **/
3904static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
3905{
3906 /* TODO: This code assumes DCB and FD is disabled for now. */
3907 return vsi->alloc_queue_pairs;
3908}
3909
3910/**
3911 * i40e_get_channels - Get the current channels enabled and max supported etc.
3912 * @netdev: network interface device structure
3913 * @ch: ethtool channels structure
3914 *
3915 * We don't support separate tx and rx queues as channels. The other count
3916 * represents how many queues are being used for control. max_combined counts
3917 * how many queue pairs we can support. They may not be mapped 1 to 1 with
3918 * q_vectors since we support a lot more queue pairs than q_vectors.
3919 **/
3920static void i40e_get_channels(struct net_device *dev,
3921 struct ethtool_channels *ch)
3922{
3923 struct i40e_netdev_priv *np = netdev_priv(dev);
3924 struct i40e_vsi *vsi = np->vsi;
3925 struct i40e_pf *pf = vsi->back;
3926
3927 /* report maximum channels */
3928 ch->max_combined = i40e_max_channels(vsi);
3929
3930 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003931 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003932 ch->max_other = ch->other_count;
3933
3934 /* Note: This code assumes DCB is disabled for now. */
3935 ch->combined_count = vsi->num_queue_pairs;
3936}
3937
3938/**
3939 * i40e_set_channels - Set the new channels count.
3940 * @netdev: network interface device structure
3941 * @ch: ethtool channels structure
3942 *
3943 * The new channels count may not be the same as requested by the user
3944 * since it gets rounded down to a power of 2 value.
3945 **/
3946static int i40e_set_channels(struct net_device *dev,
3947 struct ethtool_channels *ch)
3948{
Jacob Keller59826d92016-07-27 12:02:35 -07003949 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003950 struct i40e_netdev_priv *np = netdev_priv(dev);
3951 unsigned int count = ch->combined_count;
3952 struct i40e_vsi *vsi = np->vsi;
3953 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07003954 struct i40e_fdir_filter *rule;
3955 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003956 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07003957 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003958
3959 /* We do not support setting channels for any other VSI at present */
3960 if (vsi->type != I40E_VSI_MAIN)
3961 return -EINVAL;
3962
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07003963 /* We do not support setting channels via ethtool when TCs are
3964 * configured through mqprio
3965 */
3966 if (pf->flags & I40E_FLAG_TC_MQPRIO)
3967 return -EINVAL;
3968
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003969 /* verify they are not requesting separate vectors */
3970 if (!count || ch->rx_count || ch->tx_count)
3971 return -EINVAL;
3972
3973 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003974 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003975 return -EINVAL;
3976
3977 /* verify the number of channels does not exceed hardware limits */
3978 if (count > i40e_max_channels(vsi))
3979 return -EINVAL;
3980
Jacob Keller59826d92016-07-27 12:02:35 -07003981 /* verify that the number of channels does not invalidate any current
3982 * flow director rules
3983 */
3984 hlist_for_each_entry_safe(rule, node2,
3985 &pf->fdir_filter_list, fdir_node) {
3986 if (rule->dest_ctl != drop && count <= rule->q_index) {
3987 dev_warn(&pf->pdev->dev,
3988 "Existing user defined filter %d assigns flow to queue %d\n",
3989 rule->fd_id, rule->q_index);
3990 err = -EINVAL;
3991 }
3992 }
3993
3994 if (err) {
3995 dev_err(&pf->pdev->dev,
3996 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
3997 count);
3998 return err;
3999 }
4000
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004001 /* update feature limits from largest to smallest supported values */
4002 /* TODO: Flow director limit, DCB etc */
4003
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004004 /* use rss_reconfig to rebuild with new queue count and update traffic
4005 * class queue mapping
4006 */
4007 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004008 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004009 return 0;
4010 else
4011 return -EINVAL;
4012}
4013
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004014/**
4015 * i40e_get_rxfh_key_size - get the RSS hash key size
4016 * @netdev: network interface device structure
4017 *
4018 * Returns the table size.
4019 **/
4020static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4021{
4022 return I40E_HKEY_ARRAY_SIZE;
4023}
4024
4025/**
4026 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4027 * @netdev: network interface device structure
4028 *
4029 * Returns the table size.
4030 **/
4031static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4032{
4033 return I40E_HLUT_ARRAY_SIZE;
4034}
4035
Alan Brady21675bd2017-10-05 14:53:33 -07004036/**
4037 * i40e_get_rxfh - get the rx flow hash indirection table
4038 * @netdev: network interface device structure
4039 * @indir: indirection table
4040 * @key: hash key
4041 * @hfunc: hash function
4042 *
4043 * Reads the indirection table directly from the hardware. Returns 0 on
4044 * success.
4045 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004046static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4047 u8 *hfunc)
4048{
4049 struct i40e_netdev_priv *np = netdev_priv(netdev);
4050 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004051 u8 *lut, *seed = NULL;
4052 int ret;
4053 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004054
4055 if (hfunc)
4056 *hfunc = ETH_RSS_HASH_TOP;
4057
4058 if (!indir)
4059 return 0;
4060
Helin Zhang043dd652015-10-21 19:56:23 -04004061 seed = key;
4062 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4063 if (!lut)
4064 return -ENOMEM;
4065 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4066 if (ret)
4067 goto out;
4068 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4069 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004070
Helin Zhang043dd652015-10-21 19:56:23 -04004071out:
4072 kfree(lut);
4073
4074 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004075}
4076
4077/**
4078 * i40e_set_rxfh - set the rx flow hash indirection table
4079 * @netdev: network interface device structure
4080 * @indir: indirection table
4081 * @key: hash key
4082 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004083 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004084 * returns 0 after programming the table.
4085 **/
4086static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4087 const u8 *key, const u8 hfunc)
4088{
4089 struct i40e_netdev_priv *np = netdev_priv(netdev);
4090 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004091 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004092 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004093 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004094
4095 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4096 return -EOPNOTSUPP;
4097
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004098 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004099 if (!vsi->rss_hkey_user) {
4100 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4101 GFP_KERNEL);
4102 if (!vsi->rss_hkey_user)
4103 return -ENOMEM;
4104 }
4105 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4106 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004107 }
Helin Zhang28c58692015-10-26 19:44:27 -04004108 if (!vsi->rss_lut_user) {
4109 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4110 if (!vsi->rss_lut_user)
4111 return -ENOMEM;
4112 }
Helin Zhang043dd652015-10-21 19:56:23 -04004113
Helin Zhang28c58692015-10-26 19:44:27 -04004114 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004115 if (indir)
4116 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4117 vsi->rss_lut_user[i] = (u8)(indir[i]);
4118 else
4119 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4120 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004121
4122 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4123 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004124}
4125
Greg Rose7e45ab42015-02-06 08:52:19 +00004126/**
4127 * i40e_get_priv_flags - report device private flags
4128 * @dev: network interface device structure
4129 *
4130 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004131 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004132 * array.
4133 *
4134 * Returns a u32 bitmap of flags.
4135 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004136static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004137{
4138 struct i40e_netdev_priv *np = netdev_priv(dev);
4139 struct i40e_vsi *vsi = np->vsi;
4140 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004141 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004142
Alexander Duyckaca955d2017-03-10 12:22:01 -08004143 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4144 const struct i40e_priv_flags *priv_flags;
4145
4146 priv_flags = &i40e_gstrings_priv_flags[i];
4147
4148 if (priv_flags->flag & pf->flags)
4149 ret_flags |= BIT(i);
4150 }
4151
4152 if (pf->hw.pf_id != 0)
4153 return ret_flags;
4154
4155 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4156 const struct i40e_priv_flags *priv_flags;
4157
4158 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4159
4160 if (priv_flags->flag & pf->flags)
4161 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004162 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004163
4164 return ret_flags;
4165}
4166
Shannon Nelson9ac77262015-08-27 11:42:40 -04004167/**
4168 * i40e_set_priv_flags - set private flags
4169 * @dev: network interface device structure
4170 * @flags: bit flags to be set
4171 **/
4172static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4173{
4174 struct i40e_netdev_priv *np = netdev_priv(dev);
4175 struct i40e_vsi *vsi = np->vsi;
4176 struct i40e_pf *pf = vsi->back;
Jacob Kellerb74f5712017-09-01 13:54:07 -07004177 u32 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004178 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004179
Jacob Keller841c9502017-06-23 04:24:50 -04004180 orig_flags = READ_ONCE(pf->flags);
4181 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004182
Alexander Duyckaca955d2017-03-10 12:22:01 -08004183 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4184 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004185
Alexander Duyckaca955d2017-03-10 12:22:01 -08004186 priv_flags = &i40e_gstrings_priv_flags[i];
4187
Alexander Duyckaca955d2017-03-10 12:22:01 -08004188 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004189 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004190 else
Jacob Keller841c9502017-06-23 04:24:50 -04004191 new_flags &= ~(priv_flags->flag);
4192
4193 /* If this is a read-only flag, it can't be changed */
4194 if (priv_flags->read_only &&
4195 ((orig_flags ^ new_flags) & ~BIT(i)))
4196 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004197 }
4198
4199 if (pf->hw.pf_id != 0)
4200 goto flags_complete;
4201
4202 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4203 const struct i40e_priv_flags *priv_flags;
4204
4205 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4206
Alexander Duyckaca955d2017-03-10 12:22:01 -08004207 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004208 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004209 else
Jacob Keller841c9502017-06-23 04:24:50 -04004210 new_flags &= ~(priv_flags->flag);
4211
4212 /* If this is a read-only flag, it can't be changed */
4213 if (priv_flags->read_only &&
4214 ((orig_flags ^ new_flags) & ~BIT(i)))
4215 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004216 }
4217
4218flags_complete:
Jacob Keller841c9502017-06-23 04:24:50 -04004219 /* Before we finalize any flag changes, we need to perform some
4220 * checks to ensure that the changes are supported and safe.
4221 */
4222
4223 /* ATR eviction is not supported on all devices */
4224 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4225 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4226 return -EOPNOTSUPP;
4227
4228 /* Compare and exchange the new flags into place. If we failed, that
Jacob Kellerb74f5712017-09-01 13:54:07 -07004229 * is if cmpxchg returns anything but the old value, this means that
Jacob Keller841c9502017-06-23 04:24:50 -04004230 * something else has modified the flags variable since we copied it
4231 * originally. We'll just punt with an error and log something in the
4232 * message buffer.
4233 */
Jacob Kellerb74f5712017-09-01 13:54:07 -07004234 if (cmpxchg(&pf->flags, orig_flags, new_flags) != orig_flags) {
Jacob Keller841c9502017-06-23 04:24:50 -04004235 dev_warn(&pf->pdev->dev,
4236 "Unable to update pf->flags as it was modified by another thread...\n");
4237 return -EAGAIN;
4238 }
4239
4240 changed_flags = orig_flags ^ new_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004241
4242 /* Process any additional changes needed as a result of flag changes.
4243 * The changed_flags value reflects the list of bits that were
4244 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004245 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004246
Alexander Duyckaca955d2017-03-10 12:22:01 -08004247 /* Flush current ATR settings if ATR was disabled */
4248 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4249 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004250 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004251 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004252 }
4253
Alexander Duyckaca955d2017-03-10 12:22:01 -08004254 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4255 u16 sw_flags = 0, valid_flags = 0;
4256 int ret;
4257
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004258 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4259 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4260 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4261 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4262 NULL);
4263 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4264 dev_info(&pf->pdev->dev,
4265 "couldn't set switch config bits, err %s aq_err %s\n",
4266 i40e_stat_str(&pf->hw, ret),
4267 i40e_aq_str(&pf->hw,
4268 pf->hw.aq.asq_last_status));
4269 /* not a fatal problem, just keep going */
4270 }
4271 }
4272
Alexander Duyckaca955d2017-03-10 12:22:01 -08004273 /* Issue reset to cause things to take effect, as additional bits
4274 * are added we will need to create a mask of bits requiring reset
4275 */
Mitch Williams64615b52017-08-29 05:32:30 -04004276 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4277 I40E_FLAG_LEGACY_RX |
4278 I40E_FLAG_SOURCE_PRUNING_DISABLED))
Maciej Sosin373149f2017-04-05 07:50:55 -04004279 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004280
Shannon Nelson9ac77262015-08-27 11:42:40 -04004281 return 0;
4282}
4283
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004284/**
4285 * i40e_get_module_info - get (Q)SFP+ module type info
4286 * @netdev: network interface device structure
4287 * @modinfo: module EEPROM size and layout information structure
4288 **/
4289static int i40e_get_module_info(struct net_device *netdev,
4290 struct ethtool_modinfo *modinfo)
4291{
4292 struct i40e_netdev_priv *np = netdev_priv(netdev);
4293 struct i40e_vsi *vsi = np->vsi;
4294 struct i40e_pf *pf = vsi->back;
4295 struct i40e_hw *hw = &pf->hw;
4296 u32 sff8472_comp = 0;
4297 u32 sff8472_swap = 0;
4298 u32 sff8636_rev = 0;
4299 i40e_status status;
4300 u32 type = 0;
4301
4302 /* Check if firmware supports reading module EEPROM. */
4303 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4304 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4305 return -EINVAL;
4306 }
4307
4308 status = i40e_update_link_info(hw);
4309 if (status)
4310 return -EIO;
4311
4312 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4313 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4314 return -EINVAL;
4315 }
4316
4317 type = hw->phy.link_info.module_type[0];
4318
4319 switch (type) {
4320 case I40E_MODULE_TYPE_SFP:
4321 status = i40e_aq_get_phy_register(hw,
4322 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4323 I40E_I2C_EEPROM_DEV_ADDR,
4324 I40E_MODULE_SFF_8472_COMP,
4325 &sff8472_comp, NULL);
4326 if (status)
4327 return -EIO;
4328
4329 status = i40e_aq_get_phy_register(hw,
4330 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4331 I40E_I2C_EEPROM_DEV_ADDR,
4332 I40E_MODULE_SFF_8472_SWAP,
4333 &sff8472_swap, NULL);
4334 if (status)
4335 return -EIO;
4336
4337 /* Check if the module requires address swap to access
4338 * the other EEPROM memory page.
4339 */
4340 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4341 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4342 modinfo->type = ETH_MODULE_SFF_8079;
4343 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4344 } else if (sff8472_comp == 0x00) {
4345 /* Module is not SFF-8472 compliant */
4346 modinfo->type = ETH_MODULE_SFF_8079;
4347 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4348 } else {
4349 modinfo->type = ETH_MODULE_SFF_8472;
4350 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4351 }
4352 break;
4353 case I40E_MODULE_TYPE_QSFP_PLUS:
4354 /* Read from memory page 0. */
4355 status = i40e_aq_get_phy_register(hw,
4356 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4357 0,
4358 I40E_MODULE_REVISION_ADDR,
4359 &sff8636_rev, NULL);
4360 if (status)
4361 return -EIO;
4362 /* Determine revision compliance byte */
4363 if (sff8636_rev > 0x02) {
4364 /* Module is SFF-8636 compliant */
4365 modinfo->type = ETH_MODULE_SFF_8636;
4366 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4367 } else {
4368 modinfo->type = ETH_MODULE_SFF_8436;
4369 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4370 }
4371 break;
4372 case I40E_MODULE_TYPE_QSFP28:
4373 modinfo->type = ETH_MODULE_SFF_8636;
4374 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4375 break;
4376 default:
4377 netdev_err(vsi->netdev, "Module type unrecognized\n");
4378 return -EINVAL;
4379 }
4380 return 0;
4381}
4382
4383/**
4384 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4385 * @netdev: network interface device structure
4386 * @ee: EEPROM dump request structure
4387 * @data: buffer to be filled with EEPROM contents
4388 **/
4389static int i40e_get_module_eeprom(struct net_device *netdev,
4390 struct ethtool_eeprom *ee,
4391 u8 *data)
4392{
4393 struct i40e_netdev_priv *np = netdev_priv(netdev);
4394 struct i40e_vsi *vsi = np->vsi;
4395 struct i40e_pf *pf = vsi->back;
4396 struct i40e_hw *hw = &pf->hw;
4397 bool is_sfp = false;
4398 i40e_status status;
4399 u32 value = 0;
4400 int i;
4401
4402 if (!ee || !ee->len || !data)
4403 return -EINVAL;
4404
4405 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4406 is_sfp = true;
4407
4408 for (i = 0; i < ee->len; i++) {
4409 u32 offset = i + ee->offset;
4410 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4411
4412 /* Check if we need to access the other memory page */
4413 if (is_sfp) {
4414 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4415 offset -= ETH_MODULE_SFF_8079_LEN;
4416 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4417 }
4418 } else {
4419 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4420 /* Compute memory page number and offset. */
4421 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4422 addr++;
4423 }
4424 }
4425
4426 status = i40e_aq_get_phy_register(hw,
4427 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4428 addr, offset, &value, NULL);
4429 if (status)
4430 return -EIO;
4431 data[i] = value;
4432 }
4433 return 0;
4434}
4435
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004436static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004437 .get_drvinfo = i40e_get_drvinfo,
4438 .get_regs_len = i40e_get_regs_len,
4439 .get_regs = i40e_get_regs,
4440 .nway_reset = i40e_nway_reset,
4441 .get_link = ethtool_op_get_link,
4442 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004443 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004444 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004445 .get_eeprom_len = i40e_get_eeprom_len,
4446 .get_eeprom = i40e_get_eeprom,
4447 .get_ringparam = i40e_get_ringparam,
4448 .set_ringparam = i40e_set_ringparam,
4449 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004450 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004451 .get_msglevel = i40e_get_msglevel,
4452 .set_msglevel = i40e_set_msglevel,
4453 .get_rxnfc = i40e_get_rxnfc,
4454 .set_rxnfc = i40e_set_rxnfc,
4455 .self_test = i40e_diag_test,
4456 .get_strings = i40e_get_strings,
4457 .set_phys_id = i40e_set_phys_id,
4458 .get_sset_count = i40e_get_sset_count,
4459 .get_ethtool_stats = i40e_get_ethtool_stats,
4460 .get_coalesce = i40e_get_coalesce,
4461 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004462 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4463 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4464 .get_rxfh = i40e_get_rxfh,
4465 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004466 .get_channels = i40e_get_channels,
4467 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004468 .get_module_info = i40e_get_module_info,
4469 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004470 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004471 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004472 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004473 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004474 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004475 .get_link_ksettings = i40e_get_link_ksettings,
4476 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004477};
4478
4479void i40e_set_ethtool_ops(struct net_device *netdev)
4480{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004481 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004482}