blob: 9500e7bba76d937cbdcd471d9b504af8afe6d358 [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,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000219 I40E_ETH_TEST_LINK,
220};
221
222static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
223 "Register test (offline)",
224 "Eeprom test (offline)",
225 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000226 "Link test (on/offline)"
227};
228
229#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
230
Greg Rose7e45ab42015-02-06 08:52:19 +0000231static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700232 "MFP",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400233 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400234 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400235 "veb-stats",
Anjali Singhai Jain72b74862016-01-08 17:50:21 -0800236 "hw-atr-eviction",
Greg Rose7e45ab42015-02-06 08:52:19 +0000237};
238
Shannon Nelson9ac77262015-08-27 11:42:40 -0400239#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000240
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700241/* Private flags with a global effect, restricted to PF 0 */
242static const char i40e_gl_priv_flags_strings[][ETH_GSTRING_LEN] = {
243 "vf-true-promisc-support",
244};
245
246#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_priv_flags_strings)
247
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000248/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000249 * i40e_partition_setting_complaint - generic complaint for MFP restriction
250 * @pf: the PF struct
251 **/
252static void i40e_partition_setting_complaint(struct i40e_pf *pf)
253{
254 dev_info(&pf->pdev->dev,
255 "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");
256}
257
258/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700259 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
260 * @phy_types: PHY types to convert
261 * @supported: pointer to the ethtool supported variable to fill in
262 * @advertising: pointer to the ethtool advertising variable to fill in
263 *
264 **/
265static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
266 u32 *advertising)
267{
268 enum i40e_aq_capabilities_phy_type phy_types = pf->hw.phy.phy_types;
Avinash Dayanand28537042016-06-20 09:10:33 -0700269 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700270 *supported = 0x0;
271 *advertising = 0x0;
272
273 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
274 *supported |= SUPPORTED_Autoneg |
275 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700276 *advertising |= ADVERTISED_Autoneg;
277 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
278 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700279 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
280 *supported |= SUPPORTED_100baseT_Full;
281 *advertising |= ADVERTISED_100baseT_Full;
282 }
283 }
284 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
285 phy_types & I40E_CAP_PHY_TYPE_XFI ||
286 phy_types & I40E_CAP_PHY_TYPE_SFI ||
287 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
288 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
289 *supported |= SUPPORTED_10000baseT_Full;
290 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
291 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
292 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
294 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
295 *supported |= SUPPORTED_Autoneg |
296 SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700297 *advertising |= ADVERTISED_Autoneg;
298 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
299 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700300 }
301 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
302 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
303 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
304 *supported |= SUPPORTED_40000baseCR4_Full;
305 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
306 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
307 *supported |= SUPPORTED_Autoneg |
308 SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700309 *advertising |= ADVERTISED_Autoneg;
310 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
311 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700312 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700313 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700314 *supported |= SUPPORTED_Autoneg |
315 SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700316 *advertising |= ADVERTISED_Autoneg;
317 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
318 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700319 }
320 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
321 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
322 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
323 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
324 *supported |= SUPPORTED_Autoneg |
325 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700326 *advertising |= ADVERTISED_Autoneg;
327 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
328 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700329 }
330 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
331 *supported |= SUPPORTED_40000baseSR4_Full;
332 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
333 *supported |= SUPPORTED_40000baseLR4_Full;
334 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
335 *supported |= SUPPORTED_40000baseKR4_Full |
336 SUPPORTED_Autoneg;
337 *advertising |= ADVERTISED_40000baseKR4_Full |
338 ADVERTISED_Autoneg;
339 }
340 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
341 *supported |= SUPPORTED_20000baseKR2_Full |
342 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700343 *advertising |= ADVERTISED_Autoneg;
344 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
345 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700346 }
347 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800348 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
349 *supported |= SUPPORTED_10000baseKR_Full |
350 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700351 *advertising |= ADVERTISED_Autoneg;
352 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800353 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
354 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700355 }
356 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
357 *supported |= SUPPORTED_10000baseKX4_Full |
358 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700359 *advertising |= ADVERTISED_Autoneg;
360 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
361 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700362 }
363 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800364 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
365 *supported |= SUPPORTED_1000baseKX_Full |
366 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700367 *advertising |= ADVERTISED_Autoneg;
368 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800369 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
370 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700371 }
372}
373
374/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000375 * i40e_get_settings_link_up - Get the Link settings for when link is up
376 * @hw: hw structure
377 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000378 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000379 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000381static void i40e_get_settings_link_up(struct i40e_hw *hw,
382 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400383 struct net_device *netdev,
384 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000385{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700388 u32 e_advertising = 0x0;
389 u32 e_supported = 0x0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000390
Catherine Sullivane8278452015-02-06 08:52:08 +0000391 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000392 switch (hw_link_info->phy_type) {
393 case I40E_PHY_TYPE_40GBASE_CR4:
394 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000395 ecmd->supported = SUPPORTED_Autoneg |
396 SUPPORTED_40000baseCR4_Full;
397 ecmd->advertising = ADVERTISED_Autoneg |
398 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000399 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000400 case I40E_PHY_TYPE_XLAUI:
401 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000402 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000403 ecmd->supported = SUPPORTED_40000baseCR4_Full;
404 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000405 case I40E_PHY_TYPE_40GBASE_SR4:
406 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000407 break;
408 case I40E_PHY_TYPE_40GBASE_LR4:
409 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000410 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000411 case I40E_PHY_TYPE_10GBASE_SR:
412 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000413 case I40E_PHY_TYPE_1000BASE_SX:
414 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400415 ecmd->supported = SUPPORTED_10000baseT_Full;
416 if (hw_link_info->module_type[2] &
417 I40E_MODULE_TYPE_1000BASE_SX ||
418 hw_link_info->module_type[2] &
419 I40E_MODULE_TYPE_1000BASE_LX) {
420 ecmd->supported |= SUPPORTED_1000baseT_Full;
421 if (hw_link_info->requested_speeds &
422 I40E_LINK_SPEED_1GB)
423 ecmd->advertising |= ADVERTISED_1000baseT_Full;
424 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000425 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
426 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000427 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000428 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000429 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700430 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000431 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000432 SUPPORTED_10000baseT_Full |
Catherine Sullivan06566e52016-05-03 15:13:14 -0700433 SUPPORTED_1000baseT_Full |
434 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000435 ecmd->advertising = ADVERTISED_Autoneg;
436 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
437 ecmd->advertising |= ADVERTISED_10000baseT_Full;
438 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
439 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700440 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
441 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400442 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400443 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
444 ecmd->supported = SUPPORTED_Autoneg |
445 SUPPORTED_1000baseT_Full;
446 ecmd->advertising = ADVERTISED_Autoneg |
447 ADVERTISED_1000baseT_Full;
448 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000449 case I40E_PHY_TYPE_10GBASE_CR1_CU:
450 case I40E_PHY_TYPE_10GBASE_CR1:
451 ecmd->supported = SUPPORTED_Autoneg |
452 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000453 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000454 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000455 break;
456 case I40E_PHY_TYPE_XAUI:
457 case I40E_PHY_TYPE_XFI:
458 case I40E_PHY_TYPE_SFI:
459 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000460 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000461 ecmd->supported = SUPPORTED_10000baseT_Full;
Stefan Assmann91698272016-06-27 15:03:43 +0200462 ecmd->advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000463 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000464 case I40E_PHY_TYPE_SGMII:
465 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400466 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000467 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
468 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800469 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400470 ecmd->supported |= SUPPORTED_100baseT_Full;
471 if (hw_link_info->requested_speeds &
472 I40E_LINK_SPEED_100MB)
473 ecmd->advertising |= ADVERTISED_100baseT_Full;
474 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000475 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400476 case I40E_PHY_TYPE_40GBASE_KR4:
477 case I40E_PHY_TYPE_20GBASE_KR2:
478 case I40E_PHY_TYPE_10GBASE_KR:
479 case I40E_PHY_TYPE_10GBASE_KX4:
480 case I40E_PHY_TYPE_1000BASE_KX:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700481 ecmd->supported |= SUPPORTED_40000baseKR4_Full |
482 SUPPORTED_20000baseKR2_Full |
483 SUPPORTED_10000baseKR_Full |
484 SUPPORTED_10000baseKX4_Full |
485 SUPPORTED_1000baseKX_Full |
486 SUPPORTED_Autoneg;
487 ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
488 ADVERTISED_20000baseKR2_Full |
489 ADVERTISED_10000baseKR_Full |
490 ADVERTISED_10000baseKX4_Full |
491 ADVERTISED_1000baseKX_Full |
492 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400493 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000494 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000495 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000496 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
497 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 }
499
Catherine Sullivan06566e52016-05-03 15:13:14 -0700500 /* Now that we've worked out everything that could be supported by the
501 * current PHY type, get what is supported by the NVM and them to
502 * get what is truly supported
503 */
504 i40e_phy_type_to_ethtool(pf, &e_supported,
505 &e_advertising);
506
507 ecmd->supported = ecmd->supported & e_supported;
508 ecmd->advertising = ecmd->advertising & e_advertising;
509
Catherine Sullivane8278452015-02-06 08:52:08 +0000510 /* Set speed and duplex */
511 switch (link_speed) {
512 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400513 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000514 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700515 case I40E_LINK_SPEED_20GB:
516 ethtool_cmd_speed_set(ecmd, SPEED_20000);
517 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000518 case I40E_LINK_SPEED_10GB:
519 ethtool_cmd_speed_set(ecmd, SPEED_10000);
520 break;
521 case I40E_LINK_SPEED_1GB:
522 ethtool_cmd_speed_set(ecmd, SPEED_1000);
523 break;
524 case I40E_LINK_SPEED_100MB:
525 ethtool_cmd_speed_set(ecmd, SPEED_100);
526 break;
527 default:
528 break;
529 }
530 ecmd->duplex = DUPLEX_FULL;
531}
532
533/**
534 * i40e_get_settings_link_down - Get the Link settings for when link is down
535 * @hw: hw structure
536 * @ecmd: ethtool command to fill in
537 *
538 * Reports link settings that can be determined when link is down
539 **/
540static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400541 struct ethtool_cmd *ecmd,
542 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000543{
Catherine Sullivane8278452015-02-06 08:52:08 +0000544 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400545 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000546 */
Catherine Sullivan06566e52016-05-03 15:13:14 -0700547 i40e_phy_type_to_ethtool(pf, &ecmd->supported,
548 &ecmd->advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000549
550 /* With no link speed and duplex are unknown */
551 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
552 ecmd->duplex = DUPLEX_UNKNOWN;
553}
554
555/**
556 * i40e_get_settings - Get Link Speed and Duplex settings
557 * @netdev: network interface device structure
558 * @ecmd: ethtool command
559 *
560 * Reports speed/duplex settings based on media_type
561 **/
562static int i40e_get_settings(struct net_device *netdev,
563 struct ethtool_cmd *ecmd)
564{
565 struct i40e_netdev_priv *np = netdev_priv(netdev);
566 struct i40e_pf *pf = np->vsi->back;
567 struct i40e_hw *hw = &pf->hw;
568 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
569 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
570
571 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400572 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000573 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400574 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000575
576 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000577 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000578 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
579 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000580
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000581 switch (hw->phy.media_type) {
582 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000583 ecmd->supported |= SUPPORTED_Autoneg |
584 SUPPORTED_Backplane;
585 ecmd->advertising |= ADVERTISED_Autoneg |
586 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000587 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000588 break;
589 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000590 ecmd->supported |= SUPPORTED_TP;
591 ecmd->advertising |= ADVERTISED_TP;
592 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000593 break;
594 case I40E_MEDIA_TYPE_DA:
595 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000596 ecmd->supported |= SUPPORTED_FIBRE;
597 ecmd->advertising |= ADVERTISED_FIBRE;
598 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000599 break;
600 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000601 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000602 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000603 break;
604 case I40E_MEDIA_TYPE_UNKNOWN:
605 default:
606 ecmd->port = PORT_OTHER;
607 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000608 }
609
Catherine Sullivane8278452015-02-06 08:52:08 +0000610 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000611 ecmd->transceiver = XCVR_EXTERNAL;
612
Catherine Sullivane8278452015-02-06 08:52:08 +0000613 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000614 ecmd->supported |= SUPPORTED_Pause;
615
Catherine Sullivane8278452015-02-06 08:52:08 +0000616 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000617 case I40E_FC_FULL:
618 ecmd->advertising |= ADVERTISED_Pause;
619 break;
620 case I40E_FC_TX_PAUSE:
621 ecmd->advertising |= ADVERTISED_Asym_Pause;
622 break;
623 case I40E_FC_RX_PAUSE:
624 ecmd->advertising |= (ADVERTISED_Pause |
625 ADVERTISED_Asym_Pause);
626 break;
627 default:
628 ecmd->advertising &= ~(ADVERTISED_Pause |
629 ADVERTISED_Asym_Pause);
630 break;
631 }
632
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000633 return 0;
634}
635
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000636/**
637 * i40e_set_settings - Set Speed and Duplex
638 * @netdev: network interface device structure
639 * @ecmd: ethtool command
640 *
641 * Set speed/duplex per media_types advertised/forced
642 **/
643static int i40e_set_settings(struct net_device *netdev,
644 struct ethtool_cmd *ecmd)
645{
646 struct i40e_netdev_priv *np = netdev_priv(netdev);
647 struct i40e_aq_get_phy_abilities_resp abilities;
648 struct i40e_aq_set_phy_config config;
649 struct i40e_pf *pf = np->vsi->back;
650 struct i40e_vsi *vsi = np->vsi;
651 struct i40e_hw *hw = &pf->hw;
652 struct ethtool_cmd safe_ecmd;
653 i40e_status status = 0;
654 bool change = false;
655 int err = 0;
656 u8 autoneg;
657 u32 advertise;
658
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000659 /* Changing port settings is not supported if this isn't the
660 * port's controlling PF
661 */
662 if (hw->partition_id != 1) {
663 i40e_partition_setting_complaint(pf);
664 return -EOPNOTSUPP;
665 }
666
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000667 if (vsi != pf->vsi[pf->lan_vsi])
668 return -EOPNOTSUPP;
669
670 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
671 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000672 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700673 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000674 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000675 return -EOPNOTSUPP;
676
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400677 if (hw->device_id == I40E_DEV_ID_KX_B ||
678 hw->device_id == I40E_DEV_ID_KX_C ||
679 hw->device_id == I40E_DEV_ID_20G_KR2 ||
680 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
681 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
682 return -EOPNOTSUPP;
683 }
684
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000685 /* get our own copy of the bits to check against */
686 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
687 i40e_get_settings(netdev, &safe_ecmd);
688
689 /* save autoneg and speed out of ecmd */
690 autoneg = ecmd->autoneg;
691 advertise = ecmd->advertising;
692
693 /* set autoneg and speed back to what they currently are */
694 ecmd->autoneg = safe_ecmd.autoneg;
695 ecmd->advertising = safe_ecmd.advertising;
696
697 ecmd->cmd = safe_ecmd.cmd;
698 /* If ecmd and safe_ecmd are not the same now, then they are
699 * trying to set something that we do not support
700 */
701 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
702 return -EOPNOTSUPP;
703
704 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
705 usleep_range(1000, 2000);
706
707 /* Get the current phy config */
708 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
709 NULL);
710 if (status)
711 return -EAGAIN;
712
Catherine Sullivan124ed152014-07-12 07:28:12 +0000713 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000714 * set below
715 */
716 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000717 config.abilities = abilities.abilities;
718
719 /* Check autoneg */
720 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000721 /* If autoneg was not already enabled */
722 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400723 /* If autoneg is not supported, return error */
724 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
725 netdev_info(netdev, "Autoneg not supported on this phy\n");
726 return -EINVAL;
727 }
728 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000729 config.abilities = abilities.abilities |
730 I40E_AQ_PHY_ENABLE_AN;
731 change = true;
732 }
733 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000734 /* If autoneg is currently enabled */
735 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400736 /* If autoneg is supported 10GBASE_T is the only PHY
737 * that can disable it, so otherwise return error
738 */
739 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
740 hw->phy.link_info.phy_type !=
741 I40E_PHY_TYPE_10GBASE_T) {
742 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
743 return -EINVAL;
744 }
745 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000746 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000747 ~I40E_AQ_PHY_ENABLE_AN;
748 change = true;
749 }
750 }
751
752 if (advertise & ~safe_ecmd.supported)
753 return -EINVAL;
754
755 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000756 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000757 if (advertise & ADVERTISED_1000baseT_Full ||
758 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000759 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000760 if (advertise & ADVERTISED_10000baseT_Full ||
761 advertise & ADVERTISED_10000baseKX4_Full ||
762 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000763 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700764 if (advertise & ADVERTISED_20000baseKR2_Full)
765 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000766 if (advertise & ADVERTISED_40000baseKR4_Full ||
767 advertise & ADVERTISED_40000baseCR4_Full ||
768 advertise & ADVERTISED_40000baseSR4_Full ||
769 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000770 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000771
Catherine Sullivan0002e112015-08-26 15:14:16 -0400772 /* If speed didn't get set, set it to what it currently is.
773 * This is needed because if advertise is 0 (as it is when autoneg
774 * is disabled) then speed won't get set.
775 */
776 if (!config.link_speed)
777 config.link_speed = abilities.link_speed;
778
Catherine Sullivan124ed152014-07-12 07:28:12 +0000779 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000780 /* copy over the rest of the abilities */
781 config.phy_type = abilities.phy_type;
782 config.eee_capability = abilities.eee_capability;
783 config.eeer = abilities.eeer_val;
784 config.low_power_ctrl = abilities.d3_lpan;
785
Catherine Sullivane8278452015-02-06 08:52:08 +0000786 /* save the requested speeds */
787 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000788 /* set link and auto negotiation so changes take effect */
789 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
790 /* If link is up put link down */
791 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
792 /* Tell the OS link is going down, the link will go
793 * back up when fw says it is ready asynchronously
794 */
Matt Jaredc156f852015-08-27 11:42:39 -0400795 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000796 netif_carrier_off(netdev);
797 netif_tx_stop_all_queues(netdev);
798 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000799
800 /* make the aq call */
801 status = i40e_aq_set_phy_config(hw, &config, NULL);
802 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400803 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
804 i40e_stat_str(hw, status),
805 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000806 return -EAGAIN;
807 }
808
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400809 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000810 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400811 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
812 i40e_stat_str(hw, status),
813 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000814
815 } else {
816 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
817 }
818
819 return err;
820}
821
Jesse Brandeburga6599722014-06-04 08:45:25 +0000822static int i40e_nway_reset(struct net_device *netdev)
823{
824 /* restart autonegotiation */
825 struct i40e_netdev_priv *np = netdev_priv(netdev);
826 struct i40e_pf *pf = np->vsi->back;
827 struct i40e_hw *hw = &pf->hw;
828 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
829 i40e_status ret = 0;
830
831 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
832 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400833 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
834 i40e_stat_str(hw, ret),
835 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000836 return -EIO;
837 }
838
839 return 0;
840}
841
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000842/**
843 * i40e_get_pauseparam - Get Flow Control status
844 * Return tx/rx-pause status
845 **/
846static void i40e_get_pauseparam(struct net_device *netdev,
847 struct ethtool_pauseparam *pause)
848{
849 struct i40e_netdev_priv *np = netdev_priv(netdev);
850 struct i40e_pf *pf = np->vsi->back;
851 struct i40e_hw *hw = &pf->hw;
852 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000853 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000854
855 pause->autoneg =
856 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
857 AUTONEG_ENABLE : AUTONEG_DISABLE);
858
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000859 /* PFC enabled so report LFC as off */
860 if (dcbx_cfg->pfc.pfcenable) {
861 pause->rx_pause = 0;
862 pause->tx_pause = 0;
863 return;
864 }
865
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000866 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000867 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000868 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000869 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000870 } else if (hw->fc.current_mode == I40E_FC_FULL) {
871 pause->rx_pause = 1;
872 pause->tx_pause = 1;
873 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000874}
875
Catherine Sullivan2becc352014-06-04 08:45:27 +0000876/**
877 * i40e_set_pauseparam - Set Flow Control parameter
878 * @netdev: network interface device structure
879 * @pause: return tx/rx flow control status
880 **/
881static int i40e_set_pauseparam(struct net_device *netdev,
882 struct ethtool_pauseparam *pause)
883{
884 struct i40e_netdev_priv *np = netdev_priv(netdev);
885 struct i40e_pf *pf = np->vsi->back;
886 struct i40e_vsi *vsi = np->vsi;
887 struct i40e_hw *hw = &pf->hw;
888 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000889 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000890 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
891 i40e_status status;
892 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000893 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000894
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000895 /* Changing the port's flow control is not supported if this isn't the
896 * port's controlling PF
897 */
898 if (hw->partition_id != 1) {
899 i40e_partition_setting_complaint(pf);
900 return -EOPNOTSUPP;
901 }
902
Catherine Sullivan2becc352014-06-04 08:45:27 +0000903 if (vsi != pf->vsi[pf->lan_vsi])
904 return -EOPNOTSUPP;
905
906 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
907 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
908 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
909 return -EOPNOTSUPP;
910 }
911
912 /* If we have link and don't have autoneg */
913 if (!test_bit(__I40E_DOWN, &pf->state) &&
914 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
915 /* Send message that it might not necessarily work*/
916 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
917 }
918
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000919 if (dcbx_cfg->pfc.pfcenable) {
920 netdev_info(netdev,
921 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000922 return -EOPNOTSUPP;
923 }
924
925 if (pause->rx_pause && pause->tx_pause)
926 hw->fc.requested_mode = I40E_FC_FULL;
927 else if (pause->rx_pause && !pause->tx_pause)
928 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
929 else if (!pause->rx_pause && pause->tx_pause)
930 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
931 else if (!pause->rx_pause && !pause->tx_pause)
932 hw->fc.requested_mode = I40E_FC_NONE;
933 else
934 return -EINVAL;
935
Catherine Sullivan94128512014-07-12 07:28:16 +0000936 /* Tell the OS link is going down, the link will go back up when fw
937 * says it is ready asynchronously
938 */
Matt Jaredc156f852015-08-27 11:42:39 -0400939 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000940 netif_carrier_off(netdev);
941 netif_tx_stop_all_queues(netdev);
942
Catherine Sullivan2becc352014-06-04 08:45:27 +0000943 /* Set the fc mode and only restart an if link is up*/
944 status = i40e_set_fc(hw, &aq_failures, link_up);
945
946 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400947 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
948 i40e_stat_str(hw, status),
949 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000950 err = -EAGAIN;
951 }
952 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400953 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
954 i40e_stat_str(hw, status),
955 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000956 err = -EAGAIN;
957 }
958 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400959 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
960 i40e_stat_str(hw, status),
961 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000962 err = -EAGAIN;
963 }
964
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000965 if (!test_bit(__I40E_DOWN, &pf->state)) {
966 /* Give it a little more time to try to come back */
967 msleep(75);
968 if (!test_bit(__I40E_DOWN, &pf->state))
969 return i40e_nway_reset(netdev);
970 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000971
972 return err;
973}
974
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000975static u32 i40e_get_msglevel(struct net_device *netdev)
976{
977 struct i40e_netdev_priv *np = netdev_priv(netdev);
978 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -0400979 u32 debug_mask = pf->hw.debug_mask;
980
981 if (debug_mask)
982 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000983
984 return pf->msg_enable;
985}
986
987static void i40e_set_msglevel(struct net_device *netdev, u32 data)
988{
989 struct i40e_netdev_priv *np = netdev_priv(netdev);
990 struct i40e_pf *pf = np->vsi->back;
991
992 if (I40E_DEBUG_USER & data)
993 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -0400994 else
995 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000996}
997
998static int i40e_get_regs_len(struct net_device *netdev)
999{
1000 int reg_count = 0;
1001 int i;
1002
1003 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1004 reg_count += i40e_reg_list[i].elements;
1005
1006 return reg_count * sizeof(u32);
1007}
1008
1009static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1010 void *p)
1011{
1012 struct i40e_netdev_priv *np = netdev_priv(netdev);
1013 struct i40e_pf *pf = np->vsi->back;
1014 struct i40e_hw *hw = &pf->hw;
1015 u32 *reg_buf = p;
1016 int i, j, ri;
1017 u32 reg;
1018
1019 /* Tell ethtool which driver-version-specific regs output we have.
1020 *
1021 * At some point, if we have ethtool doing special formatting of
1022 * this data, it will rely on this version number to know how to
1023 * interpret things. Hence, this needs to be updated if/when the
1024 * diags register table is changed.
1025 */
1026 regs->version = 1;
1027
1028 /* loop through the diags reg table for what to print */
1029 ri = 0;
1030 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1031 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1032 reg = i40e_reg_list[i].offset
1033 + (j * i40e_reg_list[i].stride);
1034 reg_buf[ri++] = rd32(hw, reg);
1035 }
1036 }
1037
1038}
1039
1040static int i40e_get_eeprom(struct net_device *netdev,
1041 struct ethtool_eeprom *eeprom, u8 *bytes)
1042{
1043 struct i40e_netdev_priv *np = netdev_priv(netdev);
1044 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001045 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001046 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001047 u8 *eeprom_buff;
1048 u16 i, sectors;
1049 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001050 u32 magic;
1051
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001052#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001053 if (eeprom->len == 0)
1054 return -EINVAL;
1055
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001056 /* check for NVMUpdate access method */
1057 magic = hw->vendor_id | (hw->device_id << 16);
1058 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001059 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1060 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001061
1062 /* make sure it is the right magic for NVMUpdate */
1063 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001064 errno = -EINVAL;
1065 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1066 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1067 errno = -EBUSY;
1068 else
1069 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001070
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001071 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001072 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001073 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1074 ret_val, hw->aq.asq_last_status, errno,
1075 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1076 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001077
1078 return errno;
1079 }
1080
1081 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001082 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1083
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001084 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085 if (!eeprom_buff)
1086 return -ENOMEM;
1087
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001088 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1089 if (ret_val) {
1090 dev_info(&pf->pdev->dev,
1091 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1092 ret_val, hw->aq.asq_last_status);
1093 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001094 }
1095
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001096 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1097 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1098 len = I40E_NVM_SECTOR_SIZE;
1099 last = false;
1100 for (i = 0; i < sectors; i++) {
1101 if (i == (sectors - 1)) {
1102 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1103 last = true;
1104 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001105 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1106 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001107 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001108 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001109 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001110 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001111 "read NVM failed, invalid offset 0x%x\n",
1112 offset);
1113 break;
1114 } else if (ret_val &&
1115 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1116 dev_info(&pf->pdev->dev,
1117 "read NVM failed, access, offset 0x%x\n",
1118 offset);
1119 break;
1120 } else if (ret_val) {
1121 dev_info(&pf->pdev->dev,
1122 "read NVM failed offset %d err=%d status=0x%x\n",
1123 offset, ret_val, hw->aq.asq_last_status);
1124 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001125 }
1126 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001127
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001128 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001129 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001130free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001131 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001132 return ret_val;
1133}
1134
1135static int i40e_get_eeprom_len(struct net_device *netdev)
1136{
1137 struct i40e_netdev_priv *np = netdev_priv(netdev);
1138 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001139 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001140
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001141 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1142 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1143 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1144 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001145 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001146 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001147}
1148
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001149static int i40e_set_eeprom(struct net_device *netdev,
1150 struct ethtool_eeprom *eeprom, u8 *bytes)
1151{
1152 struct i40e_netdev_priv *np = netdev_priv(netdev);
1153 struct i40e_hw *hw = &np->vsi->back->hw;
1154 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001155 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001156 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001157 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001158 u32 magic;
1159
1160 /* normal ethtool set_eeprom is not supported */
1161 magic = hw->vendor_id | (hw->device_id << 16);
1162 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001163 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001164 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001165 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1166 errno = -EINVAL;
1167 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1168 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1169 errno = -EBUSY;
1170 else
1171 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001172
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001173 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001174 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001175 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1176 ret_val, hw->aq.asq_last_status, errno,
1177 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1178 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001179
1180 return errno;
1181}
1182
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001183static void i40e_get_drvinfo(struct net_device *netdev,
1184 struct ethtool_drvinfo *drvinfo)
1185{
1186 struct i40e_netdev_priv *np = netdev_priv(netdev);
1187 struct i40e_vsi *vsi = np->vsi;
1188 struct i40e_pf *pf = vsi->back;
1189
1190 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1191 strlcpy(drvinfo->version, i40e_driver_version_str,
1192 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001193 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001194 sizeof(drvinfo->fw_version));
1195 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1196 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001197 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001198 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001199 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001200}
1201
1202static void i40e_get_ringparam(struct net_device *netdev,
1203 struct ethtool_ringparam *ring)
1204{
1205 struct i40e_netdev_priv *np = netdev_priv(netdev);
1206 struct i40e_pf *pf = np->vsi->back;
1207 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1208
1209 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1210 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1211 ring->rx_mini_max_pending = 0;
1212 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001213 ring->rx_pending = vsi->rx_rings[0]->count;
1214 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001215 ring->rx_mini_pending = 0;
1216 ring->rx_jumbo_pending = 0;
1217}
1218
1219static int i40e_set_ringparam(struct net_device *netdev,
1220 struct ethtool_ringparam *ring)
1221{
1222 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1223 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001224 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001225 struct i40e_vsi *vsi = np->vsi;
1226 struct i40e_pf *pf = vsi->back;
1227 u32 new_rx_count, new_tx_count;
1228 int i, err = 0;
1229
1230 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1231 return -EINVAL;
1232
Shannon Nelson1fa18372013-11-20 10:03:08 +00001233 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1234 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1235 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1236 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1237 netdev_info(netdev,
1238 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1239 ring->tx_pending, ring->rx_pending,
1240 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1241 return -EINVAL;
1242 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001243
Shannon Nelson1fa18372013-11-20 10:03:08 +00001244 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1245 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001246
1247 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001248 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1249 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001250 return 0;
1251
1252 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1253 usleep_range(1000, 2000);
1254
1255 if (!netif_running(vsi->netdev)) {
1256 /* simple case - set for the next time the netdev is started */
1257 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001258 vsi->tx_rings[i]->count = new_tx_count;
1259 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001260 }
1261 goto done;
1262 }
1263
1264 /* We can't just free everything and then setup again,
1265 * because the ISRs in MSI-X mode get passed pointers
1266 * to the Tx and Rx ring structs.
1267 */
1268
1269 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001270 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001271 netdev_info(netdev,
1272 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001273 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001274 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1275 sizeof(struct i40e_ring), GFP_KERNEL);
1276 if (!tx_rings) {
1277 err = -ENOMEM;
1278 goto done;
1279 }
1280
1281 for (i = 0; i < vsi->num_queue_pairs; i++) {
1282 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001283 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001284 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001285 /* the desc and bi pointers will be reallocated in the
1286 * setup call
1287 */
1288 tx_rings[i].desc = NULL;
1289 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001290 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1291 if (err) {
1292 while (i) {
1293 i--;
1294 i40e_free_tx_resources(&tx_rings[i]);
1295 }
1296 kfree(tx_rings);
1297 tx_rings = NULL;
1298
1299 goto done;
1300 }
1301 }
1302 }
1303
1304 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001305 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001306 netdev_info(netdev,
1307 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001308 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001309 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1310 sizeof(struct i40e_ring), GFP_KERNEL);
1311 if (!rx_rings) {
1312 err = -ENOMEM;
1313 goto free_tx;
1314 }
1315
1316 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001317 struct i40e_ring *ring;
1318 u16 unused;
1319
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001320 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001321 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001322 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001323 /* the desc and bi pointers will be reallocated in the
1324 * setup call
1325 */
1326 rx_rings[i].desc = NULL;
1327 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001328 /* this is to allow wr32 to have something to write to
1329 * during early allocation of Rx buffers
1330 */
1331 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001332 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001333 if (err)
1334 goto rx_unwind;
1335
1336 /* now allocate the Rx buffers to make sure the OS
1337 * has enough memory, any failure here means abort
1338 */
1339 ring = &rx_rings[i];
1340 unused = I40E_DESC_UNUSED(ring);
1341 err = i40e_alloc_rx_buffers(ring, unused);
1342rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001343 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001344 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001345 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001346 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001347 kfree(rx_rings);
1348 rx_rings = NULL;
1349
1350 goto free_tx;
1351 }
1352 }
1353 }
1354
1355 /* Bring interface down, copy in the new ring info,
1356 * then restore the interface
1357 */
1358 i40e_down(vsi);
1359
1360 if (tx_rings) {
1361 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001362 i40e_free_tx_resources(vsi->tx_rings[i]);
1363 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364 }
1365 kfree(tx_rings);
1366 tx_rings = NULL;
1367 }
1368
1369 if (rx_rings) {
1370 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001371 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001372 /* get the real tail offset */
1373 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1374 /* this is to fake out the allocation routine
1375 * into thinking it has to realloc everything
1376 * but the recycling logic will let us re-use
1377 * the buffers allocated above
1378 */
1379 rx_rings[i].next_to_use = 0;
1380 rx_rings[i].next_to_clean = 0;
1381 rx_rings[i].next_to_alloc = 0;
1382 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001383 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001384 }
1385 kfree(rx_rings);
1386 rx_rings = NULL;
1387 }
1388
1389 i40e_up(vsi);
1390
1391free_tx:
1392 /* error cleanup if the Rx allocations failed after getting Tx */
1393 if (tx_rings) {
1394 for (i = 0; i < vsi->num_queue_pairs; i++)
1395 i40e_free_tx_resources(&tx_rings[i]);
1396 kfree(tx_rings);
1397 tx_rings = NULL;
1398 }
1399
1400done:
1401 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1402
1403 return err;
1404}
1405
1406static int i40e_get_sset_count(struct net_device *netdev, int sset)
1407{
1408 struct i40e_netdev_priv *np = netdev_priv(netdev);
1409 struct i40e_vsi *vsi = np->vsi;
1410 struct i40e_pf *pf = vsi->back;
1411
1412 switch (sset) {
1413 case ETH_SS_TEST:
1414 return I40E_TEST_LEN;
1415 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001416 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001417 int len = I40E_PF_STATS_LEN(netdev);
1418
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001419 if ((pf->lan_veb != I40E_NO_VEB) &&
1420 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001421 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001422 return len;
1423 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001424 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001425 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001426 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001427 return I40E_PRIV_FLAGS_STR_LEN +
1428 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 default:
1430 return -EOPNOTSUPP;
1431 }
1432}
1433
1434static void i40e_get_ethtool_stats(struct net_device *netdev,
1435 struct ethtool_stats *stats, u64 *data)
1436{
1437 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001438 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001439 struct i40e_vsi *vsi = np->vsi;
1440 struct i40e_pf *pf = vsi->back;
1441 int i = 0;
1442 char *p;
1443 int j;
1444 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001445 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001446
1447 i40e_update_stats(vsi);
1448
1449 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1450 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1451 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1452 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1453 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001454 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1455 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1456 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1457 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1458 }
Vasu Dev38e00432014-08-01 13:27:03 -07001459#ifdef I40E_FCOE
1460 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1461 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1462 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1463 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1464 }
1465#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001466 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001467 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001468 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001469
1470 if (!tx_ring)
1471 continue;
1472
1473 /* process Tx ring statistics */
1474 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001475 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001476 data[i] = tx_ring->stats.packets;
1477 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001478 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001479 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001480
1481 /* Rx ring is the 2nd half of the queue pair */
1482 rx_ring = &tx_ring[1];
1483 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001484 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001485 data[i] = rx_ring->stats.packets;
1486 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001487 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001488 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001490 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001491 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001492 return;
1493
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001494 if ((pf->lan_veb != I40E_NO_VEB) &&
1495 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001496 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001497
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001498 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1499 p = (char *)veb;
1500 p += i40e_gstrings_veb_stats[j].stat_offset;
1501 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1502 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001503 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001504 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1505 data[i++] = veb->tc_stats.tc_tx_packets[j];
1506 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1507 data[i++] = veb->tc_stats.tc_rx_packets[j];
1508 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1509 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001510 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001511 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1512 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1513 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1514 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1515 }
1516 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1517 data[i++] = pf->stats.priority_xon_tx[j];
1518 data[i++] = pf->stats.priority_xoff_tx[j];
1519 }
1520 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1521 data[i++] = pf->stats.priority_xon_rx[j];
1522 data[i++] = pf->stats.priority_xoff_rx[j];
1523 }
1524 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1525 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001526}
1527
1528static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1529 u8 *data)
1530{
1531 struct i40e_netdev_priv *np = netdev_priv(netdev);
1532 struct i40e_vsi *vsi = np->vsi;
1533 struct i40e_pf *pf = vsi->back;
1534 char *p = (char *)data;
1535 int i;
1536
1537 switch (stringset) {
1538 case ETH_SS_TEST:
1539 for (i = 0; i < I40E_TEST_LEN; i++) {
1540 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1541 data += ETH_GSTRING_LEN;
1542 }
1543 break;
1544 case ETH_SS_STATS:
1545 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1546 snprintf(p, ETH_GSTRING_LEN, "%s",
1547 i40e_gstrings_net_stats[i].stat_string);
1548 p += ETH_GSTRING_LEN;
1549 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001550 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1551 snprintf(p, ETH_GSTRING_LEN, "%s",
1552 i40e_gstrings_misc_stats[i].stat_string);
1553 p += ETH_GSTRING_LEN;
1554 }
Vasu Dev38e00432014-08-01 13:27:03 -07001555#ifdef I40E_FCOE
1556 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1557 snprintf(p, ETH_GSTRING_LEN, "%s",
1558 i40e_gstrings_fcoe_stats[i].stat_string);
1559 p += ETH_GSTRING_LEN;
1560 }
1561#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001563 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001564 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001565 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001567 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001569 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001570 p += ETH_GSTRING_LEN;
1571 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001572 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001573 return;
1574
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001575 if ((pf->lan_veb != I40E_NO_VEB) &&
1576 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001577 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1578 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1579 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580 p += ETH_GSTRING_LEN;
1581 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001582 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1583 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001584 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001585 p += ETH_GSTRING_LEN;
1586 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001587 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001588 p += ETH_GSTRING_LEN;
1589 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001590 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001591 p += ETH_GSTRING_LEN;
1592 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001593 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001594 p += ETH_GSTRING_LEN;
1595 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001596 }
1597 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1598 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1599 i40e_gstrings_stats[i].stat_string);
1600 p += ETH_GSTRING_LEN;
1601 }
1602 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1603 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001604 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001605 p += ETH_GSTRING_LEN;
1606 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001607 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001608 p += ETH_GSTRING_LEN;
1609 }
1610 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1611 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001612 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001613 p += ETH_GSTRING_LEN;
1614 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001615 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001616 p += ETH_GSTRING_LEN;
1617 }
1618 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1619 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001620 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001621 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001622 }
1623 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1624 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001625 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001626 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1627 memcpy(data, i40e_priv_flags_strings[i],
1628 ETH_GSTRING_LEN);
1629 data += ETH_GSTRING_LEN;
1630 }
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001631 if (pf->hw.pf_id == 0) {
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001632 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1633 memcpy(data, i40e_gl_priv_flags_strings[i],
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001634 ETH_GSTRING_LEN);
1635 data += ETH_GSTRING_LEN;
1636 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001637 }
1638 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001639 default:
1640 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001641 }
1642}
1643
1644static int i40e_get_ts_info(struct net_device *dev,
1645 struct ethtool_ts_info *info)
1646{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001647 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1648
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001649 /* only report HW timestamping if PTP is enabled */
1650 if (!(pf->flags & I40E_FLAG_PTP))
1651 return ethtool_op_get_ts_info(dev, info);
1652
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001653 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1654 SOF_TIMESTAMPING_RX_SOFTWARE |
1655 SOF_TIMESTAMPING_SOFTWARE |
1656 SOF_TIMESTAMPING_TX_HARDWARE |
1657 SOF_TIMESTAMPING_RX_HARDWARE |
1658 SOF_TIMESTAMPING_RAW_HARDWARE;
1659
1660 if (pf->ptp_clock)
1661 info->phc_index = ptp_clock_index(pf->ptp_clock);
1662 else
1663 info->phc_index = -1;
1664
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001665 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001666
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001667 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1668 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1669 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001670
1671 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001672}
1673
Shannon Nelson7b086392013-11-20 10:02:59 +00001674static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001675{
Shannon Nelson7b086392013-11-20 10:02:59 +00001676 struct i40e_netdev_priv *np = netdev_priv(netdev);
1677 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001678 i40e_status status;
1679 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001680
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001681 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001682 status = i40e_get_link_status(&pf->hw, &link_up);
1683 if (status) {
1684 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1685 *data = 1;
1686 return *data;
1687 }
1688
1689 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001690 *data = 0;
1691 else
1692 *data = 1;
1693
1694 return *data;
1695}
1696
Shannon Nelson7b086392013-11-20 10:02:59 +00001697static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001698{
Shannon Nelson7b086392013-11-20 10:02:59 +00001699 struct i40e_netdev_priv *np = netdev_priv(netdev);
1700 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001701
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001702 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001703 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001704
Shannon Nelson7b086392013-11-20 10:02:59 +00001705 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001706}
1707
Shannon Nelson7b086392013-11-20 10:02:59 +00001708static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001709{
Shannon Nelson7b086392013-11-20 10:02:59 +00001710 struct i40e_netdev_priv *np = netdev_priv(netdev);
1711 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001713 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001714 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715
Shannon Nelson4443ec92014-11-13 08:23:12 +00001716 /* forcebly clear the NVM Update state machine */
1717 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1718
Shannon Nelson7b086392013-11-20 10:02:59 +00001719 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001720}
1721
Shannon Nelson7b086392013-11-20 10:02:59 +00001722static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001723{
Shannon Nelson7b086392013-11-20 10:02:59 +00001724 struct i40e_netdev_priv *np = netdev_priv(netdev);
1725 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001726 u16 swc_old = pf->sw_int_count;
1727
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001728 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001729 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1730 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001731 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1732 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1733 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1734 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001735 usleep_range(1000, 2000);
1736 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001737
1738 return *data;
1739}
1740
Greg Rosee17bc412015-04-16 20:05:59 -04001741static inline bool i40e_active_vfs(struct i40e_pf *pf)
1742{
1743 struct i40e_vf *vfs = pf->vf;
1744 int i;
1745
1746 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001747 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001748 return true;
1749 return false;
1750}
1751
Greg Rose510efb22015-07-10 19:36:01 -04001752static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1753{
Alexander Duyck4b816442016-10-11 15:26:53 -07001754 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001755}
1756
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001757static void i40e_diag_test(struct net_device *netdev,
1758 struct ethtool_test *eth_test, u64 *data)
1759{
1760 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001761 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001762 struct i40e_pf *pf = np->vsi->back;
1763
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001764 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1765 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001766 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001767
Shannon Nelsonf551b432013-11-26 10:49:12 +00001768 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001769
Greg Rose510efb22015-07-10 19:36:01 -04001770 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001771 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001772 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001773 data[I40E_ETH_TEST_REG] = 1;
1774 data[I40E_ETH_TEST_EEPROM] = 1;
1775 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001776 data[I40E_ETH_TEST_LINK] = 1;
1777 eth_test->flags |= ETH_TEST_FL_FAILED;
1778 clear_bit(__I40E_TESTING, &pf->state);
1779 goto skip_ol_tests;
1780 }
1781
Greg Rose5b86c5c2015-02-26 16:14:35 +00001782 /* If the device is online then take it offline */
1783 if (if_running)
1784 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001785 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001786 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001787 /* This reset does not affect link - if it is
1788 * changed to a type of reset that does affect
1789 * link then the following link test would have
1790 * to be moved to before the reset
1791 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001792 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001793
Shannon Nelson7b086392013-11-20 10:02:59 +00001794 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001795 eth_test->flags |= ETH_TEST_FL_FAILED;
1796
Shannon Nelson7b086392013-11-20 10:02:59 +00001797 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001798 eth_test->flags |= ETH_TEST_FL_FAILED;
1799
Shannon Nelson7b086392013-11-20 10:02:59 +00001800 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001801 eth_test->flags |= ETH_TEST_FL_FAILED;
1802
Shannon Nelsonf551b432013-11-26 10:49:12 +00001803 /* run reg test last, a reset is required after it */
1804 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1805 eth_test->flags |= ETH_TEST_FL_FAILED;
1806
1807 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001808 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001809
1810 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001811 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001813 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001814 netif_info(pf, drv, netdev, "online testing starting\n");
1815
Shannon Nelson7b086392013-11-20 10:02:59 +00001816 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001817 eth_test->flags |= ETH_TEST_FL_FAILED;
1818
1819 /* Offline only tests, not run in online; pass by default */
1820 data[I40E_ETH_TEST_REG] = 0;
1821 data[I40E_ETH_TEST_EEPROM] = 0;
1822 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001824
Greg Rosee17bc412015-04-16 20:05:59 -04001825skip_ol_tests:
1826
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001827 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001828}
1829
1830static void i40e_get_wol(struct net_device *netdev,
1831 struct ethtool_wolinfo *wol)
1832{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001833 struct i40e_netdev_priv *np = netdev_priv(netdev);
1834 struct i40e_pf *pf = np->vsi->back;
1835 struct i40e_hw *hw = &pf->hw;
1836 u16 wol_nvm_bits;
1837
1838 /* NVM bit on means WoL disabled for the port */
1839 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001840 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001841 wol->supported = 0;
1842 wol->wolopts = 0;
1843 } else {
1844 wol->supported = WAKE_MAGIC;
1845 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1846 }
1847}
1848
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001849/**
1850 * i40e_set_wol - set the WakeOnLAN configuration
1851 * @netdev: the netdev in question
1852 * @wol: the ethtool WoL setting data
1853 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001854static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1855{
1856 struct i40e_netdev_priv *np = netdev_priv(netdev);
1857 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001858 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001859 struct i40e_hw *hw = &pf->hw;
1860 u16 wol_nvm_bits;
1861
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001862 /* WoL not supported if this isn't the controlling PF on the port */
1863 if (hw->partition_id != 1) {
1864 i40e_partition_setting_complaint(pf);
1865 return -EOPNOTSUPP;
1866 }
1867
1868 if (vsi != pf->vsi[pf->lan_vsi])
1869 return -EOPNOTSUPP;
1870
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001871 /* NVM bit on means WoL disabled for the port */
1872 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001873 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001874 return -EOPNOTSUPP;
1875
1876 /* only magic packet is supported */
1877 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1878 return -EOPNOTSUPP;
1879
1880 /* is this a new value? */
1881 if (pf->wol_en != !!wol->wolopts) {
1882 pf->wol_en = !!wol->wolopts;
1883 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1884 }
1885
1886 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001887}
1888
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001889static int i40e_set_phys_id(struct net_device *netdev,
1890 enum ethtool_phys_id_state state)
1891{
1892 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001893 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001894 struct i40e_pf *pf = np->vsi->back;
1895 struct i40e_hw *hw = &pf->hw;
1896 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001897 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001898
1899 switch (state) {
1900 case ETHTOOL_ID_ACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001901 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1902 pf->led_status = i40e_led_get(hw);
1903 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001904 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001905 ret = i40e_led_get_phy(hw, &temp_status,
1906 &pf->phy_led_val);
1907 pf->led_status = temp_status;
1908 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001909 return blink_freq;
1910 case ETHTOOL_ID_ON:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001911 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1912 i40e_led_set(hw, 0xf, false);
1913 else
1914 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001915 break;
1916 case ETHTOOL_ID_OFF:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001917 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1918 i40e_led_set(hw, 0x0, false);
1919 else
1920 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001921 break;
1922 case ETHTOOL_ID_INACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001923 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1924 i40e_led_set(hw, false, pf->led_status);
1925 } else {
1926 ret = i40e_led_set_phy(hw, false, pf->led_status,
1927 (pf->phy_led_val |
1928 I40E_PHY_LED_MODE_ORIG));
1929 i40e_aq_set_phy_debug(hw, 0, NULL);
1930 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001931 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001932 default:
1933 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001934 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001935 if (ret)
1936 return -ENOENT;
1937 else
1938 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939}
1940
1941/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1942 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1943 * 125us (8000 interrupts per second) == ITR(62)
1944 */
1945
Jacob Keller65e87c02016-09-12 14:18:44 -07001946/**
1947 * __i40e_get_coalesce - get per-queue coalesce settings
1948 * @netdev: the netdev to check
1949 * @ec: ethtool coalesce data structure
1950 * @queue: which queue to pick
1951 *
1952 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
1953 * are per queue. If queue is <0 then we default to queue 0 as the
1954 * representative value.
1955 **/
Kan Lianga75e8002016-02-19 09:24:04 -05001956static int __i40e_get_coalesce(struct net_device *netdev,
1957 struct ethtool_coalesce *ec,
1958 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001959{
1960 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07001961 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001962 struct i40e_vsi *vsi = np->vsi;
1963
1964 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1965 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1966
Kan Lianga75e8002016-02-19 09:24:04 -05001967 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
1968 * return queue 0's value to represent.
1969 */
1970 if (queue < 0) {
1971 queue = 0;
1972 } else if (queue >= vsi->num_queue_pairs) {
1973 return -EINVAL;
1974 }
1975
Jacob Keller65e87c02016-09-12 14:18:44 -07001976 rx_ring = vsi->rx_rings[queue];
1977 tx_ring = vsi->tx_rings[queue];
1978
1979 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001980 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001981
Jacob Keller65e87c02016-09-12 14:18:44 -07001982 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001983 ec->use_adaptive_tx_coalesce = 1;
1984
Jacob Keller65e87c02016-09-12 14:18:44 -07001985 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1986 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1987
Kan Lianga75e8002016-02-19 09:24:04 -05001988
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001989 /* we use the _usecs_high to store/set the interrupt rate limit
1990 * that the hardware supports, that almost but not quite
1991 * fits the original intent of the ethtool variable,
1992 * the rx_coalesce_usecs_high limits total interrupts
1993 * per second from both tx/rx sources.
1994 */
1995 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1996 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001997
1998 return 0;
1999}
2000
Jacob Keller65e87c02016-09-12 14:18:44 -07002001/**
2002 * i40e_get_coalesce - get a netdev's coalesce settings
2003 * @netdev: the netdev to check
2004 * @ec: ethtool coalesce data structure
2005 *
2006 * Gets the coalesce settings for a particular netdev. Note that if user has
2007 * modified per-queue settings, this only guarantees to represent queue 0. See
2008 * __i40e_get_coalesce for more details.
2009 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002010static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002011 struct ethtool_coalesce *ec)
2012{
Kan Lianga75e8002016-02-19 09:24:04 -05002013 return __i40e_get_coalesce(netdev, ec, -1);
2014}
2015
Jacob Keller65e87c02016-09-12 14:18:44 -07002016/**
2017 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2018 * @netdev: netdev structure
2019 * @ec: ethtool's coalesce settings
2020 * @queue: the particular queue to read
2021 *
2022 * Will read a specific queue's coalesce settings
2023 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002024static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2025 struct ethtool_coalesce *ec)
2026{
2027 return __i40e_get_coalesce(netdev, ec, queue);
2028}
2029
Jacob Keller65e87c02016-09-12 14:18:44 -07002030/**
2031 * i40e_set_itr_per_queue - set ITR values for specific queue
2032 * @vsi: the VSI to set values for
2033 * @ec: coalesce settings from ethtool
2034 * @queue: the queue to modify
2035 *
2036 * Change the ITR settings for a specific queue.
2037 **/
2038
Kan Lianga75e8002016-02-19 09:24:04 -05002039static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2040 struct ethtool_coalesce *ec,
2041 int queue)
2042{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002043 struct i40e_pf *pf = vsi->back;
2044 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002045 struct i40e_q_vector *q_vector;
2046 u16 vector, intrl;
2047
2048 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
2049
2050 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2051 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2052
2053 if (ec->use_adaptive_rx_coalesce)
2054 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2055 else
2056 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2057
2058 if (ec->use_adaptive_tx_coalesce)
2059 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2060 else
2061 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2062
2063 q_vector = vsi->rx_rings[queue]->q_vector;
2064 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2065 vector = vsi->base_vector + q_vector->v_idx;
2066 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2067
2068 q_vector = vsi->tx_rings[queue]->q_vector;
2069 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2070 vector = vsi->base_vector + q_vector->v_idx;
2071 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2072
2073 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2074 i40e_flush(hw);
2075}
2076
Jacob Keller65e87c02016-09-12 14:18:44 -07002077/**
2078 * __i40e_set_coalesce - set coalesce settings for particular queue
2079 * @netdev: the netdev to change
2080 * @ec: ethtool coalesce settings
2081 * @queue: the queue to change
2082 *
2083 * Sets the coalesce settings for a particular queue.
2084 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002085static int __i40e_set_coalesce(struct net_device *netdev,
2086 struct ethtool_coalesce *ec,
2087 int queue)
2088{
2089 struct i40e_netdev_priv *np = netdev_priv(netdev);
2090 struct i40e_vsi *vsi = np->vsi;
2091 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002092 int i;
2093
2094 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2095 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2096
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002097 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2098 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2099 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2100 return -EINVAL;
2101 }
2102
2103 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2104 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
2105 return -EINVAL;
2106 }
2107
Kan Lianga75e8002016-02-19 09:24:04 -05002108 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002109 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002110 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 -05002111 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2112 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2113 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2114 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002115 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002116
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002117 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
2118
Kan Lianga75e8002016-02-19 09:24:04 -05002119 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002120 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002121 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 -05002122 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2123 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2124 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2125 return -EINVAL;
2126 }
2127
2128 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2129 * apply to all queues.
2130 */
2131 if (queue < 0) {
2132 for (i = 0; i < vsi->num_queue_pairs; i++)
2133 i40e_set_itr_per_queue(vsi, ec, i);
2134 } else if (queue < vsi->num_queue_pairs) {
2135 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002136 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002137 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2138 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002139 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002140 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002141
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142 return 0;
2143}
2144
Jacob Keller65e87c02016-09-12 14:18:44 -07002145/**
2146 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2147 * @netdev: the netdev to change
2148 * @ec: ethtool coalesce settings
2149 *
2150 * This will set each queue to the same coalesce settings.
2151 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002152static int i40e_set_coalesce(struct net_device *netdev,
2153 struct ethtool_coalesce *ec)
2154{
2155 return __i40e_set_coalesce(netdev, ec, -1);
2156}
2157
Jacob Keller65e87c02016-09-12 14:18:44 -07002158/**
2159 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2160 * @netdev: the netdev to change
2161 * @ec: ethtool's coalesce settings
2162 * @queue: the queue to change
2163 *
2164 * Sets the specified queue's coalesce settings.
2165 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002166static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2167 struct ethtool_coalesce *ec)
2168{
2169 return __i40e_set_coalesce(netdev, ec, queue);
2170}
2171
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172/**
2173 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2174 * @pf: pointer to the physical function struct
2175 * @cmd: ethtool rxnfc command
2176 *
2177 * Returns Success if the flow is supported, else Invalid Input.
2178 **/
2179static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2180{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002181 struct i40e_hw *hw = &pf->hw;
2182 u8 flow_pctype = 0;
2183 u64 i_set = 0;
2184
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002185 cmd->data = 0;
2186
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187 switch (cmd->flow_type) {
2188 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002189 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2190 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002191 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002192 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2193 break;
2194 case TCP_V6_FLOW:
2195 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2196 break;
2197 case UDP_V6_FLOW:
2198 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2199 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200 case SCTP_V4_FLOW:
2201 case AH_ESP_V4_FLOW:
2202 case AH_V4_FLOW:
2203 case ESP_V4_FLOW:
2204 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205 case SCTP_V6_FLOW:
2206 case AH_ESP_V6_FLOW:
2207 case AH_V6_FLOW:
2208 case ESP_V6_FLOW:
2209 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002210 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002211 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2212 break;
2213 default:
2214 return -EINVAL;
2215 }
2216
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002217 /* Read flow based hash input set register */
2218 if (flow_pctype) {
2219 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2220 flow_pctype)) |
2221 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2222 flow_pctype)) << 32);
2223 }
2224
2225 /* Process bits of hash input set */
2226 if (i_set) {
2227 if (i_set & I40E_L4_SRC_MASK)
2228 cmd->data |= RXH_L4_B_0_1;
2229 if (i_set & I40E_L4_DST_MASK)
2230 cmd->data |= RXH_L4_B_2_3;
2231
2232 if (cmd->flow_type == TCP_V4_FLOW ||
2233 cmd->flow_type == UDP_V4_FLOW) {
2234 if (i_set & I40E_L3_SRC_MASK)
2235 cmd->data |= RXH_IP_SRC;
2236 if (i_set & I40E_L3_DST_MASK)
2237 cmd->data |= RXH_IP_DST;
2238 } else if (cmd->flow_type == TCP_V6_FLOW ||
2239 cmd->flow_type == UDP_V6_FLOW) {
2240 if (i_set & I40E_L3_V6_SRC_MASK)
2241 cmd->data |= RXH_IP_SRC;
2242 if (i_set & I40E_L3_V6_DST_MASK)
2243 cmd->data |= RXH_IP_DST;
2244 }
2245 }
2246
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002247 return 0;
2248}
2249
2250/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002251 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2252 * @pf: Pointer to the physical function struct
2253 * @cmd: The command to get or set Rx flow classification rules
2254 * @rule_locs: Array of used rule locations
2255 *
2256 * This function populates both the total and actual rule count of
2257 * the ethtool flow classification command
2258 *
2259 * Returns 0 on success or -EMSGSIZE if entry not found
2260 **/
2261static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2262 struct ethtool_rxnfc *cmd,
2263 u32 *rule_locs)
2264{
2265 struct i40e_fdir_filter *rule;
2266 struct hlist_node *node2;
2267 int cnt = 0;
2268
2269 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002270 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002271
2272 hlist_for_each_entry_safe(rule, node2,
2273 &pf->fdir_filter_list, fdir_node) {
2274 if (cnt == cmd->rule_cnt)
2275 return -EMSGSIZE;
2276
2277 rule_locs[cnt] = rule->fd_id;
2278 cnt++;
2279 }
2280
2281 cmd->rule_cnt = cnt;
2282
2283 return 0;
2284}
2285
2286/**
2287 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2288 * @pf: Pointer to the physical function struct
2289 * @cmd: The command to get or set Rx flow classification rules
2290 *
2291 * This function looks up a filter based on the Rx flow classification
2292 * command and fills the flow spec info for it if found
2293 *
2294 * Returns 0 on success or -EINVAL if filter not found
2295 **/
2296static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2297 struct ethtool_rxnfc *cmd)
2298{
2299 struct ethtool_rx_flow_spec *fsp =
2300 (struct ethtool_rx_flow_spec *)&cmd->fs;
2301 struct i40e_fdir_filter *rule = NULL;
2302 struct hlist_node *node2;
2303
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002304 hlist_for_each_entry_safe(rule, node2,
2305 &pf->fdir_filter_list, fdir_node) {
2306 if (fsp->location <= rule->fd_id)
2307 break;
2308 }
2309
2310 if (!rule || fsp->location != rule->fd_id)
2311 return -EINVAL;
2312
2313 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002314 if (fsp->flow_type == IP_USER_FLOW) {
2315 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2316 fsp->h_u.usr_ip4_spec.proto = 0;
2317 fsp->m_u.usr_ip4_spec.proto = 0;
2318 }
2319
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002320 /* Reverse the src and dest notion, since the HW views them from
2321 * Tx perspective where as the user expects it from Rx filter view.
2322 */
2323 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2324 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2325 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2326 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002327
2328 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2329 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2330 else
2331 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002332
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002333 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2334 struct i40e_vsi *vsi;
2335
2336 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2337 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2338 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2339 fsp->m_ext.data[1] = htonl(0x1);
2340 }
2341 }
2342
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002343 return 0;
2344}
2345
2346/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002347 * i40e_get_rxnfc - command to get RX flow classification rules
2348 * @netdev: network interface device structure
2349 * @cmd: ethtool rxnfc command
2350 *
2351 * Returns Success if the command is supported.
2352 **/
2353static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2354 u32 *rule_locs)
2355{
2356 struct i40e_netdev_priv *np = netdev_priv(netdev);
2357 struct i40e_vsi *vsi = np->vsi;
2358 struct i40e_pf *pf = vsi->back;
2359 int ret = -EOPNOTSUPP;
2360
2361 switch (cmd->cmd) {
2362 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002363 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002364 ret = 0;
2365 break;
2366 case ETHTOOL_GRXFH:
2367 ret = i40e_get_rss_hash_opts(pf, cmd);
2368 break;
2369 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002370 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002371 /* report total rule count */
2372 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002373 ret = 0;
2374 break;
2375 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002376 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002377 break;
2378 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002379 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2380 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002381 default:
2382 break;
2383 }
2384
2385 return ret;
2386}
2387
2388/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002389 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2390 * @nfc: pointer to user request
2391 * @i_setc bits currently set
2392 *
2393 * Returns value of bits to be set per user request
2394 **/
2395static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2396{
2397 u64 i_set = i_setc;
2398 u64 src_l3 = 0, dst_l3 = 0;
2399
2400 if (nfc->data & RXH_L4_B_0_1)
2401 i_set |= I40E_L4_SRC_MASK;
2402 else
2403 i_set &= ~I40E_L4_SRC_MASK;
2404 if (nfc->data & RXH_L4_B_2_3)
2405 i_set |= I40E_L4_DST_MASK;
2406 else
2407 i_set &= ~I40E_L4_DST_MASK;
2408
2409 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2410 src_l3 = I40E_L3_V6_SRC_MASK;
2411 dst_l3 = I40E_L3_V6_DST_MASK;
2412 } else if (nfc->flow_type == TCP_V4_FLOW ||
2413 nfc->flow_type == UDP_V4_FLOW) {
2414 src_l3 = I40E_L3_SRC_MASK;
2415 dst_l3 = I40E_L3_DST_MASK;
2416 } else {
2417 /* Any other flow type are not supported here */
2418 return i_set;
2419 }
2420
2421 if (nfc->data & RXH_IP_SRC)
2422 i_set |= src_l3;
2423 else
2424 i_set &= ~src_l3;
2425 if (nfc->data & RXH_IP_DST)
2426 i_set |= dst_l3;
2427 else
2428 i_set &= ~dst_l3;
2429
2430 return i_set;
2431}
2432
2433/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002434 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2435 * @pf: pointer to the physical function struct
2436 * @cmd: ethtool rxnfc command
2437 *
2438 * Returns Success if the flow input set is supported.
2439 **/
2440static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2441{
2442 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002443 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2444 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002445 u8 flow_pctype = 0;
2446 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002447
2448 /* RSS does not support anything other than hashing
2449 * to queues on src and dst IPs and ports
2450 */
2451 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2452 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2453 return -EINVAL;
2454
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002455 switch (nfc->flow_type) {
2456 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002457 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2458 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2459 hena |=
2460 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002461 break;
2462 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002463 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2464 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2465 hena |=
2466 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2467 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2468 hena |=
2469 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002470 break;
2471 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002472 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2473 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2474 hena |=
2475 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2476 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002477
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002478 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002479 break;
2480 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002481 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2482 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2483 hena |=
2484 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2485 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002486
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002487 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002488 break;
2489 case AH_ESP_V4_FLOW:
2490 case AH_V4_FLOW:
2491 case ESP_V4_FLOW:
2492 case SCTP_V4_FLOW:
2493 if ((nfc->data & RXH_L4_B_0_1) ||
2494 (nfc->data & RXH_L4_B_2_3))
2495 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002496 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002497 break;
2498 case AH_ESP_V6_FLOW:
2499 case AH_V6_FLOW:
2500 case ESP_V6_FLOW:
2501 case SCTP_V6_FLOW:
2502 if ((nfc->data & RXH_L4_B_0_1) ||
2503 (nfc->data & RXH_L4_B_2_3))
2504 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002505 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002506 break;
2507 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002508 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2509 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002510 break;
2511 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002512 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2513 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002514 break;
2515 default:
2516 return -EINVAL;
2517 }
2518
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002519 if (flow_pctype) {
2520 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2521 flow_pctype)) |
2522 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2523 flow_pctype)) << 32);
2524 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2525 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2526 (u32)i_set);
2527 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2528 (u32)(i_set >> 32));
2529 hena |= BIT_ULL(flow_pctype);
2530 }
2531
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002532 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2533 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002534 i40e_flush(hw);
2535
2536 return 0;
2537}
2538
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002539/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002540 * i40e_match_fdir_input_set - Match a new filter against an existing one
2541 * @rule: The filter already added
2542 * @input: The new filter to comapre against
2543 *
2544 * Returns true if the two input set match
2545 **/
2546static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2547 struct i40e_fdir_filter *input)
2548{
2549 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2550 (rule->src_ip[0] != input->src_ip[0]) ||
2551 (rule->dst_port != input->dst_port) ||
2552 (rule->src_port != input->src_port))
2553 return false;
2554 return true;
2555}
2556
2557/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002558 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2559 * @vsi: Pointer to the targeted VSI
2560 * @input: The filter to update or NULL to indicate deletion
2561 * @sw_idx: Software index to the filter
2562 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002563 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002564 * This function updates (or deletes) a Flow Director entry from
2565 * the hlist of the corresponding PF
2566 *
2567 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002568 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002569static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2570 struct i40e_fdir_filter *input,
2571 u16 sw_idx,
2572 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002573{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002574 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002575 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002576 struct hlist_node *node2;
2577 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002578
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002579 parent = NULL;
2580 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002581
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002582 hlist_for_each_entry_safe(rule, node2,
2583 &pf->fdir_filter_list, fdir_node) {
2584 /* hash found, or no matching entry */
2585 if (rule->fd_id >= sw_idx)
2586 break;
2587 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002588 }
2589
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002590 /* if there is an old rule occupying our place remove it */
2591 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002592 if (input && !i40e_match_fdir_input_set(rule, input))
2593 err = i40e_add_del_fdir(vsi, rule, false);
2594 else if (!input)
2595 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002596 hlist_del(&rule->fdir_node);
2597 kfree(rule);
2598 pf->fdir_pf_active_filters--;
2599 }
2600
2601 /* If no input this was a delete, err should be 0 if a rule was
2602 * successfully found and removed from the list else -EINVAL
2603 */
2604 if (!input)
2605 return err;
2606
2607 /* initialize node and set software index */
2608 INIT_HLIST_NODE(&input->fdir_node);
2609
2610 /* add filter to the list */
2611 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002612 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002613 else
2614 hlist_add_head(&input->fdir_node,
2615 &pf->fdir_filter_list);
2616
2617 /* update counts */
2618 pf->fdir_pf_active_filters++;
2619
2620 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002621}
2622
2623/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002624 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2625 * @vsi: Pointer to the targeted VSI
2626 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002627 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002628 * The function removes a Flow Director filter entry from the
2629 * hlist of the corresponding PF
2630 *
2631 * Returns 0 on success
2632 */
2633static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2634 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002635{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002636 struct ethtool_rx_flow_spec *fsp =
2637 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002638 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002639 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002640
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002641 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2642 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2643 return -EBUSY;
2644
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002645 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2646 return -EBUSY;
2647
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002648 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002649
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002650 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002651 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002652}
2653
2654/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002655 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002656 * @vsi: pointer to the targeted VSI
2657 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002658 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002659 * Add Flow Director filters for a specific flow spec based on their
2660 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002661 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002662static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2663 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002664{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002665 struct ethtool_rx_flow_spec *fsp;
2666 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002667 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002668 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002669 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002670
2671 if (!vsi)
2672 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002673 pf = vsi->back;
2674
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002675 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2676 return -EOPNOTSUPP;
2677
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002678 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002679 return -ENOSPC;
2680
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002681 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2682 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2683 return -EBUSY;
2684
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002685 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2686 return -EBUSY;
2687
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002688 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2689
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002690 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2691 pf->hw.func_caps.fd_filters_guaranteed)) {
2692 return -EINVAL;
2693 }
2694
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002695 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2696 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002697 return -EINVAL;
2698
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002699 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002700
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002701 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002702 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002703
2704 input->fd_id = fsp->location;
2705
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002706 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2707 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2708 else
2709 input->dest_ctl =
2710 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2711
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002712 input->q_index = fsp->ring_cookie;
2713 input->flex_off = 0;
2714 input->pctype = 0;
2715 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002716 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002717 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002718 input->flow_type = fsp->flow_type;
2719 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002720
2721 /* Reverse the src and dest notion, since the HW expects them to be from
2722 * Tx perspective where as the input from user is from Rx filter view.
2723 */
2724 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2725 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2726 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2727 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002728
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002729 if (ntohl(fsp->m_ext.data[1])) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002730 vf_id = ntohl(fsp->h_ext.data[1]);
2731 if (vf_id >= pf->num_alloc_vfs) {
2732 netif_info(pf, drv, vsi->netdev,
2733 "Invalid VF id %d\n", vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002734 goto free_input;
2735 }
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002736 /* Find vsi id from vf id and override dest vsi */
2737 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2738 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002739 netif_info(pf, drv, vsi->netdev,
2740 "Invalid queue id %d for VF %d\n",
2741 input->q_index, vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002742 goto free_input;
2743 }
2744 }
2745
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002746 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002747free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002748 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002749 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002750 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002751 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002752
2753 return ret;
2754}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002755
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002756/**
2757 * i40e_set_rxnfc - command to set RX flow classification rules
2758 * @netdev: network interface device structure
2759 * @cmd: ethtool rxnfc command
2760 *
2761 * Returns Success if the command is supported.
2762 **/
2763static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2764{
2765 struct i40e_netdev_priv *np = netdev_priv(netdev);
2766 struct i40e_vsi *vsi = np->vsi;
2767 struct i40e_pf *pf = vsi->back;
2768 int ret = -EOPNOTSUPP;
2769
2770 switch (cmd->cmd) {
2771 case ETHTOOL_SRXFH:
2772 ret = i40e_set_rss_hash_opt(pf, cmd);
2773 break;
2774 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002775 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002776 break;
2777 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002778 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002779 break;
2780 default:
2781 break;
2782 }
2783
2784 return ret;
2785}
2786
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002787/**
2788 * i40e_max_channels - get Max number of combined channels supported
2789 * @vsi: vsi pointer
2790 **/
2791static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2792{
2793 /* TODO: This code assumes DCB and FD is disabled for now. */
2794 return vsi->alloc_queue_pairs;
2795}
2796
2797/**
2798 * i40e_get_channels - Get the current channels enabled and max supported etc.
2799 * @netdev: network interface device structure
2800 * @ch: ethtool channels structure
2801 *
2802 * We don't support separate tx and rx queues as channels. The other count
2803 * represents how many queues are being used for control. max_combined counts
2804 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2805 * q_vectors since we support a lot more queue pairs than q_vectors.
2806 **/
2807static void i40e_get_channels(struct net_device *dev,
2808 struct ethtool_channels *ch)
2809{
2810 struct i40e_netdev_priv *np = netdev_priv(dev);
2811 struct i40e_vsi *vsi = np->vsi;
2812 struct i40e_pf *pf = vsi->back;
2813
2814 /* report maximum channels */
2815 ch->max_combined = i40e_max_channels(vsi);
2816
2817 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002818 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002819 ch->max_other = ch->other_count;
2820
2821 /* Note: This code assumes DCB is disabled for now. */
2822 ch->combined_count = vsi->num_queue_pairs;
2823}
2824
2825/**
2826 * i40e_set_channels - Set the new channels count.
2827 * @netdev: network interface device structure
2828 * @ch: ethtool channels structure
2829 *
2830 * The new channels count may not be the same as requested by the user
2831 * since it gets rounded down to a power of 2 value.
2832 **/
2833static int i40e_set_channels(struct net_device *dev,
2834 struct ethtool_channels *ch)
2835{
Jacob Keller59826d92016-07-27 12:02:35 -07002836 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002837 struct i40e_netdev_priv *np = netdev_priv(dev);
2838 unsigned int count = ch->combined_count;
2839 struct i40e_vsi *vsi = np->vsi;
2840 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07002841 struct i40e_fdir_filter *rule;
2842 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002843 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07002844 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002845
2846 /* We do not support setting channels for any other VSI at present */
2847 if (vsi->type != I40E_VSI_MAIN)
2848 return -EINVAL;
2849
2850 /* verify they are not requesting separate vectors */
2851 if (!count || ch->rx_count || ch->tx_count)
2852 return -EINVAL;
2853
2854 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002855 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002856 return -EINVAL;
2857
2858 /* verify the number of channels does not exceed hardware limits */
2859 if (count > i40e_max_channels(vsi))
2860 return -EINVAL;
2861
Jacob Keller59826d92016-07-27 12:02:35 -07002862 /* verify that the number of channels does not invalidate any current
2863 * flow director rules
2864 */
2865 hlist_for_each_entry_safe(rule, node2,
2866 &pf->fdir_filter_list, fdir_node) {
2867 if (rule->dest_ctl != drop && count <= rule->q_index) {
2868 dev_warn(&pf->pdev->dev,
2869 "Existing user defined filter %d assigns flow to queue %d\n",
2870 rule->fd_id, rule->q_index);
2871 err = -EINVAL;
2872 }
2873 }
2874
2875 if (err) {
2876 dev_err(&pf->pdev->dev,
2877 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
2878 count);
2879 return err;
2880 }
2881
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002882 /* update feature limits from largest to smallest supported values */
2883 /* TODO: Flow director limit, DCB etc */
2884
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002885 /* use rss_reconfig to rebuild with new queue count and update traffic
2886 * class queue mapping
2887 */
2888 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002889 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002890 return 0;
2891 else
2892 return -EINVAL;
2893}
2894
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002895/**
2896 * i40e_get_rxfh_key_size - get the RSS hash key size
2897 * @netdev: network interface device structure
2898 *
2899 * Returns the table size.
2900 **/
2901static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2902{
2903 return I40E_HKEY_ARRAY_SIZE;
2904}
2905
2906/**
2907 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2908 * @netdev: network interface device structure
2909 *
2910 * Returns the table size.
2911 **/
2912static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2913{
2914 return I40E_HLUT_ARRAY_SIZE;
2915}
2916
2917static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2918 u8 *hfunc)
2919{
2920 struct i40e_netdev_priv *np = netdev_priv(netdev);
2921 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002922 u8 *lut, *seed = NULL;
2923 int ret;
2924 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002925
2926 if (hfunc)
2927 *hfunc = ETH_RSS_HASH_TOP;
2928
2929 if (!indir)
2930 return 0;
2931
Helin Zhang043dd652015-10-21 19:56:23 -04002932 seed = key;
2933 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2934 if (!lut)
2935 return -ENOMEM;
2936 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2937 if (ret)
2938 goto out;
2939 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2940 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002941
Helin Zhang043dd652015-10-21 19:56:23 -04002942out:
2943 kfree(lut);
2944
2945 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002946}
2947
2948/**
2949 * i40e_set_rxfh - set the rx flow hash indirection table
2950 * @netdev: network interface device structure
2951 * @indir: indirection table
2952 * @key: hash key
2953 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002954 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002955 * returns 0 after programming the table.
2956 **/
2957static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2958 const u8 *key, const u8 hfunc)
2959{
2960 struct i40e_netdev_priv *np = netdev_priv(netdev);
2961 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07002962 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04002963 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002964 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002965
2966 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2967 return -EOPNOTSUPP;
2968
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002969 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002970 if (!vsi->rss_hkey_user) {
2971 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2972 GFP_KERNEL);
2973 if (!vsi->rss_hkey_user)
2974 return -ENOMEM;
2975 }
2976 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2977 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002978 }
Helin Zhang28c58692015-10-26 19:44:27 -04002979 if (!vsi->rss_lut_user) {
2980 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2981 if (!vsi->rss_lut_user)
2982 return -ENOMEM;
2983 }
Helin Zhang043dd652015-10-21 19:56:23 -04002984
Helin Zhang28c58692015-10-26 19:44:27 -04002985 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07002986 if (indir)
2987 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2988 vsi->rss_lut_user[i] = (u8)(indir[i]);
2989 else
2990 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
2991 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04002992
2993 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2994 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002995}
2996
Greg Rose7e45ab42015-02-06 08:52:19 +00002997/**
2998 * i40e_get_priv_flags - report device private flags
2999 * @dev: network interface device structure
3000 *
3001 * The get string set count and the string set should be matched for each
3002 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
3003 * array.
3004 *
3005 * Returns a u32 bitmap of flags.
3006 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00003007static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00003008{
3009 struct i40e_netdev_priv *np = netdev_priv(dev);
3010 struct i40e_vsi *vsi = np->vsi;
3011 struct i40e_pf *pf = vsi->back;
3012 u32 ret_flags = 0;
3013
Shannon Nelson9ac77262015-08-27 11:42:40 -04003014 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
3015 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04003016 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
3017 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003018 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
3019 I40E_PRIV_FLAGS_VEB_STATS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003020 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
3021 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003022 if (pf->hw.pf_id == 0) {
3023 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
3024 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
3025 }
Greg Rose7e45ab42015-02-06 08:52:19 +00003026
3027 return ret_flags;
3028}
3029
Shannon Nelson9ac77262015-08-27 11:42:40 -04003030/**
3031 * i40e_set_priv_flags - set private flags
3032 * @dev: network interface device structure
3033 * @flags: bit flags to be set
3034 **/
3035static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
3036{
3037 struct i40e_netdev_priv *np = netdev_priv(dev);
3038 struct i40e_vsi *vsi = np->vsi;
3039 struct i40e_pf *pf = vsi->back;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003040 u16 sw_flags = 0, valid_flags = 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003041 bool reset_required = false;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003042 bool promisc_change = false;
3043 int ret;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003044
3045 /* NOTE: MFP is not settable */
3046
Shannon Nelson9ac77262015-08-27 11:42:40 -04003047 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
3048 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
3049 else
3050 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
3051
Jesse Brandeburgef171782015-09-03 17:18:49 -04003052 /* allow the user to control the state of the Flow
3053 * Director ATR (Application Targeted Routing) feature
3054 * of the driver
3055 */
3056 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
3057 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
3058 } else {
3059 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
3060 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
Jacob Keller234dc4e2016-09-06 18:05:09 -07003061
3062 /* flush current ATR settings */
3063 set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04003064 }
3065
Shannon Nelson66fc3602016-01-13 16:51:42 -08003066 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3067 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003068 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003069 reset_required = true;
3070 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3071 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003072 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003073 reset_required = true;
3074 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003075
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003076 if (pf->hw.pf_id == 0) {
3077 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3078 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3079 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
3080 promisc_change = true;
3081 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3082 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3083 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
3084 promisc_change = true;
3085 }
3086 }
3087 if (promisc_change) {
3088 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
3089 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3090 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3091 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
3092 NULL);
3093 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
3094 dev_info(&pf->pdev->dev,
3095 "couldn't set switch config bits, err %s aq_err %s\n",
3096 i40e_stat_str(&pf->hw, ret),
3097 i40e_aq_str(&pf->hw,
3098 pf->hw.aq.asq_last_status));
3099 /* not a fatal problem, just keep going */
3100 }
3101 }
3102
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003103 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
3104 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
3105 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
3106 else
3107 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
3108
Jesse Brandeburg827de392015-11-06 15:26:07 -08003109 /* if needed, issue reset to cause things to take effect */
3110 if (reset_required)
3111 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
3112
Shannon Nelson9ac77262015-08-27 11:42:40 -04003113 return 0;
3114}
3115
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003116static const struct ethtool_ops i40e_ethtool_ops = {
3117 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00003118 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003119 .get_drvinfo = i40e_get_drvinfo,
3120 .get_regs_len = i40e_get_regs_len,
3121 .get_regs = i40e_get_regs,
3122 .nway_reset = i40e_nway_reset,
3123 .get_link = ethtool_op_get_link,
3124 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00003125 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003126 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003127 .get_eeprom_len = i40e_get_eeprom_len,
3128 .get_eeprom = i40e_get_eeprom,
3129 .get_ringparam = i40e_get_ringparam,
3130 .set_ringparam = i40e_set_ringparam,
3131 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00003132 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003133 .get_msglevel = i40e_get_msglevel,
3134 .set_msglevel = i40e_set_msglevel,
3135 .get_rxnfc = i40e_get_rxnfc,
3136 .set_rxnfc = i40e_set_rxnfc,
3137 .self_test = i40e_diag_test,
3138 .get_strings = i40e_get_strings,
3139 .set_phys_id = i40e_set_phys_id,
3140 .get_sset_count = i40e_get_sset_count,
3141 .get_ethtool_stats = i40e_get_ethtool_stats,
3142 .get_coalesce = i40e_get_coalesce,
3143 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003144 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3145 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3146 .get_rxfh = i40e_get_rxfh,
3147 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003148 .get_channels = i40e_get_channels,
3149 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003150 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00003151 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04003152 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05003153 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05003154 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003155};
3156
3157void i40e_set_ethtool_ops(struct net_device *netdev)
3158{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003159 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003160}