blob: a933c6c2aff897319bec8d7c6dc9f8d68877dc35 [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{
Avinash Dayanand28537042016-06-20 09:10:33 -0700268 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800269 u64 phy_types = pf->hw.phy.phy_types;
270
Catherine Sullivan06566e52016-05-03 15:13:14 -0700271 *supported = 0x0;
272 *advertising = 0x0;
273
274 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
275 *supported |= SUPPORTED_Autoneg |
276 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700277 *advertising |= ADVERTISED_Autoneg;
278 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
279 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700280 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
281 *supported |= SUPPORTED_100baseT_Full;
282 *advertising |= ADVERTISED_100baseT_Full;
283 }
284 }
285 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
286 phy_types & I40E_CAP_PHY_TYPE_XFI ||
287 phy_types & I40E_CAP_PHY_TYPE_SFI ||
288 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
289 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
290 *supported |= SUPPORTED_10000baseT_Full;
291 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
292 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
294 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
295 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
296 *supported |= SUPPORTED_Autoneg |
297 SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700298 *advertising |= ADVERTISED_Autoneg;
299 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
300 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700301 }
302 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
303 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
304 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
305 *supported |= SUPPORTED_40000baseCR4_Full;
306 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
307 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
308 *supported |= SUPPORTED_Autoneg |
309 SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700310 *advertising |= ADVERTISED_Autoneg;
311 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
312 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700313 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700314 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700315 *supported |= SUPPORTED_Autoneg |
316 SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700317 *advertising |= ADVERTISED_Autoneg;
318 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
319 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700320 }
321 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
322 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
323 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
324 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
325 *supported |= SUPPORTED_Autoneg |
326 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700327 *advertising |= ADVERTISED_Autoneg;
328 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
329 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700330 }
331 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
332 *supported |= SUPPORTED_40000baseSR4_Full;
333 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
334 *supported |= SUPPORTED_40000baseLR4_Full;
335 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
336 *supported |= SUPPORTED_40000baseKR4_Full |
337 SUPPORTED_Autoneg;
338 *advertising |= ADVERTISED_40000baseKR4_Full |
339 ADVERTISED_Autoneg;
340 }
341 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
342 *supported |= SUPPORTED_20000baseKR2_Full |
343 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700344 *advertising |= ADVERTISED_Autoneg;
345 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
346 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700347 }
348 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800349 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
350 *supported |= SUPPORTED_10000baseKR_Full |
351 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700352 *advertising |= ADVERTISED_Autoneg;
353 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800354 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
355 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700356 }
357 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
358 *supported |= SUPPORTED_10000baseKX4_Full |
359 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700360 *advertising |= ADVERTISED_Autoneg;
361 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
362 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700363 }
364 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800365 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
366 *supported |= SUPPORTED_1000baseKX_Full |
367 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700368 *advertising |= ADVERTISED_Autoneg;
369 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800370 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
371 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700372 }
Carolyn Wyborny31232372016-11-21 13:03:48 -0800373 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
374 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
375 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
376 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
377 *supported |= SUPPORTED_Autoneg;
378 *advertising |= ADVERTISED_Autoneg;
379 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700380}
381
382/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000383 * i40e_get_settings_link_up - Get the Link settings for when link is up
384 * @hw: hw structure
385 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000388 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000389static void i40e_get_settings_link_up(struct i40e_hw *hw,
390 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400391 struct net_device *netdev,
392 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000393{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000394 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000395 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700396 u32 e_advertising = 0x0;
397 u32 e_supported = 0x0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000398
Catherine Sullivane8278452015-02-06 08:52:08 +0000399 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000400 switch (hw_link_info->phy_type) {
401 case I40E_PHY_TYPE_40GBASE_CR4:
402 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000403 ecmd->supported = SUPPORTED_Autoneg |
404 SUPPORTED_40000baseCR4_Full;
405 ecmd->advertising = ADVERTISED_Autoneg |
406 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000407 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000408 case I40E_PHY_TYPE_XLAUI:
409 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000410 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000411 ecmd->supported = SUPPORTED_40000baseCR4_Full;
412 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000413 case I40E_PHY_TYPE_40GBASE_SR4:
414 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000415 break;
416 case I40E_PHY_TYPE_40GBASE_LR4:
417 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000418 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000419 case I40E_PHY_TYPE_10GBASE_SR:
420 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000421 case I40E_PHY_TYPE_1000BASE_SX:
422 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400423 ecmd->supported = SUPPORTED_10000baseT_Full;
424 if (hw_link_info->module_type[2] &
425 I40E_MODULE_TYPE_1000BASE_SX ||
426 hw_link_info->module_type[2] &
427 I40E_MODULE_TYPE_1000BASE_LX) {
428 ecmd->supported |= SUPPORTED_1000baseT_Full;
429 if (hw_link_info->requested_speeds &
430 I40E_LINK_SPEED_1GB)
431 ecmd->advertising |= ADVERTISED_1000baseT_Full;
432 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000433 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
434 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000435 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000436 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000437 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700438 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000439 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000440 SUPPORTED_10000baseT_Full |
Catherine Sullivan06566e52016-05-03 15:13:14 -0700441 SUPPORTED_1000baseT_Full |
442 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000443 ecmd->advertising = ADVERTISED_Autoneg;
444 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
445 ecmd->advertising |= ADVERTISED_10000baseT_Full;
446 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
447 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700448 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
449 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400450 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400451 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
452 ecmd->supported = SUPPORTED_Autoneg |
453 SUPPORTED_1000baseT_Full;
454 ecmd->advertising = ADVERTISED_Autoneg |
455 ADVERTISED_1000baseT_Full;
456 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000457 case I40E_PHY_TYPE_10GBASE_CR1_CU:
458 case I40E_PHY_TYPE_10GBASE_CR1:
459 ecmd->supported = SUPPORTED_Autoneg |
460 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000461 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000462 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000463 break;
464 case I40E_PHY_TYPE_XAUI:
465 case I40E_PHY_TYPE_XFI:
466 case I40E_PHY_TYPE_SFI:
467 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000468 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000469 ecmd->supported = SUPPORTED_10000baseT_Full;
Stefan Assmann91698272016-06-27 15:03:43 +0200470 ecmd->advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000471 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000472 case I40E_PHY_TYPE_SGMII:
473 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400474 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000475 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
476 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800477 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400478 ecmd->supported |= SUPPORTED_100baseT_Full;
479 if (hw_link_info->requested_speeds &
480 I40E_LINK_SPEED_100MB)
481 ecmd->advertising |= ADVERTISED_100baseT_Full;
482 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400484 case I40E_PHY_TYPE_40GBASE_KR4:
485 case I40E_PHY_TYPE_20GBASE_KR2:
486 case I40E_PHY_TYPE_10GBASE_KR:
487 case I40E_PHY_TYPE_10GBASE_KX4:
488 case I40E_PHY_TYPE_1000BASE_KX:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700489 ecmd->supported |= SUPPORTED_40000baseKR4_Full |
490 SUPPORTED_20000baseKR2_Full |
491 SUPPORTED_10000baseKR_Full |
492 SUPPORTED_10000baseKX4_Full |
493 SUPPORTED_1000baseKX_Full |
494 SUPPORTED_Autoneg;
495 ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
496 ADVERTISED_20000baseKR2_Full |
497 ADVERTISED_10000baseKR_Full |
498 ADVERTISED_10000baseKX4_Full |
499 ADVERTISED_1000baseKX_Full |
500 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400501 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800502 case I40E_PHY_TYPE_25GBASE_KR:
503 case I40E_PHY_TYPE_25GBASE_CR:
504 case I40E_PHY_TYPE_25GBASE_SR:
505 case I40E_PHY_TYPE_25GBASE_LR:
506 ecmd->supported = SUPPORTED_Autoneg;
507 ecmd->advertising = ADVERTISED_Autoneg;
508 /* TODO: add speeds when ethtool is ready to support*/
509 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000510 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000511 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000512 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
513 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000514 }
515
Catherine Sullivan06566e52016-05-03 15:13:14 -0700516 /* Now that we've worked out everything that could be supported by the
517 * current PHY type, get what is supported by the NVM and them to
518 * get what is truly supported
519 */
520 i40e_phy_type_to_ethtool(pf, &e_supported,
521 &e_advertising);
522
523 ecmd->supported = ecmd->supported & e_supported;
524 ecmd->advertising = ecmd->advertising & e_advertising;
525
Catherine Sullivane8278452015-02-06 08:52:08 +0000526 /* Set speed and duplex */
527 switch (link_speed) {
528 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400529 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000530 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800531 case I40E_LINK_SPEED_25GB:
532#ifdef SPEED_25000
533 ethtool_cmd_speed_set(ecmd, SPEED_25000);
534#else
535 netdev_info(netdev,
536 "Speed is 25G, display not supported by this version of ethtool.\n");
537#endif
538 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700539 case I40E_LINK_SPEED_20GB:
540 ethtool_cmd_speed_set(ecmd, SPEED_20000);
541 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000542 case I40E_LINK_SPEED_10GB:
543 ethtool_cmd_speed_set(ecmd, SPEED_10000);
544 break;
545 case I40E_LINK_SPEED_1GB:
546 ethtool_cmd_speed_set(ecmd, SPEED_1000);
547 break;
548 case I40E_LINK_SPEED_100MB:
549 ethtool_cmd_speed_set(ecmd, SPEED_100);
550 break;
551 default:
552 break;
553 }
554 ecmd->duplex = DUPLEX_FULL;
555}
556
557/**
558 * i40e_get_settings_link_down - Get the Link settings for when link is down
559 * @hw: hw structure
560 * @ecmd: ethtool command to fill in
561 *
562 * Reports link settings that can be determined when link is down
563 **/
564static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400565 struct ethtool_cmd *ecmd,
566 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000567{
Catherine Sullivane8278452015-02-06 08:52:08 +0000568 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400569 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000570 */
Catherine Sullivan06566e52016-05-03 15:13:14 -0700571 i40e_phy_type_to_ethtool(pf, &ecmd->supported,
572 &ecmd->advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000573
574 /* With no link speed and duplex are unknown */
575 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
576 ecmd->duplex = DUPLEX_UNKNOWN;
577}
578
579/**
580 * i40e_get_settings - Get Link Speed and Duplex settings
581 * @netdev: network interface device structure
582 * @ecmd: ethtool command
583 *
584 * Reports speed/duplex settings based on media_type
585 **/
586static int i40e_get_settings(struct net_device *netdev,
587 struct ethtool_cmd *ecmd)
588{
589 struct i40e_netdev_priv *np = netdev_priv(netdev);
590 struct i40e_pf *pf = np->vsi->back;
591 struct i40e_hw *hw = &pf->hw;
592 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
593 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
594
595 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400596 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000597 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400598 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000599
600 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000601 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000602 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
603 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000604
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000605 switch (hw->phy.media_type) {
606 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000607 ecmd->supported |= SUPPORTED_Autoneg |
608 SUPPORTED_Backplane;
609 ecmd->advertising |= ADVERTISED_Autoneg |
610 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000611 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000612 break;
613 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000614 ecmd->supported |= SUPPORTED_TP;
615 ecmd->advertising |= ADVERTISED_TP;
616 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000617 break;
618 case I40E_MEDIA_TYPE_DA:
619 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000620 ecmd->supported |= SUPPORTED_FIBRE;
621 ecmd->advertising |= ADVERTISED_FIBRE;
622 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000623 break;
624 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000625 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000626 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000627 break;
628 case I40E_MEDIA_TYPE_UNKNOWN:
629 default:
630 ecmd->port = PORT_OTHER;
631 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000632 }
633
Catherine Sullivane8278452015-02-06 08:52:08 +0000634 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000635 ecmd->transceiver = XCVR_EXTERNAL;
636
Catherine Sullivane8278452015-02-06 08:52:08 +0000637 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000638 ecmd->supported |= SUPPORTED_Pause;
639
Catherine Sullivane8278452015-02-06 08:52:08 +0000640 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000641 case I40E_FC_FULL:
642 ecmd->advertising |= ADVERTISED_Pause;
643 break;
644 case I40E_FC_TX_PAUSE:
645 ecmd->advertising |= ADVERTISED_Asym_Pause;
646 break;
647 case I40E_FC_RX_PAUSE:
648 ecmd->advertising |= (ADVERTISED_Pause |
649 ADVERTISED_Asym_Pause);
650 break;
651 default:
652 ecmd->advertising &= ~(ADVERTISED_Pause |
653 ADVERTISED_Asym_Pause);
654 break;
655 }
656
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000657 return 0;
658}
659
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000660/**
661 * i40e_set_settings - Set Speed and Duplex
662 * @netdev: network interface device structure
663 * @ecmd: ethtool command
664 *
665 * Set speed/duplex per media_types advertised/forced
666 **/
667static int i40e_set_settings(struct net_device *netdev,
668 struct ethtool_cmd *ecmd)
669{
670 struct i40e_netdev_priv *np = netdev_priv(netdev);
671 struct i40e_aq_get_phy_abilities_resp abilities;
672 struct i40e_aq_set_phy_config config;
673 struct i40e_pf *pf = np->vsi->back;
674 struct i40e_vsi *vsi = np->vsi;
675 struct i40e_hw *hw = &pf->hw;
676 struct ethtool_cmd safe_ecmd;
677 i40e_status status = 0;
678 bool change = false;
679 int err = 0;
680 u8 autoneg;
681 u32 advertise;
682
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000683 /* Changing port settings is not supported if this isn't the
684 * port's controlling PF
685 */
686 if (hw->partition_id != 1) {
687 i40e_partition_setting_complaint(pf);
688 return -EOPNOTSUPP;
689 }
690
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000691 if (vsi != pf->vsi[pf->lan_vsi])
692 return -EOPNOTSUPP;
693
694 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
695 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000696 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700697 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000698 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000699 return -EOPNOTSUPP;
700
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400701 if (hw->device_id == I40E_DEV_ID_KX_B ||
702 hw->device_id == I40E_DEV_ID_KX_C ||
703 hw->device_id == I40E_DEV_ID_20G_KR2 ||
704 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
705 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
706 return -EOPNOTSUPP;
707 }
708
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000709 /* get our own copy of the bits to check against */
710 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
711 i40e_get_settings(netdev, &safe_ecmd);
712
713 /* save autoneg and speed out of ecmd */
714 autoneg = ecmd->autoneg;
715 advertise = ecmd->advertising;
716
717 /* set autoneg and speed back to what they currently are */
718 ecmd->autoneg = safe_ecmd.autoneg;
719 ecmd->advertising = safe_ecmd.advertising;
720
721 ecmd->cmd = safe_ecmd.cmd;
722 /* If ecmd and safe_ecmd are not the same now, then they are
723 * trying to set something that we do not support
724 */
725 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
726 return -EOPNOTSUPP;
727
728 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
729 usleep_range(1000, 2000);
730
731 /* Get the current phy config */
732 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
733 NULL);
734 if (status)
735 return -EAGAIN;
736
Catherine Sullivan124ed152014-07-12 07:28:12 +0000737 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000738 * set below
739 */
740 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000741 config.abilities = abilities.abilities;
742
743 /* Check autoneg */
744 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000745 /* If autoneg was not already enabled */
746 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400747 /* If autoneg is not supported, return error */
748 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
749 netdev_info(netdev, "Autoneg not supported on this phy\n");
750 return -EINVAL;
751 }
752 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000753 config.abilities = abilities.abilities |
754 I40E_AQ_PHY_ENABLE_AN;
755 change = true;
756 }
757 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000758 /* If autoneg is currently enabled */
759 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400760 /* If autoneg is supported 10GBASE_T is the only PHY
761 * that can disable it, so otherwise return error
762 */
763 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
764 hw->phy.link_info.phy_type !=
765 I40E_PHY_TYPE_10GBASE_T) {
766 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
767 return -EINVAL;
768 }
769 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000770 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000771 ~I40E_AQ_PHY_ENABLE_AN;
772 change = true;
773 }
774 }
775
776 if (advertise & ~safe_ecmd.supported)
777 return -EINVAL;
778
779 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000780 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000781 if (advertise & ADVERTISED_1000baseT_Full ||
782 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000783 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000784 if (advertise & ADVERTISED_10000baseT_Full ||
785 advertise & ADVERTISED_10000baseKX4_Full ||
786 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000787 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700788 if (advertise & ADVERTISED_20000baseKR2_Full)
789 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000790 if (advertise & ADVERTISED_40000baseKR4_Full ||
791 advertise & ADVERTISED_40000baseCR4_Full ||
792 advertise & ADVERTISED_40000baseSR4_Full ||
793 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000794 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000795
Catherine Sullivan0002e112015-08-26 15:14:16 -0400796 /* If speed didn't get set, set it to what it currently is.
797 * This is needed because if advertise is 0 (as it is when autoneg
798 * is disabled) then speed won't get set.
799 */
800 if (!config.link_speed)
801 config.link_speed = abilities.link_speed;
802
Catherine Sullivan124ed152014-07-12 07:28:12 +0000803 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000804 /* copy over the rest of the abilities */
805 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800806 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000807 config.eee_capability = abilities.eee_capability;
808 config.eeer = abilities.eeer_val;
809 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800810 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
811 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000812
Catherine Sullivane8278452015-02-06 08:52:08 +0000813 /* save the requested speeds */
814 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000815 /* set link and auto negotiation so changes take effect */
816 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
817 /* If link is up put link down */
818 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
819 /* Tell the OS link is going down, the link will go
820 * back up when fw says it is ready asynchronously
821 */
Matt Jaredc156f852015-08-27 11:42:39 -0400822 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000823 netif_carrier_off(netdev);
824 netif_tx_stop_all_queues(netdev);
825 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000826
827 /* make the aq call */
828 status = i40e_aq_set_phy_config(hw, &config, NULL);
829 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400830 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
831 i40e_stat_str(hw, status),
832 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000833 return -EAGAIN;
834 }
835
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400836 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000837 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400838 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
839 i40e_stat_str(hw, status),
840 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000841
842 } else {
843 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
844 }
845
846 return err;
847}
848
Jesse Brandeburga6599722014-06-04 08:45:25 +0000849static int i40e_nway_reset(struct net_device *netdev)
850{
851 /* restart autonegotiation */
852 struct i40e_netdev_priv *np = netdev_priv(netdev);
853 struct i40e_pf *pf = np->vsi->back;
854 struct i40e_hw *hw = &pf->hw;
855 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
856 i40e_status ret = 0;
857
858 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
859 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400860 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
861 i40e_stat_str(hw, ret),
862 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000863 return -EIO;
864 }
865
866 return 0;
867}
868
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000869/**
870 * i40e_get_pauseparam - Get Flow Control status
871 * Return tx/rx-pause status
872 **/
873static void i40e_get_pauseparam(struct net_device *netdev,
874 struct ethtool_pauseparam *pause)
875{
876 struct i40e_netdev_priv *np = netdev_priv(netdev);
877 struct i40e_pf *pf = np->vsi->back;
878 struct i40e_hw *hw = &pf->hw;
879 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000880 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000881
882 pause->autoneg =
883 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
884 AUTONEG_ENABLE : AUTONEG_DISABLE);
885
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000886 /* PFC enabled so report LFC as off */
887 if (dcbx_cfg->pfc.pfcenable) {
888 pause->rx_pause = 0;
889 pause->tx_pause = 0;
890 return;
891 }
892
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000893 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000894 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000895 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000896 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000897 } else if (hw->fc.current_mode == I40E_FC_FULL) {
898 pause->rx_pause = 1;
899 pause->tx_pause = 1;
900 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000901}
902
Catherine Sullivan2becc352014-06-04 08:45:27 +0000903/**
904 * i40e_set_pauseparam - Set Flow Control parameter
905 * @netdev: network interface device structure
906 * @pause: return tx/rx flow control status
907 **/
908static int i40e_set_pauseparam(struct net_device *netdev,
909 struct ethtool_pauseparam *pause)
910{
911 struct i40e_netdev_priv *np = netdev_priv(netdev);
912 struct i40e_pf *pf = np->vsi->back;
913 struct i40e_vsi *vsi = np->vsi;
914 struct i40e_hw *hw = &pf->hw;
915 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000916 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000917 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
918 i40e_status status;
919 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000920 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000921
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000922 /* Changing the port's flow control is not supported if this isn't the
923 * port's controlling PF
924 */
925 if (hw->partition_id != 1) {
926 i40e_partition_setting_complaint(pf);
927 return -EOPNOTSUPP;
928 }
929
Catherine Sullivan2becc352014-06-04 08:45:27 +0000930 if (vsi != pf->vsi[pf->lan_vsi])
931 return -EOPNOTSUPP;
932
933 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
934 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
935 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
936 return -EOPNOTSUPP;
937 }
938
939 /* If we have link and don't have autoneg */
940 if (!test_bit(__I40E_DOWN, &pf->state) &&
941 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
942 /* Send message that it might not necessarily work*/
943 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
944 }
945
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000946 if (dcbx_cfg->pfc.pfcenable) {
947 netdev_info(netdev,
948 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000949 return -EOPNOTSUPP;
950 }
951
952 if (pause->rx_pause && pause->tx_pause)
953 hw->fc.requested_mode = I40E_FC_FULL;
954 else if (pause->rx_pause && !pause->tx_pause)
955 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
956 else if (!pause->rx_pause && pause->tx_pause)
957 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
958 else if (!pause->rx_pause && !pause->tx_pause)
959 hw->fc.requested_mode = I40E_FC_NONE;
960 else
961 return -EINVAL;
962
Catherine Sullivan94128512014-07-12 07:28:16 +0000963 /* Tell the OS link is going down, the link will go back up when fw
964 * says it is ready asynchronously
965 */
Matt Jaredc156f852015-08-27 11:42:39 -0400966 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000967 netif_carrier_off(netdev);
968 netif_tx_stop_all_queues(netdev);
969
Catherine Sullivan2becc352014-06-04 08:45:27 +0000970 /* Set the fc mode and only restart an if link is up*/
971 status = i40e_set_fc(hw, &aq_failures, link_up);
972
973 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400974 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
975 i40e_stat_str(hw, status),
976 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000977 err = -EAGAIN;
978 }
979 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400980 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
981 i40e_stat_str(hw, status),
982 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000983 err = -EAGAIN;
984 }
985 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400986 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
987 i40e_stat_str(hw, status),
988 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000989 err = -EAGAIN;
990 }
991
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000992 if (!test_bit(__I40E_DOWN, &pf->state)) {
993 /* Give it a little more time to try to come back */
994 msleep(75);
995 if (!test_bit(__I40E_DOWN, &pf->state))
996 return i40e_nway_reset(netdev);
997 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000998
999 return err;
1000}
1001
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001002static u32 i40e_get_msglevel(struct net_device *netdev)
1003{
1004 struct i40e_netdev_priv *np = netdev_priv(netdev);
1005 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001006 u32 debug_mask = pf->hw.debug_mask;
1007
1008 if (debug_mask)
1009 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001010
1011 return pf->msg_enable;
1012}
1013
1014static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1015{
1016 struct i40e_netdev_priv *np = netdev_priv(netdev);
1017 struct i40e_pf *pf = np->vsi->back;
1018
1019 if (I40E_DEBUG_USER & data)
1020 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001021 else
1022 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023}
1024
1025static int i40e_get_regs_len(struct net_device *netdev)
1026{
1027 int reg_count = 0;
1028 int i;
1029
1030 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1031 reg_count += i40e_reg_list[i].elements;
1032
1033 return reg_count * sizeof(u32);
1034}
1035
1036static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1037 void *p)
1038{
1039 struct i40e_netdev_priv *np = netdev_priv(netdev);
1040 struct i40e_pf *pf = np->vsi->back;
1041 struct i40e_hw *hw = &pf->hw;
1042 u32 *reg_buf = p;
1043 int i, j, ri;
1044 u32 reg;
1045
1046 /* Tell ethtool which driver-version-specific regs output we have.
1047 *
1048 * At some point, if we have ethtool doing special formatting of
1049 * this data, it will rely on this version number to know how to
1050 * interpret things. Hence, this needs to be updated if/when the
1051 * diags register table is changed.
1052 */
1053 regs->version = 1;
1054
1055 /* loop through the diags reg table for what to print */
1056 ri = 0;
1057 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1058 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1059 reg = i40e_reg_list[i].offset
1060 + (j * i40e_reg_list[i].stride);
1061 reg_buf[ri++] = rd32(hw, reg);
1062 }
1063 }
1064
1065}
1066
1067static int i40e_get_eeprom(struct net_device *netdev,
1068 struct ethtool_eeprom *eeprom, u8 *bytes)
1069{
1070 struct i40e_netdev_priv *np = netdev_priv(netdev);
1071 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001072 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001073 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001074 u8 *eeprom_buff;
1075 u16 i, sectors;
1076 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001077 u32 magic;
1078
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001079#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001080 if (eeprom->len == 0)
1081 return -EINVAL;
1082
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001083 /* check for NVMUpdate access method */
1084 magic = hw->vendor_id | (hw->device_id << 16);
1085 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001086 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1087 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001088
1089 /* make sure it is the right magic for NVMUpdate */
1090 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001091 errno = -EINVAL;
1092 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1093 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1094 errno = -EBUSY;
1095 else
1096 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001097
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001098 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001099 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001100 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1101 ret_val, hw->aq.asq_last_status, errno,
1102 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1103 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001104
1105 return errno;
1106 }
1107
1108 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001109 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1110
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001111 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001112 if (!eeprom_buff)
1113 return -ENOMEM;
1114
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001115 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1116 if (ret_val) {
1117 dev_info(&pf->pdev->dev,
1118 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1119 ret_val, hw->aq.asq_last_status);
1120 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001121 }
1122
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001123 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1124 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1125 len = I40E_NVM_SECTOR_SIZE;
1126 last = false;
1127 for (i = 0; i < sectors; i++) {
1128 if (i == (sectors - 1)) {
1129 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1130 last = true;
1131 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001132 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1133 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001134 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001135 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001136 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001137 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001138 "read NVM failed, invalid offset 0x%x\n",
1139 offset);
1140 break;
1141 } else if (ret_val &&
1142 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1143 dev_info(&pf->pdev->dev,
1144 "read NVM failed, access, offset 0x%x\n",
1145 offset);
1146 break;
1147 } else if (ret_val) {
1148 dev_info(&pf->pdev->dev,
1149 "read NVM failed offset %d err=%d status=0x%x\n",
1150 offset, ret_val, hw->aq.asq_last_status);
1151 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001152 }
1153 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001154
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001155 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001156 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001157free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001158 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001159 return ret_val;
1160}
1161
1162static int i40e_get_eeprom_len(struct net_device *netdev)
1163{
1164 struct i40e_netdev_priv *np = netdev_priv(netdev);
1165 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001166 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001167
Lihong Yangc271dd62017-01-30 12:29:32 -08001168#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1169 if (hw->mac.type == I40E_MAC_X722) {
1170 val = X722_EEPROM_SCOPE_LIMIT + 1;
1171 return val;
1172 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001173 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1174 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1175 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1176 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001177 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001178 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001179}
1180
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001181static int i40e_set_eeprom(struct net_device *netdev,
1182 struct ethtool_eeprom *eeprom, u8 *bytes)
1183{
1184 struct i40e_netdev_priv *np = netdev_priv(netdev);
1185 struct i40e_hw *hw = &np->vsi->back->hw;
1186 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001187 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001188 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001189 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001190 u32 magic;
1191
1192 /* normal ethtool set_eeprom is not supported */
1193 magic = hw->vendor_id | (hw->device_id << 16);
1194 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001195 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001196 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001197 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1198 errno = -EINVAL;
1199 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1200 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1201 errno = -EBUSY;
1202 else
1203 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001204
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001205 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001206 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001207 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1208 ret_val, hw->aq.asq_last_status, errno,
1209 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1210 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001211
1212 return errno;
1213}
1214
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001215static void i40e_get_drvinfo(struct net_device *netdev,
1216 struct ethtool_drvinfo *drvinfo)
1217{
1218 struct i40e_netdev_priv *np = netdev_priv(netdev);
1219 struct i40e_vsi *vsi = np->vsi;
1220 struct i40e_pf *pf = vsi->back;
1221
1222 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1223 strlcpy(drvinfo->version, i40e_driver_version_str,
1224 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001225 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001226 sizeof(drvinfo->fw_version));
1227 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1228 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001229 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001230 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001231 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232}
1233
1234static void i40e_get_ringparam(struct net_device *netdev,
1235 struct ethtool_ringparam *ring)
1236{
1237 struct i40e_netdev_priv *np = netdev_priv(netdev);
1238 struct i40e_pf *pf = np->vsi->back;
1239 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1240
1241 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1242 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1243 ring->rx_mini_max_pending = 0;
1244 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001245 ring->rx_pending = vsi->rx_rings[0]->count;
1246 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001247 ring->rx_mini_pending = 0;
1248 ring->rx_jumbo_pending = 0;
1249}
1250
1251static int i40e_set_ringparam(struct net_device *netdev,
1252 struct ethtool_ringparam *ring)
1253{
1254 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1255 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001256 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001257 struct i40e_vsi *vsi = np->vsi;
1258 struct i40e_pf *pf = vsi->back;
1259 u32 new_rx_count, new_tx_count;
1260 int i, err = 0;
1261
1262 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1263 return -EINVAL;
1264
Shannon Nelson1fa18372013-11-20 10:03:08 +00001265 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1266 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1267 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1268 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1269 netdev_info(netdev,
1270 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1271 ring->tx_pending, ring->rx_pending,
1272 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1273 return -EINVAL;
1274 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001275
Shannon Nelson1fa18372013-11-20 10:03:08 +00001276 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1277 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001278
1279 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001280 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1281 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001282 return 0;
1283
1284 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1285 usleep_range(1000, 2000);
1286
1287 if (!netif_running(vsi->netdev)) {
1288 /* simple case - set for the next time the netdev is started */
1289 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001290 vsi->tx_rings[i]->count = new_tx_count;
1291 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001292 }
1293 goto done;
1294 }
1295
1296 /* We can't just free everything and then setup again,
1297 * because the ISRs in MSI-X mode get passed pointers
1298 * to the Tx and Rx ring structs.
1299 */
1300
1301 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001302 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001303 netdev_info(netdev,
1304 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001305 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001306 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1307 sizeof(struct i40e_ring), GFP_KERNEL);
1308 if (!tx_rings) {
1309 err = -ENOMEM;
1310 goto done;
1311 }
1312
1313 for (i = 0; i < vsi->num_queue_pairs; i++) {
1314 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001315 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001316 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001317 /* the desc and bi pointers will be reallocated in the
1318 * setup call
1319 */
1320 tx_rings[i].desc = NULL;
1321 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001322 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1323 if (err) {
1324 while (i) {
1325 i--;
1326 i40e_free_tx_resources(&tx_rings[i]);
1327 }
1328 kfree(tx_rings);
1329 tx_rings = NULL;
1330
1331 goto done;
1332 }
1333 }
1334 }
1335
1336 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001337 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001338 netdev_info(netdev,
1339 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001340 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1342 sizeof(struct i40e_ring), GFP_KERNEL);
1343 if (!rx_rings) {
1344 err = -ENOMEM;
1345 goto free_tx;
1346 }
1347
1348 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001349 struct i40e_ring *ring;
1350 u16 unused;
1351
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001352 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001353 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001354 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001355 /* the desc and bi pointers will be reallocated in the
1356 * setup call
1357 */
1358 rx_rings[i].desc = NULL;
1359 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001360 /* this is to allow wr32 to have something to write to
1361 * during early allocation of Rx buffers
1362 */
1363 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001365 if (err)
1366 goto rx_unwind;
1367
1368 /* now allocate the Rx buffers to make sure the OS
1369 * has enough memory, any failure here means abort
1370 */
1371 ring = &rx_rings[i];
1372 unused = I40E_DESC_UNUSED(ring);
1373 err = i40e_alloc_rx_buffers(ring, unused);
1374rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001375 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001376 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001377 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001378 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379 kfree(rx_rings);
1380 rx_rings = NULL;
1381
1382 goto free_tx;
1383 }
1384 }
1385 }
1386
1387 /* Bring interface down, copy in the new ring info,
1388 * then restore the interface
1389 */
1390 i40e_down(vsi);
1391
1392 if (tx_rings) {
1393 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001394 i40e_free_tx_resources(vsi->tx_rings[i]);
1395 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001396 }
1397 kfree(tx_rings);
1398 tx_rings = NULL;
1399 }
1400
1401 if (rx_rings) {
1402 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001403 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001404 /* get the real tail offset */
1405 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1406 /* this is to fake out the allocation routine
1407 * into thinking it has to realloc everything
1408 * but the recycling logic will let us re-use
1409 * the buffers allocated above
1410 */
1411 rx_rings[i].next_to_use = 0;
1412 rx_rings[i].next_to_clean = 0;
1413 rx_rings[i].next_to_alloc = 0;
1414 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001415 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001416 }
1417 kfree(rx_rings);
1418 rx_rings = NULL;
1419 }
1420
1421 i40e_up(vsi);
1422
1423free_tx:
1424 /* error cleanup if the Rx allocations failed after getting Tx */
1425 if (tx_rings) {
1426 for (i = 0; i < vsi->num_queue_pairs; i++)
1427 i40e_free_tx_resources(&tx_rings[i]);
1428 kfree(tx_rings);
1429 tx_rings = NULL;
1430 }
1431
1432done:
1433 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1434
1435 return err;
1436}
1437
1438static int i40e_get_sset_count(struct net_device *netdev, int sset)
1439{
1440 struct i40e_netdev_priv *np = netdev_priv(netdev);
1441 struct i40e_vsi *vsi = np->vsi;
1442 struct i40e_pf *pf = vsi->back;
1443
1444 switch (sset) {
1445 case ETH_SS_TEST:
1446 return I40E_TEST_LEN;
1447 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001448 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001449 int len = I40E_PF_STATS_LEN(netdev);
1450
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001451 if ((pf->lan_veb != I40E_NO_VEB) &&
1452 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001453 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001454 return len;
1455 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001457 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001458 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001459 return I40E_PRIV_FLAGS_STR_LEN +
1460 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001461 default:
1462 return -EOPNOTSUPP;
1463 }
1464}
1465
1466static void i40e_get_ethtool_stats(struct net_device *netdev,
1467 struct ethtool_stats *stats, u64 *data)
1468{
1469 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001470 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001471 struct i40e_vsi *vsi = np->vsi;
1472 struct i40e_pf *pf = vsi->back;
1473 int i = 0;
1474 char *p;
1475 int j;
1476 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001477 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478
1479 i40e_update_stats(vsi);
1480
1481 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1482 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1483 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1484 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1485 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001486 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1487 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1488 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1489 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1490 }
Vasu Dev38e00432014-08-01 13:27:03 -07001491#ifdef I40E_FCOE
1492 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1493 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1494 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1495 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1496 }
1497#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001498 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001499 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001500 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001501
1502 if (!tx_ring)
1503 continue;
1504
1505 /* process Tx ring statistics */
1506 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001507 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001508 data[i] = tx_ring->stats.packets;
1509 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001510 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001511 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001512
1513 /* Rx ring is the 2nd half of the queue pair */
1514 rx_ring = &tx_ring[1];
1515 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001516 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001517 data[i] = rx_ring->stats.packets;
1518 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001519 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001520 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001521 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001522 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001523 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001524 return;
1525
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001526 if ((pf->lan_veb != I40E_NO_VEB) &&
1527 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001528 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001529
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001530 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1531 p = (char *)veb;
1532 p += i40e_gstrings_veb_stats[j].stat_offset;
1533 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1534 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001535 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001536 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1537 data[i++] = veb->tc_stats.tc_tx_packets[j];
1538 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1539 data[i++] = veb->tc_stats.tc_rx_packets[j];
1540 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1541 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001542 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001543 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1544 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1545 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1546 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1547 }
1548 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1549 data[i++] = pf->stats.priority_xon_tx[j];
1550 data[i++] = pf->stats.priority_xoff_tx[j];
1551 }
1552 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1553 data[i++] = pf->stats.priority_xon_rx[j];
1554 data[i++] = pf->stats.priority_xoff_rx[j];
1555 }
1556 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1557 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558}
1559
1560static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1561 u8 *data)
1562{
1563 struct i40e_netdev_priv *np = netdev_priv(netdev);
1564 struct i40e_vsi *vsi = np->vsi;
1565 struct i40e_pf *pf = vsi->back;
1566 char *p = (char *)data;
1567 int i;
1568
1569 switch (stringset) {
1570 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001571 memcpy(data, i40e_gstrings_test,
1572 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573 break;
1574 case ETH_SS_STATS:
1575 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1576 snprintf(p, ETH_GSTRING_LEN, "%s",
1577 i40e_gstrings_net_stats[i].stat_string);
1578 p += ETH_GSTRING_LEN;
1579 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001580 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1581 snprintf(p, ETH_GSTRING_LEN, "%s",
1582 i40e_gstrings_misc_stats[i].stat_string);
1583 p += ETH_GSTRING_LEN;
1584 }
Vasu Dev38e00432014-08-01 13:27:03 -07001585#ifdef I40E_FCOE
1586 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1587 snprintf(p, ETH_GSTRING_LEN, "%s",
1588 i40e_gstrings_fcoe_stats[i].stat_string);
1589 p += ETH_GSTRING_LEN;
1590 }
1591#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001592 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001593 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001595 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001597 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001598 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001599 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 p += ETH_GSTRING_LEN;
1601 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001602 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001603 return;
1604
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001605 if ((pf->lan_veb != I40E_NO_VEB) &&
1606 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001607 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1608 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1609 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001610 p += ETH_GSTRING_LEN;
1611 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001612 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1613 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001614 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001615 p += ETH_GSTRING_LEN;
1616 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001617 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001618 p += ETH_GSTRING_LEN;
1619 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001620 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001621 p += ETH_GSTRING_LEN;
1622 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001623 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001624 p += ETH_GSTRING_LEN;
1625 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001626 }
1627 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1628 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1629 i40e_gstrings_stats[i].stat_string);
1630 p += ETH_GSTRING_LEN;
1631 }
1632 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1633 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001634 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001635 p += ETH_GSTRING_LEN;
1636 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001637 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001638 p += ETH_GSTRING_LEN;
1639 }
1640 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1641 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001642 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001643 p += ETH_GSTRING_LEN;
1644 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001645 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001646 p += ETH_GSTRING_LEN;
1647 }
1648 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1649 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001650 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001651 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652 }
1653 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1654 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001655 case ETH_SS_PRIV_FLAGS:
Jacob Kellere5d32202016-11-08 13:05:11 -08001656 memcpy(data, i40e_priv_flags_strings,
1657 I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
1658 data += I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN;
1659 if (pf->hw.pf_id == 0)
1660 memcpy(data, i40e_gl_priv_flags_strings,
1661 I40E_GL_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
Greg Rose7e45ab42015-02-06 08:52:19 +00001662 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001663 default:
1664 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001665 }
1666}
1667
1668static int i40e_get_ts_info(struct net_device *dev,
1669 struct ethtool_ts_info *info)
1670{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001671 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1672
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001673 /* only report HW timestamping if PTP is enabled */
1674 if (!(pf->flags & I40E_FLAG_PTP))
1675 return ethtool_op_get_ts_info(dev, info);
1676
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001677 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1678 SOF_TIMESTAMPING_RX_SOFTWARE |
1679 SOF_TIMESTAMPING_SOFTWARE |
1680 SOF_TIMESTAMPING_TX_HARDWARE |
1681 SOF_TIMESTAMPING_RX_HARDWARE |
1682 SOF_TIMESTAMPING_RAW_HARDWARE;
1683
1684 if (pf->ptp_clock)
1685 info->phc_index = ptp_clock_index(pf->ptp_clock);
1686 else
1687 info->phc_index = -1;
1688
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001689 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001690
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001691 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001692 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1693 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1694 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1695
1696 if (pf->flags & I40E_FLAG_PTP_L4_CAPABLE)
1697 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1698 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1699 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1700 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1701 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1702 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1703 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1704 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001705
1706 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001707}
1708
Shannon Nelson7b086392013-11-20 10:02:59 +00001709static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001710{
Shannon Nelson7b086392013-11-20 10:02:59 +00001711 struct i40e_netdev_priv *np = netdev_priv(netdev);
1712 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001713 i40e_status status;
1714 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001715
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001716 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001717 status = i40e_get_link_status(&pf->hw, &link_up);
1718 if (status) {
1719 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1720 *data = 1;
1721 return *data;
1722 }
1723
1724 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001725 *data = 0;
1726 else
1727 *data = 1;
1728
1729 return *data;
1730}
1731
Shannon Nelson7b086392013-11-20 10:02:59 +00001732static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733{
Shannon Nelson7b086392013-11-20 10:02:59 +00001734 struct i40e_netdev_priv *np = netdev_priv(netdev);
1735 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001736
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001737 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001738 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001739
Shannon Nelson7b086392013-11-20 10:02:59 +00001740 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741}
1742
Shannon Nelson7b086392013-11-20 10:02:59 +00001743static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001744{
Shannon Nelson7b086392013-11-20 10:02:59 +00001745 struct i40e_netdev_priv *np = netdev_priv(netdev);
1746 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001747
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001748 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001749 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001750
Shannon Nelson4443ec92014-11-13 08:23:12 +00001751 /* forcebly clear the NVM Update state machine */
1752 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1753
Shannon Nelson7b086392013-11-20 10:02:59 +00001754 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001755}
1756
Shannon Nelson7b086392013-11-20 10:02:59 +00001757static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001758{
Shannon Nelson7b086392013-11-20 10:02:59 +00001759 struct i40e_netdev_priv *np = netdev_priv(netdev);
1760 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001761 u16 swc_old = pf->sw_int_count;
1762
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001763 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001764 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1765 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001766 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1767 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1768 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1769 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001770 usleep_range(1000, 2000);
1771 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001772
1773 return *data;
1774}
1775
Greg Rosee17bc412015-04-16 20:05:59 -04001776static inline bool i40e_active_vfs(struct i40e_pf *pf)
1777{
1778 struct i40e_vf *vfs = pf->vf;
1779 int i;
1780
1781 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001782 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001783 return true;
1784 return false;
1785}
1786
Greg Rose510efb22015-07-10 19:36:01 -04001787static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1788{
Alexander Duyck4b816442016-10-11 15:26:53 -07001789 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001790}
1791
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001792static void i40e_diag_test(struct net_device *netdev,
1793 struct ethtool_test *eth_test, u64 *data)
1794{
1795 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001796 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797 struct i40e_pf *pf = np->vsi->back;
1798
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001799 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1800 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001801 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001802
Shannon Nelsonf551b432013-11-26 10:49:12 +00001803 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001804
Greg Rose510efb22015-07-10 19:36:01 -04001805 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001806 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001807 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001808 data[I40E_ETH_TEST_REG] = 1;
1809 data[I40E_ETH_TEST_EEPROM] = 1;
1810 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001811 data[I40E_ETH_TEST_LINK] = 1;
1812 eth_test->flags |= ETH_TEST_FL_FAILED;
1813 clear_bit(__I40E_TESTING, &pf->state);
1814 goto skip_ol_tests;
1815 }
1816
Greg Rose5b86c5c2015-02-26 16:14:35 +00001817 /* If the device is online then take it offline */
1818 if (if_running)
1819 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001820 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001821 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001822 /* This reset does not affect link - if it is
1823 * changed to a type of reset that does affect
1824 * link then the following link test would have
1825 * to be moved to before the reset
1826 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001827 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001828
Shannon Nelson7b086392013-11-20 10:02:59 +00001829 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001830 eth_test->flags |= ETH_TEST_FL_FAILED;
1831
Shannon Nelson7b086392013-11-20 10:02:59 +00001832 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001833 eth_test->flags |= ETH_TEST_FL_FAILED;
1834
Shannon Nelson7b086392013-11-20 10:02:59 +00001835 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001836 eth_test->flags |= ETH_TEST_FL_FAILED;
1837
Shannon Nelsonf551b432013-11-26 10:49:12 +00001838 /* run reg test last, a reset is required after it */
1839 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1840 eth_test->flags |= ETH_TEST_FL_FAILED;
1841
1842 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001843 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001844
1845 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001846 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001847 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001848 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001849 netif_info(pf, drv, netdev, "online testing starting\n");
1850
Shannon Nelson7b086392013-11-20 10:02:59 +00001851 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001852 eth_test->flags |= ETH_TEST_FL_FAILED;
1853
1854 /* Offline only tests, not run in online; pass by default */
1855 data[I40E_ETH_TEST_REG] = 0;
1856 data[I40E_ETH_TEST_EEPROM] = 0;
1857 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001858 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001859
Greg Rosee17bc412015-04-16 20:05:59 -04001860skip_ol_tests:
1861
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001862 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001863}
1864
1865static void i40e_get_wol(struct net_device *netdev,
1866 struct ethtool_wolinfo *wol)
1867{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001868 struct i40e_netdev_priv *np = netdev_priv(netdev);
1869 struct i40e_pf *pf = np->vsi->back;
1870 struct i40e_hw *hw = &pf->hw;
1871 u16 wol_nvm_bits;
1872
1873 /* NVM bit on means WoL disabled for the port */
1874 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001875 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001876 wol->supported = 0;
1877 wol->wolopts = 0;
1878 } else {
1879 wol->supported = WAKE_MAGIC;
1880 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1881 }
1882}
1883
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001884/**
1885 * i40e_set_wol - set the WakeOnLAN configuration
1886 * @netdev: the netdev in question
1887 * @wol: the ethtool WoL setting data
1888 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001889static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1890{
1891 struct i40e_netdev_priv *np = netdev_priv(netdev);
1892 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001893 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001894 struct i40e_hw *hw = &pf->hw;
1895 u16 wol_nvm_bits;
1896
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001897 /* WoL not supported if this isn't the controlling PF on the port */
1898 if (hw->partition_id != 1) {
1899 i40e_partition_setting_complaint(pf);
1900 return -EOPNOTSUPP;
1901 }
1902
1903 if (vsi != pf->vsi[pf->lan_vsi])
1904 return -EOPNOTSUPP;
1905
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001906 /* NVM bit on means WoL disabled for the port */
1907 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001908 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001909 return -EOPNOTSUPP;
1910
1911 /* only magic packet is supported */
1912 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1913 return -EOPNOTSUPP;
1914
1915 /* is this a new value? */
1916 if (pf->wol_en != !!wol->wolopts) {
1917 pf->wol_en = !!wol->wolopts;
1918 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1919 }
1920
1921 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001922}
1923
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001924static int i40e_set_phys_id(struct net_device *netdev,
1925 enum ethtool_phys_id_state state)
1926{
1927 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001928 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001929 struct i40e_pf *pf = np->vsi->back;
1930 struct i40e_hw *hw = &pf->hw;
1931 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001932 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001933
1934 switch (state) {
1935 case ETHTOOL_ID_ACTIVE:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001936 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001937 pf->led_status = i40e_led_get(hw);
1938 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001939 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001940 ret = i40e_led_get_phy(hw, &temp_status,
1941 &pf->phy_led_val);
1942 pf->led_status = temp_status;
1943 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001944 return blink_freq;
1945 case ETHTOOL_ID_ON:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001946 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001947 i40e_led_set(hw, 0xf, false);
1948 else
1949 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001950 break;
1951 case ETHTOOL_ID_OFF:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001952 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001953 i40e_led_set(hw, 0x0, false);
1954 else
1955 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001956 break;
1957 case ETHTOOL_ID_INACTIVE:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001958 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
1959 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001960 } else {
1961 ret = i40e_led_set_phy(hw, false, pf->led_status,
1962 (pf->phy_led_val |
1963 I40E_PHY_LED_MODE_ORIG));
1964 i40e_aq_set_phy_debug(hw, 0, NULL);
1965 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001966 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001967 default:
1968 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001969 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001970 if (ret)
1971 return -ENOENT;
1972 else
1973 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001974}
1975
1976/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1977 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1978 * 125us (8000 interrupts per second) == ITR(62)
1979 */
1980
Jacob Keller65e87c02016-09-12 14:18:44 -07001981/**
1982 * __i40e_get_coalesce - get per-queue coalesce settings
1983 * @netdev: the netdev to check
1984 * @ec: ethtool coalesce data structure
1985 * @queue: which queue to pick
1986 *
1987 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
1988 * are per queue. If queue is <0 then we default to queue 0 as the
1989 * representative value.
1990 **/
Kan Lianga75e8002016-02-19 09:24:04 -05001991static int __i40e_get_coalesce(struct net_device *netdev,
1992 struct ethtool_coalesce *ec,
1993 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001994{
1995 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07001996 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001997 struct i40e_vsi *vsi = np->vsi;
1998
1999 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2000 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2001
Kan Lianga75e8002016-02-19 09:24:04 -05002002 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2003 * return queue 0's value to represent.
2004 */
2005 if (queue < 0) {
2006 queue = 0;
2007 } else if (queue >= vsi->num_queue_pairs) {
2008 return -EINVAL;
2009 }
2010
Jacob Keller65e87c02016-09-12 14:18:44 -07002011 rx_ring = vsi->rx_rings[queue];
2012 tx_ring = vsi->tx_rings[queue];
2013
2014 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002015 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002016
Jacob Keller65e87c02016-09-12 14:18:44 -07002017 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002018 ec->use_adaptive_tx_coalesce = 1;
2019
Jacob Keller65e87c02016-09-12 14:18:44 -07002020 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2021 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2022
Kan Lianga75e8002016-02-19 09:24:04 -05002023
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002024 /* we use the _usecs_high to store/set the interrupt rate limit
2025 * that the hardware supports, that almost but not quite
2026 * fits the original intent of the ethtool variable,
2027 * the rx_coalesce_usecs_high limits total interrupts
2028 * per second from both tx/rx sources.
2029 */
2030 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2031 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002032
2033 return 0;
2034}
2035
Jacob Keller65e87c02016-09-12 14:18:44 -07002036/**
2037 * i40e_get_coalesce - get a netdev's coalesce settings
2038 * @netdev: the netdev to check
2039 * @ec: ethtool coalesce data structure
2040 *
2041 * Gets the coalesce settings for a particular netdev. Note that if user has
2042 * modified per-queue settings, this only guarantees to represent queue 0. See
2043 * __i40e_get_coalesce for more details.
2044 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002045static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002046 struct ethtool_coalesce *ec)
2047{
Kan Lianga75e8002016-02-19 09:24:04 -05002048 return __i40e_get_coalesce(netdev, ec, -1);
2049}
2050
Jacob Keller65e87c02016-09-12 14:18:44 -07002051/**
2052 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2053 * @netdev: netdev structure
2054 * @ec: ethtool's coalesce settings
2055 * @queue: the particular queue to read
2056 *
2057 * Will read a specific queue's coalesce settings
2058 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002059static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2060 struct ethtool_coalesce *ec)
2061{
2062 return __i40e_get_coalesce(netdev, ec, queue);
2063}
2064
Jacob Keller65e87c02016-09-12 14:18:44 -07002065/**
2066 * i40e_set_itr_per_queue - set ITR values for specific queue
2067 * @vsi: the VSI to set values for
2068 * @ec: coalesce settings from ethtool
2069 * @queue: the queue to modify
2070 *
2071 * Change the ITR settings for a specific queue.
2072 **/
2073
Kan Lianga75e8002016-02-19 09:24:04 -05002074static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2075 struct ethtool_coalesce *ec,
2076 int queue)
2077{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002078 struct i40e_pf *pf = vsi->back;
2079 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002080 struct i40e_q_vector *q_vector;
2081 u16 vector, intrl;
2082
Alan Brady1c0e6a32016-11-28 16:06:02 -08002083 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002084
2085 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2086 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2087
2088 if (ec->use_adaptive_rx_coalesce)
2089 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2090 else
2091 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2092
2093 if (ec->use_adaptive_tx_coalesce)
2094 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2095 else
2096 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2097
2098 q_vector = vsi->rx_rings[queue]->q_vector;
2099 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2100 vector = vsi->base_vector + q_vector->v_idx;
2101 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2102
2103 q_vector = vsi->tx_rings[queue]->q_vector;
2104 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2105 vector = vsi->base_vector + q_vector->v_idx;
2106 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2107
2108 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2109 i40e_flush(hw);
2110}
2111
Jacob Keller65e87c02016-09-12 14:18:44 -07002112/**
2113 * __i40e_set_coalesce - set coalesce settings for particular queue
2114 * @netdev: the netdev to change
2115 * @ec: ethtool coalesce settings
2116 * @queue: the queue to change
2117 *
2118 * Sets the coalesce settings for a particular queue.
2119 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002120static int __i40e_set_coalesce(struct net_device *netdev,
2121 struct ethtool_coalesce *ec,
2122 int queue)
2123{
2124 struct i40e_netdev_priv *np = netdev_priv(netdev);
2125 struct i40e_vsi *vsi = np->vsi;
2126 struct i40e_pf *pf = vsi->back;
Alan Brady33084062016-11-28 16:06:03 -08002127 u16 intrl_reg;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002128 int i;
2129
2130 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2131 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2132
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002133 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2134 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2135 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2136 return -EINVAL;
2137 }
2138
Alan Brady33084062016-11-28 16:06:03 -08002139 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2140 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2141 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002142 return -EINVAL;
2143 }
2144
Kan Lianga75e8002016-02-19 09:24:04 -05002145 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002146 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002147 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 -05002148 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2149 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2150 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2151 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002152 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002153
Alan Brady33084062016-11-28 16:06:03 -08002154 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2155 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2156 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2157 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2158 vsi->int_rate_limit);
2159 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002160
Kan Lianga75e8002016-02-19 09:24:04 -05002161 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002162 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002163 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 -05002164 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2165 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2166 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2167 return -EINVAL;
2168 }
2169
2170 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2171 * apply to all queues.
2172 */
2173 if (queue < 0) {
2174 for (i = 0; i < vsi->num_queue_pairs; i++)
2175 i40e_set_itr_per_queue(vsi, ec, i);
2176 } else if (queue < vsi->num_queue_pairs) {
2177 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002178 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002179 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2180 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002181 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002182 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002183
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 return 0;
2185}
2186
Jacob Keller65e87c02016-09-12 14:18:44 -07002187/**
2188 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2189 * @netdev: the netdev to change
2190 * @ec: ethtool coalesce settings
2191 *
2192 * This will set each queue to the same coalesce settings.
2193 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002194static int i40e_set_coalesce(struct net_device *netdev,
2195 struct ethtool_coalesce *ec)
2196{
2197 return __i40e_set_coalesce(netdev, ec, -1);
2198}
2199
Jacob Keller65e87c02016-09-12 14:18:44 -07002200/**
2201 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2202 * @netdev: the netdev to change
2203 * @ec: ethtool's coalesce settings
2204 * @queue: the queue to change
2205 *
2206 * Sets the specified queue's coalesce settings.
2207 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002208static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2209 struct ethtool_coalesce *ec)
2210{
2211 return __i40e_set_coalesce(netdev, ec, queue);
2212}
2213
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002214/**
2215 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2216 * @pf: pointer to the physical function struct
2217 * @cmd: ethtool rxnfc command
2218 *
2219 * Returns Success if the flow is supported, else Invalid Input.
2220 **/
2221static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2222{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002223 struct i40e_hw *hw = &pf->hw;
2224 u8 flow_pctype = 0;
2225 u64 i_set = 0;
2226
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002227 cmd->data = 0;
2228
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229 switch (cmd->flow_type) {
2230 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002231 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2232 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002233 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002234 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2235 break;
2236 case TCP_V6_FLOW:
2237 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2238 break;
2239 case UDP_V6_FLOW:
2240 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2241 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242 case SCTP_V4_FLOW:
2243 case AH_ESP_V4_FLOW:
2244 case AH_V4_FLOW:
2245 case ESP_V4_FLOW:
2246 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002247 case SCTP_V6_FLOW:
2248 case AH_ESP_V6_FLOW:
2249 case AH_V6_FLOW:
2250 case ESP_V6_FLOW:
2251 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002252 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002253 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2254 break;
2255 default:
2256 return -EINVAL;
2257 }
2258
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002259 /* Read flow based hash input set register */
2260 if (flow_pctype) {
2261 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2262 flow_pctype)) |
2263 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2264 flow_pctype)) << 32);
2265 }
2266
2267 /* Process bits of hash input set */
2268 if (i_set) {
2269 if (i_set & I40E_L4_SRC_MASK)
2270 cmd->data |= RXH_L4_B_0_1;
2271 if (i_set & I40E_L4_DST_MASK)
2272 cmd->data |= RXH_L4_B_2_3;
2273
2274 if (cmd->flow_type == TCP_V4_FLOW ||
2275 cmd->flow_type == UDP_V4_FLOW) {
2276 if (i_set & I40E_L3_SRC_MASK)
2277 cmd->data |= RXH_IP_SRC;
2278 if (i_set & I40E_L3_DST_MASK)
2279 cmd->data |= RXH_IP_DST;
2280 } else if (cmd->flow_type == TCP_V6_FLOW ||
2281 cmd->flow_type == UDP_V6_FLOW) {
2282 if (i_set & I40E_L3_V6_SRC_MASK)
2283 cmd->data |= RXH_IP_SRC;
2284 if (i_set & I40E_L3_V6_DST_MASK)
2285 cmd->data |= RXH_IP_DST;
2286 }
2287 }
2288
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002289 return 0;
2290}
2291
2292/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002293 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2294 * @pf: Pointer to the physical function struct
2295 * @cmd: The command to get or set Rx flow classification rules
2296 * @rule_locs: Array of used rule locations
2297 *
2298 * This function populates both the total and actual rule count of
2299 * the ethtool flow classification command
2300 *
2301 * Returns 0 on success or -EMSGSIZE if entry not found
2302 **/
2303static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2304 struct ethtool_rxnfc *cmd,
2305 u32 *rule_locs)
2306{
2307 struct i40e_fdir_filter *rule;
2308 struct hlist_node *node2;
2309 int cnt = 0;
2310
2311 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002312 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002313
2314 hlist_for_each_entry_safe(rule, node2,
2315 &pf->fdir_filter_list, fdir_node) {
2316 if (cnt == cmd->rule_cnt)
2317 return -EMSGSIZE;
2318
2319 rule_locs[cnt] = rule->fd_id;
2320 cnt++;
2321 }
2322
2323 cmd->rule_cnt = cnt;
2324
2325 return 0;
2326}
2327
2328/**
2329 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2330 * @pf: Pointer to the physical function struct
2331 * @cmd: The command to get or set Rx flow classification rules
2332 *
2333 * This function looks up a filter based on the Rx flow classification
2334 * command and fills the flow spec info for it if found
2335 *
2336 * Returns 0 on success or -EINVAL if filter not found
2337 **/
2338static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2339 struct ethtool_rxnfc *cmd)
2340{
2341 struct ethtool_rx_flow_spec *fsp =
2342 (struct ethtool_rx_flow_spec *)&cmd->fs;
2343 struct i40e_fdir_filter *rule = NULL;
2344 struct hlist_node *node2;
2345
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002346 hlist_for_each_entry_safe(rule, node2,
2347 &pf->fdir_filter_list, fdir_node) {
2348 if (fsp->location <= rule->fd_id)
2349 break;
2350 }
2351
2352 if (!rule || fsp->location != rule->fd_id)
2353 return -EINVAL;
2354
2355 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002356 if (fsp->flow_type == IP_USER_FLOW) {
2357 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2358 fsp->h_u.usr_ip4_spec.proto = 0;
2359 fsp->m_u.usr_ip4_spec.proto = 0;
2360 }
2361
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002362 /* Reverse the src and dest notion, since the HW views them from
2363 * Tx perspective where as the user expects it from Rx filter view.
2364 */
2365 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2366 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2367 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2368 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002369
2370 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2371 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2372 else
2373 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002374
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002375 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2376 struct i40e_vsi *vsi;
2377
2378 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2379 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2380 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2381 fsp->m_ext.data[1] = htonl(0x1);
2382 }
2383 }
2384
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002385 return 0;
2386}
2387
2388/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002389 * i40e_get_rxnfc - command to get RX flow classification rules
2390 * @netdev: network interface device structure
2391 * @cmd: ethtool rxnfc command
2392 *
2393 * Returns Success if the command is supported.
2394 **/
2395static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2396 u32 *rule_locs)
2397{
2398 struct i40e_netdev_priv *np = netdev_priv(netdev);
2399 struct i40e_vsi *vsi = np->vsi;
2400 struct i40e_pf *pf = vsi->back;
2401 int ret = -EOPNOTSUPP;
2402
2403 switch (cmd->cmd) {
2404 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002405 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002406 ret = 0;
2407 break;
2408 case ETHTOOL_GRXFH:
2409 ret = i40e_get_rss_hash_opts(pf, cmd);
2410 break;
2411 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002412 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002413 /* report total rule count */
2414 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002415 ret = 0;
2416 break;
2417 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002418 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002419 break;
2420 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002421 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2422 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002423 default:
2424 break;
2425 }
2426
2427 return ret;
2428}
2429
2430/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002431 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2432 * @nfc: pointer to user request
2433 * @i_setc bits currently set
2434 *
2435 * Returns value of bits to be set per user request
2436 **/
2437static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2438{
2439 u64 i_set = i_setc;
2440 u64 src_l3 = 0, dst_l3 = 0;
2441
2442 if (nfc->data & RXH_L4_B_0_1)
2443 i_set |= I40E_L4_SRC_MASK;
2444 else
2445 i_set &= ~I40E_L4_SRC_MASK;
2446 if (nfc->data & RXH_L4_B_2_3)
2447 i_set |= I40E_L4_DST_MASK;
2448 else
2449 i_set &= ~I40E_L4_DST_MASK;
2450
2451 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2452 src_l3 = I40E_L3_V6_SRC_MASK;
2453 dst_l3 = I40E_L3_V6_DST_MASK;
2454 } else if (nfc->flow_type == TCP_V4_FLOW ||
2455 nfc->flow_type == UDP_V4_FLOW) {
2456 src_l3 = I40E_L3_SRC_MASK;
2457 dst_l3 = I40E_L3_DST_MASK;
2458 } else {
2459 /* Any other flow type are not supported here */
2460 return i_set;
2461 }
2462
2463 if (nfc->data & RXH_IP_SRC)
2464 i_set |= src_l3;
2465 else
2466 i_set &= ~src_l3;
2467 if (nfc->data & RXH_IP_DST)
2468 i_set |= dst_l3;
2469 else
2470 i_set &= ~dst_l3;
2471
2472 return i_set;
2473}
2474
2475/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002476 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2477 * @pf: pointer to the physical function struct
2478 * @cmd: ethtool rxnfc command
2479 *
2480 * Returns Success if the flow input set is supported.
2481 **/
2482static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2483{
2484 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002485 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2486 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002487 u8 flow_pctype = 0;
2488 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002489
2490 /* RSS does not support anything other than hashing
2491 * to queues on src and dst IPs and ports
2492 */
2493 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2494 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2495 return -EINVAL;
2496
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002497 switch (nfc->flow_type) {
2498 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002499 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2500 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2501 hena |=
2502 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002503 break;
2504 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002505 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2506 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2507 hena |=
2508 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2509 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2510 hena |=
2511 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002512 break;
2513 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002514 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2515 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2516 hena |=
2517 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2518 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002519
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002520 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002521 break;
2522 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002523 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2524 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2525 hena |=
2526 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2527 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002528
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002529 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002530 break;
2531 case AH_ESP_V4_FLOW:
2532 case AH_V4_FLOW:
2533 case ESP_V4_FLOW:
2534 case SCTP_V4_FLOW:
2535 if ((nfc->data & RXH_L4_B_0_1) ||
2536 (nfc->data & RXH_L4_B_2_3))
2537 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002538 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002539 break;
2540 case AH_ESP_V6_FLOW:
2541 case AH_V6_FLOW:
2542 case ESP_V6_FLOW:
2543 case SCTP_V6_FLOW:
2544 if ((nfc->data & RXH_L4_B_0_1) ||
2545 (nfc->data & RXH_L4_B_2_3))
2546 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002547 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002548 break;
2549 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002550 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2551 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002552 break;
2553 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002554 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2555 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002556 break;
2557 default:
2558 return -EINVAL;
2559 }
2560
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002561 if (flow_pctype) {
2562 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2563 flow_pctype)) |
2564 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2565 flow_pctype)) << 32);
2566 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2567 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2568 (u32)i_set);
2569 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2570 (u32)(i_set >> 32));
2571 hena |= BIT_ULL(flow_pctype);
2572 }
2573
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002574 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2575 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002576 i40e_flush(hw);
2577
2578 return 0;
2579}
2580
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002581/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002582 * i40e_match_fdir_input_set - Match a new filter against an existing one
2583 * @rule: The filter already added
2584 * @input: The new filter to comapre against
2585 *
2586 * Returns true if the two input set match
2587 **/
2588static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2589 struct i40e_fdir_filter *input)
2590{
2591 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2592 (rule->src_ip[0] != input->src_ip[0]) ||
2593 (rule->dst_port != input->dst_port) ||
2594 (rule->src_port != input->src_port))
2595 return false;
2596 return true;
2597}
2598
2599/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002600 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2601 * @vsi: Pointer to the targeted VSI
2602 * @input: The filter to update or NULL to indicate deletion
2603 * @sw_idx: Software index to the filter
2604 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002605 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002606 * This function updates (or deletes) a Flow Director entry from
2607 * the hlist of the corresponding PF
2608 *
2609 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002610 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002611static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2612 struct i40e_fdir_filter *input,
2613 u16 sw_idx,
2614 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002615{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002616 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002617 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002618 struct hlist_node *node2;
2619 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002620
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002621 parent = NULL;
2622 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002623
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002624 hlist_for_each_entry_safe(rule, node2,
2625 &pf->fdir_filter_list, fdir_node) {
2626 /* hash found, or no matching entry */
2627 if (rule->fd_id >= sw_idx)
2628 break;
2629 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002630 }
2631
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002632 /* if there is an old rule occupying our place remove it */
2633 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002634 if (input && !i40e_match_fdir_input_set(rule, input))
2635 err = i40e_add_del_fdir(vsi, rule, false);
2636 else if (!input)
2637 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002638 hlist_del(&rule->fdir_node);
2639 kfree(rule);
2640 pf->fdir_pf_active_filters--;
2641 }
2642
2643 /* If no input this was a delete, err should be 0 if a rule was
2644 * successfully found and removed from the list else -EINVAL
2645 */
2646 if (!input)
2647 return err;
2648
2649 /* initialize node and set software index */
2650 INIT_HLIST_NODE(&input->fdir_node);
2651
2652 /* add filter to the list */
2653 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002654 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002655 else
2656 hlist_add_head(&input->fdir_node,
2657 &pf->fdir_filter_list);
2658
2659 /* update counts */
2660 pf->fdir_pf_active_filters++;
2661
2662 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002663}
2664
2665/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002666 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2667 * @vsi: Pointer to the targeted VSI
2668 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002669 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002670 * The function removes a Flow Director filter entry from the
2671 * hlist of the corresponding PF
2672 *
2673 * Returns 0 on success
2674 */
2675static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2676 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002677{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002678 struct ethtool_rx_flow_spec *fsp =
2679 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002680 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002681 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002682
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002683 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2684 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2685 return -EBUSY;
2686
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002687 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2688 return -EBUSY;
2689
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002690 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002691
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002692 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002693 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002694}
2695
2696/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002697 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002698 * @vsi: pointer to the targeted VSI
2699 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002700 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002701 * Add Flow Director filters for a specific flow spec based on their
2702 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002703 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002704static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2705 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002706{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002707 struct ethtool_rx_flow_spec *fsp;
2708 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002709 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002710 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002711 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002712
2713 if (!vsi)
2714 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002715 pf = vsi->back;
2716
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002717 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2718 return -EOPNOTSUPP;
2719
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08002720 if (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002721 return -ENOSPC;
2722
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002723 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2724 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2725 return -EBUSY;
2726
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002727 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2728 return -EBUSY;
2729
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002730 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2731
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002732 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2733 pf->hw.func_caps.fd_filters_guaranteed)) {
2734 return -EINVAL;
2735 }
2736
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002737 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2738 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002739 return -EINVAL;
2740
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002741 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002742
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002743 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002744 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002745
2746 input->fd_id = fsp->location;
2747
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002748 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2749 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2750 else
2751 input->dest_ctl =
2752 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2753
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002754 input->q_index = fsp->ring_cookie;
2755 input->flex_off = 0;
2756 input->pctype = 0;
2757 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002758 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002759 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002760 input->flow_type = fsp->flow_type;
2761 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002762
2763 /* Reverse the src and dest notion, since the HW expects them to be from
2764 * Tx perspective where as the input from user is from Rx filter view.
2765 */
2766 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2767 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2768 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2769 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002770
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002771 if (ntohl(fsp->m_ext.data[1])) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002772 vf_id = ntohl(fsp->h_ext.data[1]);
2773 if (vf_id >= pf->num_alloc_vfs) {
2774 netif_info(pf, drv, vsi->netdev,
2775 "Invalid VF id %d\n", vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002776 goto free_input;
2777 }
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002778 /* Find vsi id from vf id and override dest vsi */
2779 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2780 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002781 netif_info(pf, drv, vsi->netdev,
2782 "Invalid queue id %d for VF %d\n",
2783 input->q_index, vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002784 goto free_input;
2785 }
2786 }
2787
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002788 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002789free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002790 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002791 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002792 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002793 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002794
2795 return ret;
2796}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002797
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002798/**
2799 * i40e_set_rxnfc - command to set RX flow classification rules
2800 * @netdev: network interface device structure
2801 * @cmd: ethtool rxnfc command
2802 *
2803 * Returns Success if the command is supported.
2804 **/
2805static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2806{
2807 struct i40e_netdev_priv *np = netdev_priv(netdev);
2808 struct i40e_vsi *vsi = np->vsi;
2809 struct i40e_pf *pf = vsi->back;
2810 int ret = -EOPNOTSUPP;
2811
2812 switch (cmd->cmd) {
2813 case ETHTOOL_SRXFH:
2814 ret = i40e_set_rss_hash_opt(pf, cmd);
2815 break;
2816 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002817 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002818 break;
2819 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002820 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002821 break;
2822 default:
2823 break;
2824 }
2825
2826 return ret;
2827}
2828
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002829/**
2830 * i40e_max_channels - get Max number of combined channels supported
2831 * @vsi: vsi pointer
2832 **/
2833static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2834{
2835 /* TODO: This code assumes DCB and FD is disabled for now. */
2836 return vsi->alloc_queue_pairs;
2837}
2838
2839/**
2840 * i40e_get_channels - Get the current channels enabled and max supported etc.
2841 * @netdev: network interface device structure
2842 * @ch: ethtool channels structure
2843 *
2844 * We don't support separate tx and rx queues as channels. The other count
2845 * represents how many queues are being used for control. max_combined counts
2846 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2847 * q_vectors since we support a lot more queue pairs than q_vectors.
2848 **/
2849static void i40e_get_channels(struct net_device *dev,
2850 struct ethtool_channels *ch)
2851{
2852 struct i40e_netdev_priv *np = netdev_priv(dev);
2853 struct i40e_vsi *vsi = np->vsi;
2854 struct i40e_pf *pf = vsi->back;
2855
2856 /* report maximum channels */
2857 ch->max_combined = i40e_max_channels(vsi);
2858
2859 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002860 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002861 ch->max_other = ch->other_count;
2862
2863 /* Note: This code assumes DCB is disabled for now. */
2864 ch->combined_count = vsi->num_queue_pairs;
2865}
2866
2867/**
2868 * i40e_set_channels - Set the new channels count.
2869 * @netdev: network interface device structure
2870 * @ch: ethtool channels structure
2871 *
2872 * The new channels count may not be the same as requested by the user
2873 * since it gets rounded down to a power of 2 value.
2874 **/
2875static int i40e_set_channels(struct net_device *dev,
2876 struct ethtool_channels *ch)
2877{
Jacob Keller59826d92016-07-27 12:02:35 -07002878 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002879 struct i40e_netdev_priv *np = netdev_priv(dev);
2880 unsigned int count = ch->combined_count;
2881 struct i40e_vsi *vsi = np->vsi;
2882 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07002883 struct i40e_fdir_filter *rule;
2884 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002885 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07002886 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002887
2888 /* We do not support setting channels for any other VSI at present */
2889 if (vsi->type != I40E_VSI_MAIN)
2890 return -EINVAL;
2891
2892 /* verify they are not requesting separate vectors */
2893 if (!count || ch->rx_count || ch->tx_count)
2894 return -EINVAL;
2895
2896 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002897 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002898 return -EINVAL;
2899
2900 /* verify the number of channels does not exceed hardware limits */
2901 if (count > i40e_max_channels(vsi))
2902 return -EINVAL;
2903
Jacob Keller59826d92016-07-27 12:02:35 -07002904 /* verify that the number of channels does not invalidate any current
2905 * flow director rules
2906 */
2907 hlist_for_each_entry_safe(rule, node2,
2908 &pf->fdir_filter_list, fdir_node) {
2909 if (rule->dest_ctl != drop && count <= rule->q_index) {
2910 dev_warn(&pf->pdev->dev,
2911 "Existing user defined filter %d assigns flow to queue %d\n",
2912 rule->fd_id, rule->q_index);
2913 err = -EINVAL;
2914 }
2915 }
2916
2917 if (err) {
2918 dev_err(&pf->pdev->dev,
2919 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
2920 count);
2921 return err;
2922 }
2923
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002924 /* update feature limits from largest to smallest supported values */
2925 /* TODO: Flow director limit, DCB etc */
2926
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002927 /* use rss_reconfig to rebuild with new queue count and update traffic
2928 * class queue mapping
2929 */
2930 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002931 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002932 return 0;
2933 else
2934 return -EINVAL;
2935}
2936
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002937/**
2938 * i40e_get_rxfh_key_size - get the RSS hash key size
2939 * @netdev: network interface device structure
2940 *
2941 * Returns the table size.
2942 **/
2943static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2944{
2945 return I40E_HKEY_ARRAY_SIZE;
2946}
2947
2948/**
2949 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2950 * @netdev: network interface device structure
2951 *
2952 * Returns the table size.
2953 **/
2954static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2955{
2956 return I40E_HLUT_ARRAY_SIZE;
2957}
2958
2959static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2960 u8 *hfunc)
2961{
2962 struct i40e_netdev_priv *np = netdev_priv(netdev);
2963 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002964 u8 *lut, *seed = NULL;
2965 int ret;
2966 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002967
2968 if (hfunc)
2969 *hfunc = ETH_RSS_HASH_TOP;
2970
2971 if (!indir)
2972 return 0;
2973
Helin Zhang043dd652015-10-21 19:56:23 -04002974 seed = key;
2975 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2976 if (!lut)
2977 return -ENOMEM;
2978 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2979 if (ret)
2980 goto out;
2981 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2982 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002983
Helin Zhang043dd652015-10-21 19:56:23 -04002984out:
2985 kfree(lut);
2986
2987 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002988}
2989
2990/**
2991 * i40e_set_rxfh - set the rx flow hash indirection table
2992 * @netdev: network interface device structure
2993 * @indir: indirection table
2994 * @key: hash key
2995 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002996 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002997 * returns 0 after programming the table.
2998 **/
2999static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
3000 const u8 *key, const u8 hfunc)
3001{
3002 struct i40e_netdev_priv *np = netdev_priv(netdev);
3003 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07003004 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04003005 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04003006 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003007
3008 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3009 return -EOPNOTSUPP;
3010
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003011 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04003012 if (!vsi->rss_hkey_user) {
3013 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
3014 GFP_KERNEL);
3015 if (!vsi->rss_hkey_user)
3016 return -ENOMEM;
3017 }
3018 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
3019 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003020 }
Helin Zhang28c58692015-10-26 19:44:27 -04003021 if (!vsi->rss_lut_user) {
3022 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3023 if (!vsi->rss_lut_user)
3024 return -ENOMEM;
3025 }
Helin Zhang043dd652015-10-21 19:56:23 -04003026
Helin Zhang28c58692015-10-26 19:44:27 -04003027 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07003028 if (indir)
3029 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3030 vsi->rss_lut_user[i] = (u8)(indir[i]);
3031 else
3032 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
3033 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04003034
3035 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
3036 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003037}
3038
Greg Rose7e45ab42015-02-06 08:52:19 +00003039/**
3040 * i40e_get_priv_flags - report device private flags
3041 * @dev: network interface device structure
3042 *
3043 * The get string set count and the string set should be matched for each
3044 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
3045 * array.
3046 *
3047 * Returns a u32 bitmap of flags.
3048 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00003049static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00003050{
3051 struct i40e_netdev_priv *np = netdev_priv(dev);
3052 struct i40e_vsi *vsi = np->vsi;
3053 struct i40e_pf *pf = vsi->back;
3054 u32 ret_flags = 0;
3055
Shannon Nelson9ac77262015-08-27 11:42:40 -04003056 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
3057 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04003058 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
3059 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003060 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
3061 I40E_PRIV_FLAGS_VEB_STATS : 0;
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003062 ret_flags |= pf->hw_disabled_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003063 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003064 if (pf->hw.pf_id == 0) {
3065 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
3066 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
3067 }
Greg Rose7e45ab42015-02-06 08:52:19 +00003068
3069 return ret_flags;
3070}
3071
Shannon Nelson9ac77262015-08-27 11:42:40 -04003072/**
3073 * i40e_set_priv_flags - set private flags
3074 * @dev: network interface device structure
3075 * @flags: bit flags to be set
3076 **/
3077static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
3078{
3079 struct i40e_netdev_priv *np = netdev_priv(dev);
3080 struct i40e_vsi *vsi = np->vsi;
3081 struct i40e_pf *pf = vsi->back;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003082 u16 sw_flags = 0, valid_flags = 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003083 bool reset_required = false;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003084 bool promisc_change = false;
3085 int ret;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003086
3087 /* NOTE: MFP is not settable */
3088
Shannon Nelson9ac77262015-08-27 11:42:40 -04003089 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
3090 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
3091 else
3092 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
3093
Jesse Brandeburgef171782015-09-03 17:18:49 -04003094 /* allow the user to control the state of the Flow
3095 * Director ATR (Application Targeted Routing) feature
3096 * of the driver
3097 */
3098 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
3099 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
3100 } else {
3101 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003102 pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED;
Jacob Keller234dc4e2016-09-06 18:05:09 -07003103
3104 /* flush current ATR settings */
3105 set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04003106 }
3107
Shannon Nelson66fc3602016-01-13 16:51:42 -08003108 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3109 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003110 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003111 reset_required = true;
3112 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3113 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003114 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003115 reset_required = true;
3116 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003117
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003118 if (pf->hw.pf_id == 0) {
3119 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3120 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3121 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
3122 promisc_change = true;
3123 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3124 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3125 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
3126 promisc_change = true;
3127 }
3128 }
3129 if (promisc_change) {
3130 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
3131 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3132 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3133 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
3134 NULL);
3135 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
3136 dev_info(&pf->pdev->dev,
3137 "couldn't set switch config bits, err %s aq_err %s\n",
3138 i40e_stat_str(&pf->hw, ret),
3139 i40e_aq_str(&pf->hw,
3140 pf->hw.aq.asq_last_status));
3141 /* not a fatal problem, just keep going */
3142 }
3143 }
3144
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003145 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
3146 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003147 pf->hw_disabled_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003148 else
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003149 pf->hw_disabled_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003150
Jesse Brandeburg827de392015-11-06 15:26:07 -08003151 /* if needed, issue reset to cause things to take effect */
3152 if (reset_required)
3153 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
3154
Shannon Nelson9ac77262015-08-27 11:42:40 -04003155 return 0;
3156}
3157
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003158static const struct ethtool_ops i40e_ethtool_ops = {
3159 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00003160 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003161 .get_drvinfo = i40e_get_drvinfo,
3162 .get_regs_len = i40e_get_regs_len,
3163 .get_regs = i40e_get_regs,
3164 .nway_reset = i40e_nway_reset,
3165 .get_link = ethtool_op_get_link,
3166 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00003167 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003168 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003169 .get_eeprom_len = i40e_get_eeprom_len,
3170 .get_eeprom = i40e_get_eeprom,
3171 .get_ringparam = i40e_get_ringparam,
3172 .set_ringparam = i40e_set_ringparam,
3173 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00003174 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003175 .get_msglevel = i40e_get_msglevel,
3176 .set_msglevel = i40e_set_msglevel,
3177 .get_rxnfc = i40e_get_rxnfc,
3178 .set_rxnfc = i40e_set_rxnfc,
3179 .self_test = i40e_diag_test,
3180 .get_strings = i40e_get_strings,
3181 .set_phys_id = i40e_set_phys_id,
3182 .get_sset_count = i40e_get_sset_count,
3183 .get_ethtool_stats = i40e_get_ethtool_stats,
3184 .get_coalesce = i40e_get_coalesce,
3185 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003186 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3187 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3188 .get_rxfh = i40e_get_rxfh,
3189 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003190 .get_channels = i40e_get_channels,
3191 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003192 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00003193 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04003194 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05003195 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05003196 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003197};
3198
3199void i40e_set_ethtool_ops(struct net_device *netdev)
3200{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003201 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003202}