blob: 9dcdf34699881510a2ef21f97be1aecbf462e408 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 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),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080092 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
93 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000094};
95
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096/* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
102 *
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
105 */
106static struct i40e_stats i40e_gstrings_stats[] = {
107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800148 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000149 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000150 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000151 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400152 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400153 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000154 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400155 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000156
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000157 /* LPI stats */
158 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
159 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
160 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
161 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000162};
163
Vasu Dev38e00432014-08-01 13:27:03 -0700164#ifdef I40E_FCOE
165static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
166 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
167 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
168 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
169 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
170 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
171 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
172 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
173 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
174};
175
176#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000177#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000178 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
179 * 2 /* Tx and Rx together */ \
180 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000181#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
182#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000183#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700184#ifdef I40E_FCOE
185#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
187 I40E_FCOE_STATS_LEN + \
188 I40E_MISC_STATS_LEN + \
189 I40E_QUEUE_STATS_LEN((n)))
190#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000192 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000193 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700194#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000195#define I40E_PFC_STATS_LEN ( \
196 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
201 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400202#define I40E_VEB_TC_STATS_LEN ( \
203 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
207 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000208#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400209#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000210#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
211 I40E_PFC_STATS_LEN + \
212 I40E_VSI_STATS_LEN((n)))
213
214enum i40e_ethtool_test_id {
215 I40E_ETH_TEST_REG = 0,
216 I40E_ETH_TEST_EEPROM,
217 I40E_ETH_TEST_INTR,
218 I40E_ETH_TEST_LOOPBACK,
219 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)",
226 "Loopback test (offline)",
227 "Link test (on/offline)"
228};
229
230#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
231
Greg Rose7e45ab42015-02-06 08:52:19 +0000232static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
233 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400234 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400235 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400236 "veb-stats",
Jesse Brandeburg827de392015-11-06 15:26:07 -0800237 "packet-split",
Greg Rose7e45ab42015-02-06 08:52:19 +0000238};
239
Shannon Nelson9ac77262015-08-27 11:42:40 -0400240#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000241
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000243 * i40e_partition_setting_complaint - generic complaint for MFP restriction
244 * @pf: the PF struct
245 **/
246static void i40e_partition_setting_complaint(struct i40e_pf *pf)
247{
248 dev_info(&pf->pdev->dev,
249 "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");
250}
251
252/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000253 * i40e_get_settings_link_up - Get the Link settings for when link is up
254 * @hw: hw structure
255 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000256 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000257 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000259static void i40e_get_settings_link_up(struct i40e_hw *hw,
260 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400261 struct net_device *netdev,
262 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000263{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000264 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 u32 link_speed = hw_link_info->link_speed;
266
Catherine Sullivane8278452015-02-06 08:52:08 +0000267 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000268 switch (hw_link_info->phy_type) {
269 case I40E_PHY_TYPE_40GBASE_CR4:
270 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000271 ecmd->supported = SUPPORTED_Autoneg |
272 SUPPORTED_40000baseCR4_Full;
273 ecmd->advertising = ADVERTISED_Autoneg |
274 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000275 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000276 case I40E_PHY_TYPE_XLAUI:
277 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000278 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000279 ecmd->supported = SUPPORTED_40000baseCR4_Full;
280 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000281 case I40E_PHY_TYPE_40GBASE_SR4:
282 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 break;
284 case I40E_PHY_TYPE_40GBASE_LR4:
285 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000286 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000287 case I40E_PHY_TYPE_10GBASE_SR:
288 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000289 case I40E_PHY_TYPE_1000BASE_SX:
290 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400291 ecmd->supported = SUPPORTED_10000baseT_Full;
292 if (hw_link_info->module_type[2] &
293 I40E_MODULE_TYPE_1000BASE_SX ||
294 hw_link_info->module_type[2] &
295 I40E_MODULE_TYPE_1000BASE_LX) {
296 ecmd->supported |= SUPPORTED_1000baseT_Full;
297 if (hw_link_info->requested_speeds &
298 I40E_LINK_SPEED_1GB)
299 ecmd->advertising |= ADVERTISED_1000baseT_Full;
300 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000301 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
302 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000303 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000304 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000305 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000306 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000307 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400308 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000309 ecmd->advertising = ADVERTISED_Autoneg;
310 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
311 ecmd->advertising |= ADVERTISED_10000baseT_Full;
312 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
313 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400314 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400315 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
316 ecmd->supported = SUPPORTED_Autoneg |
317 SUPPORTED_1000baseT_Full;
318 ecmd->advertising = ADVERTISED_Autoneg |
319 ADVERTISED_1000baseT_Full;
320 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400321 case I40E_PHY_TYPE_100BASE_TX:
322 ecmd->supported = SUPPORTED_Autoneg |
323 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000324 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
325 ecmd->advertising |= ADVERTISED_100baseT_Full;
326 break;
327 case I40E_PHY_TYPE_10GBASE_CR1_CU:
328 case I40E_PHY_TYPE_10GBASE_CR1:
329 ecmd->supported = SUPPORTED_Autoneg |
330 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000331 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000332 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000333 break;
334 case I40E_PHY_TYPE_XAUI:
335 case I40E_PHY_TYPE_XFI:
336 case I40E_PHY_TYPE_SFI:
337 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000338 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000339 ecmd->supported = SUPPORTED_10000baseT_Full;
340 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000341 case I40E_PHY_TYPE_SGMII:
342 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400343 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000344 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
345 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800346 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400347 ecmd->supported |= SUPPORTED_100baseT_Full;
348 if (hw_link_info->requested_speeds &
349 I40E_LINK_SPEED_100MB)
350 ecmd->advertising |= ADVERTISED_100baseT_Full;
351 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000352 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400353 /* Backplane is set based on supported phy types in get_settings
354 * so don't set anything here but don't warn either
355 */
356 case I40E_PHY_TYPE_40GBASE_KR4:
357 case I40E_PHY_TYPE_20GBASE_KR2:
358 case I40E_PHY_TYPE_10GBASE_KR:
359 case I40E_PHY_TYPE_10GBASE_KX4:
360 case I40E_PHY_TYPE_1000BASE_KX:
361 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000362 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000363 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000364 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
365 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000366 }
367
Catherine Sullivane8278452015-02-06 08:52:08 +0000368 /* Set speed and duplex */
369 switch (link_speed) {
370 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400371 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000372 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700373 case I40E_LINK_SPEED_20GB:
374 ethtool_cmd_speed_set(ecmd, SPEED_20000);
375 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000376 case I40E_LINK_SPEED_10GB:
377 ethtool_cmd_speed_set(ecmd, SPEED_10000);
378 break;
379 case I40E_LINK_SPEED_1GB:
380 ethtool_cmd_speed_set(ecmd, SPEED_1000);
381 break;
382 case I40E_LINK_SPEED_100MB:
383 ethtool_cmd_speed_set(ecmd, SPEED_100);
384 break;
385 default:
386 break;
387 }
388 ecmd->duplex = DUPLEX_FULL;
389}
390
391/**
392 * i40e_get_settings_link_down - Get the Link settings for when link is down
393 * @hw: hw structure
394 * @ecmd: ethtool command to fill in
395 *
396 * Reports link settings that can be determined when link is down
397 **/
398static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400399 struct ethtool_cmd *ecmd,
400 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000401{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400402 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000403
404 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400405 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000406 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400407 ecmd->supported = 0x0;
408 ecmd->advertising = 0x0;
409 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
410 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400411 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400412 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400413 ADVERTISED_1000baseT_Full;
414 if (pf->hw.mac.type == I40E_MAC_X722) {
415 ecmd->supported |= SUPPORTED_100baseT_Full;
416 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivanf8db54cc2015-12-22 14:25:14 -0800417 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
418 ecmd->supported |= SUPPORTED_100baseT_Full;
419 ecmd->advertising |= ADVERTISED_100baseT_Full;
420 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400421 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000422 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400423 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
424 phy_types & I40E_CAP_PHY_TYPE_XFI ||
425 phy_types & I40E_CAP_PHY_TYPE_SFI ||
426 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
427 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
428 ecmd->supported |= SUPPORTED_10000baseT_Full;
429 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
430 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
431 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
432 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
433 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
434 ecmd->supported |= SUPPORTED_Autoneg |
435 SUPPORTED_10000baseT_Full;
436 ecmd->advertising |= ADVERTISED_Autoneg |
437 ADVERTISED_10000baseT_Full;
438 }
439 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
440 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
441 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
442 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
443 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
444 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
445 ecmd->supported |= SUPPORTED_Autoneg |
446 SUPPORTED_40000baseCR4_Full;
447 ecmd->advertising |= ADVERTISED_Autoneg |
448 ADVERTISED_40000baseCR4_Full;
449 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400450 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
451 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400452 ecmd->supported |= SUPPORTED_Autoneg |
453 SUPPORTED_100baseT_Full;
454 ecmd->advertising |= ADVERTISED_Autoneg |
455 ADVERTISED_100baseT_Full;
456 }
457 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
458 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
459 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
460 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
461 ecmd->supported |= SUPPORTED_Autoneg |
462 SUPPORTED_1000baseT_Full;
463 ecmd->advertising |= ADVERTISED_Autoneg |
464 ADVERTISED_1000baseT_Full;
465 }
466 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
467 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
468 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
469 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000470
471 /* With no link speed and duplex are unknown */
472 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
473 ecmd->duplex = DUPLEX_UNKNOWN;
474}
475
476/**
477 * i40e_get_settings - Get Link Speed and Duplex settings
478 * @netdev: network interface device structure
479 * @ecmd: ethtool command
480 *
481 * Reports speed/duplex settings based on media_type
482 **/
483static int i40e_get_settings(struct net_device *netdev,
484 struct ethtool_cmd *ecmd)
485{
486 struct i40e_netdev_priv *np = netdev_priv(netdev);
487 struct i40e_pf *pf = np->vsi->back;
488 struct i40e_hw *hw = &pf->hw;
489 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
490 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
491
492 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400493 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000494 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400495 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000496
497 /* Now set the settings that don't rely on link being up/down */
498
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400499 /* For backplane, supported and advertised are only reliant on the
500 * phy types the NVM specifies are supported.
501 */
502 if (hw->device_id == I40E_DEV_ID_KX_B ||
503 hw->device_id == I40E_DEV_ID_KX_C ||
504 hw->device_id == I40E_DEV_ID_20G_KR2 ||
505 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
506 ecmd->supported = SUPPORTED_Autoneg;
507 ecmd->advertising = ADVERTISED_Autoneg;
508 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
509 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
510 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
511 }
512 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
513 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
514 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
515 }
516 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
517 ecmd->supported |= SUPPORTED_10000baseKR_Full;
518 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
519 }
520 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
521 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
522 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
523 }
524 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
525 ecmd->supported |= SUPPORTED_1000baseKX_Full;
526 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
527 }
528 }
529
Catherine Sullivane8278452015-02-06 08:52:08 +0000530 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000531 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
532 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000533
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000534 switch (hw->phy.media_type) {
535 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000536 ecmd->supported |= SUPPORTED_Autoneg |
537 SUPPORTED_Backplane;
538 ecmd->advertising |= ADVERTISED_Autoneg |
539 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000540 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000541 break;
542 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000543 ecmd->supported |= SUPPORTED_TP;
544 ecmd->advertising |= ADVERTISED_TP;
545 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000546 break;
547 case I40E_MEDIA_TYPE_DA:
548 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000549 ecmd->supported |= SUPPORTED_FIBRE;
550 ecmd->advertising |= ADVERTISED_FIBRE;
551 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000552 break;
553 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000554 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000555 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000556 break;
557 case I40E_MEDIA_TYPE_UNKNOWN:
558 default:
559 ecmd->port = PORT_OTHER;
560 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000561 }
562
Catherine Sullivane8278452015-02-06 08:52:08 +0000563 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000564 ecmd->transceiver = XCVR_EXTERNAL;
565
Catherine Sullivane8278452015-02-06 08:52:08 +0000566 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000567 ecmd->supported |= SUPPORTED_Pause;
568
Catherine Sullivane8278452015-02-06 08:52:08 +0000569 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000570 case I40E_FC_FULL:
571 ecmd->advertising |= ADVERTISED_Pause;
572 break;
573 case I40E_FC_TX_PAUSE:
574 ecmd->advertising |= ADVERTISED_Asym_Pause;
575 break;
576 case I40E_FC_RX_PAUSE:
577 ecmd->advertising |= (ADVERTISED_Pause |
578 ADVERTISED_Asym_Pause);
579 break;
580 default:
581 ecmd->advertising &= ~(ADVERTISED_Pause |
582 ADVERTISED_Asym_Pause);
583 break;
584 }
585
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000586 return 0;
587}
588
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000589/**
590 * i40e_set_settings - Set Speed and Duplex
591 * @netdev: network interface device structure
592 * @ecmd: ethtool command
593 *
594 * Set speed/duplex per media_types advertised/forced
595 **/
596static int i40e_set_settings(struct net_device *netdev,
597 struct ethtool_cmd *ecmd)
598{
599 struct i40e_netdev_priv *np = netdev_priv(netdev);
600 struct i40e_aq_get_phy_abilities_resp abilities;
601 struct i40e_aq_set_phy_config config;
602 struct i40e_pf *pf = np->vsi->back;
603 struct i40e_vsi *vsi = np->vsi;
604 struct i40e_hw *hw = &pf->hw;
605 struct ethtool_cmd safe_ecmd;
606 i40e_status status = 0;
607 bool change = false;
608 int err = 0;
609 u8 autoneg;
610 u32 advertise;
611
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000612 /* Changing port settings is not supported if this isn't the
613 * port's controlling PF
614 */
615 if (hw->partition_id != 1) {
616 i40e_partition_setting_complaint(pf);
617 return -EOPNOTSUPP;
618 }
619
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000620 if (vsi != pf->vsi[pf->lan_vsi])
621 return -EOPNOTSUPP;
622
623 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
624 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000625 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
626 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000627 return -EOPNOTSUPP;
628
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400629 if (hw->device_id == I40E_DEV_ID_KX_B ||
630 hw->device_id == I40E_DEV_ID_KX_C ||
631 hw->device_id == I40E_DEV_ID_20G_KR2 ||
632 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
633 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
634 return -EOPNOTSUPP;
635 }
636
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000637 /* get our own copy of the bits to check against */
638 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
639 i40e_get_settings(netdev, &safe_ecmd);
640
641 /* save autoneg and speed out of ecmd */
642 autoneg = ecmd->autoneg;
643 advertise = ecmd->advertising;
644
645 /* set autoneg and speed back to what they currently are */
646 ecmd->autoneg = safe_ecmd.autoneg;
647 ecmd->advertising = safe_ecmd.advertising;
648
649 ecmd->cmd = safe_ecmd.cmd;
650 /* If ecmd and safe_ecmd are not the same now, then they are
651 * trying to set something that we do not support
652 */
653 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
654 return -EOPNOTSUPP;
655
656 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
657 usleep_range(1000, 2000);
658
659 /* Get the current phy config */
660 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
661 NULL);
662 if (status)
663 return -EAGAIN;
664
Catherine Sullivan124ed152014-07-12 07:28:12 +0000665 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000666 * set below
667 */
668 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000669 config.abilities = abilities.abilities;
670
671 /* Check autoneg */
672 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000673 /* If autoneg was not already enabled */
674 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400675 /* If autoneg is not supported, return error */
676 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
677 netdev_info(netdev, "Autoneg not supported on this phy\n");
678 return -EINVAL;
679 }
680 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000681 config.abilities = abilities.abilities |
682 I40E_AQ_PHY_ENABLE_AN;
683 change = true;
684 }
685 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000686 /* If autoneg is currently enabled */
687 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400688 /* If autoneg is supported 10GBASE_T is the only PHY
689 * that can disable it, so otherwise return error
690 */
691 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
692 hw->phy.link_info.phy_type !=
693 I40E_PHY_TYPE_10GBASE_T) {
694 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
695 return -EINVAL;
696 }
697 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000698 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000699 ~I40E_AQ_PHY_ENABLE_AN;
700 change = true;
701 }
702 }
703
704 if (advertise & ~safe_ecmd.supported)
705 return -EINVAL;
706
707 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000708 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000709 if (advertise & ADVERTISED_1000baseT_Full ||
710 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000711 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000712 if (advertise & ADVERTISED_10000baseT_Full ||
713 advertise & ADVERTISED_10000baseKX4_Full ||
714 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000715 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700716 if (advertise & ADVERTISED_20000baseKR2_Full)
717 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000718 if (advertise & ADVERTISED_40000baseKR4_Full ||
719 advertise & ADVERTISED_40000baseCR4_Full ||
720 advertise & ADVERTISED_40000baseSR4_Full ||
721 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000722 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000723
Catherine Sullivan0002e112015-08-26 15:14:16 -0400724 /* If speed didn't get set, set it to what it currently is.
725 * This is needed because if advertise is 0 (as it is when autoneg
726 * is disabled) then speed won't get set.
727 */
728 if (!config.link_speed)
729 config.link_speed = abilities.link_speed;
730
Catherine Sullivan124ed152014-07-12 07:28:12 +0000731 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000732 /* copy over the rest of the abilities */
733 config.phy_type = abilities.phy_type;
734 config.eee_capability = abilities.eee_capability;
735 config.eeer = abilities.eeer_val;
736 config.low_power_ctrl = abilities.d3_lpan;
737
Catherine Sullivane8278452015-02-06 08:52:08 +0000738 /* save the requested speeds */
739 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000740 /* set link and auto negotiation so changes take effect */
741 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
742 /* If link is up put link down */
743 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
744 /* Tell the OS link is going down, the link will go
745 * back up when fw says it is ready asynchronously
746 */
Matt Jaredc156f852015-08-27 11:42:39 -0400747 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000748 netif_carrier_off(netdev);
749 netif_tx_stop_all_queues(netdev);
750 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000751
752 /* make the aq call */
753 status = i40e_aq_set_phy_config(hw, &config, NULL);
754 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400755 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
756 i40e_stat_str(hw, status),
757 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000758 return -EAGAIN;
759 }
760
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400761 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000762 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400763 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
764 i40e_stat_str(hw, status),
765 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000766
767 } else {
768 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
769 }
770
771 return err;
772}
773
Jesse Brandeburga6599722014-06-04 08:45:25 +0000774static int i40e_nway_reset(struct net_device *netdev)
775{
776 /* restart autonegotiation */
777 struct i40e_netdev_priv *np = netdev_priv(netdev);
778 struct i40e_pf *pf = np->vsi->back;
779 struct i40e_hw *hw = &pf->hw;
780 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
781 i40e_status ret = 0;
782
783 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
784 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400785 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
786 i40e_stat_str(hw, ret),
787 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000788 return -EIO;
789 }
790
791 return 0;
792}
793
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000794/**
795 * i40e_get_pauseparam - Get Flow Control status
796 * Return tx/rx-pause status
797 **/
798static void i40e_get_pauseparam(struct net_device *netdev,
799 struct ethtool_pauseparam *pause)
800{
801 struct i40e_netdev_priv *np = netdev_priv(netdev);
802 struct i40e_pf *pf = np->vsi->back;
803 struct i40e_hw *hw = &pf->hw;
804 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000805 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000806
807 pause->autoneg =
808 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
809 AUTONEG_ENABLE : AUTONEG_DISABLE);
810
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000811 /* PFC enabled so report LFC as off */
812 if (dcbx_cfg->pfc.pfcenable) {
813 pause->rx_pause = 0;
814 pause->tx_pause = 0;
815 return;
816 }
817
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000818 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000819 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000820 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000821 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000822 } else if (hw->fc.current_mode == I40E_FC_FULL) {
823 pause->rx_pause = 1;
824 pause->tx_pause = 1;
825 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000826}
827
Catherine Sullivan2becc352014-06-04 08:45:27 +0000828/**
829 * i40e_set_pauseparam - Set Flow Control parameter
830 * @netdev: network interface device structure
831 * @pause: return tx/rx flow control status
832 **/
833static int i40e_set_pauseparam(struct net_device *netdev,
834 struct ethtool_pauseparam *pause)
835{
836 struct i40e_netdev_priv *np = netdev_priv(netdev);
837 struct i40e_pf *pf = np->vsi->back;
838 struct i40e_vsi *vsi = np->vsi;
839 struct i40e_hw *hw = &pf->hw;
840 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000841 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000842 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
843 i40e_status status;
844 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000845 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000846
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000847 /* Changing the port's flow control is not supported if this isn't the
848 * port's controlling PF
849 */
850 if (hw->partition_id != 1) {
851 i40e_partition_setting_complaint(pf);
852 return -EOPNOTSUPP;
853 }
854
Catherine Sullivan2becc352014-06-04 08:45:27 +0000855 if (vsi != pf->vsi[pf->lan_vsi])
856 return -EOPNOTSUPP;
857
858 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
859 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
860 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
861 return -EOPNOTSUPP;
862 }
863
864 /* If we have link and don't have autoneg */
865 if (!test_bit(__I40E_DOWN, &pf->state) &&
866 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
867 /* Send message that it might not necessarily work*/
868 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
869 }
870
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000871 if (dcbx_cfg->pfc.pfcenable) {
872 netdev_info(netdev,
873 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000874 return -EOPNOTSUPP;
875 }
876
877 if (pause->rx_pause && pause->tx_pause)
878 hw->fc.requested_mode = I40E_FC_FULL;
879 else if (pause->rx_pause && !pause->tx_pause)
880 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
881 else if (!pause->rx_pause && pause->tx_pause)
882 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
883 else if (!pause->rx_pause && !pause->tx_pause)
884 hw->fc.requested_mode = I40E_FC_NONE;
885 else
886 return -EINVAL;
887
Catherine Sullivan94128512014-07-12 07:28:16 +0000888 /* Tell the OS link is going down, the link will go back up when fw
889 * says it is ready asynchronously
890 */
Matt Jaredc156f852015-08-27 11:42:39 -0400891 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000892 netif_carrier_off(netdev);
893 netif_tx_stop_all_queues(netdev);
894
Catherine Sullivan2becc352014-06-04 08:45:27 +0000895 /* Set the fc mode and only restart an if link is up*/
896 status = i40e_set_fc(hw, &aq_failures, link_up);
897
898 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400899 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
900 i40e_stat_str(hw, status),
901 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000902 err = -EAGAIN;
903 }
904 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400905 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
906 i40e_stat_str(hw, status),
907 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000908 err = -EAGAIN;
909 }
910 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400911 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
912 i40e_stat_str(hw, status),
913 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000914 err = -EAGAIN;
915 }
916
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000917 if (!test_bit(__I40E_DOWN, &pf->state)) {
918 /* Give it a little more time to try to come back */
919 msleep(75);
920 if (!test_bit(__I40E_DOWN, &pf->state))
921 return i40e_nway_reset(netdev);
922 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000923
924 return err;
925}
926
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000927static u32 i40e_get_msglevel(struct net_device *netdev)
928{
929 struct i40e_netdev_priv *np = netdev_priv(netdev);
930 struct i40e_pf *pf = np->vsi->back;
931
932 return pf->msg_enable;
933}
934
935static void i40e_set_msglevel(struct net_device *netdev, u32 data)
936{
937 struct i40e_netdev_priv *np = netdev_priv(netdev);
938 struct i40e_pf *pf = np->vsi->back;
939
940 if (I40E_DEBUG_USER & data)
941 pf->hw.debug_mask = data;
942 pf->msg_enable = data;
943}
944
945static int i40e_get_regs_len(struct net_device *netdev)
946{
947 int reg_count = 0;
948 int i;
949
950 for (i = 0; i40e_reg_list[i].offset != 0; i++)
951 reg_count += i40e_reg_list[i].elements;
952
953 return reg_count * sizeof(u32);
954}
955
956static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
957 void *p)
958{
959 struct i40e_netdev_priv *np = netdev_priv(netdev);
960 struct i40e_pf *pf = np->vsi->back;
961 struct i40e_hw *hw = &pf->hw;
962 u32 *reg_buf = p;
963 int i, j, ri;
964 u32 reg;
965
966 /* Tell ethtool which driver-version-specific regs output we have.
967 *
968 * At some point, if we have ethtool doing special formatting of
969 * this data, it will rely on this version number to know how to
970 * interpret things. Hence, this needs to be updated if/when the
971 * diags register table is changed.
972 */
973 regs->version = 1;
974
975 /* loop through the diags reg table for what to print */
976 ri = 0;
977 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
978 for (j = 0; j < i40e_reg_list[i].elements; j++) {
979 reg = i40e_reg_list[i].offset
980 + (j * i40e_reg_list[i].stride);
981 reg_buf[ri++] = rd32(hw, reg);
982 }
983 }
984
985}
986
987static int i40e_get_eeprom(struct net_device *netdev,
988 struct ethtool_eeprom *eeprom, u8 *bytes)
989{
990 struct i40e_netdev_priv *np = netdev_priv(netdev);
991 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000992 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000993 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000994 u8 *eeprom_buff;
995 u16 i, sectors;
996 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000997 u32 magic;
998
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000999#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001000 if (eeprom->len == 0)
1001 return -EINVAL;
1002
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001003 /* check for NVMUpdate access method */
1004 magic = hw->vendor_id | (hw->device_id << 16);
1005 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +00001006 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001007 int errno;
1008
1009 /* make sure it is the right magic for NVMUpdate */
1010 if ((eeprom->magic >> 16) != hw->device_id)
1011 return -EINVAL;
1012
Shannon Nelsonc150a502014-11-13 08:23:13 +00001013 cmd = (struct i40e_nvm_access *)eeprom;
1014 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001015 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001016 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001017 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1018 ret_val, hw->aq.asq_last_status, errno,
1019 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1020 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001021
1022 return errno;
1023 }
1024
1025 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001026 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1027
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001028 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001029 if (!eeprom_buff)
1030 return -ENOMEM;
1031
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001032 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1033 if (ret_val) {
1034 dev_info(&pf->pdev->dev,
1035 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1036 ret_val, hw->aq.asq_last_status);
1037 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001038 }
1039
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001040 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1041 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1042 len = I40E_NVM_SECTOR_SIZE;
1043 last = false;
1044 for (i = 0; i < sectors; i++) {
1045 if (i == (sectors - 1)) {
1046 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1047 last = true;
1048 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001049 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1050 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001051 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001052 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001053 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001054 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001055 "read NVM failed, invalid offset 0x%x\n",
1056 offset);
1057 break;
1058 } else if (ret_val &&
1059 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1060 dev_info(&pf->pdev->dev,
1061 "read NVM failed, access, offset 0x%x\n",
1062 offset);
1063 break;
1064 } else if (ret_val) {
1065 dev_info(&pf->pdev->dev,
1066 "read NVM failed offset %d err=%d status=0x%x\n",
1067 offset, ret_val, hw->aq.asq_last_status);
1068 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001069 }
1070 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001071
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001072 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001073 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001074free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001075 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001076 return ret_val;
1077}
1078
1079static int i40e_get_eeprom_len(struct net_device *netdev)
1080{
1081 struct i40e_netdev_priv *np = netdev_priv(netdev);
1082 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001083 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001084
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001085 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1086 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1087 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1088 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001089 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001090 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001091}
1092
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001093static int i40e_set_eeprom(struct net_device *netdev,
1094 struct ethtool_eeprom *eeprom, u8 *bytes)
1095{
1096 struct i40e_netdev_priv *np = netdev_priv(netdev);
1097 struct i40e_hw *hw = &np->vsi->back->hw;
1098 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001099 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001100 int ret_val = 0;
1101 int errno;
1102 u32 magic;
1103
1104 /* normal ethtool set_eeprom is not supported */
1105 magic = hw->vendor_id | (hw->device_id << 16);
1106 if (eeprom->magic == magic)
1107 return -EOPNOTSUPP;
1108
1109 /* check for NVMUpdate access method */
1110 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1111 return -EINVAL;
1112
1113 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1114 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1115 return -EBUSY;
1116
Shannon Nelsonc150a502014-11-13 08:23:13 +00001117 cmd = (struct i40e_nvm_access *)eeprom;
1118 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001119 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001120 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001121 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1122 ret_val, hw->aq.asq_last_status, errno,
1123 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1124 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001125
1126 return errno;
1127}
1128
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001129static void i40e_get_drvinfo(struct net_device *netdev,
1130 struct ethtool_drvinfo *drvinfo)
1131{
1132 struct i40e_netdev_priv *np = netdev_priv(netdev);
1133 struct i40e_vsi *vsi = np->vsi;
1134 struct i40e_pf *pf = vsi->back;
1135
1136 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1137 strlcpy(drvinfo->version, i40e_driver_version_str,
1138 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001139 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001140 sizeof(drvinfo->fw_version));
1141 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1142 sizeof(drvinfo->bus_info));
1143}
1144
1145static void i40e_get_ringparam(struct net_device *netdev,
1146 struct ethtool_ringparam *ring)
1147{
1148 struct i40e_netdev_priv *np = netdev_priv(netdev);
1149 struct i40e_pf *pf = np->vsi->back;
1150 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1151
1152 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1153 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1154 ring->rx_mini_max_pending = 0;
1155 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001156 ring->rx_pending = vsi->rx_rings[0]->count;
1157 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001158 ring->rx_mini_pending = 0;
1159 ring->rx_jumbo_pending = 0;
1160}
1161
1162static int i40e_set_ringparam(struct net_device *netdev,
1163 struct ethtool_ringparam *ring)
1164{
1165 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1166 struct i40e_netdev_priv *np = netdev_priv(netdev);
1167 struct i40e_vsi *vsi = np->vsi;
1168 struct i40e_pf *pf = vsi->back;
1169 u32 new_rx_count, new_tx_count;
1170 int i, err = 0;
1171
1172 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1173 return -EINVAL;
1174
Shannon Nelson1fa18372013-11-20 10:03:08 +00001175 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1176 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1177 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1178 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1179 netdev_info(netdev,
1180 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1181 ring->tx_pending, ring->rx_pending,
1182 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1183 return -EINVAL;
1184 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001185
Shannon Nelson1fa18372013-11-20 10:03:08 +00001186 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1187 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001188
1189 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001190 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1191 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001192 return 0;
1193
1194 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1195 usleep_range(1000, 2000);
1196
1197 if (!netif_running(vsi->netdev)) {
1198 /* simple case - set for the next time the netdev is started */
1199 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001200 vsi->tx_rings[i]->count = new_tx_count;
1201 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001202 }
1203 goto done;
1204 }
1205
1206 /* We can't just free everything and then setup again,
1207 * because the ISRs in MSI-X mode get passed pointers
1208 * to the Tx and Rx ring structs.
1209 */
1210
1211 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001212 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001213 netdev_info(netdev,
1214 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001215 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001216 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1217 sizeof(struct i40e_ring), GFP_KERNEL);
1218 if (!tx_rings) {
1219 err = -ENOMEM;
1220 goto done;
1221 }
1222
1223 for (i = 0; i < vsi->num_queue_pairs; i++) {
1224 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001225 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001226 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001227 /* the desc and bi pointers will be reallocated in the
1228 * setup call
1229 */
1230 tx_rings[i].desc = NULL;
1231 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1233 if (err) {
1234 while (i) {
1235 i--;
1236 i40e_free_tx_resources(&tx_rings[i]);
1237 }
1238 kfree(tx_rings);
1239 tx_rings = NULL;
1240
1241 goto done;
1242 }
1243 }
1244 }
1245
1246 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001247 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248 netdev_info(netdev,
1249 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001250 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001251 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1252 sizeof(struct i40e_ring), GFP_KERNEL);
1253 if (!rx_rings) {
1254 err = -ENOMEM;
1255 goto free_tx;
1256 }
1257
1258 for (i = 0; i < vsi->num_queue_pairs; i++) {
1259 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001260 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001261 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001262 /* the desc and bi pointers will be reallocated in the
1263 * setup call
1264 */
1265 rx_rings[i].desc = NULL;
1266 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001267 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1268 if (err) {
1269 while (i) {
1270 i--;
1271 i40e_free_rx_resources(&rx_rings[i]);
1272 }
1273 kfree(rx_rings);
1274 rx_rings = NULL;
1275
1276 goto free_tx;
1277 }
1278 }
1279 }
1280
1281 /* Bring interface down, copy in the new ring info,
1282 * then restore the interface
1283 */
1284 i40e_down(vsi);
1285
1286 if (tx_rings) {
1287 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001288 i40e_free_tx_resources(vsi->tx_rings[i]);
1289 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001290 }
1291 kfree(tx_rings);
1292 tx_rings = NULL;
1293 }
1294
1295 if (rx_rings) {
1296 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001297 i40e_free_rx_resources(vsi->rx_rings[i]);
1298 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001299 }
1300 kfree(rx_rings);
1301 rx_rings = NULL;
1302 }
1303
1304 i40e_up(vsi);
1305
1306free_tx:
1307 /* error cleanup if the Rx allocations failed after getting Tx */
1308 if (tx_rings) {
1309 for (i = 0; i < vsi->num_queue_pairs; i++)
1310 i40e_free_tx_resources(&tx_rings[i]);
1311 kfree(tx_rings);
1312 tx_rings = NULL;
1313 }
1314
1315done:
1316 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1317
1318 return err;
1319}
1320
1321static int i40e_get_sset_count(struct net_device *netdev, int sset)
1322{
1323 struct i40e_netdev_priv *np = netdev_priv(netdev);
1324 struct i40e_vsi *vsi = np->vsi;
1325 struct i40e_pf *pf = vsi->back;
1326
1327 switch (sset) {
1328 case ETH_SS_TEST:
1329 return I40E_TEST_LEN;
1330 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001331 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001332 int len = I40E_PF_STATS_LEN(netdev);
1333
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001334 if ((pf->lan_veb != I40E_NO_VEB) &&
1335 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001336 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001337 return len;
1338 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001339 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001340 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001341 case ETH_SS_PRIV_FLAGS:
1342 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001343 default:
1344 return -EOPNOTSUPP;
1345 }
1346}
1347
1348static void i40e_get_ethtool_stats(struct net_device *netdev,
1349 struct ethtool_stats *stats, u64 *data)
1350{
1351 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001352 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001353 struct i40e_vsi *vsi = np->vsi;
1354 struct i40e_pf *pf = vsi->back;
1355 int i = 0;
1356 char *p;
1357 int j;
1358 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001359 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001360
1361 i40e_update_stats(vsi);
1362
1363 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1364 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1365 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1366 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1367 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001368 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1369 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1370 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1371 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1372 }
Vasu Dev38e00432014-08-01 13:27:03 -07001373#ifdef I40E_FCOE
1374 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1375 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1376 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1377 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1378 }
1379#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001380 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001381 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001382 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001383
1384 if (!tx_ring)
1385 continue;
1386
1387 /* process Tx ring statistics */
1388 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001389 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001390 data[i] = tx_ring->stats.packets;
1391 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001392 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001393 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001394
1395 /* Rx ring is the 2nd half of the queue pair */
1396 rx_ring = &tx_ring[1];
1397 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001398 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001399 data[i] = rx_ring->stats.packets;
1400 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001401 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001402 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001403 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001404 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001405 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001406 return;
1407
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001408 if ((pf->lan_veb != I40E_NO_VEB) &&
1409 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001410 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001411
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001412 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1413 p = (char *)veb;
1414 p += i40e_gstrings_veb_stats[j].stat_offset;
1415 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1416 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001418 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1419 data[i++] = veb->tc_stats.tc_tx_packets[j];
1420 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1421 data[i++] = veb->tc_stats.tc_rx_packets[j];
1422 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1423 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001424 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001425 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1426 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1427 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1428 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1429 }
1430 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1431 data[i++] = pf->stats.priority_xon_tx[j];
1432 data[i++] = pf->stats.priority_xoff_tx[j];
1433 }
1434 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1435 data[i++] = pf->stats.priority_xon_rx[j];
1436 data[i++] = pf->stats.priority_xoff_rx[j];
1437 }
1438 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1439 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001440}
1441
1442static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1443 u8 *data)
1444{
1445 struct i40e_netdev_priv *np = netdev_priv(netdev);
1446 struct i40e_vsi *vsi = np->vsi;
1447 struct i40e_pf *pf = vsi->back;
1448 char *p = (char *)data;
1449 int i;
1450
1451 switch (stringset) {
1452 case ETH_SS_TEST:
1453 for (i = 0; i < I40E_TEST_LEN; i++) {
1454 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1455 data += ETH_GSTRING_LEN;
1456 }
1457 break;
1458 case ETH_SS_STATS:
1459 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1460 snprintf(p, ETH_GSTRING_LEN, "%s",
1461 i40e_gstrings_net_stats[i].stat_string);
1462 p += ETH_GSTRING_LEN;
1463 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001464 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1465 snprintf(p, ETH_GSTRING_LEN, "%s",
1466 i40e_gstrings_misc_stats[i].stat_string);
1467 p += ETH_GSTRING_LEN;
1468 }
Vasu Dev38e00432014-08-01 13:27:03 -07001469#ifdef I40E_FCOE
1470 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1471 snprintf(p, ETH_GSTRING_LEN, "%s",
1472 i40e_gstrings_fcoe_stats[i].stat_string);
1473 p += ETH_GSTRING_LEN;
1474 }
1475#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001476 for (i = 0; i < vsi->num_queue_pairs; i++) {
1477 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1478 p += ETH_GSTRING_LEN;
1479 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1480 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1482 p += ETH_GSTRING_LEN;
1483 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1484 p += ETH_GSTRING_LEN;
1485 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001486 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001487 return;
1488
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001489 if ((pf->lan_veb != I40E_NO_VEB) &&
1490 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001491 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1492 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1493 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494 p += ETH_GSTRING_LEN;
1495 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001496 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1497 snprintf(p, ETH_GSTRING_LEN,
1498 "veb.tc_%u_tx_packets", i);
1499 p += ETH_GSTRING_LEN;
1500 snprintf(p, ETH_GSTRING_LEN,
1501 "veb.tc_%u_tx_bytes", i);
1502 p += ETH_GSTRING_LEN;
1503 snprintf(p, ETH_GSTRING_LEN,
1504 "veb.tc_%u_rx_packets", i);
1505 p += ETH_GSTRING_LEN;
1506 snprintf(p, ETH_GSTRING_LEN,
1507 "veb.tc_%u_rx_bytes", i);
1508 p += ETH_GSTRING_LEN;
1509 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001510 }
1511 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1512 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1513 i40e_gstrings_stats[i].stat_string);
1514 p += ETH_GSTRING_LEN;
1515 }
1516 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1517 snprintf(p, ETH_GSTRING_LEN,
1518 "port.tx_priority_%u_xon", i);
1519 p += ETH_GSTRING_LEN;
1520 snprintf(p, ETH_GSTRING_LEN,
1521 "port.tx_priority_%u_xoff", i);
1522 p += ETH_GSTRING_LEN;
1523 }
1524 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1525 snprintf(p, ETH_GSTRING_LEN,
1526 "port.rx_priority_%u_xon", i);
1527 p += ETH_GSTRING_LEN;
1528 snprintf(p, ETH_GSTRING_LEN,
1529 "port.rx_priority_%u_xoff", i);
1530 p += ETH_GSTRING_LEN;
1531 }
1532 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1533 snprintf(p, ETH_GSTRING_LEN,
1534 "port.rx_priority_%u_xon_2_xoff", i);
1535 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536 }
1537 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1538 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001539 case ETH_SS_PRIV_FLAGS:
1540 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1541 memcpy(data, i40e_priv_flags_strings[i],
1542 ETH_GSTRING_LEN);
1543 data += ETH_GSTRING_LEN;
1544 }
1545 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001546 default:
1547 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 }
1549}
1550
1551static int i40e_get_ts_info(struct net_device *dev,
1552 struct ethtool_ts_info *info)
1553{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001554 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1555
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001556 /* only report HW timestamping if PTP is enabled */
1557 if (!(pf->flags & I40E_FLAG_PTP))
1558 return ethtool_op_get_ts_info(dev, info);
1559
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001560 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1561 SOF_TIMESTAMPING_RX_SOFTWARE |
1562 SOF_TIMESTAMPING_SOFTWARE |
1563 SOF_TIMESTAMPING_TX_HARDWARE |
1564 SOF_TIMESTAMPING_RX_HARDWARE |
1565 SOF_TIMESTAMPING_RAW_HARDWARE;
1566
1567 if (pf->ptp_clock)
1568 info->phc_index = ptp_clock_index(pf->ptp_clock);
1569 else
1570 info->phc_index = -1;
1571
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001572 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001573
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001574 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1575 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1576 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001577
1578 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001579}
1580
Shannon Nelson7b086392013-11-20 10:02:59 +00001581static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001582{
Shannon Nelson7b086392013-11-20 10:02:59 +00001583 struct i40e_netdev_priv *np = netdev_priv(netdev);
1584 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001585 i40e_status status;
1586 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001587
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001588 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001589 status = i40e_get_link_status(&pf->hw, &link_up);
1590 if (status) {
1591 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1592 *data = 1;
1593 return *data;
1594 }
1595
1596 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001597 *data = 0;
1598 else
1599 *data = 1;
1600
1601 return *data;
1602}
1603
Shannon Nelson7b086392013-11-20 10:02:59 +00001604static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001605{
Shannon Nelson7b086392013-11-20 10:02:59 +00001606 struct i40e_netdev_priv *np = netdev_priv(netdev);
1607 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001609 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001610 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001611
Shannon Nelson7b086392013-11-20 10:02:59 +00001612 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001613}
1614
Shannon Nelson7b086392013-11-20 10:02:59 +00001615static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001616{
Shannon Nelson7b086392013-11-20 10:02:59 +00001617 struct i40e_netdev_priv *np = netdev_priv(netdev);
1618 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001620 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001621 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001622
Shannon Nelson4443ec92014-11-13 08:23:12 +00001623 /* forcebly clear the NVM Update state machine */
1624 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1625
Shannon Nelson7b086392013-11-20 10:02:59 +00001626 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627}
1628
Shannon Nelson7b086392013-11-20 10:02:59 +00001629static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001630{
Shannon Nelson7b086392013-11-20 10:02:59 +00001631 struct i40e_netdev_priv *np = netdev_priv(netdev);
1632 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001633 u16 swc_old = pf->sw_int_count;
1634
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001635 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001636 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1637 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001638 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1639 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1640 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1641 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001642 usleep_range(1000, 2000);
1643 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001644
1645 return *data;
1646}
1647
Shannon Nelson7b086392013-11-20 10:02:59 +00001648static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001649{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001650 struct i40e_netdev_priv *np = netdev_priv(netdev);
1651 struct i40e_pf *pf = np->vsi->back;
1652
1653 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001654 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001655
1656 return *data;
1657}
1658
Greg Rosee17bc412015-04-16 20:05:59 -04001659static inline bool i40e_active_vfs(struct i40e_pf *pf)
1660{
1661 struct i40e_vf *vfs = pf->vf;
1662 int i;
1663
1664 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001665 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001666 return true;
1667 return false;
1668}
1669
Greg Rose510efb22015-07-10 19:36:01 -04001670static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1671{
1672 struct i40e_vsi **vsi = pf->vsi;
1673 int i;
1674
1675 for (i = 0; i < pf->num_alloc_vsi; i++) {
1676 if (!vsi[i])
1677 continue;
1678 if (vsi[i]->type == I40E_VSI_VMDQ2)
1679 return true;
1680 }
1681
1682 return false;
1683}
1684
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001685static void i40e_diag_test(struct net_device *netdev,
1686 struct ethtool_test *eth_test, u64 *data)
1687{
1688 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001689 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001690 struct i40e_pf *pf = np->vsi->back;
1691
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001692 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1693 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001694 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695
Shannon Nelsonf551b432013-11-26 10:49:12 +00001696 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001697
Greg Rose510efb22015-07-10 19:36:01 -04001698 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001699 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001700 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001701 data[I40E_ETH_TEST_REG] = 1;
1702 data[I40E_ETH_TEST_EEPROM] = 1;
1703 data[I40E_ETH_TEST_INTR] = 1;
1704 data[I40E_ETH_TEST_LOOPBACK] = 1;
1705 data[I40E_ETH_TEST_LINK] = 1;
1706 eth_test->flags |= ETH_TEST_FL_FAILED;
1707 clear_bit(__I40E_TESTING, &pf->state);
1708 goto skip_ol_tests;
1709 }
1710
Greg Rose5b86c5c2015-02-26 16:14:35 +00001711 /* If the device is online then take it offline */
1712 if (if_running)
1713 /* indicate we're in test mode */
1714 dev_close(netdev);
1715 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001716 /* This reset does not affect link - if it is
1717 * changed to a type of reset that does affect
1718 * link then the following link test would have
1719 * to be moved to before the reset
1720 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001721 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001722
Shannon Nelson7b086392013-11-20 10:02:59 +00001723 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001724 eth_test->flags |= ETH_TEST_FL_FAILED;
1725
Shannon Nelson7b086392013-11-20 10:02:59 +00001726 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001727 eth_test->flags |= ETH_TEST_FL_FAILED;
1728
Shannon Nelson7b086392013-11-20 10:02:59 +00001729 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001730 eth_test->flags |= ETH_TEST_FL_FAILED;
1731
Shannon Nelson7b086392013-11-20 10:02:59 +00001732 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733 eth_test->flags |= ETH_TEST_FL_FAILED;
1734
Shannon Nelsonf551b432013-11-26 10:49:12 +00001735 /* run reg test last, a reset is required after it */
1736 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1737 eth_test->flags |= ETH_TEST_FL_FAILED;
1738
1739 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001740 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001741
1742 if (if_running)
1743 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001744 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001745 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001746 netif_info(pf, drv, netdev, "online testing starting\n");
1747
Shannon Nelson7b086392013-11-20 10:02:59 +00001748 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001749 eth_test->flags |= ETH_TEST_FL_FAILED;
1750
1751 /* Offline only tests, not run in online; pass by default */
1752 data[I40E_ETH_TEST_REG] = 0;
1753 data[I40E_ETH_TEST_EEPROM] = 0;
1754 data[I40E_ETH_TEST_INTR] = 0;
1755 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001756 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001757
Greg Rosee17bc412015-04-16 20:05:59 -04001758skip_ol_tests:
1759
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001760 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001761}
1762
1763static void i40e_get_wol(struct net_device *netdev,
1764 struct ethtool_wolinfo *wol)
1765{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001766 struct i40e_netdev_priv *np = netdev_priv(netdev);
1767 struct i40e_pf *pf = np->vsi->back;
1768 struct i40e_hw *hw = &pf->hw;
1769 u16 wol_nvm_bits;
1770
1771 /* NVM bit on means WoL disabled for the port */
1772 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001773 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001774 wol->supported = 0;
1775 wol->wolopts = 0;
1776 } else {
1777 wol->supported = WAKE_MAGIC;
1778 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1779 }
1780}
1781
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001782/**
1783 * i40e_set_wol - set the WakeOnLAN configuration
1784 * @netdev: the netdev in question
1785 * @wol: the ethtool WoL setting data
1786 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001787static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1788{
1789 struct i40e_netdev_priv *np = netdev_priv(netdev);
1790 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001791 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001792 struct i40e_hw *hw = &pf->hw;
1793 u16 wol_nvm_bits;
1794
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001795 /* WoL not supported if this isn't the controlling PF on the port */
1796 if (hw->partition_id != 1) {
1797 i40e_partition_setting_complaint(pf);
1798 return -EOPNOTSUPP;
1799 }
1800
1801 if (vsi != pf->vsi[pf->lan_vsi])
1802 return -EOPNOTSUPP;
1803
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001804 /* NVM bit on means WoL disabled for the port */
1805 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001806 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001807 return -EOPNOTSUPP;
1808
1809 /* only magic packet is supported */
1810 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1811 return -EOPNOTSUPP;
1812
1813 /* is this a new value? */
1814 if (pf->wol_en != !!wol->wolopts) {
1815 pf->wol_en = !!wol->wolopts;
1816 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1817 }
1818
1819 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820}
1821
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001822static int i40e_set_phys_id(struct net_device *netdev,
1823 enum ethtool_phys_id_state state)
1824{
1825 struct i40e_netdev_priv *np = netdev_priv(netdev);
1826 struct i40e_pf *pf = np->vsi->back;
1827 struct i40e_hw *hw = &pf->hw;
1828 int blink_freq = 2;
1829
1830 switch (state) {
1831 case ETHTOOL_ID_ACTIVE:
1832 pf->led_status = i40e_led_get(hw);
1833 return blink_freq;
1834 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001835 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001836 break;
1837 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001838 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001839 break;
1840 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001841 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001842 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001843 default:
1844 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001845 }
1846
1847 return 0;
1848}
1849
1850/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1851 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1852 * 125us (8000 interrupts per second) == ITR(62)
1853 */
1854
1855static int i40e_get_coalesce(struct net_device *netdev,
1856 struct ethtool_coalesce *ec)
1857{
1858 struct i40e_netdev_priv *np = netdev_priv(netdev);
1859 struct i40e_vsi *vsi = np->vsi;
1860
1861 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1862 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1863
1864 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001865 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001866
1867 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001868 ec->use_adaptive_tx_coalesce = 1;
1869
1870 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1871 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001872 /* we use the _usecs_high to store/set the interrupt rate limit
1873 * that the hardware supports, that almost but not quite
1874 * fits the original intent of the ethtool variable,
1875 * the rx_coalesce_usecs_high limits total interrupts
1876 * per second from both tx/rx sources.
1877 */
1878 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1879 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001880
1881 return 0;
1882}
1883
1884static int i40e_set_coalesce(struct net_device *netdev,
1885 struct ethtool_coalesce *ec)
1886{
1887 struct i40e_netdev_priv *np = netdev_priv(netdev);
1888 struct i40e_q_vector *q_vector;
1889 struct i40e_vsi *vsi = np->vsi;
1890 struct i40e_pf *pf = vsi->back;
1891 struct i40e_hw *hw = &pf->hw;
1892 u16 vector;
1893 int i;
1894
1895 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1896 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1897
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001898 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1899 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1900 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1901 return -EINVAL;
1902 }
1903
1904 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1905 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1906 return -EINVAL;
1907 }
1908
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001909 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001910 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001911 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001912 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001913 } else if (ec->rx_coalesce_usecs == 0) {
1914 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001915 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001916 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001917 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001918 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001919 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001920 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001921
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001922 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1923
Mitch Williams32f5f542014-04-04 04:43:10 +00001924 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001925 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001926 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001927 } else if (ec->tx_coalesce_usecs == 0) {
1928 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001929 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001930 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001931 } else {
1932 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001933 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001934 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001935 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001936
1937 if (ec->use_adaptive_rx_coalesce)
1938 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1939 else
1940 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1941
1942 if (ec->use_adaptive_tx_coalesce)
1943 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1944 else
1945 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001946
Alexander Duyck493fb302013-09-28 07:01:44 +00001947 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001948 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1949
Alexander Duyck493fb302013-09-28 07:01:44 +00001950 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001951 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1952 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1953 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1954 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001955 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001956 i40e_flush(hw);
1957 }
1958
1959 return 0;
1960}
1961
1962/**
1963 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1964 * @pf: pointer to the physical function struct
1965 * @cmd: ethtool rxnfc command
1966 *
1967 * Returns Success if the flow is supported, else Invalid Input.
1968 **/
1969static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1970{
1971 cmd->data = 0;
1972
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001973 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1974 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1975 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1976 return 0;
1977 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001978 /* Report default options for RSS on i40e */
1979 switch (cmd->flow_type) {
1980 case TCP_V4_FLOW:
1981 case UDP_V4_FLOW:
1982 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1983 /* fall through to add IP fields */
1984 case SCTP_V4_FLOW:
1985 case AH_ESP_V4_FLOW:
1986 case AH_V4_FLOW:
1987 case ESP_V4_FLOW:
1988 case IPV4_FLOW:
1989 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1990 break;
1991 case TCP_V6_FLOW:
1992 case UDP_V6_FLOW:
1993 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1994 /* fall through to add IP fields */
1995 case SCTP_V6_FLOW:
1996 case AH_ESP_V6_FLOW:
1997 case AH_V6_FLOW:
1998 case ESP_V6_FLOW:
1999 case IPV6_FLOW:
2000 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2001 break;
2002 default:
2003 return -EINVAL;
2004 }
2005
2006 return 0;
2007}
2008
2009/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002010 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2011 * @pf: Pointer to the physical function struct
2012 * @cmd: The command to get or set Rx flow classification rules
2013 * @rule_locs: Array of used rule locations
2014 *
2015 * This function populates both the total and actual rule count of
2016 * the ethtool flow classification command
2017 *
2018 * Returns 0 on success or -EMSGSIZE if entry not found
2019 **/
2020static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2021 struct ethtool_rxnfc *cmd,
2022 u32 *rule_locs)
2023{
2024 struct i40e_fdir_filter *rule;
2025 struct hlist_node *node2;
2026 int cnt = 0;
2027
2028 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002029 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002030
2031 hlist_for_each_entry_safe(rule, node2,
2032 &pf->fdir_filter_list, fdir_node) {
2033 if (cnt == cmd->rule_cnt)
2034 return -EMSGSIZE;
2035
2036 rule_locs[cnt] = rule->fd_id;
2037 cnt++;
2038 }
2039
2040 cmd->rule_cnt = cnt;
2041
2042 return 0;
2043}
2044
2045/**
2046 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2047 * @pf: Pointer to the physical function struct
2048 * @cmd: The command to get or set Rx flow classification rules
2049 *
2050 * This function looks up a filter based on the Rx flow classification
2051 * command and fills the flow spec info for it if found
2052 *
2053 * Returns 0 on success or -EINVAL if filter not found
2054 **/
2055static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2056 struct ethtool_rxnfc *cmd)
2057{
2058 struct ethtool_rx_flow_spec *fsp =
2059 (struct ethtool_rx_flow_spec *)&cmd->fs;
2060 struct i40e_fdir_filter *rule = NULL;
2061 struct hlist_node *node2;
2062
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002063 hlist_for_each_entry_safe(rule, node2,
2064 &pf->fdir_filter_list, fdir_node) {
2065 if (fsp->location <= rule->fd_id)
2066 break;
2067 }
2068
2069 if (!rule || fsp->location != rule->fd_id)
2070 return -EINVAL;
2071
2072 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002073 if (fsp->flow_type == IP_USER_FLOW) {
2074 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2075 fsp->h_u.usr_ip4_spec.proto = 0;
2076 fsp->m_u.usr_ip4_spec.proto = 0;
2077 }
2078
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002079 /* Reverse the src and dest notion, since the HW views them from
2080 * Tx perspective where as the user expects it from Rx filter view.
2081 */
2082 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2083 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2084 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2085 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002086
2087 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2088 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2089 else
2090 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002091
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002092 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2093 struct i40e_vsi *vsi;
2094
2095 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2096 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2097 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2098 fsp->m_ext.data[1] = htonl(0x1);
2099 }
2100 }
2101
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002102 return 0;
2103}
2104
2105/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002106 * i40e_get_rxnfc - command to get RX flow classification rules
2107 * @netdev: network interface device structure
2108 * @cmd: ethtool rxnfc command
2109 *
2110 * Returns Success if the command is supported.
2111 **/
2112static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2113 u32 *rule_locs)
2114{
2115 struct i40e_netdev_priv *np = netdev_priv(netdev);
2116 struct i40e_vsi *vsi = np->vsi;
2117 struct i40e_pf *pf = vsi->back;
2118 int ret = -EOPNOTSUPP;
2119
2120 switch (cmd->cmd) {
2121 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002122 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002123 ret = 0;
2124 break;
2125 case ETHTOOL_GRXFH:
2126 ret = i40e_get_rss_hash_opts(pf, cmd);
2127 break;
2128 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002129 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002130 /* report total rule count */
2131 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002132 ret = 0;
2133 break;
2134 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002135 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002136 break;
2137 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002138 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2139 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140 default:
2141 break;
2142 }
2143
2144 return ret;
2145}
2146
2147/**
2148 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2149 * @pf: pointer to the physical function struct
2150 * @cmd: ethtool rxnfc command
2151 *
2152 * Returns Success if the flow input set is supported.
2153 **/
2154static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2155{
2156 struct i40e_hw *hw = &pf->hw;
2157 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2158 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2159
2160 /* RSS does not support anything other than hashing
2161 * to queues on src and dst IPs and ports
2162 */
2163 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2164 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2165 return -EINVAL;
2166
2167 /* We need at least the IP SRC and DEST fields for hashing */
2168 if (!(nfc->data & RXH_IP_SRC) ||
2169 !(nfc->data & RXH_IP_DST))
2170 return -EINVAL;
2171
2172 switch (nfc->flow_type) {
2173 case TCP_V4_FLOW:
2174 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2175 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002176 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002177 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002178 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2179 hena |=
2180 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2181
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002182 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002183 break;
2184 default:
2185 return -EINVAL;
2186 }
2187 break;
2188 case TCP_V6_FLOW:
2189 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2190 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002191 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002192 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002193 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2194 hena |=
2195 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2196
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002197 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198 break;
2199 default:
2200 return -EINVAL;
2201 }
2202 break;
2203 case UDP_V4_FLOW:
2204 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2205 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002206 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002207 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002208 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2209 hena |=
2210 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2211 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2212
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002213 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2214 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002215 break;
2216 default:
2217 return -EINVAL;
2218 }
2219 break;
2220 case UDP_V6_FLOW:
2221 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2222 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002223 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002224 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002225 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2226 hena |=
2227 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2228 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2229
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002230 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2231 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232 break;
2233 default:
2234 return -EINVAL;
2235 }
2236 break;
2237 case AH_ESP_V4_FLOW:
2238 case AH_V4_FLOW:
2239 case ESP_V4_FLOW:
2240 case SCTP_V4_FLOW:
2241 if ((nfc->data & RXH_L4_B_0_1) ||
2242 (nfc->data & RXH_L4_B_2_3))
2243 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002244 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002245 break;
2246 case AH_ESP_V6_FLOW:
2247 case AH_V6_FLOW:
2248 case ESP_V6_FLOW:
2249 case SCTP_V6_FLOW:
2250 if ((nfc->data & RXH_L4_B_0_1) ||
2251 (nfc->data & RXH_L4_B_2_3))
2252 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002253 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002254 break;
2255 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002256 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2257 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002258 break;
2259 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002260 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2261 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002262 break;
2263 default:
2264 return -EINVAL;
2265 }
2266
2267 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2268 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2269 i40e_flush(hw);
2270
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002271 /* Save setting for future output/update */
2272 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2273
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002274 return 0;
2275}
2276
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002277/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002278 * i40e_match_fdir_input_set - Match a new filter against an existing one
2279 * @rule: The filter already added
2280 * @input: The new filter to comapre against
2281 *
2282 * Returns true if the two input set match
2283 **/
2284static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2285 struct i40e_fdir_filter *input)
2286{
2287 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2288 (rule->src_ip[0] != input->src_ip[0]) ||
2289 (rule->dst_port != input->dst_port) ||
2290 (rule->src_port != input->src_port))
2291 return false;
2292 return true;
2293}
2294
2295/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002296 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2297 * @vsi: Pointer to the targeted VSI
2298 * @input: The filter to update or NULL to indicate deletion
2299 * @sw_idx: Software index to the filter
2300 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002301 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002302 * This function updates (or deletes) a Flow Director entry from
2303 * the hlist of the corresponding PF
2304 *
2305 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002306 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002307static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2308 struct i40e_fdir_filter *input,
2309 u16 sw_idx,
2310 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002311{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002312 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002313 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002314 struct hlist_node *node2;
2315 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002316
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002317 parent = NULL;
2318 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002319
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002320 hlist_for_each_entry_safe(rule, node2,
2321 &pf->fdir_filter_list, fdir_node) {
2322 /* hash found, or no matching entry */
2323 if (rule->fd_id >= sw_idx)
2324 break;
2325 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002326 }
2327
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002328 /* if there is an old rule occupying our place remove it */
2329 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002330 if (input && !i40e_match_fdir_input_set(rule, input))
2331 err = i40e_add_del_fdir(vsi, rule, false);
2332 else if (!input)
2333 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002334 hlist_del(&rule->fdir_node);
2335 kfree(rule);
2336 pf->fdir_pf_active_filters--;
2337 }
2338
2339 /* If no input this was a delete, err should be 0 if a rule was
2340 * successfully found and removed from the list else -EINVAL
2341 */
2342 if (!input)
2343 return err;
2344
2345 /* initialize node and set software index */
2346 INIT_HLIST_NODE(&input->fdir_node);
2347
2348 /* add filter to the list */
2349 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002350 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002351 else
2352 hlist_add_head(&input->fdir_node,
2353 &pf->fdir_filter_list);
2354
2355 /* update counts */
2356 pf->fdir_pf_active_filters++;
2357
2358 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002359}
2360
2361/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002362 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2363 * @vsi: Pointer to the targeted VSI
2364 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002365 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002366 * The function removes a Flow Director filter entry from the
2367 * hlist of the corresponding PF
2368 *
2369 * Returns 0 on success
2370 */
2371static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2372 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002373{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002374 struct ethtool_rx_flow_spec *fsp =
2375 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002376 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002377 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002378
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002379 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2380 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2381 return -EBUSY;
2382
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002383 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2384 return -EBUSY;
2385
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002386 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002387
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002388 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002389 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002390}
2391
2392/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002393 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002394 * @vsi: pointer to the targeted VSI
2395 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002396 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002397 * Add Flow Director filters for a specific flow spec based on their
2398 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002399 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002400static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2401 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002402{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002403 struct ethtool_rx_flow_spec *fsp;
2404 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002405 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002406 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002407 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002408
2409 if (!vsi)
2410 return -EINVAL;
2411
2412 pf = vsi->back;
2413
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002414 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2415 return -EOPNOTSUPP;
2416
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002417 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002418 return -ENOSPC;
2419
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002420 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2421 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2422 return -EBUSY;
2423
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002424 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2425 return -EBUSY;
2426
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002427 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2428
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002429 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2430 pf->hw.func_caps.fd_filters_guaranteed)) {
2431 return -EINVAL;
2432 }
2433
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002434 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2435 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002436 return -EINVAL;
2437
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002438 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002439
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002440 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002441 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002442
2443 input->fd_id = fsp->location;
2444
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002445 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2446 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2447 else
2448 input->dest_ctl =
2449 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2450
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002451 input->q_index = fsp->ring_cookie;
2452 input->flex_off = 0;
2453 input->pctype = 0;
2454 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002455 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002456 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002457 input->flow_type = fsp->flow_type;
2458 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002459
2460 /* Reverse the src and dest notion, since the HW expects them to be from
2461 * Tx perspective where as the input from user is from Rx filter view.
2462 */
2463 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2464 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2465 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2466 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002467
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002468 if (ntohl(fsp->m_ext.data[1])) {
2469 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2470 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2471 goto free_input;
2472 }
2473 vf_id = ntohl(fsp->h_ext.data[1]);
2474 /* Find vsi id from vf id and override dest vsi */
2475 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2476 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2477 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2478 goto free_input;
2479 }
2480 }
2481
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002482 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002483free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002484 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002485 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002486 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002487 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002488
2489 return ret;
2490}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002491
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002492/**
2493 * i40e_set_rxnfc - command to set RX flow classification rules
2494 * @netdev: network interface device structure
2495 * @cmd: ethtool rxnfc command
2496 *
2497 * Returns Success if the command is supported.
2498 **/
2499static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2500{
2501 struct i40e_netdev_priv *np = netdev_priv(netdev);
2502 struct i40e_vsi *vsi = np->vsi;
2503 struct i40e_pf *pf = vsi->back;
2504 int ret = -EOPNOTSUPP;
2505
2506 switch (cmd->cmd) {
2507 case ETHTOOL_SRXFH:
2508 ret = i40e_set_rss_hash_opt(pf, cmd);
2509 break;
2510 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002511 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002512 break;
2513 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002514 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002515 break;
2516 default:
2517 break;
2518 }
2519
2520 return ret;
2521}
2522
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002523/**
2524 * i40e_max_channels - get Max number of combined channels supported
2525 * @vsi: vsi pointer
2526 **/
2527static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2528{
2529 /* TODO: This code assumes DCB and FD is disabled for now. */
2530 return vsi->alloc_queue_pairs;
2531}
2532
2533/**
2534 * i40e_get_channels - Get the current channels enabled and max supported etc.
2535 * @netdev: network interface device structure
2536 * @ch: ethtool channels structure
2537 *
2538 * We don't support separate tx and rx queues as channels. The other count
2539 * represents how many queues are being used for control. max_combined counts
2540 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2541 * q_vectors since we support a lot more queue pairs than q_vectors.
2542 **/
2543static void i40e_get_channels(struct net_device *dev,
2544 struct ethtool_channels *ch)
2545{
2546 struct i40e_netdev_priv *np = netdev_priv(dev);
2547 struct i40e_vsi *vsi = np->vsi;
2548 struct i40e_pf *pf = vsi->back;
2549
2550 /* report maximum channels */
2551 ch->max_combined = i40e_max_channels(vsi);
2552
2553 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002554 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002555 ch->max_other = ch->other_count;
2556
2557 /* Note: This code assumes DCB is disabled for now. */
2558 ch->combined_count = vsi->num_queue_pairs;
2559}
2560
2561/**
2562 * i40e_set_channels - Set the new channels count.
2563 * @netdev: network interface device structure
2564 * @ch: ethtool channels structure
2565 *
2566 * The new channels count may not be the same as requested by the user
2567 * since it gets rounded down to a power of 2 value.
2568 **/
2569static int i40e_set_channels(struct net_device *dev,
2570 struct ethtool_channels *ch)
2571{
2572 struct i40e_netdev_priv *np = netdev_priv(dev);
2573 unsigned int count = ch->combined_count;
2574 struct i40e_vsi *vsi = np->vsi;
2575 struct i40e_pf *pf = vsi->back;
2576 int new_count;
2577
2578 /* We do not support setting channels for any other VSI at present */
2579 if (vsi->type != I40E_VSI_MAIN)
2580 return -EINVAL;
2581
2582 /* verify they are not requesting separate vectors */
2583 if (!count || ch->rx_count || ch->tx_count)
2584 return -EINVAL;
2585
2586 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002587 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002588 return -EINVAL;
2589
2590 /* verify the number of channels does not exceed hardware limits */
2591 if (count > i40e_max_channels(vsi))
2592 return -EINVAL;
2593
2594 /* update feature limits from largest to smallest supported values */
2595 /* TODO: Flow director limit, DCB etc */
2596
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002597 /* use rss_reconfig to rebuild with new queue count and update traffic
2598 * class queue mapping
2599 */
2600 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002601 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002602 return 0;
2603 else
2604 return -EINVAL;
2605}
2606
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002607/**
2608 * i40e_get_rxfh_key_size - get the RSS hash key size
2609 * @netdev: network interface device structure
2610 *
2611 * Returns the table size.
2612 **/
2613static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2614{
2615 return I40E_HKEY_ARRAY_SIZE;
2616}
2617
2618/**
2619 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2620 * @netdev: network interface device structure
2621 *
2622 * Returns the table size.
2623 **/
2624static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2625{
2626 return I40E_HLUT_ARRAY_SIZE;
2627}
2628
2629static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2630 u8 *hfunc)
2631{
2632 struct i40e_netdev_priv *np = netdev_priv(netdev);
2633 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002634 u8 *lut, *seed = NULL;
2635 int ret;
2636 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002637
2638 if (hfunc)
2639 *hfunc = ETH_RSS_HASH_TOP;
2640
2641 if (!indir)
2642 return 0;
2643
Helin Zhang043dd652015-10-21 19:56:23 -04002644 seed = key;
2645 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2646 if (!lut)
2647 return -ENOMEM;
2648 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2649 if (ret)
2650 goto out;
2651 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2652 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002653
Helin Zhang043dd652015-10-21 19:56:23 -04002654out:
2655 kfree(lut);
2656
2657 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002658}
2659
2660/**
2661 * i40e_set_rxfh - set the rx flow hash indirection table
2662 * @netdev: network interface device structure
2663 * @indir: indirection table
2664 * @key: hash key
2665 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002666 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002667 * returns 0 after programming the table.
2668 **/
2669static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2670 const u8 *key, const u8 hfunc)
2671{
2672 struct i40e_netdev_priv *np = netdev_priv(netdev);
2673 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002674 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002675 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002676
2677 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2678 return -EOPNOTSUPP;
2679
2680 if (!indir)
2681 return 0;
2682
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002683 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002684 if (!vsi->rss_hkey_user) {
2685 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2686 GFP_KERNEL);
2687 if (!vsi->rss_hkey_user)
2688 return -ENOMEM;
2689 }
2690 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2691 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002692 }
Helin Zhang28c58692015-10-26 19:44:27 -04002693 if (!vsi->rss_lut_user) {
2694 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2695 if (!vsi->rss_lut_user)
2696 return -ENOMEM;
2697 }
Helin Zhang043dd652015-10-21 19:56:23 -04002698
Helin Zhang28c58692015-10-26 19:44:27 -04002699 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2700 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2701 vsi->rss_lut_user[i] = (u8)(indir[i]);
2702
2703 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2704 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002705}
2706
Greg Rose7e45ab42015-02-06 08:52:19 +00002707/**
2708 * i40e_get_priv_flags - report device private flags
2709 * @dev: network interface device structure
2710 *
2711 * The get string set count and the string set should be matched for each
2712 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2713 * array.
2714 *
2715 * Returns a u32 bitmap of flags.
2716 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002717static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002718{
2719 struct i40e_netdev_priv *np = netdev_priv(dev);
2720 struct i40e_vsi *vsi = np->vsi;
2721 struct i40e_pf *pf = vsi->back;
2722 u32 ret_flags = 0;
2723
2724 ret_flags |= pf->hw.func_caps.npar_enable ?
2725 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002726 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2727 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002728 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2729 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002730 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2731 I40E_PRIV_FLAGS_VEB_STATS : 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002732 ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
2733 I40E_PRIV_FLAGS_PS : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002734
2735 return ret_flags;
2736}
2737
Shannon Nelson9ac77262015-08-27 11:42:40 -04002738/**
2739 * i40e_set_priv_flags - set private flags
2740 * @dev: network interface device structure
2741 * @flags: bit flags to be set
2742 **/
2743static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2744{
2745 struct i40e_netdev_priv *np = netdev_priv(dev);
2746 struct i40e_vsi *vsi = np->vsi;
2747 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002748 bool reset_required = false;
2749
2750 /* NOTE: MFP is not settable */
2751
2752 /* allow the user to control the method of receive
2753 * buffer DMA, whether the packet is split at header
2754 * boundaries into two separate buffers. In some cases
2755 * one routine or the other will perform better.
2756 */
2757 if ((flags & I40E_PRIV_FLAGS_PS) &&
2758 !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2759 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
2760 pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
2761 reset_required = true;
2762 } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
2763 (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2764 pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
2765 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
2766 reset_required = true;
2767 }
Shannon Nelson9ac77262015-08-27 11:42:40 -04002768
2769 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2770 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2771 else
2772 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2773
Jesse Brandeburgef171782015-09-03 17:18:49 -04002774 /* allow the user to control the state of the Flow
2775 * Director ATR (Application Targeted Routing) feature
2776 * of the driver
2777 */
2778 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2779 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2780 } else {
2781 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2782 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2783 }
2784
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002785 if (flags & I40E_PRIV_FLAGS_VEB_STATS)
2786 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2787 else
2788 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2789
Jesse Brandeburg827de392015-11-06 15:26:07 -08002790 /* if needed, issue reset to cause things to take effect */
2791 if (reset_required)
2792 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2793
Shannon Nelson9ac77262015-08-27 11:42:40 -04002794 return 0;
2795}
2796
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002797static const struct ethtool_ops i40e_ethtool_ops = {
2798 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002799 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002800 .get_drvinfo = i40e_get_drvinfo,
2801 .get_regs_len = i40e_get_regs_len,
2802 .get_regs = i40e_get_regs,
2803 .nway_reset = i40e_nway_reset,
2804 .get_link = ethtool_op_get_link,
2805 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002806 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002807 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002808 .get_eeprom_len = i40e_get_eeprom_len,
2809 .get_eeprom = i40e_get_eeprom,
2810 .get_ringparam = i40e_get_ringparam,
2811 .set_ringparam = i40e_set_ringparam,
2812 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002813 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002814 .get_msglevel = i40e_get_msglevel,
2815 .set_msglevel = i40e_set_msglevel,
2816 .get_rxnfc = i40e_get_rxnfc,
2817 .set_rxnfc = i40e_set_rxnfc,
2818 .self_test = i40e_diag_test,
2819 .get_strings = i40e_get_strings,
2820 .set_phys_id = i40e_set_phys_id,
2821 .get_sset_count = i40e_get_sset_count,
2822 .get_ethtool_stats = i40e_get_ethtool_stats,
2823 .get_coalesce = i40e_get_coalesce,
2824 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002825 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2826 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2827 .get_rxfh = i40e_get_rxfh,
2828 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002829 .get_channels = i40e_get_channels,
2830 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002831 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002832 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002833 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002834};
2835
2836void i40e_set_ethtool_ops(struct net_device *netdev)
2837{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002838 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002839}