blob: 4962e855fbd372b12adb30fafb8541d6c3c1b6f8 [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 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700316 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700317 *supported |= SUPPORTED_Autoneg |
318 SUPPORTED_100baseT_Full;
319 *advertising |= ADVERTISED_Autoneg |
320 ADVERTISED_100baseT_Full;
321 }
322 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
323 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
324 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
325 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
326 *supported |= SUPPORTED_Autoneg |
327 SUPPORTED_1000baseT_Full;
328 *advertising |= ADVERTISED_Autoneg |
329 ADVERTISED_1000baseT_Full;
330 }
331 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
332 *supported |= SUPPORTED_40000baseSR4_Full;
333 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
334 *supported |= SUPPORTED_40000baseLR4_Full;
335 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
336 *supported |= SUPPORTED_40000baseKR4_Full |
337 SUPPORTED_Autoneg;
338 *advertising |= ADVERTISED_40000baseKR4_Full |
339 ADVERTISED_Autoneg;
340 }
341 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
342 *supported |= SUPPORTED_20000baseKR2_Full |
343 SUPPORTED_Autoneg;
344 *advertising |= ADVERTISED_20000baseKR2_Full |
345 ADVERTISED_Autoneg;
346 }
347 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
348 *supported |= SUPPORTED_10000baseKR_Full |
349 SUPPORTED_Autoneg;
350 *advertising |= ADVERTISED_10000baseKR_Full |
351 ADVERTISED_Autoneg;
352 }
353 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
354 *supported |= SUPPORTED_10000baseKX4_Full |
355 SUPPORTED_Autoneg;
356 *advertising |= ADVERTISED_10000baseKX4_Full |
357 ADVERTISED_Autoneg;
358 }
359 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
360 *supported |= SUPPORTED_1000baseKX_Full |
361 SUPPORTED_Autoneg;
362 *advertising |= ADVERTISED_1000baseKX_Full |
363 ADVERTISED_Autoneg;
364 }
365}
366
367/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000368 * i40e_get_settings_link_up - Get the Link settings for when link is up
369 * @hw: hw structure
370 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000371 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000372 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000373 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000374static void i40e_get_settings_link_up(struct i40e_hw *hw,
375 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400376 struct net_device *netdev,
377 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000378{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000379 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700381 u32 e_advertising = 0x0;
382 u32 e_supported = 0x0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000383
Catherine Sullivane8278452015-02-06 08:52:08 +0000384 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000385 switch (hw_link_info->phy_type) {
386 case I40E_PHY_TYPE_40GBASE_CR4:
387 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000388 ecmd->supported = SUPPORTED_Autoneg |
389 SUPPORTED_40000baseCR4_Full;
390 ecmd->advertising = ADVERTISED_Autoneg |
391 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000392 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000393 case I40E_PHY_TYPE_XLAUI:
394 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000395 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000396 ecmd->supported = SUPPORTED_40000baseCR4_Full;
397 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000398 case I40E_PHY_TYPE_40GBASE_SR4:
399 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000400 break;
401 case I40E_PHY_TYPE_40GBASE_LR4:
402 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000403 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000404 case I40E_PHY_TYPE_10GBASE_SR:
405 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000406 case I40E_PHY_TYPE_1000BASE_SX:
407 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400408 ecmd->supported = SUPPORTED_10000baseT_Full;
409 if (hw_link_info->module_type[2] &
410 I40E_MODULE_TYPE_1000BASE_SX ||
411 hw_link_info->module_type[2] &
412 I40E_MODULE_TYPE_1000BASE_LX) {
413 ecmd->supported |= SUPPORTED_1000baseT_Full;
414 if (hw_link_info->requested_speeds &
415 I40E_LINK_SPEED_1GB)
416 ecmd->advertising |= ADVERTISED_1000baseT_Full;
417 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000418 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
419 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000420 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000421 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000422 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700423 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000424 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000425 SUPPORTED_10000baseT_Full |
Catherine Sullivan06566e52016-05-03 15:13:14 -0700426 SUPPORTED_1000baseT_Full |
427 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000428 ecmd->advertising = ADVERTISED_Autoneg;
429 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
430 ecmd->advertising |= ADVERTISED_10000baseT_Full;
431 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
432 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700433 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
434 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400435 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400436 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
437 ecmd->supported = SUPPORTED_Autoneg |
438 SUPPORTED_1000baseT_Full;
439 ecmd->advertising = ADVERTISED_Autoneg |
440 ADVERTISED_1000baseT_Full;
441 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000442 case I40E_PHY_TYPE_10GBASE_CR1_CU:
443 case I40E_PHY_TYPE_10GBASE_CR1:
444 ecmd->supported = SUPPORTED_Autoneg |
445 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000446 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000447 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000448 break;
449 case I40E_PHY_TYPE_XAUI:
450 case I40E_PHY_TYPE_XFI:
451 case I40E_PHY_TYPE_SFI:
452 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000453 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000454 ecmd->supported = SUPPORTED_10000baseT_Full;
455 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000456 case I40E_PHY_TYPE_SGMII:
457 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400458 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000459 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
460 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800461 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400462 ecmd->supported |= SUPPORTED_100baseT_Full;
463 if (hw_link_info->requested_speeds &
464 I40E_LINK_SPEED_100MB)
465 ecmd->advertising |= ADVERTISED_100baseT_Full;
466 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000467 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400468 case I40E_PHY_TYPE_40GBASE_KR4:
469 case I40E_PHY_TYPE_20GBASE_KR2:
470 case I40E_PHY_TYPE_10GBASE_KR:
471 case I40E_PHY_TYPE_10GBASE_KX4:
472 case I40E_PHY_TYPE_1000BASE_KX:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700473 ecmd->supported |= SUPPORTED_40000baseKR4_Full |
474 SUPPORTED_20000baseKR2_Full |
475 SUPPORTED_10000baseKR_Full |
476 SUPPORTED_10000baseKX4_Full |
477 SUPPORTED_1000baseKX_Full |
478 SUPPORTED_Autoneg;
479 ecmd->advertising |= ADVERTISED_40000baseKR4_Full |
480 ADVERTISED_20000baseKR2_Full |
481 ADVERTISED_10000baseKR_Full |
482 ADVERTISED_10000baseKX4_Full |
483 ADVERTISED_1000baseKX_Full |
484 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400485 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000486 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000487 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000488 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
489 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490 }
491
Catherine Sullivan06566e52016-05-03 15:13:14 -0700492 /* Now that we've worked out everything that could be supported by the
493 * current PHY type, get what is supported by the NVM and them to
494 * get what is truly supported
495 */
496 i40e_phy_type_to_ethtool(pf, &e_supported,
497 &e_advertising);
498
499 ecmd->supported = ecmd->supported & e_supported;
500 ecmd->advertising = ecmd->advertising & e_advertising;
501
Catherine Sullivane8278452015-02-06 08:52:08 +0000502 /* Set speed and duplex */
503 switch (link_speed) {
504 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400505 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000506 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700507 case I40E_LINK_SPEED_20GB:
508 ethtool_cmd_speed_set(ecmd, SPEED_20000);
509 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000510 case I40E_LINK_SPEED_10GB:
511 ethtool_cmd_speed_set(ecmd, SPEED_10000);
512 break;
513 case I40E_LINK_SPEED_1GB:
514 ethtool_cmd_speed_set(ecmd, SPEED_1000);
515 break;
516 case I40E_LINK_SPEED_100MB:
517 ethtool_cmd_speed_set(ecmd, SPEED_100);
518 break;
519 default:
520 break;
521 }
522 ecmd->duplex = DUPLEX_FULL;
523}
524
525/**
526 * i40e_get_settings_link_down - Get the Link settings for when link is down
527 * @hw: hw structure
528 * @ecmd: ethtool command to fill in
529 *
530 * Reports link settings that can be determined when link is down
531 **/
532static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400533 struct ethtool_cmd *ecmd,
534 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000535{
Catherine Sullivane8278452015-02-06 08:52:08 +0000536 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400537 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000538 */
Catherine Sullivan06566e52016-05-03 15:13:14 -0700539 i40e_phy_type_to_ethtool(pf, &ecmd->supported,
540 &ecmd->advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000541
542 /* With no link speed and duplex are unknown */
543 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
544 ecmd->duplex = DUPLEX_UNKNOWN;
545}
546
547/**
548 * i40e_get_settings - Get Link Speed and Duplex settings
549 * @netdev: network interface device structure
550 * @ecmd: ethtool command
551 *
552 * Reports speed/duplex settings based on media_type
553 **/
554static int i40e_get_settings(struct net_device *netdev,
555 struct ethtool_cmd *ecmd)
556{
557 struct i40e_netdev_priv *np = netdev_priv(netdev);
558 struct i40e_pf *pf = np->vsi->back;
559 struct i40e_hw *hw = &pf->hw;
560 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
561 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
562
563 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400564 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000565 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400566 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000567
568 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000569 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000570 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
571 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000572
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000573 switch (hw->phy.media_type) {
574 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000575 ecmd->supported |= SUPPORTED_Autoneg |
576 SUPPORTED_Backplane;
577 ecmd->advertising |= ADVERTISED_Autoneg |
578 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000579 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000580 break;
581 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000582 ecmd->supported |= SUPPORTED_TP;
583 ecmd->advertising |= ADVERTISED_TP;
584 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000585 break;
586 case I40E_MEDIA_TYPE_DA:
587 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000588 ecmd->supported |= SUPPORTED_FIBRE;
589 ecmd->advertising |= ADVERTISED_FIBRE;
590 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000591 break;
592 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000593 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000594 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000595 break;
596 case I40E_MEDIA_TYPE_UNKNOWN:
597 default:
598 ecmd->port = PORT_OTHER;
599 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000600 }
601
Catherine Sullivane8278452015-02-06 08:52:08 +0000602 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000603 ecmd->transceiver = XCVR_EXTERNAL;
604
Catherine Sullivane8278452015-02-06 08:52:08 +0000605 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000606 ecmd->supported |= SUPPORTED_Pause;
607
Catherine Sullivane8278452015-02-06 08:52:08 +0000608 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000609 case I40E_FC_FULL:
610 ecmd->advertising |= ADVERTISED_Pause;
611 break;
612 case I40E_FC_TX_PAUSE:
613 ecmd->advertising |= ADVERTISED_Asym_Pause;
614 break;
615 case I40E_FC_RX_PAUSE:
616 ecmd->advertising |= (ADVERTISED_Pause |
617 ADVERTISED_Asym_Pause);
618 break;
619 default:
620 ecmd->advertising &= ~(ADVERTISED_Pause |
621 ADVERTISED_Asym_Pause);
622 break;
623 }
624
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000625 return 0;
626}
627
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000628/**
629 * i40e_set_settings - Set Speed and Duplex
630 * @netdev: network interface device structure
631 * @ecmd: ethtool command
632 *
633 * Set speed/duplex per media_types advertised/forced
634 **/
635static int i40e_set_settings(struct net_device *netdev,
636 struct ethtool_cmd *ecmd)
637{
638 struct i40e_netdev_priv *np = netdev_priv(netdev);
639 struct i40e_aq_get_phy_abilities_resp abilities;
640 struct i40e_aq_set_phy_config config;
641 struct i40e_pf *pf = np->vsi->back;
642 struct i40e_vsi *vsi = np->vsi;
643 struct i40e_hw *hw = &pf->hw;
644 struct ethtool_cmd safe_ecmd;
645 i40e_status status = 0;
646 bool change = false;
647 int err = 0;
648 u8 autoneg;
649 u32 advertise;
650
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000651 /* Changing port settings is not supported if this isn't the
652 * port's controlling PF
653 */
654 if (hw->partition_id != 1) {
655 i40e_partition_setting_complaint(pf);
656 return -EOPNOTSUPP;
657 }
658
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000659 if (vsi != pf->vsi[pf->lan_vsi])
660 return -EOPNOTSUPP;
661
662 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
663 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000664 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700665 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000666 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000667 return -EOPNOTSUPP;
668
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400669 if (hw->device_id == I40E_DEV_ID_KX_B ||
670 hw->device_id == I40E_DEV_ID_KX_C ||
671 hw->device_id == I40E_DEV_ID_20G_KR2 ||
672 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
673 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
674 return -EOPNOTSUPP;
675 }
676
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000677 /* get our own copy of the bits to check against */
678 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
679 i40e_get_settings(netdev, &safe_ecmd);
680
681 /* save autoneg and speed out of ecmd */
682 autoneg = ecmd->autoneg;
683 advertise = ecmd->advertising;
684
685 /* set autoneg and speed back to what they currently are */
686 ecmd->autoneg = safe_ecmd.autoneg;
687 ecmd->advertising = safe_ecmd.advertising;
688
689 ecmd->cmd = safe_ecmd.cmd;
690 /* If ecmd and safe_ecmd are not the same now, then they are
691 * trying to set something that we do not support
692 */
693 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
694 return -EOPNOTSUPP;
695
696 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
697 usleep_range(1000, 2000);
698
699 /* Get the current phy config */
700 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
701 NULL);
702 if (status)
703 return -EAGAIN;
704
Catherine Sullivan124ed152014-07-12 07:28:12 +0000705 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000706 * set below
707 */
708 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000709 config.abilities = abilities.abilities;
710
711 /* Check autoneg */
712 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000713 /* If autoneg was not already enabled */
714 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400715 /* If autoneg is not supported, return error */
716 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
717 netdev_info(netdev, "Autoneg not supported on this phy\n");
718 return -EINVAL;
719 }
720 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000721 config.abilities = abilities.abilities |
722 I40E_AQ_PHY_ENABLE_AN;
723 change = true;
724 }
725 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000726 /* If autoneg is currently enabled */
727 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400728 /* If autoneg is supported 10GBASE_T is the only PHY
729 * that can disable it, so otherwise return error
730 */
731 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
732 hw->phy.link_info.phy_type !=
733 I40E_PHY_TYPE_10GBASE_T) {
734 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
735 return -EINVAL;
736 }
737 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000738 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000739 ~I40E_AQ_PHY_ENABLE_AN;
740 change = true;
741 }
742 }
743
744 if (advertise & ~safe_ecmd.supported)
745 return -EINVAL;
746
747 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000748 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000749 if (advertise & ADVERTISED_1000baseT_Full ||
750 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000751 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000752 if (advertise & ADVERTISED_10000baseT_Full ||
753 advertise & ADVERTISED_10000baseKX4_Full ||
754 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000755 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700756 if (advertise & ADVERTISED_20000baseKR2_Full)
757 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000758 if (advertise & ADVERTISED_40000baseKR4_Full ||
759 advertise & ADVERTISED_40000baseCR4_Full ||
760 advertise & ADVERTISED_40000baseSR4_Full ||
761 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000762 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000763
Catherine Sullivan0002e112015-08-26 15:14:16 -0400764 /* If speed didn't get set, set it to what it currently is.
765 * This is needed because if advertise is 0 (as it is when autoneg
766 * is disabled) then speed won't get set.
767 */
768 if (!config.link_speed)
769 config.link_speed = abilities.link_speed;
770
Catherine Sullivan124ed152014-07-12 07:28:12 +0000771 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000772 /* copy over the rest of the abilities */
773 config.phy_type = abilities.phy_type;
774 config.eee_capability = abilities.eee_capability;
775 config.eeer = abilities.eeer_val;
776 config.low_power_ctrl = abilities.d3_lpan;
777
Catherine Sullivane8278452015-02-06 08:52:08 +0000778 /* save the requested speeds */
779 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000780 /* set link and auto negotiation so changes take effect */
781 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
782 /* If link is up put link down */
783 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
784 /* Tell the OS link is going down, the link will go
785 * back up when fw says it is ready asynchronously
786 */
Matt Jaredc156f852015-08-27 11:42:39 -0400787 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000788 netif_carrier_off(netdev);
789 netif_tx_stop_all_queues(netdev);
790 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000791
792 /* make the aq call */
793 status = i40e_aq_set_phy_config(hw, &config, NULL);
794 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400795 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
796 i40e_stat_str(hw, status),
797 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000798 return -EAGAIN;
799 }
800
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400801 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000802 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400803 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
804 i40e_stat_str(hw, status),
805 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000806
807 } else {
808 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
809 }
810
811 return err;
812}
813
Jesse Brandeburga6599722014-06-04 08:45:25 +0000814static int i40e_nway_reset(struct net_device *netdev)
815{
816 /* restart autonegotiation */
817 struct i40e_netdev_priv *np = netdev_priv(netdev);
818 struct i40e_pf *pf = np->vsi->back;
819 struct i40e_hw *hw = &pf->hw;
820 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
821 i40e_status ret = 0;
822
823 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
824 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400825 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
826 i40e_stat_str(hw, ret),
827 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000828 return -EIO;
829 }
830
831 return 0;
832}
833
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000834/**
835 * i40e_get_pauseparam - Get Flow Control status
836 * Return tx/rx-pause status
837 **/
838static void i40e_get_pauseparam(struct net_device *netdev,
839 struct ethtool_pauseparam *pause)
840{
841 struct i40e_netdev_priv *np = netdev_priv(netdev);
842 struct i40e_pf *pf = np->vsi->back;
843 struct i40e_hw *hw = &pf->hw;
844 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000845 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000846
847 pause->autoneg =
848 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
849 AUTONEG_ENABLE : AUTONEG_DISABLE);
850
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000851 /* PFC enabled so report LFC as off */
852 if (dcbx_cfg->pfc.pfcenable) {
853 pause->rx_pause = 0;
854 pause->tx_pause = 0;
855 return;
856 }
857
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000858 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000859 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000860 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000861 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000862 } else if (hw->fc.current_mode == I40E_FC_FULL) {
863 pause->rx_pause = 1;
864 pause->tx_pause = 1;
865 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000866}
867
Catherine Sullivan2becc352014-06-04 08:45:27 +0000868/**
869 * i40e_set_pauseparam - Set Flow Control parameter
870 * @netdev: network interface device structure
871 * @pause: return tx/rx flow control status
872 **/
873static int i40e_set_pauseparam(struct net_device *netdev,
874 struct ethtool_pauseparam *pause)
875{
876 struct i40e_netdev_priv *np = netdev_priv(netdev);
877 struct i40e_pf *pf = np->vsi->back;
878 struct i40e_vsi *vsi = np->vsi;
879 struct i40e_hw *hw = &pf->hw;
880 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000881 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000882 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
883 i40e_status status;
884 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000885 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000886
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000887 /* Changing the port's flow control is not supported if this isn't the
888 * port's controlling PF
889 */
890 if (hw->partition_id != 1) {
891 i40e_partition_setting_complaint(pf);
892 return -EOPNOTSUPP;
893 }
894
Catherine Sullivan2becc352014-06-04 08:45:27 +0000895 if (vsi != pf->vsi[pf->lan_vsi])
896 return -EOPNOTSUPP;
897
898 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
899 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
900 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
901 return -EOPNOTSUPP;
902 }
903
904 /* If we have link and don't have autoneg */
905 if (!test_bit(__I40E_DOWN, &pf->state) &&
906 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
907 /* Send message that it might not necessarily work*/
908 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
909 }
910
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000911 if (dcbx_cfg->pfc.pfcenable) {
912 netdev_info(netdev,
913 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000914 return -EOPNOTSUPP;
915 }
916
917 if (pause->rx_pause && pause->tx_pause)
918 hw->fc.requested_mode = I40E_FC_FULL;
919 else if (pause->rx_pause && !pause->tx_pause)
920 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
921 else if (!pause->rx_pause && pause->tx_pause)
922 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
923 else if (!pause->rx_pause && !pause->tx_pause)
924 hw->fc.requested_mode = I40E_FC_NONE;
925 else
926 return -EINVAL;
927
Catherine Sullivan94128512014-07-12 07:28:16 +0000928 /* Tell the OS link is going down, the link will go back up when fw
929 * says it is ready asynchronously
930 */
Matt Jaredc156f852015-08-27 11:42:39 -0400931 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000932 netif_carrier_off(netdev);
933 netif_tx_stop_all_queues(netdev);
934
Catherine Sullivan2becc352014-06-04 08:45:27 +0000935 /* Set the fc mode and only restart an if link is up*/
936 status = i40e_set_fc(hw, &aq_failures, link_up);
937
938 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400939 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
940 i40e_stat_str(hw, status),
941 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000942 err = -EAGAIN;
943 }
944 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400945 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
946 i40e_stat_str(hw, status),
947 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000948 err = -EAGAIN;
949 }
950 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400951 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
952 i40e_stat_str(hw, status),
953 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000954 err = -EAGAIN;
955 }
956
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000957 if (!test_bit(__I40E_DOWN, &pf->state)) {
958 /* Give it a little more time to try to come back */
959 msleep(75);
960 if (!test_bit(__I40E_DOWN, &pf->state))
961 return i40e_nway_reset(netdev);
962 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000963
964 return err;
965}
966
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000967static u32 i40e_get_msglevel(struct net_device *netdev)
968{
969 struct i40e_netdev_priv *np = netdev_priv(netdev);
970 struct i40e_pf *pf = np->vsi->back;
971
972 return pf->msg_enable;
973}
974
975static void i40e_set_msglevel(struct net_device *netdev, u32 data)
976{
977 struct i40e_netdev_priv *np = netdev_priv(netdev);
978 struct i40e_pf *pf = np->vsi->back;
979
980 if (I40E_DEBUG_USER & data)
981 pf->hw.debug_mask = data;
982 pf->msg_enable = data;
983}
984
985static int i40e_get_regs_len(struct net_device *netdev)
986{
987 int reg_count = 0;
988 int i;
989
990 for (i = 0; i40e_reg_list[i].offset != 0; i++)
991 reg_count += i40e_reg_list[i].elements;
992
993 return reg_count * sizeof(u32);
994}
995
996static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
997 void *p)
998{
999 struct i40e_netdev_priv *np = netdev_priv(netdev);
1000 struct i40e_pf *pf = np->vsi->back;
1001 struct i40e_hw *hw = &pf->hw;
1002 u32 *reg_buf = p;
1003 int i, j, ri;
1004 u32 reg;
1005
1006 /* Tell ethtool which driver-version-specific regs output we have.
1007 *
1008 * At some point, if we have ethtool doing special formatting of
1009 * this data, it will rely on this version number to know how to
1010 * interpret things. Hence, this needs to be updated if/when the
1011 * diags register table is changed.
1012 */
1013 regs->version = 1;
1014
1015 /* loop through the diags reg table for what to print */
1016 ri = 0;
1017 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1018 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1019 reg = i40e_reg_list[i].offset
1020 + (j * i40e_reg_list[i].stride);
1021 reg_buf[ri++] = rd32(hw, reg);
1022 }
1023 }
1024
1025}
1026
1027static int i40e_get_eeprom(struct net_device *netdev,
1028 struct ethtool_eeprom *eeprom, u8 *bytes)
1029{
1030 struct i40e_netdev_priv *np = netdev_priv(netdev);
1031 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001032 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001033 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001034 u8 *eeprom_buff;
1035 u16 i, sectors;
1036 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001037 u32 magic;
1038
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001039#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001040 if (eeprom->len == 0)
1041 return -EINVAL;
1042
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001043 /* check for NVMUpdate access method */
1044 magic = hw->vendor_id | (hw->device_id << 16);
1045 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001046 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1047 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001048
1049 /* make sure it is the right magic for NVMUpdate */
1050 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001051 errno = -EINVAL;
1052 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1053 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1054 errno = -EBUSY;
1055 else
1056 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001057
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001058 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001059 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001060 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1061 ret_val, hw->aq.asq_last_status, errno,
1062 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1063 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001064
1065 return errno;
1066 }
1067
1068 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001069 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1070
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001071 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072 if (!eeprom_buff)
1073 return -ENOMEM;
1074
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001075 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1076 if (ret_val) {
1077 dev_info(&pf->pdev->dev,
1078 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1079 ret_val, hw->aq.asq_last_status);
1080 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001081 }
1082
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001083 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1084 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1085 len = I40E_NVM_SECTOR_SIZE;
1086 last = false;
1087 for (i = 0; i < sectors; i++) {
1088 if (i == (sectors - 1)) {
1089 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1090 last = true;
1091 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001092 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1093 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001094 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001095 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001096 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001097 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001098 "read NVM failed, invalid offset 0x%x\n",
1099 offset);
1100 break;
1101 } else if (ret_val &&
1102 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1103 dev_info(&pf->pdev->dev,
1104 "read NVM failed, access, offset 0x%x\n",
1105 offset);
1106 break;
1107 } else if (ret_val) {
1108 dev_info(&pf->pdev->dev,
1109 "read NVM failed offset %d err=%d status=0x%x\n",
1110 offset, ret_val, hw->aq.asq_last_status);
1111 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001112 }
1113 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001114
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001115 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001116 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001117free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001118 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001119 return ret_val;
1120}
1121
1122static int i40e_get_eeprom_len(struct net_device *netdev)
1123{
1124 struct i40e_netdev_priv *np = netdev_priv(netdev);
1125 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001126 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001127
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001128 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1129 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1130 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1131 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001132 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001133 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001134}
1135
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001136static int i40e_set_eeprom(struct net_device *netdev,
1137 struct ethtool_eeprom *eeprom, u8 *bytes)
1138{
1139 struct i40e_netdev_priv *np = netdev_priv(netdev);
1140 struct i40e_hw *hw = &np->vsi->back->hw;
1141 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001142 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001143 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001144 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001145 u32 magic;
1146
1147 /* normal ethtool set_eeprom is not supported */
1148 magic = hw->vendor_id | (hw->device_id << 16);
1149 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001150 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001151 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001152 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1153 errno = -EINVAL;
1154 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1155 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1156 errno = -EBUSY;
1157 else
1158 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001159
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001160 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001161 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001162 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1163 ret_val, hw->aq.asq_last_status, errno,
1164 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1165 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001166
1167 return errno;
1168}
1169
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001170static void i40e_get_drvinfo(struct net_device *netdev,
1171 struct ethtool_drvinfo *drvinfo)
1172{
1173 struct i40e_netdev_priv *np = netdev_priv(netdev);
1174 struct i40e_vsi *vsi = np->vsi;
1175 struct i40e_pf *pf = vsi->back;
1176
1177 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1178 strlcpy(drvinfo->version, i40e_driver_version_str,
1179 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001180 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001181 sizeof(drvinfo->fw_version));
1182 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1183 sizeof(drvinfo->bus_info));
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001184 if (pf->hw.pf_id == 0)
1185 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_GL_STR_LEN;
1186 else
1187 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001188}
1189
1190static void i40e_get_ringparam(struct net_device *netdev,
1191 struct ethtool_ringparam *ring)
1192{
1193 struct i40e_netdev_priv *np = netdev_priv(netdev);
1194 struct i40e_pf *pf = np->vsi->back;
1195 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1196
1197 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1198 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1199 ring->rx_mini_max_pending = 0;
1200 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001201 ring->rx_pending = vsi->rx_rings[0]->count;
1202 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001203 ring->rx_mini_pending = 0;
1204 ring->rx_jumbo_pending = 0;
1205}
1206
1207static int i40e_set_ringparam(struct net_device *netdev,
1208 struct ethtool_ringparam *ring)
1209{
1210 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1211 struct i40e_netdev_priv *np = netdev_priv(netdev);
1212 struct i40e_vsi *vsi = np->vsi;
1213 struct i40e_pf *pf = vsi->back;
1214 u32 new_rx_count, new_tx_count;
1215 int i, err = 0;
1216
1217 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1218 return -EINVAL;
1219
Shannon Nelson1fa18372013-11-20 10:03:08 +00001220 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1221 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1222 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1223 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1224 netdev_info(netdev,
1225 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1226 ring->tx_pending, ring->rx_pending,
1227 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1228 return -EINVAL;
1229 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001230
Shannon Nelson1fa18372013-11-20 10:03:08 +00001231 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1232 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001233
1234 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001235 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1236 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001237 return 0;
1238
1239 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1240 usleep_range(1000, 2000);
1241
1242 if (!netif_running(vsi->netdev)) {
1243 /* simple case - set for the next time the netdev is started */
1244 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001245 vsi->tx_rings[i]->count = new_tx_count;
1246 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001247 }
1248 goto done;
1249 }
1250
1251 /* We can't just free everything and then setup again,
1252 * because the ISRs in MSI-X mode get passed pointers
1253 * to the Tx and Rx ring structs.
1254 */
1255
1256 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001257 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001258 netdev_info(netdev,
1259 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001260 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001261 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1262 sizeof(struct i40e_ring), GFP_KERNEL);
1263 if (!tx_rings) {
1264 err = -ENOMEM;
1265 goto done;
1266 }
1267
1268 for (i = 0; i < vsi->num_queue_pairs; i++) {
1269 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001270 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001271 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001272 /* the desc and bi pointers will be reallocated in the
1273 * setup call
1274 */
1275 tx_rings[i].desc = NULL;
1276 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1278 if (err) {
1279 while (i) {
1280 i--;
1281 i40e_free_tx_resources(&tx_rings[i]);
1282 }
1283 kfree(tx_rings);
1284 tx_rings = NULL;
1285
1286 goto done;
1287 }
1288 }
1289 }
1290
1291 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001292 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001293 netdev_info(netdev,
1294 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001295 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001296 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1297 sizeof(struct i40e_ring), GFP_KERNEL);
1298 if (!rx_rings) {
1299 err = -ENOMEM;
1300 goto free_tx;
1301 }
1302
1303 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001304 /* this is to allow wr32 to have something to write to
1305 * during early allocation of Rx buffers
1306 */
1307 u32 __iomem faketail = 0;
1308 struct i40e_ring *ring;
1309 u16 unused;
1310
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001311 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001312 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001313 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001314 /* the desc and bi pointers will be reallocated in the
1315 * setup call
1316 */
1317 rx_rings[i].desc = NULL;
1318 rx_rings[i].rx_bi = NULL;
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001319 rx_rings[i].tail = (u8 __iomem *)&faketail;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001320 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001321 if (err)
1322 goto rx_unwind;
1323
1324 /* now allocate the Rx buffers to make sure the OS
1325 * has enough memory, any failure here means abort
1326 */
1327 ring = &rx_rings[i];
1328 unused = I40E_DESC_UNUSED(ring);
1329 err = i40e_alloc_rx_buffers(ring, unused);
1330rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001332 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001333 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001334 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001335 kfree(rx_rings);
1336 rx_rings = NULL;
1337
1338 goto free_tx;
1339 }
1340 }
1341 }
1342
1343 /* Bring interface down, copy in the new ring info,
1344 * then restore the interface
1345 */
1346 i40e_down(vsi);
1347
1348 if (tx_rings) {
1349 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001350 i40e_free_tx_resources(vsi->tx_rings[i]);
1351 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001352 }
1353 kfree(tx_rings);
1354 tx_rings = NULL;
1355 }
1356
1357 if (rx_rings) {
1358 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001359 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001360 /* get the real tail offset */
1361 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1362 /* this is to fake out the allocation routine
1363 * into thinking it has to realloc everything
1364 * but the recycling logic will let us re-use
1365 * the buffers allocated above
1366 */
1367 rx_rings[i].next_to_use = 0;
1368 rx_rings[i].next_to_clean = 0;
1369 rx_rings[i].next_to_alloc = 0;
1370 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001371 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001372 }
1373 kfree(rx_rings);
1374 rx_rings = NULL;
1375 }
1376
1377 i40e_up(vsi);
1378
1379free_tx:
1380 /* error cleanup if the Rx allocations failed after getting Tx */
1381 if (tx_rings) {
1382 for (i = 0; i < vsi->num_queue_pairs; i++)
1383 i40e_free_tx_resources(&tx_rings[i]);
1384 kfree(tx_rings);
1385 tx_rings = NULL;
1386 }
1387
1388done:
1389 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1390
1391 return err;
1392}
1393
1394static int i40e_get_sset_count(struct net_device *netdev, int sset)
1395{
1396 struct i40e_netdev_priv *np = netdev_priv(netdev);
1397 struct i40e_vsi *vsi = np->vsi;
1398 struct i40e_pf *pf = vsi->back;
1399
1400 switch (sset) {
1401 case ETH_SS_TEST:
1402 return I40E_TEST_LEN;
1403 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001404 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001405 int len = I40E_PF_STATS_LEN(netdev);
1406
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001407 if ((pf->lan_veb != I40E_NO_VEB) &&
1408 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001409 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001410 return len;
1411 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001412 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001413 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001414 case ETH_SS_PRIV_FLAGS:
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001415 if (pf->hw.pf_id == 0)
1416 return I40E_PRIV_FLAGS_GL_STR_LEN;
1417 else
1418 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001419 default:
1420 return -EOPNOTSUPP;
1421 }
1422}
1423
1424static void i40e_get_ethtool_stats(struct net_device *netdev,
1425 struct ethtool_stats *stats, u64 *data)
1426{
1427 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001428 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 struct i40e_vsi *vsi = np->vsi;
1430 struct i40e_pf *pf = vsi->back;
1431 int i = 0;
1432 char *p;
1433 int j;
1434 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001435 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001436
1437 i40e_update_stats(vsi);
1438
1439 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1440 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1441 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1442 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1443 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001444 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1445 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1446 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1447 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1448 }
Vasu Dev38e00432014-08-01 13:27:03 -07001449#ifdef I40E_FCOE
1450 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1451 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1452 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1453 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1454 }
1455#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001456 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001457 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001458 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001459
1460 if (!tx_ring)
1461 continue;
1462
1463 /* process Tx ring statistics */
1464 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001465 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001466 data[i] = tx_ring->stats.packets;
1467 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001468 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001469 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001470
1471 /* Rx ring is the 2nd half of the queue pair */
1472 rx_ring = &tx_ring[1];
1473 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001474 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001475 data[i] = rx_ring->stats.packets;
1476 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001477 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001478 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001479 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001480 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001481 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001482 return;
1483
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001484 if ((pf->lan_veb != I40E_NO_VEB) &&
1485 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001486 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001487
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001488 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1489 p = (char *)veb;
1490 p += i40e_gstrings_veb_stats[j].stat_offset;
1491 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1492 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001493 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001494 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1495 data[i++] = veb->tc_stats.tc_tx_packets[j];
1496 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1497 data[i++] = veb->tc_stats.tc_rx_packets[j];
1498 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1499 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001501 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1502 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1503 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1504 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1505 }
1506 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1507 data[i++] = pf->stats.priority_xon_tx[j];
1508 data[i++] = pf->stats.priority_xoff_tx[j];
1509 }
1510 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1511 data[i++] = pf->stats.priority_xon_rx[j];
1512 data[i++] = pf->stats.priority_xoff_rx[j];
1513 }
1514 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1515 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516}
1517
1518static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1519 u8 *data)
1520{
1521 struct i40e_netdev_priv *np = netdev_priv(netdev);
1522 struct i40e_vsi *vsi = np->vsi;
1523 struct i40e_pf *pf = vsi->back;
1524 char *p = (char *)data;
1525 int i;
1526
1527 switch (stringset) {
1528 case ETH_SS_TEST:
1529 for (i = 0; i < I40E_TEST_LEN; i++) {
1530 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1531 data += ETH_GSTRING_LEN;
1532 }
1533 break;
1534 case ETH_SS_STATS:
1535 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1536 snprintf(p, ETH_GSTRING_LEN, "%s",
1537 i40e_gstrings_net_stats[i].stat_string);
1538 p += ETH_GSTRING_LEN;
1539 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001540 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1541 snprintf(p, ETH_GSTRING_LEN, "%s",
1542 i40e_gstrings_misc_stats[i].stat_string);
1543 p += ETH_GSTRING_LEN;
1544 }
Vasu Dev38e00432014-08-01 13:27:03 -07001545#ifdef I40E_FCOE
1546 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1547 snprintf(p, ETH_GSTRING_LEN, "%s",
1548 i40e_gstrings_fcoe_stats[i].stat_string);
1549 p += ETH_GSTRING_LEN;
1550 }
1551#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001552 for (i = 0; i < vsi->num_queue_pairs; i++) {
1553 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1554 p += ETH_GSTRING_LEN;
1555 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1556 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1558 p += ETH_GSTRING_LEN;
1559 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1560 p += ETH_GSTRING_LEN;
1561 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001562 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001563 return;
1564
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001565 if ((pf->lan_veb != I40E_NO_VEB) &&
1566 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001567 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1568 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1569 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001570 p += ETH_GSTRING_LEN;
1571 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001572 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1573 snprintf(p, ETH_GSTRING_LEN,
1574 "veb.tc_%u_tx_packets", i);
1575 p += ETH_GSTRING_LEN;
1576 snprintf(p, ETH_GSTRING_LEN,
1577 "veb.tc_%u_tx_bytes", i);
1578 p += ETH_GSTRING_LEN;
1579 snprintf(p, ETH_GSTRING_LEN,
1580 "veb.tc_%u_rx_packets", i);
1581 p += ETH_GSTRING_LEN;
1582 snprintf(p, ETH_GSTRING_LEN,
1583 "veb.tc_%u_rx_bytes", i);
1584 p += ETH_GSTRING_LEN;
1585 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001586 }
1587 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1588 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1589 i40e_gstrings_stats[i].stat_string);
1590 p += ETH_GSTRING_LEN;
1591 }
1592 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1593 snprintf(p, ETH_GSTRING_LEN,
1594 "port.tx_priority_%u_xon", i);
1595 p += ETH_GSTRING_LEN;
1596 snprintf(p, ETH_GSTRING_LEN,
1597 "port.tx_priority_%u_xoff", i);
1598 p += ETH_GSTRING_LEN;
1599 }
1600 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1601 snprintf(p, ETH_GSTRING_LEN,
1602 "port.rx_priority_%u_xon", i);
1603 p += ETH_GSTRING_LEN;
1604 snprintf(p, ETH_GSTRING_LEN,
1605 "port.rx_priority_%u_xoff", i);
1606 p += ETH_GSTRING_LEN;
1607 }
1608 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1609 snprintf(p, ETH_GSTRING_LEN,
1610 "port.rx_priority_%u_xon_2_xoff", i);
1611 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001612 }
1613 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1614 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001615 case ETH_SS_PRIV_FLAGS:
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001616 if (pf->hw.pf_id == 0) {
1617 for (i = 0; i < I40E_PRIV_FLAGS_GL_STR_LEN; i++) {
1618 memcpy(data, i40e_priv_flags_strings_gl[i],
1619 ETH_GSTRING_LEN);
1620 data += ETH_GSTRING_LEN;
1621 }
1622 } else {
1623 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1624 memcpy(data, i40e_priv_flags_strings[i],
1625 ETH_GSTRING_LEN);
1626 data += ETH_GSTRING_LEN;
1627 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001628 }
1629 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001630 default:
1631 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001632 }
1633}
1634
1635static int i40e_get_ts_info(struct net_device *dev,
1636 struct ethtool_ts_info *info)
1637{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001638 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1639
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001640 /* only report HW timestamping if PTP is enabled */
1641 if (!(pf->flags & I40E_FLAG_PTP))
1642 return ethtool_op_get_ts_info(dev, info);
1643
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001644 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1645 SOF_TIMESTAMPING_RX_SOFTWARE |
1646 SOF_TIMESTAMPING_SOFTWARE |
1647 SOF_TIMESTAMPING_TX_HARDWARE |
1648 SOF_TIMESTAMPING_RX_HARDWARE |
1649 SOF_TIMESTAMPING_RAW_HARDWARE;
1650
1651 if (pf->ptp_clock)
1652 info->phc_index = ptp_clock_index(pf->ptp_clock);
1653 else
1654 info->phc_index = -1;
1655
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001656 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001657
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001658 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1659 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1660 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001661
1662 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001663}
1664
Shannon Nelson7b086392013-11-20 10:02:59 +00001665static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001666{
Shannon Nelson7b086392013-11-20 10:02:59 +00001667 struct i40e_netdev_priv *np = netdev_priv(netdev);
1668 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001669 i40e_status status;
1670 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001671
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001672 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001673 status = i40e_get_link_status(&pf->hw, &link_up);
1674 if (status) {
1675 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1676 *data = 1;
1677 return *data;
1678 }
1679
1680 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001681 *data = 0;
1682 else
1683 *data = 1;
1684
1685 return *data;
1686}
1687
Shannon Nelson7b086392013-11-20 10:02:59 +00001688static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001689{
Shannon Nelson7b086392013-11-20 10:02:59 +00001690 struct i40e_netdev_priv *np = netdev_priv(netdev);
1691 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001692
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001693 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001694 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695
Shannon Nelson7b086392013-11-20 10:02:59 +00001696 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697}
1698
Shannon Nelson7b086392013-11-20 10:02:59 +00001699static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001700{
Shannon Nelson7b086392013-11-20 10:02:59 +00001701 struct i40e_netdev_priv *np = netdev_priv(netdev);
1702 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001703
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001704 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001705 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001706
Shannon Nelson4443ec92014-11-13 08:23:12 +00001707 /* forcebly clear the NVM Update state machine */
1708 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1709
Shannon Nelson7b086392013-11-20 10:02:59 +00001710 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001711}
1712
Shannon Nelson7b086392013-11-20 10:02:59 +00001713static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714{
Shannon Nelson7b086392013-11-20 10:02:59 +00001715 struct i40e_netdev_priv *np = netdev_priv(netdev);
1716 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001717 u16 swc_old = pf->sw_int_count;
1718
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001719 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001720 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1721 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001722 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1723 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1724 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1725 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001726 usleep_range(1000, 2000);
1727 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001728
1729 return *data;
1730}
1731
Shannon Nelson7b086392013-11-20 10:02:59 +00001732static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001734 struct i40e_netdev_priv *np = netdev_priv(netdev);
1735 struct i40e_pf *pf = np->vsi->back;
1736
1737 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001738 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001739
1740 return *data;
1741}
1742
Greg Rosee17bc412015-04-16 20:05:59 -04001743static inline bool i40e_active_vfs(struct i40e_pf *pf)
1744{
1745 struct i40e_vf *vfs = pf->vf;
1746 int i;
1747
1748 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001749 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001750 return true;
1751 return false;
1752}
1753
Greg Rose510efb22015-07-10 19:36:01 -04001754static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1755{
1756 struct i40e_vsi **vsi = pf->vsi;
1757 int i;
1758
1759 for (i = 0; i < pf->num_alloc_vsi; i++) {
1760 if (!vsi[i])
1761 continue;
1762 if (vsi[i]->type == I40E_VSI_VMDQ2)
1763 return true;
1764 }
1765
1766 return false;
1767}
1768
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001769static void i40e_diag_test(struct net_device *netdev,
1770 struct ethtool_test *eth_test, u64 *data)
1771{
1772 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001773 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774 struct i40e_pf *pf = np->vsi->back;
1775
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001776 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1777 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001778 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001779
Shannon Nelsonf551b432013-11-26 10:49:12 +00001780 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001781
Greg Rose510efb22015-07-10 19:36:01 -04001782 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001783 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001784 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001785 data[I40E_ETH_TEST_REG] = 1;
1786 data[I40E_ETH_TEST_EEPROM] = 1;
1787 data[I40E_ETH_TEST_INTR] = 1;
1788 data[I40E_ETH_TEST_LOOPBACK] = 1;
1789 data[I40E_ETH_TEST_LINK] = 1;
1790 eth_test->flags |= ETH_TEST_FL_FAILED;
1791 clear_bit(__I40E_TESTING, &pf->state);
1792 goto skip_ol_tests;
1793 }
1794
Greg Rose5b86c5c2015-02-26 16:14:35 +00001795 /* If the device is online then take it offline */
1796 if (if_running)
1797 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001798 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001799 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001800 /* This reset does not affect link - if it is
1801 * changed to a type of reset that does affect
1802 * link then the following link test would have
1803 * to be moved to before the reset
1804 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001805 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001806
Shannon Nelson7b086392013-11-20 10:02:59 +00001807 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001808 eth_test->flags |= ETH_TEST_FL_FAILED;
1809
Shannon Nelson7b086392013-11-20 10:02:59 +00001810 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811 eth_test->flags |= ETH_TEST_FL_FAILED;
1812
Shannon Nelson7b086392013-11-20 10:02:59 +00001813 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001814 eth_test->flags |= ETH_TEST_FL_FAILED;
1815
Shannon Nelson7b086392013-11-20 10:02:59 +00001816 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001817 eth_test->flags |= ETH_TEST_FL_FAILED;
1818
Shannon Nelsonf551b432013-11-26 10:49:12 +00001819 /* run reg test last, a reset is required after it */
1820 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1821 eth_test->flags |= ETH_TEST_FL_FAILED;
1822
1823 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001824 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001825
1826 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001827 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001828 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001830 netif_info(pf, drv, netdev, "online testing starting\n");
1831
Shannon Nelson7b086392013-11-20 10:02:59 +00001832 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001833 eth_test->flags |= ETH_TEST_FL_FAILED;
1834
1835 /* Offline only tests, not run in online; pass by default */
1836 data[I40E_ETH_TEST_REG] = 0;
1837 data[I40E_ETH_TEST_EEPROM] = 0;
1838 data[I40E_ETH_TEST_INTR] = 0;
1839 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001840 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001841
Greg Rosee17bc412015-04-16 20:05:59 -04001842skip_ol_tests:
1843
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001844 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001845}
1846
1847static void i40e_get_wol(struct net_device *netdev,
1848 struct ethtool_wolinfo *wol)
1849{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001850 struct i40e_netdev_priv *np = netdev_priv(netdev);
1851 struct i40e_pf *pf = np->vsi->back;
1852 struct i40e_hw *hw = &pf->hw;
1853 u16 wol_nvm_bits;
1854
1855 /* NVM bit on means WoL disabled for the port */
1856 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001857 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001858 wol->supported = 0;
1859 wol->wolopts = 0;
1860 } else {
1861 wol->supported = WAKE_MAGIC;
1862 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1863 }
1864}
1865
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001866/**
1867 * i40e_set_wol - set the WakeOnLAN configuration
1868 * @netdev: the netdev in question
1869 * @wol: the ethtool WoL setting data
1870 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001871static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1872{
1873 struct i40e_netdev_priv *np = netdev_priv(netdev);
1874 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001875 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001876 struct i40e_hw *hw = &pf->hw;
1877 u16 wol_nvm_bits;
1878
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001879 /* WoL not supported if this isn't the controlling PF on the port */
1880 if (hw->partition_id != 1) {
1881 i40e_partition_setting_complaint(pf);
1882 return -EOPNOTSUPP;
1883 }
1884
1885 if (vsi != pf->vsi[pf->lan_vsi])
1886 return -EOPNOTSUPP;
1887
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001888 /* NVM bit on means WoL disabled for the port */
1889 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001890 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001891 return -EOPNOTSUPP;
1892
1893 /* only magic packet is supported */
1894 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1895 return -EOPNOTSUPP;
1896
1897 /* is this a new value? */
1898 if (pf->wol_en != !!wol->wolopts) {
1899 pf->wol_en = !!wol->wolopts;
1900 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1901 }
1902
1903 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001904}
1905
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001906static int i40e_set_phys_id(struct net_device *netdev,
1907 enum ethtool_phys_id_state state)
1908{
1909 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001910 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001911 struct i40e_pf *pf = np->vsi->back;
1912 struct i40e_hw *hw = &pf->hw;
1913 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001914 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001915
1916 switch (state) {
1917 case ETHTOOL_ID_ACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001918 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1919 pf->led_status = i40e_led_get(hw);
1920 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001921 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001922 ret = i40e_led_get_phy(hw, &temp_status,
1923 &pf->phy_led_val);
1924 pf->led_status = temp_status;
1925 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001926 return blink_freq;
1927 case ETHTOOL_ID_ON:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001928 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1929 i40e_led_set(hw, 0xf, false);
1930 else
1931 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001932 break;
1933 case ETHTOOL_ID_OFF:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001934 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1935 i40e_led_set(hw, 0x0, false);
1936 else
1937 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001938 break;
1939 case ETHTOOL_ID_INACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001940 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1941 i40e_led_set(hw, false, pf->led_status);
1942 } else {
1943 ret = i40e_led_set_phy(hw, false, pf->led_status,
1944 (pf->phy_led_val |
1945 I40E_PHY_LED_MODE_ORIG));
1946 i40e_aq_set_phy_debug(hw, 0, NULL);
1947 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001949 default:
1950 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001951 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001952 if (ret)
1953 return -ENOENT;
1954 else
1955 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001956}
1957
1958/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1959 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1960 * 125us (8000 interrupts per second) == ITR(62)
1961 */
1962
Kan Lianga75e8002016-02-19 09:24:04 -05001963static int __i40e_get_coalesce(struct net_device *netdev,
1964 struct ethtool_coalesce *ec,
1965 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001966{
1967 struct i40e_netdev_priv *np = netdev_priv(netdev);
1968 struct i40e_vsi *vsi = np->vsi;
1969
1970 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1971 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1972
Kan Lianga75e8002016-02-19 09:24:04 -05001973 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
1974 * return queue 0's value to represent.
1975 */
1976 if (queue < 0) {
1977 queue = 0;
1978 } else if (queue >= vsi->num_queue_pairs) {
1979 return -EINVAL;
1980 }
1981
1982 if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001983 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001984
Kan Lianga75e8002016-02-19 09:24:04 -05001985 if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001986 ec->use_adaptive_tx_coalesce = 1;
1987
Kan Lianga75e8002016-02-19 09:24:04 -05001988 ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1989 ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1990
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001991 /* we use the _usecs_high to store/set the interrupt rate limit
1992 * that the hardware supports, that almost but not quite
1993 * fits the original intent of the ethtool variable,
1994 * the rx_coalesce_usecs_high limits total interrupts
1995 * per second from both tx/rx sources.
1996 */
1997 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1998 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001999
2000 return 0;
2001}
2002
Kan Lianga75e8002016-02-19 09:24:04 -05002003static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002004 struct ethtool_coalesce *ec)
2005{
Kan Lianga75e8002016-02-19 09:24:04 -05002006 return __i40e_get_coalesce(netdev, ec, -1);
2007}
2008
Kan Liangbe280ba2016-02-19 09:24:05 -05002009static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2010 struct ethtool_coalesce *ec)
2011{
2012 return __i40e_get_coalesce(netdev, ec, queue);
2013}
2014
Kan Lianga75e8002016-02-19 09:24:04 -05002015static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2016 struct ethtool_coalesce *ec,
2017 int queue)
2018{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002019 struct i40e_pf *pf = vsi->back;
2020 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002021 struct i40e_q_vector *q_vector;
2022 u16 vector, intrl;
2023
2024 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
2025
2026 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2027 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2028
2029 if (ec->use_adaptive_rx_coalesce)
2030 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2031 else
2032 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2033
2034 if (ec->use_adaptive_tx_coalesce)
2035 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2036 else
2037 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2038
2039 q_vector = vsi->rx_rings[queue]->q_vector;
2040 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2041 vector = vsi->base_vector + q_vector->v_idx;
2042 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2043
2044 q_vector = vsi->tx_rings[queue]->q_vector;
2045 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2046 vector = vsi->base_vector + q_vector->v_idx;
2047 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2048
2049 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2050 i40e_flush(hw);
2051}
2052
2053static int __i40e_set_coalesce(struct net_device *netdev,
2054 struct ethtool_coalesce *ec,
2055 int queue)
2056{
2057 struct i40e_netdev_priv *np = netdev_priv(netdev);
2058 struct i40e_vsi *vsi = np->vsi;
2059 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002060 int i;
2061
2062 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2063 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2064
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002065 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2066 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2067 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2068 return -EINVAL;
2069 }
2070
2071 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2072 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
2073 return -EINVAL;
2074 }
2075
Kan Lianga75e8002016-02-19 09:24:04 -05002076 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002077 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002078 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 -05002079 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2080 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2081 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2082 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002083 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002084
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002085 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
2086
Kan Lianga75e8002016-02-19 09:24:04 -05002087 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002088 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002089 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 -05002090 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2091 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2092 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2093 return -EINVAL;
2094 }
2095
2096 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2097 * apply to all queues.
2098 */
2099 if (queue < 0) {
2100 for (i = 0; i < vsi->num_queue_pairs; i++)
2101 i40e_set_itr_per_queue(vsi, ec, i);
2102 } else if (queue < vsi->num_queue_pairs) {
2103 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002104 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002105 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2106 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002107 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002108 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002109
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002110 return 0;
2111}
2112
Kan Lianga75e8002016-02-19 09:24:04 -05002113static int i40e_set_coalesce(struct net_device *netdev,
2114 struct ethtool_coalesce *ec)
2115{
2116 return __i40e_set_coalesce(netdev, ec, -1);
2117}
2118
Kan Liangf3757a42016-02-19 09:24:06 -05002119static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2120 struct ethtool_coalesce *ec)
2121{
2122 return __i40e_set_coalesce(netdev, ec, queue);
2123}
2124
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002125/**
2126 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2127 * @pf: pointer to the physical function struct
2128 * @cmd: ethtool rxnfc command
2129 *
2130 * Returns Success if the flow is supported, else Invalid Input.
2131 **/
2132static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2133{
2134 cmd->data = 0;
2135
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002136 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
2137 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
2138 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
2139 return 0;
2140 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002141 /* Report default options for RSS on i40e */
2142 switch (cmd->flow_type) {
2143 case TCP_V4_FLOW:
2144 case UDP_V4_FLOW:
2145 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2146 /* fall through to add IP fields */
2147 case SCTP_V4_FLOW:
2148 case AH_ESP_V4_FLOW:
2149 case AH_V4_FLOW:
2150 case ESP_V4_FLOW:
2151 case IPV4_FLOW:
2152 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2153 break;
2154 case TCP_V6_FLOW:
2155 case UDP_V6_FLOW:
2156 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2157 /* fall through to add IP fields */
2158 case SCTP_V6_FLOW:
2159 case AH_ESP_V6_FLOW:
2160 case AH_V6_FLOW:
2161 case ESP_V6_FLOW:
2162 case IPV6_FLOW:
2163 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2164 break;
2165 default:
2166 return -EINVAL;
2167 }
2168
2169 return 0;
2170}
2171
2172/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002173 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2174 * @pf: Pointer to the physical function struct
2175 * @cmd: The command to get or set Rx flow classification rules
2176 * @rule_locs: Array of used rule locations
2177 *
2178 * This function populates both the total and actual rule count of
2179 * the ethtool flow classification command
2180 *
2181 * Returns 0 on success or -EMSGSIZE if entry not found
2182 **/
2183static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2184 struct ethtool_rxnfc *cmd,
2185 u32 *rule_locs)
2186{
2187 struct i40e_fdir_filter *rule;
2188 struct hlist_node *node2;
2189 int cnt = 0;
2190
2191 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002192 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002193
2194 hlist_for_each_entry_safe(rule, node2,
2195 &pf->fdir_filter_list, fdir_node) {
2196 if (cnt == cmd->rule_cnt)
2197 return -EMSGSIZE;
2198
2199 rule_locs[cnt] = rule->fd_id;
2200 cnt++;
2201 }
2202
2203 cmd->rule_cnt = cnt;
2204
2205 return 0;
2206}
2207
2208/**
2209 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2210 * @pf: Pointer to the physical function struct
2211 * @cmd: The command to get or set Rx flow classification rules
2212 *
2213 * This function looks up a filter based on the Rx flow classification
2214 * command and fills the flow spec info for it if found
2215 *
2216 * Returns 0 on success or -EINVAL if filter not found
2217 **/
2218static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2219 struct ethtool_rxnfc *cmd)
2220{
2221 struct ethtool_rx_flow_spec *fsp =
2222 (struct ethtool_rx_flow_spec *)&cmd->fs;
2223 struct i40e_fdir_filter *rule = NULL;
2224 struct hlist_node *node2;
2225
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002226 hlist_for_each_entry_safe(rule, node2,
2227 &pf->fdir_filter_list, fdir_node) {
2228 if (fsp->location <= rule->fd_id)
2229 break;
2230 }
2231
2232 if (!rule || fsp->location != rule->fd_id)
2233 return -EINVAL;
2234
2235 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002236 if (fsp->flow_type == IP_USER_FLOW) {
2237 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2238 fsp->h_u.usr_ip4_spec.proto = 0;
2239 fsp->m_u.usr_ip4_spec.proto = 0;
2240 }
2241
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002242 /* Reverse the src and dest notion, since the HW views them from
2243 * Tx perspective where as the user expects it from Rx filter view.
2244 */
2245 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2246 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2247 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2248 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002249
2250 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2251 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2252 else
2253 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002254
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002255 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2256 struct i40e_vsi *vsi;
2257
2258 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2259 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2260 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2261 fsp->m_ext.data[1] = htonl(0x1);
2262 }
2263 }
2264
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002265 return 0;
2266}
2267
2268/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002269 * i40e_get_rxnfc - command to get RX flow classification rules
2270 * @netdev: network interface device structure
2271 * @cmd: ethtool rxnfc command
2272 *
2273 * Returns Success if the command is supported.
2274 **/
2275static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2276 u32 *rule_locs)
2277{
2278 struct i40e_netdev_priv *np = netdev_priv(netdev);
2279 struct i40e_vsi *vsi = np->vsi;
2280 struct i40e_pf *pf = vsi->back;
2281 int ret = -EOPNOTSUPP;
2282
2283 switch (cmd->cmd) {
2284 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002285 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002286 ret = 0;
2287 break;
2288 case ETHTOOL_GRXFH:
2289 ret = i40e_get_rss_hash_opts(pf, cmd);
2290 break;
2291 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002292 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002293 /* report total rule count */
2294 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002295 ret = 0;
2296 break;
2297 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002298 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002299 break;
2300 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002301 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2302 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002303 default:
2304 break;
2305 }
2306
2307 return ret;
2308}
2309
2310/**
2311 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2312 * @pf: pointer to the physical function struct
2313 * @cmd: ethtool rxnfc command
2314 *
2315 * Returns Success if the flow input set is supported.
2316 **/
2317static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2318{
2319 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002320 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2321 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002322
2323 /* RSS does not support anything other than hashing
2324 * to queues on src and dst IPs and ports
2325 */
2326 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2327 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2328 return -EINVAL;
2329
2330 /* We need at least the IP SRC and DEST fields for hashing */
2331 if (!(nfc->data & RXH_IP_SRC) ||
2332 !(nfc->data & RXH_IP_DST))
2333 return -EINVAL;
2334
2335 switch (nfc->flow_type) {
2336 case TCP_V4_FLOW:
2337 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2338 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002339 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002340 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002341 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2342 hena |=
2343 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2344
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002345 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002346 break;
2347 default:
2348 return -EINVAL;
2349 }
2350 break;
2351 case TCP_V6_FLOW:
2352 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2353 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002354 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002355 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002356 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2357 hena |=
2358 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2359
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002360 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002361 break;
2362 default:
2363 return -EINVAL;
2364 }
2365 break;
2366 case UDP_V4_FLOW:
2367 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2368 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002369 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002370 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002371 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2372 hena |=
2373 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2374 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2375
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002376 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2377 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002378 break;
2379 default:
2380 return -EINVAL;
2381 }
2382 break;
2383 case UDP_V6_FLOW:
2384 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2385 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002386 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002387 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002388 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2389 hena |=
2390 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2391 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2392
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002393 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2394 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002395 break;
2396 default:
2397 return -EINVAL;
2398 }
2399 break;
2400 case AH_ESP_V4_FLOW:
2401 case AH_V4_FLOW:
2402 case ESP_V4_FLOW:
2403 case SCTP_V4_FLOW:
2404 if ((nfc->data & RXH_L4_B_0_1) ||
2405 (nfc->data & RXH_L4_B_2_3))
2406 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002407 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002408 break;
2409 case AH_ESP_V6_FLOW:
2410 case AH_V6_FLOW:
2411 case ESP_V6_FLOW:
2412 case SCTP_V6_FLOW:
2413 if ((nfc->data & RXH_L4_B_0_1) ||
2414 (nfc->data & RXH_L4_B_2_3))
2415 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002416 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002417 break;
2418 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002419 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2420 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002421 break;
2422 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002423 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2424 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002425 break;
2426 default:
2427 return -EINVAL;
2428 }
2429
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002430 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2431 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002432 i40e_flush(hw);
2433
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002434 /* Save setting for future output/update */
2435 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2436
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002437 return 0;
2438}
2439
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002440/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002441 * i40e_match_fdir_input_set - Match a new filter against an existing one
2442 * @rule: The filter already added
2443 * @input: The new filter to comapre against
2444 *
2445 * Returns true if the two input set match
2446 **/
2447static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2448 struct i40e_fdir_filter *input)
2449{
2450 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2451 (rule->src_ip[0] != input->src_ip[0]) ||
2452 (rule->dst_port != input->dst_port) ||
2453 (rule->src_port != input->src_port))
2454 return false;
2455 return true;
2456}
2457
2458/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002459 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2460 * @vsi: Pointer to the targeted VSI
2461 * @input: The filter to update or NULL to indicate deletion
2462 * @sw_idx: Software index to the filter
2463 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002464 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002465 * This function updates (or deletes) a Flow Director entry from
2466 * the hlist of the corresponding PF
2467 *
2468 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002469 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002470static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2471 struct i40e_fdir_filter *input,
2472 u16 sw_idx,
2473 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002474{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002475 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002476 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002477 struct hlist_node *node2;
2478 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002479
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002480 parent = NULL;
2481 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002482
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002483 hlist_for_each_entry_safe(rule, node2,
2484 &pf->fdir_filter_list, fdir_node) {
2485 /* hash found, or no matching entry */
2486 if (rule->fd_id >= sw_idx)
2487 break;
2488 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002489 }
2490
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002491 /* if there is an old rule occupying our place remove it */
2492 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002493 if (input && !i40e_match_fdir_input_set(rule, input))
2494 err = i40e_add_del_fdir(vsi, rule, false);
2495 else if (!input)
2496 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002497 hlist_del(&rule->fdir_node);
2498 kfree(rule);
2499 pf->fdir_pf_active_filters--;
2500 }
2501
2502 /* If no input this was a delete, err should be 0 if a rule was
2503 * successfully found and removed from the list else -EINVAL
2504 */
2505 if (!input)
2506 return err;
2507
2508 /* initialize node and set software index */
2509 INIT_HLIST_NODE(&input->fdir_node);
2510
2511 /* add filter to the list */
2512 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002513 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002514 else
2515 hlist_add_head(&input->fdir_node,
2516 &pf->fdir_filter_list);
2517
2518 /* update counts */
2519 pf->fdir_pf_active_filters++;
2520
2521 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002522}
2523
2524/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002525 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2526 * @vsi: Pointer to the targeted VSI
2527 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002528 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002529 * The function removes a Flow Director filter entry from the
2530 * hlist of the corresponding PF
2531 *
2532 * Returns 0 on success
2533 */
2534static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2535 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002536{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002537 struct ethtool_rx_flow_spec *fsp =
2538 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002539 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002540 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002541
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002542 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2543 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2544 return -EBUSY;
2545
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002546 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2547 return -EBUSY;
2548
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002549 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002550
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002551 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002552 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002553}
2554
2555/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002556 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002557 * @vsi: pointer to the targeted VSI
2558 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002559 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002560 * Add Flow Director filters for a specific flow spec based on their
2561 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002562 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002563static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2564 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002565{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002566 struct ethtool_rx_flow_spec *fsp;
2567 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002568 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002569 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002570 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002571
2572 if (!vsi)
2573 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002574 pf = vsi->back;
2575
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002576 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2577 return -EOPNOTSUPP;
2578
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002579 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002580 return -ENOSPC;
2581
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002582 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2583 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2584 return -EBUSY;
2585
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002586 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2587 return -EBUSY;
2588
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002589 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2590
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002591 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2592 pf->hw.func_caps.fd_filters_guaranteed)) {
2593 return -EINVAL;
2594 }
2595
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002596 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2597 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002598 return -EINVAL;
2599
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002600 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002601
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002602 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002603 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002604
2605 input->fd_id = fsp->location;
2606
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002607 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2608 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2609 else
2610 input->dest_ctl =
2611 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2612
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002613 input->q_index = fsp->ring_cookie;
2614 input->flex_off = 0;
2615 input->pctype = 0;
2616 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002617 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002618 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002619 input->flow_type = fsp->flow_type;
2620 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002621
2622 /* Reverse the src and dest notion, since the HW expects them to be from
2623 * Tx perspective where as the input from user is from Rx filter view.
2624 */
2625 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2626 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2627 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2628 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002629
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002630 if (ntohl(fsp->m_ext.data[1])) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002631 vf_id = ntohl(fsp->h_ext.data[1]);
2632 if (vf_id >= pf->num_alloc_vfs) {
2633 netif_info(pf, drv, vsi->netdev,
2634 "Invalid VF id %d\n", vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002635 goto free_input;
2636 }
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002637 /* Find vsi id from vf id and override dest vsi */
2638 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2639 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002640 netif_info(pf, drv, vsi->netdev,
2641 "Invalid queue id %d for VF %d\n",
2642 input->q_index, vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002643 goto free_input;
2644 }
2645 }
2646
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002647 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002648free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002649 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002650 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002651 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002652 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002653
2654 return ret;
2655}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002656
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002657/**
2658 * i40e_set_rxnfc - command to set RX flow classification rules
2659 * @netdev: network interface device structure
2660 * @cmd: ethtool rxnfc command
2661 *
2662 * Returns Success if the command is supported.
2663 **/
2664static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2665{
2666 struct i40e_netdev_priv *np = netdev_priv(netdev);
2667 struct i40e_vsi *vsi = np->vsi;
2668 struct i40e_pf *pf = vsi->back;
2669 int ret = -EOPNOTSUPP;
2670
2671 switch (cmd->cmd) {
2672 case ETHTOOL_SRXFH:
2673 ret = i40e_set_rss_hash_opt(pf, cmd);
2674 break;
2675 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002676 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002677 break;
2678 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002679 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002680 break;
2681 default:
2682 break;
2683 }
2684
2685 return ret;
2686}
2687
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002688/**
2689 * i40e_max_channels - get Max number of combined channels supported
2690 * @vsi: vsi pointer
2691 **/
2692static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2693{
2694 /* TODO: This code assumes DCB and FD is disabled for now. */
2695 return vsi->alloc_queue_pairs;
2696}
2697
2698/**
2699 * i40e_get_channels - Get the current channels enabled and max supported etc.
2700 * @netdev: network interface device structure
2701 * @ch: ethtool channels structure
2702 *
2703 * We don't support separate tx and rx queues as channels. The other count
2704 * represents how many queues are being used for control. max_combined counts
2705 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2706 * q_vectors since we support a lot more queue pairs than q_vectors.
2707 **/
2708static void i40e_get_channels(struct net_device *dev,
2709 struct ethtool_channels *ch)
2710{
2711 struct i40e_netdev_priv *np = netdev_priv(dev);
2712 struct i40e_vsi *vsi = np->vsi;
2713 struct i40e_pf *pf = vsi->back;
2714
2715 /* report maximum channels */
2716 ch->max_combined = i40e_max_channels(vsi);
2717
2718 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002719 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002720 ch->max_other = ch->other_count;
2721
2722 /* Note: This code assumes DCB is disabled for now. */
2723 ch->combined_count = vsi->num_queue_pairs;
2724}
2725
2726/**
2727 * i40e_set_channels - Set the new channels count.
2728 * @netdev: network interface device structure
2729 * @ch: ethtool channels structure
2730 *
2731 * The new channels count may not be the same as requested by the user
2732 * since it gets rounded down to a power of 2 value.
2733 **/
2734static int i40e_set_channels(struct net_device *dev,
2735 struct ethtool_channels *ch)
2736{
2737 struct i40e_netdev_priv *np = netdev_priv(dev);
2738 unsigned int count = ch->combined_count;
2739 struct i40e_vsi *vsi = np->vsi;
2740 struct i40e_pf *pf = vsi->back;
2741 int new_count;
2742
2743 /* We do not support setting channels for any other VSI at present */
2744 if (vsi->type != I40E_VSI_MAIN)
2745 return -EINVAL;
2746
2747 /* verify they are not requesting separate vectors */
2748 if (!count || ch->rx_count || ch->tx_count)
2749 return -EINVAL;
2750
2751 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002752 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002753 return -EINVAL;
2754
2755 /* verify the number of channels does not exceed hardware limits */
2756 if (count > i40e_max_channels(vsi))
2757 return -EINVAL;
2758
2759 /* update feature limits from largest to smallest supported values */
2760 /* TODO: Flow director limit, DCB etc */
2761
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002762 /* use rss_reconfig to rebuild with new queue count and update traffic
2763 * class queue mapping
2764 */
2765 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002766 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002767 return 0;
2768 else
2769 return -EINVAL;
2770}
2771
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002772/**
2773 * i40e_get_rxfh_key_size - get the RSS hash key size
2774 * @netdev: network interface device structure
2775 *
2776 * Returns the table size.
2777 **/
2778static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2779{
2780 return I40E_HKEY_ARRAY_SIZE;
2781}
2782
2783/**
2784 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2785 * @netdev: network interface device structure
2786 *
2787 * Returns the table size.
2788 **/
2789static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2790{
2791 return I40E_HLUT_ARRAY_SIZE;
2792}
2793
2794static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2795 u8 *hfunc)
2796{
2797 struct i40e_netdev_priv *np = netdev_priv(netdev);
2798 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002799 u8 *lut, *seed = NULL;
2800 int ret;
2801 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002802
2803 if (hfunc)
2804 *hfunc = ETH_RSS_HASH_TOP;
2805
2806 if (!indir)
2807 return 0;
2808
Helin Zhang043dd652015-10-21 19:56:23 -04002809 seed = key;
2810 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2811 if (!lut)
2812 return -ENOMEM;
2813 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2814 if (ret)
2815 goto out;
2816 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2817 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002818
Helin Zhang043dd652015-10-21 19:56:23 -04002819out:
2820 kfree(lut);
2821
2822 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002823}
2824
2825/**
2826 * i40e_set_rxfh - set the rx flow hash indirection table
2827 * @netdev: network interface device structure
2828 * @indir: indirection table
2829 * @key: hash key
2830 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002831 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002832 * returns 0 after programming the table.
2833 **/
2834static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2835 const u8 *key, const u8 hfunc)
2836{
2837 struct i40e_netdev_priv *np = netdev_priv(netdev);
2838 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002839 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002840 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002841
2842 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2843 return -EOPNOTSUPP;
2844
2845 if (!indir)
2846 return 0;
2847
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002848 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002849 if (!vsi->rss_hkey_user) {
2850 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2851 GFP_KERNEL);
2852 if (!vsi->rss_hkey_user)
2853 return -ENOMEM;
2854 }
2855 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2856 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002857 }
Helin Zhang28c58692015-10-26 19:44:27 -04002858 if (!vsi->rss_lut_user) {
2859 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2860 if (!vsi->rss_lut_user)
2861 return -ENOMEM;
2862 }
Helin Zhang043dd652015-10-21 19:56:23 -04002863
Helin Zhang28c58692015-10-26 19:44:27 -04002864 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2865 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2866 vsi->rss_lut_user[i] = (u8)(indir[i]);
2867
2868 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2869 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002870}
2871
Greg Rose7e45ab42015-02-06 08:52:19 +00002872/**
2873 * i40e_get_priv_flags - report device private flags
2874 * @dev: network interface device structure
2875 *
2876 * The get string set count and the string set should be matched for each
2877 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2878 * array.
2879 *
2880 * Returns a u32 bitmap of flags.
2881 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002882static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002883{
2884 struct i40e_netdev_priv *np = netdev_priv(dev);
2885 struct i40e_vsi *vsi = np->vsi;
2886 struct i40e_pf *pf = vsi->back;
2887 u32 ret_flags = 0;
2888
Shannon Nelson9ac77262015-08-27 11:42:40 -04002889 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2890 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002891 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2892 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002893 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2894 I40E_PRIV_FLAGS_VEB_STATS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002895 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
2896 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002897 if (pf->hw.pf_id == 0) {
2898 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
2899 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
2900 }
Greg Rose7e45ab42015-02-06 08:52:19 +00002901
2902 return ret_flags;
2903}
2904
Shannon Nelson9ac77262015-08-27 11:42:40 -04002905/**
2906 * i40e_set_priv_flags - set private flags
2907 * @dev: network interface device structure
2908 * @flags: bit flags to be set
2909 **/
2910static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2911{
2912 struct i40e_netdev_priv *np = netdev_priv(dev);
2913 struct i40e_vsi *vsi = np->vsi;
2914 struct i40e_pf *pf = vsi->back;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002915 u16 sw_flags = 0, valid_flags = 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002916 bool reset_required = false;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002917 bool promisc_change = false;
2918 int ret;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002919
2920 /* NOTE: MFP is not settable */
2921
Shannon Nelson9ac77262015-08-27 11:42:40 -04002922 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2923 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2924 else
2925 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2926
Jesse Brandeburgef171782015-09-03 17:18:49 -04002927 /* allow the user to control the state of the Flow
2928 * Director ATR (Application Targeted Routing) feature
2929 * of the driver
2930 */
2931 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2932 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2933 } else {
2934 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2935 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2936 }
2937
Shannon Nelson66fc3602016-01-13 16:51:42 -08002938 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2939 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002940 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002941 reset_required = true;
2942 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2943 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002944 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002945 reset_required = true;
2946 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002947
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07002948 if (pf->hw.pf_id == 0) {
2949 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
2950 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
2951 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
2952 promisc_change = true;
2953 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
2954 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
2955 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
2956 promisc_change = true;
2957 }
2958 }
2959 if (promisc_change) {
2960 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
2961 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
2962 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
2963 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
2964 NULL);
2965 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
2966 dev_info(&pf->pdev->dev,
2967 "couldn't set switch config bits, err %s aq_err %s\n",
2968 i40e_stat_str(&pf->hw, ret),
2969 i40e_aq_str(&pf->hw,
2970 pf->hw.aq.asq_last_status));
2971 /* not a fatal problem, just keep going */
2972 }
2973 }
2974
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002975 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
2976 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
2977 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2978 else
2979 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2980
Jesse Brandeburg827de392015-11-06 15:26:07 -08002981 /* if needed, issue reset to cause things to take effect */
2982 if (reset_required)
2983 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2984
Shannon Nelson9ac77262015-08-27 11:42:40 -04002985 return 0;
2986}
2987
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002988static const struct ethtool_ops i40e_ethtool_ops = {
2989 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002990 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002991 .get_drvinfo = i40e_get_drvinfo,
2992 .get_regs_len = i40e_get_regs_len,
2993 .get_regs = i40e_get_regs,
2994 .nway_reset = i40e_nway_reset,
2995 .get_link = ethtool_op_get_link,
2996 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002997 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002998 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002999 .get_eeprom_len = i40e_get_eeprom_len,
3000 .get_eeprom = i40e_get_eeprom,
3001 .get_ringparam = i40e_get_ringparam,
3002 .set_ringparam = i40e_set_ringparam,
3003 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00003004 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003005 .get_msglevel = i40e_get_msglevel,
3006 .set_msglevel = i40e_set_msglevel,
3007 .get_rxnfc = i40e_get_rxnfc,
3008 .set_rxnfc = i40e_set_rxnfc,
3009 .self_test = i40e_diag_test,
3010 .get_strings = i40e_get_strings,
3011 .set_phys_id = i40e_set_phys_id,
3012 .get_sset_count = i40e_get_sset_count,
3013 .get_ethtool_stats = i40e_get_ethtool_stats,
3014 .get_coalesce = i40e_get_coalesce,
3015 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003016 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3017 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3018 .get_rxfh = i40e_get_rxfh,
3019 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003020 .get_channels = i40e_get_channels,
3021 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003022 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00003023 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04003024 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05003025 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05003026 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003027};
3028
3029void i40e_set_ethtool_ops(struct net_device *netdev)
3030{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003031 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003032}