blob: 905d66e87247873b6b71f35e8a0d27590241426b [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Shannon Nelson66fc3602016-01-13 16:51:42 -08004 * Copyright(c) 2013 - 2016 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040091 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Anjali Singhai Jaindd353102016-01-15 14:33:12 -080092 I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080093 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
94 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000095};
96
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000097/* These PF_STATs might look like duplicates of some NETDEV_STATs,
98 * but they are separate. This device supports Virtualization, and
99 * as such might have several netdevs supporting VMDq and FCoE going
100 * through a single port. The NETDEV_STATs are for individual netdevs
101 * seen at the top of the stack, and the PF_STATs are for the physical
102 * function at the bottom of the stack hosting those netdevs.
103 *
104 * The PF_STATs are appended to the netdev stats only when ethtool -S
105 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
106 */
Joe Perchesfe180a52016-09-26 20:17:01 -0700107static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000108 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
109 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000110 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
111 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
112 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
113 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
114 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
115 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
117 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000118 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400119 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000120 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
121 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
122 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000123 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000124 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000125 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
126 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
127 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
128 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
129 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
130 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
131 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
132 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
133 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
134 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
135 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
136 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
137 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
138 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
139 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
140 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
141 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
142 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
143 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
144 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
145 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
146 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
147 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
148 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800149 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000150 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400153 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400156 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000157
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000158 /* LPI stats */
159 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
160 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
161 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
162 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000163};
164
Vasu Dev38e00432014-08-01 13:27:03 -0700165#ifdef I40E_FCOE
166static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
167 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
168 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
169 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
170 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
171 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
172 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
173 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
174 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
175};
176
177#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000178#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000179 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
180 * 2 /* Tx and Rx together */ \
181 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000182#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
183#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000184#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700185#ifdef I40E_FCOE
186#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
188 I40E_FCOE_STATS_LEN + \
189 I40E_MISC_STATS_LEN + \
190 I40E_QUEUE_STATS_LEN((n)))
191#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000193 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700195#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000196#define I40E_PFC_STATS_LEN ( \
197 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
201 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
202 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400203#define I40E_VEB_TC_STATS_LEN ( \
204 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
207 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
208 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000209#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400210#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000211#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
212 I40E_PFC_STATS_LEN + \
213 I40E_VSI_STATS_LEN((n)))
214
215enum i40e_ethtool_test_id {
216 I40E_ETH_TEST_REG = 0,
217 I40E_ETH_TEST_EEPROM,
218 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000219 I40E_ETH_TEST_LINK,
220};
221
222static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
223 "Register test (offline)",
224 "Eeprom test (offline)",
225 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000226 "Link test (on/offline)"
227};
228
229#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
230
Greg Rose7e45ab42015-02-06 08:52:19 +0000231static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700232 "MFP",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400233 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400234 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400235 "veb-stats",
Anjali Singhai Jain72b74862016-01-08 17:50:21 -0800236 "hw-atr-eviction",
Greg Rose7e45ab42015-02-06 08:52:19 +0000237};
238
Shannon Nelson9ac77262015-08-27 11:42:40 -0400239#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000240
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700241/* Private flags with a global effect, restricted to PF 0 */
242static const char i40e_gl_priv_flags_strings[][ETH_GSTRING_LEN] = {
243 "vf-true-promisc-support",
244};
245
246#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_priv_flags_strings)
247
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000248/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000249 * i40e_partition_setting_complaint - generic complaint for MFP restriction
250 * @pf: the PF struct
251 **/
252static void i40e_partition_setting_complaint(struct i40e_pf *pf)
253{
254 dev_info(&pf->pdev->dev,
255 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
256}
257
258/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700259 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
260 * @phy_types: PHY types to convert
261 * @supported: pointer to the ethtool supported variable to fill in
262 * @advertising: pointer to the ethtool advertising variable to fill in
263 *
264 **/
265static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
266 u32 *advertising)
267{
Avinash Dayanand28537042016-06-20 09:10:33 -0700268 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800269 u64 phy_types = pf->hw.phy.phy_types;
270
Catherine Sullivan06566e52016-05-03 15:13:14 -0700271 *supported = 0x0;
272 *advertising = 0x0;
273
274 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
275 *supported |= SUPPORTED_Autoneg |
276 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700277 *advertising |= ADVERTISED_Autoneg;
278 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
279 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700280 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
281 *supported |= SUPPORTED_100baseT_Full;
282 *advertising |= ADVERTISED_100baseT_Full;
283 }
284 }
285 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
286 phy_types & I40E_CAP_PHY_TYPE_XFI ||
287 phy_types & I40E_CAP_PHY_TYPE_SFI ||
288 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
289 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
290 *supported |= SUPPORTED_10000baseT_Full;
291 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
292 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
294 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
295 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
296 *supported |= SUPPORTED_Autoneg |
297 SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700298 *advertising |= ADVERTISED_Autoneg;
299 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
300 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700301 }
302 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
303 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
304 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
305 *supported |= SUPPORTED_40000baseCR4_Full;
306 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
307 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
308 *supported |= SUPPORTED_Autoneg |
309 SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700310 *advertising |= ADVERTISED_Autoneg;
311 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
312 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700313 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700314 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700315 *supported |= SUPPORTED_Autoneg |
316 SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700317 *advertising |= ADVERTISED_Autoneg;
318 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
319 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700320 }
321 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
322 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
323 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
324 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
325 *supported |= SUPPORTED_Autoneg |
326 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700327 *advertising |= ADVERTISED_Autoneg;
328 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
329 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700330 }
331 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
332 *supported |= SUPPORTED_40000baseSR4_Full;
333 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
334 *supported |= SUPPORTED_40000baseLR4_Full;
335 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
336 *supported |= SUPPORTED_40000baseKR4_Full |
337 SUPPORTED_Autoneg;
338 *advertising |= ADVERTISED_40000baseKR4_Full |
339 ADVERTISED_Autoneg;
340 }
341 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
342 *supported |= SUPPORTED_20000baseKR2_Full |
343 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700344 *advertising |= ADVERTISED_Autoneg;
345 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
346 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700347 }
348 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800349 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
350 *supported |= SUPPORTED_10000baseKR_Full |
351 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700352 *advertising |= ADVERTISED_Autoneg;
353 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800354 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
355 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700356 }
357 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
358 *supported |= SUPPORTED_10000baseKX4_Full |
359 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700360 *advertising |= ADVERTISED_Autoneg;
361 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
362 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700363 }
364 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800365 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
366 *supported |= SUPPORTED_1000baseKX_Full |
367 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700368 *advertising |= ADVERTISED_Autoneg;
369 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800370 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
371 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700372 }
Carolyn Wyborny31232372016-11-21 13:03:48 -0800373 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
374 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
375 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
376 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
377 *supported |= SUPPORTED_Autoneg;
378 *advertising |= ADVERTISED_Autoneg;
379 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700380}
381
382/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000383 * i40e_get_settings_link_up - Get the Link settings for when link is up
384 * @hw: hw structure
385 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000388 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000389static void i40e_get_settings_link_up(struct i40e_hw *hw,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100390 struct ethtool_link_ksettings *cmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400391 struct net_device *netdev,
392 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000393{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000394 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000395 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700396 u32 e_advertising = 0x0;
397 u32 e_supported = 0x0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100398 u32 supported, advertising;
399
400 ethtool_convert_link_mode_to_legacy_u32(&supported,
401 cmd->link_modes.supported);
402 ethtool_convert_link_mode_to_legacy_u32(&advertising,
403 cmd->link_modes.advertising);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000404
Catherine Sullivane8278452015-02-06 08:52:08 +0000405 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000406 switch (hw_link_info->phy_type) {
407 case I40E_PHY_TYPE_40GBASE_CR4:
408 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100409 supported = SUPPORTED_Autoneg |
410 SUPPORTED_40000baseCR4_Full;
411 advertising = ADVERTISED_Autoneg |
412 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000413 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000414 case I40E_PHY_TYPE_XLAUI:
415 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000416 case I40E_PHY_TYPE_40GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100417 supported = SUPPORTED_40000baseCR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000418 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000419 case I40E_PHY_TYPE_40GBASE_SR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100420 supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000421 break;
422 case I40E_PHY_TYPE_40GBASE_LR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100423 supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000424 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000425 case I40E_PHY_TYPE_10GBASE_SR:
426 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000427 case I40E_PHY_TYPE_1000BASE_SX:
428 case I40E_PHY_TYPE_1000BASE_LX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100429 supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400430 if (hw_link_info->module_type[2] &
431 I40E_MODULE_TYPE_1000BASE_SX ||
432 hw_link_info->module_type[2] &
433 I40E_MODULE_TYPE_1000BASE_LX) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100434 supported |= SUPPORTED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400435 if (hw_link_info->requested_speeds &
436 I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100437 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400438 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000439 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100440 advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000441 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000442 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000443 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700444 case I40E_PHY_TYPE_100BASE_TX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100445 supported = SUPPORTED_Autoneg |
446 SUPPORTED_10000baseT_Full |
447 SUPPORTED_1000baseT_Full |
448 SUPPORTED_100baseT_Full;
449 advertising = ADVERTISED_Autoneg;
Catherine Sullivane8278452015-02-06 08:52:08 +0000450 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100451 advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000452 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100453 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700454 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100455 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400456 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400457 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100458 supported = SUPPORTED_Autoneg |
459 SUPPORTED_1000baseT_Full;
460 advertising = ADVERTISED_Autoneg |
461 ADVERTISED_1000baseT_Full;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400462 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000463 case I40E_PHY_TYPE_10GBASE_CR1_CU:
464 case I40E_PHY_TYPE_10GBASE_CR1:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100465 supported = SUPPORTED_Autoneg |
466 SUPPORTED_10000baseT_Full;
467 advertising = ADVERTISED_Autoneg |
468 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000469 break;
470 case I40E_PHY_TYPE_XAUI:
471 case I40E_PHY_TYPE_XFI:
472 case I40E_PHY_TYPE_SFI:
473 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000474 case I40E_PHY_TYPE_10GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100475 supported = SUPPORTED_10000baseT_Full;
476 advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000477 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000478 case I40E_PHY_TYPE_SGMII:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100479 supported = SUPPORTED_Autoneg |
480 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000481 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100482 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800483 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100484 supported |= SUPPORTED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400485 if (hw_link_info->requested_speeds &
486 I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100487 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400488 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000489 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400490 case I40E_PHY_TYPE_40GBASE_KR4:
491 case I40E_PHY_TYPE_20GBASE_KR2:
492 case I40E_PHY_TYPE_10GBASE_KR:
493 case I40E_PHY_TYPE_10GBASE_KX4:
494 case I40E_PHY_TYPE_1000BASE_KX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100495 supported |= SUPPORTED_40000baseKR4_Full |
496 SUPPORTED_20000baseKR2_Full |
497 SUPPORTED_10000baseKR_Full |
498 SUPPORTED_10000baseKX4_Full |
499 SUPPORTED_1000baseKX_Full |
500 SUPPORTED_Autoneg;
501 advertising |= ADVERTISED_40000baseKR4_Full |
502 ADVERTISED_20000baseKR2_Full |
503 ADVERTISED_10000baseKR_Full |
504 ADVERTISED_10000baseKX4_Full |
505 ADVERTISED_1000baseKX_Full |
506 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400507 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800508 case I40E_PHY_TYPE_25GBASE_KR:
509 case I40E_PHY_TYPE_25GBASE_CR:
510 case I40E_PHY_TYPE_25GBASE_SR:
511 case I40E_PHY_TYPE_25GBASE_LR:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100512 supported = SUPPORTED_Autoneg;
513 advertising = ADVERTISED_Autoneg;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800514 /* TODO: add speeds when ethtool is ready to support*/
515 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000516 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000517 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000518 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
519 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000520 }
521
Catherine Sullivan06566e52016-05-03 15:13:14 -0700522 /* Now that we've worked out everything that could be supported by the
523 * current PHY type, get what is supported by the NVM and them to
524 * get what is truly supported
525 */
526 i40e_phy_type_to_ethtool(pf, &e_supported,
527 &e_advertising);
528
Philippe Reynesa7f90942017-02-04 22:05:06 +0100529 supported = supported & e_supported;
530 advertising = advertising & e_advertising;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700531
Catherine Sullivane8278452015-02-06 08:52:08 +0000532 /* Set speed and duplex */
533 switch (link_speed) {
534 case I40E_LINK_SPEED_40GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100535 cmd->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000536 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800537 case I40E_LINK_SPEED_25GB:
538#ifdef SPEED_25000
Philippe Reynesa7f90942017-02-04 22:05:06 +0100539 cmd->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800540#else
541 netdev_info(netdev,
542 "Speed is 25G, display not supported by this version of ethtool.\n");
543#endif
544 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700545 case I40E_LINK_SPEED_20GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100546 cmd->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700547 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000548 case I40E_LINK_SPEED_10GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100549 cmd->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000550 break;
551 case I40E_LINK_SPEED_1GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100552 cmd->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000553 break;
554 case I40E_LINK_SPEED_100MB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100555 cmd->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000556 break;
557 default:
558 break;
559 }
Philippe Reynesa7f90942017-02-04 22:05:06 +0100560 cmd->base.duplex = DUPLEX_FULL;
561
562 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
563 supported);
564 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
565 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000566}
567
568/**
569 * i40e_get_settings_link_down - Get the Link settings for when link is down
570 * @hw: hw structure
571 * @ecmd: ethtool command to fill in
572 *
573 * Reports link settings that can be determined when link is down
574 **/
575static void i40e_get_settings_link_down(struct i40e_hw *hw,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100576 struct ethtool_link_ksettings *cmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400577 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000578{
Philippe Reynesa7f90942017-02-04 22:05:06 +0100579 u32 supported, advertising;
580
Catherine Sullivane8278452015-02-06 08:52:08 +0000581 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400582 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000583 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100584 i40e_phy_type_to_ethtool(pf, &supported, &advertising);
585
586 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
587 supported);
588 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
589 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000590
591 /* With no link speed and duplex are unknown */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100592 cmd->base.speed = SPEED_UNKNOWN;
593 cmd->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000594}
595
596/**
597 * i40e_get_settings - Get Link Speed and Duplex settings
598 * @netdev: network interface device structure
599 * @ecmd: ethtool command
600 *
601 * Reports speed/duplex settings based on media_type
602 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100603static int i40e_get_link_ksettings(struct net_device *netdev,
604 struct ethtool_link_ksettings *cmd)
Catherine Sullivane8278452015-02-06 08:52:08 +0000605{
606 struct i40e_netdev_priv *np = netdev_priv(netdev);
607 struct i40e_pf *pf = np->vsi->back;
608 struct i40e_hw *hw = &pf->hw;
609 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
610 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100611 u32 advertising;
Catherine Sullivane8278452015-02-06 08:52:08 +0000612
613 if (link_up)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100614 i40e_get_settings_link_up(hw, cmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000615 else
Philippe Reynesa7f90942017-02-04 22:05:06 +0100616 i40e_get_settings_link_down(hw, cmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000617
618 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000619 /* Set autoneg settings */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100620 cmd->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000621 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000622
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000623 switch (hw->phy.media_type) {
624 case I40E_MEDIA_TYPE_BACKPLANE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100625 ethtool_link_ksettings_add_link_mode(cmd, supported,
626 Autoneg);
627 ethtool_link_ksettings_add_link_mode(cmd, supported,
628 Backplane);
629 ethtool_link_ksettings_add_link_mode(cmd, advertising,
630 Autoneg);
631 ethtool_link_ksettings_add_link_mode(cmd, advertising,
632 Backplane);
633 cmd->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000634 break;
635 case I40E_MEDIA_TYPE_BASET:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100636 ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
637 ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
638 cmd->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000639 break;
640 case I40E_MEDIA_TYPE_DA:
641 case I40E_MEDIA_TYPE_CX4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100642 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
643 ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
644 cmd->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000645 break;
646 case I40E_MEDIA_TYPE_FIBER:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100647 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
648 cmd->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000649 break;
650 case I40E_MEDIA_TYPE_UNKNOWN:
651 default:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100652 cmd->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000653 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000654 }
655
Catherine Sullivane8278452015-02-06 08:52:08 +0000656 /* Set flow control settings */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100657 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000658
Catherine Sullivane8278452015-02-06 08:52:08 +0000659 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000660 case I40E_FC_FULL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100661 ethtool_link_ksettings_add_link_mode(cmd, advertising,
662 Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000663 break;
664 case I40E_FC_TX_PAUSE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100665 ethtool_link_ksettings_add_link_mode(cmd, advertising,
666 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000667 break;
668 case I40E_FC_RX_PAUSE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100669 ethtool_link_ksettings_add_link_mode(cmd, advertising,
670 Pause);
671 ethtool_link_ksettings_add_link_mode(cmd, advertising,
672 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000673 break;
674 default:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100675 ethtool_convert_link_mode_to_legacy_u32(
676 &advertising, cmd->link_modes.advertising);
677
678 advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
679
680 ethtool_convert_legacy_u32_to_link_mode(
681 cmd->link_modes.advertising, advertising);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000682 break;
683 }
684
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000685 return 0;
686}
687
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000688/**
689 * i40e_set_settings - Set Speed and Duplex
690 * @netdev: network interface device structure
691 * @ecmd: ethtool command
692 *
693 * Set speed/duplex per media_types advertised/forced
694 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100695static int i40e_set_link_ksettings(struct net_device *netdev,
696 const struct ethtool_link_ksettings *cmd)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000697{
698 struct i40e_netdev_priv *np = netdev_priv(netdev);
699 struct i40e_aq_get_phy_abilities_resp abilities;
700 struct i40e_aq_set_phy_config config;
701 struct i40e_pf *pf = np->vsi->back;
702 struct i40e_vsi *vsi = np->vsi;
703 struct i40e_hw *hw = &pf->hw;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100704 struct ethtool_link_ksettings safe_cmd;
705 struct ethtool_link_ksettings copy_cmd;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000706 i40e_status status = 0;
707 bool change = false;
708 int err = 0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100709 u32 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000710 u32 advertise;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100711 u32 tmp;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000712
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000713 /* Changing port settings is not supported if this isn't the
714 * port's controlling PF
715 */
716 if (hw->partition_id != 1) {
717 i40e_partition_setting_complaint(pf);
718 return -EOPNOTSUPP;
719 }
720
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000721 if (vsi != pf->vsi[pf->lan_vsi])
722 return -EOPNOTSUPP;
723
724 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
725 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000726 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700727 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000728 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000729 return -EOPNOTSUPP;
730
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400731 if (hw->device_id == I40E_DEV_ID_KX_B ||
732 hw->device_id == I40E_DEV_ID_KX_C ||
733 hw->device_id == I40E_DEV_ID_20G_KR2 ||
734 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
735 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
736 return -EOPNOTSUPP;
737 }
738
Philippe Reynesa7f90942017-02-04 22:05:06 +0100739 /* copy the cmd to copy_cmd to avoid modifying the origin */
740 memcpy(&copy_cmd, cmd, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000741
Philippe Reynesa7f90942017-02-04 22:05:06 +0100742 /* get our own copy of the bits to check against */
743 memset(&safe_cmd, 0, sizeof(struct ethtool_link_ksettings));
744 i40e_get_link_ksettings(netdev, &safe_cmd);
745
746 /* save autoneg and speed out of cmd */
747 autoneg = cmd->base.autoneg;
748 ethtool_convert_link_mode_to_legacy_u32(&advertise,
749 cmd->link_modes.advertising);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750
751 /* set autoneg and speed back to what they currently are */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100752 copy_cmd.base.autoneg = safe_cmd.base.autoneg;
753 ethtool_convert_link_mode_to_legacy_u32(
754 &tmp, safe_cmd.link_modes.advertising);
755 ethtool_convert_legacy_u32_to_link_mode(
756 copy_cmd.link_modes.advertising, tmp);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000757
Philippe Reynesa7f90942017-02-04 22:05:06 +0100758 copy_cmd.base.cmd = safe_cmd.base.cmd;
759
760 /* If copy_cmd and safe_cmd are not the same now, then they are
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000761 * trying to set something that we do not support
762 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100763 if (memcmp(&copy_cmd, &safe_cmd, sizeof(struct ethtool_link_ksettings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000764 return -EOPNOTSUPP;
765
766 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
767 usleep_range(1000, 2000);
768
769 /* Get the current phy config */
770 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
771 NULL);
772 if (status)
773 return -EAGAIN;
774
Catherine Sullivan124ed152014-07-12 07:28:12 +0000775 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000776 * set below
777 */
778 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000779 config.abilities = abilities.abilities;
780
781 /* Check autoneg */
782 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000783 /* If autoneg was not already enabled */
784 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400785 /* If autoneg is not supported, return error */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100786 if (!ethtool_link_ksettings_test_link_mode(
787 &safe_cmd, supported, Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400788 netdev_info(netdev, "Autoneg not supported on this phy\n");
789 return -EINVAL;
790 }
791 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000792 config.abilities = abilities.abilities |
793 I40E_AQ_PHY_ENABLE_AN;
794 change = true;
795 }
796 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000797 /* If autoneg is currently enabled */
798 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400799 /* If autoneg is supported 10GBASE_T is the only PHY
800 * that can disable it, so otherwise return error
801 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100802 if (ethtool_link_ksettings_test_link_mode(
803 &safe_cmd, supported, Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400804 hw->phy.link_info.phy_type !=
805 I40E_PHY_TYPE_10GBASE_T) {
806 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
807 return -EINVAL;
808 }
809 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000810 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000811 ~I40E_AQ_PHY_ENABLE_AN;
812 change = true;
813 }
814 }
815
Philippe Reynesa7f90942017-02-04 22:05:06 +0100816 ethtool_convert_link_mode_to_legacy_u32(&tmp,
817 safe_cmd.link_modes.supported);
818 if (advertise & ~tmp)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000819 return -EINVAL;
820
821 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000822 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000823 if (advertise & ADVERTISED_1000baseT_Full ||
824 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000825 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000826 if (advertise & ADVERTISED_10000baseT_Full ||
827 advertise & ADVERTISED_10000baseKX4_Full ||
828 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000829 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700830 if (advertise & ADVERTISED_20000baseKR2_Full)
831 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000832 if (advertise & ADVERTISED_40000baseKR4_Full ||
833 advertise & ADVERTISED_40000baseCR4_Full ||
834 advertise & ADVERTISED_40000baseSR4_Full ||
835 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000836 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000837
Catherine Sullivan0002e112015-08-26 15:14:16 -0400838 /* If speed didn't get set, set it to what it currently is.
839 * This is needed because if advertise is 0 (as it is when autoneg
840 * is disabled) then speed won't get set.
841 */
842 if (!config.link_speed)
843 config.link_speed = abilities.link_speed;
844
Catherine Sullivan124ed152014-07-12 07:28:12 +0000845 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000846 /* copy over the rest of the abilities */
847 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800848 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000849 config.eee_capability = abilities.eee_capability;
850 config.eeer = abilities.eeer_val;
851 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800852 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
853 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000854
Catherine Sullivane8278452015-02-06 08:52:08 +0000855 /* save the requested speeds */
856 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000857 /* set link and auto negotiation so changes take effect */
858 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
859 /* If link is up put link down */
860 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
861 /* Tell the OS link is going down, the link will go
862 * back up when fw says it is ready asynchronously
863 */
Matt Jaredc156f852015-08-27 11:42:39 -0400864 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000865 netif_carrier_off(netdev);
866 netif_tx_stop_all_queues(netdev);
867 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000868
869 /* make the aq call */
870 status = i40e_aq_set_phy_config(hw, &config, NULL);
871 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400872 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
873 i40e_stat_str(hw, status),
874 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000875 return -EAGAIN;
876 }
877
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400878 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000879 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400880 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
881 i40e_stat_str(hw, status),
882 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000883
884 } else {
885 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
886 }
887
888 return err;
889}
890
Jesse Brandeburga6599722014-06-04 08:45:25 +0000891static int i40e_nway_reset(struct net_device *netdev)
892{
893 /* restart autonegotiation */
894 struct i40e_netdev_priv *np = netdev_priv(netdev);
895 struct i40e_pf *pf = np->vsi->back;
896 struct i40e_hw *hw = &pf->hw;
897 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
898 i40e_status ret = 0;
899
900 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
901 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400902 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
903 i40e_stat_str(hw, ret),
904 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000905 return -EIO;
906 }
907
908 return 0;
909}
910
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000911/**
912 * i40e_get_pauseparam - Get Flow Control status
913 * Return tx/rx-pause status
914 **/
915static void i40e_get_pauseparam(struct net_device *netdev,
916 struct ethtool_pauseparam *pause)
917{
918 struct i40e_netdev_priv *np = netdev_priv(netdev);
919 struct i40e_pf *pf = np->vsi->back;
920 struct i40e_hw *hw = &pf->hw;
921 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000922 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000923
924 pause->autoneg =
925 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
926 AUTONEG_ENABLE : AUTONEG_DISABLE);
927
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000928 /* PFC enabled so report LFC as off */
929 if (dcbx_cfg->pfc.pfcenable) {
930 pause->rx_pause = 0;
931 pause->tx_pause = 0;
932 return;
933 }
934
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000935 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000936 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000937 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000938 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000939 } else if (hw->fc.current_mode == I40E_FC_FULL) {
940 pause->rx_pause = 1;
941 pause->tx_pause = 1;
942 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000943}
944
Catherine Sullivan2becc352014-06-04 08:45:27 +0000945/**
946 * i40e_set_pauseparam - Set Flow Control parameter
947 * @netdev: network interface device structure
948 * @pause: return tx/rx flow control status
949 **/
950static int i40e_set_pauseparam(struct net_device *netdev,
951 struct ethtool_pauseparam *pause)
952{
953 struct i40e_netdev_priv *np = netdev_priv(netdev);
954 struct i40e_pf *pf = np->vsi->back;
955 struct i40e_vsi *vsi = np->vsi;
956 struct i40e_hw *hw = &pf->hw;
957 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000958 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000959 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
960 i40e_status status;
961 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000962 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000963
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000964 /* Changing the port's flow control is not supported if this isn't the
965 * port's controlling PF
966 */
967 if (hw->partition_id != 1) {
968 i40e_partition_setting_complaint(pf);
969 return -EOPNOTSUPP;
970 }
971
Catherine Sullivan2becc352014-06-04 08:45:27 +0000972 if (vsi != pf->vsi[pf->lan_vsi])
973 return -EOPNOTSUPP;
974
975 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
976 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
977 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
978 return -EOPNOTSUPP;
979 }
980
981 /* If we have link and don't have autoneg */
982 if (!test_bit(__I40E_DOWN, &pf->state) &&
983 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
984 /* Send message that it might not necessarily work*/
985 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
986 }
987
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000988 if (dcbx_cfg->pfc.pfcenable) {
989 netdev_info(netdev,
990 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000991 return -EOPNOTSUPP;
992 }
993
994 if (pause->rx_pause && pause->tx_pause)
995 hw->fc.requested_mode = I40E_FC_FULL;
996 else if (pause->rx_pause && !pause->tx_pause)
997 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
998 else if (!pause->rx_pause && pause->tx_pause)
999 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1000 else if (!pause->rx_pause && !pause->tx_pause)
1001 hw->fc.requested_mode = I40E_FC_NONE;
1002 else
1003 return -EINVAL;
1004
Catherine Sullivan94128512014-07-12 07:28:16 +00001005 /* Tell the OS link is going down, the link will go back up when fw
1006 * says it is ready asynchronously
1007 */
Matt Jaredc156f852015-08-27 11:42:39 -04001008 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001009 netif_carrier_off(netdev);
1010 netif_tx_stop_all_queues(netdev);
1011
Catherine Sullivan2becc352014-06-04 08:45:27 +00001012 /* Set the fc mode and only restart an if link is up*/
1013 status = i40e_set_fc(hw, &aq_failures, link_up);
1014
1015 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001016 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1017 i40e_stat_str(hw, status),
1018 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001019 err = -EAGAIN;
1020 }
1021 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001022 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1023 i40e_stat_str(hw, status),
1024 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001025 err = -EAGAIN;
1026 }
1027 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001028 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1029 i40e_stat_str(hw, status),
1030 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001031 err = -EAGAIN;
1032 }
1033
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001034 if (!test_bit(__I40E_DOWN, &pf->state)) {
1035 /* Give it a little more time to try to come back */
1036 msleep(75);
1037 if (!test_bit(__I40E_DOWN, &pf->state))
1038 return i40e_nway_reset(netdev);
1039 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001040
1041 return err;
1042}
1043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001044static u32 i40e_get_msglevel(struct net_device *netdev)
1045{
1046 struct i40e_netdev_priv *np = netdev_priv(netdev);
1047 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001048 u32 debug_mask = pf->hw.debug_mask;
1049
1050 if (debug_mask)
1051 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001052
1053 return pf->msg_enable;
1054}
1055
1056static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1057{
1058 struct i40e_netdev_priv *np = netdev_priv(netdev);
1059 struct i40e_pf *pf = np->vsi->back;
1060
1061 if (I40E_DEBUG_USER & data)
1062 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001063 else
1064 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001065}
1066
1067static int i40e_get_regs_len(struct net_device *netdev)
1068{
1069 int reg_count = 0;
1070 int i;
1071
1072 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1073 reg_count += i40e_reg_list[i].elements;
1074
1075 return reg_count * sizeof(u32);
1076}
1077
1078static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1079 void *p)
1080{
1081 struct i40e_netdev_priv *np = netdev_priv(netdev);
1082 struct i40e_pf *pf = np->vsi->back;
1083 struct i40e_hw *hw = &pf->hw;
1084 u32 *reg_buf = p;
1085 int i, j, ri;
1086 u32 reg;
1087
1088 /* Tell ethtool which driver-version-specific regs output we have.
1089 *
1090 * At some point, if we have ethtool doing special formatting of
1091 * this data, it will rely on this version number to know how to
1092 * interpret things. Hence, this needs to be updated if/when the
1093 * diags register table is changed.
1094 */
1095 regs->version = 1;
1096
1097 /* loop through the diags reg table for what to print */
1098 ri = 0;
1099 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1100 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1101 reg = i40e_reg_list[i].offset
1102 + (j * i40e_reg_list[i].stride);
1103 reg_buf[ri++] = rd32(hw, reg);
1104 }
1105 }
1106
1107}
1108
1109static int i40e_get_eeprom(struct net_device *netdev,
1110 struct ethtool_eeprom *eeprom, u8 *bytes)
1111{
1112 struct i40e_netdev_priv *np = netdev_priv(netdev);
1113 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001114 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001115 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001116 u8 *eeprom_buff;
1117 u16 i, sectors;
1118 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001119 u32 magic;
1120
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001121#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001122 if (eeprom->len == 0)
1123 return -EINVAL;
1124
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001125 /* check for NVMUpdate access method */
1126 magic = hw->vendor_id | (hw->device_id << 16);
1127 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001128 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1129 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001130
1131 /* make sure it is the right magic for NVMUpdate */
1132 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001133 errno = -EINVAL;
1134 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1135 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1136 errno = -EBUSY;
1137 else
1138 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001139
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001140 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001141 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001142 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1143 ret_val, hw->aq.asq_last_status, errno,
1144 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1145 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001146
1147 return errno;
1148 }
1149
1150 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001151 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1152
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001153 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001154 if (!eeprom_buff)
1155 return -ENOMEM;
1156
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001157 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1158 if (ret_val) {
1159 dev_info(&pf->pdev->dev,
1160 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1161 ret_val, hw->aq.asq_last_status);
1162 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001163 }
1164
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001165 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1166 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1167 len = I40E_NVM_SECTOR_SIZE;
1168 last = false;
1169 for (i = 0; i < sectors; i++) {
1170 if (i == (sectors - 1)) {
1171 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1172 last = true;
1173 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001174 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1175 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001176 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001177 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001178 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001179 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001180 "read NVM failed, invalid offset 0x%x\n",
1181 offset);
1182 break;
1183 } else if (ret_val &&
1184 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1185 dev_info(&pf->pdev->dev,
1186 "read NVM failed, access, offset 0x%x\n",
1187 offset);
1188 break;
1189 } else if (ret_val) {
1190 dev_info(&pf->pdev->dev,
1191 "read NVM failed offset %d err=%d status=0x%x\n",
1192 offset, ret_val, hw->aq.asq_last_status);
1193 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001194 }
1195 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001197 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001198 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001199free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001200 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001201 return ret_val;
1202}
1203
1204static int i40e_get_eeprom_len(struct net_device *netdev)
1205{
1206 struct i40e_netdev_priv *np = netdev_priv(netdev);
1207 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001208 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001209
Lihong Yangc271dd62017-01-30 12:29:32 -08001210#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1211 if (hw->mac.type == I40E_MAC_X722) {
1212 val = X722_EEPROM_SCOPE_LIMIT + 1;
1213 return val;
1214 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001215 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1216 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1217 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1218 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001219 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001220 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001221}
1222
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001223static int i40e_set_eeprom(struct net_device *netdev,
1224 struct ethtool_eeprom *eeprom, u8 *bytes)
1225{
1226 struct i40e_netdev_priv *np = netdev_priv(netdev);
1227 struct i40e_hw *hw = &np->vsi->back->hw;
1228 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001229 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001230 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001231 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001232 u32 magic;
1233
1234 /* normal ethtool set_eeprom is not supported */
1235 magic = hw->vendor_id | (hw->device_id << 16);
1236 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001237 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001238 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001239 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1240 errno = -EINVAL;
1241 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1242 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1243 errno = -EBUSY;
1244 else
1245 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001246
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001247 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001248 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001249 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1250 ret_val, hw->aq.asq_last_status, errno,
1251 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1252 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001253
1254 return errno;
1255}
1256
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001257static void i40e_get_drvinfo(struct net_device *netdev,
1258 struct ethtool_drvinfo *drvinfo)
1259{
1260 struct i40e_netdev_priv *np = netdev_priv(netdev);
1261 struct i40e_vsi *vsi = np->vsi;
1262 struct i40e_pf *pf = vsi->back;
1263
1264 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1265 strlcpy(drvinfo->version, i40e_driver_version_str,
1266 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001267 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001268 sizeof(drvinfo->fw_version));
1269 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1270 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001271 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001272 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001273 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001274}
1275
1276static void i40e_get_ringparam(struct net_device *netdev,
1277 struct ethtool_ringparam *ring)
1278{
1279 struct i40e_netdev_priv *np = netdev_priv(netdev);
1280 struct i40e_pf *pf = np->vsi->back;
1281 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1282
1283 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1284 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1285 ring->rx_mini_max_pending = 0;
1286 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001287 ring->rx_pending = vsi->rx_rings[0]->count;
1288 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001289 ring->rx_mini_pending = 0;
1290 ring->rx_jumbo_pending = 0;
1291}
1292
1293static int i40e_set_ringparam(struct net_device *netdev,
1294 struct ethtool_ringparam *ring)
1295{
1296 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1297 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001298 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001299 struct i40e_vsi *vsi = np->vsi;
1300 struct i40e_pf *pf = vsi->back;
1301 u32 new_rx_count, new_tx_count;
1302 int i, err = 0;
1303
1304 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1305 return -EINVAL;
1306
Shannon Nelson1fa18372013-11-20 10:03:08 +00001307 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1308 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1309 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1310 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1311 netdev_info(netdev,
1312 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1313 ring->tx_pending, ring->rx_pending,
1314 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1315 return -EINVAL;
1316 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001317
Shannon Nelson1fa18372013-11-20 10:03:08 +00001318 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1319 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001320
1321 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001322 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1323 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001324 return 0;
1325
1326 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1327 usleep_range(1000, 2000);
1328
1329 if (!netif_running(vsi->netdev)) {
1330 /* simple case - set for the next time the netdev is started */
1331 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001332 vsi->tx_rings[i]->count = new_tx_count;
1333 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001334 }
1335 goto done;
1336 }
1337
1338 /* We can't just free everything and then setup again,
1339 * because the ISRs in MSI-X mode get passed pointers
1340 * to the Tx and Rx ring structs.
1341 */
1342
1343 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001344 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001345 netdev_info(netdev,
1346 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001347 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1349 sizeof(struct i40e_ring), GFP_KERNEL);
1350 if (!tx_rings) {
1351 err = -ENOMEM;
1352 goto done;
1353 }
1354
1355 for (i = 0; i < vsi->num_queue_pairs; i++) {
1356 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001357 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001358 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001359 /* the desc and bi pointers will be reallocated in the
1360 * setup call
1361 */
1362 tx_rings[i].desc = NULL;
1363 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1365 if (err) {
1366 while (i) {
1367 i--;
1368 i40e_free_tx_resources(&tx_rings[i]);
1369 }
1370 kfree(tx_rings);
1371 tx_rings = NULL;
1372
1373 goto done;
1374 }
1375 }
1376 }
1377
1378 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001379 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001380 netdev_info(netdev,
1381 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001382 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001383 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1384 sizeof(struct i40e_ring), GFP_KERNEL);
1385 if (!rx_rings) {
1386 err = -ENOMEM;
1387 goto free_tx;
1388 }
1389
1390 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001391 struct i40e_ring *ring;
1392 u16 unused;
1393
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001394 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001395 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001396 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001397 /* the desc and bi pointers will be reallocated in the
1398 * setup call
1399 */
1400 rx_rings[i].desc = NULL;
1401 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001402 /* this is to allow wr32 to have something to write to
1403 * during early allocation of Rx buffers
1404 */
1405 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001407 if (err)
1408 goto rx_unwind;
1409
1410 /* now allocate the Rx buffers to make sure the OS
1411 * has enough memory, any failure here means abort
1412 */
1413 ring = &rx_rings[i];
1414 unused = I40E_DESC_UNUSED(ring);
1415 err = i40e_alloc_rx_buffers(ring, unused);
1416rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001418 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001419 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001420 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421 kfree(rx_rings);
1422 rx_rings = NULL;
1423
1424 goto free_tx;
1425 }
1426 }
1427 }
1428
1429 /* Bring interface down, copy in the new ring info,
1430 * then restore the interface
1431 */
1432 i40e_down(vsi);
1433
1434 if (tx_rings) {
1435 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001436 i40e_free_tx_resources(vsi->tx_rings[i]);
1437 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001438 }
1439 kfree(tx_rings);
1440 tx_rings = NULL;
1441 }
1442
1443 if (rx_rings) {
1444 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001445 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001446 /* get the real tail offset */
1447 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1448 /* this is to fake out the allocation routine
1449 * into thinking it has to realloc everything
1450 * but the recycling logic will let us re-use
1451 * the buffers allocated above
1452 */
1453 rx_rings[i].next_to_use = 0;
1454 rx_rings[i].next_to_clean = 0;
1455 rx_rings[i].next_to_alloc = 0;
1456 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001457 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001458 }
1459 kfree(rx_rings);
1460 rx_rings = NULL;
1461 }
1462
1463 i40e_up(vsi);
1464
1465free_tx:
1466 /* error cleanup if the Rx allocations failed after getting Tx */
1467 if (tx_rings) {
1468 for (i = 0; i < vsi->num_queue_pairs; i++)
1469 i40e_free_tx_resources(&tx_rings[i]);
1470 kfree(tx_rings);
1471 tx_rings = NULL;
1472 }
1473
1474done:
1475 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1476
1477 return err;
1478}
1479
1480static int i40e_get_sset_count(struct net_device *netdev, int sset)
1481{
1482 struct i40e_netdev_priv *np = netdev_priv(netdev);
1483 struct i40e_vsi *vsi = np->vsi;
1484 struct i40e_pf *pf = vsi->back;
1485
1486 switch (sset) {
1487 case ETH_SS_TEST:
1488 return I40E_TEST_LEN;
1489 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001490 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001491 int len = I40E_PF_STATS_LEN(netdev);
1492
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001493 if ((pf->lan_veb != I40E_NO_VEB) &&
1494 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001495 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001496 return len;
1497 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001498 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001499 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001500 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001501 return I40E_PRIV_FLAGS_STR_LEN +
1502 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001503 default:
1504 return -EOPNOTSUPP;
1505 }
1506}
1507
1508static void i40e_get_ethtool_stats(struct net_device *netdev,
1509 struct ethtool_stats *stats, u64 *data)
1510{
1511 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001512 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513 struct i40e_vsi *vsi = np->vsi;
1514 struct i40e_pf *pf = vsi->back;
1515 int i = 0;
1516 char *p;
1517 int j;
1518 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001519 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520
1521 i40e_update_stats(vsi);
1522
1523 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1524 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1525 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1526 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1527 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001528 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1529 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1530 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1531 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1532 }
Vasu Dev38e00432014-08-01 13:27:03 -07001533#ifdef I40E_FCOE
1534 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1535 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1536 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1537 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1538 }
1539#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001540 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001541 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001542 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001543
1544 if (!tx_ring)
1545 continue;
1546
1547 /* process Tx ring statistics */
1548 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001549 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001550 data[i] = tx_ring->stats.packets;
1551 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001552 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001553 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001554
1555 /* Rx ring is the 2nd half of the queue pair */
1556 rx_ring = &tx_ring[1];
1557 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001558 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001559 data[i] = rx_ring->stats.packets;
1560 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001561 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001562 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001564 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001565 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001566 return;
1567
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001568 if ((pf->lan_veb != I40E_NO_VEB) &&
1569 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001570 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001571
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001572 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1573 p = (char *)veb;
1574 p += i40e_gstrings_veb_stats[j].stat_offset;
1575 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1576 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001577 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001578 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1579 data[i++] = veb->tc_stats.tc_tx_packets[j];
1580 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1581 data[i++] = veb->tc_stats.tc_rx_packets[j];
1582 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1583 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001585 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1586 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1587 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1588 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1589 }
1590 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1591 data[i++] = pf->stats.priority_xon_tx[j];
1592 data[i++] = pf->stats.priority_xoff_tx[j];
1593 }
1594 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1595 data[i++] = pf->stats.priority_xon_rx[j];
1596 data[i++] = pf->stats.priority_xoff_rx[j];
1597 }
1598 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1599 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600}
1601
1602static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1603 u8 *data)
1604{
1605 struct i40e_netdev_priv *np = netdev_priv(netdev);
1606 struct i40e_vsi *vsi = np->vsi;
1607 struct i40e_pf *pf = vsi->back;
1608 char *p = (char *)data;
1609 int i;
1610
1611 switch (stringset) {
1612 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001613 memcpy(data, i40e_gstrings_test,
1614 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001615 break;
1616 case ETH_SS_STATS:
1617 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1618 snprintf(p, ETH_GSTRING_LEN, "%s",
1619 i40e_gstrings_net_stats[i].stat_string);
1620 p += ETH_GSTRING_LEN;
1621 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001622 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1623 snprintf(p, ETH_GSTRING_LEN, "%s",
1624 i40e_gstrings_misc_stats[i].stat_string);
1625 p += ETH_GSTRING_LEN;
1626 }
Vasu Dev38e00432014-08-01 13:27:03 -07001627#ifdef I40E_FCOE
1628 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1629 snprintf(p, ETH_GSTRING_LEN, "%s",
1630 i40e_gstrings_fcoe_stats[i].stat_string);
1631 p += ETH_GSTRING_LEN;
1632 }
1633#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001634 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001635 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001636 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001637 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001638 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001639 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001640 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001641 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001642 p += ETH_GSTRING_LEN;
1643 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001644 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001645 return;
1646
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001647 if ((pf->lan_veb != I40E_NO_VEB) &&
1648 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001649 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1650 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1651 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652 p += ETH_GSTRING_LEN;
1653 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001654 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1655 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001656 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001657 p += ETH_GSTRING_LEN;
1658 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001659 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001660 p += ETH_GSTRING_LEN;
1661 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001662 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001663 p += ETH_GSTRING_LEN;
1664 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001665 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001666 p += ETH_GSTRING_LEN;
1667 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001668 }
1669 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1670 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1671 i40e_gstrings_stats[i].stat_string);
1672 p += ETH_GSTRING_LEN;
1673 }
1674 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1675 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001676 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001677 p += ETH_GSTRING_LEN;
1678 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001679 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001680 p += ETH_GSTRING_LEN;
1681 }
1682 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1683 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001684 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001685 p += ETH_GSTRING_LEN;
1686 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001687 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001688 p += ETH_GSTRING_LEN;
1689 }
1690 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1691 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001692 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001693 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694 }
1695 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1696 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001697 case ETH_SS_PRIV_FLAGS:
Jacob Kellere5d32202016-11-08 13:05:11 -08001698 memcpy(data, i40e_priv_flags_strings,
1699 I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
1700 data += I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN;
1701 if (pf->hw.pf_id == 0)
1702 memcpy(data, i40e_gl_priv_flags_strings,
1703 I40E_GL_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
Greg Rose7e45ab42015-02-06 08:52:19 +00001704 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001705 default:
1706 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001707 }
1708}
1709
1710static int i40e_get_ts_info(struct net_device *dev,
1711 struct ethtool_ts_info *info)
1712{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001713 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1714
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001715 /* only report HW timestamping if PTP is enabled */
1716 if (!(pf->flags & I40E_FLAG_PTP))
1717 return ethtool_op_get_ts_info(dev, info);
1718
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001719 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1720 SOF_TIMESTAMPING_RX_SOFTWARE |
1721 SOF_TIMESTAMPING_SOFTWARE |
1722 SOF_TIMESTAMPING_TX_HARDWARE |
1723 SOF_TIMESTAMPING_RX_HARDWARE |
1724 SOF_TIMESTAMPING_RAW_HARDWARE;
1725
1726 if (pf->ptp_clock)
1727 info->phc_index = ptp_clock_index(pf->ptp_clock);
1728 else
1729 info->phc_index = -1;
1730
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001731 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001732
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001733 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001734 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1735 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1736 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1737
1738 if (pf->flags & I40E_FLAG_PTP_L4_CAPABLE)
1739 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1740 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1741 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1742 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1743 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1744 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1745 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1746 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001747
1748 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001749}
1750
Shannon Nelson7b086392013-11-20 10:02:59 +00001751static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001752{
Shannon Nelson7b086392013-11-20 10:02:59 +00001753 struct i40e_netdev_priv *np = netdev_priv(netdev);
1754 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001755 i40e_status status;
1756 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001757
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001758 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001759 status = i40e_get_link_status(&pf->hw, &link_up);
1760 if (status) {
1761 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1762 *data = 1;
1763 return *data;
1764 }
1765
1766 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001767 *data = 0;
1768 else
1769 *data = 1;
1770
1771 return *data;
1772}
1773
Shannon Nelson7b086392013-11-20 10:02:59 +00001774static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001775{
Shannon Nelson7b086392013-11-20 10:02:59 +00001776 struct i40e_netdev_priv *np = netdev_priv(netdev);
1777 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001778
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001779 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001780 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001781
Shannon Nelson7b086392013-11-20 10:02:59 +00001782 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001783}
1784
Shannon Nelson7b086392013-11-20 10:02:59 +00001785static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001786{
Shannon Nelson7b086392013-11-20 10:02:59 +00001787 struct i40e_netdev_priv *np = netdev_priv(netdev);
1788 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001789
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001790 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001791 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001792
Shannon Nelson4443ec92014-11-13 08:23:12 +00001793 /* forcebly clear the NVM Update state machine */
1794 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1795
Shannon Nelson7b086392013-11-20 10:02:59 +00001796 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797}
1798
Shannon Nelson7b086392013-11-20 10:02:59 +00001799static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001800{
Shannon Nelson7b086392013-11-20 10:02:59 +00001801 struct i40e_netdev_priv *np = netdev_priv(netdev);
1802 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001803 u16 swc_old = pf->sw_int_count;
1804
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001805 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001806 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1807 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001808 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1809 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1810 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1811 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001812 usleep_range(1000, 2000);
1813 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001814
1815 return *data;
1816}
1817
Greg Rosee17bc412015-04-16 20:05:59 -04001818static inline bool i40e_active_vfs(struct i40e_pf *pf)
1819{
1820 struct i40e_vf *vfs = pf->vf;
1821 int i;
1822
1823 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001824 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001825 return true;
1826 return false;
1827}
1828
Greg Rose510efb22015-07-10 19:36:01 -04001829static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1830{
Alexander Duyck4b816442016-10-11 15:26:53 -07001831 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001832}
1833
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001834static void i40e_diag_test(struct net_device *netdev,
1835 struct ethtool_test *eth_test, u64 *data)
1836{
1837 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001838 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001839 struct i40e_pf *pf = np->vsi->back;
1840
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001841 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1842 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001843 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001844
Shannon Nelsonf551b432013-11-26 10:49:12 +00001845 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001846
Greg Rose510efb22015-07-10 19:36:01 -04001847 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001848 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001849 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001850 data[I40E_ETH_TEST_REG] = 1;
1851 data[I40E_ETH_TEST_EEPROM] = 1;
1852 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001853 data[I40E_ETH_TEST_LINK] = 1;
1854 eth_test->flags |= ETH_TEST_FL_FAILED;
1855 clear_bit(__I40E_TESTING, &pf->state);
1856 goto skip_ol_tests;
1857 }
1858
Greg Rose5b86c5c2015-02-26 16:14:35 +00001859 /* If the device is online then take it offline */
1860 if (if_running)
1861 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001862 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001863 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001864 /* This reset does not affect link - if it is
1865 * changed to a type of reset that does affect
1866 * link then the following link test would have
1867 * to be moved to before the reset
1868 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001869 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001870
Shannon Nelson7b086392013-11-20 10:02:59 +00001871 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001872 eth_test->flags |= ETH_TEST_FL_FAILED;
1873
Shannon Nelson7b086392013-11-20 10:02:59 +00001874 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001875 eth_test->flags |= ETH_TEST_FL_FAILED;
1876
Shannon Nelson7b086392013-11-20 10:02:59 +00001877 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001878 eth_test->flags |= ETH_TEST_FL_FAILED;
1879
Shannon Nelsonf551b432013-11-26 10:49:12 +00001880 /* run reg test last, a reset is required after it */
1881 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1882 eth_test->flags |= ETH_TEST_FL_FAILED;
1883
1884 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001885 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001886
1887 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001888 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001889 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001890 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001891 netif_info(pf, drv, netdev, "online testing starting\n");
1892
Shannon Nelson7b086392013-11-20 10:02:59 +00001893 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001894 eth_test->flags |= ETH_TEST_FL_FAILED;
1895
1896 /* Offline only tests, not run in online; pass by default */
1897 data[I40E_ETH_TEST_REG] = 0;
1898 data[I40E_ETH_TEST_EEPROM] = 0;
1899 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001900 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001901
Greg Rosee17bc412015-04-16 20:05:59 -04001902skip_ol_tests:
1903
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001904 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001905}
1906
1907static void i40e_get_wol(struct net_device *netdev,
1908 struct ethtool_wolinfo *wol)
1909{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001910 struct i40e_netdev_priv *np = netdev_priv(netdev);
1911 struct i40e_pf *pf = np->vsi->back;
1912 struct i40e_hw *hw = &pf->hw;
1913 u16 wol_nvm_bits;
1914
1915 /* NVM bit on means WoL disabled for the port */
1916 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001917 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001918 wol->supported = 0;
1919 wol->wolopts = 0;
1920 } else {
1921 wol->supported = WAKE_MAGIC;
1922 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1923 }
1924}
1925
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001926/**
1927 * i40e_set_wol - set the WakeOnLAN configuration
1928 * @netdev: the netdev in question
1929 * @wol: the ethtool WoL setting data
1930 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001931static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1932{
1933 struct i40e_netdev_priv *np = netdev_priv(netdev);
1934 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001935 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001936 struct i40e_hw *hw = &pf->hw;
1937 u16 wol_nvm_bits;
1938
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001939 /* WoL not supported if this isn't the controlling PF on the port */
1940 if (hw->partition_id != 1) {
1941 i40e_partition_setting_complaint(pf);
1942 return -EOPNOTSUPP;
1943 }
1944
1945 if (vsi != pf->vsi[pf->lan_vsi])
1946 return -EOPNOTSUPP;
1947
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001948 /* NVM bit on means WoL disabled for the port */
1949 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001950 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001951 return -EOPNOTSUPP;
1952
1953 /* only magic packet is supported */
1954 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1955 return -EOPNOTSUPP;
1956
1957 /* is this a new value? */
1958 if (pf->wol_en != !!wol->wolopts) {
1959 pf->wol_en = !!wol->wolopts;
1960 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1961 }
1962
1963 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001964}
1965
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001966static int i40e_set_phys_id(struct net_device *netdev,
1967 enum ethtool_phys_id_state state)
1968{
1969 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001970 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001971 struct i40e_pf *pf = np->vsi->back;
1972 struct i40e_hw *hw = &pf->hw;
1973 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001974 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001975
1976 switch (state) {
1977 case ETHTOOL_ID_ACTIVE:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001978 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001979 pf->led_status = i40e_led_get(hw);
1980 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001981 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001982 ret = i40e_led_get_phy(hw, &temp_status,
1983 &pf->phy_led_val);
1984 pf->led_status = temp_status;
1985 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001986 return blink_freq;
1987 case ETHTOOL_ID_ON:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001988 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001989 i40e_led_set(hw, 0xf, false);
1990 else
1991 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992 break;
1993 case ETHTOOL_ID_OFF:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001994 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001995 i40e_led_set(hw, 0x0, false);
1996 else
1997 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998 break;
1999 case ETHTOOL_ID_INACTIVE:
Henry Tieman4f9b4302016-11-08 13:05:18 -08002000 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
2001 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002002 } else {
2003 ret = i40e_led_set_phy(hw, false, pf->led_status,
2004 (pf->phy_led_val |
2005 I40E_PHY_LED_MODE_ORIG));
2006 i40e_aq_set_phy_debug(hw, 0, NULL);
2007 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002008 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002009 default:
2010 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002011 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002012 if (ret)
2013 return -ENOENT;
2014 else
2015 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002016}
2017
2018/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2019 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2020 * 125us (8000 interrupts per second) == ITR(62)
2021 */
2022
Jacob Keller65e87c02016-09-12 14:18:44 -07002023/**
2024 * __i40e_get_coalesce - get per-queue coalesce settings
2025 * @netdev: the netdev to check
2026 * @ec: ethtool coalesce data structure
2027 * @queue: which queue to pick
2028 *
2029 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2030 * are per queue. If queue is <0 then we default to queue 0 as the
2031 * representative value.
2032 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002033static int __i40e_get_coalesce(struct net_device *netdev,
2034 struct ethtool_coalesce *ec,
2035 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002036{
2037 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002038 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002039 struct i40e_vsi *vsi = np->vsi;
2040
2041 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2042 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2043
Kan Lianga75e8002016-02-19 09:24:04 -05002044 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2045 * return queue 0's value to represent.
2046 */
2047 if (queue < 0) {
2048 queue = 0;
2049 } else if (queue >= vsi->num_queue_pairs) {
2050 return -EINVAL;
2051 }
2052
Jacob Keller65e87c02016-09-12 14:18:44 -07002053 rx_ring = vsi->rx_rings[queue];
2054 tx_ring = vsi->tx_rings[queue];
2055
2056 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002057 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002058
Jacob Keller65e87c02016-09-12 14:18:44 -07002059 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002060 ec->use_adaptive_tx_coalesce = 1;
2061
Jacob Keller65e87c02016-09-12 14:18:44 -07002062 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2063 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2064
Kan Lianga75e8002016-02-19 09:24:04 -05002065
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002066 /* we use the _usecs_high to store/set the interrupt rate limit
2067 * that the hardware supports, that almost but not quite
2068 * fits the original intent of the ethtool variable,
2069 * the rx_coalesce_usecs_high limits total interrupts
2070 * per second from both tx/rx sources.
2071 */
2072 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2073 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002074
2075 return 0;
2076}
2077
Jacob Keller65e87c02016-09-12 14:18:44 -07002078/**
2079 * i40e_get_coalesce - get a netdev's coalesce settings
2080 * @netdev: the netdev to check
2081 * @ec: ethtool coalesce data structure
2082 *
2083 * Gets the coalesce settings for a particular netdev. Note that if user has
2084 * modified per-queue settings, this only guarantees to represent queue 0. See
2085 * __i40e_get_coalesce for more details.
2086 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002087static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002088 struct ethtool_coalesce *ec)
2089{
Kan Lianga75e8002016-02-19 09:24:04 -05002090 return __i40e_get_coalesce(netdev, ec, -1);
2091}
2092
Jacob Keller65e87c02016-09-12 14:18:44 -07002093/**
2094 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2095 * @netdev: netdev structure
2096 * @ec: ethtool's coalesce settings
2097 * @queue: the particular queue to read
2098 *
2099 * Will read a specific queue's coalesce settings
2100 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002101static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2102 struct ethtool_coalesce *ec)
2103{
2104 return __i40e_get_coalesce(netdev, ec, queue);
2105}
2106
Jacob Keller65e87c02016-09-12 14:18:44 -07002107/**
2108 * i40e_set_itr_per_queue - set ITR values for specific queue
2109 * @vsi: the VSI to set values for
2110 * @ec: coalesce settings from ethtool
2111 * @queue: the queue to modify
2112 *
2113 * Change the ITR settings for a specific queue.
2114 **/
2115
Kan Lianga75e8002016-02-19 09:24:04 -05002116static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2117 struct ethtool_coalesce *ec,
2118 int queue)
2119{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002120 struct i40e_pf *pf = vsi->back;
2121 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002122 struct i40e_q_vector *q_vector;
2123 u16 vector, intrl;
2124
Alan Brady1c0e6a32016-11-28 16:06:02 -08002125 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002126
2127 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2128 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2129
2130 if (ec->use_adaptive_rx_coalesce)
2131 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2132 else
2133 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2134
2135 if (ec->use_adaptive_tx_coalesce)
2136 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2137 else
2138 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2139
2140 q_vector = vsi->rx_rings[queue]->q_vector;
2141 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2142 vector = vsi->base_vector + q_vector->v_idx;
2143 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2144
2145 q_vector = vsi->tx_rings[queue]->q_vector;
2146 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2147 vector = vsi->base_vector + q_vector->v_idx;
2148 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2149
2150 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2151 i40e_flush(hw);
2152}
2153
Jacob Keller65e87c02016-09-12 14:18:44 -07002154/**
2155 * __i40e_set_coalesce - set coalesce settings for particular queue
2156 * @netdev: the netdev to change
2157 * @ec: ethtool coalesce settings
2158 * @queue: the queue to change
2159 *
2160 * Sets the coalesce settings for a particular queue.
2161 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002162static int __i40e_set_coalesce(struct net_device *netdev,
2163 struct ethtool_coalesce *ec,
2164 int queue)
2165{
2166 struct i40e_netdev_priv *np = netdev_priv(netdev);
2167 struct i40e_vsi *vsi = np->vsi;
2168 struct i40e_pf *pf = vsi->back;
Alan Brady33084062016-11-28 16:06:03 -08002169 u16 intrl_reg;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002170 int i;
2171
2172 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2173 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2174
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002175 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2176 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2177 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2178 return -EINVAL;
2179 }
2180
Alan Brady33084062016-11-28 16:06:03 -08002181 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2182 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2183 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002184 return -EINVAL;
2185 }
2186
Kan Lianga75e8002016-02-19 09:24:04 -05002187 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002188 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002189 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 -05002190 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2191 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2192 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2193 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002194 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002195
Alan Brady33084062016-11-28 16:06:03 -08002196 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2197 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2198 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2199 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2200 vsi->int_rate_limit);
2201 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002202
Kan Lianga75e8002016-02-19 09:24:04 -05002203 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002204 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002205 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 -05002206 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2207 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2208 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2209 return -EINVAL;
2210 }
2211
2212 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2213 * apply to all queues.
2214 */
2215 if (queue < 0) {
2216 for (i = 0; i < vsi->num_queue_pairs; i++)
2217 i40e_set_itr_per_queue(vsi, ec, i);
2218 } else if (queue < vsi->num_queue_pairs) {
2219 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002220 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002221 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2222 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002223 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002224 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002225
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002226 return 0;
2227}
2228
Jacob Keller65e87c02016-09-12 14:18:44 -07002229/**
2230 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2231 * @netdev: the netdev to change
2232 * @ec: ethtool coalesce settings
2233 *
2234 * This will set each queue to the same coalesce settings.
2235 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002236static int i40e_set_coalesce(struct net_device *netdev,
2237 struct ethtool_coalesce *ec)
2238{
2239 return __i40e_set_coalesce(netdev, ec, -1);
2240}
2241
Jacob Keller65e87c02016-09-12 14:18:44 -07002242/**
2243 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2244 * @netdev: the netdev to change
2245 * @ec: ethtool's coalesce settings
2246 * @queue: the queue to change
2247 *
2248 * Sets the specified queue's coalesce settings.
2249 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002250static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2251 struct ethtool_coalesce *ec)
2252{
2253 return __i40e_set_coalesce(netdev, ec, queue);
2254}
2255
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002256/**
2257 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2258 * @pf: pointer to the physical function struct
2259 * @cmd: ethtool rxnfc command
2260 *
2261 * Returns Success if the flow is supported, else Invalid Input.
2262 **/
2263static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2264{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002265 struct i40e_hw *hw = &pf->hw;
2266 u8 flow_pctype = 0;
2267 u64 i_set = 0;
2268
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002269 cmd->data = 0;
2270
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002271 switch (cmd->flow_type) {
2272 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002273 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2274 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002276 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2277 break;
2278 case TCP_V6_FLOW:
2279 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2280 break;
2281 case UDP_V6_FLOW:
2282 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2283 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002284 case SCTP_V4_FLOW:
2285 case AH_ESP_V4_FLOW:
2286 case AH_V4_FLOW:
2287 case ESP_V4_FLOW:
2288 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002289 case SCTP_V6_FLOW:
2290 case AH_ESP_V6_FLOW:
2291 case AH_V6_FLOW:
2292 case ESP_V6_FLOW:
2293 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002294 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002295 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2296 break;
2297 default:
2298 return -EINVAL;
2299 }
2300
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002301 /* Read flow based hash input set register */
2302 if (flow_pctype) {
2303 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2304 flow_pctype)) |
2305 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2306 flow_pctype)) << 32);
2307 }
2308
2309 /* Process bits of hash input set */
2310 if (i_set) {
2311 if (i_set & I40E_L4_SRC_MASK)
2312 cmd->data |= RXH_L4_B_0_1;
2313 if (i_set & I40E_L4_DST_MASK)
2314 cmd->data |= RXH_L4_B_2_3;
2315
2316 if (cmd->flow_type == TCP_V4_FLOW ||
2317 cmd->flow_type == UDP_V4_FLOW) {
2318 if (i_set & I40E_L3_SRC_MASK)
2319 cmd->data |= RXH_IP_SRC;
2320 if (i_set & I40E_L3_DST_MASK)
2321 cmd->data |= RXH_IP_DST;
2322 } else if (cmd->flow_type == TCP_V6_FLOW ||
2323 cmd->flow_type == UDP_V6_FLOW) {
2324 if (i_set & I40E_L3_V6_SRC_MASK)
2325 cmd->data |= RXH_IP_SRC;
2326 if (i_set & I40E_L3_V6_DST_MASK)
2327 cmd->data |= RXH_IP_DST;
2328 }
2329 }
2330
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002331 return 0;
2332}
2333
2334/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002335 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2336 * @pf: Pointer to the physical function struct
2337 * @cmd: The command to get or set Rx flow classification rules
2338 * @rule_locs: Array of used rule locations
2339 *
2340 * This function populates both the total and actual rule count of
2341 * the ethtool flow classification command
2342 *
2343 * Returns 0 on success or -EMSGSIZE if entry not found
2344 **/
2345static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2346 struct ethtool_rxnfc *cmd,
2347 u32 *rule_locs)
2348{
2349 struct i40e_fdir_filter *rule;
2350 struct hlist_node *node2;
2351 int cnt = 0;
2352
2353 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002354 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002355
2356 hlist_for_each_entry_safe(rule, node2,
2357 &pf->fdir_filter_list, fdir_node) {
2358 if (cnt == cmd->rule_cnt)
2359 return -EMSGSIZE;
2360
2361 rule_locs[cnt] = rule->fd_id;
2362 cnt++;
2363 }
2364
2365 cmd->rule_cnt = cnt;
2366
2367 return 0;
2368}
2369
2370/**
2371 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2372 * @pf: Pointer to the physical function struct
2373 * @cmd: The command to get or set Rx flow classification rules
2374 *
2375 * This function looks up a filter based on the Rx flow classification
2376 * command and fills the flow spec info for it if found
2377 *
2378 * Returns 0 on success or -EINVAL if filter not found
2379 **/
2380static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2381 struct ethtool_rxnfc *cmd)
2382{
2383 struct ethtool_rx_flow_spec *fsp =
2384 (struct ethtool_rx_flow_spec *)&cmd->fs;
2385 struct i40e_fdir_filter *rule = NULL;
2386 struct hlist_node *node2;
2387
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002388 hlist_for_each_entry_safe(rule, node2,
2389 &pf->fdir_filter_list, fdir_node) {
2390 if (fsp->location <= rule->fd_id)
2391 break;
2392 }
2393
2394 if (!rule || fsp->location != rule->fd_id)
2395 return -EINVAL;
2396
2397 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002398 if (fsp->flow_type == IP_USER_FLOW) {
2399 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2400 fsp->h_u.usr_ip4_spec.proto = 0;
2401 fsp->m_u.usr_ip4_spec.proto = 0;
2402 }
2403
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002404 /* Reverse the src and dest notion, since the HW views them from
2405 * Tx perspective where as the user expects it from Rx filter view.
2406 */
2407 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2408 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002409 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2410 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002411
2412 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2413 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2414 else
2415 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002416
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002417 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2418 struct i40e_vsi *vsi;
2419
2420 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2421 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2422 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2423 fsp->m_ext.data[1] = htonl(0x1);
2424 }
2425 }
2426
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002427 return 0;
2428}
2429
2430/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002431 * i40e_get_rxnfc - command to get RX flow classification rules
2432 * @netdev: network interface device structure
2433 * @cmd: ethtool rxnfc command
2434 *
2435 * Returns Success if the command is supported.
2436 **/
2437static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2438 u32 *rule_locs)
2439{
2440 struct i40e_netdev_priv *np = netdev_priv(netdev);
2441 struct i40e_vsi *vsi = np->vsi;
2442 struct i40e_pf *pf = vsi->back;
2443 int ret = -EOPNOTSUPP;
2444
2445 switch (cmd->cmd) {
2446 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002447 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002448 ret = 0;
2449 break;
2450 case ETHTOOL_GRXFH:
2451 ret = i40e_get_rss_hash_opts(pf, cmd);
2452 break;
2453 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002454 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002455 /* report total rule count */
2456 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002457 ret = 0;
2458 break;
2459 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002460 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002461 break;
2462 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002463 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2464 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002465 default:
2466 break;
2467 }
2468
2469 return ret;
2470}
2471
2472/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002473 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2474 * @nfc: pointer to user request
2475 * @i_setc bits currently set
2476 *
2477 * Returns value of bits to be set per user request
2478 **/
2479static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2480{
2481 u64 i_set = i_setc;
2482 u64 src_l3 = 0, dst_l3 = 0;
2483
2484 if (nfc->data & RXH_L4_B_0_1)
2485 i_set |= I40E_L4_SRC_MASK;
2486 else
2487 i_set &= ~I40E_L4_SRC_MASK;
2488 if (nfc->data & RXH_L4_B_2_3)
2489 i_set |= I40E_L4_DST_MASK;
2490 else
2491 i_set &= ~I40E_L4_DST_MASK;
2492
2493 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2494 src_l3 = I40E_L3_V6_SRC_MASK;
2495 dst_l3 = I40E_L3_V6_DST_MASK;
2496 } else if (nfc->flow_type == TCP_V4_FLOW ||
2497 nfc->flow_type == UDP_V4_FLOW) {
2498 src_l3 = I40E_L3_SRC_MASK;
2499 dst_l3 = I40E_L3_DST_MASK;
2500 } else {
2501 /* Any other flow type are not supported here */
2502 return i_set;
2503 }
2504
2505 if (nfc->data & RXH_IP_SRC)
2506 i_set |= src_l3;
2507 else
2508 i_set &= ~src_l3;
2509 if (nfc->data & RXH_IP_DST)
2510 i_set |= dst_l3;
2511 else
2512 i_set &= ~dst_l3;
2513
2514 return i_set;
2515}
2516
2517/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002518 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2519 * @pf: pointer to the physical function struct
2520 * @cmd: ethtool rxnfc command
2521 *
2522 * Returns Success if the flow input set is supported.
2523 **/
2524static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2525{
2526 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002527 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2528 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002529 u8 flow_pctype = 0;
2530 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002531
2532 /* RSS does not support anything other than hashing
2533 * to queues on src and dst IPs and ports
2534 */
2535 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2536 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2537 return -EINVAL;
2538
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002539 switch (nfc->flow_type) {
2540 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002541 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2542 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2543 hena |=
2544 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002545 break;
2546 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002547 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2548 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2549 hena |=
2550 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2551 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2552 hena |=
2553 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002554 break;
2555 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002556 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2557 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2558 hena |=
2559 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2560 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002561
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002562 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002563 break;
2564 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002565 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2566 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2567 hena |=
2568 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2569 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002570
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002571 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002572 break;
2573 case AH_ESP_V4_FLOW:
2574 case AH_V4_FLOW:
2575 case ESP_V4_FLOW:
2576 case SCTP_V4_FLOW:
2577 if ((nfc->data & RXH_L4_B_0_1) ||
2578 (nfc->data & RXH_L4_B_2_3))
2579 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002580 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002581 break;
2582 case AH_ESP_V6_FLOW:
2583 case AH_V6_FLOW:
2584 case ESP_V6_FLOW:
2585 case SCTP_V6_FLOW:
2586 if ((nfc->data & RXH_L4_B_0_1) ||
2587 (nfc->data & RXH_L4_B_2_3))
2588 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002589 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002590 break;
2591 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002592 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2593 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002594 break;
2595 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002596 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2597 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002598 break;
2599 default:
2600 return -EINVAL;
2601 }
2602
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002603 if (flow_pctype) {
2604 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2605 flow_pctype)) |
2606 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2607 flow_pctype)) << 32);
2608 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2609 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2610 (u32)i_set);
2611 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2612 (u32)(i_set >> 32));
2613 hena |= BIT_ULL(flow_pctype);
2614 }
2615
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002616 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2617 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002618 i40e_flush(hw);
2619
2620 return 0;
2621}
2622
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002623/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002624 * i40e_match_fdir_input_set - Match a new filter against an existing one
2625 * @rule: The filter already added
2626 * @input: The new filter to comapre against
2627 *
2628 * Returns true if the two input set match
2629 **/
2630static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2631 struct i40e_fdir_filter *input)
2632{
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002633 if ((rule->dst_ip != input->dst_ip) ||
2634 (rule->src_ip != input->src_ip) ||
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002635 (rule->dst_port != input->dst_port) ||
2636 (rule->src_port != input->src_port))
2637 return false;
2638 return true;
2639}
2640
2641/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002642 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2643 * @vsi: Pointer to the targeted VSI
2644 * @input: The filter to update or NULL to indicate deletion
2645 * @sw_idx: Software index to the filter
2646 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002647 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002648 * This function updates (or deletes) a Flow Director entry from
2649 * the hlist of the corresponding PF
2650 *
2651 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002652 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002653static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2654 struct i40e_fdir_filter *input,
2655 u16 sw_idx,
2656 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002657{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002658 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002659 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002660 struct hlist_node *node2;
2661 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002662
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002663 parent = NULL;
2664 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002665
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002666 hlist_for_each_entry_safe(rule, node2,
2667 &pf->fdir_filter_list, fdir_node) {
2668 /* hash found, or no matching entry */
2669 if (rule->fd_id >= sw_idx)
2670 break;
2671 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002672 }
2673
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002674 /* if there is an old rule occupying our place remove it */
2675 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002676 if (input && !i40e_match_fdir_input_set(rule, input))
2677 err = i40e_add_del_fdir(vsi, rule, false);
2678 else if (!input)
2679 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002680 hlist_del(&rule->fdir_node);
2681 kfree(rule);
2682 pf->fdir_pf_active_filters--;
2683 }
2684
2685 /* If no input this was a delete, err should be 0 if a rule was
2686 * successfully found and removed from the list else -EINVAL
2687 */
2688 if (!input)
2689 return err;
2690
2691 /* initialize node and set software index */
2692 INIT_HLIST_NODE(&input->fdir_node);
2693
2694 /* add filter to the list */
2695 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002696 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002697 else
2698 hlist_add_head(&input->fdir_node,
2699 &pf->fdir_filter_list);
2700
2701 /* update counts */
2702 pf->fdir_pf_active_filters++;
2703
2704 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002705}
2706
2707/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002708 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2709 * @vsi: Pointer to the targeted VSI
2710 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002711 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002712 * The function removes a Flow Director filter entry from the
2713 * hlist of the corresponding PF
2714 *
2715 * Returns 0 on success
2716 */
2717static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2718 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002719{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002720 struct ethtool_rx_flow_spec *fsp =
2721 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002722 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002723 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002724
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002725 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2726 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2727 return -EBUSY;
2728
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002729 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2730 return -EBUSY;
2731
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002732 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002733
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002734 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002735 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002736}
2737
2738/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002739 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002740 * @vsi: pointer to the targeted VSI
2741 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002742 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002743 * Add Flow Director filters for a specific flow spec based on their
2744 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002745 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002746static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2747 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002748{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002749 struct ethtool_rx_flow_spec *fsp;
2750 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002751 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002752 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002753 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002754
2755 if (!vsi)
2756 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002757 pf = vsi->back;
2758
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002759 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2760 return -EOPNOTSUPP;
2761
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08002762 if (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002763 return -ENOSPC;
2764
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002765 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2766 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2767 return -EBUSY;
2768
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002769 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2770 return -EBUSY;
2771
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002772 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2773
Jacob Keller1ec8dea2017-02-06 14:39:12 -08002774 /* Extended MAC field is not supported */
2775 if (fsp->flow_type & FLOW_MAC_EXT)
2776 return -EINVAL;
2777
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002778 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2779 pf->hw.func_caps.fd_filters_guaranteed)) {
2780 return -EINVAL;
2781 }
2782
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002783 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2784 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002785 return -EINVAL;
2786
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002787 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002788
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002789 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002790 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002791
2792 input->fd_id = fsp->location;
2793
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002794 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2795 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2796 else
2797 input->dest_ctl =
2798 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2799
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002800 input->q_index = fsp->ring_cookie;
2801 input->flex_off = 0;
2802 input->pctype = 0;
2803 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002804 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002805 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002806 input->flow_type = fsp->flow_type;
2807 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002808
2809 /* Reverse the src and dest notion, since the HW expects them to be from
2810 * Tx perspective where as the input from user is from Rx filter view.
2811 */
2812 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2813 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002814 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
2815 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002816
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002817 if (ntohl(fsp->m_ext.data[1])) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002818 vf_id = ntohl(fsp->h_ext.data[1]);
2819 if (vf_id >= pf->num_alloc_vfs) {
2820 netif_info(pf, drv, vsi->netdev,
2821 "Invalid VF id %d\n", vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002822 goto free_input;
2823 }
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002824 /* Find vsi id from vf id and override dest vsi */
2825 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2826 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
Shannon Nelsonbab3a342016-04-12 08:30:42 -07002827 netif_info(pf, drv, vsi->netdev,
2828 "Invalid queue id %d for VF %d\n",
2829 input->q_index, vf_id);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002830 goto free_input;
2831 }
2832 }
2833
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002834 ret = i40e_add_del_fdir(vsi, input, true);
2835 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08002836 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002837
Jacob Keller01016da2017-02-06 14:38:40 -08002838 /* Add the input filter to the fdir_input_list, possibly replacing
2839 * a previous filter. Do not free the input structure after adding it
2840 * to the list as this would cause a use-after-free bug.
2841 */
2842 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
2843
2844 return 0;
2845
2846free_input:
2847 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002848 return ret;
2849}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002850
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002851/**
2852 * i40e_set_rxnfc - command to set RX flow classification rules
2853 * @netdev: network interface device structure
2854 * @cmd: ethtool rxnfc command
2855 *
2856 * Returns Success if the command is supported.
2857 **/
2858static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2859{
2860 struct i40e_netdev_priv *np = netdev_priv(netdev);
2861 struct i40e_vsi *vsi = np->vsi;
2862 struct i40e_pf *pf = vsi->back;
2863 int ret = -EOPNOTSUPP;
2864
2865 switch (cmd->cmd) {
2866 case ETHTOOL_SRXFH:
2867 ret = i40e_set_rss_hash_opt(pf, cmd);
2868 break;
2869 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002870 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002871 break;
2872 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002873 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002874 break;
2875 default:
2876 break;
2877 }
2878
2879 return ret;
2880}
2881
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002882/**
2883 * i40e_max_channels - get Max number of combined channels supported
2884 * @vsi: vsi pointer
2885 **/
2886static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2887{
2888 /* TODO: This code assumes DCB and FD is disabled for now. */
2889 return vsi->alloc_queue_pairs;
2890}
2891
2892/**
2893 * i40e_get_channels - Get the current channels enabled and max supported etc.
2894 * @netdev: network interface device structure
2895 * @ch: ethtool channels structure
2896 *
2897 * We don't support separate tx and rx queues as channels. The other count
2898 * represents how many queues are being used for control. max_combined counts
2899 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2900 * q_vectors since we support a lot more queue pairs than q_vectors.
2901 **/
2902static void i40e_get_channels(struct net_device *dev,
2903 struct ethtool_channels *ch)
2904{
2905 struct i40e_netdev_priv *np = netdev_priv(dev);
2906 struct i40e_vsi *vsi = np->vsi;
2907 struct i40e_pf *pf = vsi->back;
2908
2909 /* report maximum channels */
2910 ch->max_combined = i40e_max_channels(vsi);
2911
2912 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002913 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002914 ch->max_other = ch->other_count;
2915
2916 /* Note: This code assumes DCB is disabled for now. */
2917 ch->combined_count = vsi->num_queue_pairs;
2918}
2919
2920/**
2921 * i40e_set_channels - Set the new channels count.
2922 * @netdev: network interface device structure
2923 * @ch: ethtool channels structure
2924 *
2925 * The new channels count may not be the same as requested by the user
2926 * since it gets rounded down to a power of 2 value.
2927 **/
2928static int i40e_set_channels(struct net_device *dev,
2929 struct ethtool_channels *ch)
2930{
Jacob Keller59826d92016-07-27 12:02:35 -07002931 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002932 struct i40e_netdev_priv *np = netdev_priv(dev);
2933 unsigned int count = ch->combined_count;
2934 struct i40e_vsi *vsi = np->vsi;
2935 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07002936 struct i40e_fdir_filter *rule;
2937 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002938 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07002939 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002940
2941 /* We do not support setting channels for any other VSI at present */
2942 if (vsi->type != I40E_VSI_MAIN)
2943 return -EINVAL;
2944
2945 /* verify they are not requesting separate vectors */
2946 if (!count || ch->rx_count || ch->tx_count)
2947 return -EINVAL;
2948
2949 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002950 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002951 return -EINVAL;
2952
2953 /* verify the number of channels does not exceed hardware limits */
2954 if (count > i40e_max_channels(vsi))
2955 return -EINVAL;
2956
Jacob Keller59826d92016-07-27 12:02:35 -07002957 /* verify that the number of channels does not invalidate any current
2958 * flow director rules
2959 */
2960 hlist_for_each_entry_safe(rule, node2,
2961 &pf->fdir_filter_list, fdir_node) {
2962 if (rule->dest_ctl != drop && count <= rule->q_index) {
2963 dev_warn(&pf->pdev->dev,
2964 "Existing user defined filter %d assigns flow to queue %d\n",
2965 rule->fd_id, rule->q_index);
2966 err = -EINVAL;
2967 }
2968 }
2969
2970 if (err) {
2971 dev_err(&pf->pdev->dev,
2972 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
2973 count);
2974 return err;
2975 }
2976
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002977 /* update feature limits from largest to smallest supported values */
2978 /* TODO: Flow director limit, DCB etc */
2979
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002980 /* use rss_reconfig to rebuild with new queue count and update traffic
2981 * class queue mapping
2982 */
2983 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002984 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002985 return 0;
2986 else
2987 return -EINVAL;
2988}
2989
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002990/**
2991 * i40e_get_rxfh_key_size - get the RSS hash key size
2992 * @netdev: network interface device structure
2993 *
2994 * Returns the table size.
2995 **/
2996static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2997{
2998 return I40E_HKEY_ARRAY_SIZE;
2999}
3000
3001/**
3002 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
3003 * @netdev: network interface device structure
3004 *
3005 * Returns the table size.
3006 **/
3007static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
3008{
3009 return I40E_HLUT_ARRAY_SIZE;
3010}
3011
3012static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
3013 u8 *hfunc)
3014{
3015 struct i40e_netdev_priv *np = netdev_priv(netdev);
3016 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04003017 u8 *lut, *seed = NULL;
3018 int ret;
3019 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003020
3021 if (hfunc)
3022 *hfunc = ETH_RSS_HASH_TOP;
3023
3024 if (!indir)
3025 return 0;
3026
Helin Zhang043dd652015-10-21 19:56:23 -04003027 seed = key;
3028 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3029 if (!lut)
3030 return -ENOMEM;
3031 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
3032 if (ret)
3033 goto out;
3034 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3035 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003036
Helin Zhang043dd652015-10-21 19:56:23 -04003037out:
3038 kfree(lut);
3039
3040 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003041}
3042
3043/**
3044 * i40e_set_rxfh - set the rx flow hash indirection table
3045 * @netdev: network interface device structure
3046 * @indir: indirection table
3047 * @key: hash key
3048 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04003049 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003050 * returns 0 after programming the table.
3051 **/
3052static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
3053 const u8 *key, const u8 hfunc)
3054{
3055 struct i40e_netdev_priv *np = netdev_priv(netdev);
3056 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07003057 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04003058 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04003059 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003060
3061 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3062 return -EOPNOTSUPP;
3063
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003064 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04003065 if (!vsi->rss_hkey_user) {
3066 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
3067 GFP_KERNEL);
3068 if (!vsi->rss_hkey_user)
3069 return -ENOMEM;
3070 }
3071 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
3072 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003073 }
Helin Zhang28c58692015-10-26 19:44:27 -04003074 if (!vsi->rss_lut_user) {
3075 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3076 if (!vsi->rss_lut_user)
3077 return -ENOMEM;
3078 }
Helin Zhang043dd652015-10-21 19:56:23 -04003079
Helin Zhang28c58692015-10-26 19:44:27 -04003080 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07003081 if (indir)
3082 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3083 vsi->rss_lut_user[i] = (u8)(indir[i]);
3084 else
3085 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
3086 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04003087
3088 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
3089 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003090}
3091
Greg Rose7e45ab42015-02-06 08:52:19 +00003092/**
3093 * i40e_get_priv_flags - report device private flags
3094 * @dev: network interface device structure
3095 *
3096 * The get string set count and the string set should be matched for each
3097 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
3098 * array.
3099 *
3100 * Returns a u32 bitmap of flags.
3101 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00003102static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00003103{
3104 struct i40e_netdev_priv *np = netdev_priv(dev);
3105 struct i40e_vsi *vsi = np->vsi;
3106 struct i40e_pf *pf = vsi->back;
3107 u32 ret_flags = 0;
3108
Shannon Nelson9ac77262015-08-27 11:42:40 -04003109 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
3110 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04003111 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
3112 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003113 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
3114 I40E_PRIV_FLAGS_VEB_STATS : 0;
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003115 ret_flags |= pf->hw_disabled_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003116 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003117 if (pf->hw.pf_id == 0) {
3118 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ?
3119 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0;
3120 }
Greg Rose7e45ab42015-02-06 08:52:19 +00003121
3122 return ret_flags;
3123}
3124
Shannon Nelson9ac77262015-08-27 11:42:40 -04003125/**
3126 * i40e_set_priv_flags - set private flags
3127 * @dev: network interface device structure
3128 * @flags: bit flags to be set
3129 **/
3130static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
3131{
3132 struct i40e_netdev_priv *np = netdev_priv(dev);
3133 struct i40e_vsi *vsi = np->vsi;
3134 struct i40e_pf *pf = vsi->back;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003135 u16 sw_flags = 0, valid_flags = 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003136 bool reset_required = false;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003137 bool promisc_change = false;
3138 int ret;
Jesse Brandeburg827de392015-11-06 15:26:07 -08003139
3140 /* NOTE: MFP is not settable */
3141
Shannon Nelson9ac77262015-08-27 11:42:40 -04003142 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
3143 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
3144 else
3145 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
3146
Jesse Brandeburgef171782015-09-03 17:18:49 -04003147 /* allow the user to control the state of the Flow
3148 * Director ATR (Application Targeted Routing) feature
3149 * of the driver
3150 */
3151 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
3152 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
3153 } else {
3154 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003155 pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED;
Jacob Keller234dc4e2016-09-06 18:05:09 -07003156
3157 /* flush current ATR settings */
3158 set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04003159 }
3160
Shannon Nelson66fc3602016-01-13 16:51:42 -08003161 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3162 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003163 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003164 reset_required = true;
3165 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
3166 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003167 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08003168 reset_required = true;
3169 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04003170
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07003171 if (pf->hw.pf_id == 0) {
3172 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3173 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3174 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT;
3175 promisc_change = true;
3176 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) &&
3177 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) {
3178 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT;
3179 promisc_change = true;
3180 }
3181 }
3182 if (promisc_change) {
3183 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
3184 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3185 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
3186 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
3187 NULL);
3188 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
3189 dev_info(&pf->pdev->dev,
3190 "couldn't set switch config bits, err %s aq_err %s\n",
3191 i40e_stat_str(&pf->hw, ret),
3192 i40e_aq_str(&pf->hw,
3193 pf->hw.aq.asq_last_status));
3194 /* not a fatal problem, just keep going */
3195 }
3196 }
3197
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003198 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
3199 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003200 pf->hw_disabled_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003201 else
Harshitha Ramamurthyb77ac972017-02-03 10:57:42 -08003202 pf->hw_disabled_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08003203
Jesse Brandeburg827de392015-11-06 15:26:07 -08003204 /* if needed, issue reset to cause things to take effect */
3205 if (reset_required)
3206 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
3207
Shannon Nelson9ac77262015-08-27 11:42:40 -04003208 return 0;
3209}
3210
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003211static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003212 .get_drvinfo = i40e_get_drvinfo,
3213 .get_regs_len = i40e_get_regs_len,
3214 .get_regs = i40e_get_regs,
3215 .nway_reset = i40e_nway_reset,
3216 .get_link = ethtool_op_get_link,
3217 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00003218 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00003219 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003220 .get_eeprom_len = i40e_get_eeprom_len,
3221 .get_eeprom = i40e_get_eeprom,
3222 .get_ringparam = i40e_get_ringparam,
3223 .set_ringparam = i40e_set_ringparam,
3224 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00003225 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003226 .get_msglevel = i40e_get_msglevel,
3227 .set_msglevel = i40e_set_msglevel,
3228 .get_rxnfc = i40e_get_rxnfc,
3229 .set_rxnfc = i40e_set_rxnfc,
3230 .self_test = i40e_diag_test,
3231 .get_strings = i40e_get_strings,
3232 .set_phys_id = i40e_set_phys_id,
3233 .get_sset_count = i40e_get_sset_count,
3234 .get_ethtool_stats = i40e_get_ethtool_stats,
3235 .get_coalesce = i40e_get_coalesce,
3236 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003237 .get_rxfh_key_size = i40e_get_rxfh_key_size,
3238 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
3239 .get_rxfh = i40e_get_rxfh,
3240 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003241 .get_channels = i40e_get_channels,
3242 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003243 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00003244 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04003245 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05003246 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05003247 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01003248 .get_link_ksettings = i40e_get_link_ksettings,
3249 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003250};
3251
3252void i40e_set_ethtool_ops(struct net_device *netdev)
3253{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00003254 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003255}