blob: 8381dabf052469c9a27ddee00944a54de350e906 [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 */
107static struct i40e_stats i40e_gstrings_stats[] = {
108 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
109 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000110 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
111 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
112 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
113 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
114 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
115 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
117 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000118 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400119 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000120 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
121 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
122 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000123 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000124 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000125 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
126 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
127 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
128 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
129 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
130 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
131 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
132 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
133 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
134 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
135 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
136 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
137 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
138 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
139 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
140 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
141 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
142 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
143 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
144 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
145 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
146 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
147 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
148 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800149 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000150 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400153 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400156 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000157
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000158 /* LPI stats */
159 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
160 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
161 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
162 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000163};
164
Vasu Dev38e00432014-08-01 13:27:03 -0700165#ifdef I40E_FCOE
166static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
167 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
168 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
169 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
170 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
171 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
172 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
173 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
174 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
175};
176
177#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000178#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000179 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
180 * 2 /* Tx and Rx together */ \
181 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000182#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
183#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000184#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700185#ifdef I40E_FCOE
186#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
188 I40E_FCOE_STATS_LEN + \
189 I40E_MISC_STATS_LEN + \
190 I40E_QUEUE_STATS_LEN((n)))
191#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000193 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700195#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000196#define I40E_PFC_STATS_LEN ( \
197 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
201 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
202 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400203#define I40E_VEB_TC_STATS_LEN ( \
204 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
207 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
208 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000209#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400210#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000211#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
212 I40E_PFC_STATS_LEN + \
213 I40E_VSI_STATS_LEN((n)))
214
215enum i40e_ethtool_test_id {
216 I40E_ETH_TEST_REG = 0,
217 I40E_ETH_TEST_EEPROM,
218 I40E_ETH_TEST_INTR,
219 I40E_ETH_TEST_LOOPBACK,
220 I40E_ETH_TEST_LINK,
221};
222
223static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
224 "Register test (offline)",
225 "Eeprom test (offline)",
226 "Interrupt test (offline)",
227 "Loopback test (offline)",
228 "Link test (on/offline)"
229};
230
231#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
232
Anjali Singhai Jainb5569892016-05-03 15:13:12 -0700233static const char i40e_priv_flags_strings_gl[][ETH_GSTRING_LEN] = {
234 "MFP",
235 "LinkPolling",
236 "flow-director-atr",
237 "veb-stats",
238 "hw-atr-eviction",
239 "vf-true-promisc-support",
240};
241
242#define I40E_PRIV_FLAGS_GL_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings_gl)
243
Greg Rose7e45ab42015-02-06 08:52:19 +0000244static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
245 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400246 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400247 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400248 "veb-stats",
Anjali Singhai Jain72b74862016-01-08 17:50:21 -0800249 "hw-atr-eviction",
Greg Rose7e45ab42015-02-06 08:52:19 +0000250};
251
Shannon Nelson9ac77262015-08-27 11:42:40 -0400252#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000253
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000255 * i40e_partition_setting_complaint - generic complaint for MFP restriction
256 * @pf: the PF struct
257 **/
258static void i40e_partition_setting_complaint(struct i40e_pf *pf)
259{
260 dev_info(&pf->pdev->dev,
261 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
262}
263
264/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700265 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
266 * @phy_types: PHY types to convert
267 * @supported: pointer to the ethtool supported variable to fill in
268 * @advertising: pointer to the ethtool advertising variable to fill in
269 *
270 **/
271static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
272 u32 *advertising)
273{
274 enum i40e_aq_capabilities_phy_type phy_types = pf->hw.phy.phy_types;
275
276 *supported = 0x0;
277 *advertising = 0x0;
278
279 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
280 *supported |= SUPPORTED_Autoneg |
281 SUPPORTED_1000baseT_Full;
282 *advertising |= ADVERTISED_Autoneg |
283 ADVERTISED_1000baseT_Full;
284 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
285 *supported |= SUPPORTED_100baseT_Full;
286 *advertising |= ADVERTISED_100baseT_Full;
287 }
288 }
289 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
290 phy_types & I40E_CAP_PHY_TYPE_XFI ||
291 phy_types & I40E_CAP_PHY_TYPE_SFI ||
292 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
294 *supported |= SUPPORTED_10000baseT_Full;
295 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
296 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
297 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
298 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
299 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
300 *supported |= SUPPORTED_Autoneg |
301 SUPPORTED_10000baseT_Full;
302 *advertising |= ADVERTISED_Autoneg |
303 ADVERTISED_10000baseT_Full;
304 }
305 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
306 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
307 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
308 *supported |= SUPPORTED_40000baseCR4_Full;
309 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
310 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
311 *supported |= SUPPORTED_Autoneg |
312 SUPPORTED_40000baseCR4_Full;
313 *advertising |= ADVERTISED_Autoneg |
314 ADVERTISED_40000baseCR4_Full;
315 }
316 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
317 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
318 *supported |= SUPPORTED_Autoneg |
319 SUPPORTED_100baseT_Full;
320 *advertising |= ADVERTISED_Autoneg |
321 ADVERTISED_100baseT_Full;
322 }
323 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
324 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
325 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
326 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
327 *supported |= SUPPORTED_Autoneg |
328 SUPPORTED_1000baseT_Full;
329 *advertising |= ADVERTISED_Autoneg |
330 ADVERTISED_1000baseT_Full;
331 }
332 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
333 *supported |= SUPPORTED_40000baseSR4_Full;
334 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
335 *supported |= SUPPORTED_40000baseLR4_Full;
336 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
337 *supported |= SUPPORTED_40000baseKR4_Full |
338 SUPPORTED_Autoneg;
339 *advertising |= ADVERTISED_40000baseKR4_Full |
340 ADVERTISED_Autoneg;
341 }
342 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
343 *supported |= SUPPORTED_20000baseKR2_Full |
344 SUPPORTED_Autoneg;
345 *advertising |= ADVERTISED_20000baseKR2_Full |
346 ADVERTISED_Autoneg;
347 }
348 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
349 *supported |= SUPPORTED_10000baseKR_Full |
350 SUPPORTED_Autoneg;
351 *advertising |= ADVERTISED_10000baseKR_Full |
352 ADVERTISED_Autoneg;
353 }
354 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
355 *supported |= SUPPORTED_10000baseKX4_Full |
356 SUPPORTED_Autoneg;
357 *advertising |= ADVERTISED_10000baseKX4_Full |
358 ADVERTISED_Autoneg;
359 }
360 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
361 *supported |= SUPPORTED_1000baseKX_Full |
362 SUPPORTED_Autoneg;
363 *advertising |= ADVERTISED_1000baseKX_Full |
364 ADVERTISED_Autoneg;
365 }
366}
367
368/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000369 * i40e_get_settings_link_up - Get the Link settings for when link is up
370 * @hw: hw structure
371 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000372 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000373 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000374 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000375static void i40e_get_settings_link_up(struct i40e_hw *hw,
376 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400377 struct net_device *netdev,
378 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000379{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000381 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700382 u32 e_advertising = 0x0;
383 u32 e_supported = 0x0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000384
Catherine Sullivane8278452015-02-06 08:52:08 +0000385 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386 switch (hw_link_info->phy_type) {
387 case I40E_PHY_TYPE_40GBASE_CR4:
388 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000389 ecmd->supported = SUPPORTED_Autoneg |
390 SUPPORTED_40000baseCR4_Full;
391 ecmd->advertising = ADVERTISED_Autoneg |
392 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000393 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000394 case I40E_PHY_TYPE_XLAUI:
395 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000396 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000397 ecmd->supported = SUPPORTED_40000baseCR4_Full;
398 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000399 case I40E_PHY_TYPE_40GBASE_SR4:
400 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000401 break;
402 case I40E_PHY_TYPE_40GBASE_LR4:
403 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000404 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000405 case I40E_PHY_TYPE_10GBASE_SR:
406 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000407 case I40E_PHY_TYPE_1000BASE_SX:
408 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400409 ecmd->supported = SUPPORTED_10000baseT_Full;
410 if (hw_link_info->module_type[2] &
411 I40E_MODULE_TYPE_1000BASE_SX ||
412 hw_link_info->module_type[2] &
413 I40E_MODULE_TYPE_1000BASE_LX) {
414 ecmd->supported |= SUPPORTED_1000baseT_Full;
415 if (hw_link_info->requested_speeds &
416 I40E_LINK_SPEED_1GB)
417 ecmd->advertising |= ADVERTISED_1000baseT_Full;
418 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000419 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
420 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000421 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000422 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000423 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700424 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000425 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000426 SUPPORTED_10000baseT_Full |
Catherine Sullivan06566e52016-05-03 15:13:14 -0700427 SUPPORTED_1000baseT_Full |
428 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000429 ecmd->advertising = ADVERTISED_Autoneg;
430 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
431 ecmd->advertising |= ADVERTISED_10000baseT_Full;
432 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
433 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700434 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
435 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400436 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400437 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
438 ecmd->supported = SUPPORTED_Autoneg |
439 SUPPORTED_1000baseT_Full;
440 ecmd->advertising = ADVERTISED_Autoneg |
441 ADVERTISED_1000baseT_Full;
442 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000443 case I40E_PHY_TYPE_10GBASE_CR1_CU:
444 case I40E_PHY_TYPE_10GBASE_CR1:
445 ecmd->supported = SUPPORTED_Autoneg |
446 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000447 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000448 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000449 break;
450 case I40E_PHY_TYPE_XAUI:
451 case I40E_PHY_TYPE_XFI:
452 case I40E_PHY_TYPE_SFI:
453 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000454 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000455 ecmd->supported = SUPPORTED_10000baseT_Full;
456 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000457 case I40E_PHY_TYPE_SGMII:
458 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400459 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000460 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
461 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800462 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400463 ecmd->supported |= SUPPORTED_100baseT_Full;
464 if (hw_link_info->requested_speeds &
465 I40E_LINK_SPEED_100MB)
466 ecmd->advertising |= ADVERTISED_100baseT_Full;
467 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000468 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400469 case I40E_PHY_TYPE_40GBASE_KR4:
470 case I40E_PHY_TYPE_20GBASE_KR2:
471 case I40E_PHY_TYPE_10GBASE_KR:
472 case I40E_PHY_TYPE_10GBASE_KX4:
473 case I40E_PHY_TYPE_1000BASE_KX:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700474 ecmd->supported |= SUPPORTED_40000baseKR4_Full |
475 SUPPORTED_20000baseKR2_Full |
476 SUPPORTED_10000baseKR_Full |
477 SUPPORTED_10000baseKX4_Full |
478 SUPPORTED_1000baseKX_Full |
479 SUPPORTED_Autoneg;
480 ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
481 ADVERTISED_20000baseKR2_Full |
482 ADVERTISED_10000baseKR_Full |
483 ADVERTISED_10000baseKX4_Full |
484 ADVERTISED_1000baseKX_Full |
485 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400486 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000487 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000488 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000489 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
490 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000491 }
492
Catherine Sullivan06566e52016-05-03 15:13:14 -0700493 /* Now that we've worked out everything that could be supported by the
494 * current PHY type, get what is supported by the NVM and them to
495 * get what is truly supported
496 */
497 i40e_phy_type_to_ethtool(pf, &e_supported,
498 &e_advertising);
499
500 ecmd->supported = ecmd->supported & e_supported;
501 ecmd->advertising = ecmd->advertising & e_advertising;
502
Catherine Sullivane8278452015-02-06 08:52:08 +0000503 /* Set speed and duplex */
504 switch (link_speed) {
505 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400506 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000507 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700508 case I40E_LINK_SPEED_20GB:
509 ethtool_cmd_speed_set(ecmd, SPEED_20000);
510 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000511 case I40E_LINK_SPEED_10GB:
512 ethtool_cmd_speed_set(ecmd, SPEED_10000);
513 break;
514 case I40E_LINK_SPEED_1GB:
515 ethtool_cmd_speed_set(ecmd, SPEED_1000);
516 break;
517 case I40E_LINK_SPEED_100MB:
518 ethtool_cmd_speed_set(ecmd, SPEED_100);
519 break;
520 default:
521 break;
522 }
523 ecmd->duplex = DUPLEX_FULL;
524}
525
526/**
527 * i40e_get_settings_link_down - Get the Link settings for when link is down
528 * @hw: hw structure
529 * @ecmd: ethtool command to fill in
530 *
531 * Reports link settings that can be determined when link is down
532 **/
533static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400534 struct ethtool_cmd *ecmd,
535 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000536{
Catherine Sullivane8278452015-02-06 08:52:08 +0000537 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400538 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000539 */
Catherine Sullivan06566e52016-05-03 15:13:14 -0700540 i40e_phy_type_to_ethtool(pf, &ecmd->supported,
541 &ecmd->advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000542
543 /* With no link speed and duplex are unknown */
544 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
545 ecmd->duplex = DUPLEX_UNKNOWN;
546}
547
548/**
549 * i40e_get_settings - Get Link Speed and Duplex settings
550 * @netdev: network interface device structure
551 * @ecmd: ethtool command
552 *
553 * Reports speed/duplex settings based on media_type
554 **/
555static int i40e_get_settings(struct net_device *netdev,
556 struct ethtool_cmd *ecmd)
557{
558 struct i40e_netdev_priv *np = netdev_priv(netdev);
559 struct i40e_pf *pf = np->vsi->back;
560 struct i40e_hw *hw = &pf->hw;
561 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
562 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
563
564 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400565 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000566 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400567 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000568
569 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000570 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000571 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
572 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000573
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000574 switch (hw->phy.media_type) {
575 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000576 ecmd->supported |= SUPPORTED_Autoneg |
577 SUPPORTED_Backplane;
578 ecmd->advertising |= ADVERTISED_Autoneg |
579 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000580 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000581 break;
582 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000583 ecmd->supported |= SUPPORTED_TP;
584 ecmd->advertising |= ADVERTISED_TP;
585 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000586 break;
587 case I40E_MEDIA_TYPE_DA:
588 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000589 ecmd->supported |= SUPPORTED_FIBRE;
590 ecmd->advertising |= ADVERTISED_FIBRE;
591 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000592 break;
593 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000594 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000595 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000596 break;
597 case I40E_MEDIA_TYPE_UNKNOWN:
598 default:
599 ecmd->port = PORT_OTHER;
600 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000601 }
602
Catherine Sullivane8278452015-02-06 08:52:08 +0000603 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000604 ecmd->transceiver = XCVR_EXTERNAL;
605
Catherine Sullivane8278452015-02-06 08:52:08 +0000606 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000607 ecmd->supported |= SUPPORTED_Pause;
608
Catherine Sullivane8278452015-02-06 08:52:08 +0000609 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000610 case I40E_FC_FULL:
611 ecmd->advertising |= ADVERTISED_Pause;
612 break;
613 case I40E_FC_TX_PAUSE:
614 ecmd->advertising |= ADVERTISED_Asym_Pause;
615 break;
616 case I40E_FC_RX_PAUSE:
617 ecmd->advertising |= (ADVERTISED_Pause |
618 ADVERTISED_Asym_Pause);
619 break;
620 default:
621 ecmd->advertising &= ~(ADVERTISED_Pause |
622 ADVERTISED_Asym_Pause);
623 break;
624 }
625
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000626 return 0;
627}
628
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000629/**
630 * i40e_set_settings - Set Speed and Duplex
631 * @netdev: network interface device structure
632 * @ecmd: ethtool command
633 *
634 * Set speed/duplex per media_types advertised/forced
635 **/
636static int i40e_set_settings(struct net_device *netdev,
637 struct ethtool_cmd *ecmd)
638{
639 struct i40e_netdev_priv *np = netdev_priv(netdev);
640 struct i40e_aq_get_phy_abilities_resp abilities;
641 struct i40e_aq_set_phy_config config;
642 struct i40e_pf *pf = np->vsi->back;
643 struct i40e_vsi *vsi = np->vsi;
644 struct i40e_hw *hw = &pf->hw;
645 struct ethtool_cmd safe_ecmd;
646 i40e_status status = 0;
647 bool change = false;
648 int err = 0;
649 u8 autoneg;
650 u32 advertise;
651
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000652 /* Changing port settings is not supported if this isn't the
653 * port's controlling PF
654 */
655 if (hw->partition_id != 1) {
656 i40e_partition_setting_complaint(pf);
657 return -EOPNOTSUPP;
658 }
659
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000660 if (vsi != pf->vsi[pf->lan_vsi])
661 return -EOPNOTSUPP;
662
663 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
664 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000665 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700666 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000667 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000668 return -EOPNOTSUPP;
669
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400670 if (hw->device_id == I40E_DEV_ID_KX_B ||
671 hw->device_id == I40E_DEV_ID_KX_C ||
672 hw->device_id == I40E_DEV_ID_20G_KR2 ||
673 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
674 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
675 return -EOPNOTSUPP;
676 }
677
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000678 /* get our own copy of the bits to check against */
679 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
680 i40e_get_settings(netdev, &safe_ecmd);
681
682 /* save autoneg and speed out of ecmd */
683 autoneg = ecmd->autoneg;
684 advertise = ecmd->advertising;
685
686 /* set autoneg and speed back to what they currently are */
687 ecmd->autoneg = safe_ecmd.autoneg;
688 ecmd->advertising = safe_ecmd.advertising;
689
690 ecmd->cmd = safe_ecmd.cmd;
691 /* If ecmd and safe_ecmd are not the same now, then they are
692 * trying to set something that we do not support
693 */
694 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
695 return -EOPNOTSUPP;
696
697 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
698 usleep_range(1000, 2000);
699
700 /* Get the current phy config */
701 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
702 NULL);
703 if (status)
704 return -EAGAIN;
705
Catherine Sullivan124ed152014-07-12 07:28:12 +0000706 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000707 * set below
708 */
709 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000710 config.abilities = abilities.abilities;
711
712 /* Check autoneg */
713 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000714 /* If autoneg was not already enabled */
715 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400716 /* If autoneg is not supported, return error */
717 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
718 netdev_info(netdev, "Autoneg not supported on this phy\n");
719 return -EINVAL;
720 }
721 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000722 config.abilities = abilities.abilities |
723 I40E_AQ_PHY_ENABLE_AN;
724 change = true;
725 }
726 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000727 /* If autoneg is currently enabled */
728 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400729 /* If autoneg is supported 10GBASE_T is the only PHY
730 * that can disable it, so otherwise return error
731 */
732 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
733 hw->phy.link_info.phy_type !=
734 I40E_PHY_TYPE_10GBASE_T) {
735 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
736 return -EINVAL;
737 }
738 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000739 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000740 ~I40E_AQ_PHY_ENABLE_AN;
741 change = true;
742 }
743 }
744
745 if (advertise & ~safe_ecmd.supported)
746 return -EINVAL;
747
748 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000749 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750 if (advertise & ADVERTISED_1000baseT_Full ||
751 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000752 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000753 if (advertise & ADVERTISED_10000baseT_Full ||
754 advertise & ADVERTISED_10000baseKX4_Full ||
755 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000756 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700757 if (advertise & ADVERTISED_20000baseKR2_Full)
758 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000759 if (advertise & ADVERTISED_40000baseKR4_Full ||
760 advertise & ADVERTISED_40000baseCR4_Full ||
761 advertise & ADVERTISED_40000baseSR4_Full ||
762 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000763 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000764
Catherine Sullivan0002e112015-08-26 15:14:16 -0400765 /* If speed didn't get set, set it to what it currently is.
766 * This is needed because if advertise is 0 (as it is when autoneg
767 * is disabled) then speed won't get set.
768 */
769 if (!config.link_speed)
770 config.link_speed = abilities.link_speed;
771
Catherine Sullivan124ed152014-07-12 07:28:12 +0000772 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000773 /* copy over the rest of the abilities */
774 config.phy_type = abilities.phy_type;
775 config.eee_capability = abilities.eee_capability;
776 config.eeer = abilities.eeer_val;
777 config.low_power_ctrl = abilities.d3_lpan;
778
Catherine Sullivane8278452015-02-06 08:52:08 +0000779 /* save the requested speeds */
780 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000781 /* set link and auto negotiation so changes take effect */
782 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
783 /* If link is up put link down */
784 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
785 /* Tell the OS link is going down, the link will go
786 * back up when fw says it is ready asynchronously
787 */
Matt Jaredc156f852015-08-27 11:42:39 -0400788 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000789 netif_carrier_off(netdev);
790 netif_tx_stop_all_queues(netdev);
791 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000792
793 /* make the aq call */
794 status = i40e_aq_set_phy_config(hw, &config, NULL);
795 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400796 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
797 i40e_stat_str(hw, status),
798 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000799 return -EAGAIN;
800 }
801
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400802 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000803 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400804 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
805 i40e_stat_str(hw, status),
806 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000807
808 } else {
809 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
810 }
811
812 return err;
813}
814
Jesse Brandeburga6599722014-06-04 08:45:25 +0000815static int i40e_nway_reset(struct net_device *netdev)
816{
817 /* restart autonegotiation */
818 struct i40e_netdev_priv *np = netdev_priv(netdev);
819 struct i40e_pf *pf = np->vsi->back;
820 struct i40e_hw *hw = &pf->hw;
821 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
822 i40e_status ret = 0;
823
824 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
825 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400826 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
827 i40e_stat_str(hw, ret),
828 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000829 return -EIO;
830 }
831
832 return 0;
833}
834
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000835/**
836 * i40e_get_pauseparam - Get Flow Control status
837 * Return tx/rx-pause status
838 **/
839static void i40e_get_pauseparam(struct net_device *netdev,
840 struct ethtool_pauseparam *pause)
841{
842 struct i40e_netdev_priv *np = netdev_priv(netdev);
843 struct i40e_pf *pf = np->vsi->back;
844 struct i40e_hw *hw = &pf->hw;
845 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000846 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000847
848 pause->autoneg =
849 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
850 AUTONEG_ENABLE : AUTONEG_DISABLE);
851
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000852 /* PFC enabled so report LFC as off */
853 if (dcbx_cfg->pfc.pfcenable) {
854 pause->rx_pause = 0;
855 pause->tx_pause = 0;
856 return;
857 }
858
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000859 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000860 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000861 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000862 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000863 } else if (hw->fc.current_mode == I40E_FC_FULL) {
864 pause->rx_pause = 1;
865 pause->tx_pause = 1;
866 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000867}
868
Catherine Sullivan2becc352014-06-04 08:45:27 +0000869/**
870 * i40e_set_pauseparam - Set Flow Control parameter
871 * @netdev: network interface device structure
872 * @pause: return tx/rx flow control status
873 **/
874static int i40e_set_pauseparam(struct net_device *netdev,
875 struct ethtool_pauseparam *pause)
876{
877 struct i40e_netdev_priv *np = netdev_priv(netdev);
878 struct i40e_pf *pf = np->vsi->back;
879 struct i40e_vsi *vsi = np->vsi;
880 struct i40e_hw *hw = &pf->hw;
881 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000882 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000883 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
884 i40e_status status;
885 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000886 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000887
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000888 /* Changing the port's flow control is not supported if this isn't the
889 * port's controlling PF
890 */
891 if (hw->partition_id != 1) {
892 i40e_partition_setting_complaint(pf);
893 return -EOPNOTSUPP;
894 }
895
Catherine Sullivan2becc352014-06-04 08:45:27 +0000896 if (vsi != pf->vsi[pf->lan_vsi])
897 return -EOPNOTSUPP;
898
899 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
900 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
901 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
902 return -EOPNOTSUPP;
903 }
904
905 /* If we have link and don't have autoneg */
906 if (!test_bit(__I40E_DOWN, &pf->state) &&
907 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
908 /* Send message that it might not necessarily work*/
909 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
910 }
911
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000912 if (dcbx_cfg->pfc.pfcenable) {
913 netdev_info(netdev,
914 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000915 return -EOPNOTSUPP;
916 }
917
918 if (pause->rx_pause && pause->tx_pause)
919 hw->fc.requested_mode = I40E_FC_FULL;
920 else if (pause->rx_pause && !pause->tx_pause)
921 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
922 else if (!pause->rx_pause && pause->tx_pause)
923 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
924 else if (!pause->rx_pause && !pause->tx_pause)
925 hw->fc.requested_mode = I40E_FC_NONE;
926 else
927 return -EINVAL;
928
Catherine Sullivan94128512014-07-12 07:28:16 +0000929 /* Tell the OS link is going down, the link will go back up when fw
930 * says it is ready asynchronously
931 */
Matt Jaredc156f852015-08-27 11:42:39 -0400932 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000933 netif_carrier_off(netdev);
934 netif_tx_stop_all_queues(netdev);
935
Catherine Sullivan2becc352014-06-04 08:45:27 +0000936 /* Set the fc mode and only restart an if link is up*/
937 status = i40e_set_fc(hw, &aq_failures, link_up);
938
939 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400940 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
941 i40e_stat_str(hw, status),
942 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000943 err = -EAGAIN;
944 }
945 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400946 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
947 i40e_stat_str(hw, status),
948 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000949 err = -EAGAIN;
950 }
951 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400952 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
953 i40e_stat_str(hw, status),
954 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000955 err = -EAGAIN;
956 }
957
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000958 if (!test_bit(__I40E_DOWN, &pf->state)) {
959 /* Give it a little more time to try to come back */
960 msleep(75);
961 if (!test_bit(__I40E_DOWN, &pf->state))
962 return i40e_nway_reset(netdev);
963 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000964
965 return err;
966}
967
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000968static u32 i40e_get_msglevel(struct net_device *netdev)
969{
970 struct i40e_netdev_priv *np = netdev_priv(netdev);
971 struct i40e_pf *pf = np->vsi->back;
972
973 return pf->msg_enable;
974}
975
976static void i40e_set_msglevel(struct net_device *netdev, u32 data)
977{
978 struct i40e_netdev_priv *np = netdev_priv(netdev);
979 struct i40e_pf *pf = np->vsi->back;
980
981 if (I40E_DEBUG_USER & data)
982 pf->hw.debug_mask = data;
983 pf->msg_enable = data;
984}
985
986static int i40e_get_regs_len(struct net_device *netdev)
987{
988 int reg_count = 0;
989 int i;
990
991 for (i = 0; i40e_reg_list[i].offset != 0; i++)
992 reg_count += i40e_reg_list[i].elements;
993
994 return reg_count * sizeof(u32);
995}
996
997static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
998 void *p)
999{
1000 struct i40e_netdev_priv *np = netdev_priv(netdev);
1001 struct i40e_pf *pf = np->vsi->back;
1002 struct i40e_hw *hw = &pf->hw;
1003 u32 *reg_buf = p;
1004 int i, j, ri;
1005 u32 reg;
1006
1007 /* Tell ethtool which driver-version-specific regs output we have.
1008 *
1009 * At some point, if we have ethtool doing special formatting of
1010 * this data, it will rely on this version number to know how to
1011 * interpret things. Hence, this needs to be updated if/when the
1012 * diags register table is changed.
1013 */
1014 regs->version = 1;
1015
1016 /* loop through the diags reg table for what to print */
1017 ri = 0;
1018 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1019 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1020 reg = i40e_reg_list[i].offset
1021 + (j * i40e_reg_list[i].stride);
1022 reg_buf[ri++] = rd32(hw, reg);
1023 }
1024 }
1025
1026}
1027
1028static int i40e_get_eeprom(struct net_device *netdev,
1029 struct ethtool_eeprom *eeprom, u8 *bytes)
1030{
1031 struct i40e_netdev_priv *np = netdev_priv(netdev);
1032 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001033 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001034 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001035 u8 *eeprom_buff;
1036 u16 i, sectors;
1037 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001038 u32 magic;
1039
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001040#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001041 if (eeprom->len == 0)
1042 return -EINVAL;
1043
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001044 /* check for NVMUpdate access method */
1045 magic = hw->vendor_id | (hw->device_id << 16);
1046 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001047 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1048 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001049
1050 /* make sure it is the right magic for NVMUpdate */
1051 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001052 errno = -EINVAL;
1053 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1054 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1055 errno = -EBUSY;
1056 else
1057 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001058
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001059 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001060 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001061 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1062 ret_val, hw->aq.asq_last_status, errno,
1063 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1064 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001065
1066 return errno;
1067 }
1068
1069 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001070 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1071
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001072 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073 if (!eeprom_buff)
1074 return -ENOMEM;
1075
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001076 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1077 if (ret_val) {
1078 dev_info(&pf->pdev->dev,
1079 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1080 ret_val, hw->aq.asq_last_status);
1081 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001082 }
1083
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001084 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1085 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1086 len = I40E_NVM_SECTOR_SIZE;
1087 last = false;
1088 for (i = 0; i < sectors; i++) {
1089 if (i == (sectors - 1)) {
1090 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1091 last = true;
1092 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001093 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1094 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001095 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001096 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001097 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001098 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001099 "read NVM failed, invalid offset 0x%x\n",
1100 offset);
1101 break;
1102 } else if (ret_val &&
1103 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1104 dev_info(&pf->pdev->dev,
1105 "read NVM failed, access, offset 0x%x\n",
1106 offset);
1107 break;
1108 } else if (ret_val) {
1109 dev_info(&pf->pdev->dev,
1110 "read NVM failed offset %d err=%d status=0x%x\n",
1111 offset, ret_val, hw->aq.asq_last_status);
1112 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001113 }
1114 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001115
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001116 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001117 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001118free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001119 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001120 return ret_val;
1121}
1122
1123static int i40e_get_eeprom_len(struct net_device *netdev)
1124{
1125 struct i40e_netdev_priv *np = netdev_priv(netdev);
1126 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001127 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001128
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001129 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1130 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1131 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1132 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001133 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001134 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001135}
1136
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001137static int i40e_set_eeprom(struct net_device *netdev,
1138 struct ethtool_eeprom *eeprom, u8 *bytes)
1139{
1140 struct i40e_netdev_priv *np = netdev_priv(netdev);
1141 struct i40e_hw *hw = &np->vsi->back->hw;
1142 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001143 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001144 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001145 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001146 u32 magic;
1147
1148 /* normal ethtool set_eeprom is not supported */
1149 magic = hw->vendor_id | (hw->device_id << 16);
1150 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001151 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001152 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001153 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1154 errno = -EINVAL;
1155 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1156 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1157 errno = -EBUSY;
1158 else
1159 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001160
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001161 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001162 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001163 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1164 ret_val, hw->aq.asq_last_status, errno,
1165 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1166 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001167
1168 return errno;
1169}
1170
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001171static void i40e_get_drvinfo(struct net_device *netdev,
1172 struct ethtool_drvinfo *drvinfo)
1173{
1174 struct i40e_netdev_priv *np = netdev_priv(netdev);
1175 struct i40e_vsi *vsi = np->vsi;
1176 struct i40e_pf *pf = vsi->back;
1177
1178 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1179 strlcpy(drvinfo->version, i40e_driver_version_str,
1180 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001181 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001182 sizeof(drvinfo->fw_version));
1183 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1184 sizeof(drvinfo->bus_info));
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001185 if (pf->hw.pf_id == 0)
1186 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_GL_STR_LEN;
1187 else
1188 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001189}
1190
1191static void i40e_get_ringparam(struct net_device *netdev,
1192 struct ethtool_ringparam *ring)
1193{
1194 struct i40e_netdev_priv *np = netdev_priv(netdev);
1195 struct i40e_pf *pf = np->vsi->back;
1196 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1197
1198 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1199 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1200 ring->rx_mini_max_pending = 0;
1201 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001202 ring->rx_pending = vsi->rx_rings[0]->count;
1203 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001204 ring->rx_mini_pending = 0;
1205 ring->rx_jumbo_pending = 0;
1206}
1207
1208static int i40e_set_ringparam(struct net_device *netdev,
1209 struct ethtool_ringparam *ring)
1210{
1211 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1212 struct i40e_netdev_priv *np = netdev_priv(netdev);
1213 struct i40e_vsi *vsi = np->vsi;
1214 struct i40e_pf *pf = vsi->back;
1215 u32 new_rx_count, new_tx_count;
1216 int i, err = 0;
1217
1218 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1219 return -EINVAL;
1220
Shannon Nelson1fa18372013-11-20 10:03:08 +00001221 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1222 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1223 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1224 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1225 netdev_info(netdev,
1226 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1227 ring->tx_pending, ring->rx_pending,
1228 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1229 return -EINVAL;
1230 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001231
Shannon Nelson1fa18372013-11-20 10:03:08 +00001232 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1233 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001234
1235 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001236 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1237 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001238 return 0;
1239
1240 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1241 usleep_range(1000, 2000);
1242
1243 if (!netif_running(vsi->netdev)) {
1244 /* simple case - set for the next time the netdev is started */
1245 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001246 vsi->tx_rings[i]->count = new_tx_count;
1247 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248 }
1249 goto done;
1250 }
1251
1252 /* We can't just free everything and then setup again,
1253 * because the ISRs in MSI-X mode get passed pointers
1254 * to the Tx and Rx ring structs.
1255 */
1256
1257 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001258 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001259 netdev_info(netdev,
1260 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001261 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001262 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1263 sizeof(struct i40e_ring), GFP_KERNEL);
1264 if (!tx_rings) {
1265 err = -ENOMEM;
1266 goto done;
1267 }
1268
1269 for (i = 0; i < vsi->num_queue_pairs; i++) {
1270 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001271 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001272 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001273 /* the desc and bi pointers will be reallocated in the
1274 * setup call
1275 */
1276 tx_rings[i].desc = NULL;
1277 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001278 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1279 if (err) {
1280 while (i) {
1281 i--;
1282 i40e_free_tx_resources(&tx_rings[i]);
1283 }
1284 kfree(tx_rings);
1285 tx_rings = NULL;
1286
1287 goto done;
1288 }
1289 }
1290 }
1291
1292 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001293 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001294 netdev_info(netdev,
1295 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001296 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001297 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1298 sizeof(struct i40e_ring), GFP_KERNEL);
1299 if (!rx_rings) {
1300 err = -ENOMEM;
1301 goto free_tx;
1302 }
1303
1304 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001305 /* this is to allow wr32 to have something to write to
1306 * during early allocation of Rx buffers
1307 */
1308 u32 __iomem faketail = 0;
1309 struct i40e_ring *ring;
1310 u16 unused;
1311
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001312 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001313 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001314 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001315 /* the desc and bi pointers will be reallocated in the
1316 * setup call
1317 */
1318 rx_rings[i].desc = NULL;
1319 rx_rings[i].rx_bi = NULL;
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001320 rx_rings[i].tail = (u8 __iomem *)&faketail;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001321 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001322 if (err)
1323 goto rx_unwind;
1324
1325 /* now allocate the Rx buffers to make sure the OS
1326 * has enough memory, any failure here means abort
1327 */
1328 ring = &rx_rings[i];
1329 unused = I40E_DESC_UNUSED(ring);
1330 err = i40e_alloc_rx_buffers(ring, unused);
1331rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001332 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001333 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001334 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001335 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001336 kfree(rx_rings);
1337 rx_rings = NULL;
1338
1339 goto free_tx;
1340 }
1341 }
1342 }
1343
1344 /* Bring interface down, copy in the new ring info,
1345 * then restore the interface
1346 */
1347 i40e_down(vsi);
1348
1349 if (tx_rings) {
1350 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001351 i40e_free_tx_resources(vsi->tx_rings[i]);
1352 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001353 }
1354 kfree(tx_rings);
1355 tx_rings = NULL;
1356 }
1357
1358 if (rx_rings) {
1359 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001360 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001361 /* get the real tail offset */
1362 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1363 /* this is to fake out the allocation routine
1364 * into thinking it has to realloc everything
1365 * but the recycling logic will let us re-use
1366 * the buffers allocated above
1367 */
1368 rx_rings[i].next_to_use = 0;
1369 rx_rings[i].next_to_clean = 0;
1370 rx_rings[i].next_to_alloc = 0;
1371 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001372 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001373 }
1374 kfree(rx_rings);
1375 rx_rings = NULL;
1376 }
1377
1378 i40e_up(vsi);
1379
1380free_tx:
1381 /* error cleanup if the Rx allocations failed after getting Tx */
1382 if (tx_rings) {
1383 for (i = 0; i < vsi->num_queue_pairs; i++)
1384 i40e_free_tx_resources(&tx_rings[i]);
1385 kfree(tx_rings);
1386 tx_rings = NULL;
1387 }
1388
1389done:
1390 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1391
1392 return err;
1393}
1394
1395static int i40e_get_sset_count(struct net_device *netdev, int sset)
1396{
1397 struct i40e_netdev_priv *np = netdev_priv(netdev);
1398 struct i40e_vsi *vsi = np->vsi;
1399 struct i40e_pf *pf = vsi->back;
1400
1401 switch (sset) {
1402 case ETH_SS_TEST:
1403 return I40E_TEST_LEN;
1404 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001405 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001406 int len = I40E_PF_STATS_LEN(netdev);
1407
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001408 if ((pf->lan_veb != I40E_NO_VEB) &&
1409 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001410 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001411 return len;
1412 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001413 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001414 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001415 case ETH_SS_PRIV_FLAGS:
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001416 if (pf->hw.pf_id == 0)
1417 return I40E_PRIV_FLAGS_GL_STR_LEN;
1418 else
1419 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 default:
1421 return -EOPNOTSUPP;
1422 }
1423}
1424
1425static void i40e_get_ethtool_stats(struct net_device *netdev,
1426 struct ethtool_stats *stats, u64 *data)
1427{
1428 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001429 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001430 struct i40e_vsi *vsi = np->vsi;
1431 struct i40e_pf *pf = vsi->back;
1432 int i = 0;
1433 char *p;
1434 int j;
1435 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001436 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001437
1438 i40e_update_stats(vsi);
1439
1440 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1441 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1442 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1443 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1444 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001445 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1446 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1447 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1448 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1449 }
Vasu Dev38e00432014-08-01 13:27:03 -07001450#ifdef I40E_FCOE
1451 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1452 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1453 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1454 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1455 }
1456#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001457 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001458 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001459 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001460
1461 if (!tx_ring)
1462 continue;
1463
1464 /* process Tx ring statistics */
1465 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001466 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001467 data[i] = tx_ring->stats.packets;
1468 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001469 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001470 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001471
1472 /* Rx ring is the 2nd half of the queue pair */
1473 rx_ring = &tx_ring[1];
1474 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001475 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001476 data[i] = rx_ring->stats.packets;
1477 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001478 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001479 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001481 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001482 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001483 return;
1484
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001485 if ((pf->lan_veb != I40E_NO_VEB) &&
1486 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001487 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001488
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001489 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1490 p = (char *)veb;
1491 p += i40e_gstrings_veb_stats[j].stat_offset;
1492 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1493 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001495 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1496 data[i++] = veb->tc_stats.tc_tx_packets[j];
1497 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1498 data[i++] = veb->tc_stats.tc_rx_packets[j];
1499 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1500 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001501 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001502 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1503 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1504 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1505 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1506 }
1507 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1508 data[i++] = pf->stats.priority_xon_tx[j];
1509 data[i++] = pf->stats.priority_xoff_tx[j];
1510 }
1511 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1512 data[i++] = pf->stats.priority_xon_rx[j];
1513 data[i++] = pf->stats.priority_xoff_rx[j];
1514 }
1515 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1516 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001517}
1518
1519static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1520 u8 *data)
1521{
1522 struct i40e_netdev_priv *np = netdev_priv(netdev);
1523 struct i40e_vsi *vsi = np->vsi;
1524 struct i40e_pf *pf = vsi->back;
1525 char *p = (char *)data;
1526 int i;
1527
1528 switch (stringset) {
1529 case ETH_SS_TEST:
1530 for (i = 0; i < I40E_TEST_LEN; i++) {
1531 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1532 data += ETH_GSTRING_LEN;
1533 }
1534 break;
1535 case ETH_SS_STATS:
1536 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1537 snprintf(p, ETH_GSTRING_LEN, "%s",
1538 i40e_gstrings_net_stats[i].stat_string);
1539 p += ETH_GSTRING_LEN;
1540 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001541 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1542 snprintf(p, ETH_GSTRING_LEN, "%s",
1543 i40e_gstrings_misc_stats[i].stat_string);
1544 p += ETH_GSTRING_LEN;
1545 }
Vasu Dev38e00432014-08-01 13:27:03 -07001546#ifdef I40E_FCOE
1547 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1548 snprintf(p, ETH_GSTRING_LEN, "%s",
1549 i40e_gstrings_fcoe_stats[i].stat_string);
1550 p += ETH_GSTRING_LEN;
1551 }
1552#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001553 for (i = 0; i < vsi->num_queue_pairs; i++) {
1554 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1555 p += ETH_GSTRING_LEN;
1556 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1557 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1559 p += ETH_GSTRING_LEN;
1560 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1561 p += ETH_GSTRING_LEN;
1562 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001563 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001564 return;
1565
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001566 if ((pf->lan_veb != I40E_NO_VEB) &&
1567 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001568 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1569 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1570 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571 p += ETH_GSTRING_LEN;
1572 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001573 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1574 snprintf(p, ETH_GSTRING_LEN,
1575 "veb.tc_%u_tx_packets", i);
1576 p += ETH_GSTRING_LEN;
1577 snprintf(p, ETH_GSTRING_LEN,
1578 "veb.tc_%u_tx_bytes", i);
1579 p += ETH_GSTRING_LEN;
1580 snprintf(p, ETH_GSTRING_LEN,
1581 "veb.tc_%u_rx_packets", i);
1582 p += ETH_GSTRING_LEN;
1583 snprintf(p, ETH_GSTRING_LEN,
1584 "veb.tc_%u_rx_bytes", i);
1585 p += ETH_GSTRING_LEN;
1586 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001587 }
1588 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1589 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1590 i40e_gstrings_stats[i].stat_string);
1591 p += ETH_GSTRING_LEN;
1592 }
1593 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1594 snprintf(p, ETH_GSTRING_LEN,
1595 "port.tx_priority_%u_xon", i);
1596 p += ETH_GSTRING_LEN;
1597 snprintf(p, ETH_GSTRING_LEN,
1598 "port.tx_priority_%u_xoff", i);
1599 p += ETH_GSTRING_LEN;
1600 }
1601 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1602 snprintf(p, ETH_GSTRING_LEN,
1603 "port.rx_priority_%u_xon", i);
1604 p += ETH_GSTRING_LEN;
1605 snprintf(p, ETH_GSTRING_LEN,
1606 "port.rx_priority_%u_xoff", i);
1607 p += ETH_GSTRING_LEN;
1608 }
1609 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1610 snprintf(p, ETH_GSTRING_LEN,
1611 "port.rx_priority_%u_xon_2_xoff", i);
1612 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001613 }
1614 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1615 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001616 case ETH_SS_PRIV_FLAGS:
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001617 if (pf->hw.pf_id == 0) {
1618 for (i = 0; i < I40E_PRIV_FLAGS_GL_STR_LEN; i++) {
1619 memcpy(data, i40e_priv_flags_strings_gl[i],
1620 ETH_GSTRING_LEN);
1621 data += ETH_GSTRING_LEN;
1622 }
1623 } else {
1624 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1625 memcpy(data, i40e_priv_flags_strings[i],
1626 ETH_GSTRING_LEN);
1627 data += ETH_GSTRING_LEN;
1628 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001629 }
1630 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001631 default:
1632 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633 }
1634}
1635
1636static int i40e_get_ts_info(struct net_device *dev,
1637 struct ethtool_ts_info *info)
1638{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001639 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1640
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001641 /* only report HW timestamping if PTP is enabled */
1642 if (!(pf->flags & I40E_FLAG_PTP))
1643 return ethtool_op_get_ts_info(dev, info);
1644
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001645 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1646 SOF_TIMESTAMPING_RX_SOFTWARE |
1647 SOF_TIMESTAMPING_SOFTWARE |
1648 SOF_TIMESTAMPING_TX_HARDWARE |
1649 SOF_TIMESTAMPING_RX_HARDWARE |
1650 SOF_TIMESTAMPING_RAW_HARDWARE;
1651
1652 if (pf->ptp_clock)
1653 info->phc_index = ptp_clock_index(pf->ptp_clock);
1654 else
1655 info->phc_index = -1;
1656
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001657 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001658
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001659 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1660 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1661 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001662
1663 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001664}
1665
Shannon Nelson7b086392013-11-20 10:02:59 +00001666static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667{
Shannon Nelson7b086392013-11-20 10:02:59 +00001668 struct i40e_netdev_priv *np = netdev_priv(netdev);
1669 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001670 i40e_status status;
1671 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001672
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001673 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001674 status = i40e_get_link_status(&pf->hw, &link_up);
1675 if (status) {
1676 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1677 *data = 1;
1678 return *data;
1679 }
1680
1681 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001682 *data = 0;
1683 else
1684 *data = 1;
1685
1686 return *data;
1687}
1688
Shannon Nelson7b086392013-11-20 10:02:59 +00001689static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001690{
Shannon Nelson7b086392013-11-20 10:02:59 +00001691 struct i40e_netdev_priv *np = netdev_priv(netdev);
1692 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001693
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001694 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001695 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001696
Shannon Nelson7b086392013-11-20 10:02:59 +00001697 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001698}
1699
Shannon Nelson7b086392013-11-20 10:02:59 +00001700static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001701{
Shannon Nelson7b086392013-11-20 10:02:59 +00001702 struct i40e_netdev_priv *np = netdev_priv(netdev);
1703 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001704
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001705 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001706 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001707
Shannon Nelson4443ec92014-11-13 08:23:12 +00001708 /* forcebly clear the NVM Update state machine */
1709 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1710
Shannon Nelson7b086392013-11-20 10:02:59 +00001711 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712}
1713
Shannon Nelson7b086392013-11-20 10:02:59 +00001714static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715{
Shannon Nelson7b086392013-11-20 10:02:59 +00001716 struct i40e_netdev_priv *np = netdev_priv(netdev);
1717 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001718 u16 swc_old = pf->sw_int_count;
1719
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001720 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001721 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1722 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001723 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1724 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1725 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1726 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001727 usleep_range(1000, 2000);
1728 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001729
1730 return *data;
1731}
1732
Shannon Nelson7b086392013-11-20 10:02:59 +00001733static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001734{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001735 struct i40e_netdev_priv *np = netdev_priv(netdev);
1736 struct i40e_pf *pf = np->vsi->back;
1737
1738 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001739 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001740
1741 return *data;
1742}
1743
Greg Rosee17bc412015-04-16 20:05:59 -04001744static inline bool i40e_active_vfs(struct i40e_pf *pf)
1745{
1746 struct i40e_vf *vfs = pf->vf;
1747 int i;
1748
1749 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001750 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001751 return true;
1752 return false;
1753}
1754
Greg Rose510efb22015-07-10 19:36:01 -04001755static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1756{
1757 struct i40e_vsi **vsi = pf->vsi;
1758 int i;
1759
1760 for (i = 0; i < pf->num_alloc_vsi; i++) {
1761 if (!vsi[i])
1762 continue;
1763 if (vsi[i]->type == I40E_VSI_VMDQ2)
1764 return true;
1765 }
1766
1767 return false;
1768}
1769
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001770static void i40e_diag_test(struct net_device *netdev,
1771 struct ethtool_test *eth_test, u64 *data)
1772{
1773 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001774 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001775 struct i40e_pf *pf = np->vsi->back;
1776
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001777 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1778 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001779 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001780
Shannon Nelsonf551b432013-11-26 10:49:12 +00001781 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001782
Greg Rose510efb22015-07-10 19:36:01 -04001783 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001784 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001785 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001786 data[I40E_ETH_TEST_REG] = 1;
1787 data[I40E_ETH_TEST_EEPROM] = 1;
1788 data[I40E_ETH_TEST_INTR] = 1;
1789 data[I40E_ETH_TEST_LOOPBACK] = 1;
1790 data[I40E_ETH_TEST_LINK] = 1;
1791 eth_test->flags |= ETH_TEST_FL_FAILED;
1792 clear_bit(__I40E_TESTING, &pf->state);
1793 goto skip_ol_tests;
1794 }
1795
Greg Rose5b86c5c2015-02-26 16:14:35 +00001796 /* If the device is online then take it offline */
1797 if (if_running)
1798 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001799 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001800 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001801 /* This reset does not affect link - if it is
1802 * changed to a type of reset that does affect
1803 * link then the following link test would have
1804 * to be moved to before the reset
1805 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001806 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001807
Shannon Nelson7b086392013-11-20 10:02:59 +00001808 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001809 eth_test->flags |= ETH_TEST_FL_FAILED;
1810
Shannon Nelson7b086392013-11-20 10:02:59 +00001811 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812 eth_test->flags |= ETH_TEST_FL_FAILED;
1813
Shannon Nelson7b086392013-11-20 10:02:59 +00001814 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001815 eth_test->flags |= ETH_TEST_FL_FAILED;
1816
Shannon Nelson7b086392013-11-20 10:02:59 +00001817 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818 eth_test->flags |= ETH_TEST_FL_FAILED;
1819
Shannon Nelsonf551b432013-11-26 10:49:12 +00001820 /* run reg test last, a reset is required after it */
1821 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1822 eth_test->flags |= ETH_TEST_FL_FAILED;
1823
1824 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001825 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001826
1827 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001828 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001830 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001831 netif_info(pf, drv, netdev, "online testing starting\n");
1832
Shannon Nelson7b086392013-11-20 10:02:59 +00001833 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001834 eth_test->flags |= ETH_TEST_FL_FAILED;
1835
1836 /* Offline only tests, not run in online; pass by default */
1837 data[I40E_ETH_TEST_REG] = 0;
1838 data[I40E_ETH_TEST_EEPROM] = 0;
1839 data[I40E_ETH_TEST_INTR] = 0;
1840 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001841 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001842
Greg Rosee17bc412015-04-16 20:05:59 -04001843skip_ol_tests:
1844
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001845 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001846}
1847
1848static void i40e_get_wol(struct net_device *netdev,
1849 struct ethtool_wolinfo *wol)
1850{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001851 struct i40e_netdev_priv *np = netdev_priv(netdev);
1852 struct i40e_pf *pf = np->vsi->back;
1853 struct i40e_hw *hw = &pf->hw;
1854 u16 wol_nvm_bits;
1855
1856 /* NVM bit on means WoL disabled for the port */
1857 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001858 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001859 wol->supported = 0;
1860 wol->wolopts = 0;
1861 } else {
1862 wol->supported = WAKE_MAGIC;
1863 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1864 }
1865}
1866
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001867/**
1868 * i40e_set_wol - set the WakeOnLAN configuration
1869 * @netdev: the netdev in question
1870 * @wol: the ethtool WoL setting data
1871 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001872static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1873{
1874 struct i40e_netdev_priv *np = netdev_priv(netdev);
1875 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001876 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001877 struct i40e_hw *hw = &pf->hw;
1878 u16 wol_nvm_bits;
1879
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001880 /* WoL not supported if this isn't the controlling PF on the port */
1881 if (hw->partition_id != 1) {
1882 i40e_partition_setting_complaint(pf);
1883 return -EOPNOTSUPP;
1884 }
1885
1886 if (vsi != pf->vsi[pf->lan_vsi])
1887 return -EOPNOTSUPP;
1888
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001889 /* NVM bit on means WoL disabled for the port */
1890 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001891 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001892 return -EOPNOTSUPP;
1893
1894 /* only magic packet is supported */
1895 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1896 return -EOPNOTSUPP;
1897
1898 /* is this a new value? */
1899 if (pf->wol_en != !!wol->wolopts) {
1900 pf->wol_en = !!wol->wolopts;
1901 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1902 }
1903
1904 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001905}
1906
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001907static int i40e_set_phys_id(struct net_device *netdev,
1908 enum ethtool_phys_id_state state)
1909{
1910 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001911 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001912 struct i40e_pf *pf = np->vsi->back;
1913 struct i40e_hw *hw = &pf->hw;
1914 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001915 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001916
1917 switch (state) {
1918 case ETHTOOL_ID_ACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001919 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1920 pf->led_status = i40e_led_get(hw);
1921 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001922 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001923 ret = i40e_led_get_phy(hw, &temp_status,
1924 &pf->phy_led_val);
1925 pf->led_status = temp_status;
1926 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001927 return blink_freq;
1928 case ETHTOOL_ID_ON:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001929 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1930 i40e_led_set(hw, 0xf, false);
1931 else
1932 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001933 break;
1934 case ETHTOOL_ID_OFF:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001935 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1936 i40e_led_set(hw, 0x0, false);
1937 else
1938 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939 break;
1940 case ETHTOOL_ID_INACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001941 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1942 i40e_led_set(hw, false, pf->led_status);
1943 } else {
1944 ret = i40e_led_set_phy(hw, false, pf->led_status,
1945 (pf->phy_led_val |
1946 I40E_PHY_LED_MODE_ORIG));
1947 i40e_aq_set_phy_debug(hw, 0, NULL);
1948 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001949 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001950 default:
1951 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001952 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001953 if (ret)
1954 return -ENOENT;
1955 else
1956 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001957}
1958
1959/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1960 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1961 * 125us (8000 interrupts per second) == ITR(62)
1962 */
1963
Kan Lianga75e8002016-02-19 09:24:04 -05001964static int __i40e_get_coalesce(struct net_device *netdev,
1965 struct ethtool_coalesce *ec,
1966 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001967{
1968 struct i40e_netdev_priv *np = netdev_priv(netdev);
1969 struct i40e_vsi *vsi = np->vsi;
1970
1971 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1972 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1973
Kan Lianga75e8002016-02-19 09:24:04 -05001974 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
1975 * return queue 0's value to represent.
1976 */
1977 if (queue < 0) {
1978 queue = 0;
1979 } else if (queue >= vsi->num_queue_pairs) {
1980 return -EINVAL;
1981 }
1982
1983 if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001984 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001985
Kan Lianga75e8002016-02-19 09:24:04 -05001986 if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001987 ec->use_adaptive_tx_coalesce = 1;
1988
Kan Lianga75e8002016-02-19 09:24:04 -05001989 ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1990 ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1991
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001992 /* we use the _usecs_high to store/set the interrupt rate limit
1993 * that the hardware supports, that almost but not quite
1994 * fits the original intent of the ethtool variable,
1995 * the rx_coalesce_usecs_high limits total interrupts
1996 * per second from both tx/rx sources.
1997 */
1998 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1999 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002000
2001 return 0;
2002}
2003
Kan Lianga75e8002016-02-19 09:24:04 -05002004static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002005 struct ethtool_coalesce *ec)
2006{
Kan Lianga75e8002016-02-19 09:24:04 -05002007 return __i40e_get_coalesce(netdev, ec, -1);
2008}
2009
Kan Liangbe280ba2016-02-19 09:24:05 -05002010static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2011 struct ethtool_coalesce *ec)
2012{
2013 return __i40e_get_coalesce(netdev, ec, queue);
2014}
2015
Kan Lianga75e8002016-02-19 09:24:04 -05002016static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2017 struct ethtool_coalesce *ec,
2018 int queue)
2019{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002020 struct i40e_pf *pf = vsi->back;
2021 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002022 struct i40e_q_vector *q_vector;
2023 u16 vector, intrl;
2024
2025 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
2026
2027 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2028 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2029
2030 if (ec->use_adaptive_rx_coalesce)
2031 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2032 else
2033 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2034
2035 if (ec->use_adaptive_tx_coalesce)
2036 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2037 else
2038 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2039
2040 q_vector = vsi->rx_rings[queue]->q_vector;
2041 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2042 vector = vsi->base_vector + q_vector->v_idx;
2043 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2044
2045 q_vector = vsi->tx_rings[queue]->q_vector;
2046 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2047 vector = vsi->base_vector + q_vector->v_idx;
2048 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2049
2050 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2051 i40e_flush(hw);
2052}
2053
2054static int __i40e_set_coalesce(struct net_device *netdev,
2055 struct ethtool_coalesce *ec,
2056 int queue)
2057{
2058 struct i40e_netdev_priv *np = netdev_priv(netdev);
2059 struct i40e_vsi *vsi = np->vsi;
2060 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002061 int i;
2062
2063 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2064 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2065
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002066 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2067 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2068 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2069 return -EINVAL;
2070 }
2071
2072 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2073 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
2074 return -EINVAL;
2075 }
2076
Kan Lianga75e8002016-02-19 09:24:04 -05002077 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002078 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002079 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 -05002080 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2081 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2082 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2083 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002084 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002085
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002086 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
2087
Kan Lianga75e8002016-02-19 09:24:04 -05002088 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002089 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002090 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 -05002091 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2092 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2093 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2094 return -EINVAL;
2095 }
2096
2097 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2098 * apply to all queues.
2099 */
2100 if (queue < 0) {
2101 for (i = 0; i < vsi->num_queue_pairs; i++)
2102 i40e_set_itr_per_queue(vsi, ec, i);
2103 } else if (queue < vsi->num_queue_pairs) {
2104 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002105 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002106 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2107 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002108 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002109 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002110
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002111 return 0;
2112}
2113
Kan Lianga75e8002016-02-19 09:24:04 -05002114static int i40e_set_coalesce(struct net_device *netdev,
2115 struct ethtool_coalesce *ec)
2116{
2117 return __i40e_set_coalesce(netdev, ec, -1);
2118}
2119
Kan Liangf3757a42016-02-19 09:24:06 -05002120static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2121 struct ethtool_coalesce *ec)
2122{
2123 return __i40e_set_coalesce(netdev, ec, queue);
2124}
2125
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002126/**
2127 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2128 * @pf: pointer to the physical function struct
2129 * @cmd: ethtool rxnfc command
2130 *
2131 * Returns Success if the flow is supported, else Invalid Input.
2132 **/
2133static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2134{
2135 cmd->data = 0;
2136
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002137 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
2138 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
2139 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
2140 return 0;
2141 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142 /* Report default options for RSS on i40e */
2143 switch (cmd->flow_type) {
2144 case TCP_V4_FLOW:
2145 case UDP_V4_FLOW:
2146 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2147 /* fall through to add IP fields */
2148 case SCTP_V4_FLOW:
2149 case AH_ESP_V4_FLOW:
2150 case AH_V4_FLOW:
2151 case ESP_V4_FLOW:
2152 case IPV4_FLOW:
2153 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2154 break;
2155 case TCP_V6_FLOW:
2156 case UDP_V6_FLOW:
2157 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2158 /* fall through to add IP fields */
2159 case SCTP_V6_FLOW:
2160 case AH_ESP_V6_FLOW:
2161 case AH_V6_FLOW:
2162 case ESP_V6_FLOW:
2163 case IPV6_FLOW:
2164 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2165 break;
2166 default:
2167 return -EINVAL;
2168 }
2169
2170 return 0;
2171}
2172
2173/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002174 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2175 * @pf: Pointer to the physical function struct
2176 * @cmd: The command to get or set Rx flow classification rules
2177 * @rule_locs: Array of used rule locations
2178 *
2179 * This function populates both the total and actual rule count of
2180 * the ethtool flow classification command
2181 *
2182 * Returns 0 on success or -EMSGSIZE if entry not found
2183 **/
2184static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2185 struct ethtool_rxnfc *cmd,
2186 u32 *rule_locs)
2187{
2188 struct i40e_fdir_filter *rule;
2189 struct hlist_node *node2;
2190 int cnt = 0;
2191
2192 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002193 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002194
2195 hlist_for_each_entry_safe(rule, node2,
2196 &pf->fdir_filter_list, fdir_node) {
2197 if (cnt == cmd->rule_cnt)
2198 return -EMSGSIZE;
2199
2200 rule_locs[cnt] = rule->fd_id;
2201 cnt++;
2202 }
2203
2204 cmd->rule_cnt = cnt;
2205
2206 return 0;
2207}
2208
2209/**
2210 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2211 * @pf: Pointer to the physical function struct
2212 * @cmd: The command to get or set Rx flow classification rules
2213 *
2214 * This function looks up a filter based on the Rx flow classification
2215 * command and fills the flow spec info for it if found
2216 *
2217 * Returns 0 on success or -EINVAL if filter not found
2218 **/
2219static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2220 struct ethtool_rxnfc *cmd)
2221{
2222 struct ethtool_rx_flow_spec *fsp =
2223 (struct ethtool_rx_flow_spec *)&cmd->fs;
2224 struct i40e_fdir_filter *rule = NULL;
2225 struct hlist_node *node2;
2226
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002227 hlist_for_each_entry_safe(rule, node2,
2228 &pf->fdir_filter_list, fdir_node) {
2229 if (fsp->location <= rule->fd_id)
2230 break;
2231 }
2232
2233 if (!rule || fsp->location != rule->fd_id)
2234 return -EINVAL;
2235
2236 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002237 if (fsp->flow_type == IP_USER_FLOW) {
2238 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2239 fsp->h_u.usr_ip4_spec.proto = 0;
2240 fsp->m_u.usr_ip4_spec.proto = 0;
2241 }
2242
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002243 /* Reverse the src and dest notion, since the HW views them from
2244 * Tx perspective where as the user expects it from Rx filter view.
2245 */
2246 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2247 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2248 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2249 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002250
2251 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2252 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2253 else
2254 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002255
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002256 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2257 struct i40e_vsi *vsi;
2258
2259 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2260 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2261 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2262 fsp->m_ext.data[1] = htonl(0x1);
2263 }
2264 }
2265
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002266 return 0;
2267}
2268
2269/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002270 * i40e_get_rxnfc - command to get RX flow classification rules
2271 * @netdev: network interface device structure
2272 * @cmd: ethtool rxnfc command
2273 *
2274 * Returns Success if the command is supported.
2275 **/
2276static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2277 u32 *rule_locs)
2278{
2279 struct i40e_netdev_priv *np = netdev_priv(netdev);
2280 struct i40e_vsi *vsi = np->vsi;
2281 struct i40e_pf *pf = vsi->back;
2282 int ret = -EOPNOTSUPP;
2283
2284 switch (cmd->cmd) {
2285 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002286 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002287 ret = 0;
2288 break;
2289 case ETHTOOL_GRXFH:
2290 ret = i40e_get_rss_hash_opts(pf, cmd);
2291 break;
2292 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002293 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002294 /* report total rule count */
2295 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002296 ret = 0;
2297 break;
2298 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002299 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002300 break;
2301 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002302 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2303 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002304 default:
2305 break;
2306 }
2307
2308 return ret;
2309}
2310
2311/**
2312 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2313 * @pf: pointer to the physical function struct
2314 * @cmd: ethtool rxnfc command
2315 *
2316 * Returns Success if the flow input set is supported.
2317 **/
2318static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2319{
2320 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002321 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2322 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002323
2324 /* RSS does not support anything other than hashing
2325 * to queues on src and dst IPs and ports
2326 */
2327 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2328 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2329 return -EINVAL;
2330
2331 /* We need at least the IP SRC and DEST fields for hashing */
2332 if (!(nfc->data & RXH_IP_SRC) ||
2333 !(nfc->data & RXH_IP_DST))
2334 return -EINVAL;
2335
2336 switch (nfc->flow_type) {
2337 case TCP_V4_FLOW:
2338 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2339 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002340 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002341 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002342 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2343 hena |=
2344 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2345
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002346 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002347 break;
2348 default:
2349 return -EINVAL;
2350 }
2351 break;
2352 case TCP_V6_FLOW:
2353 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2354 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002355 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002356 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002357 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2358 hena |=
2359 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2360
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002361 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002362 break;
2363 default:
2364 return -EINVAL;
2365 }
2366 break;
2367 case UDP_V4_FLOW:
2368 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2369 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002370 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002371 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002372 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2373 hena |=
2374 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2375 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2376
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002377 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2378 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002379 break;
2380 default:
2381 return -EINVAL;
2382 }
2383 break;
2384 case UDP_V6_FLOW:
2385 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2386 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002387 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002388 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002389 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2390 hena |=
2391 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2392 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2393
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002394 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2395 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002396 break;
2397 default:
2398 return -EINVAL;
2399 }
2400 break;
2401 case AH_ESP_V4_FLOW:
2402 case AH_V4_FLOW:
2403 case ESP_V4_FLOW:
2404 case SCTP_V4_FLOW:
2405 if ((nfc->data & RXH_L4_B_0_1) ||
2406 (nfc->data & RXH_L4_B_2_3))
2407 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002408 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002409 break;
2410 case AH_ESP_V6_FLOW:
2411 case AH_V6_FLOW:
2412 case ESP_V6_FLOW:
2413 case SCTP_V6_FLOW:
2414 if ((nfc->data & RXH_L4_B_0_1) ||
2415 (nfc->data & RXH_L4_B_2_3))
2416 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002417 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002418 break;
2419 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002420 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2421 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002422 break;
2423 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002424 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2425 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002426 break;
2427 default:
2428 return -EINVAL;
2429 }
2430
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002431 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2432 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002433 i40e_flush(hw);
2434
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002435 /* Save setting for future output/update */
2436 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2437
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002438 return 0;
2439}
2440
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002441/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002442 * i40e_match_fdir_input_set - Match a new filter against an existing one
2443 * @rule: The filter already added
2444 * @input: The new filter to comapre against
2445 *
2446 * Returns true if the two input set match
2447 **/
2448static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2449 struct i40e_fdir_filter *input)
2450{
2451 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2452 (rule->src_ip[0] != input->src_ip[0]) ||
2453 (rule->dst_port != input->dst_port) ||
2454 (rule->src_port != input->src_port))
2455 return false;
2456 return true;
2457}
2458
2459/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002460 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2461 * @vsi: Pointer to the targeted VSI
2462 * @input: The filter to update or NULL to indicate deletion
2463 * @sw_idx: Software index to the filter
2464 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002465 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002466 * This function updates (or deletes) a Flow Director entry from
2467 * the hlist of the corresponding PF
2468 *
2469 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002470 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002471static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2472 struct i40e_fdir_filter *input,
2473 u16 sw_idx,
2474 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002475{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002476 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002477 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002478 struct hlist_node *node2;
2479 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002480
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002481 parent = NULL;
2482 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002483
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002484 hlist_for_each_entry_safe(rule, node2,
2485 &pf->fdir_filter_list, fdir_node) {
2486 /* hash found, or no matching entry */
2487 if (rule->fd_id >= sw_idx)
2488 break;
2489 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002490 }
2491
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002492 /* if there is an old rule occupying our place remove it */
2493 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002494 if (input && !i40e_match_fdir_input_set(rule, input))
2495 err = i40e_add_del_fdir(vsi, rule, false);
2496 else if (!input)
2497 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002498 hlist_del(&rule->fdir_node);
2499 kfree(rule);
2500 pf->fdir_pf_active_filters--;
2501 }
2502
2503 /* If no input this was a delete, err should be 0 if a rule was
2504 * successfully found and removed from the list else -EINVAL
2505 */
2506 if (!input)
2507 return err;
2508
2509 /* initialize node and set software index */
2510 INIT_HLIST_NODE(&input->fdir_node);
2511
2512 /* add filter to the list */
2513 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002514 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002515 else
2516 hlist_add_head(&input->fdir_node,
2517 &pf->fdir_filter_list);
2518
2519 /* update counts */
2520 pf->fdir_pf_active_filters++;
2521
2522 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002523}
2524
2525/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002526 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2527 * @vsi: Pointer to the targeted VSI
2528 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002529 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002530 * The function removes a Flow Director filter entry from the
2531 * hlist of the corresponding PF
2532 *
2533 * Returns 0 on success
2534 */
2535static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2536 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002537{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002538 struct ethtool_rx_flow_spec *fsp =
2539 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002540 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002541 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002542
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002543 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2544 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2545 return -EBUSY;
2546
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002547 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2548 return -EBUSY;
2549
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002550 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002551
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002552 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002553 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002554}
2555
2556/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002557 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002558 * @vsi: pointer to the targeted VSI
2559 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002560 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002561 * Add Flow Director filters for a specific flow spec based on their
2562 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002563 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002564static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2565 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002566{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002567 struct ethtool_rx_flow_spec *fsp;
2568 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002569 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002570 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002571 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002572
2573 if (!vsi)
2574 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002575 pf = vsi->back;
2576
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002577 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2578 return -EOPNOTSUPP;
2579
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002580 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002581 return -ENOSPC;
2582
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002583 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2584 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2585 return -EBUSY;
2586
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002587 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2588 return -EBUSY;
2589
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002590 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2591
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002592 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2593 pf->hw.func_caps.fd_filters_guaranteed)) {
2594 return -EINVAL;
2595 }
2596
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002597 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2598 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002599 return -EINVAL;
2600
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002601 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002602
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002603 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002604 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002605
2606 input->fd_id = fsp->location;
2607
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002608 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2609 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2610 else
2611 input->dest_ctl =
2612 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2613
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002614 input->q_index = fsp->ring_cookie;
2615 input->flex_off = 0;
2616 input->pctype = 0;
2617 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002618 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002619 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002620 input->flow_type = fsp->flow_type;
2621 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002622
2623 /* Reverse the src and dest notion, since the HW expects them to be from
2624 * Tx perspective where as the input from user is from Rx filter view.
2625 */
2626 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2627 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2628 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2629 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002630
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002631 if (ntohl(fsp->m_ext.data[1])) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002632 vf_id = ntohl(fsp->h_ext.data[1]);
2633 if (vf_id >= pf->num_alloc_vfs) {
2634 netif_info(pf, drv, vsi->netdev,
2635 "Invalid VF id %d\n", vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002636 goto free_input;
2637 }
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002638 /* Find vsi id from vf id and override dest vsi */
2639 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2640 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002641 netif_info(pf, drv, vsi->netdev,
2642 "Invalid queue id %d for VF %d\n",
2643 input->q_index, vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002644 goto free_input;
2645 }
2646 }
2647
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002648 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002649free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002650 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002651 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002652 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002653 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002654
2655 return ret;
2656}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002657
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002658/**
2659 * i40e_set_rxnfc - command to set RX flow classification rules
2660 * @netdev: network interface device structure
2661 * @cmd: ethtool rxnfc command
2662 *
2663 * Returns Success if the command is supported.
2664 **/
2665static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2666{
2667 struct i40e_netdev_priv *np = netdev_priv(netdev);
2668 struct i40e_vsi *vsi = np->vsi;
2669 struct i40e_pf *pf = vsi->back;
2670 int ret = -EOPNOTSUPP;
2671
2672 switch (cmd->cmd) {
2673 case ETHTOOL_SRXFH:
2674 ret = i40e_set_rss_hash_opt(pf, cmd);
2675 break;
2676 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002677 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002678 break;
2679 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002680 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002681 break;
2682 default:
2683 break;
2684 }
2685
2686 return ret;
2687}
2688
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002689/**
2690 * i40e_max_channels - get Max number of combined channels supported
2691 * @vsi: vsi pointer
2692 **/
2693static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2694{
2695 /* TODO: This code assumes DCB and FD is disabled for now. */
2696 return vsi->alloc_queue_pairs;
2697}
2698
2699/**
2700 * i40e_get_channels - Get the current channels enabled and max supported etc.
2701 * @netdev: network interface device structure
2702 * @ch: ethtool channels structure
2703 *
2704 * We don't support separate tx and rx queues as channels. The other count
2705 * represents how many queues are being used for control. max_combined counts
2706 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2707 * q_vectors since we support a lot more queue pairs than q_vectors.
2708 **/
2709static void i40e_get_channels(struct net_device *dev,
2710 struct ethtool_channels *ch)
2711{
2712 struct i40e_netdev_priv *np = netdev_priv(dev);
2713 struct i40e_vsi *vsi = np->vsi;
2714 struct i40e_pf *pf = vsi->back;
2715
2716 /* report maximum channels */
2717 ch->max_combined = i40e_max_channels(vsi);
2718
2719 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002720 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002721 ch->max_other = ch->other_count;
2722
2723 /* Note: This code assumes DCB is disabled for now. */
2724 ch->combined_count = vsi->num_queue_pairs;
2725}
2726
2727/**
2728 * i40e_set_channels - Set the new channels count.
2729 * @netdev: network interface device structure
2730 * @ch: ethtool channels structure
2731 *
2732 * The new channels count may not be the same as requested by the user
2733 * since it gets rounded down to a power of 2 value.
2734 **/
2735static int i40e_set_channels(struct net_device *dev,
2736 struct ethtool_channels *ch)
2737{
2738 struct i40e_netdev_priv *np = netdev_priv(dev);
2739 unsigned int count = ch->combined_count;
2740 struct i40e_vsi *vsi = np->vsi;
2741 struct i40e_pf *pf = vsi->back;
2742 int new_count;
2743
2744 /* We do not support setting channels for any other VSI at present */
2745 if (vsi->type != I40E_VSI_MAIN)
2746 return -EINVAL;
2747
2748 /* verify they are not requesting separate vectors */
2749 if (!count || ch->rx_count || ch->tx_count)
2750 return -EINVAL;
2751
2752 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002753 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002754 return -EINVAL;
2755
2756 /* verify the number of channels does not exceed hardware limits */
2757 if (count > i40e_max_channels(vsi))
2758 return -EINVAL;
2759
2760 /* update feature limits from largest to smallest supported values */
2761 /* TODO: Flow director limit, DCB etc */
2762
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002763 /* use rss_reconfig to rebuild with new queue count and update traffic
2764 * class queue mapping
2765 */
2766 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002767 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002768 return 0;
2769 else
2770 return -EINVAL;
2771}
2772
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002773/**
2774 * i40e_get_rxfh_key_size - get the RSS hash key size
2775 * @netdev: network interface device structure
2776 *
2777 * Returns the table size.
2778 **/
2779static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2780{
2781 return I40E_HKEY_ARRAY_SIZE;
2782}
2783
2784/**
2785 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2786 * @netdev: network interface device structure
2787 *
2788 * Returns the table size.
2789 **/
2790static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2791{
2792 return I40E_HLUT_ARRAY_SIZE;
2793}
2794
2795static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2796 u8 *hfunc)
2797{
2798 struct i40e_netdev_priv *np = netdev_priv(netdev);
2799 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002800 u8 *lut, *seed = NULL;
2801 int ret;
2802 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002803
2804 if (hfunc)
2805 *hfunc = ETH_RSS_HASH_TOP;
2806
2807 if (!indir)
2808 return 0;
2809
Helin Zhang043dd652015-10-21 19:56:23 -04002810 seed = key;
2811 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2812 if (!lut)
2813 return -ENOMEM;
2814 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2815 if (ret)
2816 goto out;
2817 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2818 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002819
Helin Zhang043dd652015-10-21 19:56:23 -04002820out:
2821 kfree(lut);
2822
2823 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002824}
2825
2826/**
2827 * i40e_set_rxfh - set the rx flow hash indirection table
2828 * @netdev: network interface device structure
2829 * @indir: indirection table
2830 * @key: hash key
2831 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002832 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002833 * returns 0 after programming the table.
2834 **/
2835static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2836 const u8 *key, const u8 hfunc)
2837{
2838 struct i40e_netdev_priv *np = netdev_priv(netdev);
2839 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002840 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002841 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002842
2843 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2844 return -EOPNOTSUPP;
2845
2846 if (!indir)
2847 return 0;
2848
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002849 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002850 if (!vsi->rss_hkey_user) {
2851 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2852 GFP_KERNEL);
2853 if (!vsi->rss_hkey_user)
2854 return -ENOMEM;
2855 }
2856 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2857 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002858 }
Helin Zhang28c58692015-10-26 19:44:27 -04002859 if (!vsi->rss_lut_user) {
2860 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2861 if (!vsi->rss_lut_user)
2862 return -ENOMEM;
2863 }
Helin Zhang043dd652015-10-21 19:56:23 -04002864
Helin Zhang28c58692015-10-26 19:44:27 -04002865 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2866 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2867 vsi->rss_lut_user[i] = (u8)(indir[i]);
2868
2869 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2870 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002871}
2872
Greg Rose7e45ab42015-02-06 08:52:19 +00002873/**
2874 * i40e_get_priv_flags - report device private flags
2875 * @dev: network interface device structure
2876 *
2877 * The get string set count and the string set should be matched for each
2878 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2879 * array.
2880 *
2881 * Returns a u32 bitmap of flags.
2882 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002883static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002884{
2885 struct i40e_netdev_priv *np = netdev_priv(dev);
2886 struct i40e_vsi *vsi = np->vsi;
2887 struct i40e_pf *pf = vsi->back;
2888 u32 ret_flags = 0;
2889
Shannon Nelson9ac77262015-08-27 11:42:40 -04002890 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2891 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002892 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2893 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002894 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2895 I40E_PRIV_FLAGS_VEB_STATS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002896 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
2897 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002898 if (pf->hw.pf_id == 0) {
2899 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
2900 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
2901 }
Greg Rose7e45ab42015-02-06 08:52:19 +00002902
2903 return ret_flags;
2904}
2905
Shannon Nelson9ac77262015-08-27 11:42:40 -04002906/**
2907 * i40e_set_priv_flags - set private flags
2908 * @dev: network interface device structure
2909 * @flags: bit flags to be set
2910 **/
2911static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2912{
2913 struct i40e_netdev_priv *np = netdev_priv(dev);
2914 struct i40e_vsi *vsi = np->vsi;
2915 struct i40e_pf *pf = vsi->back;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002916 u16 sw_flags = 0, valid_flags = 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002917 bool reset_required = false;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002918 bool promisc_change = false;
2919 int ret;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002920
2921 /* NOTE: MFP is not settable */
2922
Shannon Nelson9ac77262015-08-27 11:42:40 -04002923 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2924 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2925 else
2926 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2927
Jesse Brandeburgef171782015-09-03 17:18:49 -04002928 /* allow the user to control the state of the Flow
2929 * Director ATR (Application Targeted Routing) feature
2930 * of the driver
2931 */
2932 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2933 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2934 } else {
2935 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2936 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2937 }
2938
Shannon Nelson66fc3602016-01-13 16:51:42 -08002939 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2940 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002941 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002942 reset_required = true;
2943 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2944 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002945 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002946 reset_required = true;
2947 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002948
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002949 if (pf->hw.pf_id == 0) {
2950 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
2951 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
2952 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
2953 promisc_change = true;
2954 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
2955 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
2956 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
2957 promisc_change = true;
2958 }
2959 }
2960 if (promisc_change) {
2961 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
2962 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
2963 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
2964 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
2965 NULL);
2966 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
2967 dev_info(&pf->pdev->dev,
2968 "couldn't set switch config bits, err %s aq_err %s\n",
2969 i40e_stat_str(&pf->hw, ret),
2970 i40e_aq_str(&pf->hw,
2971 pf->hw.aq.asq_last_status));
2972 /* not a fatal problem, just keep going */
2973 }
2974 }
2975
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002976 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
2977 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
2978 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2979 else
2980 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2981
Jesse Brandeburg827de392015-11-06 15:26:07 -08002982 /* if needed, issue reset to cause things to take effect */
2983 if (reset_required)
2984 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2985
Shannon Nelson9ac77262015-08-27 11:42:40 -04002986 return 0;
2987}
2988
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002989static const struct ethtool_ops i40e_ethtool_ops = {
2990 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002991 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002992 .get_drvinfo = i40e_get_drvinfo,
2993 .get_regs_len = i40e_get_regs_len,
2994 .get_regs = i40e_get_regs,
2995 .nway_reset = i40e_nway_reset,
2996 .get_link = ethtool_op_get_link,
2997 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002998 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002999 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003000 .get_eeprom_len = i40e_get_eeprom_len,
3001 .get_eeprom = i40e_get_eeprom,
3002 .get_ringparam = i40e_get_ringparam,
3003 .set_ringparam = i40e_set_ringparam,
3004 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00003005 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003006 .get_msglevel = i40e_get_msglevel,
3007 .set_msglevel = i40e_set_msglevel,
3008 .get_rxnfc = i40e_get_rxnfc,
3009 .set_rxnfc = i40e_set_rxnfc,
3010 .self_test = i40e_diag_test,
3011 .get_strings = i40e_get_strings,
3012 .set_phys_id = i40e_set_phys_id,
3013 .get_sset_count = i40e_get_sset_count,
3014 .get_ethtool_stats = i40e_get_ethtool_stats,
3015 .get_coalesce = i40e_get_coalesce,
3016 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003017 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3018 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3019 .get_rxfh = i40e_get_rxfh,
3020 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003021 .get_channels = i40e_get_channels,
3022 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003023 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00003024 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04003025 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05003026 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05003027 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003028};
3029
3030void i40e_set_ethtool_ops(struct net_device *netdev)
3031{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003032 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003033}