blob: f99c135718dd53d08ec908d3f9ac9b952cae1348 [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) {
348 *supported |= SUPPORTED_10000baseKR_Full |
349 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700350 *advertising |= ADVERTISED_Autoneg;
351 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
352 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700353 }
354 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
355 *supported |= SUPPORTED_10000baseKX4_Full |
356 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700357 *advertising |= ADVERTISED_Autoneg;
358 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
359 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700360 }
361 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
362 *supported |= SUPPORTED_1000baseKX_Full |
363 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700364 *advertising |= ADVERTISED_Autoneg;
365 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
366 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700367 }
368}
369
370/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000371 * i40e_get_settings_link_up - Get the Link settings for when link is up
372 * @hw: hw structure
373 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000374 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000375 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000376 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000377static void i40e_get_settings_link_up(struct i40e_hw *hw,
378 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400379 struct net_device *netdev,
380 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000381{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000382 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000383 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700384 u32 e_advertising = 0x0;
385 u32 e_supported = 0x0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386
Catherine Sullivane8278452015-02-06 08:52:08 +0000387 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000388 switch (hw_link_info->phy_type) {
389 case I40E_PHY_TYPE_40GBASE_CR4:
390 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000391 ecmd->supported = SUPPORTED_Autoneg |
392 SUPPORTED_40000baseCR4_Full;
393 ecmd->advertising = ADVERTISED_Autoneg |
394 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000395 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000396 case I40E_PHY_TYPE_XLAUI:
397 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000398 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000399 ecmd->supported = SUPPORTED_40000baseCR4_Full;
400 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000401 case I40E_PHY_TYPE_40GBASE_SR4:
402 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000403 break;
404 case I40E_PHY_TYPE_40GBASE_LR4:
405 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000406 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000407 case I40E_PHY_TYPE_10GBASE_SR:
408 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000409 case I40E_PHY_TYPE_1000BASE_SX:
410 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400411 ecmd->supported = SUPPORTED_10000baseT_Full;
412 if (hw_link_info->module_type[2] &
413 I40E_MODULE_TYPE_1000BASE_SX ||
414 hw_link_info->module_type[2] &
415 I40E_MODULE_TYPE_1000BASE_LX) {
416 ecmd->supported |= SUPPORTED_1000baseT_Full;
417 if (hw_link_info->requested_speeds &
418 I40E_LINK_SPEED_1GB)
419 ecmd->advertising |= ADVERTISED_1000baseT_Full;
420 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000421 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
422 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000423 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000424 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000425 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700426 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000427 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000428 SUPPORTED_10000baseT_Full |
Catherine Sullivan06566e52016-05-03 15:13:14 -0700429 SUPPORTED_1000baseT_Full |
430 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000431 ecmd->advertising = ADVERTISED_Autoneg;
432 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
433 ecmd->advertising |= ADVERTISED_10000baseT_Full;
434 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
435 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700436 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
437 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400438 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400439 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
440 ecmd->supported = SUPPORTED_Autoneg |
441 SUPPORTED_1000baseT_Full;
442 ecmd->advertising = ADVERTISED_Autoneg |
443 ADVERTISED_1000baseT_Full;
444 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000445 case I40E_PHY_TYPE_10GBASE_CR1_CU:
446 case I40E_PHY_TYPE_10GBASE_CR1:
447 ecmd->supported = SUPPORTED_Autoneg |
448 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000449 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000450 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000451 break;
452 case I40E_PHY_TYPE_XAUI:
453 case I40E_PHY_TYPE_XFI:
454 case I40E_PHY_TYPE_SFI:
455 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000456 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000457 ecmd->supported = SUPPORTED_10000baseT_Full;
Stefan Assmann91698272016-06-27 15:03:43 +0200458 ecmd->advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000459 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000460 case I40E_PHY_TYPE_SGMII:
461 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400462 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000463 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
464 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800465 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400466 ecmd->supported |= SUPPORTED_100baseT_Full;
467 if (hw_link_info->requested_speeds &
468 I40E_LINK_SPEED_100MB)
469 ecmd->advertising |= ADVERTISED_100baseT_Full;
470 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000471 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400472 case I40E_PHY_TYPE_40GBASE_KR4:
473 case I40E_PHY_TYPE_20GBASE_KR2:
474 case I40E_PHY_TYPE_10GBASE_KR:
475 case I40E_PHY_TYPE_10GBASE_KX4:
476 case I40E_PHY_TYPE_1000BASE_KX:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700477 ecmd->supported |= SUPPORTED_40000baseKR4_Full |
478 SUPPORTED_20000baseKR2_Full |
479 SUPPORTED_10000baseKR_Full |
480 SUPPORTED_10000baseKX4_Full |
481 SUPPORTED_1000baseKX_Full |
482 SUPPORTED_Autoneg;
483 ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
484 ADVERTISED_20000baseKR2_Full |
485 ADVERTISED_10000baseKR_Full |
486 ADVERTISED_10000baseKX4_Full |
487 ADVERTISED_1000baseKX_Full |
488 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400489 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000491 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000492 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
493 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000494 }
495
Catherine Sullivan06566e52016-05-03 15:13:14 -0700496 /* Now that we've worked out everything that could be supported by the
497 * current PHY type, get what is supported by the NVM and them to
498 * get what is truly supported
499 */
500 i40e_phy_type_to_ethtool(pf, &e_supported,
501 &e_advertising);
502
503 ecmd->supported = ecmd->supported & e_supported;
504 ecmd->advertising = ecmd->advertising & e_advertising;
505
Catherine Sullivane8278452015-02-06 08:52:08 +0000506 /* Set speed and duplex */
507 switch (link_speed) {
508 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400509 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000510 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700511 case I40E_LINK_SPEED_20GB:
512 ethtool_cmd_speed_set(ecmd, SPEED_20000);
513 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000514 case I40E_LINK_SPEED_10GB:
515 ethtool_cmd_speed_set(ecmd, SPEED_10000);
516 break;
517 case I40E_LINK_SPEED_1GB:
518 ethtool_cmd_speed_set(ecmd, SPEED_1000);
519 break;
520 case I40E_LINK_SPEED_100MB:
521 ethtool_cmd_speed_set(ecmd, SPEED_100);
522 break;
523 default:
524 break;
525 }
526 ecmd->duplex = DUPLEX_FULL;
527}
528
529/**
530 * i40e_get_settings_link_down - Get the Link settings for when link is down
531 * @hw: hw structure
532 * @ecmd: ethtool command to fill in
533 *
534 * Reports link settings that can be determined when link is down
535 **/
536static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400537 struct ethtool_cmd *ecmd,
538 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000539{
Catherine Sullivane8278452015-02-06 08:52:08 +0000540 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400541 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000542 */
Catherine Sullivan06566e52016-05-03 15:13:14 -0700543 i40e_phy_type_to_ethtool(pf, &ecmd->supported,
544 &ecmd->advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000545
546 /* With no link speed and duplex are unknown */
547 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
548 ecmd->duplex = DUPLEX_UNKNOWN;
549}
550
551/**
552 * i40e_get_settings - Get Link Speed and Duplex settings
553 * @netdev: network interface device structure
554 * @ecmd: ethtool command
555 *
556 * Reports speed/duplex settings based on media_type
557 **/
558static int i40e_get_settings(struct net_device *netdev,
559 struct ethtool_cmd *ecmd)
560{
561 struct i40e_netdev_priv *np = netdev_priv(netdev);
562 struct i40e_pf *pf = np->vsi->back;
563 struct i40e_hw *hw = &pf->hw;
564 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
565 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
566
567 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400568 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000569 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400570 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000571
572 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000573 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000574 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
575 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000576
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000577 switch (hw->phy.media_type) {
578 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000579 ecmd->supported |= SUPPORTED_Autoneg |
580 SUPPORTED_Backplane;
581 ecmd->advertising |= ADVERTISED_Autoneg |
582 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000583 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000584 break;
585 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000586 ecmd->supported |= SUPPORTED_TP;
587 ecmd->advertising |= ADVERTISED_TP;
588 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000589 break;
590 case I40E_MEDIA_TYPE_DA:
591 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000592 ecmd->supported |= SUPPORTED_FIBRE;
593 ecmd->advertising |= ADVERTISED_FIBRE;
594 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000595 break;
596 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000597 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000598 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000599 break;
600 case I40E_MEDIA_TYPE_UNKNOWN:
601 default:
602 ecmd->port = PORT_OTHER;
603 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000604 }
605
Catherine Sullivane8278452015-02-06 08:52:08 +0000606 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000607 ecmd->transceiver = XCVR_EXTERNAL;
608
Catherine Sullivane8278452015-02-06 08:52:08 +0000609 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000610 ecmd->supported |= SUPPORTED_Pause;
611
Catherine Sullivane8278452015-02-06 08:52:08 +0000612 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000613 case I40E_FC_FULL:
614 ecmd->advertising |= ADVERTISED_Pause;
615 break;
616 case I40E_FC_TX_PAUSE:
617 ecmd->advertising |= ADVERTISED_Asym_Pause;
618 break;
619 case I40E_FC_RX_PAUSE:
620 ecmd->advertising |= (ADVERTISED_Pause |
621 ADVERTISED_Asym_Pause);
622 break;
623 default:
624 ecmd->advertising &= ~(ADVERTISED_Pause |
625 ADVERTISED_Asym_Pause);
626 break;
627 }
628
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000629 return 0;
630}
631
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000632/**
633 * i40e_set_settings - Set Speed and Duplex
634 * @netdev: network interface device structure
635 * @ecmd: ethtool command
636 *
637 * Set speed/duplex per media_types advertised/forced
638 **/
639static int i40e_set_settings(struct net_device *netdev,
640 struct ethtool_cmd *ecmd)
641{
642 struct i40e_netdev_priv *np = netdev_priv(netdev);
643 struct i40e_aq_get_phy_abilities_resp abilities;
644 struct i40e_aq_set_phy_config config;
645 struct i40e_pf *pf = np->vsi->back;
646 struct i40e_vsi *vsi = np->vsi;
647 struct i40e_hw *hw = &pf->hw;
648 struct ethtool_cmd safe_ecmd;
649 i40e_status status = 0;
650 bool change = false;
651 int err = 0;
652 u8 autoneg;
653 u32 advertise;
654
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000655 /* Changing port settings is not supported if this isn't the
656 * port's controlling PF
657 */
658 if (hw->partition_id != 1) {
659 i40e_partition_setting_complaint(pf);
660 return -EOPNOTSUPP;
661 }
662
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000663 if (vsi != pf->vsi[pf->lan_vsi])
664 return -EOPNOTSUPP;
665
666 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
667 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000668 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700669 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000670 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000671 return -EOPNOTSUPP;
672
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400673 if (hw->device_id == I40E_DEV_ID_KX_B ||
674 hw->device_id == I40E_DEV_ID_KX_C ||
675 hw->device_id == I40E_DEV_ID_20G_KR2 ||
676 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
677 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
678 return -EOPNOTSUPP;
679 }
680
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000681 /* get our own copy of the bits to check against */
682 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
683 i40e_get_settings(netdev, &safe_ecmd);
684
685 /* save autoneg and speed out of ecmd */
686 autoneg = ecmd->autoneg;
687 advertise = ecmd->advertising;
688
689 /* set autoneg and speed back to what they currently are */
690 ecmd->autoneg = safe_ecmd.autoneg;
691 ecmd->advertising = safe_ecmd.advertising;
692
693 ecmd->cmd = safe_ecmd.cmd;
694 /* If ecmd and safe_ecmd are not the same now, then they are
695 * trying to set something that we do not support
696 */
697 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
698 return -EOPNOTSUPP;
699
700 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
701 usleep_range(1000, 2000);
702
703 /* Get the current phy config */
704 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
705 NULL);
706 if (status)
707 return -EAGAIN;
708
Catherine Sullivan124ed152014-07-12 07:28:12 +0000709 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000710 * set below
711 */
712 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000713 config.abilities = abilities.abilities;
714
715 /* Check autoneg */
716 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000717 /* If autoneg was not already enabled */
718 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400719 /* If autoneg is not supported, return error */
720 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
721 netdev_info(netdev, "Autoneg not supported on this phy\n");
722 return -EINVAL;
723 }
724 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000725 config.abilities = abilities.abilities |
726 I40E_AQ_PHY_ENABLE_AN;
727 change = true;
728 }
729 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000730 /* If autoneg is currently enabled */
731 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400732 /* If autoneg is supported 10GBASE_T is the only PHY
733 * that can disable it, so otherwise return error
734 */
735 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
736 hw->phy.link_info.phy_type !=
737 I40E_PHY_TYPE_10GBASE_T) {
738 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
739 return -EINVAL;
740 }
741 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000742 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000743 ~I40E_AQ_PHY_ENABLE_AN;
744 change = true;
745 }
746 }
747
748 if (advertise & ~safe_ecmd.supported)
749 return -EINVAL;
750
751 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000752 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000753 if (advertise & ADVERTISED_1000baseT_Full ||
754 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000755 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000756 if (advertise & ADVERTISED_10000baseT_Full ||
757 advertise & ADVERTISED_10000baseKX4_Full ||
758 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000759 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700760 if (advertise & ADVERTISED_20000baseKR2_Full)
761 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000762 if (advertise & ADVERTISED_40000baseKR4_Full ||
763 advertise & ADVERTISED_40000baseCR4_Full ||
764 advertise & ADVERTISED_40000baseSR4_Full ||
765 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000766 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000767
Catherine Sullivan0002e112015-08-26 15:14:16 -0400768 /* If speed didn't get set, set it to what it currently is.
769 * This is needed because if advertise is 0 (as it is when autoneg
770 * is disabled) then speed won't get set.
771 */
772 if (!config.link_speed)
773 config.link_speed = abilities.link_speed;
774
Catherine Sullivan124ed152014-07-12 07:28:12 +0000775 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000776 /* copy over the rest of the abilities */
777 config.phy_type = abilities.phy_type;
778 config.eee_capability = abilities.eee_capability;
779 config.eeer = abilities.eeer_val;
780 config.low_power_ctrl = abilities.d3_lpan;
781
Catherine Sullivane8278452015-02-06 08:52:08 +0000782 /* save the requested speeds */
783 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000784 /* set link and auto negotiation so changes take effect */
785 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
786 /* If link is up put link down */
787 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
788 /* Tell the OS link is going down, the link will go
789 * back up when fw says it is ready asynchronously
790 */
Matt Jaredc156f852015-08-27 11:42:39 -0400791 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000792 netif_carrier_off(netdev);
793 netif_tx_stop_all_queues(netdev);
794 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000795
796 /* make the aq call */
797 status = i40e_aq_set_phy_config(hw, &config, NULL);
798 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400799 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
800 i40e_stat_str(hw, status),
801 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000802 return -EAGAIN;
803 }
804
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400805 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000806 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400807 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
808 i40e_stat_str(hw, status),
809 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000810
811 } else {
812 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
813 }
814
815 return err;
816}
817
Jesse Brandeburga6599722014-06-04 08:45:25 +0000818static int i40e_nway_reset(struct net_device *netdev)
819{
820 /* restart autonegotiation */
821 struct i40e_netdev_priv *np = netdev_priv(netdev);
822 struct i40e_pf *pf = np->vsi->back;
823 struct i40e_hw *hw = &pf->hw;
824 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
825 i40e_status ret = 0;
826
827 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
828 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400829 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
830 i40e_stat_str(hw, ret),
831 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000832 return -EIO;
833 }
834
835 return 0;
836}
837
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000838/**
839 * i40e_get_pauseparam - Get Flow Control status
840 * Return tx/rx-pause status
841 **/
842static void i40e_get_pauseparam(struct net_device *netdev,
843 struct ethtool_pauseparam *pause)
844{
845 struct i40e_netdev_priv *np = netdev_priv(netdev);
846 struct i40e_pf *pf = np->vsi->back;
847 struct i40e_hw *hw = &pf->hw;
848 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000849 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000850
851 pause->autoneg =
852 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
853 AUTONEG_ENABLE : AUTONEG_DISABLE);
854
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000855 /* PFC enabled so report LFC as off */
856 if (dcbx_cfg->pfc.pfcenable) {
857 pause->rx_pause = 0;
858 pause->tx_pause = 0;
859 return;
860 }
861
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000862 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000863 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000864 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000865 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000866 } else if (hw->fc.current_mode == I40E_FC_FULL) {
867 pause->rx_pause = 1;
868 pause->tx_pause = 1;
869 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000870}
871
Catherine Sullivan2becc352014-06-04 08:45:27 +0000872/**
873 * i40e_set_pauseparam - Set Flow Control parameter
874 * @netdev: network interface device structure
875 * @pause: return tx/rx flow control status
876 **/
877static int i40e_set_pauseparam(struct net_device *netdev,
878 struct ethtool_pauseparam *pause)
879{
880 struct i40e_netdev_priv *np = netdev_priv(netdev);
881 struct i40e_pf *pf = np->vsi->back;
882 struct i40e_vsi *vsi = np->vsi;
883 struct i40e_hw *hw = &pf->hw;
884 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000885 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000886 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
887 i40e_status status;
888 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000889 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000890
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000891 /* Changing the port's flow control is not supported if this isn't the
892 * port's controlling PF
893 */
894 if (hw->partition_id != 1) {
895 i40e_partition_setting_complaint(pf);
896 return -EOPNOTSUPP;
897 }
898
Catherine Sullivan2becc352014-06-04 08:45:27 +0000899 if (vsi != pf->vsi[pf->lan_vsi])
900 return -EOPNOTSUPP;
901
902 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
903 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
904 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
905 return -EOPNOTSUPP;
906 }
907
908 /* If we have link and don't have autoneg */
909 if (!test_bit(__I40E_DOWN, &pf->state) &&
910 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
911 /* Send message that it might not necessarily work*/
912 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
913 }
914
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000915 if (dcbx_cfg->pfc.pfcenable) {
916 netdev_info(netdev,
917 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000918 return -EOPNOTSUPP;
919 }
920
921 if (pause->rx_pause && pause->tx_pause)
922 hw->fc.requested_mode = I40E_FC_FULL;
923 else if (pause->rx_pause && !pause->tx_pause)
924 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
925 else if (!pause->rx_pause && pause->tx_pause)
926 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
927 else if (!pause->rx_pause && !pause->tx_pause)
928 hw->fc.requested_mode = I40E_FC_NONE;
929 else
930 return -EINVAL;
931
Catherine Sullivan94128512014-07-12 07:28:16 +0000932 /* Tell the OS link is going down, the link will go back up when fw
933 * says it is ready asynchronously
934 */
Matt Jaredc156f852015-08-27 11:42:39 -0400935 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000936 netif_carrier_off(netdev);
937 netif_tx_stop_all_queues(netdev);
938
Catherine Sullivan2becc352014-06-04 08:45:27 +0000939 /* Set the fc mode and only restart an if link is up*/
940 status = i40e_set_fc(hw, &aq_failures, link_up);
941
942 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400943 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
944 i40e_stat_str(hw, status),
945 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000946 err = -EAGAIN;
947 }
948 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400949 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
950 i40e_stat_str(hw, status),
951 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000952 err = -EAGAIN;
953 }
954 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400955 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
956 i40e_stat_str(hw, status),
957 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000958 err = -EAGAIN;
959 }
960
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000961 if (!test_bit(__I40E_DOWN, &pf->state)) {
962 /* Give it a little more time to try to come back */
963 msleep(75);
964 if (!test_bit(__I40E_DOWN, &pf->state))
965 return i40e_nway_reset(netdev);
966 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000967
968 return err;
969}
970
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000971static u32 i40e_get_msglevel(struct net_device *netdev)
972{
973 struct i40e_netdev_priv *np = netdev_priv(netdev);
974 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -0400975 u32 debug_mask = pf->hw.debug_mask;
976
977 if (debug_mask)
978 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000979
980 return pf->msg_enable;
981}
982
983static void i40e_set_msglevel(struct net_device *netdev, u32 data)
984{
985 struct i40e_netdev_priv *np = netdev_priv(netdev);
986 struct i40e_pf *pf = np->vsi->back;
987
988 if (I40E_DEBUG_USER & data)
989 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -0400990 else
991 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000992}
993
994static int i40e_get_regs_len(struct net_device *netdev)
995{
996 int reg_count = 0;
997 int i;
998
999 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1000 reg_count += i40e_reg_list[i].elements;
1001
1002 return reg_count * sizeof(u32);
1003}
1004
1005static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1006 void *p)
1007{
1008 struct i40e_netdev_priv *np = netdev_priv(netdev);
1009 struct i40e_pf *pf = np->vsi->back;
1010 struct i40e_hw *hw = &pf->hw;
1011 u32 *reg_buf = p;
1012 int i, j, ri;
1013 u32 reg;
1014
1015 /* Tell ethtool which driver-version-specific regs output we have.
1016 *
1017 * At some point, if we have ethtool doing special formatting of
1018 * this data, it will rely on this version number to know how to
1019 * interpret things. Hence, this needs to be updated if/when the
1020 * diags register table is changed.
1021 */
1022 regs->version = 1;
1023
1024 /* loop through the diags reg table for what to print */
1025 ri = 0;
1026 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1027 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1028 reg = i40e_reg_list[i].offset
1029 + (j * i40e_reg_list[i].stride);
1030 reg_buf[ri++] = rd32(hw, reg);
1031 }
1032 }
1033
1034}
1035
1036static int i40e_get_eeprom(struct net_device *netdev,
1037 struct ethtool_eeprom *eeprom, u8 *bytes)
1038{
1039 struct i40e_netdev_priv *np = netdev_priv(netdev);
1040 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001041 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001042 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001043 u8 *eeprom_buff;
1044 u16 i, sectors;
1045 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001046 u32 magic;
1047
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001048#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001049 if (eeprom->len == 0)
1050 return -EINVAL;
1051
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001052 /* check for NVMUpdate access method */
1053 magic = hw->vendor_id | (hw->device_id << 16);
1054 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001055 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1056 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001057
1058 /* make sure it is the right magic for NVMUpdate */
1059 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001060 errno = -EINVAL;
1061 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1062 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1063 errno = -EBUSY;
1064 else
1065 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001066
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001067 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001068 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001069 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1070 ret_val, hw->aq.asq_last_status, errno,
1071 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1072 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001073
1074 return errno;
1075 }
1076
1077 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001078 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1079
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001080 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001081 if (!eeprom_buff)
1082 return -ENOMEM;
1083
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001084 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1085 if (ret_val) {
1086 dev_info(&pf->pdev->dev,
1087 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1088 ret_val, hw->aq.asq_last_status);
1089 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001090 }
1091
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001092 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1093 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1094 len = I40E_NVM_SECTOR_SIZE;
1095 last = false;
1096 for (i = 0; i < sectors; i++) {
1097 if (i == (sectors - 1)) {
1098 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1099 last = true;
1100 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001101 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1102 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001103 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001104 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001105 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001106 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001107 "read NVM failed, invalid offset 0x%x\n",
1108 offset);
1109 break;
1110 } else if (ret_val &&
1111 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1112 dev_info(&pf->pdev->dev,
1113 "read NVM failed, access, offset 0x%x\n",
1114 offset);
1115 break;
1116 } else if (ret_val) {
1117 dev_info(&pf->pdev->dev,
1118 "read NVM failed offset %d err=%d status=0x%x\n",
1119 offset, ret_val, hw->aq.asq_last_status);
1120 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001121 }
1122 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001123
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001124 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001125 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001126free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001127 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001128 return ret_val;
1129}
1130
1131static int i40e_get_eeprom_len(struct net_device *netdev)
1132{
1133 struct i40e_netdev_priv *np = netdev_priv(netdev);
1134 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001135 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001136
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001137 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1138 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1139 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1140 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001141 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001142 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001143}
1144
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001145static int i40e_set_eeprom(struct net_device *netdev,
1146 struct ethtool_eeprom *eeprom, u8 *bytes)
1147{
1148 struct i40e_netdev_priv *np = netdev_priv(netdev);
1149 struct i40e_hw *hw = &np->vsi->back->hw;
1150 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001151 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001152 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001153 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001154 u32 magic;
1155
1156 /* normal ethtool set_eeprom is not supported */
1157 magic = hw->vendor_id | (hw->device_id << 16);
1158 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001159 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001160 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001161 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1162 errno = -EINVAL;
1163 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1164 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1165 errno = -EBUSY;
1166 else
1167 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001168
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001169 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001170 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001171 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1172 ret_val, hw->aq.asq_last_status, errno,
1173 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1174 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001175
1176 return errno;
1177}
1178
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001179static void i40e_get_drvinfo(struct net_device *netdev,
1180 struct ethtool_drvinfo *drvinfo)
1181{
1182 struct i40e_netdev_priv *np = netdev_priv(netdev);
1183 struct i40e_vsi *vsi = np->vsi;
1184 struct i40e_pf *pf = vsi->back;
1185
1186 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1187 strlcpy(drvinfo->version, i40e_driver_version_str,
1188 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001189 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001190 sizeof(drvinfo->fw_version));
1191 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1192 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001193 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001194 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001195 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196}
1197
1198static void i40e_get_ringparam(struct net_device *netdev,
1199 struct ethtool_ringparam *ring)
1200{
1201 struct i40e_netdev_priv *np = netdev_priv(netdev);
1202 struct i40e_pf *pf = np->vsi->back;
1203 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1204
1205 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1206 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1207 ring->rx_mini_max_pending = 0;
1208 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001209 ring->rx_pending = vsi->rx_rings[0]->count;
1210 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001211 ring->rx_mini_pending = 0;
1212 ring->rx_jumbo_pending = 0;
1213}
1214
1215static int i40e_set_ringparam(struct net_device *netdev,
1216 struct ethtool_ringparam *ring)
1217{
1218 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1219 struct i40e_netdev_priv *np = netdev_priv(netdev);
1220 struct i40e_vsi *vsi = np->vsi;
1221 struct i40e_pf *pf = vsi->back;
1222 u32 new_rx_count, new_tx_count;
1223 int i, err = 0;
1224
1225 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1226 return -EINVAL;
1227
Shannon Nelson1fa18372013-11-20 10:03:08 +00001228 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1229 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1230 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1231 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1232 netdev_info(netdev,
1233 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1234 ring->tx_pending, ring->rx_pending,
1235 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1236 return -EINVAL;
1237 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001238
Shannon Nelson1fa18372013-11-20 10:03:08 +00001239 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1240 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001241
1242 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001243 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1244 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001245 return 0;
1246
1247 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1248 usleep_range(1000, 2000);
1249
1250 if (!netif_running(vsi->netdev)) {
1251 /* simple case - set for the next time the netdev is started */
1252 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001253 vsi->tx_rings[i]->count = new_tx_count;
1254 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001255 }
1256 goto done;
1257 }
1258
1259 /* We can't just free everything and then setup again,
1260 * because the ISRs in MSI-X mode get passed pointers
1261 * to the Tx and Rx ring structs.
1262 */
1263
1264 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001265 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001266 netdev_info(netdev,
1267 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001268 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1270 sizeof(struct i40e_ring), GFP_KERNEL);
1271 if (!tx_rings) {
1272 err = -ENOMEM;
1273 goto done;
1274 }
1275
1276 for (i = 0; i < vsi->num_queue_pairs; i++) {
1277 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001278 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001279 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001280 /* the desc and bi pointers will be reallocated in the
1281 * setup call
1282 */
1283 tx_rings[i].desc = NULL;
1284 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001285 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1286 if (err) {
1287 while (i) {
1288 i--;
1289 i40e_free_tx_resources(&tx_rings[i]);
1290 }
1291 kfree(tx_rings);
1292 tx_rings = NULL;
1293
1294 goto done;
1295 }
1296 }
1297 }
1298
1299 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001300 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301 netdev_info(netdev,
1302 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001303 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001304 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1305 sizeof(struct i40e_ring), GFP_KERNEL);
1306 if (!rx_rings) {
1307 err = -ENOMEM;
1308 goto free_tx;
1309 }
1310
1311 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001312 /* this is to allow wr32 to have something to write to
1313 * during early allocation of Rx buffers
1314 */
1315 u32 __iomem faketail = 0;
1316 struct i40e_ring *ring;
1317 u16 unused;
1318
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001320 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001321 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001322 /* the desc and bi pointers will be reallocated in the
1323 * setup call
1324 */
1325 rx_rings[i].desc = NULL;
1326 rx_rings[i].rx_bi = NULL;
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001327 rx_rings[i].tail = (u8 __iomem *)&faketail;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001328 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001329 if (err)
1330 goto rx_unwind;
1331
1332 /* now allocate the Rx buffers to make sure the OS
1333 * has enough memory, any failure here means abort
1334 */
1335 ring = &rx_rings[i];
1336 unused = I40E_DESC_UNUSED(ring);
1337 err = i40e_alloc_rx_buffers(ring, unused);
1338rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001339 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001340 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001342 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001343 kfree(rx_rings);
1344 rx_rings = NULL;
1345
1346 goto free_tx;
1347 }
1348 }
1349 }
1350
1351 /* Bring interface down, copy in the new ring info,
1352 * then restore the interface
1353 */
1354 i40e_down(vsi);
1355
1356 if (tx_rings) {
1357 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001358 i40e_free_tx_resources(vsi->tx_rings[i]);
1359 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001360 }
1361 kfree(tx_rings);
1362 tx_rings = NULL;
1363 }
1364
1365 if (rx_rings) {
1366 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001367 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001368 /* get the real tail offset */
1369 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1370 /* this is to fake out the allocation routine
1371 * into thinking it has to realloc everything
1372 * but the recycling logic will let us re-use
1373 * the buffers allocated above
1374 */
1375 rx_rings[i].next_to_use = 0;
1376 rx_rings[i].next_to_clean = 0;
1377 rx_rings[i].next_to_alloc = 0;
1378 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001379 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001380 }
1381 kfree(rx_rings);
1382 rx_rings = NULL;
1383 }
1384
1385 i40e_up(vsi);
1386
1387free_tx:
1388 /* error cleanup if the Rx allocations failed after getting Tx */
1389 if (tx_rings) {
1390 for (i = 0; i < vsi->num_queue_pairs; i++)
1391 i40e_free_tx_resources(&tx_rings[i]);
1392 kfree(tx_rings);
1393 tx_rings = NULL;
1394 }
1395
1396done:
1397 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1398
1399 return err;
1400}
1401
1402static int i40e_get_sset_count(struct net_device *netdev, int sset)
1403{
1404 struct i40e_netdev_priv *np = netdev_priv(netdev);
1405 struct i40e_vsi *vsi = np->vsi;
1406 struct i40e_pf *pf = vsi->back;
1407
1408 switch (sset) {
1409 case ETH_SS_TEST:
1410 return I40E_TEST_LEN;
1411 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001412 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001413 int len = I40E_PF_STATS_LEN(netdev);
1414
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001415 if ((pf->lan_veb != I40E_NO_VEB) &&
1416 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001417 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001418 return len;
1419 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001421 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001422 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001423 return I40E_PRIV_FLAGS_STR_LEN +
1424 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001425 default:
1426 return -EOPNOTSUPP;
1427 }
1428}
1429
1430static void i40e_get_ethtool_stats(struct net_device *netdev,
1431 struct ethtool_stats *stats, u64 *data)
1432{
1433 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001434 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001435 struct i40e_vsi *vsi = np->vsi;
1436 struct i40e_pf *pf = vsi->back;
1437 int i = 0;
1438 char *p;
1439 int j;
1440 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001441 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001442
1443 i40e_update_stats(vsi);
1444
1445 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1446 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1447 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1448 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1449 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001450 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1451 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1452 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1453 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1454 }
Vasu Dev38e00432014-08-01 13:27:03 -07001455#ifdef I40E_FCOE
1456 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1457 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1458 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1459 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1460 }
1461#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001462 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001463 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001464 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001465
1466 if (!tx_ring)
1467 continue;
1468
1469 /* process Tx ring statistics */
1470 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001471 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001472 data[i] = tx_ring->stats.packets;
1473 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001474 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001475 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001476
1477 /* Rx ring is the 2nd half of the queue pair */
1478 rx_ring = &tx_ring[1];
1479 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001480 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001481 data[i] = rx_ring->stats.packets;
1482 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001483 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001484 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001485 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001486 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001487 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001488 return;
1489
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001490 if ((pf->lan_veb != I40E_NO_VEB) &&
1491 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001492 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001493
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001494 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1495 p = (char *)veb;
1496 p += i40e_gstrings_veb_stats[j].stat_offset;
1497 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1498 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001499 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001500 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1501 data[i++] = veb->tc_stats.tc_tx_packets[j];
1502 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1503 data[i++] = veb->tc_stats.tc_rx_packets[j];
1504 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1505 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001507 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1508 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1509 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1510 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1511 }
1512 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1513 data[i++] = pf->stats.priority_xon_tx[j];
1514 data[i++] = pf->stats.priority_xoff_tx[j];
1515 }
1516 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1517 data[i++] = pf->stats.priority_xon_rx[j];
1518 data[i++] = pf->stats.priority_xoff_rx[j];
1519 }
1520 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1521 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522}
1523
1524static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1525 u8 *data)
1526{
1527 struct i40e_netdev_priv *np = netdev_priv(netdev);
1528 struct i40e_vsi *vsi = np->vsi;
1529 struct i40e_pf *pf = vsi->back;
1530 char *p = (char *)data;
1531 int i;
1532
1533 switch (stringset) {
1534 case ETH_SS_TEST:
1535 for (i = 0; i < I40E_TEST_LEN; i++) {
1536 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1537 data += ETH_GSTRING_LEN;
1538 }
1539 break;
1540 case ETH_SS_STATS:
1541 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1542 snprintf(p, ETH_GSTRING_LEN, "%s",
1543 i40e_gstrings_net_stats[i].stat_string);
1544 p += ETH_GSTRING_LEN;
1545 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001546 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1547 snprintf(p, ETH_GSTRING_LEN, "%s",
1548 i40e_gstrings_misc_stats[i].stat_string);
1549 p += ETH_GSTRING_LEN;
1550 }
Vasu Dev38e00432014-08-01 13:27:03 -07001551#ifdef I40E_FCOE
1552 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1553 snprintf(p, ETH_GSTRING_LEN, "%s",
1554 i40e_gstrings_fcoe_stats[i].stat_string);
1555 p += ETH_GSTRING_LEN;
1556 }
1557#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001559 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001560 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001561 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001563 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_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, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566 p += ETH_GSTRING_LEN;
1567 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001568 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001569 return;
1570
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001571 if ((pf->lan_veb != I40E_NO_VEB) &&
1572 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001573 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1574 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1575 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001576 p += ETH_GSTRING_LEN;
1577 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001578 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1579 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001580 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001581 p += ETH_GSTRING_LEN;
1582 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001583 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001584 p += ETH_GSTRING_LEN;
1585 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001586 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001587 p += ETH_GSTRING_LEN;
1588 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001589 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001590 p += ETH_GSTRING_LEN;
1591 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001592 }
1593 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1594 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1595 i40e_gstrings_stats[i].stat_string);
1596 p += ETH_GSTRING_LEN;
1597 }
1598 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1599 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001600 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001601 p += ETH_GSTRING_LEN;
1602 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001603 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001604 p += ETH_GSTRING_LEN;
1605 }
1606 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1607 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001608 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001609 p += ETH_GSTRING_LEN;
1610 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001611 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001612 p += ETH_GSTRING_LEN;
1613 }
1614 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1615 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001616 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001617 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001618 }
1619 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1620 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001621 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001622 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1623 memcpy(data, i40e_priv_flags_strings[i],
1624 ETH_GSTRING_LEN);
1625 data += ETH_GSTRING_LEN;
1626 }
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001627 if (pf->hw.pf_id == 0) {
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001628 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1629 memcpy(data, i40e_gl_priv_flags_strings[i],
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001630 ETH_GSTRING_LEN);
1631 data += ETH_GSTRING_LEN;
1632 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001633 }
1634 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001635 default:
1636 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001637 }
1638}
1639
1640static int i40e_get_ts_info(struct net_device *dev,
1641 struct ethtool_ts_info *info)
1642{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001643 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1644
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001645 /* only report HW timestamping if PTP is enabled */
1646 if (!(pf->flags & I40E_FLAG_PTP))
1647 return ethtool_op_get_ts_info(dev, info);
1648
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001649 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1650 SOF_TIMESTAMPING_RX_SOFTWARE |
1651 SOF_TIMESTAMPING_SOFTWARE |
1652 SOF_TIMESTAMPING_TX_HARDWARE |
1653 SOF_TIMESTAMPING_RX_HARDWARE |
1654 SOF_TIMESTAMPING_RAW_HARDWARE;
1655
1656 if (pf->ptp_clock)
1657 info->phc_index = ptp_clock_index(pf->ptp_clock);
1658 else
1659 info->phc_index = -1;
1660
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001661 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001662
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001663 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1664 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1665 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001666
1667 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668}
1669
Shannon Nelson7b086392013-11-20 10:02:59 +00001670static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001671{
Shannon Nelson7b086392013-11-20 10:02:59 +00001672 struct i40e_netdev_priv *np = netdev_priv(netdev);
1673 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001674 i40e_status status;
1675 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001676
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001677 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001678 status = i40e_get_link_status(&pf->hw, &link_up);
1679 if (status) {
1680 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1681 *data = 1;
1682 return *data;
1683 }
1684
1685 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001686 *data = 0;
1687 else
1688 *data = 1;
1689
1690 return *data;
1691}
1692
Shannon Nelson7b086392013-11-20 10:02:59 +00001693static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694{
Shannon Nelson7b086392013-11-20 10:02:59 +00001695 struct i40e_netdev_priv *np = netdev_priv(netdev);
1696 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001698 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001699 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001700
Shannon Nelson7b086392013-11-20 10:02:59 +00001701 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001702}
1703
Shannon Nelson7b086392013-11-20 10:02:59 +00001704static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001705{
Shannon Nelson7b086392013-11-20 10:02:59 +00001706 struct i40e_netdev_priv *np = netdev_priv(netdev);
1707 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001708
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001709 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001710 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001711
Shannon Nelson4443ec92014-11-13 08:23:12 +00001712 /* forcebly clear the NVM Update state machine */
1713 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1714
Shannon Nelson7b086392013-11-20 10:02:59 +00001715 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001716}
1717
Shannon Nelson7b086392013-11-20 10:02:59 +00001718static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001719{
Shannon Nelson7b086392013-11-20 10:02:59 +00001720 struct i40e_netdev_priv *np = netdev_priv(netdev);
1721 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001722 u16 swc_old = pf->sw_int_count;
1723
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001724 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001725 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1726 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001727 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1728 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1729 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1730 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001731 usleep_range(1000, 2000);
1732 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733
1734 return *data;
1735}
1736
Greg Rosee17bc412015-04-16 20:05:59 -04001737static inline bool i40e_active_vfs(struct i40e_pf *pf)
1738{
1739 struct i40e_vf *vfs = pf->vf;
1740 int i;
1741
1742 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001743 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001744 return true;
1745 return false;
1746}
1747
Greg Rose510efb22015-07-10 19:36:01 -04001748static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1749{
Alexander Duyck4b816442016-10-11 15:26:53 -07001750 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001751}
1752
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001753static void i40e_diag_test(struct net_device *netdev,
1754 struct ethtool_test *eth_test, u64 *data)
1755{
1756 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001757 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001758 struct i40e_pf *pf = np->vsi->back;
1759
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001760 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1761 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001762 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001763
Shannon Nelsonf551b432013-11-26 10:49:12 +00001764 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001765
Greg Rose510efb22015-07-10 19:36:01 -04001766 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001767 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001768 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001769 data[I40E_ETH_TEST_REG] = 1;
1770 data[I40E_ETH_TEST_EEPROM] = 1;
1771 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001772 data[I40E_ETH_TEST_LINK] = 1;
1773 eth_test->flags |= ETH_TEST_FL_FAILED;
1774 clear_bit(__I40E_TESTING, &pf->state);
1775 goto skip_ol_tests;
1776 }
1777
Greg Rose5b86c5c2015-02-26 16:14:35 +00001778 /* If the device is online then take it offline */
1779 if (if_running)
1780 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001781 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001782 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001783 /* This reset does not affect link - if it is
1784 * changed to a type of reset that does affect
1785 * link then the following link test would have
1786 * to be moved to before the reset
1787 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001788 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001789
Shannon Nelson7b086392013-11-20 10:02:59 +00001790 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791 eth_test->flags |= ETH_TEST_FL_FAILED;
1792
Shannon Nelson7b086392013-11-20 10:02:59 +00001793 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001794 eth_test->flags |= ETH_TEST_FL_FAILED;
1795
Shannon Nelson7b086392013-11-20 10:02:59 +00001796 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797 eth_test->flags |= ETH_TEST_FL_FAILED;
1798
Shannon Nelsonf551b432013-11-26 10:49:12 +00001799 /* run reg test last, a reset is required after it */
1800 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1801 eth_test->flags |= ETH_TEST_FL_FAILED;
1802
1803 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001804 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001805
1806 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001807 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001808 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001809 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001810 netif_info(pf, drv, netdev, "online testing starting\n");
1811
Shannon Nelson7b086392013-11-20 10:02:59 +00001812 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001813 eth_test->flags |= ETH_TEST_FL_FAILED;
1814
1815 /* Offline only tests, not run in online; pass by default */
1816 data[I40E_ETH_TEST_REG] = 0;
1817 data[I40E_ETH_TEST_EEPROM] = 0;
1818 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001820
Greg Rosee17bc412015-04-16 20:05:59 -04001821skip_ol_tests:
1822
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001823 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001824}
1825
1826static void i40e_get_wol(struct net_device *netdev,
1827 struct ethtool_wolinfo *wol)
1828{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001829 struct i40e_netdev_priv *np = netdev_priv(netdev);
1830 struct i40e_pf *pf = np->vsi->back;
1831 struct i40e_hw *hw = &pf->hw;
1832 u16 wol_nvm_bits;
1833
1834 /* NVM bit on means WoL disabled for the port */
1835 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001836 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001837 wol->supported = 0;
1838 wol->wolopts = 0;
1839 } else {
1840 wol->supported = WAKE_MAGIC;
1841 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1842 }
1843}
1844
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001845/**
1846 * i40e_set_wol - set the WakeOnLAN configuration
1847 * @netdev: the netdev in question
1848 * @wol: the ethtool WoL setting data
1849 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001850static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1851{
1852 struct i40e_netdev_priv *np = netdev_priv(netdev);
1853 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001854 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001855 struct i40e_hw *hw = &pf->hw;
1856 u16 wol_nvm_bits;
1857
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001858 /* WoL not supported if this isn't the controlling PF on the port */
1859 if (hw->partition_id != 1) {
1860 i40e_partition_setting_complaint(pf);
1861 return -EOPNOTSUPP;
1862 }
1863
1864 if (vsi != pf->vsi[pf->lan_vsi])
1865 return -EOPNOTSUPP;
1866
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001867 /* NVM bit on means WoL disabled for the port */
1868 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001869 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001870 return -EOPNOTSUPP;
1871
1872 /* only magic packet is supported */
1873 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1874 return -EOPNOTSUPP;
1875
1876 /* is this a new value? */
1877 if (pf->wol_en != !!wol->wolopts) {
1878 pf->wol_en = !!wol->wolopts;
1879 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1880 }
1881
1882 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001883}
1884
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001885static int i40e_set_phys_id(struct net_device *netdev,
1886 enum ethtool_phys_id_state state)
1887{
1888 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001889 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001890 struct i40e_pf *pf = np->vsi->back;
1891 struct i40e_hw *hw = &pf->hw;
1892 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001893 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001894
1895 switch (state) {
1896 case ETHTOOL_ID_ACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001897 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1898 pf->led_status = i40e_led_get(hw);
1899 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001900 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001901 ret = i40e_led_get_phy(hw, &temp_status,
1902 &pf->phy_led_val);
1903 pf->led_status = temp_status;
1904 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001905 return blink_freq;
1906 case ETHTOOL_ID_ON:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001907 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1908 i40e_led_set(hw, 0xf, false);
1909 else
1910 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001911 break;
1912 case ETHTOOL_ID_OFF:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001913 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1914 i40e_led_set(hw, 0x0, false);
1915 else
1916 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001917 break;
1918 case ETHTOOL_ID_INACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001919 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1920 i40e_led_set(hw, false, pf->led_status);
1921 } else {
1922 ret = i40e_led_set_phy(hw, false, pf->led_status,
1923 (pf->phy_led_val |
1924 I40E_PHY_LED_MODE_ORIG));
1925 i40e_aq_set_phy_debug(hw, 0, NULL);
1926 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001927 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001928 default:
1929 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001931 if (ret)
1932 return -ENOENT;
1933 else
1934 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001935}
1936
1937/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1938 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1939 * 125us (8000 interrupts per second) == ITR(62)
1940 */
1941
Jacob Keller65e87c02016-09-12 14:18:44 -07001942/**
1943 * __i40e_get_coalesce - get per-queue coalesce settings
1944 * @netdev: the netdev to check
1945 * @ec: ethtool coalesce data structure
1946 * @queue: which queue to pick
1947 *
1948 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
1949 * are per queue. If queue is <0 then we default to queue 0 as the
1950 * representative value.
1951 **/
Kan Lianga75e8002016-02-19 09:24:04 -05001952static int __i40e_get_coalesce(struct net_device *netdev,
1953 struct ethtool_coalesce *ec,
1954 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001955{
1956 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07001957 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958 struct i40e_vsi *vsi = np->vsi;
1959
1960 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1961 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1962
Kan Lianga75e8002016-02-19 09:24:04 -05001963 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
1964 * return queue 0's value to represent.
1965 */
1966 if (queue < 0) {
1967 queue = 0;
1968 } else if (queue >= vsi->num_queue_pairs) {
1969 return -EINVAL;
1970 }
1971
Jacob Keller65e87c02016-09-12 14:18:44 -07001972 rx_ring = vsi->rx_rings[queue];
1973 tx_ring = vsi->tx_rings[queue];
1974
1975 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001976 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001977
Jacob Keller65e87c02016-09-12 14:18:44 -07001978 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001979 ec->use_adaptive_tx_coalesce = 1;
1980
Jacob Keller65e87c02016-09-12 14:18:44 -07001981 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1982 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1983
Kan Lianga75e8002016-02-19 09:24:04 -05001984
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001985 /* we use the _usecs_high to store/set the interrupt rate limit
1986 * that the hardware supports, that almost but not quite
1987 * fits the original intent of the ethtool variable,
1988 * the rx_coalesce_usecs_high limits total interrupts
1989 * per second from both tx/rx sources.
1990 */
1991 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1992 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001993
1994 return 0;
1995}
1996
Jacob Keller65e87c02016-09-12 14:18:44 -07001997/**
1998 * i40e_get_coalesce - get a netdev's coalesce settings
1999 * @netdev: the netdev to check
2000 * @ec: ethtool coalesce data structure
2001 *
2002 * Gets the coalesce settings for a particular netdev. Note that if user has
2003 * modified per-queue settings, this only guarantees to represent queue 0. See
2004 * __i40e_get_coalesce for more details.
2005 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002006static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002007 struct ethtool_coalesce *ec)
2008{
Kan Lianga75e8002016-02-19 09:24:04 -05002009 return __i40e_get_coalesce(netdev, ec, -1);
2010}
2011
Jacob Keller65e87c02016-09-12 14:18:44 -07002012/**
2013 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2014 * @netdev: netdev structure
2015 * @ec: ethtool's coalesce settings
2016 * @queue: the particular queue to read
2017 *
2018 * Will read a specific queue's coalesce settings
2019 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002020static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2021 struct ethtool_coalesce *ec)
2022{
2023 return __i40e_get_coalesce(netdev, ec, queue);
2024}
2025
Jacob Keller65e87c02016-09-12 14:18:44 -07002026/**
2027 * i40e_set_itr_per_queue - set ITR values for specific queue
2028 * @vsi: the VSI to set values for
2029 * @ec: coalesce settings from ethtool
2030 * @queue: the queue to modify
2031 *
2032 * Change the ITR settings for a specific queue.
2033 **/
2034
Kan Lianga75e8002016-02-19 09:24:04 -05002035static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2036 struct ethtool_coalesce *ec,
2037 int queue)
2038{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002039 struct i40e_pf *pf = vsi->back;
2040 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002041 struct i40e_q_vector *q_vector;
2042 u16 vector, intrl;
2043
2044 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
2045
2046 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2047 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2048
2049 if (ec->use_adaptive_rx_coalesce)
2050 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2051 else
2052 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2053
2054 if (ec->use_adaptive_tx_coalesce)
2055 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2056 else
2057 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2058
2059 q_vector = vsi->rx_rings[queue]->q_vector;
2060 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2061 vector = vsi->base_vector + q_vector->v_idx;
2062 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2063
2064 q_vector = vsi->tx_rings[queue]->q_vector;
2065 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2066 vector = vsi->base_vector + q_vector->v_idx;
2067 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2068
2069 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2070 i40e_flush(hw);
2071}
2072
Jacob Keller65e87c02016-09-12 14:18:44 -07002073/**
2074 * __i40e_set_coalesce - set coalesce settings for particular queue
2075 * @netdev: the netdev to change
2076 * @ec: ethtool coalesce settings
2077 * @queue: the queue to change
2078 *
2079 * Sets the coalesce settings for a particular queue.
2080 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002081static int __i40e_set_coalesce(struct net_device *netdev,
2082 struct ethtool_coalesce *ec,
2083 int queue)
2084{
2085 struct i40e_netdev_priv *np = netdev_priv(netdev);
2086 struct i40e_vsi *vsi = np->vsi;
2087 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002088 int i;
2089
2090 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2091 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2092
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002093 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2094 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2095 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2096 return -EINVAL;
2097 }
2098
2099 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2100 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
2101 return -EINVAL;
2102 }
2103
Kan Lianga75e8002016-02-19 09:24:04 -05002104 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002105 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002106 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 -05002107 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2108 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2109 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2110 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002111 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002112
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002113 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
2114
Kan Lianga75e8002016-02-19 09:24:04 -05002115 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002116 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002117 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 -05002118 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2119 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2120 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2121 return -EINVAL;
2122 }
2123
2124 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2125 * apply to all queues.
2126 */
2127 if (queue < 0) {
2128 for (i = 0; i < vsi->num_queue_pairs; i++)
2129 i40e_set_itr_per_queue(vsi, ec, i);
2130 } else if (queue < vsi->num_queue_pairs) {
2131 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002132 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002133 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2134 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002135 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002136 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002137
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002138 return 0;
2139}
2140
Jacob Keller65e87c02016-09-12 14:18:44 -07002141/**
2142 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2143 * @netdev: the netdev to change
2144 * @ec: ethtool coalesce settings
2145 *
2146 * This will set each queue to the same coalesce settings.
2147 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002148static int i40e_set_coalesce(struct net_device *netdev,
2149 struct ethtool_coalesce *ec)
2150{
2151 return __i40e_set_coalesce(netdev, ec, -1);
2152}
2153
Jacob Keller65e87c02016-09-12 14:18:44 -07002154/**
2155 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2156 * @netdev: the netdev to change
2157 * @ec: ethtool's coalesce settings
2158 * @queue: the queue to change
2159 *
2160 * Sets the specified queue's coalesce settings.
2161 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002162static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2163 struct ethtool_coalesce *ec)
2164{
2165 return __i40e_set_coalesce(netdev, ec, queue);
2166}
2167
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002168/**
2169 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2170 * @pf: pointer to the physical function struct
2171 * @cmd: ethtool rxnfc command
2172 *
2173 * Returns Success if the flow is supported, else Invalid Input.
2174 **/
2175static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2176{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002177 struct i40e_hw *hw = &pf->hw;
2178 u8 flow_pctype = 0;
2179 u64 i_set = 0;
2180
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002181 cmd->data = 0;
2182
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002183 switch (cmd->flow_type) {
2184 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002185 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2186 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002188 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2189 break;
2190 case TCP_V6_FLOW:
2191 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2192 break;
2193 case UDP_V6_FLOW:
2194 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2195 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002196 case SCTP_V4_FLOW:
2197 case AH_ESP_V4_FLOW:
2198 case AH_V4_FLOW:
2199 case ESP_V4_FLOW:
2200 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002201 case SCTP_V6_FLOW:
2202 case AH_ESP_V6_FLOW:
2203 case AH_V6_FLOW:
2204 case ESP_V6_FLOW:
2205 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002206 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002207 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2208 break;
2209 default:
2210 return -EINVAL;
2211 }
2212
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002213 /* Read flow based hash input set register */
2214 if (flow_pctype) {
2215 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2216 flow_pctype)) |
2217 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2218 flow_pctype)) << 32);
2219 }
2220
2221 /* Process bits of hash input set */
2222 if (i_set) {
2223 if (i_set & I40E_L4_SRC_MASK)
2224 cmd->data |= RXH_L4_B_0_1;
2225 if (i_set & I40E_L4_DST_MASK)
2226 cmd->data |= RXH_L4_B_2_3;
2227
2228 if (cmd->flow_type == TCP_V4_FLOW ||
2229 cmd->flow_type == UDP_V4_FLOW) {
2230 if (i_set & I40E_L3_SRC_MASK)
2231 cmd->data |= RXH_IP_SRC;
2232 if (i_set & I40E_L3_DST_MASK)
2233 cmd->data |= RXH_IP_DST;
2234 } else if (cmd->flow_type == TCP_V6_FLOW ||
2235 cmd->flow_type == UDP_V6_FLOW) {
2236 if (i_set & I40E_L3_V6_SRC_MASK)
2237 cmd->data |= RXH_IP_SRC;
2238 if (i_set & I40E_L3_V6_DST_MASK)
2239 cmd->data |= RXH_IP_DST;
2240 }
2241 }
2242
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002243 return 0;
2244}
2245
2246/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002247 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2248 * @pf: Pointer to the physical function struct
2249 * @cmd: The command to get or set Rx flow classification rules
2250 * @rule_locs: Array of used rule locations
2251 *
2252 * This function populates both the total and actual rule count of
2253 * the ethtool flow classification command
2254 *
2255 * Returns 0 on success or -EMSGSIZE if entry not found
2256 **/
2257static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2258 struct ethtool_rxnfc *cmd,
2259 u32 *rule_locs)
2260{
2261 struct i40e_fdir_filter *rule;
2262 struct hlist_node *node2;
2263 int cnt = 0;
2264
2265 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002266 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002267
2268 hlist_for_each_entry_safe(rule, node2,
2269 &pf->fdir_filter_list, fdir_node) {
2270 if (cnt == cmd->rule_cnt)
2271 return -EMSGSIZE;
2272
2273 rule_locs[cnt] = rule->fd_id;
2274 cnt++;
2275 }
2276
2277 cmd->rule_cnt = cnt;
2278
2279 return 0;
2280}
2281
2282/**
2283 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2284 * @pf: Pointer to the physical function struct
2285 * @cmd: The command to get or set Rx flow classification rules
2286 *
2287 * This function looks up a filter based on the Rx flow classification
2288 * command and fills the flow spec info for it if found
2289 *
2290 * Returns 0 on success or -EINVAL if filter not found
2291 **/
2292static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2293 struct ethtool_rxnfc *cmd)
2294{
2295 struct ethtool_rx_flow_spec *fsp =
2296 (struct ethtool_rx_flow_spec *)&cmd->fs;
2297 struct i40e_fdir_filter *rule = NULL;
2298 struct hlist_node *node2;
2299
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002300 hlist_for_each_entry_safe(rule, node2,
2301 &pf->fdir_filter_list, fdir_node) {
2302 if (fsp->location <= rule->fd_id)
2303 break;
2304 }
2305
2306 if (!rule || fsp->location != rule->fd_id)
2307 return -EINVAL;
2308
2309 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002310 if (fsp->flow_type == IP_USER_FLOW) {
2311 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2312 fsp->h_u.usr_ip4_spec.proto = 0;
2313 fsp->m_u.usr_ip4_spec.proto = 0;
2314 }
2315
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002316 /* Reverse the src and dest notion, since the HW views them from
2317 * Tx perspective where as the user expects it from Rx filter view.
2318 */
2319 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2320 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2321 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2322 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002323
2324 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2325 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2326 else
2327 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002328
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002329 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2330 struct i40e_vsi *vsi;
2331
2332 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2333 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2334 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2335 fsp->m_ext.data[1] = htonl(0x1);
2336 }
2337 }
2338
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002339 return 0;
2340}
2341
2342/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002343 * i40e_get_rxnfc - command to get RX flow classification rules
2344 * @netdev: network interface device structure
2345 * @cmd: ethtool rxnfc command
2346 *
2347 * Returns Success if the command is supported.
2348 **/
2349static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2350 u32 *rule_locs)
2351{
2352 struct i40e_netdev_priv *np = netdev_priv(netdev);
2353 struct i40e_vsi *vsi = np->vsi;
2354 struct i40e_pf *pf = vsi->back;
2355 int ret = -EOPNOTSUPP;
2356
2357 switch (cmd->cmd) {
2358 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002359 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002360 ret = 0;
2361 break;
2362 case ETHTOOL_GRXFH:
2363 ret = i40e_get_rss_hash_opts(pf, cmd);
2364 break;
2365 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002366 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002367 /* report total rule count */
2368 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002369 ret = 0;
2370 break;
2371 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002372 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002373 break;
2374 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002375 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2376 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002377 default:
2378 break;
2379 }
2380
2381 return ret;
2382}
2383
2384/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002385 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2386 * @nfc: pointer to user request
2387 * @i_setc bits currently set
2388 *
2389 * Returns value of bits to be set per user request
2390 **/
2391static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2392{
2393 u64 i_set = i_setc;
2394 u64 src_l3 = 0, dst_l3 = 0;
2395
2396 if (nfc->data & RXH_L4_B_0_1)
2397 i_set |= I40E_L4_SRC_MASK;
2398 else
2399 i_set &= ~I40E_L4_SRC_MASK;
2400 if (nfc->data & RXH_L4_B_2_3)
2401 i_set |= I40E_L4_DST_MASK;
2402 else
2403 i_set &= ~I40E_L4_DST_MASK;
2404
2405 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2406 src_l3 = I40E_L3_V6_SRC_MASK;
2407 dst_l3 = I40E_L3_V6_DST_MASK;
2408 } else if (nfc->flow_type == TCP_V4_FLOW ||
2409 nfc->flow_type == UDP_V4_FLOW) {
2410 src_l3 = I40E_L3_SRC_MASK;
2411 dst_l3 = I40E_L3_DST_MASK;
2412 } else {
2413 /* Any other flow type are not supported here */
2414 return i_set;
2415 }
2416
2417 if (nfc->data & RXH_IP_SRC)
2418 i_set |= src_l3;
2419 else
2420 i_set &= ~src_l3;
2421 if (nfc->data & RXH_IP_DST)
2422 i_set |= dst_l3;
2423 else
2424 i_set &= ~dst_l3;
2425
2426 return i_set;
2427}
2428
2429/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002430 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2431 * @pf: pointer to the physical function struct
2432 * @cmd: ethtool rxnfc command
2433 *
2434 * Returns Success if the flow input set is supported.
2435 **/
2436static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2437{
2438 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002439 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2440 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002441 u8 flow_pctype = 0;
2442 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002443
2444 /* RSS does not support anything other than hashing
2445 * to queues on src and dst IPs and ports
2446 */
2447 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2448 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2449 return -EINVAL;
2450
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002451 switch (nfc->flow_type) {
2452 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002453 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2454 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2455 hena |=
2456 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002457 break;
2458 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002459 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2460 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2461 hena |=
2462 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2463 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2464 hena |=
2465 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002466 break;
2467 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002468 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2469 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2470 hena |=
2471 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2472 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002473
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002474 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002475 break;
2476 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002477 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2478 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2479 hena |=
2480 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2481 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002482
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002483 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002484 break;
2485 case AH_ESP_V4_FLOW:
2486 case AH_V4_FLOW:
2487 case ESP_V4_FLOW:
2488 case SCTP_V4_FLOW:
2489 if ((nfc->data & RXH_L4_B_0_1) ||
2490 (nfc->data & RXH_L4_B_2_3))
2491 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002492 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002493 break;
2494 case AH_ESP_V6_FLOW:
2495 case AH_V6_FLOW:
2496 case ESP_V6_FLOW:
2497 case SCTP_V6_FLOW:
2498 if ((nfc->data & RXH_L4_B_0_1) ||
2499 (nfc->data & RXH_L4_B_2_3))
2500 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002501 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002502 break;
2503 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002504 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2505 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002506 break;
2507 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002508 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2509 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002510 break;
2511 default:
2512 return -EINVAL;
2513 }
2514
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002515 if (flow_pctype) {
2516 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2517 flow_pctype)) |
2518 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2519 flow_pctype)) << 32);
2520 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2521 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2522 (u32)i_set);
2523 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2524 (u32)(i_set >> 32));
2525 hena |= BIT_ULL(flow_pctype);
2526 }
2527
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002528 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2529 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002530 i40e_flush(hw);
2531
2532 return 0;
2533}
2534
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002535/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002536 * i40e_match_fdir_input_set - Match a new filter against an existing one
2537 * @rule: The filter already added
2538 * @input: The new filter to comapre against
2539 *
2540 * Returns true if the two input set match
2541 **/
2542static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2543 struct i40e_fdir_filter *input)
2544{
2545 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2546 (rule->src_ip[0] != input->src_ip[0]) ||
2547 (rule->dst_port != input->dst_port) ||
2548 (rule->src_port != input->src_port))
2549 return false;
2550 return true;
2551}
2552
2553/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002554 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2555 * @vsi: Pointer to the targeted VSI
2556 * @input: The filter to update or NULL to indicate deletion
2557 * @sw_idx: Software index to the filter
2558 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002559 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002560 * This function updates (or deletes) a Flow Director entry from
2561 * the hlist of the corresponding PF
2562 *
2563 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002564 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002565static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2566 struct i40e_fdir_filter *input,
2567 u16 sw_idx,
2568 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002569{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002570 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002571 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002572 struct hlist_node *node2;
2573 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002574
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002575 parent = NULL;
2576 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002577
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002578 hlist_for_each_entry_safe(rule, node2,
2579 &pf->fdir_filter_list, fdir_node) {
2580 /* hash found, or no matching entry */
2581 if (rule->fd_id >= sw_idx)
2582 break;
2583 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002584 }
2585
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002586 /* if there is an old rule occupying our place remove it */
2587 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002588 if (input && !i40e_match_fdir_input_set(rule, input))
2589 err = i40e_add_del_fdir(vsi, rule, false);
2590 else if (!input)
2591 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002592 hlist_del(&rule->fdir_node);
2593 kfree(rule);
2594 pf->fdir_pf_active_filters--;
2595 }
2596
2597 /* If no input this was a delete, err should be 0 if a rule was
2598 * successfully found and removed from the list else -EINVAL
2599 */
2600 if (!input)
2601 return err;
2602
2603 /* initialize node and set software index */
2604 INIT_HLIST_NODE(&input->fdir_node);
2605
2606 /* add filter to the list */
2607 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002608 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002609 else
2610 hlist_add_head(&input->fdir_node,
2611 &pf->fdir_filter_list);
2612
2613 /* update counts */
2614 pf->fdir_pf_active_filters++;
2615
2616 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002617}
2618
2619/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002620 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2621 * @vsi: Pointer to the targeted VSI
2622 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002623 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002624 * The function removes a Flow Director filter entry from the
2625 * hlist of the corresponding PF
2626 *
2627 * Returns 0 on success
2628 */
2629static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2630 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002631{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002632 struct ethtool_rx_flow_spec *fsp =
2633 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002634 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002635 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002636
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002637 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2638 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2639 return -EBUSY;
2640
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002641 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2642 return -EBUSY;
2643
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002644 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002645
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002646 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002647 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002648}
2649
2650/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002651 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002652 * @vsi: pointer to the targeted VSI
2653 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002654 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002655 * Add Flow Director filters for a specific flow spec based on their
2656 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002657 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002658static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2659 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002660{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002661 struct ethtool_rx_flow_spec *fsp;
2662 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002663 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002664 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002665 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002666
2667 if (!vsi)
2668 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002669 pf = vsi->back;
2670
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002671 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2672 return -EOPNOTSUPP;
2673
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002674 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002675 return -ENOSPC;
2676
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002677 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2678 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2679 return -EBUSY;
2680
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002681 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2682 return -EBUSY;
2683
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002684 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2685
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002686 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2687 pf->hw.func_caps.fd_filters_guaranteed)) {
2688 return -EINVAL;
2689 }
2690
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002691 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2692 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002693 return -EINVAL;
2694
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002695 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002696
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002697 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002698 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002699
2700 input->fd_id = fsp->location;
2701
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002702 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2703 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2704 else
2705 input->dest_ctl =
2706 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2707
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002708 input->q_index = fsp->ring_cookie;
2709 input->flex_off = 0;
2710 input->pctype = 0;
2711 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002712 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002713 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002714 input->flow_type = fsp->flow_type;
2715 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002716
2717 /* Reverse the src and dest notion, since the HW expects them to be from
2718 * Tx perspective where as the input from user is from Rx filter view.
2719 */
2720 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2721 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2722 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2723 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002724
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002725 if (ntohl(fsp->m_ext.data[1])) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002726 vf_id = ntohl(fsp->h_ext.data[1]);
2727 if (vf_id >= pf->num_alloc_vfs) {
2728 netif_info(pf, drv, vsi->netdev,
2729 "Invalid VF id %d\n", vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002730 goto free_input;
2731 }
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002732 /* Find vsi id from vf id and override dest vsi */
2733 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2734 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002735 netif_info(pf, drv, vsi->netdev,
2736 "Invalid queue id %d for VF %d\n",
2737 input->q_index, vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002738 goto free_input;
2739 }
2740 }
2741
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002742 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002743free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002744 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002745 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002746 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002747 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002748
2749 return ret;
2750}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002751
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002752/**
2753 * i40e_set_rxnfc - command to set RX flow classification rules
2754 * @netdev: network interface device structure
2755 * @cmd: ethtool rxnfc command
2756 *
2757 * Returns Success if the command is supported.
2758 **/
2759static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2760{
2761 struct i40e_netdev_priv *np = netdev_priv(netdev);
2762 struct i40e_vsi *vsi = np->vsi;
2763 struct i40e_pf *pf = vsi->back;
2764 int ret = -EOPNOTSUPP;
2765
2766 switch (cmd->cmd) {
2767 case ETHTOOL_SRXFH:
2768 ret = i40e_set_rss_hash_opt(pf, cmd);
2769 break;
2770 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002771 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002772 break;
2773 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002774 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002775 break;
2776 default:
2777 break;
2778 }
2779
2780 return ret;
2781}
2782
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002783/**
2784 * i40e_max_channels - get Max number of combined channels supported
2785 * @vsi: vsi pointer
2786 **/
2787static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2788{
2789 /* TODO: This code assumes DCB and FD is disabled for now. */
2790 return vsi->alloc_queue_pairs;
2791}
2792
2793/**
2794 * i40e_get_channels - Get the current channels enabled and max supported etc.
2795 * @netdev: network interface device structure
2796 * @ch: ethtool channels structure
2797 *
2798 * We don't support separate tx and rx queues as channels. The other count
2799 * represents how many queues are being used for control. max_combined counts
2800 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2801 * q_vectors since we support a lot more queue pairs than q_vectors.
2802 **/
2803static void i40e_get_channels(struct net_device *dev,
2804 struct ethtool_channels *ch)
2805{
2806 struct i40e_netdev_priv *np = netdev_priv(dev);
2807 struct i40e_vsi *vsi = np->vsi;
2808 struct i40e_pf *pf = vsi->back;
2809
2810 /* report maximum channels */
2811 ch->max_combined = i40e_max_channels(vsi);
2812
2813 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002814 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002815 ch->max_other = ch->other_count;
2816
2817 /* Note: This code assumes DCB is disabled for now. */
2818 ch->combined_count = vsi->num_queue_pairs;
2819}
2820
2821/**
2822 * i40e_set_channels - Set the new channels count.
2823 * @netdev: network interface device structure
2824 * @ch: ethtool channels structure
2825 *
2826 * The new channels count may not be the same as requested by the user
2827 * since it gets rounded down to a power of 2 value.
2828 **/
2829static int i40e_set_channels(struct net_device *dev,
2830 struct ethtool_channels *ch)
2831{
Jacob Keller59826d92016-07-27 12:02:35 -07002832 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002833 struct i40e_netdev_priv *np = netdev_priv(dev);
2834 unsigned int count = ch->combined_count;
2835 struct i40e_vsi *vsi = np->vsi;
2836 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07002837 struct i40e_fdir_filter *rule;
2838 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002839 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07002840 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002841
2842 /* We do not support setting channels for any other VSI at present */
2843 if (vsi->type != I40E_VSI_MAIN)
2844 return -EINVAL;
2845
2846 /* verify they are not requesting separate vectors */
2847 if (!count || ch->rx_count || ch->tx_count)
2848 return -EINVAL;
2849
2850 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002851 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002852 return -EINVAL;
2853
2854 /* verify the number of channels does not exceed hardware limits */
2855 if (count > i40e_max_channels(vsi))
2856 return -EINVAL;
2857
Jacob Keller59826d92016-07-27 12:02:35 -07002858 /* verify that the number of channels does not invalidate any current
2859 * flow director rules
2860 */
2861 hlist_for_each_entry_safe(rule, node2,
2862 &pf->fdir_filter_list, fdir_node) {
2863 if (rule->dest_ctl != drop && count <= rule->q_index) {
2864 dev_warn(&pf->pdev->dev,
2865 "Existing user defined filter %d assigns flow to queue %d\n",
2866 rule->fd_id, rule->q_index);
2867 err = -EINVAL;
2868 }
2869 }
2870
2871 if (err) {
2872 dev_err(&pf->pdev->dev,
2873 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
2874 count);
2875 return err;
2876 }
2877
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002878 /* update feature limits from largest to smallest supported values */
2879 /* TODO: Flow director limit, DCB etc */
2880
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002881 /* use rss_reconfig to rebuild with new queue count and update traffic
2882 * class queue mapping
2883 */
2884 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002885 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002886 return 0;
2887 else
2888 return -EINVAL;
2889}
2890
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002891/**
2892 * i40e_get_rxfh_key_size - get the RSS hash key size
2893 * @netdev: network interface device structure
2894 *
2895 * Returns the table size.
2896 **/
2897static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2898{
2899 return I40E_HKEY_ARRAY_SIZE;
2900}
2901
2902/**
2903 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2904 * @netdev: network interface device structure
2905 *
2906 * Returns the table size.
2907 **/
2908static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2909{
2910 return I40E_HLUT_ARRAY_SIZE;
2911}
2912
2913static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2914 u8 *hfunc)
2915{
2916 struct i40e_netdev_priv *np = netdev_priv(netdev);
2917 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002918 u8 *lut, *seed = NULL;
2919 int ret;
2920 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002921
2922 if (hfunc)
2923 *hfunc = ETH_RSS_HASH_TOP;
2924
2925 if (!indir)
2926 return 0;
2927
Helin Zhang043dd652015-10-21 19:56:23 -04002928 seed = key;
2929 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2930 if (!lut)
2931 return -ENOMEM;
2932 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2933 if (ret)
2934 goto out;
2935 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2936 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002937
Helin Zhang043dd652015-10-21 19:56:23 -04002938out:
2939 kfree(lut);
2940
2941 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002942}
2943
2944/**
2945 * i40e_set_rxfh - set the rx flow hash indirection table
2946 * @netdev: network interface device structure
2947 * @indir: indirection table
2948 * @key: hash key
2949 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002950 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002951 * returns 0 after programming the table.
2952 **/
2953static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2954 const u8 *key, const u8 hfunc)
2955{
2956 struct i40e_netdev_priv *np = netdev_priv(netdev);
2957 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07002958 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04002959 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002960 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002961
2962 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2963 return -EOPNOTSUPP;
2964
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002965 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002966 if (!vsi->rss_hkey_user) {
2967 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2968 GFP_KERNEL);
2969 if (!vsi->rss_hkey_user)
2970 return -ENOMEM;
2971 }
2972 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2973 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002974 }
Helin Zhang28c58692015-10-26 19:44:27 -04002975 if (!vsi->rss_lut_user) {
2976 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2977 if (!vsi->rss_lut_user)
2978 return -ENOMEM;
2979 }
Helin Zhang043dd652015-10-21 19:56:23 -04002980
Helin Zhang28c58692015-10-26 19:44:27 -04002981 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07002982 if (indir)
2983 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2984 vsi->rss_lut_user[i] = (u8)(indir[i]);
2985 else
2986 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
2987 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04002988
2989 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2990 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002991}
2992
Greg Rose7e45ab42015-02-06 08:52:19 +00002993/**
2994 * i40e_get_priv_flags - report device private flags
2995 * @dev: network interface device structure
2996 *
2997 * The get string set count and the string set should be matched for each
2998 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2999 * array.
3000 *
3001 * Returns a u32 bitmap of flags.
3002 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00003003static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00003004{
3005 struct i40e_netdev_priv *np = netdev_priv(dev);
3006 struct i40e_vsi *vsi = np->vsi;
3007 struct i40e_pf *pf = vsi->back;
3008 u32 ret_flags = 0;
3009
Shannon Nelson9ac77262015-08-27 11:42:40 -04003010 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
3011 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04003012 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
3013 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003014 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
3015 I40E_PRIV_FLAGS_VEB_STATS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003016 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
3017 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003018 if (pf->hw.pf_id == 0) {
3019 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
3020 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
3021 }
Greg Rose7e45ab42015-02-06 08:52:19 +00003022
3023 return ret_flags;
3024}
3025
Shannon Nelson9ac77262015-08-27 11:42:40 -04003026/**
3027 * i40e_set_priv_flags - set private flags
3028 * @dev: network interface device structure
3029 * @flags: bit flags to be set
3030 **/
3031static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
3032{
3033 struct i40e_netdev_priv *np = netdev_priv(dev);
3034 struct i40e_vsi *vsi = np->vsi;
3035 struct i40e_pf *pf = vsi->back;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003036 u16 sw_flags = 0, valid_flags = 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003037 bool reset_required = false;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003038 bool promisc_change = false;
3039 int ret;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003040
3041 /* NOTE: MFP is not settable */
3042
Shannon Nelson9ac77262015-08-27 11:42:40 -04003043 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
3044 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
3045 else
3046 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
3047
Jesse Brandeburgef171782015-09-03 17:18:49 -04003048 /* allow the user to control the state of the Flow
3049 * Director ATR (Application Targeted Routing) feature
3050 * of the driver
3051 */
3052 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
3053 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
3054 } else {
3055 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
3056 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
Jacob Keller234dc4e2016-09-06 18:05:09 -07003057
3058 /* flush current ATR settings */
3059 set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04003060 }
3061
Shannon Nelson66fc3602016-01-13 16:51:42 -08003062 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3063 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003064 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003065 reset_required = true;
3066 } else 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 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003071
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003072 if (pf->hw.pf_id == 0) {
3073 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3074 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3075 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
3076 promisc_change = true;
3077 } else 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 }
3082 }
3083 if (promisc_change) {
3084 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
3085 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3086 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3087 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
3088 NULL);
3089 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
3090 dev_info(&pf->pdev->dev,
3091 "couldn't set switch config bits, err %s aq_err %s\n",
3092 i40e_stat_str(&pf->hw, ret),
3093 i40e_aq_str(&pf->hw,
3094 pf->hw.aq.asq_last_status));
3095 /* not a fatal problem, just keep going */
3096 }
3097 }
3098
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003099 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
3100 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
3101 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
3102 else
3103 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
3104
Jesse Brandeburg827de392015-11-06 15:26:07 -08003105 /* if needed, issue reset to cause things to take effect */
3106 if (reset_required)
3107 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
3108
Shannon Nelson9ac77262015-08-27 11:42:40 -04003109 return 0;
3110}
3111
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003112static const struct ethtool_ops i40e_ethtool_ops = {
3113 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00003114 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003115 .get_drvinfo = i40e_get_drvinfo,
3116 .get_regs_len = i40e_get_regs_len,
3117 .get_regs = i40e_get_regs,
3118 .nway_reset = i40e_nway_reset,
3119 .get_link = ethtool_op_get_link,
3120 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00003121 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003122 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003123 .get_eeprom_len = i40e_get_eeprom_len,
3124 .get_eeprom = i40e_get_eeprom,
3125 .get_ringparam = i40e_get_ringparam,
3126 .set_ringparam = i40e_set_ringparam,
3127 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00003128 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003129 .get_msglevel = i40e_get_msglevel,
3130 .set_msglevel = i40e_set_msglevel,
3131 .get_rxnfc = i40e_get_rxnfc,
3132 .set_rxnfc = i40e_set_rxnfc,
3133 .self_test = i40e_diag_test,
3134 .get_strings = i40e_get_strings,
3135 .set_phys_id = i40e_set_phys_id,
3136 .get_sset_count = i40e_get_sset_count,
3137 .get_ethtool_stats = i40e_get_ethtool_stats,
3138 .get_coalesce = i40e_get_coalesce,
3139 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003140 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3141 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3142 .get_rxfh = i40e_get_rxfh,
3143 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003144 .get_channels = i40e_get_channels,
3145 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003146 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00003147 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04003148 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05003149 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05003150 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003151};
3152
3153void i40e_set_ethtool_ops(struct net_device *netdev)
3154{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003155 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003156}