blob: 89ad2f7499181d63133834b7dc6c545e78b4ea9a [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",
Anjali Singhai Jain72b74862016-01-08 17:50:21 -0800238 "hw-atr-eviction",
Greg Rose7e45ab42015-02-06 08:52:19 +0000239};
240
Shannon Nelson9ac77262015-08-27 11:42:40 -0400241#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000242
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000243/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000244 * i40e_partition_setting_complaint - generic complaint for MFP restriction
245 * @pf: the PF struct
246 **/
247static void i40e_partition_setting_complaint(struct i40e_pf *pf)
248{
249 dev_info(&pf->pdev->dev,
250 "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");
251}
252
253/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000254 * i40e_get_settings_link_up - Get the Link settings for when link is up
255 * @hw: hw structure
256 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000257 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000260static void i40e_get_settings_link_up(struct i40e_hw *hw,
261 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400262 struct net_device *netdev,
263 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000264{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000266 u32 link_speed = hw_link_info->link_speed;
267
Catherine Sullivane8278452015-02-06 08:52:08 +0000268 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000269 switch (hw_link_info->phy_type) {
270 case I40E_PHY_TYPE_40GBASE_CR4:
271 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000272 ecmd->supported = SUPPORTED_Autoneg |
273 SUPPORTED_40000baseCR4_Full;
274 ecmd->advertising = ADVERTISED_Autoneg |
275 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000277 case I40E_PHY_TYPE_XLAUI:
278 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000279 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000280 ecmd->supported = SUPPORTED_40000baseCR4_Full;
281 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000282 case I40E_PHY_TYPE_40GBASE_SR4:
283 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000284 break;
285 case I40E_PHY_TYPE_40GBASE_LR4:
286 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000287 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000288 case I40E_PHY_TYPE_10GBASE_SR:
289 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000290 case I40E_PHY_TYPE_1000BASE_SX:
291 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400292 ecmd->supported = SUPPORTED_10000baseT_Full;
293 if (hw_link_info->module_type[2] &
294 I40E_MODULE_TYPE_1000BASE_SX ||
295 hw_link_info->module_type[2] &
296 I40E_MODULE_TYPE_1000BASE_LX) {
297 ecmd->supported |= SUPPORTED_1000baseT_Full;
298 if (hw_link_info->requested_speeds &
299 I40E_LINK_SPEED_1GB)
300 ecmd->advertising |= ADVERTISED_1000baseT_Full;
301 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000302 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
303 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000304 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000305 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000306 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000307 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000308 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400309 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000310 ecmd->advertising = ADVERTISED_Autoneg;
311 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
312 ecmd->advertising |= ADVERTISED_10000baseT_Full;
313 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
314 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400315 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400316 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_1000baseT_Full;
319 ecmd->advertising = ADVERTISED_Autoneg |
320 ADVERTISED_1000baseT_Full;
321 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400322 case I40E_PHY_TYPE_100BASE_TX:
323 ecmd->supported = SUPPORTED_Autoneg |
324 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000325 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
326 ecmd->advertising |= ADVERTISED_100baseT_Full;
327 break;
328 case I40E_PHY_TYPE_10GBASE_CR1_CU:
329 case I40E_PHY_TYPE_10GBASE_CR1:
330 ecmd->supported = SUPPORTED_Autoneg |
331 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000332 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000333 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000334 break;
335 case I40E_PHY_TYPE_XAUI:
336 case I40E_PHY_TYPE_XFI:
337 case I40E_PHY_TYPE_SFI:
338 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000339 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000340 ecmd->supported = SUPPORTED_10000baseT_Full;
341 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000342 case I40E_PHY_TYPE_SGMII:
343 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400344 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000345 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
346 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800347 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400348 ecmd->supported |= SUPPORTED_100baseT_Full;
349 if (hw_link_info->requested_speeds &
350 I40E_LINK_SPEED_100MB)
351 ecmd->advertising |= ADVERTISED_100baseT_Full;
352 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000353 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400354 /* Backplane is set based on supported phy types in get_settings
355 * so don't set anything here but don't warn either
356 */
357 case I40E_PHY_TYPE_40GBASE_KR4:
358 case I40E_PHY_TYPE_20GBASE_KR2:
359 case I40E_PHY_TYPE_10GBASE_KR:
360 case I40E_PHY_TYPE_10GBASE_KX4:
361 case I40E_PHY_TYPE_1000BASE_KX:
362 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000363 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000364 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000365 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
366 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000367 }
368
Catherine Sullivane8278452015-02-06 08:52:08 +0000369 /* Set speed and duplex */
370 switch (link_speed) {
371 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400372 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000373 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700374 case I40E_LINK_SPEED_20GB:
375 ethtool_cmd_speed_set(ecmd, SPEED_20000);
376 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000377 case I40E_LINK_SPEED_10GB:
378 ethtool_cmd_speed_set(ecmd, SPEED_10000);
379 break;
380 case I40E_LINK_SPEED_1GB:
381 ethtool_cmd_speed_set(ecmd, SPEED_1000);
382 break;
383 case I40E_LINK_SPEED_100MB:
384 ethtool_cmd_speed_set(ecmd, SPEED_100);
385 break;
386 default:
387 break;
388 }
389 ecmd->duplex = DUPLEX_FULL;
390}
391
392/**
393 * i40e_get_settings_link_down - Get the Link settings for when link is down
394 * @hw: hw structure
395 * @ecmd: ethtool command to fill in
396 *
397 * Reports link settings that can be determined when link is down
398 **/
399static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400400 struct ethtool_cmd *ecmd,
401 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000402{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400403 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000404
405 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400406 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000407 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400408 ecmd->supported = 0x0;
409 ecmd->advertising = 0x0;
410 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
411 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400412 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400413 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400414 ADVERTISED_1000baseT_Full;
415 if (pf->hw.mac.type == I40E_MAC_X722) {
416 ecmd->supported |= SUPPORTED_100baseT_Full;
417 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivanf8db54cc2015-12-22 14:25:14 -0800418 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
419 ecmd->supported |= SUPPORTED_100baseT_Full;
420 ecmd->advertising |= ADVERTISED_100baseT_Full;
421 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400422 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000423 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400424 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
425 phy_types & I40E_CAP_PHY_TYPE_XFI ||
426 phy_types & I40E_CAP_PHY_TYPE_SFI ||
427 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
429 ecmd->supported |= SUPPORTED_10000baseT_Full;
430 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
431 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
432 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
433 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
434 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
435 ecmd->supported |= SUPPORTED_Autoneg |
436 SUPPORTED_10000baseT_Full;
437 ecmd->advertising |= ADVERTISED_Autoneg |
438 ADVERTISED_10000baseT_Full;
439 }
440 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
441 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
442 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
443 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
444 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
445 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
446 ecmd->supported |= SUPPORTED_Autoneg |
447 SUPPORTED_40000baseCR4_Full;
448 ecmd->advertising |= ADVERTISED_Autoneg |
449 ADVERTISED_40000baseCR4_Full;
450 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400451 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
452 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400453 ecmd->supported |= SUPPORTED_Autoneg |
454 SUPPORTED_100baseT_Full;
455 ecmd->advertising |= ADVERTISED_Autoneg |
456 ADVERTISED_100baseT_Full;
457 }
458 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
459 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
460 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
461 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
462 ecmd->supported |= SUPPORTED_Autoneg |
463 SUPPORTED_1000baseT_Full;
464 ecmd->advertising |= ADVERTISED_Autoneg |
465 ADVERTISED_1000baseT_Full;
466 }
467 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
468 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
469 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
470 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000471
472 /* With no link speed and duplex are unknown */
473 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
474 ecmd->duplex = DUPLEX_UNKNOWN;
475}
476
477/**
478 * i40e_get_settings - Get Link Speed and Duplex settings
479 * @netdev: network interface device structure
480 * @ecmd: ethtool command
481 *
482 * Reports speed/duplex settings based on media_type
483 **/
484static int i40e_get_settings(struct net_device *netdev,
485 struct ethtool_cmd *ecmd)
486{
487 struct i40e_netdev_priv *np = netdev_priv(netdev);
488 struct i40e_pf *pf = np->vsi->back;
489 struct i40e_hw *hw = &pf->hw;
490 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
491 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
492
493 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400494 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000495 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400496 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000497
498 /* Now set the settings that don't rely on link being up/down */
499
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400500 /* For backplane, supported and advertised are only reliant on the
501 * phy types the NVM specifies are supported.
502 */
503 if (hw->device_id == I40E_DEV_ID_KX_B ||
504 hw->device_id == I40E_DEV_ID_KX_C ||
505 hw->device_id == I40E_DEV_ID_20G_KR2 ||
506 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
507 ecmd->supported = SUPPORTED_Autoneg;
508 ecmd->advertising = ADVERTISED_Autoneg;
509 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
510 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
511 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
512 }
513 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
514 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
515 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
516 }
517 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
518 ecmd->supported |= SUPPORTED_10000baseKR_Full;
519 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
520 }
521 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
522 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
523 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
524 }
525 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
526 ecmd->supported |= SUPPORTED_1000baseKX_Full;
527 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
528 }
529 }
530
Catherine Sullivane8278452015-02-06 08:52:08 +0000531 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000532 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
533 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000534
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000535 switch (hw->phy.media_type) {
536 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000537 ecmd->supported |= SUPPORTED_Autoneg |
538 SUPPORTED_Backplane;
539 ecmd->advertising |= ADVERTISED_Autoneg |
540 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000541 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000542 break;
543 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000544 ecmd->supported |= SUPPORTED_TP;
545 ecmd->advertising |= ADVERTISED_TP;
546 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000547 break;
548 case I40E_MEDIA_TYPE_DA:
549 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000550 ecmd->supported |= SUPPORTED_FIBRE;
551 ecmd->advertising |= ADVERTISED_FIBRE;
552 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000553 break;
554 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000555 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000556 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000557 break;
558 case I40E_MEDIA_TYPE_UNKNOWN:
559 default:
560 ecmd->port = PORT_OTHER;
561 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000562 }
563
Catherine Sullivane8278452015-02-06 08:52:08 +0000564 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000565 ecmd->transceiver = XCVR_EXTERNAL;
566
Catherine Sullivane8278452015-02-06 08:52:08 +0000567 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000568 ecmd->supported |= SUPPORTED_Pause;
569
Catherine Sullivane8278452015-02-06 08:52:08 +0000570 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000571 case I40E_FC_FULL:
572 ecmd->advertising |= ADVERTISED_Pause;
573 break;
574 case I40E_FC_TX_PAUSE:
575 ecmd->advertising |= ADVERTISED_Asym_Pause;
576 break;
577 case I40E_FC_RX_PAUSE:
578 ecmd->advertising |= (ADVERTISED_Pause |
579 ADVERTISED_Asym_Pause);
580 break;
581 default:
582 ecmd->advertising &= ~(ADVERTISED_Pause |
583 ADVERTISED_Asym_Pause);
584 break;
585 }
586
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000587 return 0;
588}
589
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000590/**
591 * i40e_set_settings - Set Speed and Duplex
592 * @netdev: network interface device structure
593 * @ecmd: ethtool command
594 *
595 * Set speed/duplex per media_types advertised/forced
596 **/
597static int i40e_set_settings(struct net_device *netdev,
598 struct ethtool_cmd *ecmd)
599{
600 struct i40e_netdev_priv *np = netdev_priv(netdev);
601 struct i40e_aq_get_phy_abilities_resp abilities;
602 struct i40e_aq_set_phy_config config;
603 struct i40e_pf *pf = np->vsi->back;
604 struct i40e_vsi *vsi = np->vsi;
605 struct i40e_hw *hw = &pf->hw;
606 struct ethtool_cmd safe_ecmd;
607 i40e_status status = 0;
608 bool change = false;
609 int err = 0;
610 u8 autoneg;
611 u32 advertise;
612
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000613 /* Changing port settings is not supported if this isn't the
614 * port's controlling PF
615 */
616 if (hw->partition_id != 1) {
617 i40e_partition_setting_complaint(pf);
618 return -EOPNOTSUPP;
619 }
620
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000621 if (vsi != pf->vsi[pf->lan_vsi])
622 return -EOPNOTSUPP;
623
624 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
625 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000626 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
627 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000628 return -EOPNOTSUPP;
629
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400630 if (hw->device_id == I40E_DEV_ID_KX_B ||
631 hw->device_id == I40E_DEV_ID_KX_C ||
632 hw->device_id == I40E_DEV_ID_20G_KR2 ||
633 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
634 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
635 return -EOPNOTSUPP;
636 }
637
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000638 /* get our own copy of the bits to check against */
639 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
640 i40e_get_settings(netdev, &safe_ecmd);
641
642 /* save autoneg and speed out of ecmd */
643 autoneg = ecmd->autoneg;
644 advertise = ecmd->advertising;
645
646 /* set autoneg and speed back to what they currently are */
647 ecmd->autoneg = safe_ecmd.autoneg;
648 ecmd->advertising = safe_ecmd.advertising;
649
650 ecmd->cmd = safe_ecmd.cmd;
651 /* If ecmd and safe_ecmd are not the same now, then they are
652 * trying to set something that we do not support
653 */
654 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
655 return -EOPNOTSUPP;
656
657 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
658 usleep_range(1000, 2000);
659
660 /* Get the current phy config */
661 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
662 NULL);
663 if (status)
664 return -EAGAIN;
665
Catherine Sullivan124ed152014-07-12 07:28:12 +0000666 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000667 * set below
668 */
669 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000670 config.abilities = abilities.abilities;
671
672 /* Check autoneg */
673 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000674 /* If autoneg was not already enabled */
675 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400676 /* If autoneg is not supported, return error */
677 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
678 netdev_info(netdev, "Autoneg not supported on this phy\n");
679 return -EINVAL;
680 }
681 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000682 config.abilities = abilities.abilities |
683 I40E_AQ_PHY_ENABLE_AN;
684 change = true;
685 }
686 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000687 /* If autoneg is currently enabled */
688 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400689 /* If autoneg is supported 10GBASE_T is the only PHY
690 * that can disable it, so otherwise return error
691 */
692 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
693 hw->phy.link_info.phy_type !=
694 I40E_PHY_TYPE_10GBASE_T) {
695 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
696 return -EINVAL;
697 }
698 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000699 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000700 ~I40E_AQ_PHY_ENABLE_AN;
701 change = true;
702 }
703 }
704
705 if (advertise & ~safe_ecmd.supported)
706 return -EINVAL;
707
708 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000709 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000710 if (advertise & ADVERTISED_1000baseT_Full ||
711 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000712 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000713 if (advertise & ADVERTISED_10000baseT_Full ||
714 advertise & ADVERTISED_10000baseKX4_Full ||
715 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000716 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700717 if (advertise & ADVERTISED_20000baseKR2_Full)
718 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000719 if (advertise & ADVERTISED_40000baseKR4_Full ||
720 advertise & ADVERTISED_40000baseCR4_Full ||
721 advertise & ADVERTISED_40000baseSR4_Full ||
722 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000723 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000724
Catherine Sullivan0002e112015-08-26 15:14:16 -0400725 /* If speed didn't get set, set it to what it currently is.
726 * This is needed because if advertise is 0 (as it is when autoneg
727 * is disabled) then speed won't get set.
728 */
729 if (!config.link_speed)
730 config.link_speed = abilities.link_speed;
731
Catherine Sullivan124ed152014-07-12 07:28:12 +0000732 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000733 /* copy over the rest of the abilities */
734 config.phy_type = abilities.phy_type;
735 config.eee_capability = abilities.eee_capability;
736 config.eeer = abilities.eeer_val;
737 config.low_power_ctrl = abilities.d3_lpan;
738
Catherine Sullivane8278452015-02-06 08:52:08 +0000739 /* save the requested speeds */
740 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000741 /* set link and auto negotiation so changes take effect */
742 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
743 /* If link is up put link down */
744 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
745 /* Tell the OS link is going down, the link will go
746 * back up when fw says it is ready asynchronously
747 */
Matt Jaredc156f852015-08-27 11:42:39 -0400748 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000749 netif_carrier_off(netdev);
750 netif_tx_stop_all_queues(netdev);
751 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000752
753 /* make the aq call */
754 status = i40e_aq_set_phy_config(hw, &config, NULL);
755 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400756 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
757 i40e_stat_str(hw, status),
758 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000759 return -EAGAIN;
760 }
761
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400762 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000763 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400764 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
765 i40e_stat_str(hw, status),
766 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000767
768 } else {
769 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
770 }
771
772 return err;
773}
774
Jesse Brandeburga6599722014-06-04 08:45:25 +0000775static int i40e_nway_reset(struct net_device *netdev)
776{
777 /* restart autonegotiation */
778 struct i40e_netdev_priv *np = netdev_priv(netdev);
779 struct i40e_pf *pf = np->vsi->back;
780 struct i40e_hw *hw = &pf->hw;
781 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
782 i40e_status ret = 0;
783
784 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
785 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400786 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
787 i40e_stat_str(hw, ret),
788 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000789 return -EIO;
790 }
791
792 return 0;
793}
794
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000795/**
796 * i40e_get_pauseparam - Get Flow Control status
797 * Return tx/rx-pause status
798 **/
799static void i40e_get_pauseparam(struct net_device *netdev,
800 struct ethtool_pauseparam *pause)
801{
802 struct i40e_netdev_priv *np = netdev_priv(netdev);
803 struct i40e_pf *pf = np->vsi->back;
804 struct i40e_hw *hw = &pf->hw;
805 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000806 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000807
808 pause->autoneg =
809 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
810 AUTONEG_ENABLE : AUTONEG_DISABLE);
811
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000812 /* PFC enabled so report LFC as off */
813 if (dcbx_cfg->pfc.pfcenable) {
814 pause->rx_pause = 0;
815 pause->tx_pause = 0;
816 return;
817 }
818
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000819 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000820 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000821 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000822 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000823 } else if (hw->fc.current_mode == I40E_FC_FULL) {
824 pause->rx_pause = 1;
825 pause->tx_pause = 1;
826 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000827}
828
Catherine Sullivan2becc352014-06-04 08:45:27 +0000829/**
830 * i40e_set_pauseparam - Set Flow Control parameter
831 * @netdev: network interface device structure
832 * @pause: return tx/rx flow control status
833 **/
834static int i40e_set_pauseparam(struct net_device *netdev,
835 struct ethtool_pauseparam *pause)
836{
837 struct i40e_netdev_priv *np = netdev_priv(netdev);
838 struct i40e_pf *pf = np->vsi->back;
839 struct i40e_vsi *vsi = np->vsi;
840 struct i40e_hw *hw = &pf->hw;
841 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000842 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000843 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
844 i40e_status status;
845 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000846 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000847
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000848 /* Changing the port's flow control is not supported if this isn't the
849 * port's controlling PF
850 */
851 if (hw->partition_id != 1) {
852 i40e_partition_setting_complaint(pf);
853 return -EOPNOTSUPP;
854 }
855
Catherine Sullivan2becc352014-06-04 08:45:27 +0000856 if (vsi != pf->vsi[pf->lan_vsi])
857 return -EOPNOTSUPP;
858
859 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
860 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
861 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
862 return -EOPNOTSUPP;
863 }
864
865 /* If we have link and don't have autoneg */
866 if (!test_bit(__I40E_DOWN, &pf->state) &&
867 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
868 /* Send message that it might not necessarily work*/
869 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
870 }
871
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000872 if (dcbx_cfg->pfc.pfcenable) {
873 netdev_info(netdev,
874 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000875 return -EOPNOTSUPP;
876 }
877
878 if (pause->rx_pause && pause->tx_pause)
879 hw->fc.requested_mode = I40E_FC_FULL;
880 else if (pause->rx_pause && !pause->tx_pause)
881 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
882 else if (!pause->rx_pause && pause->tx_pause)
883 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
884 else if (!pause->rx_pause && !pause->tx_pause)
885 hw->fc.requested_mode = I40E_FC_NONE;
886 else
887 return -EINVAL;
888
Catherine Sullivan94128512014-07-12 07:28:16 +0000889 /* Tell the OS link is going down, the link will go back up when fw
890 * says it is ready asynchronously
891 */
Matt Jaredc156f852015-08-27 11:42:39 -0400892 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000893 netif_carrier_off(netdev);
894 netif_tx_stop_all_queues(netdev);
895
Catherine Sullivan2becc352014-06-04 08:45:27 +0000896 /* Set the fc mode and only restart an if link is up*/
897 status = i40e_set_fc(hw, &aq_failures, link_up);
898
899 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400900 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
901 i40e_stat_str(hw, status),
902 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000903 err = -EAGAIN;
904 }
905 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400906 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
907 i40e_stat_str(hw, status),
908 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000909 err = -EAGAIN;
910 }
911 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400912 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
913 i40e_stat_str(hw, status),
914 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000915 err = -EAGAIN;
916 }
917
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000918 if (!test_bit(__I40E_DOWN, &pf->state)) {
919 /* Give it a little more time to try to come back */
920 msleep(75);
921 if (!test_bit(__I40E_DOWN, &pf->state))
922 return i40e_nway_reset(netdev);
923 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000924
925 return err;
926}
927
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000928static u32 i40e_get_msglevel(struct net_device *netdev)
929{
930 struct i40e_netdev_priv *np = netdev_priv(netdev);
931 struct i40e_pf *pf = np->vsi->back;
932
933 return pf->msg_enable;
934}
935
936static void i40e_set_msglevel(struct net_device *netdev, u32 data)
937{
938 struct i40e_netdev_priv *np = netdev_priv(netdev);
939 struct i40e_pf *pf = np->vsi->back;
940
941 if (I40E_DEBUG_USER & data)
942 pf->hw.debug_mask = data;
943 pf->msg_enable = data;
944}
945
946static int i40e_get_regs_len(struct net_device *netdev)
947{
948 int reg_count = 0;
949 int i;
950
951 for (i = 0; i40e_reg_list[i].offset != 0; i++)
952 reg_count += i40e_reg_list[i].elements;
953
954 return reg_count * sizeof(u32);
955}
956
957static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
958 void *p)
959{
960 struct i40e_netdev_priv *np = netdev_priv(netdev);
961 struct i40e_pf *pf = np->vsi->back;
962 struct i40e_hw *hw = &pf->hw;
963 u32 *reg_buf = p;
964 int i, j, ri;
965 u32 reg;
966
967 /* Tell ethtool which driver-version-specific regs output we have.
968 *
969 * At some point, if we have ethtool doing special formatting of
970 * this data, it will rely on this version number to know how to
971 * interpret things. Hence, this needs to be updated if/when the
972 * diags register table is changed.
973 */
974 regs->version = 1;
975
976 /* loop through the diags reg table for what to print */
977 ri = 0;
978 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
979 for (j = 0; j < i40e_reg_list[i].elements; j++) {
980 reg = i40e_reg_list[i].offset
981 + (j * i40e_reg_list[i].stride);
982 reg_buf[ri++] = rd32(hw, reg);
983 }
984 }
985
986}
987
988static int i40e_get_eeprom(struct net_device *netdev,
989 struct ethtool_eeprom *eeprom, u8 *bytes)
990{
991 struct i40e_netdev_priv *np = netdev_priv(netdev);
992 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000993 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000994 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000995 u8 *eeprom_buff;
996 u16 i, sectors;
997 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000998 u32 magic;
999
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001000#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001001 if (eeprom->len == 0)
1002 return -EINVAL;
1003
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001004 /* check for NVMUpdate access method */
1005 magic = hw->vendor_id | (hw->device_id << 16);
1006 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +00001007 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001008 int errno;
1009
1010 /* make sure it is the right magic for NVMUpdate */
1011 if ((eeprom->magic >> 16) != hw->device_id)
1012 return -EINVAL;
1013
Shannon Nelsonc150a502014-11-13 08:23:13 +00001014 cmd = (struct i40e_nvm_access *)eeprom;
1015 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001016 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001017 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001018 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1019 ret_val, hw->aq.asq_last_status, errno,
1020 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1021 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001022
1023 return errno;
1024 }
1025
1026 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001027 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1028
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001029 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001030 if (!eeprom_buff)
1031 return -ENOMEM;
1032
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001033 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1034 if (ret_val) {
1035 dev_info(&pf->pdev->dev,
1036 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1037 ret_val, hw->aq.asq_last_status);
1038 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001039 }
1040
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001041 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1042 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1043 len = I40E_NVM_SECTOR_SIZE;
1044 last = false;
1045 for (i = 0; i < sectors; i++) {
1046 if (i == (sectors - 1)) {
1047 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1048 last = true;
1049 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001050 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1051 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001052 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001053 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001054 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001055 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001056 "read NVM failed, invalid offset 0x%x\n",
1057 offset);
1058 break;
1059 } else if (ret_val &&
1060 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1061 dev_info(&pf->pdev->dev,
1062 "read NVM failed, access, offset 0x%x\n",
1063 offset);
1064 break;
1065 } else if (ret_val) {
1066 dev_info(&pf->pdev->dev,
1067 "read NVM failed offset %d err=%d status=0x%x\n",
1068 offset, ret_val, hw->aq.asq_last_status);
1069 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001070 }
1071 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001073 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001074 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001075free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001076 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001077 return ret_val;
1078}
1079
1080static int i40e_get_eeprom_len(struct net_device *netdev)
1081{
1082 struct i40e_netdev_priv *np = netdev_priv(netdev);
1083 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001084 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001086 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1087 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1088 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1089 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001090 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001091 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001092}
1093
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001094static int i40e_set_eeprom(struct net_device *netdev,
1095 struct ethtool_eeprom *eeprom, u8 *bytes)
1096{
1097 struct i40e_netdev_priv *np = netdev_priv(netdev);
1098 struct i40e_hw *hw = &np->vsi->back->hw;
1099 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001100 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001101 int ret_val = 0;
1102 int errno;
1103 u32 magic;
1104
1105 /* normal ethtool set_eeprom is not supported */
1106 magic = hw->vendor_id | (hw->device_id << 16);
1107 if (eeprom->magic == magic)
1108 return -EOPNOTSUPP;
1109
1110 /* check for NVMUpdate access method */
1111 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1112 return -EINVAL;
1113
1114 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1115 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1116 return -EBUSY;
1117
Shannon Nelsonc150a502014-11-13 08:23:13 +00001118 cmd = (struct i40e_nvm_access *)eeprom;
1119 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001120 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001121 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001122 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1123 ret_val, hw->aq.asq_last_status, errno,
1124 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1125 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001126
1127 return errno;
1128}
1129
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001130static void i40e_get_drvinfo(struct net_device *netdev,
1131 struct ethtool_drvinfo *drvinfo)
1132{
1133 struct i40e_netdev_priv *np = netdev_priv(netdev);
1134 struct i40e_vsi *vsi = np->vsi;
1135 struct i40e_pf *pf = vsi->back;
1136
1137 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1138 strlcpy(drvinfo->version, i40e_driver_version_str,
1139 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001140 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001141 sizeof(drvinfo->fw_version));
1142 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1143 sizeof(drvinfo->bus_info));
1144}
1145
1146static void i40e_get_ringparam(struct net_device *netdev,
1147 struct ethtool_ringparam *ring)
1148{
1149 struct i40e_netdev_priv *np = netdev_priv(netdev);
1150 struct i40e_pf *pf = np->vsi->back;
1151 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1152
1153 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1154 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1155 ring->rx_mini_max_pending = 0;
1156 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001157 ring->rx_pending = vsi->rx_rings[0]->count;
1158 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001159 ring->rx_mini_pending = 0;
1160 ring->rx_jumbo_pending = 0;
1161}
1162
1163static int i40e_set_ringparam(struct net_device *netdev,
1164 struct ethtool_ringparam *ring)
1165{
1166 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1167 struct i40e_netdev_priv *np = netdev_priv(netdev);
1168 struct i40e_vsi *vsi = np->vsi;
1169 struct i40e_pf *pf = vsi->back;
1170 u32 new_rx_count, new_tx_count;
1171 int i, err = 0;
1172
1173 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1174 return -EINVAL;
1175
Shannon Nelson1fa18372013-11-20 10:03:08 +00001176 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1177 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1178 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1179 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1180 netdev_info(netdev,
1181 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1182 ring->tx_pending, ring->rx_pending,
1183 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1184 return -EINVAL;
1185 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001186
Shannon Nelson1fa18372013-11-20 10:03:08 +00001187 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1188 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001189
1190 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001191 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1192 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001193 return 0;
1194
1195 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1196 usleep_range(1000, 2000);
1197
1198 if (!netif_running(vsi->netdev)) {
1199 /* simple case - set for the next time the netdev is started */
1200 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001201 vsi->tx_rings[i]->count = new_tx_count;
1202 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001203 }
1204 goto done;
1205 }
1206
1207 /* We can't just free everything and then setup again,
1208 * because the ISRs in MSI-X mode get passed pointers
1209 * to the Tx and Rx ring structs.
1210 */
1211
1212 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001213 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001214 netdev_info(netdev,
1215 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001216 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001217 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1218 sizeof(struct i40e_ring), GFP_KERNEL);
1219 if (!tx_rings) {
1220 err = -ENOMEM;
1221 goto done;
1222 }
1223
1224 for (i = 0; i < vsi->num_queue_pairs; i++) {
1225 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001226 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001227 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001228 /* the desc and bi pointers will be reallocated in the
1229 * setup call
1230 */
1231 tx_rings[i].desc = NULL;
1232 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001233 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1234 if (err) {
1235 while (i) {
1236 i--;
1237 i40e_free_tx_resources(&tx_rings[i]);
1238 }
1239 kfree(tx_rings);
1240 tx_rings = NULL;
1241
1242 goto done;
1243 }
1244 }
1245 }
1246
1247 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001248 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001249 netdev_info(netdev,
1250 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001251 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001252 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1253 sizeof(struct i40e_ring), GFP_KERNEL);
1254 if (!rx_rings) {
1255 err = -ENOMEM;
1256 goto free_tx;
1257 }
1258
1259 for (i = 0; i < vsi->num_queue_pairs; i++) {
1260 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001261 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001262 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001263 /* the desc and bi pointers will be reallocated in the
1264 * setup call
1265 */
1266 rx_rings[i].desc = NULL;
1267 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001268 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1269 if (err) {
1270 while (i) {
1271 i--;
1272 i40e_free_rx_resources(&rx_rings[i]);
1273 }
1274 kfree(rx_rings);
1275 rx_rings = NULL;
1276
1277 goto free_tx;
1278 }
1279 }
1280 }
1281
1282 /* Bring interface down, copy in the new ring info,
1283 * then restore the interface
1284 */
1285 i40e_down(vsi);
1286
1287 if (tx_rings) {
1288 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001289 i40e_free_tx_resources(vsi->tx_rings[i]);
1290 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001291 }
1292 kfree(tx_rings);
1293 tx_rings = NULL;
1294 }
1295
1296 if (rx_rings) {
1297 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001298 i40e_free_rx_resources(vsi->rx_rings[i]);
1299 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001300 }
1301 kfree(rx_rings);
1302 rx_rings = NULL;
1303 }
1304
1305 i40e_up(vsi);
1306
1307free_tx:
1308 /* error cleanup if the Rx allocations failed after getting Tx */
1309 if (tx_rings) {
1310 for (i = 0; i < vsi->num_queue_pairs; i++)
1311 i40e_free_tx_resources(&tx_rings[i]);
1312 kfree(tx_rings);
1313 tx_rings = NULL;
1314 }
1315
1316done:
1317 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1318
1319 return err;
1320}
1321
1322static int i40e_get_sset_count(struct net_device *netdev, int sset)
1323{
1324 struct i40e_netdev_priv *np = netdev_priv(netdev);
1325 struct i40e_vsi *vsi = np->vsi;
1326 struct i40e_pf *pf = vsi->back;
1327
1328 switch (sset) {
1329 case ETH_SS_TEST:
1330 return I40E_TEST_LEN;
1331 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001332 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001333 int len = I40E_PF_STATS_LEN(netdev);
1334
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001335 if ((pf->lan_veb != I40E_NO_VEB) &&
1336 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001337 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001338 return len;
1339 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001340 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001341 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001342 case ETH_SS_PRIV_FLAGS:
1343 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001344 default:
1345 return -EOPNOTSUPP;
1346 }
1347}
1348
1349static void i40e_get_ethtool_stats(struct net_device *netdev,
1350 struct ethtool_stats *stats, u64 *data)
1351{
1352 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001353 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001354 struct i40e_vsi *vsi = np->vsi;
1355 struct i40e_pf *pf = vsi->back;
1356 int i = 0;
1357 char *p;
1358 int j;
1359 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001360 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361
1362 i40e_update_stats(vsi);
1363
1364 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1365 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1366 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1367 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1368 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001369 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1370 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1371 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1372 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1373 }
Vasu Dev38e00432014-08-01 13:27:03 -07001374#ifdef I40E_FCOE
1375 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1376 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1377 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1378 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1379 }
1380#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001381 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001382 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001383 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001384
1385 if (!tx_ring)
1386 continue;
1387
1388 /* process Tx ring statistics */
1389 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001390 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001391 data[i] = tx_ring->stats.packets;
1392 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001393 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001394 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001395
1396 /* Rx ring is the 2nd half of the queue pair */
1397 rx_ring = &tx_ring[1];
1398 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001399 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001400 data[i] = rx_ring->stats.packets;
1401 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001402 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001403 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001404 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001405 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001406 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001407 return;
1408
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001409 if ((pf->lan_veb != I40E_NO_VEB) &&
1410 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001411 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001412
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001413 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1414 p = (char *)veb;
1415 p += i40e_gstrings_veb_stats[j].stat_offset;
1416 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1417 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001418 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001419 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1420 data[i++] = veb->tc_stats.tc_tx_packets[j];
1421 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1422 data[i++] = veb->tc_stats.tc_rx_packets[j];
1423 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1424 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001425 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001426 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1427 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1428 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1429 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1430 }
1431 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1432 data[i++] = pf->stats.priority_xon_tx[j];
1433 data[i++] = pf->stats.priority_xoff_tx[j];
1434 }
1435 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1436 data[i++] = pf->stats.priority_xon_rx[j];
1437 data[i++] = pf->stats.priority_xoff_rx[j];
1438 }
1439 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1440 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441}
1442
1443static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1444 u8 *data)
1445{
1446 struct i40e_netdev_priv *np = netdev_priv(netdev);
1447 struct i40e_vsi *vsi = np->vsi;
1448 struct i40e_pf *pf = vsi->back;
1449 char *p = (char *)data;
1450 int i;
1451
1452 switch (stringset) {
1453 case ETH_SS_TEST:
1454 for (i = 0; i < I40E_TEST_LEN; i++) {
1455 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1456 data += ETH_GSTRING_LEN;
1457 }
1458 break;
1459 case ETH_SS_STATS:
1460 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1461 snprintf(p, ETH_GSTRING_LEN, "%s",
1462 i40e_gstrings_net_stats[i].stat_string);
1463 p += ETH_GSTRING_LEN;
1464 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001465 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1466 snprintf(p, ETH_GSTRING_LEN, "%s",
1467 i40e_gstrings_misc_stats[i].stat_string);
1468 p += ETH_GSTRING_LEN;
1469 }
Vasu Dev38e00432014-08-01 13:27:03 -07001470#ifdef I40E_FCOE
1471 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1472 snprintf(p, ETH_GSTRING_LEN, "%s",
1473 i40e_gstrings_fcoe_stats[i].stat_string);
1474 p += ETH_GSTRING_LEN;
1475 }
1476#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477 for (i = 0; i < vsi->num_queue_pairs; i++) {
1478 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1479 p += ETH_GSTRING_LEN;
1480 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1481 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1483 p += ETH_GSTRING_LEN;
1484 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1485 p += ETH_GSTRING_LEN;
1486 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001487 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001488 return;
1489
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001490 if ((pf->lan_veb != I40E_NO_VEB) &&
1491 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001492 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1493 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1494 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495 p += ETH_GSTRING_LEN;
1496 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001497 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1498 snprintf(p, ETH_GSTRING_LEN,
1499 "veb.tc_%u_tx_packets", i);
1500 p += ETH_GSTRING_LEN;
1501 snprintf(p, ETH_GSTRING_LEN,
1502 "veb.tc_%u_tx_bytes", i);
1503 p += ETH_GSTRING_LEN;
1504 snprintf(p, ETH_GSTRING_LEN,
1505 "veb.tc_%u_rx_packets", i);
1506 p += ETH_GSTRING_LEN;
1507 snprintf(p, ETH_GSTRING_LEN,
1508 "veb.tc_%u_rx_bytes", i);
1509 p += ETH_GSTRING_LEN;
1510 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001511 }
1512 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1513 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1514 i40e_gstrings_stats[i].stat_string);
1515 p += ETH_GSTRING_LEN;
1516 }
1517 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1518 snprintf(p, ETH_GSTRING_LEN,
1519 "port.tx_priority_%u_xon", i);
1520 p += ETH_GSTRING_LEN;
1521 snprintf(p, ETH_GSTRING_LEN,
1522 "port.tx_priority_%u_xoff", i);
1523 p += ETH_GSTRING_LEN;
1524 }
1525 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1526 snprintf(p, ETH_GSTRING_LEN,
1527 "port.rx_priority_%u_xon", i);
1528 p += ETH_GSTRING_LEN;
1529 snprintf(p, ETH_GSTRING_LEN,
1530 "port.rx_priority_%u_xoff", i);
1531 p += ETH_GSTRING_LEN;
1532 }
1533 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1534 snprintf(p, ETH_GSTRING_LEN,
1535 "port.rx_priority_%u_xon_2_xoff", i);
1536 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537 }
1538 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1539 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001540 case ETH_SS_PRIV_FLAGS:
1541 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1542 memcpy(data, i40e_priv_flags_strings[i],
1543 ETH_GSTRING_LEN);
1544 data += ETH_GSTRING_LEN;
1545 }
1546 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001547 default:
1548 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001549 }
1550}
1551
1552static int i40e_get_ts_info(struct net_device *dev,
1553 struct ethtool_ts_info *info)
1554{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001555 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1556
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001557 /* only report HW timestamping if PTP is enabled */
1558 if (!(pf->flags & I40E_FLAG_PTP))
1559 return ethtool_op_get_ts_info(dev, info);
1560
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001561 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1562 SOF_TIMESTAMPING_RX_SOFTWARE |
1563 SOF_TIMESTAMPING_SOFTWARE |
1564 SOF_TIMESTAMPING_TX_HARDWARE |
1565 SOF_TIMESTAMPING_RX_HARDWARE |
1566 SOF_TIMESTAMPING_RAW_HARDWARE;
1567
1568 if (pf->ptp_clock)
1569 info->phc_index = ptp_clock_index(pf->ptp_clock);
1570 else
1571 info->phc_index = -1;
1572
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001573 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001574
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001575 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1576 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1577 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001578
1579 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580}
1581
Shannon Nelson7b086392013-11-20 10:02:59 +00001582static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001583{
Shannon Nelson7b086392013-11-20 10:02:59 +00001584 struct i40e_netdev_priv *np = netdev_priv(netdev);
1585 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001586 i40e_status status;
1587 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001588
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001589 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001590 status = i40e_get_link_status(&pf->hw, &link_up);
1591 if (status) {
1592 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1593 *data = 1;
1594 return *data;
1595 }
1596
1597 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001598 *data = 0;
1599 else
1600 *data = 1;
1601
1602 return *data;
1603}
1604
Shannon Nelson7b086392013-11-20 10:02:59 +00001605static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001606{
Shannon Nelson7b086392013-11-20 10:02:59 +00001607 struct i40e_netdev_priv *np = netdev_priv(netdev);
1608 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001610 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001611 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001612
Shannon Nelson7b086392013-11-20 10:02:59 +00001613 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614}
1615
Shannon Nelson7b086392013-11-20 10:02:59 +00001616static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001617{
Shannon Nelson7b086392013-11-20 10:02:59 +00001618 struct i40e_netdev_priv *np = netdev_priv(netdev);
1619 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001620
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001621 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001622 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001623
Shannon Nelson4443ec92014-11-13 08:23:12 +00001624 /* forcebly clear the NVM Update state machine */
1625 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1626
Shannon Nelson7b086392013-11-20 10:02:59 +00001627 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001628}
1629
Shannon Nelson7b086392013-11-20 10:02:59 +00001630static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001631{
Shannon Nelson7b086392013-11-20 10:02:59 +00001632 struct i40e_netdev_priv *np = netdev_priv(netdev);
1633 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001634 u16 swc_old = pf->sw_int_count;
1635
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001636 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001637 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1638 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001639 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1640 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1641 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1642 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001643 usleep_range(1000, 2000);
1644 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001645
1646 return *data;
1647}
1648
Shannon Nelson7b086392013-11-20 10:02:59 +00001649static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001650{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001651 struct i40e_netdev_priv *np = netdev_priv(netdev);
1652 struct i40e_pf *pf = np->vsi->back;
1653
1654 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001655 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001656
1657 return *data;
1658}
1659
Greg Rosee17bc412015-04-16 20:05:59 -04001660static inline bool i40e_active_vfs(struct i40e_pf *pf)
1661{
1662 struct i40e_vf *vfs = pf->vf;
1663 int i;
1664
1665 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001666 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001667 return true;
1668 return false;
1669}
1670
Greg Rose510efb22015-07-10 19:36:01 -04001671static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1672{
1673 struct i40e_vsi **vsi = pf->vsi;
1674 int i;
1675
1676 for (i = 0; i < pf->num_alloc_vsi; i++) {
1677 if (!vsi[i])
1678 continue;
1679 if (vsi[i]->type == I40E_VSI_VMDQ2)
1680 return true;
1681 }
1682
1683 return false;
1684}
1685
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001686static void i40e_diag_test(struct net_device *netdev,
1687 struct ethtool_test *eth_test, u64 *data)
1688{
1689 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001690 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001691 struct i40e_pf *pf = np->vsi->back;
1692
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001693 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1694 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001695 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001696
Shannon Nelsonf551b432013-11-26 10:49:12 +00001697 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001698
Greg Rose510efb22015-07-10 19:36:01 -04001699 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001700 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001701 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001702 data[I40E_ETH_TEST_REG] = 1;
1703 data[I40E_ETH_TEST_EEPROM] = 1;
1704 data[I40E_ETH_TEST_INTR] = 1;
1705 data[I40E_ETH_TEST_LOOPBACK] = 1;
1706 data[I40E_ETH_TEST_LINK] = 1;
1707 eth_test->flags |= ETH_TEST_FL_FAILED;
1708 clear_bit(__I40E_TESTING, &pf->state);
1709 goto skip_ol_tests;
1710 }
1711
Greg Rose5b86c5c2015-02-26 16:14:35 +00001712 /* If the device is online then take it offline */
1713 if (if_running)
1714 /* indicate we're in test mode */
1715 dev_close(netdev);
1716 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001717 /* This reset does not affect link - if it is
1718 * changed to a type of reset that does affect
1719 * link then the following link test would have
1720 * to be moved to before the reset
1721 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001722 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001723
Shannon Nelson7b086392013-11-20 10:02:59 +00001724 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001725 eth_test->flags |= ETH_TEST_FL_FAILED;
1726
Shannon Nelson7b086392013-11-20 10:02:59 +00001727 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001728 eth_test->flags |= ETH_TEST_FL_FAILED;
1729
Shannon Nelson7b086392013-11-20 10:02:59 +00001730 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001731 eth_test->flags |= ETH_TEST_FL_FAILED;
1732
Shannon Nelson7b086392013-11-20 10:02:59 +00001733 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001734 eth_test->flags |= ETH_TEST_FL_FAILED;
1735
Shannon Nelsonf551b432013-11-26 10:49:12 +00001736 /* run reg test last, a reset is required after it */
1737 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1738 eth_test->flags |= ETH_TEST_FL_FAILED;
1739
1740 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001741 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001742
1743 if (if_running)
1744 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001745 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001746 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001747 netif_info(pf, drv, netdev, "online testing starting\n");
1748
Shannon Nelson7b086392013-11-20 10:02:59 +00001749 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001750 eth_test->flags |= ETH_TEST_FL_FAILED;
1751
1752 /* Offline only tests, not run in online; pass by default */
1753 data[I40E_ETH_TEST_REG] = 0;
1754 data[I40E_ETH_TEST_EEPROM] = 0;
1755 data[I40E_ETH_TEST_INTR] = 0;
1756 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001757 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001758
Greg Rosee17bc412015-04-16 20:05:59 -04001759skip_ol_tests:
1760
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001761 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001762}
1763
1764static void i40e_get_wol(struct net_device *netdev,
1765 struct ethtool_wolinfo *wol)
1766{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001767 struct i40e_netdev_priv *np = netdev_priv(netdev);
1768 struct i40e_pf *pf = np->vsi->back;
1769 struct i40e_hw *hw = &pf->hw;
1770 u16 wol_nvm_bits;
1771
1772 /* NVM bit on means WoL disabled for the port */
1773 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001774 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001775 wol->supported = 0;
1776 wol->wolopts = 0;
1777 } else {
1778 wol->supported = WAKE_MAGIC;
1779 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1780 }
1781}
1782
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001783/**
1784 * i40e_set_wol - set the WakeOnLAN configuration
1785 * @netdev: the netdev in question
1786 * @wol: the ethtool WoL setting data
1787 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001788static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1789{
1790 struct i40e_netdev_priv *np = netdev_priv(netdev);
1791 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001792 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001793 struct i40e_hw *hw = &pf->hw;
1794 u16 wol_nvm_bits;
1795
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001796 /* WoL not supported if this isn't the controlling PF on the port */
1797 if (hw->partition_id != 1) {
1798 i40e_partition_setting_complaint(pf);
1799 return -EOPNOTSUPP;
1800 }
1801
1802 if (vsi != pf->vsi[pf->lan_vsi])
1803 return -EOPNOTSUPP;
1804
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001805 /* NVM bit on means WoL disabled for the port */
1806 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001807 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001808 return -EOPNOTSUPP;
1809
1810 /* only magic packet is supported */
1811 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1812 return -EOPNOTSUPP;
1813
1814 /* is this a new value? */
1815 if (pf->wol_en != !!wol->wolopts) {
1816 pf->wol_en = !!wol->wolopts;
1817 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1818 }
1819
1820 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001821}
1822
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823static int i40e_set_phys_id(struct net_device *netdev,
1824 enum ethtool_phys_id_state state)
1825{
1826 struct i40e_netdev_priv *np = netdev_priv(netdev);
1827 struct i40e_pf *pf = np->vsi->back;
1828 struct i40e_hw *hw = &pf->hw;
1829 int blink_freq = 2;
1830
1831 switch (state) {
1832 case ETHTOOL_ID_ACTIVE:
1833 pf->led_status = i40e_led_get(hw);
1834 return blink_freq;
1835 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001836 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001837 break;
1838 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001839 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001840 break;
1841 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001842 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001843 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001844 default:
1845 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001846 }
1847
1848 return 0;
1849}
1850
1851/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1852 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1853 * 125us (8000 interrupts per second) == ITR(62)
1854 */
1855
1856static int i40e_get_coalesce(struct net_device *netdev,
1857 struct ethtool_coalesce *ec)
1858{
1859 struct i40e_netdev_priv *np = netdev_priv(netdev);
1860 struct i40e_vsi *vsi = np->vsi;
1861
1862 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1863 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1864
1865 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001866 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001867
1868 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001869 ec->use_adaptive_tx_coalesce = 1;
1870
1871 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1872 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001873 /* we use the _usecs_high to store/set the interrupt rate limit
1874 * that the hardware supports, that almost but not quite
1875 * fits the original intent of the ethtool variable,
1876 * the rx_coalesce_usecs_high limits total interrupts
1877 * per second from both tx/rx sources.
1878 */
1879 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1880 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001881
1882 return 0;
1883}
1884
1885static int i40e_set_coalesce(struct net_device *netdev,
1886 struct ethtool_coalesce *ec)
1887{
1888 struct i40e_netdev_priv *np = netdev_priv(netdev);
1889 struct i40e_q_vector *q_vector;
1890 struct i40e_vsi *vsi = np->vsi;
1891 struct i40e_pf *pf = vsi->back;
1892 struct i40e_hw *hw = &pf->hw;
1893 u16 vector;
1894 int i;
1895
1896 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1897 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1898
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001899 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1900 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1901 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1902 return -EINVAL;
1903 }
1904
1905 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1906 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1907 return -EINVAL;
1908 }
1909
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001910 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001911 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001912 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001913 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001914 } else if (ec->rx_coalesce_usecs == 0) {
1915 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001916 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001917 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 +00001918 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001919 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001920 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001921 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001922
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001923 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1924
Mitch Williams32f5f542014-04-04 04:43:10 +00001925 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001926 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001927 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001928 } else if (ec->tx_coalesce_usecs == 0) {
1929 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001930 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001931 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 +00001932 } else {
1933 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001934 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001935 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001936 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001937
1938 if (ec->use_adaptive_rx_coalesce)
1939 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1940 else
1941 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1942
1943 if (ec->use_adaptive_tx_coalesce)
1944 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1945 else
1946 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001947
Alexander Duyck493fb302013-09-28 07:01:44 +00001948 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001949 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1950
Alexander Duyck493fb302013-09-28 07:01:44 +00001951 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001952 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1953 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1954 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1955 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001956 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001957 i40e_flush(hw);
1958 }
1959
1960 return 0;
1961}
1962
1963/**
1964 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1965 * @pf: pointer to the physical function struct
1966 * @cmd: ethtool rxnfc command
1967 *
1968 * Returns Success if the flow is supported, else Invalid Input.
1969 **/
1970static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1971{
1972 cmd->data = 0;
1973
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001974 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1975 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1976 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1977 return 0;
1978 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001979 /* Report default options for RSS on i40e */
1980 switch (cmd->flow_type) {
1981 case TCP_V4_FLOW:
1982 case UDP_V4_FLOW:
1983 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1984 /* fall through to add IP fields */
1985 case SCTP_V4_FLOW:
1986 case AH_ESP_V4_FLOW:
1987 case AH_V4_FLOW:
1988 case ESP_V4_FLOW:
1989 case IPV4_FLOW:
1990 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1991 break;
1992 case TCP_V6_FLOW:
1993 case UDP_V6_FLOW:
1994 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1995 /* fall through to add IP fields */
1996 case SCTP_V6_FLOW:
1997 case AH_ESP_V6_FLOW:
1998 case AH_V6_FLOW:
1999 case ESP_V6_FLOW:
2000 case IPV6_FLOW:
2001 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2002 break;
2003 default:
2004 return -EINVAL;
2005 }
2006
2007 return 0;
2008}
2009
2010/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002011 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2012 * @pf: Pointer to the physical function struct
2013 * @cmd: The command to get or set Rx flow classification rules
2014 * @rule_locs: Array of used rule locations
2015 *
2016 * This function populates both the total and actual rule count of
2017 * the ethtool flow classification command
2018 *
2019 * Returns 0 on success or -EMSGSIZE if entry not found
2020 **/
2021static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2022 struct ethtool_rxnfc *cmd,
2023 u32 *rule_locs)
2024{
2025 struct i40e_fdir_filter *rule;
2026 struct hlist_node *node2;
2027 int cnt = 0;
2028
2029 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002030 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002031
2032 hlist_for_each_entry_safe(rule, node2,
2033 &pf->fdir_filter_list, fdir_node) {
2034 if (cnt == cmd->rule_cnt)
2035 return -EMSGSIZE;
2036
2037 rule_locs[cnt] = rule->fd_id;
2038 cnt++;
2039 }
2040
2041 cmd->rule_cnt = cnt;
2042
2043 return 0;
2044}
2045
2046/**
2047 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2048 * @pf: Pointer to the physical function struct
2049 * @cmd: The command to get or set Rx flow classification rules
2050 *
2051 * This function looks up a filter based on the Rx flow classification
2052 * command and fills the flow spec info for it if found
2053 *
2054 * Returns 0 on success or -EINVAL if filter not found
2055 **/
2056static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2057 struct ethtool_rxnfc *cmd)
2058{
2059 struct ethtool_rx_flow_spec *fsp =
2060 (struct ethtool_rx_flow_spec *)&cmd->fs;
2061 struct i40e_fdir_filter *rule = NULL;
2062 struct hlist_node *node2;
2063
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002064 hlist_for_each_entry_safe(rule, node2,
2065 &pf->fdir_filter_list, fdir_node) {
2066 if (fsp->location <= rule->fd_id)
2067 break;
2068 }
2069
2070 if (!rule || fsp->location != rule->fd_id)
2071 return -EINVAL;
2072
2073 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002074 if (fsp->flow_type == IP_USER_FLOW) {
2075 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2076 fsp->h_u.usr_ip4_spec.proto = 0;
2077 fsp->m_u.usr_ip4_spec.proto = 0;
2078 }
2079
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002080 /* Reverse the src and dest notion, since the HW views them from
2081 * Tx perspective where as the user expects it from Rx filter view.
2082 */
2083 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2084 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2085 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2086 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002087
2088 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2089 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2090 else
2091 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002092
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002093 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2094 struct i40e_vsi *vsi;
2095
2096 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2097 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2098 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2099 fsp->m_ext.data[1] = htonl(0x1);
2100 }
2101 }
2102
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002103 return 0;
2104}
2105
2106/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002107 * i40e_get_rxnfc - command to get RX flow classification rules
2108 * @netdev: network interface device structure
2109 * @cmd: ethtool rxnfc command
2110 *
2111 * Returns Success if the command is supported.
2112 **/
2113static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2114 u32 *rule_locs)
2115{
2116 struct i40e_netdev_priv *np = netdev_priv(netdev);
2117 struct i40e_vsi *vsi = np->vsi;
2118 struct i40e_pf *pf = vsi->back;
2119 int ret = -EOPNOTSUPP;
2120
2121 switch (cmd->cmd) {
2122 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002123 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002124 ret = 0;
2125 break;
2126 case ETHTOOL_GRXFH:
2127 ret = i40e_get_rss_hash_opts(pf, cmd);
2128 break;
2129 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002130 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002131 /* report total rule count */
2132 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002133 ret = 0;
2134 break;
2135 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002136 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002137 break;
2138 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002139 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2140 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002141 default:
2142 break;
2143 }
2144
2145 return ret;
2146}
2147
2148/**
2149 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2150 * @pf: pointer to the physical function struct
2151 * @cmd: ethtool rxnfc command
2152 *
2153 * Returns Success if the flow input set is supported.
2154 **/
2155static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2156{
2157 struct i40e_hw *hw = &pf->hw;
2158 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2159 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2160
2161 /* RSS does not support anything other than hashing
2162 * to queues on src and dst IPs and ports
2163 */
2164 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2165 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2166 return -EINVAL;
2167
2168 /* We need at least the IP SRC and DEST fields for hashing */
2169 if (!(nfc->data & RXH_IP_SRC) ||
2170 !(nfc->data & RXH_IP_DST))
2171 return -EINVAL;
2172
2173 switch (nfc->flow_type) {
2174 case TCP_V4_FLOW:
2175 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2176 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002177 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002179 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2180 hena |=
2181 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2182
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002183 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 break;
2185 default:
2186 return -EINVAL;
2187 }
2188 break;
2189 case TCP_V6_FLOW:
2190 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2191 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002192 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002193 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002194 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2195 hena |=
2196 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2197
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002198 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002199 break;
2200 default:
2201 return -EINVAL;
2202 }
2203 break;
2204 case UDP_V4_FLOW:
2205 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2206 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002207 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002208 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002209 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2210 hena |=
2211 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2212 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2213
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002214 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2215 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002216 break;
2217 default:
2218 return -EINVAL;
2219 }
2220 break;
2221 case UDP_V6_FLOW:
2222 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2223 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002224 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002226 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2227 hena |=
2228 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2229 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2230
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002231 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2232 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002233 break;
2234 default:
2235 return -EINVAL;
2236 }
2237 break;
2238 case AH_ESP_V4_FLOW:
2239 case AH_V4_FLOW:
2240 case ESP_V4_FLOW:
2241 case SCTP_V4_FLOW:
2242 if ((nfc->data & RXH_L4_B_0_1) ||
2243 (nfc->data & RXH_L4_B_2_3))
2244 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002245 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002246 break;
2247 case AH_ESP_V6_FLOW:
2248 case AH_V6_FLOW:
2249 case ESP_V6_FLOW:
2250 case SCTP_V6_FLOW:
2251 if ((nfc->data & RXH_L4_B_0_1) ||
2252 (nfc->data & RXH_L4_B_2_3))
2253 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002254 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002255 break;
2256 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002257 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2258 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002259 break;
2260 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002261 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2262 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002263 break;
2264 default:
2265 return -EINVAL;
2266 }
2267
2268 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2269 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2270 i40e_flush(hw);
2271
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002272 /* Save setting for future output/update */
2273 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2274
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275 return 0;
2276}
2277
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002278/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002279 * i40e_match_fdir_input_set - Match a new filter against an existing one
2280 * @rule: The filter already added
2281 * @input: The new filter to comapre against
2282 *
2283 * Returns true if the two input set match
2284 **/
2285static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2286 struct i40e_fdir_filter *input)
2287{
2288 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2289 (rule->src_ip[0] != input->src_ip[0]) ||
2290 (rule->dst_port != input->dst_port) ||
2291 (rule->src_port != input->src_port))
2292 return false;
2293 return true;
2294}
2295
2296/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002297 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2298 * @vsi: Pointer to the targeted VSI
2299 * @input: The filter to update or NULL to indicate deletion
2300 * @sw_idx: Software index to the filter
2301 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002302 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002303 * This function updates (or deletes) a Flow Director entry from
2304 * the hlist of the corresponding PF
2305 *
2306 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002307 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002308static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2309 struct i40e_fdir_filter *input,
2310 u16 sw_idx,
2311 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002312{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002313 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002314 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002315 struct hlist_node *node2;
2316 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002317
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002318 parent = NULL;
2319 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002320
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002321 hlist_for_each_entry_safe(rule, node2,
2322 &pf->fdir_filter_list, fdir_node) {
2323 /* hash found, or no matching entry */
2324 if (rule->fd_id >= sw_idx)
2325 break;
2326 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002327 }
2328
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002329 /* if there is an old rule occupying our place remove it */
2330 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002331 if (input && !i40e_match_fdir_input_set(rule, input))
2332 err = i40e_add_del_fdir(vsi, rule, false);
2333 else if (!input)
2334 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002335 hlist_del(&rule->fdir_node);
2336 kfree(rule);
2337 pf->fdir_pf_active_filters--;
2338 }
2339
2340 /* If no input this was a delete, err should be 0 if a rule was
2341 * successfully found and removed from the list else -EINVAL
2342 */
2343 if (!input)
2344 return err;
2345
2346 /* initialize node and set software index */
2347 INIT_HLIST_NODE(&input->fdir_node);
2348
2349 /* add filter to the list */
2350 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002351 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002352 else
2353 hlist_add_head(&input->fdir_node,
2354 &pf->fdir_filter_list);
2355
2356 /* update counts */
2357 pf->fdir_pf_active_filters++;
2358
2359 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002360}
2361
2362/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002363 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2364 * @vsi: Pointer to the targeted VSI
2365 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002366 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002367 * The function removes a Flow Director filter entry from the
2368 * hlist of the corresponding PF
2369 *
2370 * Returns 0 on success
2371 */
2372static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2373 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002374{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002375 struct ethtool_rx_flow_spec *fsp =
2376 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002377 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002378 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002379
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002380 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2381 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2382 return -EBUSY;
2383
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002384 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2385 return -EBUSY;
2386
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002387 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002388
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002389 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002390 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002391}
2392
2393/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002394 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002395 * @vsi: pointer to the targeted VSI
2396 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002397 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002398 * Add Flow Director filters for a specific flow spec based on their
2399 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002400 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002401static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2402 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002403{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002404 struct ethtool_rx_flow_spec *fsp;
2405 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002406 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002407 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002408 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002409
2410 if (!vsi)
2411 return -EINVAL;
2412
2413 pf = vsi->back;
2414
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002415 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2416 return -EOPNOTSUPP;
2417
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002418 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002419 return -ENOSPC;
2420
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002421 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2422 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2423 return -EBUSY;
2424
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002425 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2426 return -EBUSY;
2427
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002428 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2429
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002430 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2431 pf->hw.func_caps.fd_filters_guaranteed)) {
2432 return -EINVAL;
2433 }
2434
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002435 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2436 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002437 return -EINVAL;
2438
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002439 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002440
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002441 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002442 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002443
2444 input->fd_id = fsp->location;
2445
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002446 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2447 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2448 else
2449 input->dest_ctl =
2450 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2451
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002452 input->q_index = fsp->ring_cookie;
2453 input->flex_off = 0;
2454 input->pctype = 0;
2455 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002456 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002457 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002458 input->flow_type = fsp->flow_type;
2459 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002460
2461 /* Reverse the src and dest notion, since the HW expects them to be from
2462 * Tx perspective where as the input from user is from Rx filter view.
2463 */
2464 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2465 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2466 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2467 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002468
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002469 if (ntohl(fsp->m_ext.data[1])) {
2470 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2471 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2472 goto free_input;
2473 }
2474 vf_id = ntohl(fsp->h_ext.data[1]);
2475 /* Find vsi id from vf id and override dest vsi */
2476 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2477 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2478 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2479 goto free_input;
2480 }
2481 }
2482
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002483 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002484free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002485 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002486 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002487 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002488 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002489
2490 return ret;
2491}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002492
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002493/**
2494 * i40e_set_rxnfc - command to set RX flow classification rules
2495 * @netdev: network interface device structure
2496 * @cmd: ethtool rxnfc command
2497 *
2498 * Returns Success if the command is supported.
2499 **/
2500static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2501{
2502 struct i40e_netdev_priv *np = netdev_priv(netdev);
2503 struct i40e_vsi *vsi = np->vsi;
2504 struct i40e_pf *pf = vsi->back;
2505 int ret = -EOPNOTSUPP;
2506
2507 switch (cmd->cmd) {
2508 case ETHTOOL_SRXFH:
2509 ret = i40e_set_rss_hash_opt(pf, cmd);
2510 break;
2511 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002512 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002513 break;
2514 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002515 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002516 break;
2517 default:
2518 break;
2519 }
2520
2521 return ret;
2522}
2523
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002524/**
2525 * i40e_max_channels - get Max number of combined channels supported
2526 * @vsi: vsi pointer
2527 **/
2528static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2529{
2530 /* TODO: This code assumes DCB and FD is disabled for now. */
2531 return vsi->alloc_queue_pairs;
2532}
2533
2534/**
2535 * i40e_get_channels - Get the current channels enabled and max supported etc.
2536 * @netdev: network interface device structure
2537 * @ch: ethtool channels structure
2538 *
2539 * We don't support separate tx and rx queues as channels. The other count
2540 * represents how many queues are being used for control. max_combined counts
2541 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2542 * q_vectors since we support a lot more queue pairs than q_vectors.
2543 **/
2544static void i40e_get_channels(struct net_device *dev,
2545 struct ethtool_channels *ch)
2546{
2547 struct i40e_netdev_priv *np = netdev_priv(dev);
2548 struct i40e_vsi *vsi = np->vsi;
2549 struct i40e_pf *pf = vsi->back;
2550
2551 /* report maximum channels */
2552 ch->max_combined = i40e_max_channels(vsi);
2553
2554 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002555 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002556 ch->max_other = ch->other_count;
2557
2558 /* Note: This code assumes DCB is disabled for now. */
2559 ch->combined_count = vsi->num_queue_pairs;
2560}
2561
2562/**
2563 * i40e_set_channels - Set the new channels count.
2564 * @netdev: network interface device structure
2565 * @ch: ethtool channels structure
2566 *
2567 * The new channels count may not be the same as requested by the user
2568 * since it gets rounded down to a power of 2 value.
2569 **/
2570static int i40e_set_channels(struct net_device *dev,
2571 struct ethtool_channels *ch)
2572{
2573 struct i40e_netdev_priv *np = netdev_priv(dev);
2574 unsigned int count = ch->combined_count;
2575 struct i40e_vsi *vsi = np->vsi;
2576 struct i40e_pf *pf = vsi->back;
2577 int new_count;
2578
2579 /* We do not support setting channels for any other VSI at present */
2580 if (vsi->type != I40E_VSI_MAIN)
2581 return -EINVAL;
2582
2583 /* verify they are not requesting separate vectors */
2584 if (!count || ch->rx_count || ch->tx_count)
2585 return -EINVAL;
2586
2587 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002588 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002589 return -EINVAL;
2590
2591 /* verify the number of channels does not exceed hardware limits */
2592 if (count > i40e_max_channels(vsi))
2593 return -EINVAL;
2594
2595 /* update feature limits from largest to smallest supported values */
2596 /* TODO: Flow director limit, DCB etc */
2597
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002598 /* use rss_reconfig to rebuild with new queue count and update traffic
2599 * class queue mapping
2600 */
2601 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002602 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002603 return 0;
2604 else
2605 return -EINVAL;
2606}
2607
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002608/**
2609 * i40e_get_rxfh_key_size - get the RSS hash key size
2610 * @netdev: network interface device structure
2611 *
2612 * Returns the table size.
2613 **/
2614static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2615{
2616 return I40E_HKEY_ARRAY_SIZE;
2617}
2618
2619/**
2620 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2621 * @netdev: network interface device structure
2622 *
2623 * Returns the table size.
2624 **/
2625static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2626{
2627 return I40E_HLUT_ARRAY_SIZE;
2628}
2629
2630static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2631 u8 *hfunc)
2632{
2633 struct i40e_netdev_priv *np = netdev_priv(netdev);
2634 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002635 u8 *lut, *seed = NULL;
2636 int ret;
2637 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002638
2639 if (hfunc)
2640 *hfunc = ETH_RSS_HASH_TOP;
2641
2642 if (!indir)
2643 return 0;
2644
Helin Zhang043dd652015-10-21 19:56:23 -04002645 seed = key;
2646 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2647 if (!lut)
2648 return -ENOMEM;
2649 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2650 if (ret)
2651 goto out;
2652 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2653 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002654
Helin Zhang043dd652015-10-21 19:56:23 -04002655out:
2656 kfree(lut);
2657
2658 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002659}
2660
2661/**
2662 * i40e_set_rxfh - set the rx flow hash indirection table
2663 * @netdev: network interface device structure
2664 * @indir: indirection table
2665 * @key: hash key
2666 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002667 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002668 * returns 0 after programming the table.
2669 **/
2670static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2671 const u8 *key, const u8 hfunc)
2672{
2673 struct i40e_netdev_priv *np = netdev_priv(netdev);
2674 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002675 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002676 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002677
2678 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2679 return -EOPNOTSUPP;
2680
2681 if (!indir)
2682 return 0;
2683
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002684 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002685 if (!vsi->rss_hkey_user) {
2686 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2687 GFP_KERNEL);
2688 if (!vsi->rss_hkey_user)
2689 return -ENOMEM;
2690 }
2691 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2692 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002693 }
Helin Zhang28c58692015-10-26 19:44:27 -04002694 if (!vsi->rss_lut_user) {
2695 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2696 if (!vsi->rss_lut_user)
2697 return -ENOMEM;
2698 }
Helin Zhang043dd652015-10-21 19:56:23 -04002699
Helin Zhang28c58692015-10-26 19:44:27 -04002700 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2701 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2702 vsi->rss_lut_user[i] = (u8)(indir[i]);
2703
2704 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2705 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002706}
2707
Greg Rose7e45ab42015-02-06 08:52:19 +00002708/**
2709 * i40e_get_priv_flags - report device private flags
2710 * @dev: network interface device structure
2711 *
2712 * The get string set count and the string set should be matched for each
2713 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2714 * array.
2715 *
2716 * Returns a u32 bitmap of flags.
2717 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002718static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002719{
2720 struct i40e_netdev_priv *np = netdev_priv(dev);
2721 struct i40e_vsi *vsi = np->vsi;
2722 struct i40e_pf *pf = vsi->back;
2723 u32 ret_flags = 0;
2724
2725 ret_flags |= pf->hw.func_caps.npar_enable ?
2726 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002727 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2728 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002729 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2730 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002731 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2732 I40E_PRIV_FLAGS_VEB_STATS : 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002733 ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
2734 I40E_PRIV_FLAGS_PS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002735 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
2736 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Greg Rose7e45ab42015-02-06 08:52:19 +00002737
2738 return ret_flags;
2739}
2740
Shannon Nelson9ac77262015-08-27 11:42:40 -04002741/**
2742 * i40e_set_priv_flags - set private flags
2743 * @dev: network interface device structure
2744 * @flags: bit flags to be set
2745 **/
2746static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2747{
2748 struct i40e_netdev_priv *np = netdev_priv(dev);
2749 struct i40e_vsi *vsi = np->vsi;
2750 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002751 bool reset_required = false;
2752
2753 /* NOTE: MFP is not settable */
2754
2755 /* allow the user to control the method of receive
2756 * buffer DMA, whether the packet is split at header
2757 * boundaries into two separate buffers. In some cases
2758 * one routine or the other will perform better.
2759 */
2760 if ((flags & I40E_PRIV_FLAGS_PS) &&
2761 !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2762 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
2763 pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
2764 reset_required = true;
2765 } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
2766 (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2767 pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
2768 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
2769 reset_required = true;
2770 }
Shannon Nelson9ac77262015-08-27 11:42:40 -04002771
2772 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2773 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2774 else
2775 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2776
Jesse Brandeburgef171782015-09-03 17:18:49 -04002777 /* allow the user to control the state of the Flow
2778 * Director ATR (Application Targeted Routing) feature
2779 * of the driver
2780 */
2781 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2782 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2783 } else {
2784 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2785 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2786 }
2787
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002788 if (flags & I40E_PRIV_FLAGS_VEB_STATS)
2789 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2790 else
2791 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2792
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002793 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
2794 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
2795 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2796 else
2797 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2798
Jesse Brandeburg827de392015-11-06 15:26:07 -08002799 /* if needed, issue reset to cause things to take effect */
2800 if (reset_required)
2801 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2802
Shannon Nelson9ac77262015-08-27 11:42:40 -04002803 return 0;
2804}
2805
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002806static const struct ethtool_ops i40e_ethtool_ops = {
2807 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002808 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002809 .get_drvinfo = i40e_get_drvinfo,
2810 .get_regs_len = i40e_get_regs_len,
2811 .get_regs = i40e_get_regs,
2812 .nway_reset = i40e_nway_reset,
2813 .get_link = ethtool_op_get_link,
2814 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002815 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002816 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002817 .get_eeprom_len = i40e_get_eeprom_len,
2818 .get_eeprom = i40e_get_eeprom,
2819 .get_ringparam = i40e_get_ringparam,
2820 .set_ringparam = i40e_set_ringparam,
2821 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002822 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002823 .get_msglevel = i40e_get_msglevel,
2824 .set_msglevel = i40e_set_msglevel,
2825 .get_rxnfc = i40e_get_rxnfc,
2826 .set_rxnfc = i40e_set_rxnfc,
2827 .self_test = i40e_diag_test,
2828 .get_strings = i40e_get_strings,
2829 .set_phys_id = i40e_set_phys_id,
2830 .get_sset_count = i40e_get_sset_count,
2831 .get_ethtool_stats = i40e_get_ethtool_stats,
2832 .get_coalesce = i40e_get_coalesce,
2833 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002834 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2835 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2836 .get_rxfh = i40e_get_rxfh,
2837 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002838 .get_channels = i40e_get_channels,
2839 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002840 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002841 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002842 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002843};
2844
2845void i40e_set_ethtool_ops(struct net_device *netdev)
2846{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002847 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002848}