blob: 767b1db1005f57b1beb7982126f1dcba4e87820a [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),
Shannon Nelson41a9e552014-04-23 04:50:20 +000091};
92
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000093/* These PF_STATs might look like duplicates of some NETDEV_STATs,
94 * but they are separate. This device supports Virtualization, and
95 * as such might have several netdevs supporting VMDq and FCoE going
96 * through a single port. The NETDEV_STATs are for individual netdevs
97 * seen at the top of the stack, and the PF_STATs are for the physical
98 * function at the bottom of the stack hosting those netdevs.
99 *
100 * The PF_STATs are appended to the netdev stats only when ethtool -S
101 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
102 */
103static struct i40e_stats i40e_gstrings_stats[] = {
104 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
105 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000106 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
107 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
108 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
109 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
110 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
111 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000112 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
113 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000114 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400115 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
117 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
118 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000119 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000120 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000121 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
122 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
123 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
124 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
125 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
126 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
127 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
128 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
129 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
130 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
131 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
132 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
133 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
134 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
135 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
136 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
137 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
138 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
139 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
140 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
141 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
142 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
143 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
144 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000145 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000146 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000147 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400148 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400149 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400151 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000153 /* LPI stats */
154 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
155 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
156 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
157 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000158};
159
Vasu Dev38e00432014-08-01 13:27:03 -0700160#ifdef I40E_FCOE
161static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
162 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
163 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
164 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
165 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
166 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
167 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
168 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
169 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
170};
171
172#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000173#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000174 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
175 * 2 /* Tx and Rx together */ \
176 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000177#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
178#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000179#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700180#ifdef I40E_FCOE
181#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
182#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
183 I40E_FCOE_STATS_LEN + \
184 I40E_MISC_STATS_LEN + \
185 I40E_QUEUE_STATS_LEN((n)))
186#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000188 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700190#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191#define I40E_PFC_STATS_LEN ( \
192 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
197 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400198#define I40E_VEB_TC_STATS_LEN ( \
199 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
200 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
201 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
203 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000204#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400205#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000206#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
207 I40E_PFC_STATS_LEN + \
208 I40E_VSI_STATS_LEN((n)))
209
210enum i40e_ethtool_test_id {
211 I40E_ETH_TEST_REG = 0,
212 I40E_ETH_TEST_EEPROM,
213 I40E_ETH_TEST_INTR,
214 I40E_ETH_TEST_LOOPBACK,
215 I40E_ETH_TEST_LINK,
216};
217
218static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
219 "Register test (offline)",
220 "Eeprom test (offline)",
221 "Interrupt test (offline)",
222 "Loopback test (offline)",
223 "Link test (on/offline)"
224};
225
226#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
227
Greg Rose7e45ab42015-02-06 08:52:19 +0000228static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
229 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400230 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400231 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400232 "veb-stats",
Greg Rose7e45ab42015-02-06 08:52:19 +0000233};
234
Shannon Nelson9ac77262015-08-27 11:42:40 -0400235#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000236
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000237/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000238 * i40e_partition_setting_complaint - generic complaint for MFP restriction
239 * @pf: the PF struct
240 **/
241static void i40e_partition_setting_complaint(struct i40e_pf *pf)
242{
243 dev_info(&pf->pdev->dev,
244 "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");
245}
246
247/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000248 * i40e_get_settings_link_up - Get the Link settings for when link is up
249 * @hw: hw structure
250 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000254static void i40e_get_settings_link_up(struct i40e_hw *hw,
255 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400256 struct net_device *netdev,
257 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260 u32 link_speed = hw_link_info->link_speed;
261
Catherine Sullivane8278452015-02-06 08:52:08 +0000262 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000263 switch (hw_link_info->phy_type) {
264 case I40E_PHY_TYPE_40GBASE_CR4:
265 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000266 ecmd->supported = SUPPORTED_Autoneg |
267 SUPPORTED_40000baseCR4_Full;
268 ecmd->advertising = ADVERTISED_Autoneg |
269 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000270 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000271 case I40E_PHY_TYPE_XLAUI:
272 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000273 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000274 ecmd->supported = SUPPORTED_40000baseCR4_Full;
275 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 case I40E_PHY_TYPE_40GBASE_SR4:
277 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000278 break;
279 case I40E_PHY_TYPE_40GBASE_LR4:
280 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000281 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000282 case I40E_PHY_TYPE_10GBASE_SR:
283 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000284 case I40E_PHY_TYPE_1000BASE_SX:
285 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400286 ecmd->supported = SUPPORTED_10000baseT_Full;
287 if (hw_link_info->module_type[2] &
288 I40E_MODULE_TYPE_1000BASE_SX ||
289 hw_link_info->module_type[2] &
290 I40E_MODULE_TYPE_1000BASE_LX) {
291 ecmd->supported |= SUPPORTED_1000baseT_Full;
292 if (hw_link_info->requested_speeds &
293 I40E_LINK_SPEED_1GB)
294 ecmd->advertising |= ADVERTISED_1000baseT_Full;
295 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000296 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
297 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000298 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000299 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000300 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000302 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400303 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000304 ecmd->advertising = ADVERTISED_Autoneg;
305 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
306 ecmd->advertising |= ADVERTISED_10000baseT_Full;
307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
308 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400309 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400310 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
311 ecmd->supported = SUPPORTED_Autoneg |
312 SUPPORTED_1000baseT_Full;
313 ecmd->advertising = ADVERTISED_Autoneg |
314 ADVERTISED_1000baseT_Full;
315 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400316 case I40E_PHY_TYPE_100BASE_TX:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000319 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
320 ecmd->advertising |= ADVERTISED_100baseT_Full;
321 break;
322 case I40E_PHY_TYPE_10GBASE_CR1_CU:
323 case I40E_PHY_TYPE_10GBASE_CR1:
324 ecmd->supported = SUPPORTED_Autoneg |
325 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000326 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000327 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000328 break;
329 case I40E_PHY_TYPE_XAUI:
330 case I40E_PHY_TYPE_XFI:
331 case I40E_PHY_TYPE_SFI:
332 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000333 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000334 ecmd->supported = SUPPORTED_10000baseT_Full;
335 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336 case I40E_PHY_TYPE_SGMII:
337 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400338 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000339 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
340 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400341 if (pf->hw.mac.type == I40E_MAC_X722) {
342 ecmd->supported |= SUPPORTED_100baseT_Full;
343 if (hw_link_info->requested_speeds &
344 I40E_LINK_SPEED_100MB)
345 ecmd->advertising |= ADVERTISED_100baseT_Full;
346 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000347 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400348 /* Backplane is set based on supported phy types in get_settings
349 * so don't set anything here but don't warn either
350 */
351 case I40E_PHY_TYPE_40GBASE_KR4:
352 case I40E_PHY_TYPE_20GBASE_KR2:
353 case I40E_PHY_TYPE_10GBASE_KR:
354 case I40E_PHY_TYPE_10GBASE_KX4:
355 case I40E_PHY_TYPE_1000BASE_KX:
356 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000357 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000358 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000359 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
360 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000361 }
362
Catherine Sullivane8278452015-02-06 08:52:08 +0000363 /* Set speed and duplex */
364 switch (link_speed) {
365 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400366 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000367 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700368 case I40E_LINK_SPEED_20GB:
369 ethtool_cmd_speed_set(ecmd, SPEED_20000);
370 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000371 case I40E_LINK_SPEED_10GB:
372 ethtool_cmd_speed_set(ecmd, SPEED_10000);
373 break;
374 case I40E_LINK_SPEED_1GB:
375 ethtool_cmd_speed_set(ecmd, SPEED_1000);
376 break;
377 case I40E_LINK_SPEED_100MB:
378 ethtool_cmd_speed_set(ecmd, SPEED_100);
379 break;
380 default:
381 break;
382 }
383 ecmd->duplex = DUPLEX_FULL;
384}
385
386/**
387 * i40e_get_settings_link_down - Get the Link settings for when link is down
388 * @hw: hw structure
389 * @ecmd: ethtool command to fill in
390 *
391 * Reports link settings that can be determined when link is down
392 **/
393static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400394 struct ethtool_cmd *ecmd,
395 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000396{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400397 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000398
399 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400400 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000401 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400402 ecmd->supported = 0x0;
403 ecmd->advertising = 0x0;
404 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
405 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400406 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400407 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400408 ADVERTISED_1000baseT_Full;
409 if (pf->hw.mac.type == I40E_MAC_X722) {
410 ecmd->supported |= SUPPORTED_100baseT_Full;
411 ecmd->advertising |= ADVERTISED_100baseT_Full;
412 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000413 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400414 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
415 phy_types & I40E_CAP_PHY_TYPE_XFI ||
416 phy_types & I40E_CAP_PHY_TYPE_SFI ||
417 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
418 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
419 ecmd->supported |= SUPPORTED_10000baseT_Full;
420 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
421 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
422 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
423 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
424 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
425 ecmd->supported |= SUPPORTED_Autoneg |
426 SUPPORTED_10000baseT_Full;
427 ecmd->advertising |= ADVERTISED_Autoneg |
428 ADVERTISED_10000baseT_Full;
429 }
430 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
431 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
432 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
433 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
434 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
435 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
436 ecmd->supported |= SUPPORTED_Autoneg |
437 SUPPORTED_40000baseCR4_Full;
438 ecmd->advertising |= ADVERTISED_Autoneg |
439 ADVERTISED_40000baseCR4_Full;
440 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400441 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
442 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400443 ecmd->supported |= SUPPORTED_Autoneg |
444 SUPPORTED_100baseT_Full;
445 ecmd->advertising |= ADVERTISED_Autoneg |
446 ADVERTISED_100baseT_Full;
447 }
448 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
449 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
450 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
451 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
452 ecmd->supported |= SUPPORTED_Autoneg |
453 SUPPORTED_1000baseT_Full;
454 ecmd->advertising |= ADVERTISED_Autoneg |
455 ADVERTISED_1000baseT_Full;
456 }
457 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
458 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
459 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
460 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000461
462 /* With no link speed and duplex are unknown */
463 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
464 ecmd->duplex = DUPLEX_UNKNOWN;
465}
466
467/**
468 * i40e_get_settings - Get Link Speed and Duplex settings
469 * @netdev: network interface device structure
470 * @ecmd: ethtool command
471 *
472 * Reports speed/duplex settings based on media_type
473 **/
474static int i40e_get_settings(struct net_device *netdev,
475 struct ethtool_cmd *ecmd)
476{
477 struct i40e_netdev_priv *np = netdev_priv(netdev);
478 struct i40e_pf *pf = np->vsi->back;
479 struct i40e_hw *hw = &pf->hw;
480 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
481 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
482
483 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400484 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000485 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400486 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000487
488 /* Now set the settings that don't rely on link being up/down */
489
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400490 /* For backplane, supported and advertised are only reliant on the
491 * phy types the NVM specifies are supported.
492 */
493 if (hw->device_id == I40E_DEV_ID_KX_B ||
494 hw->device_id == I40E_DEV_ID_KX_C ||
495 hw->device_id == I40E_DEV_ID_20G_KR2 ||
496 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
497 ecmd->supported = SUPPORTED_Autoneg;
498 ecmd->advertising = ADVERTISED_Autoneg;
499 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
500 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
501 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
502 }
503 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
504 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
505 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
506 }
507 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
508 ecmd->supported |= SUPPORTED_10000baseKR_Full;
509 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
510 }
511 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
512 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
513 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
514 }
515 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
516 ecmd->supported |= SUPPORTED_1000baseKX_Full;
517 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
518 }
519 }
520
Catherine Sullivane8278452015-02-06 08:52:08 +0000521 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000522 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
523 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000524
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000525 switch (hw->phy.media_type) {
526 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000527 ecmd->supported |= SUPPORTED_Autoneg |
528 SUPPORTED_Backplane;
529 ecmd->advertising |= ADVERTISED_Autoneg |
530 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000531 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000532 break;
533 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000534 ecmd->supported |= SUPPORTED_TP;
535 ecmd->advertising |= ADVERTISED_TP;
536 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000537 break;
538 case I40E_MEDIA_TYPE_DA:
539 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000540 ecmd->supported |= SUPPORTED_FIBRE;
541 ecmd->advertising |= ADVERTISED_FIBRE;
542 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000543 break;
544 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000545 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000546 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000547 break;
548 case I40E_MEDIA_TYPE_UNKNOWN:
549 default:
550 ecmd->port = PORT_OTHER;
551 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000552 }
553
Catherine Sullivane8278452015-02-06 08:52:08 +0000554 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000555 ecmd->transceiver = XCVR_EXTERNAL;
556
Catherine Sullivane8278452015-02-06 08:52:08 +0000557 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000558 ecmd->supported |= SUPPORTED_Pause;
559
Catherine Sullivane8278452015-02-06 08:52:08 +0000560 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000561 case I40E_FC_FULL:
562 ecmd->advertising |= ADVERTISED_Pause;
563 break;
564 case I40E_FC_TX_PAUSE:
565 ecmd->advertising |= ADVERTISED_Asym_Pause;
566 break;
567 case I40E_FC_RX_PAUSE:
568 ecmd->advertising |= (ADVERTISED_Pause |
569 ADVERTISED_Asym_Pause);
570 break;
571 default:
572 ecmd->advertising &= ~(ADVERTISED_Pause |
573 ADVERTISED_Asym_Pause);
574 break;
575 }
576
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000577 return 0;
578}
579
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000580/**
581 * i40e_set_settings - Set Speed and Duplex
582 * @netdev: network interface device structure
583 * @ecmd: ethtool command
584 *
585 * Set speed/duplex per media_types advertised/forced
586 **/
587static int i40e_set_settings(struct net_device *netdev,
588 struct ethtool_cmd *ecmd)
589{
590 struct i40e_netdev_priv *np = netdev_priv(netdev);
591 struct i40e_aq_get_phy_abilities_resp abilities;
592 struct i40e_aq_set_phy_config config;
593 struct i40e_pf *pf = np->vsi->back;
594 struct i40e_vsi *vsi = np->vsi;
595 struct i40e_hw *hw = &pf->hw;
596 struct ethtool_cmd safe_ecmd;
597 i40e_status status = 0;
598 bool change = false;
599 int err = 0;
600 u8 autoneg;
601 u32 advertise;
602
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000603 /* Changing port settings is not supported if this isn't the
604 * port's controlling PF
605 */
606 if (hw->partition_id != 1) {
607 i40e_partition_setting_complaint(pf);
608 return -EOPNOTSUPP;
609 }
610
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000611 if (vsi != pf->vsi[pf->lan_vsi])
612 return -EOPNOTSUPP;
613
614 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
615 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000616 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
617 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000618 return -EOPNOTSUPP;
619
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400620 if (hw->device_id == I40E_DEV_ID_KX_B ||
621 hw->device_id == I40E_DEV_ID_KX_C ||
622 hw->device_id == I40E_DEV_ID_20G_KR2 ||
623 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
624 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
625 return -EOPNOTSUPP;
626 }
627
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000628 /* get our own copy of the bits to check against */
629 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
630 i40e_get_settings(netdev, &safe_ecmd);
631
632 /* save autoneg and speed out of ecmd */
633 autoneg = ecmd->autoneg;
634 advertise = ecmd->advertising;
635
636 /* set autoneg and speed back to what they currently are */
637 ecmd->autoneg = safe_ecmd.autoneg;
638 ecmd->advertising = safe_ecmd.advertising;
639
640 ecmd->cmd = safe_ecmd.cmd;
641 /* If ecmd and safe_ecmd are not the same now, then they are
642 * trying to set something that we do not support
643 */
644 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
645 return -EOPNOTSUPP;
646
647 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
648 usleep_range(1000, 2000);
649
650 /* Get the current phy config */
651 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
652 NULL);
653 if (status)
654 return -EAGAIN;
655
Catherine Sullivan124ed152014-07-12 07:28:12 +0000656 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000657 * set below
658 */
659 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000660 config.abilities = abilities.abilities;
661
662 /* Check autoneg */
663 if (autoneg == AUTONEG_ENABLE) {
664 /* If autoneg is not supported, return error */
665 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
666 netdev_info(netdev, "Autoneg not supported on this phy\n");
667 return -EINVAL;
668 }
669 /* If autoneg was not already enabled */
670 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
671 config.abilities = abilities.abilities |
672 I40E_AQ_PHY_ENABLE_AN;
673 change = true;
674 }
675 } else {
676 /* If autoneg is supported 10GBASE_T is the only phy that
677 * can disable it, so otherwise return error
678 */
679 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
680 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
681 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
682 return -EINVAL;
683 }
684 /* If autoneg is currently enabled */
685 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000686 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000687 ~I40E_AQ_PHY_ENABLE_AN;
688 change = true;
689 }
690 }
691
692 if (advertise & ~safe_ecmd.supported)
693 return -EINVAL;
694
695 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000696 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000697 if (advertise & ADVERTISED_1000baseT_Full ||
698 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000699 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000700 if (advertise & ADVERTISED_10000baseT_Full ||
701 advertise & ADVERTISED_10000baseKX4_Full ||
702 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000703 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700704 if (advertise & ADVERTISED_20000baseKR2_Full)
705 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000706 if (advertise & ADVERTISED_40000baseKR4_Full ||
707 advertise & ADVERTISED_40000baseCR4_Full ||
708 advertise & ADVERTISED_40000baseSR4_Full ||
709 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000710 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000711
Catherine Sullivan0002e112015-08-26 15:14:16 -0400712 /* If speed didn't get set, set it to what it currently is.
713 * This is needed because if advertise is 0 (as it is when autoneg
714 * is disabled) then speed won't get set.
715 */
716 if (!config.link_speed)
717 config.link_speed = abilities.link_speed;
718
Catherine Sullivan124ed152014-07-12 07:28:12 +0000719 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000720 /* copy over the rest of the abilities */
721 config.phy_type = abilities.phy_type;
722 config.eee_capability = abilities.eee_capability;
723 config.eeer = abilities.eeer_val;
724 config.low_power_ctrl = abilities.d3_lpan;
725
Catherine Sullivane8278452015-02-06 08:52:08 +0000726 /* save the requested speeds */
727 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000728 /* set link and auto negotiation so changes take effect */
729 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
730 /* If link is up put link down */
731 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
732 /* Tell the OS link is going down, the link will go
733 * back up when fw says it is ready asynchronously
734 */
Matt Jaredc156f852015-08-27 11:42:39 -0400735 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000736 netif_carrier_off(netdev);
737 netif_tx_stop_all_queues(netdev);
738 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000739
740 /* make the aq call */
741 status = i40e_aq_set_phy_config(hw, &config, NULL);
742 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400743 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
744 i40e_stat_str(hw, status),
745 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000746 return -EAGAIN;
747 }
748
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400749 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400751 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
752 i40e_stat_str(hw, status),
753 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000754
755 } else {
756 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
757 }
758
759 return err;
760}
761
Jesse Brandeburga6599722014-06-04 08:45:25 +0000762static int i40e_nway_reset(struct net_device *netdev)
763{
764 /* restart autonegotiation */
765 struct i40e_netdev_priv *np = netdev_priv(netdev);
766 struct i40e_pf *pf = np->vsi->back;
767 struct i40e_hw *hw = &pf->hw;
768 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
769 i40e_status ret = 0;
770
771 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
772 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400773 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
774 i40e_stat_str(hw, ret),
775 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000776 return -EIO;
777 }
778
779 return 0;
780}
781
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000782/**
783 * i40e_get_pauseparam - Get Flow Control status
784 * Return tx/rx-pause status
785 **/
786static void i40e_get_pauseparam(struct net_device *netdev,
787 struct ethtool_pauseparam *pause)
788{
789 struct i40e_netdev_priv *np = netdev_priv(netdev);
790 struct i40e_pf *pf = np->vsi->back;
791 struct i40e_hw *hw = &pf->hw;
792 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000793 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000794
795 pause->autoneg =
796 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
797 AUTONEG_ENABLE : AUTONEG_DISABLE);
798
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000799 /* PFC enabled so report LFC as off */
800 if (dcbx_cfg->pfc.pfcenable) {
801 pause->rx_pause = 0;
802 pause->tx_pause = 0;
803 return;
804 }
805
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000806 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000807 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000808 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000809 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000810 } else if (hw->fc.current_mode == I40E_FC_FULL) {
811 pause->rx_pause = 1;
812 pause->tx_pause = 1;
813 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000814}
815
Catherine Sullivan2becc352014-06-04 08:45:27 +0000816/**
817 * i40e_set_pauseparam - Set Flow Control parameter
818 * @netdev: network interface device structure
819 * @pause: return tx/rx flow control status
820 **/
821static int i40e_set_pauseparam(struct net_device *netdev,
822 struct ethtool_pauseparam *pause)
823{
824 struct i40e_netdev_priv *np = netdev_priv(netdev);
825 struct i40e_pf *pf = np->vsi->back;
826 struct i40e_vsi *vsi = np->vsi;
827 struct i40e_hw *hw = &pf->hw;
828 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000829 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000830 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
831 i40e_status status;
832 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000833 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000834
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000835 /* Changing the port's flow control is not supported if this isn't the
836 * port's controlling PF
837 */
838 if (hw->partition_id != 1) {
839 i40e_partition_setting_complaint(pf);
840 return -EOPNOTSUPP;
841 }
842
Catherine Sullivan2becc352014-06-04 08:45:27 +0000843 if (vsi != pf->vsi[pf->lan_vsi])
844 return -EOPNOTSUPP;
845
846 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
847 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
848 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
849 return -EOPNOTSUPP;
850 }
851
852 /* If we have link and don't have autoneg */
853 if (!test_bit(__I40E_DOWN, &pf->state) &&
854 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
855 /* Send message that it might not necessarily work*/
856 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
857 }
858
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000859 if (dcbx_cfg->pfc.pfcenable) {
860 netdev_info(netdev,
861 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000862 return -EOPNOTSUPP;
863 }
864
865 if (pause->rx_pause && pause->tx_pause)
866 hw->fc.requested_mode = I40E_FC_FULL;
867 else if (pause->rx_pause && !pause->tx_pause)
868 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
869 else if (!pause->rx_pause && pause->tx_pause)
870 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
871 else if (!pause->rx_pause && !pause->tx_pause)
872 hw->fc.requested_mode = I40E_FC_NONE;
873 else
874 return -EINVAL;
875
Catherine Sullivan94128512014-07-12 07:28:16 +0000876 /* Tell the OS link is going down, the link will go back up when fw
877 * says it is ready asynchronously
878 */
Matt Jaredc156f852015-08-27 11:42:39 -0400879 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000880 netif_carrier_off(netdev);
881 netif_tx_stop_all_queues(netdev);
882
Catherine Sullivan2becc352014-06-04 08:45:27 +0000883 /* Set the fc mode and only restart an if link is up*/
884 status = i40e_set_fc(hw, &aq_failures, link_up);
885
886 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400887 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
888 i40e_stat_str(hw, status),
889 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000890 err = -EAGAIN;
891 }
892 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400893 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
894 i40e_stat_str(hw, status),
895 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000896 err = -EAGAIN;
897 }
898 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400899 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
900 i40e_stat_str(hw, status),
901 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000902 err = -EAGAIN;
903 }
904
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000905 if (!test_bit(__I40E_DOWN, &pf->state)) {
906 /* Give it a little more time to try to come back */
907 msleep(75);
908 if (!test_bit(__I40E_DOWN, &pf->state))
909 return i40e_nway_reset(netdev);
910 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000911
912 return err;
913}
914
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000915static u32 i40e_get_msglevel(struct net_device *netdev)
916{
917 struct i40e_netdev_priv *np = netdev_priv(netdev);
918 struct i40e_pf *pf = np->vsi->back;
919
920 return pf->msg_enable;
921}
922
923static void i40e_set_msglevel(struct net_device *netdev, u32 data)
924{
925 struct i40e_netdev_priv *np = netdev_priv(netdev);
926 struct i40e_pf *pf = np->vsi->back;
927
928 if (I40E_DEBUG_USER & data)
929 pf->hw.debug_mask = data;
930 pf->msg_enable = data;
931}
932
933static int i40e_get_regs_len(struct net_device *netdev)
934{
935 int reg_count = 0;
936 int i;
937
938 for (i = 0; i40e_reg_list[i].offset != 0; i++)
939 reg_count += i40e_reg_list[i].elements;
940
941 return reg_count * sizeof(u32);
942}
943
944static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
945 void *p)
946{
947 struct i40e_netdev_priv *np = netdev_priv(netdev);
948 struct i40e_pf *pf = np->vsi->back;
949 struct i40e_hw *hw = &pf->hw;
950 u32 *reg_buf = p;
951 int i, j, ri;
952 u32 reg;
953
954 /* Tell ethtool which driver-version-specific regs output we have.
955 *
956 * At some point, if we have ethtool doing special formatting of
957 * this data, it will rely on this version number to know how to
958 * interpret things. Hence, this needs to be updated if/when the
959 * diags register table is changed.
960 */
961 regs->version = 1;
962
963 /* loop through the diags reg table for what to print */
964 ri = 0;
965 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
966 for (j = 0; j < i40e_reg_list[i].elements; j++) {
967 reg = i40e_reg_list[i].offset
968 + (j * i40e_reg_list[i].stride);
969 reg_buf[ri++] = rd32(hw, reg);
970 }
971 }
972
973}
974
975static int i40e_get_eeprom(struct net_device *netdev,
976 struct ethtool_eeprom *eeprom, u8 *bytes)
977{
978 struct i40e_netdev_priv *np = netdev_priv(netdev);
979 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000980 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000981 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000982 u8 *eeprom_buff;
983 u16 i, sectors;
984 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000985 u32 magic;
986
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000987#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000988 if (eeprom->len == 0)
989 return -EINVAL;
990
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000991 /* check for NVMUpdate access method */
992 magic = hw->vendor_id | (hw->device_id << 16);
993 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000994 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000995 int errno;
996
997 /* make sure it is the right magic for NVMUpdate */
998 if ((eeprom->magic >> 16) != hw->device_id)
999 return -EINVAL;
1000
Shannon Nelsonc150a502014-11-13 08:23:13 +00001001 cmd = (struct i40e_nvm_access *)eeprom;
1002 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001003 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001004 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001005 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1006 ret_val, hw->aq.asq_last_status, errno,
1007 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1008 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001009
1010 return errno;
1011 }
1012
1013 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001014 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1015
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001016 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001017 if (!eeprom_buff)
1018 return -ENOMEM;
1019
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001020 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1021 if (ret_val) {
1022 dev_info(&pf->pdev->dev,
1023 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1024 ret_val, hw->aq.asq_last_status);
1025 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001026 }
1027
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001028 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1029 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1030 len = I40E_NVM_SECTOR_SIZE;
1031 last = false;
1032 for (i = 0; i < sectors; i++) {
1033 if (i == (sectors - 1)) {
1034 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1035 last = true;
1036 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001037 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1038 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001039 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001040 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001041 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001042 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001043 "read NVM failed, invalid offset 0x%x\n",
1044 offset);
1045 break;
1046 } else if (ret_val &&
1047 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1048 dev_info(&pf->pdev->dev,
1049 "read NVM failed, access, offset 0x%x\n",
1050 offset);
1051 break;
1052 } else if (ret_val) {
1053 dev_info(&pf->pdev->dev,
1054 "read NVM failed offset %d err=%d status=0x%x\n",
1055 offset, ret_val, hw->aq.asq_last_status);
1056 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001057 }
1058 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001059
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001060 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001061 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001062free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001064 return ret_val;
1065}
1066
1067static int i40e_get_eeprom_len(struct net_device *netdev)
1068{
1069 struct i40e_netdev_priv *np = netdev_priv(netdev);
1070 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001071 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001073 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1074 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1075 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1076 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001077 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001078 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001079}
1080
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001081static int i40e_set_eeprom(struct net_device *netdev,
1082 struct ethtool_eeprom *eeprom, u8 *bytes)
1083{
1084 struct i40e_netdev_priv *np = netdev_priv(netdev);
1085 struct i40e_hw *hw = &np->vsi->back->hw;
1086 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001087 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001088 int ret_val = 0;
1089 int errno;
1090 u32 magic;
1091
1092 /* normal ethtool set_eeprom is not supported */
1093 magic = hw->vendor_id | (hw->device_id << 16);
1094 if (eeprom->magic == magic)
1095 return -EOPNOTSUPP;
1096
1097 /* check for NVMUpdate access method */
1098 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1099 return -EINVAL;
1100
1101 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1102 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1103 return -EBUSY;
1104
Shannon Nelsonc150a502014-11-13 08:23:13 +00001105 cmd = (struct i40e_nvm_access *)eeprom;
1106 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001107 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001108 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001109 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1110 ret_val, hw->aq.asq_last_status, errno,
1111 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1112 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001113
1114 return errno;
1115}
1116
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001117static void i40e_get_drvinfo(struct net_device *netdev,
1118 struct ethtool_drvinfo *drvinfo)
1119{
1120 struct i40e_netdev_priv *np = netdev_priv(netdev);
1121 struct i40e_vsi *vsi = np->vsi;
1122 struct i40e_pf *pf = vsi->back;
1123
1124 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1125 strlcpy(drvinfo->version, i40e_driver_version_str,
1126 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001127 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001128 sizeof(drvinfo->fw_version));
1129 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1130 sizeof(drvinfo->bus_info));
1131}
1132
1133static void i40e_get_ringparam(struct net_device *netdev,
1134 struct ethtool_ringparam *ring)
1135{
1136 struct i40e_netdev_priv *np = netdev_priv(netdev);
1137 struct i40e_pf *pf = np->vsi->back;
1138 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1139
1140 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1141 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1142 ring->rx_mini_max_pending = 0;
1143 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001144 ring->rx_pending = vsi->rx_rings[0]->count;
1145 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001146 ring->rx_mini_pending = 0;
1147 ring->rx_jumbo_pending = 0;
1148}
1149
1150static int i40e_set_ringparam(struct net_device *netdev,
1151 struct ethtool_ringparam *ring)
1152{
1153 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1154 struct i40e_netdev_priv *np = netdev_priv(netdev);
1155 struct i40e_vsi *vsi = np->vsi;
1156 struct i40e_pf *pf = vsi->back;
1157 u32 new_rx_count, new_tx_count;
1158 int i, err = 0;
1159
1160 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1161 return -EINVAL;
1162
Shannon Nelson1fa18372013-11-20 10:03:08 +00001163 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1164 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1165 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1166 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1167 netdev_info(netdev,
1168 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1169 ring->tx_pending, ring->rx_pending,
1170 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1171 return -EINVAL;
1172 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001173
Shannon Nelson1fa18372013-11-20 10:03:08 +00001174 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1175 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001176
1177 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001178 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1179 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001180 return 0;
1181
1182 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1183 usleep_range(1000, 2000);
1184
1185 if (!netif_running(vsi->netdev)) {
1186 /* simple case - set for the next time the netdev is started */
1187 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001188 vsi->tx_rings[i]->count = new_tx_count;
1189 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001190 }
1191 goto done;
1192 }
1193
1194 /* We can't just free everything and then setup again,
1195 * because the ISRs in MSI-X mode get passed pointers
1196 * to the Tx and Rx ring structs.
1197 */
1198
1199 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001200 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001201 netdev_info(netdev,
1202 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001203 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001204 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1205 sizeof(struct i40e_ring), GFP_KERNEL);
1206 if (!tx_rings) {
1207 err = -ENOMEM;
1208 goto done;
1209 }
1210
1211 for (i = 0; i < vsi->num_queue_pairs; i++) {
1212 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001213 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001214 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001215 /* the desc and bi pointers will be reallocated in the
1216 * setup call
1217 */
1218 tx_rings[i].desc = NULL;
1219 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1221 if (err) {
1222 while (i) {
1223 i--;
1224 i40e_free_tx_resources(&tx_rings[i]);
1225 }
1226 kfree(tx_rings);
1227 tx_rings = NULL;
1228
1229 goto done;
1230 }
1231 }
1232 }
1233
1234 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001235 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001236 netdev_info(netdev,
1237 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001238 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001239 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1240 sizeof(struct i40e_ring), GFP_KERNEL);
1241 if (!rx_rings) {
1242 err = -ENOMEM;
1243 goto free_tx;
1244 }
1245
1246 for (i = 0; i < vsi->num_queue_pairs; i++) {
1247 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001248 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001249 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001250 /* the desc and bi pointers will be reallocated in the
1251 * setup call
1252 */
1253 rx_rings[i].desc = NULL;
1254 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001255 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1256 if (err) {
1257 while (i) {
1258 i--;
1259 i40e_free_rx_resources(&rx_rings[i]);
1260 }
1261 kfree(rx_rings);
1262 rx_rings = NULL;
1263
1264 goto free_tx;
1265 }
1266 }
1267 }
1268
1269 /* Bring interface down, copy in the new ring info,
1270 * then restore the interface
1271 */
1272 i40e_down(vsi);
1273
1274 if (tx_rings) {
1275 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001276 i40e_free_tx_resources(vsi->tx_rings[i]);
1277 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001278 }
1279 kfree(tx_rings);
1280 tx_rings = NULL;
1281 }
1282
1283 if (rx_rings) {
1284 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001285 i40e_free_rx_resources(vsi->rx_rings[i]);
1286 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001287 }
1288 kfree(rx_rings);
1289 rx_rings = NULL;
1290 }
1291
1292 i40e_up(vsi);
1293
1294free_tx:
1295 /* error cleanup if the Rx allocations failed after getting Tx */
1296 if (tx_rings) {
1297 for (i = 0; i < vsi->num_queue_pairs; i++)
1298 i40e_free_tx_resources(&tx_rings[i]);
1299 kfree(tx_rings);
1300 tx_rings = NULL;
1301 }
1302
1303done:
1304 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1305
1306 return err;
1307}
1308
1309static int i40e_get_sset_count(struct net_device *netdev, int sset)
1310{
1311 struct i40e_netdev_priv *np = netdev_priv(netdev);
1312 struct i40e_vsi *vsi = np->vsi;
1313 struct i40e_pf *pf = vsi->back;
1314
1315 switch (sset) {
1316 case ETH_SS_TEST:
1317 return I40E_TEST_LEN;
1318 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001319 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001320 int len = I40E_PF_STATS_LEN(netdev);
1321
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001322 if ((pf->lan_veb != I40E_NO_VEB) &&
1323 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001324 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001325 return len;
1326 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001327 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001328 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001329 case ETH_SS_PRIV_FLAGS:
1330 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 default:
1332 return -EOPNOTSUPP;
1333 }
1334}
1335
1336static void i40e_get_ethtool_stats(struct net_device *netdev,
1337 struct ethtool_stats *stats, u64 *data)
1338{
1339 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001340 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341 struct i40e_vsi *vsi = np->vsi;
1342 struct i40e_pf *pf = vsi->back;
1343 int i = 0;
1344 char *p;
1345 int j;
1346 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001347 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348
1349 i40e_update_stats(vsi);
1350
1351 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1352 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1353 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1354 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1355 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001356 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1357 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1358 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1359 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1360 }
Vasu Dev38e00432014-08-01 13:27:03 -07001361#ifdef I40E_FCOE
1362 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1363 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1364 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1365 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1366 }
1367#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001368 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001369 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001370 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001371
1372 if (!tx_ring)
1373 continue;
1374
1375 /* process Tx ring statistics */
1376 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001377 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001378 data[i] = tx_ring->stats.packets;
1379 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001380 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001381 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001382
1383 /* Rx ring is the 2nd half of the queue pair */
1384 rx_ring = &tx_ring[1];
1385 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001386 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001387 data[i] = rx_ring->stats.packets;
1388 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001389 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001390 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001391 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001392 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001393 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001394 return;
1395
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001396 if ((pf->lan_veb != I40E_NO_VEB) &&
1397 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001398 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001399
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001400 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1401 p = (char *)veb;
1402 p += i40e_gstrings_veb_stats[j].stat_offset;
1403 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1404 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001405 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001407 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1408 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1409 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1410 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1411 }
1412 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1413 data[i++] = pf->stats.priority_xon_tx[j];
1414 data[i++] = pf->stats.priority_xoff_tx[j];
1415 }
1416 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1417 data[i++] = pf->stats.priority_xon_rx[j];
1418 data[i++] = pf->stats.priority_xoff_rx[j];
1419 }
1420 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1421 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001422}
1423
1424static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1425 u8 *data)
1426{
1427 struct i40e_netdev_priv *np = netdev_priv(netdev);
1428 struct i40e_vsi *vsi = np->vsi;
1429 struct i40e_pf *pf = vsi->back;
1430 char *p = (char *)data;
1431 int i;
1432
1433 switch (stringset) {
1434 case ETH_SS_TEST:
1435 for (i = 0; i < I40E_TEST_LEN; i++) {
1436 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1437 data += ETH_GSTRING_LEN;
1438 }
1439 break;
1440 case ETH_SS_STATS:
1441 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1442 snprintf(p, ETH_GSTRING_LEN, "%s",
1443 i40e_gstrings_net_stats[i].stat_string);
1444 p += ETH_GSTRING_LEN;
1445 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001446 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1447 snprintf(p, ETH_GSTRING_LEN, "%s",
1448 i40e_gstrings_misc_stats[i].stat_string);
1449 p += ETH_GSTRING_LEN;
1450 }
Vasu Dev38e00432014-08-01 13:27:03 -07001451#ifdef I40E_FCOE
1452 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1453 snprintf(p, ETH_GSTRING_LEN, "%s",
1454 i40e_gstrings_fcoe_stats[i].stat_string);
1455 p += ETH_GSTRING_LEN;
1456 }
1457#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001458 for (i = 0; i < vsi->num_queue_pairs; i++) {
1459 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1460 p += ETH_GSTRING_LEN;
1461 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1462 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001463 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1464 p += ETH_GSTRING_LEN;
1465 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1466 p += ETH_GSTRING_LEN;
1467 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001468 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001469 return;
1470
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001471 if ((pf->lan_veb != I40E_NO_VEB) &&
1472 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001473 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1474 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1475 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001476 p += ETH_GSTRING_LEN;
1477 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001478 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1479 snprintf(p, ETH_GSTRING_LEN,
1480 "veb.tc_%u_tx_packets", i);
1481 p += ETH_GSTRING_LEN;
1482 snprintf(p, ETH_GSTRING_LEN,
1483 "veb.tc_%u_tx_bytes", i);
1484 p += ETH_GSTRING_LEN;
1485 snprintf(p, ETH_GSTRING_LEN,
1486 "veb.tc_%u_rx_packets", i);
1487 p += ETH_GSTRING_LEN;
1488 snprintf(p, ETH_GSTRING_LEN,
1489 "veb.tc_%u_rx_bytes", i);
1490 p += ETH_GSTRING_LEN;
1491 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001492 }
1493 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1494 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1495 i40e_gstrings_stats[i].stat_string);
1496 p += ETH_GSTRING_LEN;
1497 }
1498 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1499 snprintf(p, ETH_GSTRING_LEN,
1500 "port.tx_priority_%u_xon", i);
1501 p += ETH_GSTRING_LEN;
1502 snprintf(p, ETH_GSTRING_LEN,
1503 "port.tx_priority_%u_xoff", i);
1504 p += ETH_GSTRING_LEN;
1505 }
1506 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1507 snprintf(p, ETH_GSTRING_LEN,
1508 "port.rx_priority_%u_xon", i);
1509 p += ETH_GSTRING_LEN;
1510 snprintf(p, ETH_GSTRING_LEN,
1511 "port.rx_priority_%u_xoff", i);
1512 p += ETH_GSTRING_LEN;
1513 }
1514 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1515 snprintf(p, ETH_GSTRING_LEN,
1516 "port.rx_priority_%u_xon_2_xoff", i);
1517 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001518 }
1519 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1520 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001521 case ETH_SS_PRIV_FLAGS:
1522 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1523 memcpy(data, i40e_priv_flags_strings[i],
1524 ETH_GSTRING_LEN);
1525 data += ETH_GSTRING_LEN;
1526 }
1527 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001528 default:
1529 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001530 }
1531}
1532
1533static int i40e_get_ts_info(struct net_device *dev,
1534 struct ethtool_ts_info *info)
1535{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001536 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1537
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001538 /* only report HW timestamping if PTP is enabled */
1539 if (!(pf->flags & I40E_FLAG_PTP))
1540 return ethtool_op_get_ts_info(dev, info);
1541
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001542 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1543 SOF_TIMESTAMPING_RX_SOFTWARE |
1544 SOF_TIMESTAMPING_SOFTWARE |
1545 SOF_TIMESTAMPING_TX_HARDWARE |
1546 SOF_TIMESTAMPING_RX_HARDWARE |
1547 SOF_TIMESTAMPING_RAW_HARDWARE;
1548
1549 if (pf->ptp_clock)
1550 info->phc_index = ptp_clock_index(pf->ptp_clock);
1551 else
1552 info->phc_index = -1;
1553
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001554 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001555
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001556 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1557 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1558 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001559
1560 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001561}
1562
Shannon Nelson7b086392013-11-20 10:02:59 +00001563static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001564{
Shannon Nelson7b086392013-11-20 10:02:59 +00001565 struct i40e_netdev_priv *np = netdev_priv(netdev);
1566 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001567 i40e_status status;
1568 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001569
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001570 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001571 status = i40e_get_link_status(&pf->hw, &link_up);
1572 if (status) {
1573 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1574 *data = 1;
1575 return *data;
1576 }
1577
1578 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001579 *data = 0;
1580 else
1581 *data = 1;
1582
1583 return *data;
1584}
1585
Shannon Nelson7b086392013-11-20 10:02:59 +00001586static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001587{
Shannon Nelson7b086392013-11-20 10:02:59 +00001588 struct i40e_netdev_priv *np = netdev_priv(netdev);
1589 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001590
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001591 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001592 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593
Shannon Nelson7b086392013-11-20 10:02:59 +00001594 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595}
1596
Shannon Nelson7b086392013-11-20 10:02:59 +00001597static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001598{
Shannon Nelson7b086392013-11-20 10:02:59 +00001599 struct i40e_netdev_priv *np = netdev_priv(netdev);
1600 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001601
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001602 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001603 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001604
Shannon Nelson4443ec92014-11-13 08:23:12 +00001605 /* forcebly clear the NVM Update state machine */
1606 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1607
Shannon Nelson7b086392013-11-20 10:02:59 +00001608 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609}
1610
Shannon Nelson7b086392013-11-20 10:02:59 +00001611static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001612{
Shannon Nelson7b086392013-11-20 10:02:59 +00001613 struct i40e_netdev_priv *np = netdev_priv(netdev);
1614 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001615 u16 swc_old = pf->sw_int_count;
1616
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001617 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001618 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1619 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001620 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1621 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1622 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1623 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001624 usleep_range(1000, 2000);
1625 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001626
1627 return *data;
1628}
1629
Shannon Nelson7b086392013-11-20 10:02:59 +00001630static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001631{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001632 struct i40e_netdev_priv *np = netdev_priv(netdev);
1633 struct i40e_pf *pf = np->vsi->back;
1634
1635 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001636 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001637
1638 return *data;
1639}
1640
Greg Rosee17bc412015-04-16 20:05:59 -04001641static inline bool i40e_active_vfs(struct i40e_pf *pf)
1642{
1643 struct i40e_vf *vfs = pf->vf;
1644 int i;
1645
1646 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001647 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001648 return true;
1649 return false;
1650}
1651
Greg Rose510efb22015-07-10 19:36:01 -04001652static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1653{
1654 struct i40e_vsi **vsi = pf->vsi;
1655 int i;
1656
1657 for (i = 0; i < pf->num_alloc_vsi; i++) {
1658 if (!vsi[i])
1659 continue;
1660 if (vsi[i]->type == I40E_VSI_VMDQ2)
1661 return true;
1662 }
1663
1664 return false;
1665}
1666
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667static void i40e_diag_test(struct net_device *netdev,
1668 struct ethtool_test *eth_test, u64 *data)
1669{
1670 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001671 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001672 struct i40e_pf *pf = np->vsi->back;
1673
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001674 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1675 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001676 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001677
Shannon Nelsonf551b432013-11-26 10:49:12 +00001678 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001679
Greg Rose510efb22015-07-10 19:36:01 -04001680 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001681 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001682 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001683 data[I40E_ETH_TEST_REG] = 1;
1684 data[I40E_ETH_TEST_EEPROM] = 1;
1685 data[I40E_ETH_TEST_INTR] = 1;
1686 data[I40E_ETH_TEST_LOOPBACK] = 1;
1687 data[I40E_ETH_TEST_LINK] = 1;
1688 eth_test->flags |= ETH_TEST_FL_FAILED;
1689 clear_bit(__I40E_TESTING, &pf->state);
1690 goto skip_ol_tests;
1691 }
1692
Greg Rose5b86c5c2015-02-26 16:14:35 +00001693 /* If the device is online then take it offline */
1694 if (if_running)
1695 /* indicate we're in test mode */
1696 dev_close(netdev);
1697 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001698 /* This reset does not affect link - if it is
1699 * changed to a type of reset that does affect
1700 * link then the following link test would have
1701 * to be moved to before the reset
1702 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001703 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001704
Shannon Nelson7b086392013-11-20 10:02:59 +00001705 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001706 eth_test->flags |= ETH_TEST_FL_FAILED;
1707
Shannon Nelson7b086392013-11-20 10:02:59 +00001708 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001709 eth_test->flags |= ETH_TEST_FL_FAILED;
1710
Shannon Nelson7b086392013-11-20 10:02:59 +00001711 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712 eth_test->flags |= ETH_TEST_FL_FAILED;
1713
Shannon Nelson7b086392013-11-20 10:02:59 +00001714 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715 eth_test->flags |= ETH_TEST_FL_FAILED;
1716
Shannon Nelsonf551b432013-11-26 10:49:12 +00001717 /* run reg test last, a reset is required after it */
1718 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1719 eth_test->flags |= ETH_TEST_FL_FAILED;
1720
1721 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001722 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001723
1724 if (if_running)
1725 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001726 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001727 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001728 netif_info(pf, drv, netdev, "online testing starting\n");
1729
Shannon Nelson7b086392013-11-20 10:02:59 +00001730 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001731 eth_test->flags |= ETH_TEST_FL_FAILED;
1732
1733 /* Offline only tests, not run in online; pass by default */
1734 data[I40E_ETH_TEST_REG] = 0;
1735 data[I40E_ETH_TEST_EEPROM] = 0;
1736 data[I40E_ETH_TEST_INTR] = 0;
1737 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001738 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001739
Greg Rosee17bc412015-04-16 20:05:59 -04001740skip_ol_tests:
1741
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001742 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001743}
1744
1745static void i40e_get_wol(struct net_device *netdev,
1746 struct ethtool_wolinfo *wol)
1747{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001748 struct i40e_netdev_priv *np = netdev_priv(netdev);
1749 struct i40e_pf *pf = np->vsi->back;
1750 struct i40e_hw *hw = &pf->hw;
1751 u16 wol_nvm_bits;
1752
1753 /* NVM bit on means WoL disabled for the port */
1754 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001755 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001756 wol->supported = 0;
1757 wol->wolopts = 0;
1758 } else {
1759 wol->supported = WAKE_MAGIC;
1760 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1761 }
1762}
1763
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001764/**
1765 * i40e_set_wol - set the WakeOnLAN configuration
1766 * @netdev: the netdev in question
1767 * @wol: the ethtool WoL setting data
1768 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001769static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1770{
1771 struct i40e_netdev_priv *np = netdev_priv(netdev);
1772 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001773 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001774 struct i40e_hw *hw = &pf->hw;
1775 u16 wol_nvm_bits;
1776
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001777 /* WoL not supported if this isn't the controlling PF on the port */
1778 if (hw->partition_id != 1) {
1779 i40e_partition_setting_complaint(pf);
1780 return -EOPNOTSUPP;
1781 }
1782
1783 if (vsi != pf->vsi[pf->lan_vsi])
1784 return -EOPNOTSUPP;
1785
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001786 /* NVM bit on means WoL disabled for the port */
1787 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001788 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001789 return -EOPNOTSUPP;
1790
1791 /* only magic packet is supported */
1792 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1793 return -EOPNOTSUPP;
1794
1795 /* is this a new value? */
1796 if (pf->wol_en != !!wol->wolopts) {
1797 pf->wol_en = !!wol->wolopts;
1798 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1799 }
1800
1801 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001802}
1803
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001804static int i40e_set_phys_id(struct net_device *netdev,
1805 enum ethtool_phys_id_state state)
1806{
1807 struct i40e_netdev_priv *np = netdev_priv(netdev);
1808 struct i40e_pf *pf = np->vsi->back;
1809 struct i40e_hw *hw = &pf->hw;
1810 int blink_freq = 2;
1811
1812 switch (state) {
1813 case ETHTOOL_ID_ACTIVE:
1814 pf->led_status = i40e_led_get(hw);
1815 return blink_freq;
1816 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001817 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818 break;
1819 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001820 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001821 break;
1822 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001823 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001824 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001825 default:
1826 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001827 }
1828
1829 return 0;
1830}
1831
1832/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1833 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1834 * 125us (8000 interrupts per second) == ITR(62)
1835 */
1836
1837static int i40e_get_coalesce(struct net_device *netdev,
1838 struct ethtool_coalesce *ec)
1839{
1840 struct i40e_netdev_priv *np = netdev_priv(netdev);
1841 struct i40e_vsi *vsi = np->vsi;
1842
1843 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1844 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1845
1846 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001847 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001848
1849 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001850 ec->use_adaptive_tx_coalesce = 1;
1851
1852 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1853 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001854 /* we use the _usecs_high to store/set the interrupt rate limit
1855 * that the hardware supports, that almost but not quite
1856 * fits the original intent of the ethtool variable,
1857 * the rx_coalesce_usecs_high limits total interrupts
1858 * per second from both tx/rx sources.
1859 */
1860 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1861 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001862
1863 return 0;
1864}
1865
1866static int i40e_set_coalesce(struct net_device *netdev,
1867 struct ethtool_coalesce *ec)
1868{
1869 struct i40e_netdev_priv *np = netdev_priv(netdev);
1870 struct i40e_q_vector *q_vector;
1871 struct i40e_vsi *vsi = np->vsi;
1872 struct i40e_pf *pf = vsi->back;
1873 struct i40e_hw *hw = &pf->hw;
1874 u16 vector;
1875 int i;
1876
1877 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1878 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1879
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001880 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1881 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1882 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1883 return -EINVAL;
1884 }
1885
1886 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1887 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1888 return -EINVAL;
1889 }
1890
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001891 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001892 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001893 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001894 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001895 } else if (ec->rx_coalesce_usecs == 0) {
1896 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001897 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001898 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 +00001899 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001900 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001901 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001902 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001903
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001904 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1905
Mitch Williams32f5f542014-04-04 04:43:10 +00001906 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001907 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001908 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001909 } else if (ec->tx_coalesce_usecs == 0) {
1910 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001911 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001912 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 +00001913 } else {
1914 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001915 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001916 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001917 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001918
1919 if (ec->use_adaptive_rx_coalesce)
1920 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1921 else
1922 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1923
1924 if (ec->use_adaptive_tx_coalesce)
1925 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1926 else
1927 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001928
Alexander Duyck493fb302013-09-28 07:01:44 +00001929 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001930 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1931
Alexander Duyck493fb302013-09-28 07:01:44 +00001932 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001933 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1934 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1935 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1936 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001937 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001938 i40e_flush(hw);
1939 }
1940
1941 return 0;
1942}
1943
1944/**
1945 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1946 * @pf: pointer to the physical function struct
1947 * @cmd: ethtool rxnfc command
1948 *
1949 * Returns Success if the flow is supported, else Invalid Input.
1950 **/
1951static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1952{
1953 cmd->data = 0;
1954
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001955 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1956 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1957 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1958 return 0;
1959 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001960 /* Report default options for RSS on i40e */
1961 switch (cmd->flow_type) {
1962 case TCP_V4_FLOW:
1963 case UDP_V4_FLOW:
1964 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1965 /* fall through to add IP fields */
1966 case SCTP_V4_FLOW:
1967 case AH_ESP_V4_FLOW:
1968 case AH_V4_FLOW:
1969 case ESP_V4_FLOW:
1970 case IPV4_FLOW:
1971 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1972 break;
1973 case TCP_V6_FLOW:
1974 case UDP_V6_FLOW:
1975 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1976 /* fall through to add IP fields */
1977 case SCTP_V6_FLOW:
1978 case AH_ESP_V6_FLOW:
1979 case AH_V6_FLOW:
1980 case ESP_V6_FLOW:
1981 case IPV6_FLOW:
1982 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1983 break;
1984 default:
1985 return -EINVAL;
1986 }
1987
1988 return 0;
1989}
1990
1991/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001992 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1993 * @pf: Pointer to the physical function struct
1994 * @cmd: The command to get or set Rx flow classification rules
1995 * @rule_locs: Array of used rule locations
1996 *
1997 * This function populates both the total and actual rule count of
1998 * the ethtool flow classification command
1999 *
2000 * Returns 0 on success or -EMSGSIZE if entry not found
2001 **/
2002static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2003 struct ethtool_rxnfc *cmd,
2004 u32 *rule_locs)
2005{
2006 struct i40e_fdir_filter *rule;
2007 struct hlist_node *node2;
2008 int cnt = 0;
2009
2010 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002011 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002012
2013 hlist_for_each_entry_safe(rule, node2,
2014 &pf->fdir_filter_list, fdir_node) {
2015 if (cnt == cmd->rule_cnt)
2016 return -EMSGSIZE;
2017
2018 rule_locs[cnt] = rule->fd_id;
2019 cnt++;
2020 }
2021
2022 cmd->rule_cnt = cnt;
2023
2024 return 0;
2025}
2026
2027/**
2028 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2029 * @pf: Pointer to the physical function struct
2030 * @cmd: The command to get or set Rx flow classification rules
2031 *
2032 * This function looks up a filter based on the Rx flow classification
2033 * command and fills the flow spec info for it if found
2034 *
2035 * Returns 0 on success or -EINVAL if filter not found
2036 **/
2037static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2038 struct ethtool_rxnfc *cmd)
2039{
2040 struct ethtool_rx_flow_spec *fsp =
2041 (struct ethtool_rx_flow_spec *)&cmd->fs;
2042 struct i40e_fdir_filter *rule = NULL;
2043 struct hlist_node *node2;
2044
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002045 hlist_for_each_entry_safe(rule, node2,
2046 &pf->fdir_filter_list, fdir_node) {
2047 if (fsp->location <= rule->fd_id)
2048 break;
2049 }
2050
2051 if (!rule || fsp->location != rule->fd_id)
2052 return -EINVAL;
2053
2054 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002055 if (fsp->flow_type == IP_USER_FLOW) {
2056 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2057 fsp->h_u.usr_ip4_spec.proto = 0;
2058 fsp->m_u.usr_ip4_spec.proto = 0;
2059 }
2060
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002061 /* Reverse the src and dest notion, since the HW views them from
2062 * Tx perspective where as the user expects it from Rx filter view.
2063 */
2064 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2065 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2066 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2067 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002068
2069 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2070 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2071 else
2072 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002073
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002074 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2075 struct i40e_vsi *vsi;
2076
2077 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2078 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2079 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2080 fsp->m_ext.data[1] = htonl(0x1);
2081 }
2082 }
2083
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002084 return 0;
2085}
2086
2087/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002088 * i40e_get_rxnfc - command to get RX flow classification rules
2089 * @netdev: network interface device structure
2090 * @cmd: ethtool rxnfc command
2091 *
2092 * Returns Success if the command is supported.
2093 **/
2094static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2095 u32 *rule_locs)
2096{
2097 struct i40e_netdev_priv *np = netdev_priv(netdev);
2098 struct i40e_vsi *vsi = np->vsi;
2099 struct i40e_pf *pf = vsi->back;
2100 int ret = -EOPNOTSUPP;
2101
2102 switch (cmd->cmd) {
2103 case ETHTOOL_GRXRINGS:
2104 cmd->data = vsi->alloc_queue_pairs;
2105 ret = 0;
2106 break;
2107 case ETHTOOL_GRXFH:
2108 ret = i40e_get_rss_hash_opts(pf, cmd);
2109 break;
2110 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002111 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002112 /* report total rule count */
2113 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002114 ret = 0;
2115 break;
2116 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002117 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002118 break;
2119 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002120 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2121 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002122 default:
2123 break;
2124 }
2125
2126 return ret;
2127}
2128
2129/**
2130 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2131 * @pf: pointer to the physical function struct
2132 * @cmd: ethtool rxnfc command
2133 *
2134 * Returns Success if the flow input set is supported.
2135 **/
2136static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2137{
2138 struct i40e_hw *hw = &pf->hw;
2139 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2140 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2141
2142 /* RSS does not support anything other than hashing
2143 * to queues on src and dst IPs and ports
2144 */
2145 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2146 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2147 return -EINVAL;
2148
2149 /* We need at least the IP SRC and DEST fields for hashing */
2150 if (!(nfc->data & RXH_IP_SRC) ||
2151 !(nfc->data & RXH_IP_DST))
2152 return -EINVAL;
2153
2154 switch (nfc->flow_type) {
2155 case TCP_V4_FLOW:
2156 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2157 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002158 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002159 break;
2160 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002161 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002162 break;
2163 default:
2164 return -EINVAL;
2165 }
2166 break;
2167 case TCP_V6_FLOW:
2168 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2169 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002170 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002171 break;
2172 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002173 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002174 break;
2175 default:
2176 return -EINVAL;
2177 }
2178 break;
2179 case UDP_V4_FLOW:
2180 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2181 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002182 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2183 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 break;
2185 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002186 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2187 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002188 break;
2189 default:
2190 return -EINVAL;
2191 }
2192 break;
2193 case UDP_V6_FLOW:
2194 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2195 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002196 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2197 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198 break;
2199 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002200 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2201 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002202 break;
2203 default:
2204 return -EINVAL;
2205 }
2206 break;
2207 case AH_ESP_V4_FLOW:
2208 case AH_V4_FLOW:
2209 case ESP_V4_FLOW:
2210 case SCTP_V4_FLOW:
2211 if ((nfc->data & RXH_L4_B_0_1) ||
2212 (nfc->data & RXH_L4_B_2_3))
2213 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002214 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002215 break;
2216 case AH_ESP_V6_FLOW:
2217 case AH_V6_FLOW:
2218 case ESP_V6_FLOW:
2219 case SCTP_V6_FLOW:
2220 if ((nfc->data & RXH_L4_B_0_1) ||
2221 (nfc->data & RXH_L4_B_2_3))
2222 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002223 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002224 break;
2225 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002226 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2227 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002228 break;
2229 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002230 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2231 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232 break;
2233 default:
2234 return -EINVAL;
2235 }
2236
2237 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2238 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2239 i40e_flush(hw);
2240
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002241 /* Save setting for future output/update */
2242 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2243
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002244 return 0;
2245}
2246
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002247/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002248 * i40e_match_fdir_input_set - Match a new filter against an existing one
2249 * @rule: The filter already added
2250 * @input: The new filter to comapre against
2251 *
2252 * Returns true if the two input set match
2253 **/
2254static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2255 struct i40e_fdir_filter *input)
2256{
2257 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2258 (rule->src_ip[0] != input->src_ip[0]) ||
2259 (rule->dst_port != input->dst_port) ||
2260 (rule->src_port != input->src_port))
2261 return false;
2262 return true;
2263}
2264
2265/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002266 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2267 * @vsi: Pointer to the targeted VSI
2268 * @input: The filter to update or NULL to indicate deletion
2269 * @sw_idx: Software index to the filter
2270 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002271 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002272 * This function updates (or deletes) a Flow Director entry from
2273 * the hlist of the corresponding PF
2274 *
2275 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002276 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002277static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2278 struct i40e_fdir_filter *input,
2279 u16 sw_idx,
2280 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002282 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002283 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002284 struct hlist_node *node2;
2285 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002286
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002287 parent = NULL;
2288 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002289
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002290 hlist_for_each_entry_safe(rule, node2,
2291 &pf->fdir_filter_list, fdir_node) {
2292 /* hash found, or no matching entry */
2293 if (rule->fd_id >= sw_idx)
2294 break;
2295 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002296 }
2297
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002298 /* if there is an old rule occupying our place remove it */
2299 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002300 if (input && !i40e_match_fdir_input_set(rule, input))
2301 err = i40e_add_del_fdir(vsi, rule, false);
2302 else if (!input)
2303 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002304 hlist_del(&rule->fdir_node);
2305 kfree(rule);
2306 pf->fdir_pf_active_filters--;
2307 }
2308
2309 /* If no input this was a delete, err should be 0 if a rule was
2310 * successfully found and removed from the list else -EINVAL
2311 */
2312 if (!input)
2313 return err;
2314
2315 /* initialize node and set software index */
2316 INIT_HLIST_NODE(&input->fdir_node);
2317
2318 /* add filter to the list */
2319 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002320 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002321 else
2322 hlist_add_head(&input->fdir_node,
2323 &pf->fdir_filter_list);
2324
2325 /* update counts */
2326 pf->fdir_pf_active_filters++;
2327
2328 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002329}
2330
2331/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002332 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2333 * @vsi: Pointer to the targeted VSI
2334 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002335 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002336 * The function removes a Flow Director filter entry from the
2337 * hlist of the corresponding PF
2338 *
2339 * Returns 0 on success
2340 */
2341static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2342 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002343{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002344 struct ethtool_rx_flow_spec *fsp =
2345 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002346 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002347 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002348
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002349 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2350 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2351 return -EBUSY;
2352
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002353 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2354 return -EBUSY;
2355
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002356 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002357
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002358 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002359 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002360}
2361
2362/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002363 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002364 * @vsi: pointer to the targeted VSI
2365 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002366 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002367 * Add Flow Director filters for a specific flow spec based on their
2368 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002369 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002370static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2371 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002372{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002373 struct ethtool_rx_flow_spec *fsp;
2374 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002375 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002376 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002377 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002378
2379 if (!vsi)
2380 return -EINVAL;
2381
2382 pf = vsi->back;
2383
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002384 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2385 return -EOPNOTSUPP;
2386
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002387 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002388 return -ENOSPC;
2389
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002390 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2391 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2392 return -EBUSY;
2393
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002394 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2395 return -EBUSY;
2396
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002397 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2398
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002399 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2400 pf->hw.func_caps.fd_filters_guaranteed)) {
2401 return -EINVAL;
2402 }
2403
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002404 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2405 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002406 return -EINVAL;
2407
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002408 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002409
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002410 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002411 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002412
2413 input->fd_id = fsp->location;
2414
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002415 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2416 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2417 else
2418 input->dest_ctl =
2419 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2420
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002421 input->q_index = fsp->ring_cookie;
2422 input->flex_off = 0;
2423 input->pctype = 0;
2424 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002425 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002426 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002427 input->flow_type = fsp->flow_type;
2428 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002429
2430 /* Reverse the src and dest notion, since the HW expects them to be from
2431 * Tx perspective where as the input from user is from Rx filter view.
2432 */
2433 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2434 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2435 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2436 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002437
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002438 if (ntohl(fsp->m_ext.data[1])) {
2439 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2440 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2441 goto free_input;
2442 }
2443 vf_id = ntohl(fsp->h_ext.data[1]);
2444 /* Find vsi id from vf id and override dest vsi */
2445 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2446 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2447 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2448 goto free_input;
2449 }
2450 }
2451
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002452 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002453free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002454 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002455 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002456 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002457 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002458
2459 return ret;
2460}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002461
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002462/**
2463 * i40e_set_rxnfc - command to set RX flow classification rules
2464 * @netdev: network interface device structure
2465 * @cmd: ethtool rxnfc command
2466 *
2467 * Returns Success if the command is supported.
2468 **/
2469static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2470{
2471 struct i40e_netdev_priv *np = netdev_priv(netdev);
2472 struct i40e_vsi *vsi = np->vsi;
2473 struct i40e_pf *pf = vsi->back;
2474 int ret = -EOPNOTSUPP;
2475
2476 switch (cmd->cmd) {
2477 case ETHTOOL_SRXFH:
2478 ret = i40e_set_rss_hash_opt(pf, cmd);
2479 break;
2480 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002481 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002482 break;
2483 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002484 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002485 break;
2486 default:
2487 break;
2488 }
2489
2490 return ret;
2491}
2492
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002493/**
2494 * i40e_max_channels - get Max number of combined channels supported
2495 * @vsi: vsi pointer
2496 **/
2497static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2498{
2499 /* TODO: This code assumes DCB and FD is disabled for now. */
2500 return vsi->alloc_queue_pairs;
2501}
2502
2503/**
2504 * i40e_get_channels - Get the current channels enabled and max supported etc.
2505 * @netdev: network interface device structure
2506 * @ch: ethtool channels structure
2507 *
2508 * We don't support separate tx and rx queues as channels. The other count
2509 * represents how many queues are being used for control. max_combined counts
2510 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2511 * q_vectors since we support a lot more queue pairs than q_vectors.
2512 **/
2513static void i40e_get_channels(struct net_device *dev,
2514 struct ethtool_channels *ch)
2515{
2516 struct i40e_netdev_priv *np = netdev_priv(dev);
2517 struct i40e_vsi *vsi = np->vsi;
2518 struct i40e_pf *pf = vsi->back;
2519
2520 /* report maximum channels */
2521 ch->max_combined = i40e_max_channels(vsi);
2522
2523 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002524 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002525 ch->max_other = ch->other_count;
2526
2527 /* Note: This code assumes DCB is disabled for now. */
2528 ch->combined_count = vsi->num_queue_pairs;
2529}
2530
2531/**
2532 * i40e_set_channels - Set the new channels count.
2533 * @netdev: network interface device structure
2534 * @ch: ethtool channels structure
2535 *
2536 * The new channels count may not be the same as requested by the user
2537 * since it gets rounded down to a power of 2 value.
2538 **/
2539static int i40e_set_channels(struct net_device *dev,
2540 struct ethtool_channels *ch)
2541{
2542 struct i40e_netdev_priv *np = netdev_priv(dev);
2543 unsigned int count = ch->combined_count;
2544 struct i40e_vsi *vsi = np->vsi;
2545 struct i40e_pf *pf = vsi->back;
2546 int new_count;
2547
2548 /* We do not support setting channels for any other VSI at present */
2549 if (vsi->type != I40E_VSI_MAIN)
2550 return -EINVAL;
2551
2552 /* verify they are not requesting separate vectors */
2553 if (!count || ch->rx_count || ch->tx_count)
2554 return -EINVAL;
2555
2556 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002557 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002558 return -EINVAL;
2559
2560 /* verify the number of channels does not exceed hardware limits */
2561 if (count > i40e_max_channels(vsi))
2562 return -EINVAL;
2563
2564 /* update feature limits from largest to smallest supported values */
2565 /* TODO: Flow director limit, DCB etc */
2566
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002567 /* use rss_reconfig to rebuild with new queue count and update traffic
2568 * class queue mapping
2569 */
2570 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002571 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002572 return 0;
2573 else
2574 return -EINVAL;
2575}
2576
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002577#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2578/**
2579 * i40e_get_rxfh_key_size - get the RSS hash key size
2580 * @netdev: network interface device structure
2581 *
2582 * Returns the table size.
2583 **/
2584static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2585{
2586 return I40E_HKEY_ARRAY_SIZE;
2587}
2588
2589/**
2590 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2591 * @netdev: network interface device structure
2592 *
2593 * Returns the table size.
2594 **/
2595static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2596{
2597 return I40E_HLUT_ARRAY_SIZE;
2598}
2599
2600static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2601 u8 *hfunc)
2602{
2603 struct i40e_netdev_priv *np = netdev_priv(netdev);
2604 struct i40e_vsi *vsi = np->vsi;
2605 struct i40e_pf *pf = vsi->back;
2606 struct i40e_hw *hw = &pf->hw;
2607 u32 reg_val;
2608 int i, j;
2609
2610 if (hfunc)
2611 *hfunc = ETH_RSS_HASH_TOP;
2612
2613 if (!indir)
2614 return 0;
2615
2616 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2617 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2618 indir[j++] = reg_val & 0xff;
2619 indir[j++] = (reg_val >> 8) & 0xff;
2620 indir[j++] = (reg_val >> 16) & 0xff;
2621 indir[j++] = (reg_val >> 24) & 0xff;
2622 }
2623
2624 if (key) {
2625 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2626 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2627 key[j++] = (u8)(reg_val & 0xff);
2628 key[j++] = (u8)((reg_val >> 8) & 0xff);
2629 key[j++] = (u8)((reg_val >> 16) & 0xff);
2630 key[j++] = (u8)((reg_val >> 24) & 0xff);
2631 }
2632 }
2633 return 0;
2634}
2635
2636/**
2637 * i40e_set_rxfh - set the rx flow hash indirection table
2638 * @netdev: network interface device structure
2639 * @indir: indirection table
2640 * @key: hash key
2641 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002642 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002643 * returns 0 after programming the table.
2644 **/
2645static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2646 const u8 *key, const u8 hfunc)
2647{
2648 struct i40e_netdev_priv *np = netdev_priv(netdev);
2649 struct i40e_vsi *vsi = np->vsi;
2650 struct i40e_pf *pf = vsi->back;
2651 struct i40e_hw *hw = &pf->hw;
2652 u32 reg_val;
2653 int i, j;
2654
2655 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2656 return -EOPNOTSUPP;
2657
2658 if (!indir)
2659 return 0;
2660
2661 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2662 reg_val = indir[j++];
2663 reg_val |= indir[j++] << 8;
2664 reg_val |= indir[j++] << 16;
2665 reg_val |= indir[j++] << 24;
2666 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2667 }
2668
2669 if (key) {
2670 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2671 reg_val = key[j++];
2672 reg_val |= key[j++] << 8;
2673 reg_val |= key[j++] << 16;
2674 reg_val |= key[j++] << 24;
2675 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2676 }
2677 }
2678 return 0;
2679}
2680
Greg Rose7e45ab42015-02-06 08:52:19 +00002681/**
2682 * i40e_get_priv_flags - report device private flags
2683 * @dev: network interface device structure
2684 *
2685 * The get string set count and the string set should be matched for each
2686 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2687 * array.
2688 *
2689 * Returns a u32 bitmap of flags.
2690 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002691static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002692{
2693 struct i40e_netdev_priv *np = netdev_priv(dev);
2694 struct i40e_vsi *vsi = np->vsi;
2695 struct i40e_pf *pf = vsi->back;
2696 u32 ret_flags = 0;
2697
2698 ret_flags |= pf->hw.func_caps.npar_enable ?
2699 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002700 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2701 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002702 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2703 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002704 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2705 I40E_PRIV_FLAGS_VEB_STATS : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002706
2707 return ret_flags;
2708}
2709
Shannon Nelson9ac77262015-08-27 11:42:40 -04002710/**
2711 * i40e_set_priv_flags - set private flags
2712 * @dev: network interface device structure
2713 * @flags: bit flags to be set
2714 **/
2715static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2716{
2717 struct i40e_netdev_priv *np = netdev_priv(dev);
2718 struct i40e_vsi *vsi = np->vsi;
2719 struct i40e_pf *pf = vsi->back;
2720
2721 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2722 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2723 else
2724 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2725
Jesse Brandeburgef171782015-09-03 17:18:49 -04002726 /* allow the user to control the state of the Flow
2727 * Director ATR (Application Targeted Routing) feature
2728 * of the driver
2729 */
2730 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2731 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2732 } else {
2733 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2734 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2735 }
2736
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002737 if (flags & I40E_PRIV_FLAGS_VEB_STATS)
2738 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2739 else
2740 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2741
Shannon Nelson9ac77262015-08-27 11:42:40 -04002742 return 0;
2743}
2744
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002745static const struct ethtool_ops i40e_ethtool_ops = {
2746 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002747 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002748 .get_drvinfo = i40e_get_drvinfo,
2749 .get_regs_len = i40e_get_regs_len,
2750 .get_regs = i40e_get_regs,
2751 .nway_reset = i40e_nway_reset,
2752 .get_link = ethtool_op_get_link,
2753 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002754 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002755 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002756 .get_eeprom_len = i40e_get_eeprom_len,
2757 .get_eeprom = i40e_get_eeprom,
2758 .get_ringparam = i40e_get_ringparam,
2759 .set_ringparam = i40e_set_ringparam,
2760 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002761 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002762 .get_msglevel = i40e_get_msglevel,
2763 .set_msglevel = i40e_set_msglevel,
2764 .get_rxnfc = i40e_get_rxnfc,
2765 .set_rxnfc = i40e_set_rxnfc,
2766 .self_test = i40e_diag_test,
2767 .get_strings = i40e_get_strings,
2768 .set_phys_id = i40e_set_phys_id,
2769 .get_sset_count = i40e_get_sset_count,
2770 .get_ethtool_stats = i40e_get_ethtool_stats,
2771 .get_coalesce = i40e_get_coalesce,
2772 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002773 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2774 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2775 .get_rxfh = i40e_get_rxfh,
2776 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002777 .get_channels = i40e_get_channels,
2778 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002779 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002780 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002781 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002782};
2783
2784void i40e_set_ethtool_ops(struct net_device *netdev)
2785{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002786 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002787}