blob: cfd788b4fd7a0bf53589bc1312d5236f9143c004 [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 }
346 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);
Catherine Sullivan06566e52016-05-03 15:13:14 -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);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700368 }
Alan Brady1eaae512017-10-05 14:53:41 -0700369 /* 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 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800385 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
Alan Brady1eaae512017-10-05 14:53:41 -0700386 ethtool_link_ksettings_add_link_mode(ks, supported,
387 25000baseSR_Full);
388 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
389 ethtool_link_ksettings_add_link_mode(ks, advertising,
390 25000baseSR_Full);
391 }
392 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
393 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
394 ethtool_link_ksettings_add_link_mode(ks, supported,
395 25000baseCR_Full);
396 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
397 ethtool_link_ksettings_add_link_mode(ks, advertising,
398 25000baseCR_Full);
399 }
400 /* need to add new 10G PHY types */
401 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
402 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
403 ethtool_link_ksettings_add_link_mode(ks, supported,
404 10000baseCR_Full);
405 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
406 ethtool_link_ksettings_add_link_mode(ks, advertising,
407 10000baseCR_Full);
408 }
409 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
410 ethtool_link_ksettings_add_link_mode(ks, supported,
411 10000baseSR_Full);
412 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
413 ethtool_link_ksettings_add_link_mode(ks, advertising,
414 10000baseSR_Full);
415 }
416 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
417 ethtool_link_ksettings_add_link_mode(ks, supported,
418 10000baseLR_Full);
419 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
420 ethtool_link_ksettings_add_link_mode(ks, advertising,
421 10000baseLR_Full);
422 }
423 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
424 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
425 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
426 ethtool_link_ksettings_add_link_mode(ks, supported,
427 1000baseX_Full);
428 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
429 ethtool_link_ksettings_add_link_mode(ks, advertising,
430 1000baseX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700431 }
432 /* Autoneg PHY types */
433 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
434 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
435 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
436 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800437 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700438 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
439 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
440 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
441 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
442 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
443 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
444 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
445 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
446 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
447 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
448 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
449 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
450 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
451 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
452 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
453 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
454 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700455 ethtool_link_ksettings_add_link_mode(ks, supported,
456 Autoneg);
457 ethtool_link_ksettings_add_link_mode(ks, advertising,
458 Autoneg);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800459 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700460}
461
462/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000463 * i40e_get_settings_link_up - Get the Link settings for when link is up
464 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700465 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000466 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700467 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000468 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000469static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700470 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400471 struct net_device *netdev,
472 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000473{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000474 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Alan Brady1eaae512017-10-05 14:53:41 -0700475 struct ethtool_link_ksettings cap_ksettings;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000476 u32 link_speed = hw_link_info->link_speed;
477
Catherine Sullivane8278452015-02-06 08:52:08 +0000478 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000479 switch (hw_link_info->phy_type) {
480 case I40E_PHY_TYPE_40GBASE_CR4:
481 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Alan Brady79f04a32017-10-05 14:53:42 -0700482 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
483 ethtool_link_ksettings_add_link_mode(ks, supported,
484 40000baseCR4_Full);
485 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
486 ethtool_link_ksettings_add_link_mode(ks, advertising,
487 40000baseCR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000488 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000489 case I40E_PHY_TYPE_XLAUI:
490 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000491 case I40E_PHY_TYPE_40GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700492 ethtool_link_ksettings_add_link_mode(ks, supported,
493 40000baseCR4_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000494 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000495 case I40E_PHY_TYPE_40GBASE_SR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700496 ethtool_link_ksettings_add_link_mode(ks, supported,
497 40000baseSR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 break;
499 case I40E_PHY_TYPE_40GBASE_LR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700500 ethtool_link_ksettings_add_link_mode(ks, supported,
501 40000baseLR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000502 break;
Alan Brady79f04a32017-10-05 14:53:42 -0700503 case I40E_PHY_TYPE_25GBASE_SR:
504 case I40E_PHY_TYPE_25GBASE_LR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000505 case I40E_PHY_TYPE_10GBASE_SR:
506 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000507 case I40E_PHY_TYPE_1000BASE_SX:
508 case I40E_PHY_TYPE_1000BASE_LX:
Alan Brady79f04a32017-10-05 14:53:42 -0700509 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
510 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
511 ethtool_link_ksettings_add_link_mode(ks, supported,
512 25000baseSR_Full);
513 ethtool_link_ksettings_add_link_mode(ks, advertising,
514 25000baseSR_Full);
515 ethtool_link_ksettings_add_link_mode(ks, supported,
516 10000baseSR_Full);
517 ethtool_link_ksettings_add_link_mode(ks, advertising,
518 10000baseSR_Full);
519 ethtool_link_ksettings_add_link_mode(ks, supported,
520 10000baseLR_Full);
521 ethtool_link_ksettings_add_link_mode(ks, advertising,
522 10000baseLR_Full);
523 ethtool_link_ksettings_add_link_mode(ks, supported,
524 1000baseX_Full);
525 ethtool_link_ksettings_add_link_mode(ks, advertising,
526 1000baseX_Full);
527 ethtool_link_ksettings_add_link_mode(ks, supported,
528 10000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400529 if (hw_link_info->module_type[2] &
530 I40E_MODULE_TYPE_1000BASE_SX ||
531 hw_link_info->module_type[2] &
532 I40E_MODULE_TYPE_1000BASE_LX) {
Alan Brady79f04a32017-10-05 14:53:42 -0700533 ethtool_link_ksettings_add_link_mode(ks, supported,
534 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400535 if (hw_link_info->requested_speeds &
536 I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700537 ethtool_link_ksettings_add_link_mode(
538 ks, advertising, 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400539 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000540 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700541 ethtool_link_ksettings_add_link_mode(ks, advertising,
542 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000543 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000544 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000545 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700546 case I40E_PHY_TYPE_100BASE_TX:
Alan Brady79f04a32017-10-05 14:53:42 -0700547 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
548 ethtool_link_ksettings_add_link_mode(ks, supported,
549 10000baseT_Full);
550 ethtool_link_ksettings_add_link_mode(ks, supported,
551 1000baseT_Full);
552 ethtool_link_ksettings_add_link_mode(ks, supported,
553 100baseT_Full);
554 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivane8278452015-02-06 08:52:08 +0000555 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700556 ethtool_link_ksettings_add_link_mode(ks, advertising,
557 10000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000558 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700559 ethtool_link_ksettings_add_link_mode(ks, advertising,
560 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700561 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700562 ethtool_link_ksettings_add_link_mode(ks, advertising,
563 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400564 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400565 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Alan Brady79f04a32017-10-05 14:53:42 -0700566 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
567 ethtool_link_ksettings_add_link_mode(ks, supported,
568 1000baseT_Full);
569 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
570 ethtool_link_ksettings_add_link_mode(ks, advertising,
571 1000baseT_Full);
Catherine Sullivan48becae2015-09-28 14:12:41 -0400572 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000573 case I40E_PHY_TYPE_10GBASE_CR1_CU:
574 case I40E_PHY_TYPE_10GBASE_CR1:
Alan Brady79f04a32017-10-05 14:53:42 -0700575 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
576 ethtool_link_ksettings_add_link_mode(ks, supported,
577 10000baseT_Full);
578 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
579 ethtool_link_ksettings_add_link_mode(ks, advertising,
580 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000581 break;
582 case I40E_PHY_TYPE_XAUI:
583 case I40E_PHY_TYPE_XFI:
584 case I40E_PHY_TYPE_SFI:
585 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000586 case I40E_PHY_TYPE_10GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700587 ethtool_link_ksettings_add_link_mode(ks, supported,
588 10000baseT_Full);
589 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
590 ethtool_link_ksettings_add_link_mode(ks, advertising,
591 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000592 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000593 case I40E_PHY_TYPE_SGMII:
Alan Brady79f04a32017-10-05 14:53:42 -0700594 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
595 ethtool_link_ksettings_add_link_mode(ks, supported,
596 1000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000597 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700598 ethtool_link_ksettings_add_link_mode(ks, advertising,
599 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400600 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady79f04a32017-10-05 14:53:42 -0700601 ethtool_link_ksettings_add_link_mode(ks, supported,
602 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400603 if (hw_link_info->requested_speeds &
604 I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700605 ethtool_link_ksettings_add_link_mode(
606 ks, advertising, 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400607 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000608 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400609 case I40E_PHY_TYPE_40GBASE_KR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700610 case I40E_PHY_TYPE_25GBASE_KR:
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400611 case I40E_PHY_TYPE_20GBASE_KR2:
612 case I40E_PHY_TYPE_10GBASE_KR:
613 case I40E_PHY_TYPE_10GBASE_KX4:
614 case I40E_PHY_TYPE_1000BASE_KX:
Alan Brady79f04a32017-10-05 14:53:42 -0700615 ethtool_link_ksettings_add_link_mode(ks, supported,
616 40000baseKR4_Full);
617 ethtool_link_ksettings_add_link_mode(ks, supported,
618 25000baseKR_Full);
619 ethtool_link_ksettings_add_link_mode(ks, supported,
620 20000baseKR2_Full);
621 ethtool_link_ksettings_add_link_mode(ks, supported,
622 10000baseKR_Full);
623 ethtool_link_ksettings_add_link_mode(ks, supported,
624 10000baseKX4_Full);
625 ethtool_link_ksettings_add_link_mode(ks, supported,
626 1000baseKX_Full);
627 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
628 ethtool_link_ksettings_add_link_mode(ks, advertising,
629 40000baseKR4_Full);
630 ethtool_link_ksettings_add_link_mode(ks, advertising,
631 25000baseKR_Full);
632 ethtool_link_ksettings_add_link_mode(ks, advertising,
633 20000baseKR2_Full);
634 ethtool_link_ksettings_add_link_mode(ks, advertising,
635 10000baseKR_Full);
636 ethtool_link_ksettings_add_link_mode(ks, advertising,
637 10000baseKX4_Full);
638 ethtool_link_ksettings_add_link_mode(ks, advertising,
639 1000baseKX_Full);
640 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400641 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800642 case I40E_PHY_TYPE_25GBASE_CR:
Alan Brady79f04a32017-10-05 14:53:42 -0700643 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
644 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
645 ethtool_link_ksettings_add_link_mode(ks, supported,
646 25000baseCR_Full);
647 ethtool_link_ksettings_add_link_mode(ks, advertising,
648 25000baseCR_Full);
649 break;
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700650 case I40E_PHY_TYPE_25GBASE_AOC:
651 case I40E_PHY_TYPE_25GBASE_ACC:
Alan Brady79f04a32017-10-05 14:53:42 -0700652 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
653 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
654 ethtool_link_ksettings_add_link_mode(ks, supported,
655 25000baseCR_Full);
656
657 ethtool_link_ksettings_add_link_mode(ks, advertising,
658 25000baseCR_Full);
659 ethtool_link_ksettings_add_link_mode(ks, supported,
660 10000baseCR_Full);
661 ethtool_link_ksettings_add_link_mode(ks, advertising,
662 10000baseCR_Full);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800663 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000664 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000665 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700666 netdev_info(netdev,
667 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000668 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000669 }
670
Catherine Sullivan06566e52016-05-03 15:13:14 -0700671 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700672 * current PHY type, get what is supported by the NVM and intersect
673 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700674 */
Alan Brady1eaae512017-10-05 14:53:41 -0700675 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
676 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
677 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700678
Catherine Sullivane8278452015-02-06 08:52:08 +0000679 /* Set speed and duplex */
680 switch (link_speed) {
681 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700682 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000683 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800684 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700685 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800686 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700687 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700688 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700689 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000690 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700691 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000692 break;
693 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700694 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000695 break;
696 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700697 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000698 break;
699 default:
700 break;
701 }
Alan Brady1c142e12017-10-05 14:53:31 -0700702 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000703}
704
705/**
706 * i40e_get_settings_link_down - Get the Link settings for when link is down
707 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700708 * @ks: ethtool ksettings to fill in
709 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000710 *
711 * Reports link settings that can be determined when link is down
712 **/
713static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700714 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400715 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000716{
Catherine Sullivane8278452015-02-06 08:52:08 +0000717 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400718 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000719 */
Alan Brady1eaae512017-10-05 14:53:41 -0700720 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000721
722 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700723 ks->base.speed = SPEED_UNKNOWN;
724 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000725}
726
727/**
Alan Brady1c142e12017-10-05 14:53:31 -0700728 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000729 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700730 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000731 *
732 * Reports speed/duplex settings based on media_type
733 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100734static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700735 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000736{
737 struct i40e_netdev_priv *np = netdev_priv(netdev);
738 struct i40e_pf *pf = np->vsi->back;
739 struct i40e_hw *hw = &pf->hw;
740 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
741 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700742
743 ethtool_link_ksettings_zero_link_mode(ks, supported);
744 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000745
746 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700747 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000748 else
Alan Brady1c142e12017-10-05 14:53:31 -0700749 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000750
751 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000752 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700753 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
754 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000755
Alan Bradya03af692017-10-05 14:53:37 -0700756 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000757 switch (hw->phy.media_type) {
758 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700759 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
760 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
761 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700762 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100763 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700764 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000765 break;
766 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700767 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
768 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
769 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000770 break;
771 case I40E_MEDIA_TYPE_DA:
772 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700773 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
774 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
775 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000776 break;
777 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700778 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
779 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000780 break;
781 case I40E_MEDIA_TYPE_UNKNOWN:
782 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700783 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000784 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000785 }
786
Catherine Sullivane8278452015-02-06 08:52:08 +0000787 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700788 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000789
Catherine Sullivane8278452015-02-06 08:52:08 +0000790 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000791 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700792 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000793 break;
794 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700795 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100796 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000797 break;
798 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700799 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700800 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100801 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000802 break;
803 default:
Alan Brady5f434992017-10-05 14:53:34 -0700804 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
805 ethtool_link_ksettings_del_link_mode(ks, advertising,
806 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000807 break;
808 }
809
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000810 return 0;
811}
812
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000813/**
Alan Brady1c142e12017-10-05 14:53:31 -0700814 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000815 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700816 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000817 *
818 * Set speed/duplex per media_types advertised/forced
819 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100820static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700821 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000822{
823 struct i40e_netdev_priv *np = netdev_priv(netdev);
824 struct i40e_aq_get_phy_abilities_resp abilities;
Alan Brady636b62d2017-10-05 14:53:43 -0700825 struct ethtool_link_ksettings safe_ks;
826 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000827 struct i40e_aq_set_phy_config config;
828 struct i40e_pf *pf = np->vsi->back;
829 struct i40e_vsi *vsi = np->vsi;
830 struct i40e_hw *hw = &pf->hw;
Alan Brady636b62d2017-10-05 14:53:43 -0700831 bool autoneg_changed = false;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000832 i40e_status status = 0;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400833 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000834 int err = 0;
Alan Bradycee91992017-10-05 14:53:44 -0700835 u8 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000836
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000837 /* Changing port settings is not supported if this isn't the
838 * port's controlling PF
839 */
840 if (hw->partition_id != 1) {
841 i40e_partition_setting_complaint(pf);
842 return -EOPNOTSUPP;
843 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000844 if (vsi != pf->vsi[pf->lan_vsi])
845 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000846 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
847 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000848 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700849 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000850 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000851 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400852 if (hw->device_id == I40E_DEV_ID_KX_B ||
853 hw->device_id == I40E_DEV_ID_KX_C ||
854 hw->device_id == I40E_DEV_ID_20G_KR2 ||
855 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
856 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
857 return -EOPNOTSUPP;
858 }
859
Alan Brady1c142e12017-10-05 14:53:31 -0700860 /* copy the ksettings to copy_ks to avoid modifying the origin */
861 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000862
Alan Bradycee91992017-10-05 14:53:44 -0700863 /* save autoneg out of ksettings */
864 autoneg = copy_ks.base.autoneg;
865
866 memset(&safe_ks, 0, sizeof(safe_ks));
867 /* Get link modes supported by hardware and check against modes
868 * requested by the user. Return an error if unsupported mode was set.
869 */
870 i40e_phy_type_to_ethtool(pf, &safe_ks);
871 if (!bitmap_subset(copy_ks.link_modes.advertising,
872 safe_ks.link_modes.supported,
873 __ETHTOOL_LINK_MODE_MASK_NBITS))
874 return -EINVAL;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000875
Philippe Reynesa7f90942017-02-04 22:05:06 +0100876 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700877 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
Alan Bradycee91992017-10-05 14:53:44 -0700878 safe_ks.base.cmd = copy_ks.base.cmd;
879 safe_ks.base.link_mode_masks_nwords =
880 copy_ks.base.link_mode_masks_nwords;
Alan Brady1c142e12017-10-05 14:53:31 -0700881 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100882
Alan Bradycee91992017-10-05 14:53:44 -0700883 /* set autoneg back to what it currently is */
Alan Brady1c142e12017-10-05 14:53:31 -0700884 copy_ks.base.autoneg = safe_ks.base.autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000885
Alan Bradycee91992017-10-05 14:53:44 -0700886 /* If copy_ks.base and safe_ks.base are not the same now, then they are
887 * trying to set something that we do not support.
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000888 */
Alan Bradycee91992017-10-05 14:53:44 -0700889 if (memcmp(&copy_ks.base, &safe_ks.base,
890 sizeof(struct ethtool_link_settings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000891 return -EOPNOTSUPP;
892
Jacob Keller0da36b92017-04-19 09:25:55 -0400893 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400894 timeout--;
895 if (!timeout)
896 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000897 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400898 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000899
900 /* Get the current phy config */
901 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
902 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400903 if (status) {
904 err = -EAGAIN;
905 goto done;
906 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000907
Catherine Sullivan124ed152014-07-12 07:28:12 +0000908 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000909 * set below
910 */
911 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000912 config.abilities = abilities.abilities;
913
914 /* Check autoneg */
915 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000916 /* If autoneg was not already enabled */
917 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400918 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700919 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
920 supported,
921 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400922 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400923 err = -EINVAL;
924 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400925 }
926 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000927 config.abilities = abilities.abilities |
928 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700929 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000930 }
931 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000932 /* If autoneg is currently enabled */
933 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400934 /* If autoneg is supported 10GBASE_T is the only PHY
935 * that can disable it, so otherwise return error
936 */
Alan Brady1c142e12017-10-05 14:53:31 -0700937 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
938 supported,
939 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400940 hw->phy.link_info.phy_type !=
941 I40E_PHY_TYPE_10GBASE_T) {
942 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400943 err = -EINVAL;
944 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400945 }
946 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000947 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000948 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700949 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000950 }
951 }
952
Alan Bradycee91992017-10-05 14:53:44 -0700953 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
954 100baseT_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000955 config.link_speed |= I40E_LINK_SPEED_100MB;
Alan Bradycee91992017-10-05 14:53:44 -0700956 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
957 1000baseT_Full) ||
958 ethtool_link_ksettings_test_link_mode(ks, advertising,
959 1000baseX_Full) ||
960 ethtool_link_ksettings_test_link_mode(ks, advertising,
961 1000baseKX_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000962 config.link_speed |= I40E_LINK_SPEED_1GB;
Alan Bradycee91992017-10-05 14:53:44 -0700963 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
964 10000baseT_Full) ||
965 ethtool_link_ksettings_test_link_mode(ks, advertising,
966 10000baseKX4_Full) ||
967 ethtool_link_ksettings_test_link_mode(ks, advertising,
968 10000baseKR_Full) ||
969 ethtool_link_ksettings_test_link_mode(ks, advertising,
970 10000baseCR_Full) ||
971 ethtool_link_ksettings_test_link_mode(ks, advertising,
972 10000baseSR_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000973 config.link_speed |= I40E_LINK_SPEED_10GB;
Alan Bradycee91992017-10-05 14:53:44 -0700974 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
975 20000baseKR2_Full))
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700976 config.link_speed |= I40E_LINK_SPEED_20GB;
Alan Bradycee91992017-10-05 14:53:44 -0700977 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
978 25000baseCR_Full) ||
979 ethtool_link_ksettings_test_link_mode(ks, advertising,
980 25000baseKR_Full) ||
981 ethtool_link_ksettings_test_link_mode(ks, advertising,
982 25000baseSR_Full))
983 config.link_speed |= I40E_LINK_SPEED_25GB;
984 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
985 40000baseKR4_Full) ||
986 ethtool_link_ksettings_test_link_mode(ks, advertising,
987 40000baseCR4_Full) ||
988 ethtool_link_ksettings_test_link_mode(ks, advertising,
989 40000baseSR4_Full) ||
990 ethtool_link_ksettings_test_link_mode(ks, advertising,
991 40000baseLR4_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000992 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000993
Catherine Sullivan0002e112015-08-26 15:14:16 -0400994 /* If speed didn't get set, set it to what it currently is.
995 * This is needed because if advertise is 0 (as it is when autoneg
996 * is disabled) then speed won't get set.
997 */
998 if (!config.link_speed)
999 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -07001000 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001001 /* copy over the rest of the abilities */
1002 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -08001003 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001004 config.eee_capability = abilities.eee_capability;
1005 config.eeer = abilities.eeer_val;
1006 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -08001007 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
1008 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001009
Catherine Sullivane8278452015-02-06 08:52:08 +00001010 /* save the requested speeds */
1011 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +00001012 /* set link and auto negotiation so changes take effect */
1013 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1014 /* If link is up put link down */
1015 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
1016 /* Tell the OS link is going down, the link will go
1017 * back up when fw says it is ready asynchronously
1018 */
Matt Jaredc156f852015-08-27 11:42:39 -04001019 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001020 netif_carrier_off(netdev);
1021 netif_tx_stop_all_queues(netdev);
1022 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001023
1024 /* make the aq call */
1025 status = i40e_aq_set_phy_config(hw, &config, NULL);
1026 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001027 netdev_info(netdev,
1028 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001029 i40e_stat_str(hw, status),
1030 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001031 err = -EAGAIN;
1032 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001033 }
1034
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001035 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001036 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001037 netdev_dbg(netdev,
1038 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001039 i40e_stat_str(hw, status),
1040 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001041
1042 } else {
1043 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1044 }
1045
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001046done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001047 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001048
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001049 return err;
1050}
1051
Jesse Brandeburga6599722014-06-04 08:45:25 +00001052static int i40e_nway_reset(struct net_device *netdev)
1053{
1054 /* restart autonegotiation */
1055 struct i40e_netdev_priv *np = netdev_priv(netdev);
1056 struct i40e_pf *pf = np->vsi->back;
1057 struct i40e_hw *hw = &pf->hw;
1058 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1059 i40e_status ret = 0;
1060
1061 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1062 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001063 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1064 i40e_stat_str(hw, ret),
1065 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001066 return -EIO;
1067 }
1068
1069 return 0;
1070}
1071
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072/**
1073 * i40e_get_pauseparam - Get Flow Control status
1074 * Return tx/rx-pause status
1075 **/
1076static void i40e_get_pauseparam(struct net_device *netdev,
1077 struct ethtool_pauseparam *pause)
1078{
1079 struct i40e_netdev_priv *np = netdev_priv(netdev);
1080 struct i40e_pf *pf = np->vsi->back;
1081 struct i40e_hw *hw = &pf->hw;
1082 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001083 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001084
1085 pause->autoneg =
1086 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1087 AUTONEG_ENABLE : AUTONEG_DISABLE);
1088
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001089 /* PFC enabled so report LFC as off */
1090 if (dcbx_cfg->pfc.pfcenable) {
1091 pause->rx_pause = 0;
1092 pause->tx_pause = 0;
1093 return;
1094 }
1095
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001096 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001097 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001098 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001099 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001100 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1101 pause->rx_pause = 1;
1102 pause->tx_pause = 1;
1103 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001104}
1105
Catherine Sullivan2becc352014-06-04 08:45:27 +00001106/**
1107 * i40e_set_pauseparam - Set Flow Control parameter
1108 * @netdev: network interface device structure
1109 * @pause: return tx/rx flow control status
1110 **/
1111static int i40e_set_pauseparam(struct net_device *netdev,
1112 struct ethtool_pauseparam *pause)
1113{
1114 struct i40e_netdev_priv *np = netdev_priv(netdev);
1115 struct i40e_pf *pf = np->vsi->back;
1116 struct i40e_vsi *vsi = np->vsi;
1117 struct i40e_hw *hw = &pf->hw;
1118 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001119 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001120 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1121 i40e_status status;
1122 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001123 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001124
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001125 /* Changing the port's flow control is not supported if this isn't the
1126 * port's controlling PF
1127 */
1128 if (hw->partition_id != 1) {
1129 i40e_partition_setting_complaint(pf);
1130 return -EOPNOTSUPP;
1131 }
1132
Catherine Sullivan2becc352014-06-04 08:45:27 +00001133 if (vsi != pf->vsi[pf->lan_vsi])
1134 return -EOPNOTSUPP;
1135
1136 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1137 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1138 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1139 return -EOPNOTSUPP;
1140 }
1141
1142 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001143 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001144 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1145 /* Send message that it might not necessarily work*/
1146 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1147 }
1148
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001149 if (dcbx_cfg->pfc.pfcenable) {
1150 netdev_info(netdev,
1151 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001152 return -EOPNOTSUPP;
1153 }
1154
1155 if (pause->rx_pause && pause->tx_pause)
1156 hw->fc.requested_mode = I40E_FC_FULL;
1157 else if (pause->rx_pause && !pause->tx_pause)
1158 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1159 else if (!pause->rx_pause && pause->tx_pause)
1160 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1161 else if (!pause->rx_pause && !pause->tx_pause)
1162 hw->fc.requested_mode = I40E_FC_NONE;
1163 else
1164 return -EINVAL;
1165
Catherine Sullivan94128512014-07-12 07:28:16 +00001166 /* Tell the OS link is going down, the link will go back up when fw
1167 * says it is ready asynchronously
1168 */
Matt Jaredc156f852015-08-27 11:42:39 -04001169 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001170 netif_carrier_off(netdev);
1171 netif_tx_stop_all_queues(netdev);
1172
Catherine Sullivan2becc352014-06-04 08:45:27 +00001173 /* Set the fc mode and only restart an if link is up*/
1174 status = i40e_set_fc(hw, &aq_failures, link_up);
1175
1176 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001177 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1178 i40e_stat_str(hw, status),
1179 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001180 err = -EAGAIN;
1181 }
1182 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001183 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1184 i40e_stat_str(hw, status),
1185 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001186 err = -EAGAIN;
1187 }
1188 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001189 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1190 i40e_stat_str(hw, status),
1191 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001192 err = -EAGAIN;
1193 }
1194
Jacob Keller0da36b92017-04-19 09:25:55 -04001195 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001196 /* Give it a little more time to try to come back */
1197 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001198 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001199 return i40e_nway_reset(netdev);
1200 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001201
1202 return err;
1203}
1204
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001205static u32 i40e_get_msglevel(struct net_device *netdev)
1206{
1207 struct i40e_netdev_priv *np = netdev_priv(netdev);
1208 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001209 u32 debug_mask = pf->hw.debug_mask;
1210
1211 if (debug_mask)
1212 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001213
1214 return pf->msg_enable;
1215}
1216
1217static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1218{
1219 struct i40e_netdev_priv *np = netdev_priv(netdev);
1220 struct i40e_pf *pf = np->vsi->back;
1221
1222 if (I40E_DEBUG_USER & data)
1223 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001224 else
1225 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001226}
1227
1228static int i40e_get_regs_len(struct net_device *netdev)
1229{
1230 int reg_count = 0;
1231 int i;
1232
1233 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1234 reg_count += i40e_reg_list[i].elements;
1235
1236 return reg_count * sizeof(u32);
1237}
1238
1239static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1240 void *p)
1241{
1242 struct i40e_netdev_priv *np = netdev_priv(netdev);
1243 struct i40e_pf *pf = np->vsi->back;
1244 struct i40e_hw *hw = &pf->hw;
1245 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001246 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001247 u32 reg;
1248
1249 /* Tell ethtool which driver-version-specific regs output we have.
1250 *
1251 * At some point, if we have ethtool doing special formatting of
1252 * this data, it will rely on this version number to know how to
1253 * interpret things. Hence, this needs to be updated if/when the
1254 * diags register table is changed.
1255 */
1256 regs->version = 1;
1257
1258 /* loop through the diags reg table for what to print */
1259 ri = 0;
1260 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1261 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1262 reg = i40e_reg_list[i].offset
1263 + (j * i40e_reg_list[i].stride);
1264 reg_buf[ri++] = rd32(hw, reg);
1265 }
1266 }
1267
1268}
1269
1270static int i40e_get_eeprom(struct net_device *netdev,
1271 struct ethtool_eeprom *eeprom, u8 *bytes)
1272{
1273 struct i40e_netdev_priv *np = netdev_priv(netdev);
1274 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001275 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001276 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001277 u8 *eeprom_buff;
1278 u16 i, sectors;
1279 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001280 u32 magic;
1281
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001282#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001283 if (eeprom->len == 0)
1284 return -EINVAL;
1285
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001286 /* check for NVMUpdate access method */
1287 magic = hw->vendor_id | (hw->device_id << 16);
1288 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001289 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1290 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001291
1292 /* make sure it is the right magic for NVMUpdate */
1293 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001294 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001295 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1296 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001297 errno = -EBUSY;
1298 else
1299 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001300
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001301 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001302 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001303 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1304 ret_val, hw->aq.asq_last_status, errno,
1305 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1306 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001307
1308 return errno;
1309 }
1310
1311 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001312 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1313
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001314 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001315 if (!eeprom_buff)
1316 return -ENOMEM;
1317
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001318 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1319 if (ret_val) {
1320 dev_info(&pf->pdev->dev,
1321 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1322 ret_val, hw->aq.asq_last_status);
1323 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001324 }
1325
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001326 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1327 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1328 len = I40E_NVM_SECTOR_SIZE;
1329 last = false;
1330 for (i = 0; i < sectors; i++) {
1331 if (i == (sectors - 1)) {
1332 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1333 last = true;
1334 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001335 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1336 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001337 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001338 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001339 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001340 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001341 "read NVM failed, invalid offset 0x%x\n",
1342 offset);
1343 break;
1344 } else if (ret_val &&
1345 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1346 dev_info(&pf->pdev->dev,
1347 "read NVM failed, access, offset 0x%x\n",
1348 offset);
1349 break;
1350 } else if (ret_val) {
1351 dev_info(&pf->pdev->dev,
1352 "read NVM failed offset %d err=%d status=0x%x\n",
1353 offset, ret_val, hw->aq.asq_last_status);
1354 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001355 }
1356 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001357
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001358 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001359 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001360free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001362 return ret_val;
1363}
1364
1365static int i40e_get_eeprom_len(struct net_device *netdev)
1366{
1367 struct i40e_netdev_priv *np = netdev_priv(netdev);
1368 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001369 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001370
Lihong Yangc271dd62017-01-30 12:29:32 -08001371#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1372 if (hw->mac.type == I40E_MAC_X722) {
1373 val = X722_EEPROM_SCOPE_LIMIT + 1;
1374 return val;
1375 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001376 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1377 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1378 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1379 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001380 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001381 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001382}
1383
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001384static int i40e_set_eeprom(struct net_device *netdev,
1385 struct ethtool_eeprom *eeprom, u8 *bytes)
1386{
1387 struct i40e_netdev_priv *np = netdev_priv(netdev);
1388 struct i40e_hw *hw = &np->vsi->back->hw;
1389 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001390 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001391 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001392 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001393 u32 magic;
1394
1395 /* normal ethtool set_eeprom is not supported */
1396 magic = hw->vendor_id | (hw->device_id << 16);
1397 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001398 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001399 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001400 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1401 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001402 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1403 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001404 errno = -EBUSY;
1405 else
1406 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001407
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001408 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001409 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001410 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1411 ret_val, hw->aq.asq_last_status, errno,
1412 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1413 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001414
1415 return errno;
1416}
1417
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001418static void i40e_get_drvinfo(struct net_device *netdev,
1419 struct ethtool_drvinfo *drvinfo)
1420{
1421 struct i40e_netdev_priv *np = netdev_priv(netdev);
1422 struct i40e_vsi *vsi = np->vsi;
1423 struct i40e_pf *pf = vsi->back;
1424
1425 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1426 strlcpy(drvinfo->version, i40e_driver_version_str,
1427 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001428 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 sizeof(drvinfo->fw_version));
1430 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1431 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001432 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001433 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001434 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001435}
1436
1437static void i40e_get_ringparam(struct net_device *netdev,
1438 struct ethtool_ringparam *ring)
1439{
1440 struct i40e_netdev_priv *np = netdev_priv(netdev);
1441 struct i40e_pf *pf = np->vsi->back;
1442 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1443
1444 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1445 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1446 ring->rx_mini_max_pending = 0;
1447 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001448 ring->rx_pending = vsi->rx_rings[0]->count;
1449 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001450 ring->rx_mini_pending = 0;
1451 ring->rx_jumbo_pending = 0;
1452}
1453
Björn Töpel74608d12017-05-24 07:55:35 +02001454static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1455{
1456 if (i40e_enabled_xdp_vsi(vsi)) {
1457 return index < vsi->num_queue_pairs ||
1458 (index >= vsi->alloc_queue_pairs &&
1459 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1460 }
1461
1462 return index < vsi->num_queue_pairs;
1463}
1464
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001465static int i40e_set_ringparam(struct net_device *netdev,
1466 struct ethtool_ringparam *ring)
1467{
1468 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1469 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001470 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001471 struct i40e_vsi *vsi = np->vsi;
1472 struct i40e_pf *pf = vsi->back;
1473 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001474 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001475 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001476 int i, err = 0;
1477
1478 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1479 return -EINVAL;
1480
Shannon Nelson1fa18372013-11-20 10:03:08 +00001481 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1482 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1483 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1484 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1485 netdev_info(netdev,
1486 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1487 ring->tx_pending, ring->rx_pending,
1488 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1489 return -EINVAL;
1490 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001491
Shannon Nelson1fa18372013-11-20 10:03:08 +00001492 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1493 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494
1495 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001496 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1497 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001498 return 0;
1499
Jacob Keller0da36b92017-04-19 09:25:55 -04001500 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001501 timeout--;
1502 if (!timeout)
1503 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001505 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506
1507 if (!netif_running(vsi->netdev)) {
1508 /* simple case - set for the next time the netdev is started */
1509 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001510 vsi->tx_rings[i]->count = new_tx_count;
1511 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001512 if (i40e_enabled_xdp_vsi(vsi))
1513 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514 }
1515 goto done;
1516 }
1517
1518 /* We can't just free everything and then setup again,
1519 * because the ISRs in MSI-X mode get passed pointers
1520 * to the Tx and Rx ring structs.
1521 */
1522
Björn Töpel74608d12017-05-24 07:55:35 +02001523 /* alloc updated Tx and XDP Tx resources */
1524 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1525 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001526 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001527 netdev_info(netdev,
1528 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001529 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001530 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001531 sizeof(struct i40e_ring), GFP_KERNEL);
1532 if (!tx_rings) {
1533 err = -ENOMEM;
1534 goto done;
1535 }
1536
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 continue;
1540
Alexander Duyck9f65e152013-09-28 06:00:58 +00001541 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001542 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001543 /* the desc and bi pointers will be reallocated in the
1544 * setup call
1545 */
1546 tx_rings[i].desc = NULL;
1547 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1549 if (err) {
1550 while (i) {
1551 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001552 if (!i40e_active_tx_ring_index(vsi, i))
1553 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554 i40e_free_tx_resources(&tx_rings[i]);
1555 }
1556 kfree(tx_rings);
1557 tx_rings = NULL;
1558
1559 goto done;
1560 }
1561 }
1562 }
1563
1564 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001565 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566 netdev_info(netdev,
1567 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001568 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001569 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1570 sizeof(struct i40e_ring), GFP_KERNEL);
1571 if (!rx_rings) {
1572 err = -ENOMEM;
1573 goto free_tx;
1574 }
1575
1576 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001577 struct i40e_ring *ring;
1578 u16 unused;
1579
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001581 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001582 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001583 /* the desc and bi pointers will be reallocated in the
1584 * setup call
1585 */
1586 rx_rings[i].desc = NULL;
1587 rx_rings[i].rx_bi = NULL;
Jesper Dangaard Brouer87128822018-01-03 11:25:23 +01001588 /* Clear cloned XDP RX-queue info before setup call */
1589 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
Tushar Dave2f7679e2016-10-26 10:49:27 -07001590 /* this is to allow wr32 to have something to write to
1591 * during early allocation of Rx buffers
1592 */
1593 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001595 if (err)
1596 goto rx_unwind;
1597
1598 /* now allocate the Rx buffers to make sure the OS
1599 * has enough memory, any failure here means abort
1600 */
1601 ring = &rx_rings[i];
1602 unused = I40E_DESC_UNUSED(ring);
1603 err = i40e_alloc_rx_buffers(ring, unused);
1604rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001605 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001606 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001607 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001608 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609 kfree(rx_rings);
1610 rx_rings = NULL;
1611
1612 goto free_tx;
1613 }
1614 }
1615 }
1616
1617 /* Bring interface down, copy in the new ring info,
1618 * then restore the interface
1619 */
1620 i40e_down(vsi);
1621
1622 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001623 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1624 if (i40e_active_tx_ring_index(vsi, i)) {
1625 i40e_free_tx_resources(vsi->tx_rings[i]);
1626 *vsi->tx_rings[i] = tx_rings[i];
1627 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001628 }
1629 kfree(tx_rings);
1630 tx_rings = NULL;
1631 }
1632
1633 if (rx_rings) {
1634 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001635 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001636 /* get the real tail offset */
1637 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1638 /* this is to fake out the allocation routine
1639 * into thinking it has to realloc everything
1640 * but the recycling logic will let us re-use
1641 * the buffers allocated above
1642 */
1643 rx_rings[i].next_to_use = 0;
1644 rx_rings[i].next_to_clean = 0;
1645 rx_rings[i].next_to_alloc = 0;
1646 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001647 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001648 }
1649 kfree(rx_rings);
1650 rx_rings = NULL;
1651 }
1652
1653 i40e_up(vsi);
1654
1655free_tx:
1656 /* error cleanup if the Rx allocations failed after getting Tx */
1657 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001658 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1659 if (i40e_active_tx_ring_index(vsi, i))
1660 i40e_free_tx_resources(vsi->tx_rings[i]);
1661 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 kfree(tx_rings);
1663 tx_rings = NULL;
1664 }
1665
1666done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001667 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668
1669 return err;
1670}
1671
1672static int i40e_get_sset_count(struct net_device *netdev, int sset)
1673{
1674 struct i40e_netdev_priv *np = netdev_priv(netdev);
1675 struct i40e_vsi *vsi = np->vsi;
1676 struct i40e_pf *pf = vsi->back;
1677
1678 switch (sset) {
1679 case ETH_SS_TEST:
1680 return I40E_TEST_LEN;
1681 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001682 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001683 int len = I40E_PF_STATS_LEN(netdev);
1684
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001685 if ((pf->lan_veb != I40E_NO_VEB) &&
1686 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001687 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001688 return len;
1689 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001690 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001691 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001692 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001693 return I40E_PRIV_FLAGS_STR_LEN +
1694 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695 default:
1696 return -EOPNOTSUPP;
1697 }
1698}
1699
1700static void i40e_get_ethtool_stats(struct net_device *netdev,
1701 struct ethtool_stats *stats, u64 *data)
1702{
1703 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001704 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001705 struct i40e_vsi *vsi = np->vsi;
1706 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001707 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001708 int i = 0;
1709 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001710 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001711 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712
1713 i40e_update_stats(vsi);
1714
1715 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1716 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1717 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1718 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1719 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001720 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1721 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1722 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1723 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1724 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001725 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001726 for (j = 0; j < vsi->num_queue_pairs; j++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07001727 tx_ring = READ_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001728
1729 if (!tx_ring)
1730 continue;
1731
1732 /* process Tx ring statistics */
1733 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001734 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001735 data[i] = tx_ring->stats.packets;
1736 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001737 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001738 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001739
1740 /* Rx ring is the 2nd half of the queue pair */
1741 rx_ring = &tx_ring[1];
1742 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001743 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001744 data[i] = rx_ring->stats.packets;
1745 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001746 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001747 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001748 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001749 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001750 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001751 return;
1752
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001753 if ((pf->lan_veb != I40E_NO_VEB) &&
1754 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001755 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001756
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001757 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1758 p = (char *)veb;
1759 p += i40e_gstrings_veb_stats[j].stat_offset;
1760 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1761 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001762 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001763 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1764 data[i++] = veb->tc_stats.tc_tx_packets[j];
1765 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1766 data[i++] = veb->tc_stats.tc_rx_packets[j];
1767 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1768 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001769 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001770 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1771 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1772 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1773 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1774 }
1775 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1776 data[i++] = pf->stats.priority_xon_tx[j];
1777 data[i++] = pf->stats.priority_xoff_tx[j];
1778 }
1779 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1780 data[i++] = pf->stats.priority_xon_rx[j];
1781 data[i++] = pf->stats.priority_xoff_rx[j];
1782 }
1783 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1784 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001785}
1786
1787static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1788 u8 *data)
1789{
1790 struct i40e_netdev_priv *np = netdev_priv(netdev);
1791 struct i40e_vsi *vsi = np->vsi;
1792 struct i40e_pf *pf = vsi->back;
1793 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001794 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001795
1796 switch (stringset) {
1797 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001798 memcpy(data, i40e_gstrings_test,
1799 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001800 break;
1801 case ETH_SS_STATS:
1802 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1803 snprintf(p, ETH_GSTRING_LEN, "%s",
1804 i40e_gstrings_net_stats[i].stat_string);
1805 p += ETH_GSTRING_LEN;
1806 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001807 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1808 snprintf(p, ETH_GSTRING_LEN, "%s",
1809 i40e_gstrings_misc_stats[i].stat_string);
1810 p += ETH_GSTRING_LEN;
1811 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001813 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001814 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001815 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001816 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001817 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001819 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820 p += ETH_GSTRING_LEN;
1821 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001822 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001823 return;
1824
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001825 if ((pf->lan_veb != I40E_NO_VEB) &&
1826 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001827 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1828 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1829 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001830 p += ETH_GSTRING_LEN;
1831 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001832 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1833 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001834 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001835 p += ETH_GSTRING_LEN;
1836 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001837 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001838 p += ETH_GSTRING_LEN;
1839 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001840 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001841 p += ETH_GSTRING_LEN;
1842 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001843 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001844 p += ETH_GSTRING_LEN;
1845 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001846 }
1847 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1848 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1849 i40e_gstrings_stats[i].stat_string);
1850 p += ETH_GSTRING_LEN;
1851 }
1852 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1853 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001854 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001855 p += ETH_GSTRING_LEN;
1856 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001857 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001858 p += ETH_GSTRING_LEN;
1859 }
1860 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1861 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001862 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001863 p += ETH_GSTRING_LEN;
1864 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001865 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001866 p += ETH_GSTRING_LEN;
1867 }
1868 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1869 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001870 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001871 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001872 }
1873 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1874 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001875 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001876 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1877 snprintf(p, ETH_GSTRING_LEN, "%s",
1878 i40e_gstrings_priv_flags[i].flag_string);
1879 p += ETH_GSTRING_LEN;
1880 }
1881 if (pf->hw.pf_id != 0)
1882 break;
1883 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1884 snprintf(p, ETH_GSTRING_LEN, "%s",
1885 i40e_gl_gstrings_priv_flags[i].flag_string);
1886 p += ETH_GSTRING_LEN;
1887 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001888 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001889 default:
1890 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001891 }
1892}
1893
1894static int i40e_get_ts_info(struct net_device *dev,
1895 struct ethtool_ts_info *info)
1896{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001897 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1898
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001899 /* only report HW timestamping if PTP is enabled */
1900 if (!(pf->flags & I40E_FLAG_PTP))
1901 return ethtool_op_get_ts_info(dev, info);
1902
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001903 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1904 SOF_TIMESTAMPING_RX_SOFTWARE |
1905 SOF_TIMESTAMPING_SOFTWARE |
1906 SOF_TIMESTAMPING_TX_HARDWARE |
1907 SOF_TIMESTAMPING_RX_HARDWARE |
1908 SOF_TIMESTAMPING_RAW_HARDWARE;
1909
1910 if (pf->ptp_clock)
1911 info->phc_index = ptp_clock_index(pf->ptp_clock);
1912 else
1913 info->phc_index = -1;
1914
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001915 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001916
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001917 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001918 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1919 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1920 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1921
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001922 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001923 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1924 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1925 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1926 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1927 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1928 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1929 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1930 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001931
1932 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001933}
1934
Shannon Nelson7b086392013-11-20 10:02:59 +00001935static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001936{
Shannon Nelson7b086392013-11-20 10:02:59 +00001937 struct i40e_netdev_priv *np = netdev_priv(netdev);
1938 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001939 i40e_status status;
1940 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001941
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001942 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001943 status = i40e_get_link_status(&pf->hw, &link_up);
1944 if (status) {
1945 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1946 *data = 1;
1947 return *data;
1948 }
1949
1950 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001951 *data = 0;
1952 else
1953 *data = 1;
1954
1955 return *data;
1956}
1957
Shannon Nelson7b086392013-11-20 10:02:59 +00001958static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001959{
Shannon Nelson7b086392013-11-20 10:02:59 +00001960 struct i40e_netdev_priv *np = netdev_priv(netdev);
1961 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001962
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001963 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001964 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001965
Shannon Nelson7b086392013-11-20 10:02:59 +00001966 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001967}
1968
Shannon Nelson7b086392013-11-20 10:02:59 +00001969static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001970{
Shannon Nelson7b086392013-11-20 10:02:59 +00001971 struct i40e_netdev_priv *np = netdev_priv(netdev);
1972 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001973
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001974 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001975 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001976
Shannon Nelson4443ec92014-11-13 08:23:12 +00001977 /* forcebly clear the NVM Update state machine */
1978 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1979
Shannon Nelson7b086392013-11-20 10:02:59 +00001980 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001981}
1982
Shannon Nelson7b086392013-11-20 10:02:59 +00001983static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001984{
Shannon Nelson7b086392013-11-20 10:02:59 +00001985 struct i40e_netdev_priv *np = netdev_priv(netdev);
1986 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001987 u16 swc_old = pf->sw_int_count;
1988
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001989 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001990 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1991 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001992 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1993 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1994 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1995 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001996 usleep_range(1000, 2000);
1997 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998
1999 return *data;
2000}
2001
Greg Rosee17bc412015-04-16 20:05:59 -04002002static inline bool i40e_active_vfs(struct i40e_pf *pf)
2003{
2004 struct i40e_vf *vfs = pf->vf;
2005 int i;
2006
2007 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04002008 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04002009 return true;
2010 return false;
2011}
2012
Greg Rose510efb22015-07-10 19:36:01 -04002013static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2014{
Alexander Duyck4b816442016-10-11 15:26:53 -07002015 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04002016}
2017
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002018static void i40e_diag_test(struct net_device *netdev,
2019 struct ethtool_test *eth_test, u64 *data)
2020{
2021 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002022 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002023 struct i40e_pf *pf = np->vsi->back;
2024
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002025 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2026 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002027 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002028
Jacob Keller0da36b92017-04-19 09:25:55 -04002029 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002030
Greg Rose510efb22015-07-10 19:36:01 -04002031 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002032 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002033 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002034 data[I40E_ETH_TEST_REG] = 1;
2035 data[I40E_ETH_TEST_EEPROM] = 1;
2036 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002037 data[I40E_ETH_TEST_LINK] = 1;
2038 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002039 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002040 goto skip_ol_tests;
2041 }
2042
Greg Rose5b86c5c2015-02-26 16:14:35 +00002043 /* If the device is online then take it offline */
2044 if (if_running)
2045 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002046 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002047 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002048 /* This reset does not affect link - if it is
2049 * changed to a type of reset that does affect
2050 * link then the following link test would have
2051 * to be moved to before the reset
2052 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002053 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002054
Shannon Nelson7b086392013-11-20 10:02:59 +00002055 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002056 eth_test->flags |= ETH_TEST_FL_FAILED;
2057
Shannon Nelson7b086392013-11-20 10:02:59 +00002058 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002059 eth_test->flags |= ETH_TEST_FL_FAILED;
2060
Shannon Nelson7b086392013-11-20 10:02:59 +00002061 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062 eth_test->flags |= ETH_TEST_FL_FAILED;
2063
Shannon Nelsonf551b432013-11-26 10:49:12 +00002064 /* run reg test last, a reset is required after it */
2065 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2066 eth_test->flags |= ETH_TEST_FL_FAILED;
2067
Jacob Keller0da36b92017-04-19 09:25:55 -04002068 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002069 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002070
2071 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002072 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002073 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002074 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002075 netif_info(pf, drv, netdev, "online testing starting\n");
2076
Shannon Nelson7b086392013-11-20 10:02:59 +00002077 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002078 eth_test->flags |= ETH_TEST_FL_FAILED;
2079
2080 /* Offline only tests, not run in online; pass by default */
2081 data[I40E_ETH_TEST_REG] = 0;
2082 data[I40E_ETH_TEST_EEPROM] = 0;
2083 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002084 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002085
Greg Rosee17bc412015-04-16 20:05:59 -04002086skip_ol_tests:
2087
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002088 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002089}
2090
2091static void i40e_get_wol(struct net_device *netdev,
2092 struct ethtool_wolinfo *wol)
2093{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002094 struct i40e_netdev_priv *np = netdev_priv(netdev);
2095 struct i40e_pf *pf = np->vsi->back;
2096 struct i40e_hw *hw = &pf->hw;
2097 u16 wol_nvm_bits;
2098
2099 /* NVM bit on means WoL disabled for the port */
2100 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002101 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002102 wol->supported = 0;
2103 wol->wolopts = 0;
2104 } else {
2105 wol->supported = WAKE_MAGIC;
2106 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2107 }
2108}
2109
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002110/**
2111 * i40e_set_wol - set the WakeOnLAN configuration
2112 * @netdev: the netdev in question
2113 * @wol: the ethtool WoL setting data
2114 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002115static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2116{
2117 struct i40e_netdev_priv *np = netdev_priv(netdev);
2118 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002119 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002120 struct i40e_hw *hw = &pf->hw;
2121 u16 wol_nvm_bits;
2122
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002123 /* WoL not supported if this isn't the controlling PF on the port */
2124 if (hw->partition_id != 1) {
2125 i40e_partition_setting_complaint(pf);
2126 return -EOPNOTSUPP;
2127 }
2128
2129 if (vsi != pf->vsi[pf->lan_vsi])
2130 return -EOPNOTSUPP;
2131
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002132 /* NVM bit on means WoL disabled for the port */
2133 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002134 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002135 return -EOPNOTSUPP;
2136
2137 /* only magic packet is supported */
2138 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2139 return -EOPNOTSUPP;
2140
2141 /* is this a new value? */
2142 if (pf->wol_en != !!wol->wolopts) {
2143 pf->wol_en = !!wol->wolopts;
2144 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2145 }
2146
2147 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002148}
2149
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002150static int i40e_set_phys_id(struct net_device *netdev,
2151 enum ethtool_phys_id_state state)
2152{
2153 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002154 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155 struct i40e_pf *pf = np->vsi->back;
2156 struct i40e_hw *hw = &pf->hw;
2157 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002158 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002159
2160 switch (state) {
2161 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002162 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002163 pf->led_status = i40e_led_get(hw);
2164 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002165 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2166 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2167 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002168 ret = i40e_led_get_phy(hw, &temp_status,
2169 &pf->phy_led_val);
2170 pf->led_status = temp_status;
2171 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 return blink_freq;
2173 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002174 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002175 i40e_led_set(hw, 0xf, false);
2176 else
2177 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178 break;
2179 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002180 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002181 i40e_led_set(hw, 0x0, false);
2182 else
2183 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 break;
2185 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002186 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002187 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002188 } else {
2189 ret = i40e_led_set_phy(hw, false, pf->led_status,
2190 (pf->phy_led_val |
2191 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002192 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2193 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002194 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002195 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002196 default:
2197 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002199 if (ret)
2200 return -ENOENT;
2201 else
2202 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002203}
2204
2205/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2206 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2207 * 125us (8000 interrupts per second) == ITR(62)
2208 */
2209
Jacob Keller65e87c02016-09-12 14:18:44 -07002210/**
2211 * __i40e_get_coalesce - get per-queue coalesce settings
2212 * @netdev: the netdev to check
2213 * @ec: ethtool coalesce data structure
2214 * @queue: which queue to pick
2215 *
2216 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2217 * are per queue. If queue is <0 then we default to queue 0 as the
2218 * representative value.
2219 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002220static int __i40e_get_coalesce(struct net_device *netdev,
2221 struct ethtool_coalesce *ec,
2222 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002223{
2224 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002225 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002226 struct i40e_vsi *vsi = np->vsi;
2227
2228 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2229 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2230
Alan Bradya03af692017-10-05 14:53:37 -07002231 /* rx and tx usecs has per queue value. If user doesn't specify the
2232 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002233 */
Alan Bradya03af692017-10-05 14:53:37 -07002234 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002235 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002236 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002237 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002238
Jacob Keller65e87c02016-09-12 14:18:44 -07002239 rx_ring = vsi->rx_rings[queue];
2240 tx_ring = vsi->tx_rings[queue];
2241
2242 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002243 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002244
Jacob Keller65e87c02016-09-12 14:18:44 -07002245 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002246 ec->use_adaptive_tx_coalesce = 1;
2247
Jacob Keller65e87c02016-09-12 14:18:44 -07002248 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2249 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2250
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002251 /* we use the _usecs_high to store/set the interrupt rate limit
2252 * that the hardware supports, that almost but not quite
2253 * fits the original intent of the ethtool variable,
2254 * the rx_coalesce_usecs_high limits total interrupts
2255 * per second from both tx/rx sources.
2256 */
2257 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2258 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002259
2260 return 0;
2261}
2262
Jacob Keller65e87c02016-09-12 14:18:44 -07002263/**
2264 * i40e_get_coalesce - get a netdev's coalesce settings
2265 * @netdev: the netdev to check
2266 * @ec: ethtool coalesce data structure
2267 *
2268 * Gets the coalesce settings for a particular netdev. Note that if user has
2269 * modified per-queue settings, this only guarantees to represent queue 0. See
2270 * __i40e_get_coalesce for more details.
2271 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002272static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002273 struct ethtool_coalesce *ec)
2274{
Kan Lianga75e8002016-02-19 09:24:04 -05002275 return __i40e_get_coalesce(netdev, ec, -1);
2276}
2277
Jacob Keller65e87c02016-09-12 14:18:44 -07002278/**
2279 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2280 * @netdev: netdev structure
2281 * @ec: ethtool's coalesce settings
2282 * @queue: the particular queue to read
2283 *
2284 * Will read a specific queue's coalesce settings
2285 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002286static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2287 struct ethtool_coalesce *ec)
2288{
2289 return __i40e_get_coalesce(netdev, ec, queue);
2290}
2291
Jacob Keller65e87c02016-09-12 14:18:44 -07002292/**
2293 * i40e_set_itr_per_queue - set ITR values for specific queue
2294 * @vsi: the VSI to set values for
2295 * @ec: coalesce settings from ethtool
2296 * @queue: the queue to modify
2297 *
2298 * Change the ITR settings for a specific queue.
2299 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002300static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2301 struct ethtool_coalesce *ec,
2302 int queue)
2303{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002304 struct i40e_pf *pf = vsi->back;
2305 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002306 struct i40e_q_vector *q_vector;
2307 u16 vector, intrl;
2308
Alan Brady1c0e6a32016-11-28 16:06:02 -08002309 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002310
2311 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2312 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2313
2314 if (ec->use_adaptive_rx_coalesce)
2315 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2316 else
2317 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2318
2319 if (ec->use_adaptive_tx_coalesce)
2320 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2321 else
2322 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2323
2324 q_vector = vsi->rx_rings[queue]->q_vector;
2325 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2326 vector = vsi->base_vector + q_vector->v_idx;
2327 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2328
2329 q_vector = vsi->tx_rings[queue]->q_vector;
2330 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2331 vector = vsi->base_vector + q_vector->v_idx;
2332 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2333
2334 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2335 i40e_flush(hw);
2336}
2337
Jacob Keller65e87c02016-09-12 14:18:44 -07002338/**
2339 * __i40e_set_coalesce - set coalesce settings for particular queue
2340 * @netdev: the netdev to change
2341 * @ec: ethtool coalesce settings
2342 * @queue: the queue to change
2343 *
2344 * Sets the coalesce settings for a particular queue.
2345 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002346static int __i40e_set_coalesce(struct net_device *netdev,
2347 struct ethtool_coalesce *ec,
2348 int queue)
2349{
2350 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002351 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002352 struct i40e_vsi *vsi = np->vsi;
2353 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002354 int i;
2355
2356 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2357 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2358
Alan Brady06b2dec2017-07-12 05:46:06 -04002359 if (queue < 0) {
2360 cur_rx_itr = vsi->rx_rings[0]->rx_itr_setting;
2361 cur_tx_itr = vsi->tx_rings[0]->tx_itr_setting;
2362 } else if (queue < vsi->num_queue_pairs) {
2363 cur_rx_itr = vsi->rx_rings[queue]->rx_itr_setting;
2364 cur_tx_itr = vsi->tx_rings[queue]->tx_itr_setting;
2365 } else {
2366 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2367 vsi->num_queue_pairs - 1);
2368 return -EINVAL;
2369 }
2370
2371 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2372 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2373
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002374 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2375 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2376 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2377 return -EINVAL;
2378 }
2379
Alan Brady33084062016-11-28 16:06:03 -08002380 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2381 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2382 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002383 return -EINVAL;
2384 }
2385
Alan Brady06b2dec2017-07-12 05:46:06 -04002386 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2387 ec->use_adaptive_rx_coalesce) {
2388 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2389 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002390 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002391
Alan Brady06b2dec2017-07-12 05:46:06 -04002392 if (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2393 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2394 return -EINVAL;
2395 }
2396
2397 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2398 ec->use_adaptive_tx_coalesce) {
2399 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2400 return -EINVAL;
2401 }
2402
2403 if (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2404 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2405 return -EINVAL;
2406 }
2407
2408 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2409 ec->rx_coalesce_usecs = I40E_MIN_ITR << 1;
2410
2411 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2412 ec->tx_coalesce_usecs = I40E_MIN_ITR << 1;
2413
Alan Brady33084062016-11-28 16:06:03 -08002414 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2415 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2416 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2417 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2418 vsi->int_rate_limit);
2419 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002420
Alan Bradya03af692017-10-05 14:53:37 -07002421 /* rx and tx usecs has per queue value. If user doesn't specify the
2422 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002423 */
2424 if (queue < 0) {
2425 for (i = 0; i < vsi->num_queue_pairs; i++)
2426 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002427 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002428 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002429 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002430
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002431 return 0;
2432}
2433
Jacob Keller65e87c02016-09-12 14:18:44 -07002434/**
2435 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2436 * @netdev: the netdev to change
2437 * @ec: ethtool coalesce settings
2438 *
2439 * This will set each queue to the same coalesce settings.
2440 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002441static int i40e_set_coalesce(struct net_device *netdev,
2442 struct ethtool_coalesce *ec)
2443{
2444 return __i40e_set_coalesce(netdev, ec, -1);
2445}
2446
Jacob Keller65e87c02016-09-12 14:18:44 -07002447/**
2448 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2449 * @netdev: the netdev to change
2450 * @ec: ethtool's coalesce settings
2451 * @queue: the queue to change
2452 *
2453 * Sets the specified queue's coalesce settings.
2454 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002455static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2456 struct ethtool_coalesce *ec)
2457{
2458 return __i40e_set_coalesce(netdev, ec, queue);
2459}
2460
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002461/**
2462 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2463 * @pf: pointer to the physical function struct
2464 * @cmd: ethtool rxnfc command
2465 *
2466 * Returns Success if the flow is supported, else Invalid Input.
2467 **/
2468static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2469{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002470 struct i40e_hw *hw = &pf->hw;
2471 u8 flow_pctype = 0;
2472 u64 i_set = 0;
2473
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002474 cmd->data = 0;
2475
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002476 switch (cmd->flow_type) {
2477 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002478 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2479 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002480 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002481 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2482 break;
2483 case TCP_V6_FLOW:
2484 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2485 break;
2486 case UDP_V6_FLOW:
2487 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2488 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002489 case SCTP_V4_FLOW:
2490 case AH_ESP_V4_FLOW:
2491 case AH_V4_FLOW:
2492 case ESP_V4_FLOW:
2493 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002494 case SCTP_V6_FLOW:
2495 case AH_ESP_V6_FLOW:
2496 case AH_V6_FLOW:
2497 case ESP_V6_FLOW:
2498 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002499 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002500 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2501 break;
2502 default:
2503 return -EINVAL;
2504 }
2505
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002506 /* Read flow based hash input set register */
2507 if (flow_pctype) {
2508 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2509 flow_pctype)) |
2510 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2511 flow_pctype)) << 32);
2512 }
2513
2514 /* Process bits of hash input set */
2515 if (i_set) {
2516 if (i_set & I40E_L4_SRC_MASK)
2517 cmd->data |= RXH_L4_B_0_1;
2518 if (i_set & I40E_L4_DST_MASK)
2519 cmd->data |= RXH_L4_B_2_3;
2520
2521 if (cmd->flow_type == TCP_V4_FLOW ||
2522 cmd->flow_type == UDP_V4_FLOW) {
2523 if (i_set & I40E_L3_SRC_MASK)
2524 cmd->data |= RXH_IP_SRC;
2525 if (i_set & I40E_L3_DST_MASK)
2526 cmd->data |= RXH_IP_DST;
2527 } else if (cmd->flow_type == TCP_V6_FLOW ||
2528 cmd->flow_type == UDP_V6_FLOW) {
2529 if (i_set & I40E_L3_V6_SRC_MASK)
2530 cmd->data |= RXH_IP_SRC;
2531 if (i_set & I40E_L3_V6_DST_MASK)
2532 cmd->data |= RXH_IP_DST;
2533 }
2534 }
2535
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002536 return 0;
2537}
2538
2539/**
Jacob Kellere7930952017-02-06 14:38:49 -08002540 * i40e_check_mask - Check whether a mask field is set
2541 * @mask: the full mask value
2542 * @field; mask of the field to check
2543 *
2544 * If the given mask is fully set, return positive value. If the mask for the
2545 * field is fully unset, return zero. Otherwise return a negative error code.
2546 **/
2547static int i40e_check_mask(u64 mask, u64 field)
2548{
2549 u64 value = mask & field;
2550
2551 if (value == field)
2552 return 1;
2553 else if (!value)
2554 return 0;
2555 else
2556 return -1;
2557}
2558
2559/**
2560 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2561 * @fsp: pointer to rx flow specification
2562 * @data: pointer to userdef data structure for storage
2563 *
2564 * Read the user-defined data and deconstruct the value into a structure. No
2565 * other code should read the user-defined data, so as to ensure that every
2566 * place consistently reads the value correctly.
2567 *
2568 * The user-defined field is a 64bit Big Endian format value, which we
2569 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2570 * be defined starting from the highest bits, while small bit field values
2571 * shall be defined starting from the lowest bits.
2572 *
2573 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2574 * and the filter should be rejected. The data structure will always be
2575 * modified even if FLOW_EXT is not set.
2576 *
2577 **/
2578static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2579 struct i40e_rx_flow_userdef *data)
2580{
2581 u64 value, mask;
2582 int valid;
2583
2584 /* Zero memory first so it's always consistent. */
2585 memset(data, 0, sizeof(*data));
2586
2587 if (!(fsp->flow_type & FLOW_EXT))
2588 return 0;
2589
2590 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2591 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2592
2593#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2594#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2595#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2596
2597 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2598 if (valid < 0) {
2599 return -EINVAL;
2600 } else if (valid) {
2601 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2602 data->flex_offset =
2603 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2604 data->flex_filter = true;
2605 }
2606
2607 return 0;
2608}
2609
2610/**
2611 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2612 * @fsp: pointer to rx_flow specification
2613 *
2614 * Reads the userdef data structure and properly fills in the user defined
2615 * fields of the rx_flow_spec.
2616 **/
2617static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2618 struct i40e_rx_flow_userdef *data)
2619{
2620 u64 value = 0, mask = 0;
2621
2622 if (data->flex_filter) {
2623 value |= data->flex_word;
2624 value |= (u64)data->flex_offset << 16;
2625 mask |= I40E_USERDEF_FLEX_FILTER;
2626 }
2627
2628 if (value || mask)
2629 fsp->flow_type |= FLOW_EXT;
2630
2631 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2632 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2633}
2634
2635/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002636 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2637 * @pf: Pointer to the physical function struct
2638 * @cmd: The command to get or set Rx flow classification rules
2639 * @rule_locs: Array of used rule locations
2640 *
2641 * This function populates both the total and actual rule count of
2642 * the ethtool flow classification command
2643 *
2644 * Returns 0 on success or -EMSGSIZE if entry not found
2645 **/
2646static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2647 struct ethtool_rxnfc *cmd,
2648 u32 *rule_locs)
2649{
2650 struct i40e_fdir_filter *rule;
2651 struct hlist_node *node2;
2652 int cnt = 0;
2653
2654 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002655 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002656
2657 hlist_for_each_entry_safe(rule, node2,
2658 &pf->fdir_filter_list, fdir_node) {
2659 if (cnt == cmd->rule_cnt)
2660 return -EMSGSIZE;
2661
2662 rule_locs[cnt] = rule->fd_id;
2663 cnt++;
2664 }
2665
2666 cmd->rule_cnt = cnt;
2667
2668 return 0;
2669}
2670
2671/**
2672 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2673 * @pf: Pointer to the physical function struct
2674 * @cmd: The command to get or set Rx flow classification rules
2675 *
2676 * This function looks up a filter based on the Rx flow classification
2677 * command and fills the flow spec info for it if found
2678 *
2679 * Returns 0 on success or -EINVAL if filter not found
2680 **/
2681static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2682 struct ethtool_rxnfc *cmd)
2683{
2684 struct ethtool_rx_flow_spec *fsp =
2685 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002686 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002687 struct i40e_fdir_filter *rule = NULL;
2688 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002689 u64 input_set;
2690 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002691
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002692 hlist_for_each_entry_safe(rule, node2,
2693 &pf->fdir_filter_list, fdir_node) {
2694 if (fsp->location <= rule->fd_id)
2695 break;
2696 }
2697
2698 if (!rule || fsp->location != rule->fd_id)
2699 return -EINVAL;
2700
2701 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002702 if (fsp->flow_type == IP_USER_FLOW) {
2703 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2704 fsp->h_u.usr_ip4_spec.proto = 0;
2705 fsp->m_u.usr_ip4_spec.proto = 0;
2706 }
2707
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002708 /* Reverse the src and dest notion, since the HW views them from
2709 * Tx perspective where as the user expects it from Rx filter view.
2710 */
2711 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2712 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002713 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2714 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002715
Jacob Keller36777d92017-03-07 15:05:23 -08002716 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002717 case SCTP_V4_FLOW:
2718 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2719 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002720 case TCP_V4_FLOW:
2721 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2722 break;
2723 case UDP_V4_FLOW:
2724 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2725 break;
2726 case IP_USER_FLOW:
2727 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2728 break;
2729 default:
2730 /* If we have stored a filter with a flow type not listed here
2731 * it is almost certainly a driver bug. WARN(), and then
2732 * assign the input_set as if all fields are enabled to avoid
2733 * reading unassigned memory.
2734 */
2735 WARN(1, "Missing input set index for flow_type %d\n",
2736 rule->flow_type);
2737 input_set = 0xFFFFFFFFFFFFFFFFULL;
2738 goto no_input_set;
2739 }
2740
2741 input_set = i40e_read_fd_input_set(pf, index);
2742
2743no_input_set:
2744 if (input_set & I40E_L3_SRC_MASK)
2745 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
2746
2747 if (input_set & I40E_L3_DST_MASK)
2748 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
2749
2750 if (input_set & I40E_L4_SRC_MASK)
2751 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
2752
2753 if (input_set & I40E_L4_DST_MASK)
2754 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002755
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002756 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2757 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2758 else
2759 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002760
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002761 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2762 struct i40e_vsi *vsi;
2763
2764 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2765 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002766 /* VFs are zero-indexed by the driver, but ethtool
2767 * expects them to be one-indexed, so add one here
2768 */
2769 u64 ring_vf = vsi->vf_id + 1;
2770
2771 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2772 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002773 }
2774 }
2775
Jacob Keller0e588de2017-02-06 14:38:50 -08002776 if (rule->flex_filter) {
2777 userdef.flex_filter = true;
2778 userdef.flex_word = be16_to_cpu(rule->flex_word);
2779 userdef.flex_offset = rule->flex_offset;
2780 }
2781
Jacob Kellere7930952017-02-06 14:38:49 -08002782 i40e_fill_rx_flow_user_data(fsp, &userdef);
2783
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002784 return 0;
2785}
2786
2787/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002788 * i40e_get_rxnfc - command to get RX flow classification rules
2789 * @netdev: network interface device structure
2790 * @cmd: ethtool rxnfc command
2791 *
2792 * Returns Success if the command is supported.
2793 **/
2794static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2795 u32 *rule_locs)
2796{
2797 struct i40e_netdev_priv *np = netdev_priv(netdev);
2798 struct i40e_vsi *vsi = np->vsi;
2799 struct i40e_pf *pf = vsi->back;
2800 int ret = -EOPNOTSUPP;
2801
2802 switch (cmd->cmd) {
2803 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002804 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002805 ret = 0;
2806 break;
2807 case ETHTOOL_GRXFH:
2808 ret = i40e_get_rss_hash_opts(pf, cmd);
2809 break;
2810 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002811 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002812 /* report total rule count */
2813 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002814 ret = 0;
2815 break;
2816 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002817 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002818 break;
2819 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002820 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2821 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002822 default:
2823 break;
2824 }
2825
2826 return ret;
2827}
2828
2829/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002830 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2831 * @nfc: pointer to user request
2832 * @i_setc bits currently set
2833 *
2834 * Returns value of bits to be set per user request
2835 **/
2836static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2837{
2838 u64 i_set = i_setc;
2839 u64 src_l3 = 0, dst_l3 = 0;
2840
2841 if (nfc->data & RXH_L4_B_0_1)
2842 i_set |= I40E_L4_SRC_MASK;
2843 else
2844 i_set &= ~I40E_L4_SRC_MASK;
2845 if (nfc->data & RXH_L4_B_2_3)
2846 i_set |= I40E_L4_DST_MASK;
2847 else
2848 i_set &= ~I40E_L4_DST_MASK;
2849
2850 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2851 src_l3 = I40E_L3_V6_SRC_MASK;
2852 dst_l3 = I40E_L3_V6_DST_MASK;
2853 } else if (nfc->flow_type == TCP_V4_FLOW ||
2854 nfc->flow_type == UDP_V4_FLOW) {
2855 src_l3 = I40E_L3_SRC_MASK;
2856 dst_l3 = I40E_L3_DST_MASK;
2857 } else {
2858 /* Any other flow type are not supported here */
2859 return i_set;
2860 }
2861
2862 if (nfc->data & RXH_IP_SRC)
2863 i_set |= src_l3;
2864 else
2865 i_set &= ~src_l3;
2866 if (nfc->data & RXH_IP_DST)
2867 i_set |= dst_l3;
2868 else
2869 i_set &= ~dst_l3;
2870
2871 return i_set;
2872}
2873
2874/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002875 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2876 * @pf: pointer to the physical function struct
2877 * @cmd: ethtool rxnfc command
2878 *
2879 * Returns Success if the flow input set is supported.
2880 **/
2881static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2882{
2883 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002884 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2885 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002886 u8 flow_pctype = 0;
2887 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002888
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002889 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2890 dev_err(&pf->pdev->dev,
2891 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2892 return -EOPNOTSUPP;
2893 }
2894
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002895 /* RSS does not support anything other than hashing
2896 * to queues on src and dst IPs and ports
2897 */
2898 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2899 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2900 return -EINVAL;
2901
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002902 switch (nfc->flow_type) {
2903 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002904 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002905 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002906 hena |=
2907 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002908 break;
2909 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002910 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002911 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002912 hena |=
2913 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002914 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002915 hena |=
2916 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002917 break;
2918 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002919 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002920 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002921 hena |=
2922 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2923 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002924
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002925 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002926 break;
2927 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002928 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002929 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002930 hena |=
2931 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2932 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002933
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002934 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002935 break;
2936 case AH_ESP_V4_FLOW:
2937 case AH_V4_FLOW:
2938 case ESP_V4_FLOW:
2939 case SCTP_V4_FLOW:
2940 if ((nfc->data & RXH_L4_B_0_1) ||
2941 (nfc->data & RXH_L4_B_2_3))
2942 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002943 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002944 break;
2945 case AH_ESP_V6_FLOW:
2946 case AH_V6_FLOW:
2947 case ESP_V6_FLOW:
2948 case SCTP_V6_FLOW:
2949 if ((nfc->data & RXH_L4_B_0_1) ||
2950 (nfc->data & RXH_L4_B_2_3))
2951 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002952 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002953 break;
2954 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002955 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2956 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002957 break;
2958 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002959 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2960 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002961 break;
2962 default:
2963 return -EINVAL;
2964 }
2965
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002966 if (flow_pctype) {
2967 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2968 flow_pctype)) |
2969 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2970 flow_pctype)) << 32);
2971 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2972 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2973 (u32)i_set);
2974 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2975 (u32)(i_set >> 32));
2976 hena |= BIT_ULL(flow_pctype);
2977 }
2978
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002979 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2980 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002981 i40e_flush(hw);
2982
2983 return 0;
2984}
2985
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002986/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002987 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2988 * @vsi: Pointer to the targeted VSI
2989 * @input: The filter to update or NULL to indicate deletion
2990 * @sw_idx: Software index to the filter
2991 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002992 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002993 * This function updates (or deletes) a Flow Director entry from
2994 * the hlist of the corresponding PF
2995 *
2996 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002997 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002998static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2999 struct i40e_fdir_filter *input,
3000 u16 sw_idx,
3001 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003002{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003003 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003004 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003005 struct hlist_node *node2;
3006 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003007
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003008 parent = NULL;
3009 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003010
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003011 hlist_for_each_entry_safe(rule, node2,
3012 &pf->fdir_filter_list, fdir_node) {
3013 /* hash found, or no matching entry */
3014 if (rule->fd_id >= sw_idx)
3015 break;
3016 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003017 }
3018
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003019 /* if there is an old rule occupying our place remove it */
3020 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08003021 /* Remove this rule, since we're either deleting it, or
3022 * replacing it.
3023 */
3024 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003025 hlist_del(&rule->fdir_node);
3026 kfree(rule);
3027 pf->fdir_pf_active_filters--;
3028 }
3029
Jacob Kellerc6da5252017-02-06 14:39:13 -08003030 /* If we weren't given an input, this is a delete, so just return the
3031 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003032 */
3033 if (!input)
3034 return err;
3035
Jacob Kellerc6da5252017-02-06 14:39:13 -08003036 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003037 INIT_HLIST_NODE(&input->fdir_node);
3038
3039 /* add filter to the list */
3040 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003041 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003042 else
3043 hlist_add_head(&input->fdir_node,
3044 &pf->fdir_filter_list);
3045
3046 /* update counts */
3047 pf->fdir_pf_active_filters++;
3048
3049 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003050}
3051
3052/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003053 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3054 * @pf: pointer to PF structure
3055 *
3056 * This function searches the list of filters and determines which FLX_PIT
3057 * entries are still required. It will prune any entries which are no longer
3058 * in use after the deletion.
3059 **/
3060static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3061{
3062 struct i40e_flex_pit *entry, *tmp;
3063 struct i40e_fdir_filter *rule;
3064
3065 /* First, we'll check the l3 table */
3066 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3067 bool found = false;
3068
3069 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3070 if (rule->flow_type != IP_USER_FLOW)
3071 continue;
3072 if (rule->flex_filter &&
3073 rule->flex_offset == entry->src_offset) {
3074 found = true;
3075 break;
3076 }
3077 }
3078
3079 /* If we didn't find the filter, then we can prune this entry
3080 * from the list.
3081 */
3082 if (!found) {
3083 list_del(&entry->list);
3084 kfree(entry);
3085 }
3086 }
3087
3088 /* Followed by the L4 table */
3089 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3090 bool found = false;
3091
3092 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3093 /* Skip this filter if it's L3, since we already
3094 * checked those in the above loop
3095 */
3096 if (rule->flow_type == IP_USER_FLOW)
3097 continue;
3098 if (rule->flex_filter &&
3099 rule->flex_offset == entry->src_offset) {
3100 found = true;
3101 break;
3102 }
3103 }
3104
3105 /* If we didn't find the filter, then we can prune this entry
3106 * from the list.
3107 */
3108 if (!found) {
3109 list_del(&entry->list);
3110 kfree(entry);
3111 }
3112 }
3113}
3114
3115/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003116 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3117 * @vsi: Pointer to the targeted VSI
3118 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003119 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003120 * The function removes a Flow Director filter entry from the
3121 * hlist of the corresponding PF
3122 *
3123 * Returns 0 on success
3124 */
3125static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3126 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003127{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003128 struct ethtool_rx_flow_spec *fsp =
3129 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003130 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003131 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003132
Jacob Keller0da36b92017-04-19 09:25:55 -04003133 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3134 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003135 return -EBUSY;
3136
Jacob Keller0da36b92017-04-19 09:25:55 -04003137 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003138 return -EBUSY;
3139
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003140 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003141
Jacob Keller0e588de2017-02-06 14:38:50 -08003142 i40e_prune_flex_pit_list(pf);
3143
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003144 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003145 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003146}
3147
3148/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003149 * i40e_unused_pit_index - Find an unused PIT index for given list
3150 * @pf: the PF data structure
3151 *
3152 * Find the first unused flexible PIT index entry. We search both the L3 and
3153 * L4 flexible PIT lists so that the returned index is unique and unused by
3154 * either currently programmed L3 or L4 filters. We use a bit field as storage
3155 * to track which indexes are already used.
3156 **/
3157static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3158{
3159 unsigned long available_index = 0xFF;
3160 struct i40e_flex_pit *entry;
3161
3162 /* We need to make sure that the new index isn't in use by either L3
3163 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3164 * L4 to use the same index.
3165 */
3166
3167 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3168 clear_bit(entry->pit_index, &available_index);
3169
3170 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3171 clear_bit(entry->pit_index, &available_index);
3172
3173 return find_first_bit(&available_index, 8);
3174}
3175
3176/**
3177 * i40e_find_flex_offset - Find an existing flex src_offset
3178 * @flex_pit_list: L3 or L4 flex PIT list
3179 * @src_offset: new src_offset to find
3180 *
3181 * Searches the flex_pit_list for an existing offset. If no offset is
3182 * currently programmed, then this will return an ERR_PTR if there is no space
3183 * to add a new offset, otherwise it returns NULL.
3184 **/
3185static
3186struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3187 u16 src_offset)
3188{
3189 struct i40e_flex_pit *entry;
3190 int size = 0;
3191
3192 /* Search for the src_offset first. If we find a matching entry
3193 * already programmed, we can simply re-use it.
3194 */
3195 list_for_each_entry(entry, flex_pit_list, list) {
3196 size++;
3197 if (entry->src_offset == src_offset)
3198 return entry;
3199 }
3200
3201 /* If we haven't found an entry yet, then the provided src offset has
3202 * not yet been programmed. We will program the src offset later on,
3203 * but we need to indicate whether there is enough space to do so
3204 * here. We'll make use of ERR_PTR for this purpose.
3205 */
3206 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3207 return ERR_PTR(-ENOSPC);
3208
3209 return NULL;
3210}
3211
3212/**
3213 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3214 * @flex_pit_list: L3 or L4 flex PIT list
3215 * @src_offset: new src_offset to add
3216 * @pit_index: the PIT index to program
3217 *
3218 * This function programs the new src_offset to the list. It is expected that
3219 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3220 * that this offset is not programmed, and that the list has enough space to
3221 * store another offset.
3222 *
3223 * Returns 0 on success, and negative value on error.
3224 **/
3225static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3226 u16 src_offset,
3227 u8 pit_index)
3228{
3229 struct i40e_flex_pit *new_pit, *entry;
3230
3231 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3232 if (!new_pit)
3233 return -ENOMEM;
3234
3235 new_pit->src_offset = src_offset;
3236 new_pit->pit_index = pit_index;
3237
3238 /* We need to insert this item such that the list is sorted by
3239 * src_offset in ascending order.
3240 */
3241 list_for_each_entry(entry, flex_pit_list, list) {
3242 if (new_pit->src_offset < entry->src_offset) {
3243 list_add_tail(&new_pit->list, &entry->list);
3244 return 0;
3245 }
3246
3247 /* If we found an entry with our offset already programmed we
3248 * can simply return here, after freeing the memory. However,
3249 * if the pit_index does not match we need to report an error.
3250 */
3251 if (new_pit->src_offset == entry->src_offset) {
3252 int err = 0;
3253
3254 /* If the PIT index is not the same we can't re-use
3255 * the entry, so we must report an error.
3256 */
3257 if (new_pit->pit_index != entry->pit_index)
3258 err = -EINVAL;
3259
3260 kfree(new_pit);
3261 return err;
3262 }
3263 }
3264
3265 /* If we reached here, then we haven't yet added the item. This means
3266 * that we should add the item at the end of the list.
3267 */
3268 list_add_tail(&new_pit->list, flex_pit_list);
3269 return 0;
3270}
3271
3272/**
3273 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3274 * @pf: Pointer to the PF structure
3275 * @flex_pit_list: list of flexible src offsets in use
3276 * #flex_pit_start: index to first entry for this section of the table
3277 *
3278 * In order to handle flexible data, the hardware uses a table of values
3279 * called the FLX_PIT table. This table is used to indicate which sections of
3280 * the input correspond to what PIT index values. Unfortunately, hardware is
3281 * very restrictive about programming this table. Entries must be ordered by
3282 * src_offset in ascending order, without duplicates. Additionally, unused
3283 * entries must be set to the unused index value, and must have valid size and
3284 * length according to the src_offset ordering.
3285 *
3286 * This function will reprogram the FLX_PIT register from a book-keeping
3287 * structure that we guarantee is already ordered correctly, and has no more
3288 * than 3 entries.
3289 *
3290 * To make things easier, we only support flexible values of one word length,
3291 * rather than allowing variable length flexible values.
3292 **/
3293static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3294 struct list_head *flex_pit_list,
3295 int flex_pit_start)
3296{
3297 struct i40e_flex_pit *entry = NULL;
3298 u16 last_offset = 0;
3299 int i = 0, j = 0;
3300
3301 /* First, loop over the list of flex PIT entries, and reprogram the
3302 * registers.
3303 */
3304 list_for_each_entry(entry, flex_pit_list, list) {
3305 /* We have to be careful when programming values for the
3306 * largest SRC_OFFSET value. It is possible that adding
3307 * additional empty values at the end would overflow the space
3308 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3309 * we check here and add the empty values prior to adding the
3310 * largest value.
3311 *
3312 * To determine this, we will use a loop from i+1 to 3, which
3313 * will determine whether the unused entries would have valid
3314 * SRC_OFFSET. Note that there cannot be extra entries past
3315 * this value, because the only valid values would have been
3316 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3317 * have been added to the list in the first place.
3318 */
3319 for (j = i + 1; j < 3; j++) {
3320 u16 offset = entry->src_offset + j;
3321 int index = flex_pit_start + i;
3322 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3323 1,
3324 offset - 3);
3325
3326 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3327 i40e_write_rx_ctl(&pf->hw,
3328 I40E_PRTQF_FLX_PIT(index),
3329 value);
3330 i++;
3331 }
3332 }
3333
3334 /* Now, we can program the actual value into the table */
3335 i40e_write_rx_ctl(&pf->hw,
3336 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3337 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3338 1,
3339 entry->src_offset));
3340 i++;
3341 }
3342
3343 /* In order to program the last entries in the table, we need to
3344 * determine the valid offset. If the list is empty, we'll just start
3345 * with 0. Otherwise, we'll start with the last item offset and add 1.
3346 * This ensures that all entries have valid sizes. If we don't do this
3347 * correctly, the hardware will disable flexible field parsing.
3348 */
3349 if (!list_empty(flex_pit_list))
3350 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3351
3352 for (; i < 3; i++, last_offset++) {
3353 i40e_write_rx_ctl(&pf->hw,
3354 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3355 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3356 1,
3357 last_offset));
3358 }
3359}
3360
3361/**
3362 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3363 * @pf: pointer to the PF structure
3364 *
3365 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3366 * internal helper function for implementation details.
3367 **/
3368static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3369{
3370 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3371 I40E_FLEX_PIT_IDX_START_L3);
3372
3373 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3374 I40E_FLEX_PIT_IDX_START_L4);
3375
3376 /* We also need to program the L3 and L4 GLQF ORT register */
3377 i40e_write_rx_ctl(&pf->hw,
3378 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3379 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3380 3, 1));
3381
3382 i40e_write_rx_ctl(&pf->hw,
3383 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3384 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3385 3, 1));
3386}
3387
3388/**
Jacob Keller9229e992017-02-06 14:38:47 -08003389 * i40e_flow_str - Converts a flow_type into a human readable string
3390 * @flow_type: the flow type from a flow specification
3391 *
3392 * Currently only flow types we support are included here, and the string
3393 * value attempts to match what ethtool would use to configure this flow type.
3394 **/
3395static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3396{
3397 switch (fsp->flow_type & ~FLOW_EXT) {
3398 case TCP_V4_FLOW:
3399 return "tcp4";
3400 case UDP_V4_FLOW:
3401 return "udp4";
3402 case SCTP_V4_FLOW:
3403 return "sctp4";
3404 case IP_USER_FLOW:
3405 return "ip4";
3406 default:
3407 return "unknown";
3408 }
3409}
3410
3411/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003412 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3413 * @pit_index: PIT index to convert
3414 *
3415 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3416 * of range.
3417 **/
3418static u64 i40e_pit_index_to_mask(int pit_index)
3419{
3420 switch (pit_index) {
3421 case 0:
3422 return I40E_FLEX_50_MASK;
3423 case 1:
3424 return I40E_FLEX_51_MASK;
3425 case 2:
3426 return I40E_FLEX_52_MASK;
3427 case 3:
3428 return I40E_FLEX_53_MASK;
3429 case 4:
3430 return I40E_FLEX_54_MASK;
3431 case 5:
3432 return I40E_FLEX_55_MASK;
3433 case 6:
3434 return I40E_FLEX_56_MASK;
3435 case 7:
3436 return I40E_FLEX_57_MASK;
3437 default:
3438 return 0;
3439 }
3440}
3441
3442/**
Jacob Keller9229e992017-02-06 14:38:47 -08003443 * i40e_print_input_set - Show changes between two input sets
3444 * @vsi: the vsi being configured
3445 * @old: the old input set
3446 * @new: the new input set
3447 *
3448 * Print the difference between old and new input sets by showing which series
3449 * of words are toggled on or off. Only displays the bits we actually support
3450 * changing.
3451 **/
3452static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3453{
3454 struct i40e_pf *pf = vsi->back;
3455 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003456 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003457
3458 old_value = !!(old & I40E_L3_SRC_MASK);
3459 new_value = !!(new & I40E_L3_SRC_MASK);
3460 if (old_value != new_value)
3461 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3462 old_value ? "ON" : "OFF",
3463 new_value ? "ON" : "OFF");
3464
3465 old_value = !!(old & I40E_L3_DST_MASK);
3466 new_value = !!(new & I40E_L3_DST_MASK);
3467 if (old_value != new_value)
3468 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3469 old_value ? "ON" : "OFF",
3470 new_value ? "ON" : "OFF");
3471
3472 old_value = !!(old & I40E_L4_SRC_MASK);
3473 new_value = !!(new & I40E_L4_SRC_MASK);
3474 if (old_value != new_value)
3475 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3476 old_value ? "ON" : "OFF",
3477 new_value ? "ON" : "OFF");
3478
3479 old_value = !!(old & I40E_L4_DST_MASK);
3480 new_value = !!(new & I40E_L4_DST_MASK);
3481 if (old_value != new_value)
3482 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3483 old_value ? "ON" : "OFF",
3484 new_value ? "ON" : "OFF");
3485
3486 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3487 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3488 if (old_value != new_value)
3489 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3490 old_value ? "ON" : "OFF",
3491 new_value ? "ON" : "OFF");
3492
Jacob Keller0e588de2017-02-06 14:38:50 -08003493 /* Show change of flexible filter entries */
3494 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3495 u64 flex_mask = i40e_pit_index_to_mask(i);
3496
3497 old_value = !!(old & flex_mask);
3498 new_value = !!(new & flex_mask);
3499 if (old_value != new_value)
3500 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3501 i,
3502 old_value ? "ON" : "OFF",
3503 new_value ? "ON" : "OFF");
3504 }
3505
Jacob Keller9229e992017-02-06 14:38:47 -08003506 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3507 old);
3508 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3509 new);
3510}
3511
3512/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003513 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003514 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003515 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003516 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003517 *
Jacob Keller9229e992017-02-06 14:38:47 -08003518 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3519 * for partial matches exists with a few limitations. First, hardware only
3520 * supports masking by word boundary (2 bytes) and not per individual bit.
3521 * Second, hardware is limited to using one mask for a flow type and cannot
3522 * use a separate mask for each filter.
3523 *
3524 * To support these limitations, if we already have a configured filter for
3525 * the specified type, this function enforces that new filters of the type
3526 * match the configured input set. Otherwise, if we do not have a filter of
3527 * the specified type, we allow the input set to be updated to match the
3528 * desired filter.
3529 *
3530 * To help ensure that administrators understand why filters weren't displayed
3531 * as supported, we print a diagnostic message displaying how the input set
3532 * would change and warning to delete the preexisting filters if required.
3533 *
3534 * Returns 0 on successful input set match, and a negative return code on
3535 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003536 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003537static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003538 struct ethtool_rx_flow_spec *fsp,
3539 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003540{
Jacob Keller36777d92017-03-07 15:05:23 -08003541 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003542 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3543 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003544 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003545 bool new_flex_offset = false;
3546 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003547 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003548 u16 index, src_offset = 0;
3549 u8 pit_index = 0;
3550 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003551
3552 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003553 case SCTP_V4_FLOW:
3554 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3555 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3556 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003557 case TCP_V4_FLOW:
3558 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003559 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003560 break;
3561 case UDP_V4_FLOW:
3562 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003563 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003564 break;
3565 case IP_USER_FLOW:
3566 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003567 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003568 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003569 break;
3570 default:
3571 return -EOPNOTSUPP;
3572 }
3573
3574 /* Read the current input set from register memory. */
3575 current_mask = i40e_read_fd_input_set(pf, index);
3576 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003577
Jacob Keller9229e992017-02-06 14:38:47 -08003578 /* Determine, if any, the required changes to the input set in order
3579 * to support the provided mask.
3580 *
3581 * Hardware only supports masking at word (2 byte) granularity and does
3582 * not support full bitwise masking. This implementation simplifies
3583 * even further and only supports fully enabled or fully disabled
3584 * masks for each field, even though we could split the ip4src and
3585 * ip4dst fields.
3586 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003587 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003588 case SCTP_V4_FLOW:
3589 new_mask &= ~I40E_VERIFY_TAG_MASK;
3590 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003591 case TCP_V4_FLOW:
3592 case UDP_V4_FLOW:
3593 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3594
3595 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003596 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3597 new_mask |= I40E_L3_SRC_MASK;
3598 else if (!tcp_ip4_spec->ip4src)
3599 new_mask &= ~I40E_L3_SRC_MASK;
3600 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003601 return -EOPNOTSUPP;
3602
3603 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003604 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3605 new_mask |= I40E_L3_DST_MASK;
3606 else if (!tcp_ip4_spec->ip4dst)
3607 new_mask &= ~I40E_L3_DST_MASK;
3608 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003609 return -EOPNOTSUPP;
3610
3611 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003612 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3613 new_mask |= I40E_L4_SRC_MASK;
3614 else if (!tcp_ip4_spec->psrc)
3615 new_mask &= ~I40E_L4_SRC_MASK;
3616 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003617 return -EOPNOTSUPP;
3618
3619 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003620 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3621 new_mask |= I40E_L4_DST_MASK;
3622 else if (!tcp_ip4_spec->pdst)
3623 new_mask &= ~I40E_L4_DST_MASK;
3624 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003625 return -EOPNOTSUPP;
3626
3627 /* Filtering on Type of Service is not supported. */
3628 if (tcp_ip4_spec->tos)
3629 return -EOPNOTSUPP;
3630
3631 break;
3632 case IP_USER_FLOW:
3633 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3634
3635 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003636 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3637 new_mask |= I40E_L3_SRC_MASK;
3638 else if (!usr_ip4_spec->ip4src)
3639 new_mask &= ~I40E_L3_SRC_MASK;
3640 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003641 return -EOPNOTSUPP;
3642
3643 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003644 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3645 new_mask |= I40E_L3_DST_MASK;
3646 else if (!usr_ip4_spec->ip4dst)
3647 new_mask &= ~I40E_L3_DST_MASK;
3648 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003649 return -EOPNOTSUPP;
3650
3651 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003652 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3653 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3654 else if (!usr_ip4_spec->l4_4_bytes)
3655 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3656 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003657 return -EOPNOTSUPP;
3658
3659 /* Filtering on Type of Service is not supported. */
3660 if (usr_ip4_spec->tos)
3661 return -EOPNOTSUPP;
3662
Jacob Keller0e588de2017-02-06 14:38:50 -08003663 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003664 if (usr_ip4_spec->ip_ver)
3665 return -EINVAL;
3666
Jacob Keller0e588de2017-02-06 14:38:50 -08003667 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003668 if (usr_ip4_spec->proto)
3669 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003670
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003671 break;
3672 default:
3673 return -EOPNOTSUPP;
3674 }
3675
Jacob Keller0e588de2017-02-06 14:38:50 -08003676 /* First, clear all flexible filter entries */
3677 new_mask &= ~I40E_FLEX_INPUT_MASK;
3678
3679 /* If we have a flexible filter, try to add this offset to the correct
3680 * flexible filter PIT list. Once finished, we can update the mask.
3681 * If the src_offset changed, we will get a new mask value which will
3682 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003683 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003684 if (userdef->flex_filter) {
3685 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3686
3687 /* Flexible offset must be even, since the flexible payload
3688 * must be aligned on 2-byte boundary.
3689 */
3690 if (userdef->flex_offset & 0x1) {
3691 dev_warn(&pf->pdev->dev,
3692 "Flexible data offset must be 2-byte aligned\n");
3693 return -EINVAL;
3694 }
3695
3696 src_offset = userdef->flex_offset >> 1;
3697
3698 /* FLX_PIT source offset value is only so large */
3699 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3700 dev_warn(&pf->pdev->dev,
3701 "Flexible data must reside within first 64 bytes of the packet payload\n");
3702 return -EINVAL;
3703 }
3704
3705 /* See if this offset has already been programmed. If we get
3706 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3707 * if we get a NULL pointer, this means we will need to add
3708 * the offset.
3709 */
3710 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3711 src_offset);
3712 if (IS_ERR(flex_pit))
3713 return PTR_ERR(flex_pit);
3714
3715 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3716 * packet types, and thus we need to program both L3 and L4
3717 * flexible values. These must have identical flexible index,
3718 * as otherwise we can't correctly program the input set. So
3719 * we'll find both an L3 and L4 index and make sure they are
3720 * the same.
3721 */
3722 if (flex_l3) {
3723 l3_flex_pit =
3724 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3725 src_offset);
3726 if (IS_ERR(l3_flex_pit))
3727 return PTR_ERR(l3_flex_pit);
3728
3729 if (flex_pit) {
3730 /* If we already had a matching L4 entry, we
3731 * need to make sure that the L3 entry we
3732 * obtained uses the same index.
3733 */
3734 if (l3_flex_pit) {
3735 if (l3_flex_pit->pit_index !=
3736 flex_pit->pit_index) {
3737 return -EINVAL;
3738 }
3739 } else {
3740 new_flex_offset = true;
3741 }
3742 } else {
3743 flex_pit = l3_flex_pit;
3744 }
3745 }
3746
3747 /* If we didn't find an existing flex offset, we need to
3748 * program a new one. However, we don't immediately program it
3749 * here because we will wait to program until after we check
3750 * that it is safe to change the input set.
3751 */
3752 if (!flex_pit) {
3753 new_flex_offset = true;
3754 pit_index = i40e_unused_pit_index(pf);
3755 } else {
3756 pit_index = flex_pit->pit_index;
3757 }
3758
3759 /* Update the mask with the new offset */
3760 new_mask |= i40e_pit_index_to_mask(pit_index);
3761 }
3762
3763 /* If the mask and flexible filter offsets for this filter match the
3764 * currently programmed values we don't need any input set change, so
3765 * this filter is safe to install.
3766 */
3767 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003768 return 0;
3769
3770 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3771 i40e_flow_str(fsp));
3772 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003773 if (new_flex_offset) {
3774 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3775 pit_index, src_offset);
3776 }
Jacob Keller9229e992017-02-06 14:38:47 -08003777
3778 /* Hardware input sets are global across multiple ports, so even the
3779 * main port cannot change them when in MFP mode as this would impact
3780 * any filters on the other ports.
3781 */
3782 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3783 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003784 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003785 }
3786
3787 /* This filter requires us to update the input set. However, hardware
3788 * only supports one input set per flow type, and does not support
3789 * separate masks for each filter. This means that we can only support
3790 * a single mask for all filters of a specific type.
3791 *
3792 * If we have preexisting filters, they obviously depend on the
3793 * current programmed input set. Display a diagnostic message in this
3794 * case explaining why the filter could not be accepted.
3795 */
3796 if (*fdir_filter_count) {
3797 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3798 i40e_flow_str(fsp),
3799 *fdir_filter_count);
3800 return -EOPNOTSUPP;
3801 }
3802
3803 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003804
Jacob Keller0e588de2017-02-06 14:38:50 -08003805 /* Add the new offset and update table, if necessary */
3806 if (new_flex_offset) {
3807 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3808 pit_index);
3809 if (err)
3810 return err;
3811
3812 if (flex_l3) {
3813 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3814 src_offset,
3815 pit_index);
3816 if (err)
3817 return err;
3818 }
3819
3820 i40e_reprogram_flex_pit(pf);
3821 }
3822
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003823 return 0;
3824}
3825
3826/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003827 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003828 * @vsi: pointer to the targeted VSI
3829 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003830 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003831 * Add Flow Director filters for a specific flow spec based on their
3832 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003833 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003834static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3835 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003836{
Jacob Kellere7930952017-02-06 14:38:49 -08003837 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003838 struct ethtool_rx_flow_spec *fsp;
3839 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003840 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003841 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003842 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003843 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003844
3845 if (!vsi)
3846 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003847 pf = vsi->back;
3848
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003849 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3850 return -EOPNOTSUPP;
3851
Jacob Keller47994c12017-04-19 09:25:57 -04003852 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003853 return -ENOSPC;
3854
Jacob Keller0da36b92017-04-19 09:25:55 -04003855 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3856 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003857 return -EBUSY;
3858
Jacob Keller0da36b92017-04-19 09:25:55 -04003859 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003860 return -EBUSY;
3861
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003862 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3863
Jacob Kellere7930952017-02-06 14:38:49 -08003864 /* Parse the user-defined field */
3865 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3866 return -EINVAL;
3867
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003868 /* Extended MAC field is not supported */
3869 if (fsp->flow_type & FLOW_MAC_EXT)
3870 return -EINVAL;
3871
Jacob Keller0e588de2017-02-06 14:38:50 -08003872 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003873 if (ret)
3874 return ret;
3875
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003876 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3877 pf->hw.func_caps.fd_filters_guaranteed)) {
3878 return -EINVAL;
3879 }
3880
Jacob Keller43b15692017-02-06 14:38:48 -08003881 /* ring_cookie is either the drop index, or is a mask of the queue
3882 * index and VF id we wish to target.
3883 */
3884 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3885 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3886 } else {
3887 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3888 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3889
3890 if (!vf) {
3891 if (ring >= vsi->num_queue_pairs)
3892 return -EINVAL;
3893 dest_vsi = vsi->id;
3894 } else {
3895 /* VFs are zero-indexed, so we subtract one here */
3896 vf--;
3897
3898 if (vf >= pf->num_alloc_vfs)
3899 return -EINVAL;
3900 if (ring >= pf->vf[vf].num_queue_pairs)
3901 return -EINVAL;
3902 dest_vsi = pf->vf[vf].lan_vsi_id;
3903 }
3904 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3905 q_index = ring;
3906 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003907
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003908 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003909
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003910 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003911 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003912
3913 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003914 input->q_index = q_index;
3915 input->dest_vsi = dest_vsi;
3916 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003917 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04003918 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08003919 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3920 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08003921 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003922 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00003923
3924 /* Reverse the src and dest notion, since the HW expects them to be from
3925 * Tx perspective where as the input from user is from Rx filter view.
3926 */
3927 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
3928 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08003929 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3930 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003931
Jacob Keller0e588de2017-02-06 14:38:50 -08003932 if (userdef.flex_filter) {
3933 input->flex_filter = true;
3934 input->flex_word = cpu_to_be16(userdef.flex_word);
3935 input->flex_offset = userdef.flex_offset;
3936 }
3937
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003938 ret = i40e_add_del_fdir(vsi, input, true);
3939 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08003940 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003941
Jacob Keller01016da2017-02-06 14:38:40 -08003942 /* Add the input filter to the fdir_input_list, possibly replacing
3943 * a previous filter. Do not free the input structure after adding it
3944 * to the list as this would cause a use-after-free bug.
3945 */
3946 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
3947
3948 return 0;
3949
3950free_input:
3951 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003952 return ret;
3953}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003954
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003955/**
3956 * i40e_set_rxnfc - command to set RX flow classification rules
3957 * @netdev: network interface device structure
3958 * @cmd: ethtool rxnfc command
3959 *
3960 * Returns Success if the command is supported.
3961 **/
3962static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3963{
3964 struct i40e_netdev_priv *np = netdev_priv(netdev);
3965 struct i40e_vsi *vsi = np->vsi;
3966 struct i40e_pf *pf = vsi->back;
3967 int ret = -EOPNOTSUPP;
3968
3969 switch (cmd->cmd) {
3970 case ETHTOOL_SRXFH:
3971 ret = i40e_set_rss_hash_opt(pf, cmd);
3972 break;
3973 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003974 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003975 break;
3976 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003977 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003978 break;
3979 default:
3980 break;
3981 }
3982
3983 return ret;
3984}
3985
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003986/**
3987 * i40e_max_channels - get Max number of combined channels supported
3988 * @vsi: vsi pointer
3989 **/
3990static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
3991{
3992 /* TODO: This code assumes DCB and FD is disabled for now. */
3993 return vsi->alloc_queue_pairs;
3994}
3995
3996/**
3997 * i40e_get_channels - Get the current channels enabled and max supported etc.
3998 * @netdev: network interface device structure
3999 * @ch: ethtool channels structure
4000 *
4001 * We don't support separate tx and rx queues as channels. The other count
4002 * represents how many queues are being used for control. max_combined counts
4003 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4004 * q_vectors since we support a lot more queue pairs than q_vectors.
4005 **/
4006static void i40e_get_channels(struct net_device *dev,
4007 struct ethtool_channels *ch)
4008{
4009 struct i40e_netdev_priv *np = netdev_priv(dev);
4010 struct i40e_vsi *vsi = np->vsi;
4011 struct i40e_pf *pf = vsi->back;
4012
4013 /* report maximum channels */
4014 ch->max_combined = i40e_max_channels(vsi);
4015
4016 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004017 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004018 ch->max_other = ch->other_count;
4019
4020 /* Note: This code assumes DCB is disabled for now. */
4021 ch->combined_count = vsi->num_queue_pairs;
4022}
4023
4024/**
4025 * i40e_set_channels - Set the new channels count.
4026 * @netdev: network interface device structure
4027 * @ch: ethtool channels structure
4028 *
4029 * The new channels count may not be the same as requested by the user
4030 * since it gets rounded down to a power of 2 value.
4031 **/
4032static int i40e_set_channels(struct net_device *dev,
4033 struct ethtool_channels *ch)
4034{
Jacob Keller59826d92016-07-27 12:02:35 -07004035 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004036 struct i40e_netdev_priv *np = netdev_priv(dev);
4037 unsigned int count = ch->combined_count;
4038 struct i40e_vsi *vsi = np->vsi;
4039 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004040 struct i40e_fdir_filter *rule;
4041 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004042 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004043 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004044
4045 /* We do not support setting channels for any other VSI at present */
4046 if (vsi->type != I40E_VSI_MAIN)
4047 return -EINVAL;
4048
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004049 /* We do not support setting channels via ethtool when TCs are
4050 * configured through mqprio
4051 */
4052 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4053 return -EINVAL;
4054
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004055 /* verify they are not requesting separate vectors */
4056 if (!count || ch->rx_count || ch->tx_count)
4057 return -EINVAL;
4058
4059 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004060 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004061 return -EINVAL;
4062
4063 /* verify the number of channels does not exceed hardware limits */
4064 if (count > i40e_max_channels(vsi))
4065 return -EINVAL;
4066
Jacob Keller59826d92016-07-27 12:02:35 -07004067 /* verify that the number of channels does not invalidate any current
4068 * flow director rules
4069 */
4070 hlist_for_each_entry_safe(rule, node2,
4071 &pf->fdir_filter_list, fdir_node) {
4072 if (rule->dest_ctl != drop && count <= rule->q_index) {
4073 dev_warn(&pf->pdev->dev,
4074 "Existing user defined filter %d assigns flow to queue %d\n",
4075 rule->fd_id, rule->q_index);
4076 err = -EINVAL;
4077 }
4078 }
4079
4080 if (err) {
4081 dev_err(&pf->pdev->dev,
4082 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4083 count);
4084 return err;
4085 }
4086
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004087 /* update feature limits from largest to smallest supported values */
4088 /* TODO: Flow director limit, DCB etc */
4089
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004090 /* use rss_reconfig to rebuild with new queue count and update traffic
4091 * class queue mapping
4092 */
4093 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004094 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004095 return 0;
4096 else
4097 return -EINVAL;
4098}
4099
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004100/**
4101 * i40e_get_rxfh_key_size - get the RSS hash key size
4102 * @netdev: network interface device structure
4103 *
4104 * Returns the table size.
4105 **/
4106static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4107{
4108 return I40E_HKEY_ARRAY_SIZE;
4109}
4110
4111/**
4112 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4113 * @netdev: network interface device structure
4114 *
4115 * Returns the table size.
4116 **/
4117static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4118{
4119 return I40E_HLUT_ARRAY_SIZE;
4120}
4121
Alan Brady21675bd2017-10-05 14:53:33 -07004122/**
4123 * i40e_get_rxfh - get the rx flow hash indirection table
4124 * @netdev: network interface device structure
4125 * @indir: indirection table
4126 * @key: hash key
4127 * @hfunc: hash function
4128 *
4129 * Reads the indirection table directly from the hardware. Returns 0 on
4130 * success.
4131 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004132static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4133 u8 *hfunc)
4134{
4135 struct i40e_netdev_priv *np = netdev_priv(netdev);
4136 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004137 u8 *lut, *seed = NULL;
4138 int ret;
4139 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004140
4141 if (hfunc)
4142 *hfunc = ETH_RSS_HASH_TOP;
4143
4144 if (!indir)
4145 return 0;
4146
Helin Zhang043dd652015-10-21 19:56:23 -04004147 seed = key;
4148 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4149 if (!lut)
4150 return -ENOMEM;
4151 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4152 if (ret)
4153 goto out;
4154 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4155 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004156
Helin Zhang043dd652015-10-21 19:56:23 -04004157out:
4158 kfree(lut);
4159
4160 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004161}
4162
4163/**
4164 * i40e_set_rxfh - set the rx flow hash indirection table
4165 * @netdev: network interface device structure
4166 * @indir: indirection table
4167 * @key: hash key
4168 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004169 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004170 * returns 0 after programming the table.
4171 **/
4172static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4173 const u8 *key, const u8 hfunc)
4174{
4175 struct i40e_netdev_priv *np = netdev_priv(netdev);
4176 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004177 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004178 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004179 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004180
4181 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4182 return -EOPNOTSUPP;
4183
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004184 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004185 if (!vsi->rss_hkey_user) {
4186 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4187 GFP_KERNEL);
4188 if (!vsi->rss_hkey_user)
4189 return -ENOMEM;
4190 }
4191 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4192 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004193 }
Helin Zhang28c58692015-10-26 19:44:27 -04004194 if (!vsi->rss_lut_user) {
4195 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4196 if (!vsi->rss_lut_user)
4197 return -ENOMEM;
4198 }
Helin Zhang043dd652015-10-21 19:56:23 -04004199
Helin Zhang28c58692015-10-26 19:44:27 -04004200 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004201 if (indir)
4202 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4203 vsi->rss_lut_user[i] = (u8)(indir[i]);
4204 else
4205 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4206 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004207
4208 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4209 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004210}
4211
Greg Rose7e45ab42015-02-06 08:52:19 +00004212/**
4213 * i40e_get_priv_flags - report device private flags
4214 * @dev: network interface device structure
4215 *
4216 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004217 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004218 * array.
4219 *
4220 * Returns a u32 bitmap of flags.
4221 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004222static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004223{
4224 struct i40e_netdev_priv *np = netdev_priv(dev);
4225 struct i40e_vsi *vsi = np->vsi;
4226 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004227 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004228
Alexander Duyckaca955d2017-03-10 12:22:01 -08004229 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4230 const struct i40e_priv_flags *priv_flags;
4231
4232 priv_flags = &i40e_gstrings_priv_flags[i];
4233
4234 if (priv_flags->flag & pf->flags)
4235 ret_flags |= BIT(i);
4236 }
4237
4238 if (pf->hw.pf_id != 0)
4239 return ret_flags;
4240
4241 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4242 const struct i40e_priv_flags *priv_flags;
4243
4244 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4245
4246 if (priv_flags->flag & pf->flags)
4247 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004248 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004249
4250 return ret_flags;
4251}
4252
Shannon Nelson9ac77262015-08-27 11:42:40 -04004253/**
4254 * i40e_set_priv_flags - set private flags
4255 * @dev: network interface device structure
4256 * @flags: bit flags to be set
4257 **/
4258static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4259{
4260 struct i40e_netdev_priv *np = netdev_priv(dev);
4261 struct i40e_vsi *vsi = np->vsi;
4262 struct i40e_pf *pf = vsi->back;
Jacob Kellerb74f5712017-09-01 13:54:07 -07004263 u32 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004264 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004265
Jacob Keller841c9502017-06-23 04:24:50 -04004266 orig_flags = READ_ONCE(pf->flags);
4267 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004268
Alexander Duyckaca955d2017-03-10 12:22:01 -08004269 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4270 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004271
Alexander Duyckaca955d2017-03-10 12:22:01 -08004272 priv_flags = &i40e_gstrings_priv_flags[i];
4273
Alexander Duyckaca955d2017-03-10 12:22:01 -08004274 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004275 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004276 else
Jacob Keller841c9502017-06-23 04:24:50 -04004277 new_flags &= ~(priv_flags->flag);
4278
4279 /* If this is a read-only flag, it can't be changed */
4280 if (priv_flags->read_only &&
4281 ((orig_flags ^ new_flags) & ~BIT(i)))
4282 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004283 }
4284
4285 if (pf->hw.pf_id != 0)
4286 goto flags_complete;
4287
4288 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4289 const struct i40e_priv_flags *priv_flags;
4290
4291 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4292
Alexander Duyckaca955d2017-03-10 12:22:01 -08004293 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004294 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004295 else
Jacob Keller841c9502017-06-23 04:24:50 -04004296 new_flags &= ~(priv_flags->flag);
4297
4298 /* If this is a read-only flag, it can't be changed */
4299 if (priv_flags->read_only &&
4300 ((orig_flags ^ new_flags) & ~BIT(i)))
4301 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004302 }
4303
4304flags_complete:
Jacob Keller841c9502017-06-23 04:24:50 -04004305 /* Before we finalize any flag changes, we need to perform some
4306 * checks to ensure that the changes are supported and safe.
4307 */
4308
4309 /* ATR eviction is not supported on all devices */
4310 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4311 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4312 return -EOPNOTSUPP;
4313
4314 /* Compare and exchange the new flags into place. If we failed, that
Jacob Kellerb74f5712017-09-01 13:54:07 -07004315 * is if cmpxchg returns anything but the old value, this means that
Jacob Keller841c9502017-06-23 04:24:50 -04004316 * something else has modified the flags variable since we copied it
4317 * originally. We'll just punt with an error and log something in the
4318 * message buffer.
4319 */
Jacob Kellerb74f5712017-09-01 13:54:07 -07004320 if (cmpxchg(&pf->flags, orig_flags, new_flags) != orig_flags) {
Jacob Keller841c9502017-06-23 04:24:50 -04004321 dev_warn(&pf->pdev->dev,
4322 "Unable to update pf->flags as it was modified by another thread...\n");
4323 return -EAGAIN;
4324 }
4325
4326 changed_flags = orig_flags ^ new_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004327
4328 /* Process any additional changes needed as a result of flag changes.
4329 * The changed_flags value reflects the list of bits that were
4330 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004331 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004332
Alexander Duyckaca955d2017-03-10 12:22:01 -08004333 /* Flush current ATR settings if ATR was disabled */
4334 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4335 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004336 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004337 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004338 }
4339
Alexander Duyckaca955d2017-03-10 12:22:01 -08004340 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4341 u16 sw_flags = 0, valid_flags = 0;
4342 int ret;
4343
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004344 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4345 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4346 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4347 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07004348 0, NULL);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004349 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4350 dev_info(&pf->pdev->dev,
4351 "couldn't set switch config bits, err %s aq_err %s\n",
4352 i40e_stat_str(&pf->hw, ret),
4353 i40e_aq_str(&pf->hw,
4354 pf->hw.aq.asq_last_status));
4355 /* not a fatal problem, just keep going */
4356 }
4357 }
4358
Alexander Duyckaca955d2017-03-10 12:22:01 -08004359 /* Issue reset to cause things to take effect, as additional bits
4360 * are added we will need to create a mask of bits requiring reset
4361 */
Mitch Williams64615b52017-08-29 05:32:30 -04004362 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4363 I40E_FLAG_LEGACY_RX |
4364 I40E_FLAG_SOURCE_PRUNING_DISABLED))
Maciej Sosin373149f2017-04-05 07:50:55 -04004365 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004366
Shannon Nelson9ac77262015-08-27 11:42:40 -04004367 return 0;
4368}
4369
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004370/**
4371 * i40e_get_module_info - get (Q)SFP+ module type info
4372 * @netdev: network interface device structure
4373 * @modinfo: module EEPROM size and layout information structure
4374 **/
4375static int i40e_get_module_info(struct net_device *netdev,
4376 struct ethtool_modinfo *modinfo)
4377{
4378 struct i40e_netdev_priv *np = netdev_priv(netdev);
4379 struct i40e_vsi *vsi = np->vsi;
4380 struct i40e_pf *pf = vsi->back;
4381 struct i40e_hw *hw = &pf->hw;
4382 u32 sff8472_comp = 0;
4383 u32 sff8472_swap = 0;
4384 u32 sff8636_rev = 0;
4385 i40e_status status;
4386 u32 type = 0;
4387
4388 /* Check if firmware supports reading module EEPROM. */
4389 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4390 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4391 return -EINVAL;
4392 }
4393
4394 status = i40e_update_link_info(hw);
4395 if (status)
4396 return -EIO;
4397
4398 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4399 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4400 return -EINVAL;
4401 }
4402
4403 type = hw->phy.link_info.module_type[0];
4404
4405 switch (type) {
4406 case I40E_MODULE_TYPE_SFP:
4407 status = i40e_aq_get_phy_register(hw,
4408 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4409 I40E_I2C_EEPROM_DEV_ADDR,
4410 I40E_MODULE_SFF_8472_COMP,
4411 &sff8472_comp, NULL);
4412 if (status)
4413 return -EIO;
4414
4415 status = i40e_aq_get_phy_register(hw,
4416 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4417 I40E_I2C_EEPROM_DEV_ADDR,
4418 I40E_MODULE_SFF_8472_SWAP,
4419 &sff8472_swap, NULL);
4420 if (status)
4421 return -EIO;
4422
4423 /* Check if the module requires address swap to access
4424 * the other EEPROM memory page.
4425 */
4426 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4427 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4428 modinfo->type = ETH_MODULE_SFF_8079;
4429 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4430 } else if (sff8472_comp == 0x00) {
4431 /* Module is not SFF-8472 compliant */
4432 modinfo->type = ETH_MODULE_SFF_8079;
4433 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4434 } else {
4435 modinfo->type = ETH_MODULE_SFF_8472;
4436 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4437 }
4438 break;
4439 case I40E_MODULE_TYPE_QSFP_PLUS:
4440 /* Read from memory page 0. */
4441 status = i40e_aq_get_phy_register(hw,
4442 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4443 0,
4444 I40E_MODULE_REVISION_ADDR,
4445 &sff8636_rev, NULL);
4446 if (status)
4447 return -EIO;
4448 /* Determine revision compliance byte */
4449 if (sff8636_rev > 0x02) {
4450 /* Module is SFF-8636 compliant */
4451 modinfo->type = ETH_MODULE_SFF_8636;
4452 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4453 } else {
4454 modinfo->type = ETH_MODULE_SFF_8436;
4455 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4456 }
4457 break;
4458 case I40E_MODULE_TYPE_QSFP28:
4459 modinfo->type = ETH_MODULE_SFF_8636;
4460 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4461 break;
4462 default:
4463 netdev_err(vsi->netdev, "Module type unrecognized\n");
4464 return -EINVAL;
4465 }
4466 return 0;
4467}
4468
4469/**
4470 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4471 * @netdev: network interface device structure
4472 * @ee: EEPROM dump request structure
4473 * @data: buffer to be filled with EEPROM contents
4474 **/
4475static int i40e_get_module_eeprom(struct net_device *netdev,
4476 struct ethtool_eeprom *ee,
4477 u8 *data)
4478{
4479 struct i40e_netdev_priv *np = netdev_priv(netdev);
4480 struct i40e_vsi *vsi = np->vsi;
4481 struct i40e_pf *pf = vsi->back;
4482 struct i40e_hw *hw = &pf->hw;
4483 bool is_sfp = false;
4484 i40e_status status;
4485 u32 value = 0;
4486 int i;
4487
4488 if (!ee || !ee->len || !data)
4489 return -EINVAL;
4490
4491 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4492 is_sfp = true;
4493
4494 for (i = 0; i < ee->len; i++) {
4495 u32 offset = i + ee->offset;
4496 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4497
4498 /* Check if we need to access the other memory page */
4499 if (is_sfp) {
4500 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4501 offset -= ETH_MODULE_SFF_8079_LEN;
4502 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4503 }
4504 } else {
4505 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4506 /* Compute memory page number and offset. */
4507 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4508 addr++;
4509 }
4510 }
4511
4512 status = i40e_aq_get_phy_register(hw,
4513 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4514 addr, offset, &value, NULL);
4515 if (status)
4516 return -EIO;
4517 data[i] = value;
4518 }
4519 return 0;
4520}
4521
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004522static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004523 .get_drvinfo = i40e_get_drvinfo,
4524 .get_regs_len = i40e_get_regs_len,
4525 .get_regs = i40e_get_regs,
4526 .nway_reset = i40e_nway_reset,
4527 .get_link = ethtool_op_get_link,
4528 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004529 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004530 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004531 .get_eeprom_len = i40e_get_eeprom_len,
4532 .get_eeprom = i40e_get_eeprom,
4533 .get_ringparam = i40e_get_ringparam,
4534 .set_ringparam = i40e_set_ringparam,
4535 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004536 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004537 .get_msglevel = i40e_get_msglevel,
4538 .set_msglevel = i40e_set_msglevel,
4539 .get_rxnfc = i40e_get_rxnfc,
4540 .set_rxnfc = i40e_set_rxnfc,
4541 .self_test = i40e_diag_test,
4542 .get_strings = i40e_get_strings,
4543 .set_phys_id = i40e_set_phys_id,
4544 .get_sset_count = i40e_get_sset_count,
4545 .get_ethtool_stats = i40e_get_ethtool_stats,
4546 .get_coalesce = i40e_get_coalesce,
4547 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004548 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4549 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4550 .get_rxfh = i40e_get_rxfh,
4551 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004552 .get_channels = i40e_get_channels,
4553 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004554 .get_module_info = i40e_get_module_info,
4555 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004556 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004557 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004558 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004559 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004560 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004561 .get_link_ksettings = i40e_get_link_ksettings,
4562 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004563};
4564
4565void i40e_set_ethtool_ops(struct net_device *netdev)
4566{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004567 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004568}