blob: fb4fb524eab22ddfd614b04b86f815961d00aba0 [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),
Anjali Singhai Jaindd353102016-01-15 14:33:12 -080092 I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080093 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
94 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000095};
96
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000097/* These PF_STATs might look like duplicates of some NETDEV_STATs,
98 * but they are separate. This device supports Virtualization, and
99 * as such might have several netdevs supporting VMDq and FCoE going
100 * through a single port. The NETDEV_STATs are for individual netdevs
101 * seen at the top of the stack, and the PF_STATs are for the physical
102 * function at the bottom of the stack hosting those netdevs.
103 *
104 * The PF_STATs are appended to the netdev stats only when ethtool -S
105 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
106 */
Joe Perchesfe180a52016-09-26 20:17:01 -0700107static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000108 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
109 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000110 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
111 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
112 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
113 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
114 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
115 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
117 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000118 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400119 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000120 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
121 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
122 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000123 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000124 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000125 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
126 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
127 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
128 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
129 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
130 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
131 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
132 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
133 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
134 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
135 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
136 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
137 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
138 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
139 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
140 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
141 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
142 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
143 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
144 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
145 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
146 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
147 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
148 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800149 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000150 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
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
Vasu Dev38e00432014-08-01 13:27:03 -0700165#ifdef I40E_FCOE
166static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
167 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
168 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
169 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
170 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
171 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
172 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
173 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
174 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
175};
176
177#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000178#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000179 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
180 * 2 /* Tx and Rx together */ \
181 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000182#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
183#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000184#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700185#ifdef I40E_FCOE
186#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
188 I40E_FCOE_STATS_LEN + \
189 I40E_MISC_STATS_LEN + \
190 I40E_QUEUE_STATS_LEN((n)))
191#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000193 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700195#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000196#define I40E_PFC_STATS_LEN ( \
197 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
201 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
202 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400203#define I40E_VEB_TC_STATS_LEN ( \
204 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
207 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
208 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000209#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400210#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000211#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
212 I40E_PFC_STATS_LEN + \
213 I40E_VSI_STATS_LEN((n)))
214
215enum i40e_ethtool_test_id {
216 I40E_ETH_TEST_REG = 0,
217 I40E_ETH_TEST_EEPROM,
218 I40E_ETH_TEST_INTR,
219 I40E_ETH_TEST_LOOPBACK,
220 I40E_ETH_TEST_LINK,
221};
222
223static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
224 "Register test (offline)",
225 "Eeprom test (offline)",
226 "Interrupt test (offline)",
227 "Loopback test (offline)",
228 "Link test (on/offline)"
229};
230
231#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
232
Anjali Singhai Jainb5569892016-05-03 15:13:12 -0700233static const char i40e_priv_flags_strings_gl[][ETH_GSTRING_LEN] = {
234 "MFP",
235 "LinkPolling",
236 "flow-director-atr",
237 "veb-stats",
238 "hw-atr-eviction",
239 "vf-true-promisc-support",
240};
241
242#define I40E_PRIV_FLAGS_GL_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings_gl)
243
Greg Rose7e45ab42015-02-06 08:52:19 +0000244static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
245 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400246 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400247 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400248 "veb-stats",
Anjali Singhai Jain72b74862016-01-08 17:50:21 -0800249 "hw-atr-eviction",
Greg Rose7e45ab42015-02-06 08:52:19 +0000250};
251
Shannon Nelson9ac77262015-08-27 11:42:40 -0400252#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000253
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000255 * i40e_partition_setting_complaint - generic complaint for MFP restriction
256 * @pf: the PF struct
257 **/
258static void i40e_partition_setting_complaint(struct i40e_pf *pf)
259{
260 dev_info(&pf->pdev->dev,
261 "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");
262}
263
264/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700265 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
266 * @phy_types: PHY types to convert
267 * @supported: pointer to the ethtool supported variable to fill in
268 * @advertising: pointer to the ethtool advertising variable to fill in
269 *
270 **/
271static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
272 u32 *advertising)
273{
274 enum i40e_aq_capabilities_phy_type phy_types = pf->hw.phy.phy_types;
Avinash Dayanand28537042016-06-20 09:10:33 -0700275 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700276 *supported = 0x0;
277 *advertising = 0x0;
278
279 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
280 *supported |= SUPPORTED_Autoneg |
281 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700282 *advertising |= ADVERTISED_Autoneg;
283 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
284 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700285 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
286 *supported |= SUPPORTED_100baseT_Full;
287 *advertising |= ADVERTISED_100baseT_Full;
288 }
289 }
290 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
291 phy_types & I40E_CAP_PHY_TYPE_XFI ||
292 phy_types & I40E_CAP_PHY_TYPE_SFI ||
293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
294 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
295 *supported |= SUPPORTED_10000baseT_Full;
296 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
297 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
298 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
299 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
300 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
301 *supported |= SUPPORTED_Autoneg |
302 SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700303 *advertising |= ADVERTISED_Autoneg;
304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
305 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700306 }
307 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
308 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
309 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
310 *supported |= SUPPORTED_40000baseCR4_Full;
311 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
312 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
313 *supported |= SUPPORTED_Autoneg |
314 SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700315 *advertising |= ADVERTISED_Autoneg;
316 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
317 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700318 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700319 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700320 *supported |= SUPPORTED_Autoneg |
321 SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700322 *advertising |= ADVERTISED_Autoneg;
323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
324 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700325 }
326 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
327 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
328 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
329 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
330 *supported |= SUPPORTED_Autoneg |
331 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700332 *advertising |= ADVERTISED_Autoneg;
333 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
334 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700335 }
336 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
337 *supported |= SUPPORTED_40000baseSR4_Full;
338 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
339 *supported |= SUPPORTED_40000baseLR4_Full;
340 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
341 *supported |= SUPPORTED_40000baseKR4_Full |
342 SUPPORTED_Autoneg;
343 *advertising |= ADVERTISED_40000baseKR4_Full |
344 ADVERTISED_Autoneg;
345 }
346 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
347 *supported |= SUPPORTED_20000baseKR2_Full |
348 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700349 *advertising |= ADVERTISED_Autoneg;
350 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
351 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700352 }
353 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
354 *supported |= SUPPORTED_10000baseKR_Full |
355 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700356 *advertising |= ADVERTISED_Autoneg;
357 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
358 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700359 }
360 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
361 *supported |= SUPPORTED_10000baseKX4_Full |
362 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700363 *advertising |= ADVERTISED_Autoneg;
364 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
365 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700366 }
367 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
368 *supported |= SUPPORTED_1000baseKX_Full |
369 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700370 *advertising |= ADVERTISED_Autoneg;
371 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
372 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700373 }
374}
375
376/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000377 * i40e_get_settings_link_up - Get the Link settings for when link is up
378 * @hw: hw structure
379 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000381 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000382 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000383static void i40e_get_settings_link_up(struct i40e_hw *hw,
384 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400385 struct net_device *netdev,
386 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000388 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000389 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700390 u32 e_advertising = 0x0;
391 u32 e_supported = 0x0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000392
Catherine Sullivane8278452015-02-06 08:52:08 +0000393 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000394 switch (hw_link_info->phy_type) {
395 case I40E_PHY_TYPE_40GBASE_CR4:
396 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000397 ecmd->supported = SUPPORTED_Autoneg |
398 SUPPORTED_40000baseCR4_Full;
399 ecmd->advertising = ADVERTISED_Autoneg |
400 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000401 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000402 case I40E_PHY_TYPE_XLAUI:
403 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000404 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000405 ecmd->supported = SUPPORTED_40000baseCR4_Full;
406 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000407 case I40E_PHY_TYPE_40GBASE_SR4:
408 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000409 break;
410 case I40E_PHY_TYPE_40GBASE_LR4:
411 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000412 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000413 case I40E_PHY_TYPE_10GBASE_SR:
414 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000415 case I40E_PHY_TYPE_1000BASE_SX:
416 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400417 ecmd->supported = SUPPORTED_10000baseT_Full;
418 if (hw_link_info->module_type[2] &
419 I40E_MODULE_TYPE_1000BASE_SX ||
420 hw_link_info->module_type[2] &
421 I40E_MODULE_TYPE_1000BASE_LX) {
422 ecmd->supported |= SUPPORTED_1000baseT_Full;
423 if (hw_link_info->requested_speeds &
424 I40E_LINK_SPEED_1GB)
425 ecmd->advertising |= ADVERTISED_1000baseT_Full;
426 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000427 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
428 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000429 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000430 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000431 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700432 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000433 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000434 SUPPORTED_10000baseT_Full |
Catherine Sullivan06566e52016-05-03 15:13:14 -0700435 SUPPORTED_1000baseT_Full |
436 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000437 ecmd->advertising = ADVERTISED_Autoneg;
438 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
439 ecmd->advertising |= ADVERTISED_10000baseT_Full;
440 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
441 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700442 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
443 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400444 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400445 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
446 ecmd->supported = SUPPORTED_Autoneg |
447 SUPPORTED_1000baseT_Full;
448 ecmd->advertising = ADVERTISED_Autoneg |
449 ADVERTISED_1000baseT_Full;
450 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000451 case I40E_PHY_TYPE_10GBASE_CR1_CU:
452 case I40E_PHY_TYPE_10GBASE_CR1:
453 ecmd->supported = SUPPORTED_Autoneg |
454 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000455 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000456 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000457 break;
458 case I40E_PHY_TYPE_XAUI:
459 case I40E_PHY_TYPE_XFI:
460 case I40E_PHY_TYPE_SFI:
461 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000462 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000463 ecmd->supported = SUPPORTED_10000baseT_Full;
Stefan Assmann91698272016-06-27 15:03:43 +0200464 ecmd->advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000465 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000466 case I40E_PHY_TYPE_SGMII:
467 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400468 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000469 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
470 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800471 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400472 ecmd->supported |= SUPPORTED_100baseT_Full;
473 if (hw_link_info->requested_speeds &
474 I40E_LINK_SPEED_100MB)
475 ecmd->advertising |= ADVERTISED_100baseT_Full;
476 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000477 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400478 case I40E_PHY_TYPE_40GBASE_KR4:
479 case I40E_PHY_TYPE_20GBASE_KR2:
480 case I40E_PHY_TYPE_10GBASE_KR:
481 case I40E_PHY_TYPE_10GBASE_KX4:
482 case I40E_PHY_TYPE_1000BASE_KX:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700483 ecmd->supported |= SUPPORTED_40000baseKR4_Full |
484 SUPPORTED_20000baseKR2_Full |
485 SUPPORTED_10000baseKR_Full |
486 SUPPORTED_10000baseKX4_Full |
487 SUPPORTED_1000baseKX_Full |
488 SUPPORTED_Autoneg;
489 ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
490 ADVERTISED_20000baseKR2_Full |
491 ADVERTISED_10000baseKR_Full |
492 ADVERTISED_10000baseKX4_Full |
493 ADVERTISED_1000baseKX_Full |
494 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400495 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000496 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000497 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000498 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
499 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000500 }
501
Catherine Sullivan06566e52016-05-03 15:13:14 -0700502 /* Now that we've worked out everything that could be supported by the
503 * current PHY type, get what is supported by the NVM and them to
504 * get what is truly supported
505 */
506 i40e_phy_type_to_ethtool(pf, &e_supported,
507 &e_advertising);
508
509 ecmd->supported = ecmd->supported & e_supported;
510 ecmd->advertising = ecmd->advertising & e_advertising;
511
Catherine Sullivane8278452015-02-06 08:52:08 +0000512 /* Set speed and duplex */
513 switch (link_speed) {
514 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400515 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000516 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700517 case I40E_LINK_SPEED_20GB:
518 ethtool_cmd_speed_set(ecmd, SPEED_20000);
519 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000520 case I40E_LINK_SPEED_10GB:
521 ethtool_cmd_speed_set(ecmd, SPEED_10000);
522 break;
523 case I40E_LINK_SPEED_1GB:
524 ethtool_cmd_speed_set(ecmd, SPEED_1000);
525 break;
526 case I40E_LINK_SPEED_100MB:
527 ethtool_cmd_speed_set(ecmd, SPEED_100);
528 break;
529 default:
530 break;
531 }
532 ecmd->duplex = DUPLEX_FULL;
533}
534
535/**
536 * i40e_get_settings_link_down - Get the Link settings for when link is down
537 * @hw: hw structure
538 * @ecmd: ethtool command to fill in
539 *
540 * Reports link settings that can be determined when link is down
541 **/
542static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400543 struct ethtool_cmd *ecmd,
544 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000545{
Catherine Sullivane8278452015-02-06 08:52:08 +0000546 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400547 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000548 */
Catherine Sullivan06566e52016-05-03 15:13:14 -0700549 i40e_phy_type_to_ethtool(pf, &ecmd->supported,
550 &ecmd->advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000551
552 /* With no link speed and duplex are unknown */
553 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
554 ecmd->duplex = DUPLEX_UNKNOWN;
555}
556
557/**
558 * i40e_get_settings - Get Link Speed and Duplex settings
559 * @netdev: network interface device structure
560 * @ecmd: ethtool command
561 *
562 * Reports speed/duplex settings based on media_type
563 **/
564static int i40e_get_settings(struct net_device *netdev,
565 struct ethtool_cmd *ecmd)
566{
567 struct i40e_netdev_priv *np = netdev_priv(netdev);
568 struct i40e_pf *pf = np->vsi->back;
569 struct i40e_hw *hw = &pf->hw;
570 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
571 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
572
573 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400574 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000575 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400576 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000577
578 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000579 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000580 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
581 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000582
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000583 switch (hw->phy.media_type) {
584 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000585 ecmd->supported |= SUPPORTED_Autoneg |
586 SUPPORTED_Backplane;
587 ecmd->advertising |= ADVERTISED_Autoneg |
588 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000589 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000590 break;
591 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000592 ecmd->supported |= SUPPORTED_TP;
593 ecmd->advertising |= ADVERTISED_TP;
594 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000595 break;
596 case I40E_MEDIA_TYPE_DA:
597 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000598 ecmd->supported |= SUPPORTED_FIBRE;
599 ecmd->advertising |= ADVERTISED_FIBRE;
600 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000601 break;
602 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000603 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000604 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000605 break;
606 case I40E_MEDIA_TYPE_UNKNOWN:
607 default:
608 ecmd->port = PORT_OTHER;
609 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000610 }
611
Catherine Sullivane8278452015-02-06 08:52:08 +0000612 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000613 ecmd->transceiver = XCVR_EXTERNAL;
614
Catherine Sullivane8278452015-02-06 08:52:08 +0000615 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000616 ecmd->supported |= SUPPORTED_Pause;
617
Catherine Sullivane8278452015-02-06 08:52:08 +0000618 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000619 case I40E_FC_FULL:
620 ecmd->advertising |= ADVERTISED_Pause;
621 break;
622 case I40E_FC_TX_PAUSE:
623 ecmd->advertising |= ADVERTISED_Asym_Pause;
624 break;
625 case I40E_FC_RX_PAUSE:
626 ecmd->advertising |= (ADVERTISED_Pause |
627 ADVERTISED_Asym_Pause);
628 break;
629 default:
630 ecmd->advertising &= ~(ADVERTISED_Pause |
631 ADVERTISED_Asym_Pause);
632 break;
633 }
634
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000635 return 0;
636}
637
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000638/**
639 * i40e_set_settings - Set Speed and Duplex
640 * @netdev: network interface device structure
641 * @ecmd: ethtool command
642 *
643 * Set speed/duplex per media_types advertised/forced
644 **/
645static int i40e_set_settings(struct net_device *netdev,
646 struct ethtool_cmd *ecmd)
647{
648 struct i40e_netdev_priv *np = netdev_priv(netdev);
649 struct i40e_aq_get_phy_abilities_resp abilities;
650 struct i40e_aq_set_phy_config config;
651 struct i40e_pf *pf = np->vsi->back;
652 struct i40e_vsi *vsi = np->vsi;
653 struct i40e_hw *hw = &pf->hw;
654 struct ethtool_cmd safe_ecmd;
655 i40e_status status = 0;
656 bool change = false;
657 int err = 0;
658 u8 autoneg;
659 u32 advertise;
660
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000661 /* Changing port settings is not supported if this isn't the
662 * port's controlling PF
663 */
664 if (hw->partition_id != 1) {
665 i40e_partition_setting_complaint(pf);
666 return -EOPNOTSUPP;
667 }
668
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000669 if (vsi != pf->vsi[pf->lan_vsi])
670 return -EOPNOTSUPP;
671
672 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
673 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000674 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700675 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000676 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000677 return -EOPNOTSUPP;
678
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400679 if (hw->device_id == I40E_DEV_ID_KX_B ||
680 hw->device_id == I40E_DEV_ID_KX_C ||
681 hw->device_id == I40E_DEV_ID_20G_KR2 ||
682 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
683 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
684 return -EOPNOTSUPP;
685 }
686
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000687 /* get our own copy of the bits to check against */
688 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
689 i40e_get_settings(netdev, &safe_ecmd);
690
691 /* save autoneg and speed out of ecmd */
692 autoneg = ecmd->autoneg;
693 advertise = ecmd->advertising;
694
695 /* set autoneg and speed back to what they currently are */
696 ecmd->autoneg = safe_ecmd.autoneg;
697 ecmd->advertising = safe_ecmd.advertising;
698
699 ecmd->cmd = safe_ecmd.cmd;
700 /* If ecmd and safe_ecmd are not the same now, then they are
701 * trying to set something that we do not support
702 */
703 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
704 return -EOPNOTSUPP;
705
706 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
707 usleep_range(1000, 2000);
708
709 /* Get the current phy config */
710 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
711 NULL);
712 if (status)
713 return -EAGAIN;
714
Catherine Sullivan124ed152014-07-12 07:28:12 +0000715 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000716 * set below
717 */
718 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000719 config.abilities = abilities.abilities;
720
721 /* Check autoneg */
722 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000723 /* If autoneg was not already enabled */
724 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400725 /* If autoneg is not supported, return error */
726 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
727 netdev_info(netdev, "Autoneg not supported on this phy\n");
728 return -EINVAL;
729 }
730 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000731 config.abilities = abilities.abilities |
732 I40E_AQ_PHY_ENABLE_AN;
733 change = true;
734 }
735 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000736 /* If autoneg is currently enabled */
737 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400738 /* If autoneg is supported 10GBASE_T is the only PHY
739 * that can disable it, so otherwise return error
740 */
741 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
742 hw->phy.link_info.phy_type !=
743 I40E_PHY_TYPE_10GBASE_T) {
744 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
745 return -EINVAL;
746 }
747 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000748 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000749 ~I40E_AQ_PHY_ENABLE_AN;
750 change = true;
751 }
752 }
753
754 if (advertise & ~safe_ecmd.supported)
755 return -EINVAL;
756
757 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000758 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000759 if (advertise & ADVERTISED_1000baseT_Full ||
760 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000761 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000762 if (advertise & ADVERTISED_10000baseT_Full ||
763 advertise & ADVERTISED_10000baseKX4_Full ||
764 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000765 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700766 if (advertise & ADVERTISED_20000baseKR2_Full)
767 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000768 if (advertise & ADVERTISED_40000baseKR4_Full ||
769 advertise & ADVERTISED_40000baseCR4_Full ||
770 advertise & ADVERTISED_40000baseSR4_Full ||
771 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000772 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000773
Catherine Sullivan0002e112015-08-26 15:14:16 -0400774 /* If speed didn't get set, set it to what it currently is.
775 * This is needed because if advertise is 0 (as it is when autoneg
776 * is disabled) then speed won't get set.
777 */
778 if (!config.link_speed)
779 config.link_speed = abilities.link_speed;
780
Catherine Sullivan124ed152014-07-12 07:28:12 +0000781 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000782 /* copy over the rest of the abilities */
783 config.phy_type = abilities.phy_type;
784 config.eee_capability = abilities.eee_capability;
785 config.eeer = abilities.eeer_val;
786 config.low_power_ctrl = abilities.d3_lpan;
787
Catherine Sullivane8278452015-02-06 08:52:08 +0000788 /* save the requested speeds */
789 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000790 /* set link and auto negotiation so changes take effect */
791 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
792 /* If link is up put link down */
793 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
794 /* Tell the OS link is going down, the link will go
795 * back up when fw says it is ready asynchronously
796 */
Matt Jaredc156f852015-08-27 11:42:39 -0400797 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000798 netif_carrier_off(netdev);
799 netif_tx_stop_all_queues(netdev);
800 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000801
802 /* make the aq call */
803 status = i40e_aq_set_phy_config(hw, &config, NULL);
804 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400805 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
806 i40e_stat_str(hw, status),
807 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000808 return -EAGAIN;
809 }
810
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400811 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000812 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400813 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
814 i40e_stat_str(hw, status),
815 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000816
817 } else {
818 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
819 }
820
821 return err;
822}
823
Jesse Brandeburga6599722014-06-04 08:45:25 +0000824static int i40e_nway_reset(struct net_device *netdev)
825{
826 /* restart autonegotiation */
827 struct i40e_netdev_priv *np = netdev_priv(netdev);
828 struct i40e_pf *pf = np->vsi->back;
829 struct i40e_hw *hw = &pf->hw;
830 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
831 i40e_status ret = 0;
832
833 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
834 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400835 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
836 i40e_stat_str(hw, ret),
837 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000838 return -EIO;
839 }
840
841 return 0;
842}
843
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000844/**
845 * i40e_get_pauseparam - Get Flow Control status
846 * Return tx/rx-pause status
847 **/
848static void i40e_get_pauseparam(struct net_device *netdev,
849 struct ethtool_pauseparam *pause)
850{
851 struct i40e_netdev_priv *np = netdev_priv(netdev);
852 struct i40e_pf *pf = np->vsi->back;
853 struct i40e_hw *hw = &pf->hw;
854 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000855 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000856
857 pause->autoneg =
858 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
859 AUTONEG_ENABLE : AUTONEG_DISABLE);
860
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000861 /* PFC enabled so report LFC as off */
862 if (dcbx_cfg->pfc.pfcenable) {
863 pause->rx_pause = 0;
864 pause->tx_pause = 0;
865 return;
866 }
867
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000868 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000869 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000870 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000871 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000872 } else if (hw->fc.current_mode == I40E_FC_FULL) {
873 pause->rx_pause = 1;
874 pause->tx_pause = 1;
875 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000876}
877
Catherine Sullivan2becc352014-06-04 08:45:27 +0000878/**
879 * i40e_set_pauseparam - Set Flow Control parameter
880 * @netdev: network interface device structure
881 * @pause: return tx/rx flow control status
882 **/
883static int i40e_set_pauseparam(struct net_device *netdev,
884 struct ethtool_pauseparam *pause)
885{
886 struct i40e_netdev_priv *np = netdev_priv(netdev);
887 struct i40e_pf *pf = np->vsi->back;
888 struct i40e_vsi *vsi = np->vsi;
889 struct i40e_hw *hw = &pf->hw;
890 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000891 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000892 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
893 i40e_status status;
894 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000895 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000896
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000897 /* Changing the port's flow control is not supported if this isn't the
898 * port's controlling PF
899 */
900 if (hw->partition_id != 1) {
901 i40e_partition_setting_complaint(pf);
902 return -EOPNOTSUPP;
903 }
904
Catherine Sullivan2becc352014-06-04 08:45:27 +0000905 if (vsi != pf->vsi[pf->lan_vsi])
906 return -EOPNOTSUPP;
907
908 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
909 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
910 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
911 return -EOPNOTSUPP;
912 }
913
914 /* If we have link and don't have autoneg */
915 if (!test_bit(__I40E_DOWN, &pf->state) &&
916 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
917 /* Send message that it might not necessarily work*/
918 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
919 }
920
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000921 if (dcbx_cfg->pfc.pfcenable) {
922 netdev_info(netdev,
923 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000924 return -EOPNOTSUPP;
925 }
926
927 if (pause->rx_pause && pause->tx_pause)
928 hw->fc.requested_mode = I40E_FC_FULL;
929 else if (pause->rx_pause && !pause->tx_pause)
930 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
931 else if (!pause->rx_pause && pause->tx_pause)
932 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
933 else if (!pause->rx_pause && !pause->tx_pause)
934 hw->fc.requested_mode = I40E_FC_NONE;
935 else
936 return -EINVAL;
937
Catherine Sullivan94128512014-07-12 07:28:16 +0000938 /* Tell the OS link is going down, the link will go back up when fw
939 * says it is ready asynchronously
940 */
Matt Jaredc156f852015-08-27 11:42:39 -0400941 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000942 netif_carrier_off(netdev);
943 netif_tx_stop_all_queues(netdev);
944
Catherine Sullivan2becc352014-06-04 08:45:27 +0000945 /* Set the fc mode and only restart an if link is up*/
946 status = i40e_set_fc(hw, &aq_failures, link_up);
947
948 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400949 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
950 i40e_stat_str(hw, status),
951 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000952 err = -EAGAIN;
953 }
954 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400955 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
956 i40e_stat_str(hw, status),
957 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000958 err = -EAGAIN;
959 }
960 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400961 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
962 i40e_stat_str(hw, status),
963 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000964 err = -EAGAIN;
965 }
966
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000967 if (!test_bit(__I40E_DOWN, &pf->state)) {
968 /* Give it a little more time to try to come back */
969 msleep(75);
970 if (!test_bit(__I40E_DOWN, &pf->state))
971 return i40e_nway_reset(netdev);
972 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000973
974 return err;
975}
976
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000977static u32 i40e_get_msglevel(struct net_device *netdev)
978{
979 struct i40e_netdev_priv *np = netdev_priv(netdev);
980 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -0400981 u32 debug_mask = pf->hw.debug_mask;
982
983 if (debug_mask)
984 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000985
986 return pf->msg_enable;
987}
988
989static void i40e_set_msglevel(struct net_device *netdev, u32 data)
990{
991 struct i40e_netdev_priv *np = netdev_priv(netdev);
992 struct i40e_pf *pf = np->vsi->back;
993
994 if (I40E_DEBUG_USER & data)
995 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -0400996 else
997 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000998}
999
1000static int i40e_get_regs_len(struct net_device *netdev)
1001{
1002 int reg_count = 0;
1003 int i;
1004
1005 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1006 reg_count += i40e_reg_list[i].elements;
1007
1008 return reg_count * sizeof(u32);
1009}
1010
1011static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1012 void *p)
1013{
1014 struct i40e_netdev_priv *np = netdev_priv(netdev);
1015 struct i40e_pf *pf = np->vsi->back;
1016 struct i40e_hw *hw = &pf->hw;
1017 u32 *reg_buf = p;
1018 int i, j, ri;
1019 u32 reg;
1020
1021 /* Tell ethtool which driver-version-specific regs output we have.
1022 *
1023 * At some point, if we have ethtool doing special formatting of
1024 * this data, it will rely on this version number to know how to
1025 * interpret things. Hence, this needs to be updated if/when the
1026 * diags register table is changed.
1027 */
1028 regs->version = 1;
1029
1030 /* loop through the diags reg table for what to print */
1031 ri = 0;
1032 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1033 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1034 reg = i40e_reg_list[i].offset
1035 + (j * i40e_reg_list[i].stride);
1036 reg_buf[ri++] = rd32(hw, reg);
1037 }
1038 }
1039
1040}
1041
1042static int i40e_get_eeprom(struct net_device *netdev,
1043 struct ethtool_eeprom *eeprom, u8 *bytes)
1044{
1045 struct i40e_netdev_priv *np = netdev_priv(netdev);
1046 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001047 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001048 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001049 u8 *eeprom_buff;
1050 u16 i, sectors;
1051 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001052 u32 magic;
1053
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001054#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001055 if (eeprom->len == 0)
1056 return -EINVAL;
1057
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001058 /* check for NVMUpdate access method */
1059 magic = hw->vendor_id | (hw->device_id << 16);
1060 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001061 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1062 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001063
1064 /* make sure it is the right magic for NVMUpdate */
1065 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001066 errno = -EINVAL;
1067 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1068 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1069 errno = -EBUSY;
1070 else
1071 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001072
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001073 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001074 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001075 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1076 ret_val, hw->aq.asq_last_status, errno,
1077 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1078 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001079
1080 return errno;
1081 }
1082
1083 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001084 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1085
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001086 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001087 if (!eeprom_buff)
1088 return -ENOMEM;
1089
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001090 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1091 if (ret_val) {
1092 dev_info(&pf->pdev->dev,
1093 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1094 ret_val, hw->aq.asq_last_status);
1095 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001096 }
1097
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001098 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1099 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1100 len = I40E_NVM_SECTOR_SIZE;
1101 last = false;
1102 for (i = 0; i < sectors; i++) {
1103 if (i == (sectors - 1)) {
1104 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1105 last = true;
1106 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001107 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1108 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001109 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001110 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001111 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001112 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001113 "read NVM failed, invalid offset 0x%x\n",
1114 offset);
1115 break;
1116 } else if (ret_val &&
1117 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1118 dev_info(&pf->pdev->dev,
1119 "read NVM failed, access, offset 0x%x\n",
1120 offset);
1121 break;
1122 } else if (ret_val) {
1123 dev_info(&pf->pdev->dev,
1124 "read NVM failed offset %d err=%d status=0x%x\n",
1125 offset, ret_val, hw->aq.asq_last_status);
1126 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001127 }
1128 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001129
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001130 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001131 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001132free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001133 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001134 return ret_val;
1135}
1136
1137static int i40e_get_eeprom_len(struct net_device *netdev)
1138{
1139 struct i40e_netdev_priv *np = netdev_priv(netdev);
1140 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001141 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001142
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001143 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1144 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1145 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1146 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001147 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001148 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001149}
1150
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001151static int i40e_set_eeprom(struct net_device *netdev,
1152 struct ethtool_eeprom *eeprom, u8 *bytes)
1153{
1154 struct i40e_netdev_priv *np = netdev_priv(netdev);
1155 struct i40e_hw *hw = &np->vsi->back->hw;
1156 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001157 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001158 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001159 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001160 u32 magic;
1161
1162 /* normal ethtool set_eeprom is not supported */
1163 magic = hw->vendor_id | (hw->device_id << 16);
1164 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001165 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001166 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001167 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1168 errno = -EINVAL;
1169 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1170 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1171 errno = -EBUSY;
1172 else
1173 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001174
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001175 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001176 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001177 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1178 ret_val, hw->aq.asq_last_status, errno,
1179 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1180 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001181
1182 return errno;
1183}
1184
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001185static void i40e_get_drvinfo(struct net_device *netdev,
1186 struct ethtool_drvinfo *drvinfo)
1187{
1188 struct i40e_netdev_priv *np = netdev_priv(netdev);
1189 struct i40e_vsi *vsi = np->vsi;
1190 struct i40e_pf *pf = vsi->back;
1191
1192 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1193 strlcpy(drvinfo->version, i40e_driver_version_str,
1194 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001195 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196 sizeof(drvinfo->fw_version));
1197 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1198 sizeof(drvinfo->bus_info));
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001199 if (pf->hw.pf_id == 0)
1200 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_GL_STR_LEN;
1201 else
1202 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001203}
1204
1205static void i40e_get_ringparam(struct net_device *netdev,
1206 struct ethtool_ringparam *ring)
1207{
1208 struct i40e_netdev_priv *np = netdev_priv(netdev);
1209 struct i40e_pf *pf = np->vsi->back;
1210 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1211
1212 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1213 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1214 ring->rx_mini_max_pending = 0;
1215 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001216 ring->rx_pending = vsi->rx_rings[0]->count;
1217 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001218 ring->rx_mini_pending = 0;
1219 ring->rx_jumbo_pending = 0;
1220}
1221
1222static int i40e_set_ringparam(struct net_device *netdev,
1223 struct ethtool_ringparam *ring)
1224{
1225 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1226 struct i40e_netdev_priv *np = netdev_priv(netdev);
1227 struct i40e_vsi *vsi = np->vsi;
1228 struct i40e_pf *pf = vsi->back;
1229 u32 new_rx_count, new_tx_count;
1230 int i, err = 0;
1231
1232 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1233 return -EINVAL;
1234
Shannon Nelson1fa18372013-11-20 10:03:08 +00001235 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1236 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1237 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1238 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1239 netdev_info(netdev,
1240 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1241 ring->tx_pending, ring->rx_pending,
1242 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1243 return -EINVAL;
1244 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001245
Shannon Nelson1fa18372013-11-20 10:03:08 +00001246 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1247 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248
1249 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001250 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1251 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001252 return 0;
1253
1254 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1255 usleep_range(1000, 2000);
1256
1257 if (!netif_running(vsi->netdev)) {
1258 /* simple case - set for the next time the netdev is started */
1259 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001260 vsi->tx_rings[i]->count = new_tx_count;
1261 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001262 }
1263 goto done;
1264 }
1265
1266 /* We can't just free everything and then setup again,
1267 * because the ISRs in MSI-X mode get passed pointers
1268 * to the Tx and Rx ring structs.
1269 */
1270
1271 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001272 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001273 netdev_info(netdev,
1274 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001275 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001276 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1277 sizeof(struct i40e_ring), GFP_KERNEL);
1278 if (!tx_rings) {
1279 err = -ENOMEM;
1280 goto done;
1281 }
1282
1283 for (i = 0; i < vsi->num_queue_pairs; i++) {
1284 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001285 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001286 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001287 /* the desc and bi pointers will be reallocated in the
1288 * setup call
1289 */
1290 tx_rings[i].desc = NULL;
1291 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001292 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1293 if (err) {
1294 while (i) {
1295 i--;
1296 i40e_free_tx_resources(&tx_rings[i]);
1297 }
1298 kfree(tx_rings);
1299 tx_rings = NULL;
1300
1301 goto done;
1302 }
1303 }
1304 }
1305
1306 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001307 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001308 netdev_info(netdev,
1309 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001310 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001311 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1312 sizeof(struct i40e_ring), GFP_KERNEL);
1313 if (!rx_rings) {
1314 err = -ENOMEM;
1315 goto free_tx;
1316 }
1317
1318 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001319 /* this is to allow wr32 to have something to write to
1320 * during early allocation of Rx buffers
1321 */
1322 u32 __iomem faketail = 0;
1323 struct i40e_ring *ring;
1324 u16 unused;
1325
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001326 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001327 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001328 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001329 /* the desc and bi pointers will be reallocated in the
1330 * setup call
1331 */
1332 rx_rings[i].desc = NULL;
1333 rx_rings[i].rx_bi = NULL;
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001334 rx_rings[i].tail = (u8 __iomem *)&faketail;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001335 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001336 if (err)
1337 goto rx_unwind;
1338
1339 /* now allocate the Rx buffers to make sure the OS
1340 * has enough memory, any failure here means abort
1341 */
1342 ring = &rx_rings[i];
1343 unused = I40E_DESC_UNUSED(ring);
1344 err = i40e_alloc_rx_buffers(ring, unused);
1345rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001346 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001347 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001349 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350 kfree(rx_rings);
1351 rx_rings = NULL;
1352
1353 goto free_tx;
1354 }
1355 }
1356 }
1357
1358 /* Bring interface down, copy in the new ring info,
1359 * then restore the interface
1360 */
1361 i40e_down(vsi);
1362
1363 if (tx_rings) {
1364 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001365 i40e_free_tx_resources(vsi->tx_rings[i]);
1366 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001367 }
1368 kfree(tx_rings);
1369 tx_rings = NULL;
1370 }
1371
1372 if (rx_rings) {
1373 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001374 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001375 /* get the real tail offset */
1376 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1377 /* this is to fake out the allocation routine
1378 * into thinking it has to realloc everything
1379 * but the recycling logic will let us re-use
1380 * the buffers allocated above
1381 */
1382 rx_rings[i].next_to_use = 0;
1383 rx_rings[i].next_to_clean = 0;
1384 rx_rings[i].next_to_alloc = 0;
1385 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001386 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001387 }
1388 kfree(rx_rings);
1389 rx_rings = NULL;
1390 }
1391
1392 i40e_up(vsi);
1393
1394free_tx:
1395 /* error cleanup if the Rx allocations failed after getting Tx */
1396 if (tx_rings) {
1397 for (i = 0; i < vsi->num_queue_pairs; i++)
1398 i40e_free_tx_resources(&tx_rings[i]);
1399 kfree(tx_rings);
1400 tx_rings = NULL;
1401 }
1402
1403done:
1404 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1405
1406 return err;
1407}
1408
1409static int i40e_get_sset_count(struct net_device *netdev, int sset)
1410{
1411 struct i40e_netdev_priv *np = netdev_priv(netdev);
1412 struct i40e_vsi *vsi = np->vsi;
1413 struct i40e_pf *pf = vsi->back;
1414
1415 switch (sset) {
1416 case ETH_SS_TEST:
1417 return I40E_TEST_LEN;
1418 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001419 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001420 int len = I40E_PF_STATS_LEN(netdev);
1421
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001422 if ((pf->lan_veb != I40E_NO_VEB) &&
1423 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001424 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001425 return len;
1426 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001427 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001428 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001429 case ETH_SS_PRIV_FLAGS:
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001430 if (pf->hw.pf_id == 0)
1431 return I40E_PRIV_FLAGS_GL_STR_LEN;
1432 else
1433 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001434 default:
1435 return -EOPNOTSUPP;
1436 }
1437}
1438
1439static void i40e_get_ethtool_stats(struct net_device *netdev,
1440 struct ethtool_stats *stats, u64 *data)
1441{
1442 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001443 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001444 struct i40e_vsi *vsi = np->vsi;
1445 struct i40e_pf *pf = vsi->back;
1446 int i = 0;
1447 char *p;
1448 int j;
1449 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001450 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001451
1452 i40e_update_stats(vsi);
1453
1454 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1455 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1456 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1457 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1458 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001459 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1460 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1461 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1462 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1463 }
Vasu Dev38e00432014-08-01 13:27:03 -07001464#ifdef I40E_FCOE
1465 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1466 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1467 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1468 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1469 }
1470#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001471 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001472 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001473 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001474
1475 if (!tx_ring)
1476 continue;
1477
1478 /* process Tx ring statistics */
1479 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001480 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001481 data[i] = tx_ring->stats.packets;
1482 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001483 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001484 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001485
1486 /* Rx ring is the 2nd half of the queue pair */
1487 rx_ring = &tx_ring[1];
1488 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001489 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001490 data[i] = rx_ring->stats.packets;
1491 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001492 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001493 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001495 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001496 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001497 return;
1498
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001499 if ((pf->lan_veb != I40E_NO_VEB) &&
1500 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001501 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001502
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001503 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1504 p = (char *)veb;
1505 p += i40e_gstrings_veb_stats[j].stat_offset;
1506 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1507 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001508 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001509 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1510 data[i++] = veb->tc_stats.tc_tx_packets[j];
1511 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1512 data[i++] = veb->tc_stats.tc_rx_packets[j];
1513 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1514 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001515 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001516 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1517 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1518 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1519 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1520 }
1521 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1522 data[i++] = pf->stats.priority_xon_tx[j];
1523 data[i++] = pf->stats.priority_xoff_tx[j];
1524 }
1525 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1526 data[i++] = pf->stats.priority_xon_rx[j];
1527 data[i++] = pf->stats.priority_xoff_rx[j];
1528 }
1529 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1530 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001531}
1532
1533static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1534 u8 *data)
1535{
1536 struct i40e_netdev_priv *np = netdev_priv(netdev);
1537 struct i40e_vsi *vsi = np->vsi;
1538 struct i40e_pf *pf = vsi->back;
1539 char *p = (char *)data;
1540 int i;
1541
1542 switch (stringset) {
1543 case ETH_SS_TEST:
1544 for (i = 0; i < I40E_TEST_LEN; i++) {
1545 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1546 data += ETH_GSTRING_LEN;
1547 }
1548 break;
1549 case ETH_SS_STATS:
1550 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1551 snprintf(p, ETH_GSTRING_LEN, "%s",
1552 i40e_gstrings_net_stats[i].stat_string);
1553 p += ETH_GSTRING_LEN;
1554 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001555 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1556 snprintf(p, ETH_GSTRING_LEN, "%s",
1557 i40e_gstrings_misc_stats[i].stat_string);
1558 p += ETH_GSTRING_LEN;
1559 }
Vasu Dev38e00432014-08-01 13:27:03 -07001560#ifdef I40E_FCOE
1561 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1562 snprintf(p, ETH_GSTRING_LEN, "%s",
1563 i40e_gstrings_fcoe_stats[i].stat_string);
1564 p += ETH_GSTRING_LEN;
1565 }
1566#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001567 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001568 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001569 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001570 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001572 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001574 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001575 p += ETH_GSTRING_LEN;
1576 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001577 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001578 return;
1579
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001580 if ((pf->lan_veb != I40E_NO_VEB) &&
1581 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001582 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1583 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1584 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001585 p += ETH_GSTRING_LEN;
1586 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001587 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1588 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001589 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001590 p += ETH_GSTRING_LEN;
1591 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001592 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001593 p += ETH_GSTRING_LEN;
1594 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001595 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001596 p += ETH_GSTRING_LEN;
1597 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001598 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001599 p += ETH_GSTRING_LEN;
1600 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001601 }
1602 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1603 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1604 i40e_gstrings_stats[i].stat_string);
1605 p += ETH_GSTRING_LEN;
1606 }
1607 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1608 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001609 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001610 p += ETH_GSTRING_LEN;
1611 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001612 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001613 p += ETH_GSTRING_LEN;
1614 }
1615 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1616 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001617 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001618 p += ETH_GSTRING_LEN;
1619 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001620 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001621 p += ETH_GSTRING_LEN;
1622 }
1623 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1624 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001625 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001626 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627 }
1628 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1629 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001630 case ETH_SS_PRIV_FLAGS:
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001631 if (pf->hw.pf_id == 0) {
1632 for (i = 0; i < I40E_PRIV_FLAGS_GL_STR_LEN; i++) {
1633 memcpy(data, i40e_priv_flags_strings_gl[i],
1634 ETH_GSTRING_LEN);
1635 data += ETH_GSTRING_LEN;
1636 }
1637 } else {
1638 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1639 memcpy(data, i40e_priv_flags_strings[i],
1640 ETH_GSTRING_LEN);
1641 data += ETH_GSTRING_LEN;
1642 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001643 }
1644 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001645 default:
1646 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001647 }
1648}
1649
1650static int i40e_get_ts_info(struct net_device *dev,
1651 struct ethtool_ts_info *info)
1652{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001653 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1654
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001655 /* only report HW timestamping if PTP is enabled */
1656 if (!(pf->flags & I40E_FLAG_PTP))
1657 return ethtool_op_get_ts_info(dev, info);
1658
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001659 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1660 SOF_TIMESTAMPING_RX_SOFTWARE |
1661 SOF_TIMESTAMPING_SOFTWARE |
1662 SOF_TIMESTAMPING_TX_HARDWARE |
1663 SOF_TIMESTAMPING_RX_HARDWARE |
1664 SOF_TIMESTAMPING_RAW_HARDWARE;
1665
1666 if (pf->ptp_clock)
1667 info->phc_index = ptp_clock_index(pf->ptp_clock);
1668 else
1669 info->phc_index = -1;
1670
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001671 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001672
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001673 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1674 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1675 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001676
1677 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001678}
1679
Shannon Nelson7b086392013-11-20 10:02:59 +00001680static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001681{
Shannon Nelson7b086392013-11-20 10:02:59 +00001682 struct i40e_netdev_priv *np = netdev_priv(netdev);
1683 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001684 i40e_status status;
1685 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001686
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001687 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001688 status = i40e_get_link_status(&pf->hw, &link_up);
1689 if (status) {
1690 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1691 *data = 1;
1692 return *data;
1693 }
1694
1695 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001696 *data = 0;
1697 else
1698 *data = 1;
1699
1700 return *data;
1701}
1702
Shannon Nelson7b086392013-11-20 10:02:59 +00001703static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001704{
Shannon Nelson7b086392013-11-20 10:02:59 +00001705 struct i40e_netdev_priv *np = netdev_priv(netdev);
1706 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001707
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001708 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001709 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001710
Shannon Nelson7b086392013-11-20 10:02:59 +00001711 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712}
1713
Shannon Nelson7b086392013-11-20 10:02:59 +00001714static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715{
Shannon Nelson7b086392013-11-20 10:02:59 +00001716 struct i40e_netdev_priv *np = netdev_priv(netdev);
1717 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001718
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001719 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001720 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721
Shannon Nelson4443ec92014-11-13 08:23:12 +00001722 /* forcebly clear the NVM Update state machine */
1723 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1724
Shannon Nelson7b086392013-11-20 10:02:59 +00001725 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001726}
1727
Shannon Nelson7b086392013-11-20 10:02:59 +00001728static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001729{
Shannon Nelson7b086392013-11-20 10:02:59 +00001730 struct i40e_netdev_priv *np = netdev_priv(netdev);
1731 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001732 u16 swc_old = pf->sw_int_count;
1733
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001734 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001735 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1736 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001737 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1738 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1739 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1740 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001741 usleep_range(1000, 2000);
1742 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001743
1744 return *data;
1745}
1746
Shannon Nelson7b086392013-11-20 10:02:59 +00001747static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001748{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001749 struct i40e_netdev_priv *np = netdev_priv(netdev);
1750 struct i40e_pf *pf = np->vsi->back;
1751
1752 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001753 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001754
1755 return *data;
1756}
1757
Greg Rosee17bc412015-04-16 20:05:59 -04001758static inline bool i40e_active_vfs(struct i40e_pf *pf)
1759{
1760 struct i40e_vf *vfs = pf->vf;
1761 int i;
1762
1763 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001764 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001765 return true;
1766 return false;
1767}
1768
Greg Rose510efb22015-07-10 19:36:01 -04001769static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1770{
1771 struct i40e_vsi **vsi = pf->vsi;
1772 int i;
1773
1774 for (i = 0; i < pf->num_alloc_vsi; i++) {
1775 if (!vsi[i])
1776 continue;
1777 if (vsi[i]->type == I40E_VSI_VMDQ2)
1778 return true;
1779 }
1780
1781 return false;
1782}
1783
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001784static void i40e_diag_test(struct net_device *netdev,
1785 struct ethtool_test *eth_test, u64 *data)
1786{
1787 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001788 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001789 struct i40e_pf *pf = np->vsi->back;
1790
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1792 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001793 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001794
Shannon Nelsonf551b432013-11-26 10:49:12 +00001795 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001796
Greg Rose510efb22015-07-10 19:36:01 -04001797 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001798 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001799 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001800 data[I40E_ETH_TEST_REG] = 1;
1801 data[I40E_ETH_TEST_EEPROM] = 1;
1802 data[I40E_ETH_TEST_INTR] = 1;
1803 data[I40E_ETH_TEST_LOOPBACK] = 1;
1804 data[I40E_ETH_TEST_LINK] = 1;
1805 eth_test->flags |= ETH_TEST_FL_FAILED;
1806 clear_bit(__I40E_TESTING, &pf->state);
1807 goto skip_ol_tests;
1808 }
1809
Greg Rose5b86c5c2015-02-26 16:14:35 +00001810 /* If the device is online then take it offline */
1811 if (if_running)
1812 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001813 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001814 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001815 /* This reset does not affect link - if it is
1816 * changed to a type of reset that does affect
1817 * link then the following link test would have
1818 * to be moved to before the reset
1819 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001820 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001821
Shannon Nelson7b086392013-11-20 10:02:59 +00001822 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 eth_test->flags |= ETH_TEST_FL_FAILED;
1824
Shannon Nelson7b086392013-11-20 10:02:59 +00001825 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001826 eth_test->flags |= ETH_TEST_FL_FAILED;
1827
Shannon Nelson7b086392013-11-20 10:02:59 +00001828 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829 eth_test->flags |= ETH_TEST_FL_FAILED;
1830
Shannon Nelson7b086392013-11-20 10:02:59 +00001831 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001832 eth_test->flags |= ETH_TEST_FL_FAILED;
1833
Shannon Nelsonf551b432013-11-26 10:49:12 +00001834 /* run reg test last, a reset is required after it */
1835 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1836 eth_test->flags |= ETH_TEST_FL_FAILED;
1837
1838 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001839 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001840
1841 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001842 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001843 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001844 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001845 netif_info(pf, drv, netdev, "online testing starting\n");
1846
Shannon Nelson7b086392013-11-20 10:02:59 +00001847 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001848 eth_test->flags |= ETH_TEST_FL_FAILED;
1849
1850 /* Offline only tests, not run in online; pass by default */
1851 data[I40E_ETH_TEST_REG] = 0;
1852 data[I40E_ETH_TEST_EEPROM] = 0;
1853 data[I40E_ETH_TEST_INTR] = 0;
1854 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001855 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001856
Greg Rosee17bc412015-04-16 20:05:59 -04001857skip_ol_tests:
1858
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001859 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001860}
1861
1862static void i40e_get_wol(struct net_device *netdev,
1863 struct ethtool_wolinfo *wol)
1864{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001865 struct i40e_netdev_priv *np = netdev_priv(netdev);
1866 struct i40e_pf *pf = np->vsi->back;
1867 struct i40e_hw *hw = &pf->hw;
1868 u16 wol_nvm_bits;
1869
1870 /* NVM bit on means WoL disabled for the port */
1871 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001872 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001873 wol->supported = 0;
1874 wol->wolopts = 0;
1875 } else {
1876 wol->supported = WAKE_MAGIC;
1877 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1878 }
1879}
1880
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001881/**
1882 * i40e_set_wol - set the WakeOnLAN configuration
1883 * @netdev: the netdev in question
1884 * @wol: the ethtool WoL setting data
1885 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001886static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1887{
1888 struct i40e_netdev_priv *np = netdev_priv(netdev);
1889 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001890 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001891 struct i40e_hw *hw = &pf->hw;
1892 u16 wol_nvm_bits;
1893
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001894 /* WoL not supported if this isn't the controlling PF on the port */
1895 if (hw->partition_id != 1) {
1896 i40e_partition_setting_complaint(pf);
1897 return -EOPNOTSUPP;
1898 }
1899
1900 if (vsi != pf->vsi[pf->lan_vsi])
1901 return -EOPNOTSUPP;
1902
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001903 /* NVM bit on means WoL disabled for the port */
1904 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001905 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001906 return -EOPNOTSUPP;
1907
1908 /* only magic packet is supported */
1909 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1910 return -EOPNOTSUPP;
1911
1912 /* is this a new value? */
1913 if (pf->wol_en != !!wol->wolopts) {
1914 pf->wol_en = !!wol->wolopts;
1915 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1916 }
1917
1918 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001919}
1920
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001921static int i40e_set_phys_id(struct net_device *netdev,
1922 enum ethtool_phys_id_state state)
1923{
1924 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001925 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001926 struct i40e_pf *pf = np->vsi->back;
1927 struct i40e_hw *hw = &pf->hw;
1928 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001929 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930
1931 switch (state) {
1932 case ETHTOOL_ID_ACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001933 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1934 pf->led_status = i40e_led_get(hw);
1935 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001936 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001937 ret = i40e_led_get_phy(hw, &temp_status,
1938 &pf->phy_led_val);
1939 pf->led_status = temp_status;
1940 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001941 return blink_freq;
1942 case ETHTOOL_ID_ON:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001943 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1944 i40e_led_set(hw, 0xf, false);
1945 else
1946 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001947 break;
1948 case ETHTOOL_ID_OFF:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001949 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1950 i40e_led_set(hw, 0x0, false);
1951 else
1952 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953 break;
1954 case ETHTOOL_ID_INACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001955 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1956 i40e_led_set(hw, false, pf->led_status);
1957 } else {
1958 ret = i40e_led_set_phy(hw, false, pf->led_status,
1959 (pf->phy_led_val |
1960 I40E_PHY_LED_MODE_ORIG));
1961 i40e_aq_set_phy_debug(hw, 0, NULL);
1962 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001963 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001964 default:
1965 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001966 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001967 if (ret)
1968 return -ENOENT;
1969 else
1970 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001971}
1972
1973/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1974 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1975 * 125us (8000 interrupts per second) == ITR(62)
1976 */
1977
Jacob Keller65e87c02016-09-12 14:18:44 -07001978/**
1979 * __i40e_get_coalesce - get per-queue coalesce settings
1980 * @netdev: the netdev to check
1981 * @ec: ethtool coalesce data structure
1982 * @queue: which queue to pick
1983 *
1984 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
1985 * are per queue. If queue is <0 then we default to queue 0 as the
1986 * representative value.
1987 **/
Kan Lianga75e8002016-02-19 09:24:04 -05001988static int __i40e_get_coalesce(struct net_device *netdev,
1989 struct ethtool_coalesce *ec,
1990 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001991{
1992 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07001993 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001994 struct i40e_vsi *vsi = np->vsi;
1995
1996 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1997 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1998
Kan Lianga75e8002016-02-19 09:24:04 -05001999 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2000 * return queue 0's value to represent.
2001 */
2002 if (queue < 0) {
2003 queue = 0;
2004 } else if (queue >= vsi->num_queue_pairs) {
2005 return -EINVAL;
2006 }
2007
Jacob Keller65e87c02016-09-12 14:18:44 -07002008 rx_ring = vsi->rx_rings[queue];
2009 tx_ring = vsi->tx_rings[queue];
2010
2011 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002012 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002013
Jacob Keller65e87c02016-09-12 14:18:44 -07002014 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002015 ec->use_adaptive_tx_coalesce = 1;
2016
Jacob Keller65e87c02016-09-12 14:18:44 -07002017 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2018 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2019
Kan Lianga75e8002016-02-19 09:24:04 -05002020
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002021 /* we use the _usecs_high to store/set the interrupt rate limit
2022 * that the hardware supports, that almost but not quite
2023 * fits the original intent of the ethtool variable,
2024 * the rx_coalesce_usecs_high limits total interrupts
2025 * per second from both tx/rx sources.
2026 */
2027 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2028 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002029
2030 return 0;
2031}
2032
Jacob Keller65e87c02016-09-12 14:18:44 -07002033/**
2034 * i40e_get_coalesce - get a netdev's coalesce settings
2035 * @netdev: the netdev to check
2036 * @ec: ethtool coalesce data structure
2037 *
2038 * Gets the coalesce settings for a particular netdev. Note that if user has
2039 * modified per-queue settings, this only guarantees to represent queue 0. See
2040 * __i40e_get_coalesce for more details.
2041 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002042static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002043 struct ethtool_coalesce *ec)
2044{
Kan Lianga75e8002016-02-19 09:24:04 -05002045 return __i40e_get_coalesce(netdev, ec, -1);
2046}
2047
Jacob Keller65e87c02016-09-12 14:18:44 -07002048/**
2049 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2050 * @netdev: netdev structure
2051 * @ec: ethtool's coalesce settings
2052 * @queue: the particular queue to read
2053 *
2054 * Will read a specific queue's coalesce settings
2055 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002056static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2057 struct ethtool_coalesce *ec)
2058{
2059 return __i40e_get_coalesce(netdev, ec, queue);
2060}
2061
Jacob Keller65e87c02016-09-12 14:18:44 -07002062/**
2063 * i40e_set_itr_per_queue - set ITR values for specific queue
2064 * @vsi: the VSI to set values for
2065 * @ec: coalesce settings from ethtool
2066 * @queue: the queue to modify
2067 *
2068 * Change the ITR settings for a specific queue.
2069 **/
2070
Kan Lianga75e8002016-02-19 09:24:04 -05002071static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2072 struct ethtool_coalesce *ec,
2073 int queue)
2074{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002075 struct i40e_pf *pf = vsi->back;
2076 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002077 struct i40e_q_vector *q_vector;
2078 u16 vector, intrl;
2079
2080 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
2081
2082 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2083 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2084
2085 if (ec->use_adaptive_rx_coalesce)
2086 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2087 else
2088 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2089
2090 if (ec->use_adaptive_tx_coalesce)
2091 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2092 else
2093 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2094
2095 q_vector = vsi->rx_rings[queue]->q_vector;
2096 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2097 vector = vsi->base_vector + q_vector->v_idx;
2098 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2099
2100 q_vector = vsi->tx_rings[queue]->q_vector;
2101 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2102 vector = vsi->base_vector + q_vector->v_idx;
2103 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2104
2105 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2106 i40e_flush(hw);
2107}
2108
Jacob Keller65e87c02016-09-12 14:18:44 -07002109/**
2110 * __i40e_set_coalesce - set coalesce settings for particular queue
2111 * @netdev: the netdev to change
2112 * @ec: ethtool coalesce settings
2113 * @queue: the queue to change
2114 *
2115 * Sets the coalesce settings for a particular queue.
2116 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002117static int __i40e_set_coalesce(struct net_device *netdev,
2118 struct ethtool_coalesce *ec,
2119 int queue)
2120{
2121 struct i40e_netdev_priv *np = netdev_priv(netdev);
2122 struct i40e_vsi *vsi = np->vsi;
2123 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002124 int i;
2125
2126 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2127 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2128
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002129 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2130 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2131 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2132 return -EINVAL;
2133 }
2134
2135 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2136 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
2137 return -EINVAL;
2138 }
2139
Kan Lianga75e8002016-02-19 09:24:04 -05002140 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002141 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002142 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
Kan Lianga75e8002016-02-19 09:24:04 -05002143 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2144 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2145 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2146 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002147 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002148
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002149 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
2150
Kan Lianga75e8002016-02-19 09:24:04 -05002151 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002152 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002153 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
Kan Lianga75e8002016-02-19 09:24:04 -05002154 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2155 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2156 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2157 return -EINVAL;
2158 }
2159
2160 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2161 * apply to all queues.
2162 */
2163 if (queue < 0) {
2164 for (i = 0; i < vsi->num_queue_pairs; i++)
2165 i40e_set_itr_per_queue(vsi, ec, i);
2166 } else if (queue < vsi->num_queue_pairs) {
2167 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002168 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002169 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2170 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002171 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002172 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002173
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002174 return 0;
2175}
2176
Jacob Keller65e87c02016-09-12 14:18:44 -07002177/**
2178 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2179 * @netdev: the netdev to change
2180 * @ec: ethtool coalesce settings
2181 *
2182 * This will set each queue to the same coalesce settings.
2183 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002184static int i40e_set_coalesce(struct net_device *netdev,
2185 struct ethtool_coalesce *ec)
2186{
2187 return __i40e_set_coalesce(netdev, ec, -1);
2188}
2189
Jacob Keller65e87c02016-09-12 14:18:44 -07002190/**
2191 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2192 * @netdev: the netdev to change
2193 * @ec: ethtool's coalesce settings
2194 * @queue: the queue to change
2195 *
2196 * Sets the specified queue's coalesce settings.
2197 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002198static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2199 struct ethtool_coalesce *ec)
2200{
2201 return __i40e_set_coalesce(netdev, ec, queue);
2202}
2203
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204/**
2205 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2206 * @pf: pointer to the physical function struct
2207 * @cmd: ethtool rxnfc command
2208 *
2209 * Returns Success if the flow is supported, else Invalid Input.
2210 **/
2211static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2212{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002213 struct i40e_hw *hw = &pf->hw;
2214 u8 flow_pctype = 0;
2215 u64 i_set = 0;
2216
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002217 cmd->data = 0;
2218
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002219 switch (cmd->flow_type) {
2220 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002221 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2222 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002223 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002224 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2225 break;
2226 case TCP_V6_FLOW:
2227 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2228 break;
2229 case UDP_V6_FLOW:
2230 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2231 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232 case SCTP_V4_FLOW:
2233 case AH_ESP_V4_FLOW:
2234 case AH_V4_FLOW:
2235 case ESP_V4_FLOW:
2236 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002237 case SCTP_V6_FLOW:
2238 case AH_ESP_V6_FLOW:
2239 case AH_V6_FLOW:
2240 case ESP_V6_FLOW:
2241 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002242 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002243 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2244 break;
2245 default:
2246 return -EINVAL;
2247 }
2248
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002249 /* Read flow based hash input set register */
2250 if (flow_pctype) {
2251 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2252 flow_pctype)) |
2253 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2254 flow_pctype)) << 32);
2255 }
2256
2257 /* Process bits of hash input set */
2258 if (i_set) {
2259 if (i_set & I40E_L4_SRC_MASK)
2260 cmd->data |= RXH_L4_B_0_1;
2261 if (i_set & I40E_L4_DST_MASK)
2262 cmd->data |= RXH_L4_B_2_3;
2263
2264 if (cmd->flow_type == TCP_V4_FLOW ||
2265 cmd->flow_type == UDP_V4_FLOW) {
2266 if (i_set & I40E_L3_SRC_MASK)
2267 cmd->data |= RXH_IP_SRC;
2268 if (i_set & I40E_L3_DST_MASK)
2269 cmd->data |= RXH_IP_DST;
2270 } else if (cmd->flow_type == TCP_V6_FLOW ||
2271 cmd->flow_type == UDP_V6_FLOW) {
2272 if (i_set & I40E_L3_V6_SRC_MASK)
2273 cmd->data |= RXH_IP_SRC;
2274 if (i_set & I40E_L3_V6_DST_MASK)
2275 cmd->data |= RXH_IP_DST;
2276 }
2277 }
2278
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002279 return 0;
2280}
2281
2282/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002283 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2284 * @pf: Pointer to the physical function struct
2285 * @cmd: The command to get or set Rx flow classification rules
2286 * @rule_locs: Array of used rule locations
2287 *
2288 * This function populates both the total and actual rule count of
2289 * the ethtool flow classification command
2290 *
2291 * Returns 0 on success or -EMSGSIZE if entry not found
2292 **/
2293static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2294 struct ethtool_rxnfc *cmd,
2295 u32 *rule_locs)
2296{
2297 struct i40e_fdir_filter *rule;
2298 struct hlist_node *node2;
2299 int cnt = 0;
2300
2301 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002302 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002303
2304 hlist_for_each_entry_safe(rule, node2,
2305 &pf->fdir_filter_list, fdir_node) {
2306 if (cnt == cmd->rule_cnt)
2307 return -EMSGSIZE;
2308
2309 rule_locs[cnt] = rule->fd_id;
2310 cnt++;
2311 }
2312
2313 cmd->rule_cnt = cnt;
2314
2315 return 0;
2316}
2317
2318/**
2319 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2320 * @pf: Pointer to the physical function struct
2321 * @cmd: The command to get or set Rx flow classification rules
2322 *
2323 * This function looks up a filter based on the Rx flow classification
2324 * command and fills the flow spec info for it if found
2325 *
2326 * Returns 0 on success or -EINVAL if filter not found
2327 **/
2328static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2329 struct ethtool_rxnfc *cmd)
2330{
2331 struct ethtool_rx_flow_spec *fsp =
2332 (struct ethtool_rx_flow_spec *)&cmd->fs;
2333 struct i40e_fdir_filter *rule = NULL;
2334 struct hlist_node *node2;
2335
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002336 hlist_for_each_entry_safe(rule, node2,
2337 &pf->fdir_filter_list, fdir_node) {
2338 if (fsp->location <= rule->fd_id)
2339 break;
2340 }
2341
2342 if (!rule || fsp->location != rule->fd_id)
2343 return -EINVAL;
2344
2345 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002346 if (fsp->flow_type == IP_USER_FLOW) {
2347 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2348 fsp->h_u.usr_ip4_spec.proto = 0;
2349 fsp->m_u.usr_ip4_spec.proto = 0;
2350 }
2351
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002352 /* Reverse the src and dest notion, since the HW views them from
2353 * Tx perspective where as the user expects it from Rx filter view.
2354 */
2355 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2356 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2357 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2358 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002359
2360 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2361 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2362 else
2363 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002364
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002365 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2366 struct i40e_vsi *vsi;
2367
2368 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2369 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2370 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2371 fsp->m_ext.data[1] = htonl(0x1);
2372 }
2373 }
2374
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002375 return 0;
2376}
2377
2378/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002379 * i40e_get_rxnfc - command to get RX flow classification rules
2380 * @netdev: network interface device structure
2381 * @cmd: ethtool rxnfc command
2382 *
2383 * Returns Success if the command is supported.
2384 **/
2385static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2386 u32 *rule_locs)
2387{
2388 struct i40e_netdev_priv *np = netdev_priv(netdev);
2389 struct i40e_vsi *vsi = np->vsi;
2390 struct i40e_pf *pf = vsi->back;
2391 int ret = -EOPNOTSUPP;
2392
2393 switch (cmd->cmd) {
2394 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002395 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002396 ret = 0;
2397 break;
2398 case ETHTOOL_GRXFH:
2399 ret = i40e_get_rss_hash_opts(pf, cmd);
2400 break;
2401 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002402 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002403 /* report total rule count */
2404 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002405 ret = 0;
2406 break;
2407 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002408 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002409 break;
2410 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002411 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2412 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002413 default:
2414 break;
2415 }
2416
2417 return ret;
2418}
2419
2420/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002421 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2422 * @nfc: pointer to user request
2423 * @i_setc bits currently set
2424 *
2425 * Returns value of bits to be set per user request
2426 **/
2427static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2428{
2429 u64 i_set = i_setc;
2430 u64 src_l3 = 0, dst_l3 = 0;
2431
2432 if (nfc->data & RXH_L4_B_0_1)
2433 i_set |= I40E_L4_SRC_MASK;
2434 else
2435 i_set &= ~I40E_L4_SRC_MASK;
2436 if (nfc->data & RXH_L4_B_2_3)
2437 i_set |= I40E_L4_DST_MASK;
2438 else
2439 i_set &= ~I40E_L4_DST_MASK;
2440
2441 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2442 src_l3 = I40E_L3_V6_SRC_MASK;
2443 dst_l3 = I40E_L3_V6_DST_MASK;
2444 } else if (nfc->flow_type == TCP_V4_FLOW ||
2445 nfc->flow_type == UDP_V4_FLOW) {
2446 src_l3 = I40E_L3_SRC_MASK;
2447 dst_l3 = I40E_L3_DST_MASK;
2448 } else {
2449 /* Any other flow type are not supported here */
2450 return i_set;
2451 }
2452
2453 if (nfc->data & RXH_IP_SRC)
2454 i_set |= src_l3;
2455 else
2456 i_set &= ~src_l3;
2457 if (nfc->data & RXH_IP_DST)
2458 i_set |= dst_l3;
2459 else
2460 i_set &= ~dst_l3;
2461
2462 return i_set;
2463}
2464
2465/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002466 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2467 * @pf: pointer to the physical function struct
2468 * @cmd: ethtool rxnfc command
2469 *
2470 * Returns Success if the flow input set is supported.
2471 **/
2472static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2473{
2474 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002475 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2476 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002477 u8 flow_pctype = 0;
2478 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002479
2480 /* RSS does not support anything other than hashing
2481 * to queues on src and dst IPs and ports
2482 */
2483 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2484 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2485 return -EINVAL;
2486
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002487 switch (nfc->flow_type) {
2488 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002489 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2490 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2491 hena |=
2492 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002493 break;
2494 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002495 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2496 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2497 hena |=
2498 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2499 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2500 hena |=
2501 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002502 break;
2503 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002504 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2505 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2506 hena |=
2507 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2508 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002509
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002510 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002511 break;
2512 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002513 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2514 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2515 hena |=
2516 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2517 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002518
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002519 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002520 break;
2521 case AH_ESP_V4_FLOW:
2522 case AH_V4_FLOW:
2523 case ESP_V4_FLOW:
2524 case SCTP_V4_FLOW:
2525 if ((nfc->data & RXH_L4_B_0_1) ||
2526 (nfc->data & RXH_L4_B_2_3))
2527 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002528 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002529 break;
2530 case AH_ESP_V6_FLOW:
2531 case AH_V6_FLOW:
2532 case ESP_V6_FLOW:
2533 case SCTP_V6_FLOW:
2534 if ((nfc->data & RXH_L4_B_0_1) ||
2535 (nfc->data & RXH_L4_B_2_3))
2536 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002537 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002538 break;
2539 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002540 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2541 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002542 break;
2543 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002544 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2545 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002546 break;
2547 default:
2548 return -EINVAL;
2549 }
2550
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002551 if (flow_pctype) {
2552 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2553 flow_pctype)) |
2554 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2555 flow_pctype)) << 32);
2556 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2557 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2558 (u32)i_set);
2559 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2560 (u32)(i_set >> 32));
2561 hena |= BIT_ULL(flow_pctype);
2562 }
2563
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002564 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2565 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002566 i40e_flush(hw);
2567
2568 return 0;
2569}
2570
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002571/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002572 * i40e_match_fdir_input_set - Match a new filter against an existing one
2573 * @rule: The filter already added
2574 * @input: The new filter to comapre against
2575 *
2576 * Returns true if the two input set match
2577 **/
2578static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2579 struct i40e_fdir_filter *input)
2580{
2581 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2582 (rule->src_ip[0] != input->src_ip[0]) ||
2583 (rule->dst_port != input->dst_port) ||
2584 (rule->src_port != input->src_port))
2585 return false;
2586 return true;
2587}
2588
2589/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002590 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2591 * @vsi: Pointer to the targeted VSI
2592 * @input: The filter to update or NULL to indicate deletion
2593 * @sw_idx: Software index to the filter
2594 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002595 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002596 * This function updates (or deletes) a Flow Director entry from
2597 * the hlist of the corresponding PF
2598 *
2599 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002600 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002601static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2602 struct i40e_fdir_filter *input,
2603 u16 sw_idx,
2604 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002605{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002606 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002607 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002608 struct hlist_node *node2;
2609 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002610
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002611 parent = NULL;
2612 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002613
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002614 hlist_for_each_entry_safe(rule, node2,
2615 &pf->fdir_filter_list, fdir_node) {
2616 /* hash found, or no matching entry */
2617 if (rule->fd_id >= sw_idx)
2618 break;
2619 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002620 }
2621
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002622 /* if there is an old rule occupying our place remove it */
2623 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002624 if (input && !i40e_match_fdir_input_set(rule, input))
2625 err = i40e_add_del_fdir(vsi, rule, false);
2626 else if (!input)
2627 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002628 hlist_del(&rule->fdir_node);
2629 kfree(rule);
2630 pf->fdir_pf_active_filters--;
2631 }
2632
2633 /* If no input this was a delete, err should be 0 if a rule was
2634 * successfully found and removed from the list else -EINVAL
2635 */
2636 if (!input)
2637 return err;
2638
2639 /* initialize node and set software index */
2640 INIT_HLIST_NODE(&input->fdir_node);
2641
2642 /* add filter to the list */
2643 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002644 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002645 else
2646 hlist_add_head(&input->fdir_node,
2647 &pf->fdir_filter_list);
2648
2649 /* update counts */
2650 pf->fdir_pf_active_filters++;
2651
2652 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002653}
2654
2655/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002656 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2657 * @vsi: Pointer to the targeted VSI
2658 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002659 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002660 * The function removes a Flow Director filter entry from the
2661 * hlist of the corresponding PF
2662 *
2663 * Returns 0 on success
2664 */
2665static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2666 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002667{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002668 struct ethtool_rx_flow_spec *fsp =
2669 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002670 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002671 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002672
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002673 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2674 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2675 return -EBUSY;
2676
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002677 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2678 return -EBUSY;
2679
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002680 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002681
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002682 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002683 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002684}
2685
2686/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002687 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002688 * @vsi: pointer to the targeted VSI
2689 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002690 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002691 * Add Flow Director filters for a specific flow spec based on their
2692 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002693 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002694static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2695 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002696{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002697 struct ethtool_rx_flow_spec *fsp;
2698 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002699 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002700 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002701 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002702
2703 if (!vsi)
2704 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002705 pf = vsi->back;
2706
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002707 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2708 return -EOPNOTSUPP;
2709
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002710 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002711 return -ENOSPC;
2712
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002713 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2714 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2715 return -EBUSY;
2716
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002717 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2718 return -EBUSY;
2719
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002720 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2721
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002722 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2723 pf->hw.func_caps.fd_filters_guaranteed)) {
2724 return -EINVAL;
2725 }
2726
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002727 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2728 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002729 return -EINVAL;
2730
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002731 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002732
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002733 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002734 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002735
2736 input->fd_id = fsp->location;
2737
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002738 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2739 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2740 else
2741 input->dest_ctl =
2742 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2743
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002744 input->q_index = fsp->ring_cookie;
2745 input->flex_off = 0;
2746 input->pctype = 0;
2747 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002748 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002749 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002750 input->flow_type = fsp->flow_type;
2751 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002752
2753 /* Reverse the src and dest notion, since the HW expects them to be from
2754 * Tx perspective where as the input from user is from Rx filter view.
2755 */
2756 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2757 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2758 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2759 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002760
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002761 if (ntohl(fsp->m_ext.data[1])) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002762 vf_id = ntohl(fsp->h_ext.data[1]);
2763 if (vf_id >= pf->num_alloc_vfs) {
2764 netif_info(pf, drv, vsi->netdev,
2765 "Invalid VF id %d\n", vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002766 goto free_input;
2767 }
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002768 /* Find vsi id from vf id and override dest vsi */
2769 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2770 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002771 netif_info(pf, drv, vsi->netdev,
2772 "Invalid queue id %d for VF %d\n",
2773 input->q_index, vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002774 goto free_input;
2775 }
2776 }
2777
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002778 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002779free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002780 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002781 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002782 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002783 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002784
2785 return ret;
2786}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002787
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002788/**
2789 * i40e_set_rxnfc - command to set RX flow classification rules
2790 * @netdev: network interface device structure
2791 * @cmd: ethtool rxnfc command
2792 *
2793 * Returns Success if the command is supported.
2794 **/
2795static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
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_SRXFH:
2804 ret = i40e_set_rss_hash_opt(pf, cmd);
2805 break;
2806 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002807 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002808 break;
2809 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002810 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002811 break;
2812 default:
2813 break;
2814 }
2815
2816 return ret;
2817}
2818
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002819/**
2820 * i40e_max_channels - get Max number of combined channels supported
2821 * @vsi: vsi pointer
2822 **/
2823static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2824{
2825 /* TODO: This code assumes DCB and FD is disabled for now. */
2826 return vsi->alloc_queue_pairs;
2827}
2828
2829/**
2830 * i40e_get_channels - Get the current channels enabled and max supported etc.
2831 * @netdev: network interface device structure
2832 * @ch: ethtool channels structure
2833 *
2834 * We don't support separate tx and rx queues as channels. The other count
2835 * represents how many queues are being used for control. max_combined counts
2836 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2837 * q_vectors since we support a lot more queue pairs than q_vectors.
2838 **/
2839static void i40e_get_channels(struct net_device *dev,
2840 struct ethtool_channels *ch)
2841{
2842 struct i40e_netdev_priv *np = netdev_priv(dev);
2843 struct i40e_vsi *vsi = np->vsi;
2844 struct i40e_pf *pf = vsi->back;
2845
2846 /* report maximum channels */
2847 ch->max_combined = i40e_max_channels(vsi);
2848
2849 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002850 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002851 ch->max_other = ch->other_count;
2852
2853 /* Note: This code assumes DCB is disabled for now. */
2854 ch->combined_count = vsi->num_queue_pairs;
2855}
2856
2857/**
2858 * i40e_set_channels - Set the new channels count.
2859 * @netdev: network interface device structure
2860 * @ch: ethtool channels structure
2861 *
2862 * The new channels count may not be the same as requested by the user
2863 * since it gets rounded down to a power of 2 value.
2864 **/
2865static int i40e_set_channels(struct net_device *dev,
2866 struct ethtool_channels *ch)
2867{
Jacob Keller59826d92016-07-27 12:02:35 -07002868 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002869 struct i40e_netdev_priv *np = netdev_priv(dev);
2870 unsigned int count = ch->combined_count;
2871 struct i40e_vsi *vsi = np->vsi;
2872 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07002873 struct i40e_fdir_filter *rule;
2874 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002875 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07002876 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002877
2878 /* We do not support setting channels for any other VSI at present */
2879 if (vsi->type != I40E_VSI_MAIN)
2880 return -EINVAL;
2881
2882 /* verify they are not requesting separate vectors */
2883 if (!count || ch->rx_count || ch->tx_count)
2884 return -EINVAL;
2885
2886 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002887 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002888 return -EINVAL;
2889
2890 /* verify the number of channels does not exceed hardware limits */
2891 if (count > i40e_max_channels(vsi))
2892 return -EINVAL;
2893
Jacob Keller59826d92016-07-27 12:02:35 -07002894 /* verify that the number of channels does not invalidate any current
2895 * flow director rules
2896 */
2897 hlist_for_each_entry_safe(rule, node2,
2898 &pf->fdir_filter_list, fdir_node) {
2899 if (rule->dest_ctl != drop && count <= rule->q_index) {
2900 dev_warn(&pf->pdev->dev,
2901 "Existing user defined filter %d assigns flow to queue %d\n",
2902 rule->fd_id, rule->q_index);
2903 err = -EINVAL;
2904 }
2905 }
2906
2907 if (err) {
2908 dev_err(&pf->pdev->dev,
2909 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
2910 count);
2911 return err;
2912 }
2913
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002914 /* update feature limits from largest to smallest supported values */
2915 /* TODO: Flow director limit, DCB etc */
2916
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002917 /* use rss_reconfig to rebuild with new queue count and update traffic
2918 * class queue mapping
2919 */
2920 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002921 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002922 return 0;
2923 else
2924 return -EINVAL;
2925}
2926
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002927/**
2928 * i40e_get_rxfh_key_size - get the RSS hash key size
2929 * @netdev: network interface device structure
2930 *
2931 * Returns the table size.
2932 **/
2933static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2934{
2935 return I40E_HKEY_ARRAY_SIZE;
2936}
2937
2938/**
2939 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2940 * @netdev: network interface device structure
2941 *
2942 * Returns the table size.
2943 **/
2944static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2945{
2946 return I40E_HLUT_ARRAY_SIZE;
2947}
2948
2949static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2950 u8 *hfunc)
2951{
2952 struct i40e_netdev_priv *np = netdev_priv(netdev);
2953 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002954 u8 *lut, *seed = NULL;
2955 int ret;
2956 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002957
2958 if (hfunc)
2959 *hfunc = ETH_RSS_HASH_TOP;
2960
2961 if (!indir)
2962 return 0;
2963
Helin Zhang043dd652015-10-21 19:56:23 -04002964 seed = key;
2965 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2966 if (!lut)
2967 return -ENOMEM;
2968 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2969 if (ret)
2970 goto out;
2971 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2972 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002973
Helin Zhang043dd652015-10-21 19:56:23 -04002974out:
2975 kfree(lut);
2976
2977 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002978}
2979
2980/**
2981 * i40e_set_rxfh - set the rx flow hash indirection table
2982 * @netdev: network interface device structure
2983 * @indir: indirection table
2984 * @key: hash key
2985 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002986 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002987 * returns 0 after programming the table.
2988 **/
2989static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2990 const u8 *key, const u8 hfunc)
2991{
2992 struct i40e_netdev_priv *np = netdev_priv(netdev);
2993 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07002994 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04002995 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002996 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002997
2998 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2999 return -EOPNOTSUPP;
3000
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003001 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04003002 if (!vsi->rss_hkey_user) {
3003 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
3004 GFP_KERNEL);
3005 if (!vsi->rss_hkey_user)
3006 return -ENOMEM;
3007 }
3008 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
3009 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003010 }
Helin Zhang28c58692015-10-26 19:44:27 -04003011 if (!vsi->rss_lut_user) {
3012 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3013 if (!vsi->rss_lut_user)
3014 return -ENOMEM;
3015 }
Helin Zhang043dd652015-10-21 19:56:23 -04003016
Helin Zhang28c58692015-10-26 19:44:27 -04003017 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07003018 if (indir)
3019 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3020 vsi->rss_lut_user[i] = (u8)(indir[i]);
3021 else
3022 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
3023 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04003024
3025 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
3026 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003027}
3028
Greg Rose7e45ab42015-02-06 08:52:19 +00003029/**
3030 * i40e_get_priv_flags - report device private flags
3031 * @dev: network interface device structure
3032 *
3033 * The get string set count and the string set should be matched for each
3034 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
3035 * array.
3036 *
3037 * Returns a u32 bitmap of flags.
3038 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00003039static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00003040{
3041 struct i40e_netdev_priv *np = netdev_priv(dev);
3042 struct i40e_vsi *vsi = np->vsi;
3043 struct i40e_pf *pf = vsi->back;
3044 u32 ret_flags = 0;
3045
Shannon Nelson9ac77262015-08-27 11:42:40 -04003046 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
3047 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04003048 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
3049 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003050 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
3051 I40E_PRIV_FLAGS_VEB_STATS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003052 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
3053 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003054 if (pf->hw.pf_id == 0) {
3055 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
3056 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
3057 }
Greg Rose7e45ab42015-02-06 08:52:19 +00003058
3059 return ret_flags;
3060}
3061
Shannon Nelson9ac77262015-08-27 11:42:40 -04003062/**
3063 * i40e_set_priv_flags - set private flags
3064 * @dev: network interface device structure
3065 * @flags: bit flags to be set
3066 **/
3067static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
3068{
3069 struct i40e_netdev_priv *np = netdev_priv(dev);
3070 struct i40e_vsi *vsi = np->vsi;
3071 struct i40e_pf *pf = vsi->back;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003072 u16 sw_flags = 0, valid_flags = 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003073 bool reset_required = false;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003074 bool promisc_change = false;
3075 int ret;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003076
3077 /* NOTE: MFP is not settable */
3078
Shannon Nelson9ac77262015-08-27 11:42:40 -04003079 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
3080 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
3081 else
3082 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
3083
Jesse Brandeburgef171782015-09-03 17:18:49 -04003084 /* allow the user to control the state of the Flow
3085 * Director ATR (Application Targeted Routing) feature
3086 * of the driver
3087 */
3088 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
3089 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
3090 } else {
3091 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
3092 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
Jacob Keller234dc4e2016-09-06 18:05:09 -07003093
3094 /* flush current ATR settings */
3095 set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04003096 }
3097
Shannon Nelson66fc3602016-01-13 16:51:42 -08003098 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3099 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003100 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003101 reset_required = true;
3102 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3103 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003104 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003105 reset_required = true;
3106 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003107
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003108 if (pf->hw.pf_id == 0) {
3109 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3110 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3111 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
3112 promisc_change = true;
3113 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3114 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3115 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
3116 promisc_change = true;
3117 }
3118 }
3119 if (promisc_change) {
3120 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
3121 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3122 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3123 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
3124 NULL);
3125 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
3126 dev_info(&pf->pdev->dev,
3127 "couldn't set switch config bits, err %s aq_err %s\n",
3128 i40e_stat_str(&pf->hw, ret),
3129 i40e_aq_str(&pf->hw,
3130 pf->hw.aq.asq_last_status));
3131 /* not a fatal problem, just keep going */
3132 }
3133 }
3134
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003135 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
3136 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
3137 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
3138 else
3139 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
3140
Jesse Brandeburg827de392015-11-06 15:26:07 -08003141 /* if needed, issue reset to cause things to take effect */
3142 if (reset_required)
3143 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
3144
Shannon Nelson9ac77262015-08-27 11:42:40 -04003145 return 0;
3146}
3147
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003148static const struct ethtool_ops i40e_ethtool_ops = {
3149 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00003150 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003151 .get_drvinfo = i40e_get_drvinfo,
3152 .get_regs_len = i40e_get_regs_len,
3153 .get_regs = i40e_get_regs,
3154 .nway_reset = i40e_nway_reset,
3155 .get_link = ethtool_op_get_link,
3156 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00003157 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003158 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003159 .get_eeprom_len = i40e_get_eeprom_len,
3160 .get_eeprom = i40e_get_eeprom,
3161 .get_ringparam = i40e_get_ringparam,
3162 .set_ringparam = i40e_set_ringparam,
3163 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00003164 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003165 .get_msglevel = i40e_get_msglevel,
3166 .set_msglevel = i40e_set_msglevel,
3167 .get_rxnfc = i40e_get_rxnfc,
3168 .set_rxnfc = i40e_set_rxnfc,
3169 .self_test = i40e_diag_test,
3170 .get_strings = i40e_get_strings,
3171 .set_phys_id = i40e_set_phys_id,
3172 .get_sset_count = i40e_get_sset_count,
3173 .get_ethtool_stats = i40e_get_ethtool_stats,
3174 .get_coalesce = i40e_get_coalesce,
3175 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003176 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3177 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3178 .get_rxfh = i40e_get_rxfh,
3179 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003180 .get_channels = i40e_get_channels,
3181 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003182 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00003183 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04003184 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05003185 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05003186 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003187};
3188
3189void i40e_set_ethtool_ops(struct net_device *netdev)
3190{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003191 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003192}