blob: a89da8a220921a83433ba233f15e651bec676431 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040091 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Shannon Nelson41a9e552014-04-23 04:50:20 +000092};
93
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000094/* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
100 *
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 */
104static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400116 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
118 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
119 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000120 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000121 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000122 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
123 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
124 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
125 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
126 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
127 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
128 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
129 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
130 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
131 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
132 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
133 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
134 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
135 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
136 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
137 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
138 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
139 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
140 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
141 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
142 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
143 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
144 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
145 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000146 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000147 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000148 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400149 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400150 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000151 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400152 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000153
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000154 /* LPI stats */
155 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
156 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
157 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
158 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000159};
160
Vasu Dev38e00432014-08-01 13:27:03 -0700161#ifdef I40E_FCOE
162static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
163 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
164 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
165 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
166 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
167 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
168 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
169 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
170 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
171};
172
173#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000174#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000175 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
176 * 2 /* Tx and Rx together */ \
177 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000178#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
179#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000180#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700181#ifdef I40E_FCOE
182#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
183#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
184 I40E_FCOE_STATS_LEN + \
185 I40E_MISC_STATS_LEN + \
186 I40E_QUEUE_STATS_LEN((n)))
187#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000189 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700191#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192#define I40E_PFC_STATS_LEN ( \
193 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
198 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400199#define I40E_VEB_TC_STATS_LEN ( \
200 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
201 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
204 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000205#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400206#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000207#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
208 I40E_PFC_STATS_LEN + \
209 I40E_VSI_STATS_LEN((n)))
210
211enum i40e_ethtool_test_id {
212 I40E_ETH_TEST_REG = 0,
213 I40E_ETH_TEST_EEPROM,
214 I40E_ETH_TEST_INTR,
215 I40E_ETH_TEST_LOOPBACK,
216 I40E_ETH_TEST_LINK,
217};
218
219static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
220 "Register test (offline)",
221 "Eeprom test (offline)",
222 "Interrupt test (offline)",
223 "Loopback test (offline)",
224 "Link test (on/offline)"
225};
226
227#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
228
Greg Rose7e45ab42015-02-06 08:52:19 +0000229static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
230 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400231 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400232 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400233 "veb-stats",
Greg Rose7e45ab42015-02-06 08:52:19 +0000234};
235
Shannon Nelson9ac77262015-08-27 11:42:40 -0400236#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000237
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000238/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000239 * i40e_partition_setting_complaint - generic complaint for MFP restriction
240 * @pf: the PF struct
241 **/
242static void i40e_partition_setting_complaint(struct i40e_pf *pf)
243{
244 dev_info(&pf->pdev->dev,
245 "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");
246}
247
248/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000249 * i40e_get_settings_link_up - Get the Link settings for when link is up
250 * @hw: hw structure
251 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000255static void i40e_get_settings_link_up(struct i40e_hw *hw,
256 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400257 struct net_device *netdev,
258 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000261 u32 link_speed = hw_link_info->link_speed;
262
Catherine Sullivane8278452015-02-06 08:52:08 +0000263 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000264 switch (hw_link_info->phy_type) {
265 case I40E_PHY_TYPE_40GBASE_CR4:
266 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000267 ecmd->supported = SUPPORTED_Autoneg |
268 SUPPORTED_40000baseCR4_Full;
269 ecmd->advertising = ADVERTISED_Autoneg |
270 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000271 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000272 case I40E_PHY_TYPE_XLAUI:
273 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000274 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000275 ecmd->supported = SUPPORTED_40000baseCR4_Full;
276 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000277 case I40E_PHY_TYPE_40GBASE_SR4:
278 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000279 break;
280 case I40E_PHY_TYPE_40GBASE_LR4:
281 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000282 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000283 case I40E_PHY_TYPE_10GBASE_SR:
284 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000285 case I40E_PHY_TYPE_1000BASE_SX:
286 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400287 ecmd->supported = SUPPORTED_10000baseT_Full;
288 if (hw_link_info->module_type[2] &
289 I40E_MODULE_TYPE_1000BASE_SX ||
290 hw_link_info->module_type[2] &
291 I40E_MODULE_TYPE_1000BASE_LX) {
292 ecmd->supported |= SUPPORTED_1000baseT_Full;
293 if (hw_link_info->requested_speeds &
294 I40E_LINK_SPEED_1GB)
295 ecmd->advertising |= ADVERTISED_1000baseT_Full;
296 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000297 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
298 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000299 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000300 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000301 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000302 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000303 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400304 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000305 ecmd->advertising = ADVERTISED_Autoneg;
306 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
307 ecmd->advertising |= ADVERTISED_10000baseT_Full;
308 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
309 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400310 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400311 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
312 ecmd->supported = SUPPORTED_Autoneg |
313 SUPPORTED_1000baseT_Full;
314 ecmd->advertising = ADVERTISED_Autoneg |
315 ADVERTISED_1000baseT_Full;
316 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400317 case I40E_PHY_TYPE_100BASE_TX:
318 ecmd->supported = SUPPORTED_Autoneg |
319 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000320 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
321 ecmd->advertising |= ADVERTISED_100baseT_Full;
322 break;
323 case I40E_PHY_TYPE_10GBASE_CR1_CU:
324 case I40E_PHY_TYPE_10GBASE_CR1:
325 ecmd->supported = SUPPORTED_Autoneg |
326 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000327 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000328 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000329 break;
330 case I40E_PHY_TYPE_XAUI:
331 case I40E_PHY_TYPE_XFI:
332 case I40E_PHY_TYPE_SFI:
333 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000334 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000335 ecmd->supported = SUPPORTED_10000baseT_Full;
336 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000337 case I40E_PHY_TYPE_SGMII:
338 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400339 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000340 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
341 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400342 if (pf->hw.mac.type == I40E_MAC_X722) {
343 ecmd->supported |= SUPPORTED_100baseT_Full;
344 if (hw_link_info->requested_speeds &
345 I40E_LINK_SPEED_100MB)
346 ecmd->advertising |= ADVERTISED_100baseT_Full;
347 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000348 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400349 /* Backplane is set based on supported phy types in get_settings
350 * so don't set anything here but don't warn either
351 */
352 case I40E_PHY_TYPE_40GBASE_KR4:
353 case I40E_PHY_TYPE_20GBASE_KR2:
354 case I40E_PHY_TYPE_10GBASE_KR:
355 case I40E_PHY_TYPE_10GBASE_KX4:
356 case I40E_PHY_TYPE_1000BASE_KX:
357 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000358 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000359 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000360 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
361 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000362 }
363
Catherine Sullivane8278452015-02-06 08:52:08 +0000364 /* Set speed and duplex */
365 switch (link_speed) {
366 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400367 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000368 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700369 case I40E_LINK_SPEED_20GB:
370 ethtool_cmd_speed_set(ecmd, SPEED_20000);
371 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000372 case I40E_LINK_SPEED_10GB:
373 ethtool_cmd_speed_set(ecmd, SPEED_10000);
374 break;
375 case I40E_LINK_SPEED_1GB:
376 ethtool_cmd_speed_set(ecmd, SPEED_1000);
377 break;
378 case I40E_LINK_SPEED_100MB:
379 ethtool_cmd_speed_set(ecmd, SPEED_100);
380 break;
381 default:
382 break;
383 }
384 ecmd->duplex = DUPLEX_FULL;
385}
386
387/**
388 * i40e_get_settings_link_down - Get the Link settings for when link is down
389 * @hw: hw structure
390 * @ecmd: ethtool command to fill in
391 *
392 * Reports link settings that can be determined when link is down
393 **/
394static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400395 struct ethtool_cmd *ecmd,
396 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000397{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400398 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000399
400 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400401 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000402 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400403 ecmd->supported = 0x0;
404 ecmd->advertising = 0x0;
405 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
406 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400407 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400408 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400409 ADVERTISED_1000baseT_Full;
410 if (pf->hw.mac.type == I40E_MAC_X722) {
411 ecmd->supported |= SUPPORTED_100baseT_Full;
412 ecmd->advertising |= ADVERTISED_100baseT_Full;
413 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000414 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400415 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
416 phy_types & I40E_CAP_PHY_TYPE_XFI ||
417 phy_types & I40E_CAP_PHY_TYPE_SFI ||
418 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
419 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
420 ecmd->supported |= SUPPORTED_10000baseT_Full;
421 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
422 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
423 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
424 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
425 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
426 ecmd->supported |= SUPPORTED_Autoneg |
427 SUPPORTED_10000baseT_Full;
428 ecmd->advertising |= ADVERTISED_Autoneg |
429 ADVERTISED_10000baseT_Full;
430 }
431 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
432 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
433 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
434 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
435 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
436 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
437 ecmd->supported |= SUPPORTED_Autoneg |
438 SUPPORTED_40000baseCR4_Full;
439 ecmd->advertising |= ADVERTISED_Autoneg |
440 ADVERTISED_40000baseCR4_Full;
441 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400442 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
443 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400444 ecmd->supported |= SUPPORTED_Autoneg |
445 SUPPORTED_100baseT_Full;
446 ecmd->advertising |= ADVERTISED_Autoneg |
447 ADVERTISED_100baseT_Full;
448 }
449 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
450 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
451 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
452 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
453 ecmd->supported |= SUPPORTED_Autoneg |
454 SUPPORTED_1000baseT_Full;
455 ecmd->advertising |= ADVERTISED_Autoneg |
456 ADVERTISED_1000baseT_Full;
457 }
458 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
459 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
460 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
461 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000462
463 /* With no link speed and duplex are unknown */
464 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
465 ecmd->duplex = DUPLEX_UNKNOWN;
466}
467
468/**
469 * i40e_get_settings - Get Link Speed and Duplex settings
470 * @netdev: network interface device structure
471 * @ecmd: ethtool command
472 *
473 * Reports speed/duplex settings based on media_type
474 **/
475static int i40e_get_settings(struct net_device *netdev,
476 struct ethtool_cmd *ecmd)
477{
478 struct i40e_netdev_priv *np = netdev_priv(netdev);
479 struct i40e_pf *pf = np->vsi->back;
480 struct i40e_hw *hw = &pf->hw;
481 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
482 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
483
484 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400485 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000486 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400487 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000488
489 /* Now set the settings that don't rely on link being up/down */
490
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400491 /* For backplane, supported and advertised are only reliant on the
492 * phy types the NVM specifies are supported.
493 */
494 if (hw->device_id == I40E_DEV_ID_KX_B ||
495 hw->device_id == I40E_DEV_ID_KX_C ||
496 hw->device_id == I40E_DEV_ID_20G_KR2 ||
497 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
498 ecmd->supported = SUPPORTED_Autoneg;
499 ecmd->advertising = ADVERTISED_Autoneg;
500 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
501 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
502 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
503 }
504 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
505 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
506 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
507 }
508 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
509 ecmd->supported |= SUPPORTED_10000baseKR_Full;
510 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
511 }
512 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
513 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
514 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
515 }
516 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
517 ecmd->supported |= SUPPORTED_1000baseKX_Full;
518 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
519 }
520 }
521
Catherine Sullivane8278452015-02-06 08:52:08 +0000522 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000523 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
524 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000525
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000526 switch (hw->phy.media_type) {
527 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000528 ecmd->supported |= SUPPORTED_Autoneg |
529 SUPPORTED_Backplane;
530 ecmd->advertising |= ADVERTISED_Autoneg |
531 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000532 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000533 break;
534 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000535 ecmd->supported |= SUPPORTED_TP;
536 ecmd->advertising |= ADVERTISED_TP;
537 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000538 break;
539 case I40E_MEDIA_TYPE_DA:
540 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000541 ecmd->supported |= SUPPORTED_FIBRE;
542 ecmd->advertising |= ADVERTISED_FIBRE;
543 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000544 break;
545 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000546 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000547 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000548 break;
549 case I40E_MEDIA_TYPE_UNKNOWN:
550 default:
551 ecmd->port = PORT_OTHER;
552 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000553 }
554
Catherine Sullivane8278452015-02-06 08:52:08 +0000555 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000556 ecmd->transceiver = XCVR_EXTERNAL;
557
Catherine Sullivane8278452015-02-06 08:52:08 +0000558 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000559 ecmd->supported |= SUPPORTED_Pause;
560
Catherine Sullivane8278452015-02-06 08:52:08 +0000561 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000562 case I40E_FC_FULL:
563 ecmd->advertising |= ADVERTISED_Pause;
564 break;
565 case I40E_FC_TX_PAUSE:
566 ecmd->advertising |= ADVERTISED_Asym_Pause;
567 break;
568 case I40E_FC_RX_PAUSE:
569 ecmd->advertising |= (ADVERTISED_Pause |
570 ADVERTISED_Asym_Pause);
571 break;
572 default:
573 ecmd->advertising &= ~(ADVERTISED_Pause |
574 ADVERTISED_Asym_Pause);
575 break;
576 }
577
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000578 return 0;
579}
580
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000581/**
582 * i40e_set_settings - Set Speed and Duplex
583 * @netdev: network interface device structure
584 * @ecmd: ethtool command
585 *
586 * Set speed/duplex per media_types advertised/forced
587 **/
588static int i40e_set_settings(struct net_device *netdev,
589 struct ethtool_cmd *ecmd)
590{
591 struct i40e_netdev_priv *np = netdev_priv(netdev);
592 struct i40e_aq_get_phy_abilities_resp abilities;
593 struct i40e_aq_set_phy_config config;
594 struct i40e_pf *pf = np->vsi->back;
595 struct i40e_vsi *vsi = np->vsi;
596 struct i40e_hw *hw = &pf->hw;
597 struct ethtool_cmd safe_ecmd;
598 i40e_status status = 0;
599 bool change = false;
600 int err = 0;
601 u8 autoneg;
602 u32 advertise;
603
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000604 /* Changing port settings is not supported if this isn't the
605 * port's controlling PF
606 */
607 if (hw->partition_id != 1) {
608 i40e_partition_setting_complaint(pf);
609 return -EOPNOTSUPP;
610 }
611
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000612 if (vsi != pf->vsi[pf->lan_vsi])
613 return -EOPNOTSUPP;
614
615 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
616 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000617 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
618 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000619 return -EOPNOTSUPP;
620
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400621 if (hw->device_id == I40E_DEV_ID_KX_B ||
622 hw->device_id == I40E_DEV_ID_KX_C ||
623 hw->device_id == I40E_DEV_ID_20G_KR2 ||
624 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
625 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
626 return -EOPNOTSUPP;
627 }
628
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000629 /* get our own copy of the bits to check against */
630 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
631 i40e_get_settings(netdev, &safe_ecmd);
632
633 /* save autoneg and speed out of ecmd */
634 autoneg = ecmd->autoneg;
635 advertise = ecmd->advertising;
636
637 /* set autoneg and speed back to what they currently are */
638 ecmd->autoneg = safe_ecmd.autoneg;
639 ecmd->advertising = safe_ecmd.advertising;
640
641 ecmd->cmd = safe_ecmd.cmd;
642 /* If ecmd and safe_ecmd are not the same now, then they are
643 * trying to set something that we do not support
644 */
645 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
646 return -EOPNOTSUPP;
647
648 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
649 usleep_range(1000, 2000);
650
651 /* Get the current phy config */
652 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
653 NULL);
654 if (status)
655 return -EAGAIN;
656
Catherine Sullivan124ed152014-07-12 07:28:12 +0000657 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000658 * set below
659 */
660 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000661 config.abilities = abilities.abilities;
662
663 /* Check autoneg */
664 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000665 /* If autoneg was not already enabled */
666 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400667 /* If autoneg is not supported, return error */
668 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
669 netdev_info(netdev, "Autoneg not supported on this phy\n");
670 return -EINVAL;
671 }
672 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000673 config.abilities = abilities.abilities |
674 I40E_AQ_PHY_ENABLE_AN;
675 change = true;
676 }
677 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000678 /* If autoneg is currently enabled */
679 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400680 /* If autoneg is supported 10GBASE_T is the only PHY
681 * that can disable it, so otherwise return error
682 */
683 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
684 hw->phy.link_info.phy_type !=
685 I40E_PHY_TYPE_10GBASE_T) {
686 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
687 return -EINVAL;
688 }
689 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000690 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000691 ~I40E_AQ_PHY_ENABLE_AN;
692 change = true;
693 }
694 }
695
696 if (advertise & ~safe_ecmd.supported)
697 return -EINVAL;
698
699 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000700 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000701 if (advertise & ADVERTISED_1000baseT_Full ||
702 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000703 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000704 if (advertise & ADVERTISED_10000baseT_Full ||
705 advertise & ADVERTISED_10000baseKX4_Full ||
706 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000707 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700708 if (advertise & ADVERTISED_20000baseKR2_Full)
709 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000710 if (advertise & ADVERTISED_40000baseKR4_Full ||
711 advertise & ADVERTISED_40000baseCR4_Full ||
712 advertise & ADVERTISED_40000baseSR4_Full ||
713 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000714 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000715
Catherine Sullivan0002e112015-08-26 15:14:16 -0400716 /* If speed didn't get set, set it to what it currently is.
717 * This is needed because if advertise is 0 (as it is when autoneg
718 * is disabled) then speed won't get set.
719 */
720 if (!config.link_speed)
721 config.link_speed = abilities.link_speed;
722
Catherine Sullivan124ed152014-07-12 07:28:12 +0000723 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000724 /* copy over the rest of the abilities */
725 config.phy_type = abilities.phy_type;
726 config.eee_capability = abilities.eee_capability;
727 config.eeer = abilities.eeer_val;
728 config.low_power_ctrl = abilities.d3_lpan;
729
Catherine Sullivane8278452015-02-06 08:52:08 +0000730 /* save the requested speeds */
731 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000732 /* set link and auto negotiation so changes take effect */
733 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
734 /* If link is up put link down */
735 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
736 /* Tell the OS link is going down, the link will go
737 * back up when fw says it is ready asynchronously
738 */
Matt Jaredc156f852015-08-27 11:42:39 -0400739 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000740 netif_carrier_off(netdev);
741 netif_tx_stop_all_queues(netdev);
742 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000743
744 /* make the aq call */
745 status = i40e_aq_set_phy_config(hw, &config, NULL);
746 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400747 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
748 i40e_stat_str(hw, status),
749 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750 return -EAGAIN;
751 }
752
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400753 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000754 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400755 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
756 i40e_stat_str(hw, status),
757 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000758
759 } else {
760 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
761 }
762
763 return err;
764}
765
Jesse Brandeburga6599722014-06-04 08:45:25 +0000766static int i40e_nway_reset(struct net_device *netdev)
767{
768 /* restart autonegotiation */
769 struct i40e_netdev_priv *np = netdev_priv(netdev);
770 struct i40e_pf *pf = np->vsi->back;
771 struct i40e_hw *hw = &pf->hw;
772 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
773 i40e_status ret = 0;
774
775 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
776 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400777 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
778 i40e_stat_str(hw, ret),
779 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000780 return -EIO;
781 }
782
783 return 0;
784}
785
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000786/**
787 * i40e_get_pauseparam - Get Flow Control status
788 * Return tx/rx-pause status
789 **/
790static void i40e_get_pauseparam(struct net_device *netdev,
791 struct ethtool_pauseparam *pause)
792{
793 struct i40e_netdev_priv *np = netdev_priv(netdev);
794 struct i40e_pf *pf = np->vsi->back;
795 struct i40e_hw *hw = &pf->hw;
796 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000797 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000798
799 pause->autoneg =
800 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
801 AUTONEG_ENABLE : AUTONEG_DISABLE);
802
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000803 /* PFC enabled so report LFC as off */
804 if (dcbx_cfg->pfc.pfcenable) {
805 pause->rx_pause = 0;
806 pause->tx_pause = 0;
807 return;
808 }
809
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000810 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000811 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000812 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000813 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000814 } else if (hw->fc.current_mode == I40E_FC_FULL) {
815 pause->rx_pause = 1;
816 pause->tx_pause = 1;
817 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000818}
819
Catherine Sullivan2becc352014-06-04 08:45:27 +0000820/**
821 * i40e_set_pauseparam - Set Flow Control parameter
822 * @netdev: network interface device structure
823 * @pause: return tx/rx flow control status
824 **/
825static int i40e_set_pauseparam(struct net_device *netdev,
826 struct ethtool_pauseparam *pause)
827{
828 struct i40e_netdev_priv *np = netdev_priv(netdev);
829 struct i40e_pf *pf = np->vsi->back;
830 struct i40e_vsi *vsi = np->vsi;
831 struct i40e_hw *hw = &pf->hw;
832 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000833 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000834 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
835 i40e_status status;
836 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000837 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000838
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000839 /* Changing the port's flow control is not supported if this isn't the
840 * port's controlling PF
841 */
842 if (hw->partition_id != 1) {
843 i40e_partition_setting_complaint(pf);
844 return -EOPNOTSUPP;
845 }
846
Catherine Sullivan2becc352014-06-04 08:45:27 +0000847 if (vsi != pf->vsi[pf->lan_vsi])
848 return -EOPNOTSUPP;
849
850 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
851 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
852 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
853 return -EOPNOTSUPP;
854 }
855
856 /* If we have link and don't have autoneg */
857 if (!test_bit(__I40E_DOWN, &pf->state) &&
858 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
859 /* Send message that it might not necessarily work*/
860 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
861 }
862
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000863 if (dcbx_cfg->pfc.pfcenable) {
864 netdev_info(netdev,
865 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000866 return -EOPNOTSUPP;
867 }
868
869 if (pause->rx_pause && pause->tx_pause)
870 hw->fc.requested_mode = I40E_FC_FULL;
871 else if (pause->rx_pause && !pause->tx_pause)
872 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
873 else if (!pause->rx_pause && pause->tx_pause)
874 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
875 else if (!pause->rx_pause && !pause->tx_pause)
876 hw->fc.requested_mode = I40E_FC_NONE;
877 else
878 return -EINVAL;
879
Catherine Sullivan94128512014-07-12 07:28:16 +0000880 /* Tell the OS link is going down, the link will go back up when fw
881 * says it is ready asynchronously
882 */
Matt Jaredc156f852015-08-27 11:42:39 -0400883 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000884 netif_carrier_off(netdev);
885 netif_tx_stop_all_queues(netdev);
886
Catherine Sullivan2becc352014-06-04 08:45:27 +0000887 /* Set the fc mode and only restart an if link is up*/
888 status = i40e_set_fc(hw, &aq_failures, link_up);
889
890 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400891 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
892 i40e_stat_str(hw, status),
893 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000894 err = -EAGAIN;
895 }
896 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400897 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
898 i40e_stat_str(hw, status),
899 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000900 err = -EAGAIN;
901 }
902 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400903 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
904 i40e_stat_str(hw, status),
905 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000906 err = -EAGAIN;
907 }
908
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000909 if (!test_bit(__I40E_DOWN, &pf->state)) {
910 /* Give it a little more time to try to come back */
911 msleep(75);
912 if (!test_bit(__I40E_DOWN, &pf->state))
913 return i40e_nway_reset(netdev);
914 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000915
916 return err;
917}
918
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000919static u32 i40e_get_msglevel(struct net_device *netdev)
920{
921 struct i40e_netdev_priv *np = netdev_priv(netdev);
922 struct i40e_pf *pf = np->vsi->back;
923
924 return pf->msg_enable;
925}
926
927static void i40e_set_msglevel(struct net_device *netdev, u32 data)
928{
929 struct i40e_netdev_priv *np = netdev_priv(netdev);
930 struct i40e_pf *pf = np->vsi->back;
931
932 if (I40E_DEBUG_USER & data)
933 pf->hw.debug_mask = data;
934 pf->msg_enable = data;
935}
936
937static int i40e_get_regs_len(struct net_device *netdev)
938{
939 int reg_count = 0;
940 int i;
941
942 for (i = 0; i40e_reg_list[i].offset != 0; i++)
943 reg_count += i40e_reg_list[i].elements;
944
945 return reg_count * sizeof(u32);
946}
947
948static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
949 void *p)
950{
951 struct i40e_netdev_priv *np = netdev_priv(netdev);
952 struct i40e_pf *pf = np->vsi->back;
953 struct i40e_hw *hw = &pf->hw;
954 u32 *reg_buf = p;
955 int i, j, ri;
956 u32 reg;
957
958 /* Tell ethtool which driver-version-specific regs output we have.
959 *
960 * At some point, if we have ethtool doing special formatting of
961 * this data, it will rely on this version number to know how to
962 * interpret things. Hence, this needs to be updated if/when the
963 * diags register table is changed.
964 */
965 regs->version = 1;
966
967 /* loop through the diags reg table for what to print */
968 ri = 0;
969 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
970 for (j = 0; j < i40e_reg_list[i].elements; j++) {
971 reg = i40e_reg_list[i].offset
972 + (j * i40e_reg_list[i].stride);
973 reg_buf[ri++] = rd32(hw, reg);
974 }
975 }
976
977}
978
979static int i40e_get_eeprom(struct net_device *netdev,
980 struct ethtool_eeprom *eeprom, u8 *bytes)
981{
982 struct i40e_netdev_priv *np = netdev_priv(netdev);
983 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000984 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000985 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000986 u8 *eeprom_buff;
987 u16 i, sectors;
988 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000989 u32 magic;
990
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000991#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000992 if (eeprom->len == 0)
993 return -EINVAL;
994
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000995 /* check for NVMUpdate access method */
996 magic = hw->vendor_id | (hw->device_id << 16);
997 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000998 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000999 int errno;
1000
1001 /* make sure it is the right magic for NVMUpdate */
1002 if ((eeprom->magic >> 16) != hw->device_id)
1003 return -EINVAL;
1004
Shannon Nelsonc150a502014-11-13 08:23:13 +00001005 cmd = (struct i40e_nvm_access *)eeprom;
1006 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001007 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001008 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001009 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1010 ret_val, hw->aq.asq_last_status, errno,
1011 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1012 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001013
1014 return errno;
1015 }
1016
1017 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001018 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1019
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001020 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001021 if (!eeprom_buff)
1022 return -ENOMEM;
1023
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001024 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1025 if (ret_val) {
1026 dev_info(&pf->pdev->dev,
1027 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1028 ret_val, hw->aq.asq_last_status);
1029 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001030 }
1031
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001032 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1033 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1034 len = I40E_NVM_SECTOR_SIZE;
1035 last = false;
1036 for (i = 0; i < sectors; i++) {
1037 if (i == (sectors - 1)) {
1038 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1039 last = true;
1040 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001041 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1042 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001043 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001044 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001045 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001046 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001047 "read NVM failed, invalid offset 0x%x\n",
1048 offset);
1049 break;
1050 } else if (ret_val &&
1051 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1052 dev_info(&pf->pdev->dev,
1053 "read NVM failed, access, offset 0x%x\n",
1054 offset);
1055 break;
1056 } else if (ret_val) {
1057 dev_info(&pf->pdev->dev,
1058 "read NVM failed offset %d err=%d status=0x%x\n",
1059 offset, ret_val, hw->aq.asq_last_status);
1060 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001061 }
1062 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001064 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001065 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001066free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001067 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001068 return ret_val;
1069}
1070
1071static int i40e_get_eeprom_len(struct net_device *netdev)
1072{
1073 struct i40e_netdev_priv *np = netdev_priv(netdev);
1074 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001075 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001076
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001077 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1078 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1079 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1080 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001081 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001082 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001083}
1084
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001085static int i40e_set_eeprom(struct net_device *netdev,
1086 struct ethtool_eeprom *eeprom, u8 *bytes)
1087{
1088 struct i40e_netdev_priv *np = netdev_priv(netdev);
1089 struct i40e_hw *hw = &np->vsi->back->hw;
1090 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001091 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001092 int ret_val = 0;
1093 int errno;
1094 u32 magic;
1095
1096 /* normal ethtool set_eeprom is not supported */
1097 magic = hw->vendor_id | (hw->device_id << 16);
1098 if (eeprom->magic == magic)
1099 return -EOPNOTSUPP;
1100
1101 /* check for NVMUpdate access method */
1102 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1103 return -EINVAL;
1104
1105 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1106 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1107 return -EBUSY;
1108
Shannon Nelsonc150a502014-11-13 08:23:13 +00001109 cmd = (struct i40e_nvm_access *)eeprom;
1110 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001111 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001112 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001113 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1114 ret_val, hw->aq.asq_last_status, errno,
1115 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1116 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001117
1118 return errno;
1119}
1120
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001121static void i40e_get_drvinfo(struct net_device *netdev,
1122 struct ethtool_drvinfo *drvinfo)
1123{
1124 struct i40e_netdev_priv *np = netdev_priv(netdev);
1125 struct i40e_vsi *vsi = np->vsi;
1126 struct i40e_pf *pf = vsi->back;
1127
1128 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1129 strlcpy(drvinfo->version, i40e_driver_version_str,
1130 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001131 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001132 sizeof(drvinfo->fw_version));
1133 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1134 sizeof(drvinfo->bus_info));
1135}
1136
1137static void i40e_get_ringparam(struct net_device *netdev,
1138 struct ethtool_ringparam *ring)
1139{
1140 struct i40e_netdev_priv *np = netdev_priv(netdev);
1141 struct i40e_pf *pf = np->vsi->back;
1142 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1143
1144 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1145 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1146 ring->rx_mini_max_pending = 0;
1147 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001148 ring->rx_pending = vsi->rx_rings[0]->count;
1149 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001150 ring->rx_mini_pending = 0;
1151 ring->rx_jumbo_pending = 0;
1152}
1153
1154static int i40e_set_ringparam(struct net_device *netdev,
1155 struct ethtool_ringparam *ring)
1156{
1157 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1158 struct i40e_netdev_priv *np = netdev_priv(netdev);
1159 struct i40e_vsi *vsi = np->vsi;
1160 struct i40e_pf *pf = vsi->back;
1161 u32 new_rx_count, new_tx_count;
1162 int i, err = 0;
1163
1164 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1165 return -EINVAL;
1166
Shannon Nelson1fa18372013-11-20 10:03:08 +00001167 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1168 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1169 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1170 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1171 netdev_info(netdev,
1172 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1173 ring->tx_pending, ring->rx_pending,
1174 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1175 return -EINVAL;
1176 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001177
Shannon Nelson1fa18372013-11-20 10:03:08 +00001178 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1179 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001180
1181 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001182 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1183 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001184 return 0;
1185
1186 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1187 usleep_range(1000, 2000);
1188
1189 if (!netif_running(vsi->netdev)) {
1190 /* simple case - set for the next time the netdev is started */
1191 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001192 vsi->tx_rings[i]->count = new_tx_count;
1193 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001194 }
1195 goto done;
1196 }
1197
1198 /* We can't just free everything and then setup again,
1199 * because the ISRs in MSI-X mode get passed pointers
1200 * to the Tx and Rx ring structs.
1201 */
1202
1203 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001204 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001205 netdev_info(netdev,
1206 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001207 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001208 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1209 sizeof(struct i40e_ring), GFP_KERNEL);
1210 if (!tx_rings) {
1211 err = -ENOMEM;
1212 goto done;
1213 }
1214
1215 for (i = 0; i < vsi->num_queue_pairs; i++) {
1216 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001217 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001218 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001219 /* the desc and bi pointers will be reallocated in the
1220 * setup call
1221 */
1222 tx_rings[i].desc = NULL;
1223 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001224 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1225 if (err) {
1226 while (i) {
1227 i--;
1228 i40e_free_tx_resources(&tx_rings[i]);
1229 }
1230 kfree(tx_rings);
1231 tx_rings = NULL;
1232
1233 goto done;
1234 }
1235 }
1236 }
1237
1238 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001239 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001240 netdev_info(netdev,
1241 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001242 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001243 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1244 sizeof(struct i40e_ring), GFP_KERNEL);
1245 if (!rx_rings) {
1246 err = -ENOMEM;
1247 goto free_tx;
1248 }
1249
1250 for (i = 0; i < vsi->num_queue_pairs; i++) {
1251 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001252 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001253 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001254 /* the desc and bi pointers will be reallocated in the
1255 * setup call
1256 */
1257 rx_rings[i].desc = NULL;
1258 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001259 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1260 if (err) {
1261 while (i) {
1262 i--;
1263 i40e_free_rx_resources(&rx_rings[i]);
1264 }
1265 kfree(rx_rings);
1266 rx_rings = NULL;
1267
1268 goto free_tx;
1269 }
1270 }
1271 }
1272
1273 /* Bring interface down, copy in the new ring info,
1274 * then restore the interface
1275 */
1276 i40e_down(vsi);
1277
1278 if (tx_rings) {
1279 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001280 i40e_free_tx_resources(vsi->tx_rings[i]);
1281 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001282 }
1283 kfree(tx_rings);
1284 tx_rings = NULL;
1285 }
1286
1287 if (rx_rings) {
1288 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001289 i40e_free_rx_resources(vsi->rx_rings[i]);
1290 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001291 }
1292 kfree(rx_rings);
1293 rx_rings = NULL;
1294 }
1295
1296 i40e_up(vsi);
1297
1298free_tx:
1299 /* error cleanup if the Rx allocations failed after getting Tx */
1300 if (tx_rings) {
1301 for (i = 0; i < vsi->num_queue_pairs; i++)
1302 i40e_free_tx_resources(&tx_rings[i]);
1303 kfree(tx_rings);
1304 tx_rings = NULL;
1305 }
1306
1307done:
1308 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1309
1310 return err;
1311}
1312
1313static int i40e_get_sset_count(struct net_device *netdev, int sset)
1314{
1315 struct i40e_netdev_priv *np = netdev_priv(netdev);
1316 struct i40e_vsi *vsi = np->vsi;
1317 struct i40e_pf *pf = vsi->back;
1318
1319 switch (sset) {
1320 case ETH_SS_TEST:
1321 return I40E_TEST_LEN;
1322 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001323 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001324 int len = I40E_PF_STATS_LEN(netdev);
1325
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001326 if ((pf->lan_veb != I40E_NO_VEB) &&
1327 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001328 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001329 return len;
1330 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001332 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001333 case ETH_SS_PRIV_FLAGS:
1334 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001335 default:
1336 return -EOPNOTSUPP;
1337 }
1338}
1339
1340static void i40e_get_ethtool_stats(struct net_device *netdev,
1341 struct ethtool_stats *stats, u64 *data)
1342{
1343 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001344 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001345 struct i40e_vsi *vsi = np->vsi;
1346 struct i40e_pf *pf = vsi->back;
1347 int i = 0;
1348 char *p;
1349 int j;
1350 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001351 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001352
1353 i40e_update_stats(vsi);
1354
1355 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1356 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1357 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1358 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1359 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001360 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1361 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1362 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1363 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1364 }
Vasu Dev38e00432014-08-01 13:27:03 -07001365#ifdef I40E_FCOE
1366 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1367 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1368 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1369 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1370 }
1371#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001372 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001373 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001374 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001375
1376 if (!tx_ring)
1377 continue;
1378
1379 /* process Tx ring statistics */
1380 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001381 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001382 data[i] = tx_ring->stats.packets;
1383 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001384 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001385 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001386
1387 /* Rx ring is the 2nd half of the queue pair */
1388 rx_ring = &tx_ring[1];
1389 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001390 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001391 data[i] = rx_ring->stats.packets;
1392 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001393 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001394 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001395 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001396 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001397 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001398 return;
1399
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001400 if ((pf->lan_veb != I40E_NO_VEB) &&
1401 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001402 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001403
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001404 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1405 p = (char *)veb;
1406 p += i40e_gstrings_veb_stats[j].stat_offset;
1407 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1408 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001409 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001410 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1411 data[i++] = veb->tc_stats.tc_tx_packets[j];
1412 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1413 data[i++] = veb->tc_stats.tc_rx_packets[j];
1414 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1415 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001416 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001417 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1418 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1419 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1420 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1421 }
1422 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1423 data[i++] = pf->stats.priority_xon_tx[j];
1424 data[i++] = pf->stats.priority_xoff_tx[j];
1425 }
1426 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1427 data[i++] = pf->stats.priority_xon_rx[j];
1428 data[i++] = pf->stats.priority_xoff_rx[j];
1429 }
1430 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1431 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001432}
1433
1434static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1435 u8 *data)
1436{
1437 struct i40e_netdev_priv *np = netdev_priv(netdev);
1438 struct i40e_vsi *vsi = np->vsi;
1439 struct i40e_pf *pf = vsi->back;
1440 char *p = (char *)data;
1441 int i;
1442
1443 switch (stringset) {
1444 case ETH_SS_TEST:
1445 for (i = 0; i < I40E_TEST_LEN; i++) {
1446 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1447 data += ETH_GSTRING_LEN;
1448 }
1449 break;
1450 case ETH_SS_STATS:
1451 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1452 snprintf(p, ETH_GSTRING_LEN, "%s",
1453 i40e_gstrings_net_stats[i].stat_string);
1454 p += ETH_GSTRING_LEN;
1455 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001456 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1457 snprintf(p, ETH_GSTRING_LEN, "%s",
1458 i40e_gstrings_misc_stats[i].stat_string);
1459 p += ETH_GSTRING_LEN;
1460 }
Vasu Dev38e00432014-08-01 13:27:03 -07001461#ifdef I40E_FCOE
1462 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1463 snprintf(p, ETH_GSTRING_LEN, "%s",
1464 i40e_gstrings_fcoe_stats[i].stat_string);
1465 p += ETH_GSTRING_LEN;
1466 }
1467#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001468 for (i = 0; i < vsi->num_queue_pairs; i++) {
1469 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1470 p += ETH_GSTRING_LEN;
1471 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1472 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001473 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1474 p += ETH_GSTRING_LEN;
1475 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1476 p += ETH_GSTRING_LEN;
1477 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001478 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001479 return;
1480
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001481 if ((pf->lan_veb != I40E_NO_VEB) &&
1482 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001483 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1484 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1485 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001486 p += ETH_GSTRING_LEN;
1487 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001488 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1489 snprintf(p, ETH_GSTRING_LEN,
1490 "veb.tc_%u_tx_packets", i);
1491 p += ETH_GSTRING_LEN;
1492 snprintf(p, ETH_GSTRING_LEN,
1493 "veb.tc_%u_tx_bytes", i);
1494 p += ETH_GSTRING_LEN;
1495 snprintf(p, ETH_GSTRING_LEN,
1496 "veb.tc_%u_rx_packets", i);
1497 p += ETH_GSTRING_LEN;
1498 snprintf(p, ETH_GSTRING_LEN,
1499 "veb.tc_%u_rx_bytes", i);
1500 p += ETH_GSTRING_LEN;
1501 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001502 }
1503 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1504 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1505 i40e_gstrings_stats[i].stat_string);
1506 p += ETH_GSTRING_LEN;
1507 }
1508 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1509 snprintf(p, ETH_GSTRING_LEN,
1510 "port.tx_priority_%u_xon", i);
1511 p += ETH_GSTRING_LEN;
1512 snprintf(p, ETH_GSTRING_LEN,
1513 "port.tx_priority_%u_xoff", i);
1514 p += ETH_GSTRING_LEN;
1515 }
1516 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1517 snprintf(p, ETH_GSTRING_LEN,
1518 "port.rx_priority_%u_xon", i);
1519 p += ETH_GSTRING_LEN;
1520 snprintf(p, ETH_GSTRING_LEN,
1521 "port.rx_priority_%u_xoff", i);
1522 p += ETH_GSTRING_LEN;
1523 }
1524 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1525 snprintf(p, ETH_GSTRING_LEN,
1526 "port.rx_priority_%u_xon_2_xoff", i);
1527 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001528 }
1529 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1530 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001531 case ETH_SS_PRIV_FLAGS:
1532 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1533 memcpy(data, i40e_priv_flags_strings[i],
1534 ETH_GSTRING_LEN);
1535 data += ETH_GSTRING_LEN;
1536 }
1537 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001538 default:
1539 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001540 }
1541}
1542
1543static int i40e_get_ts_info(struct net_device *dev,
1544 struct ethtool_ts_info *info)
1545{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001546 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1547
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001548 /* only report HW timestamping if PTP is enabled */
1549 if (!(pf->flags & I40E_FLAG_PTP))
1550 return ethtool_op_get_ts_info(dev, info);
1551
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001552 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1553 SOF_TIMESTAMPING_RX_SOFTWARE |
1554 SOF_TIMESTAMPING_SOFTWARE |
1555 SOF_TIMESTAMPING_TX_HARDWARE |
1556 SOF_TIMESTAMPING_RX_HARDWARE |
1557 SOF_TIMESTAMPING_RAW_HARDWARE;
1558
1559 if (pf->ptp_clock)
1560 info->phc_index = ptp_clock_index(pf->ptp_clock);
1561 else
1562 info->phc_index = -1;
1563
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001564 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001565
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001566 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1567 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1568 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001569
1570 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571}
1572
Shannon Nelson7b086392013-11-20 10:02:59 +00001573static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001574{
Shannon Nelson7b086392013-11-20 10:02:59 +00001575 struct i40e_netdev_priv *np = netdev_priv(netdev);
1576 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001577 i40e_status status;
1578 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001579
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001580 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001581 status = i40e_get_link_status(&pf->hw, &link_up);
1582 if (status) {
1583 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1584 *data = 1;
1585 return *data;
1586 }
1587
1588 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001589 *data = 0;
1590 else
1591 *data = 1;
1592
1593 return *data;
1594}
1595
Shannon Nelson7b086392013-11-20 10:02:59 +00001596static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001597{
Shannon Nelson7b086392013-11-20 10:02:59 +00001598 struct i40e_netdev_priv *np = netdev_priv(netdev);
1599 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001601 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001602 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001603
Shannon Nelson7b086392013-11-20 10:02:59 +00001604 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001605}
1606
Shannon Nelson7b086392013-11-20 10:02:59 +00001607static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608{
Shannon Nelson7b086392013-11-20 10:02:59 +00001609 struct i40e_netdev_priv *np = netdev_priv(netdev);
1610 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001611
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001612 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001613 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614
Shannon Nelson4443ec92014-11-13 08:23:12 +00001615 /* forcebly clear the NVM Update state machine */
1616 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1617
Shannon Nelson7b086392013-11-20 10:02:59 +00001618 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619}
1620
Shannon Nelson7b086392013-11-20 10:02:59 +00001621static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001622{
Shannon Nelson7b086392013-11-20 10:02:59 +00001623 struct i40e_netdev_priv *np = netdev_priv(netdev);
1624 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001625 u16 swc_old = pf->sw_int_count;
1626
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001627 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001628 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1629 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001630 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1631 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1632 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1633 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001634 usleep_range(1000, 2000);
1635 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001636
1637 return *data;
1638}
1639
Shannon Nelson7b086392013-11-20 10:02:59 +00001640static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001641{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001642 struct i40e_netdev_priv *np = netdev_priv(netdev);
1643 struct i40e_pf *pf = np->vsi->back;
1644
1645 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001646 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001647
1648 return *data;
1649}
1650
Greg Rosee17bc412015-04-16 20:05:59 -04001651static inline bool i40e_active_vfs(struct i40e_pf *pf)
1652{
1653 struct i40e_vf *vfs = pf->vf;
1654 int i;
1655
1656 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001657 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001658 return true;
1659 return false;
1660}
1661
Greg Rose510efb22015-07-10 19:36:01 -04001662static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1663{
1664 struct i40e_vsi **vsi = pf->vsi;
1665 int i;
1666
1667 for (i = 0; i < pf->num_alloc_vsi; i++) {
1668 if (!vsi[i])
1669 continue;
1670 if (vsi[i]->type == I40E_VSI_VMDQ2)
1671 return true;
1672 }
1673
1674 return false;
1675}
1676
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001677static void i40e_diag_test(struct net_device *netdev,
1678 struct ethtool_test *eth_test, u64 *data)
1679{
1680 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001681 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001682 struct i40e_pf *pf = np->vsi->back;
1683
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001684 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1685 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001686 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001687
Shannon Nelsonf551b432013-11-26 10:49:12 +00001688 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001689
Greg Rose510efb22015-07-10 19:36:01 -04001690 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001691 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001692 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001693 data[I40E_ETH_TEST_REG] = 1;
1694 data[I40E_ETH_TEST_EEPROM] = 1;
1695 data[I40E_ETH_TEST_INTR] = 1;
1696 data[I40E_ETH_TEST_LOOPBACK] = 1;
1697 data[I40E_ETH_TEST_LINK] = 1;
1698 eth_test->flags |= ETH_TEST_FL_FAILED;
1699 clear_bit(__I40E_TESTING, &pf->state);
1700 goto skip_ol_tests;
1701 }
1702
Greg Rose5b86c5c2015-02-26 16:14:35 +00001703 /* If the device is online then take it offline */
1704 if (if_running)
1705 /* indicate we're in test mode */
1706 dev_close(netdev);
1707 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001708 /* This reset does not affect link - if it is
1709 * changed to a type of reset that does affect
1710 * link then the following link test would have
1711 * to be moved to before the reset
1712 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001713 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001714
Shannon Nelson7b086392013-11-20 10:02:59 +00001715 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001716 eth_test->flags |= ETH_TEST_FL_FAILED;
1717
Shannon Nelson7b086392013-11-20 10:02:59 +00001718 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001719 eth_test->flags |= ETH_TEST_FL_FAILED;
1720
Shannon Nelson7b086392013-11-20 10:02:59 +00001721 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001722 eth_test->flags |= ETH_TEST_FL_FAILED;
1723
Shannon Nelson7b086392013-11-20 10:02:59 +00001724 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001725 eth_test->flags |= ETH_TEST_FL_FAILED;
1726
Shannon Nelsonf551b432013-11-26 10:49:12 +00001727 /* run reg test last, a reset is required after it */
1728 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1729 eth_test->flags |= ETH_TEST_FL_FAILED;
1730
1731 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001732 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001733
1734 if (if_running)
1735 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001736 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001737 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001738 netif_info(pf, drv, netdev, "online testing starting\n");
1739
Shannon Nelson7b086392013-11-20 10:02:59 +00001740 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741 eth_test->flags |= ETH_TEST_FL_FAILED;
1742
1743 /* Offline only tests, not run in online; pass by default */
1744 data[I40E_ETH_TEST_REG] = 0;
1745 data[I40E_ETH_TEST_EEPROM] = 0;
1746 data[I40E_ETH_TEST_INTR] = 0;
1747 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001748 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001749
Greg Rosee17bc412015-04-16 20:05:59 -04001750skip_ol_tests:
1751
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001752 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001753}
1754
1755static void i40e_get_wol(struct net_device *netdev,
1756 struct ethtool_wolinfo *wol)
1757{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001758 struct i40e_netdev_priv *np = netdev_priv(netdev);
1759 struct i40e_pf *pf = np->vsi->back;
1760 struct i40e_hw *hw = &pf->hw;
1761 u16 wol_nvm_bits;
1762
1763 /* NVM bit on means WoL disabled for the port */
1764 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001765 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001766 wol->supported = 0;
1767 wol->wolopts = 0;
1768 } else {
1769 wol->supported = WAKE_MAGIC;
1770 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1771 }
1772}
1773
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001774/**
1775 * i40e_set_wol - set the WakeOnLAN configuration
1776 * @netdev: the netdev in question
1777 * @wol: the ethtool WoL setting data
1778 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001779static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1780{
1781 struct i40e_netdev_priv *np = netdev_priv(netdev);
1782 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001783 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001784 struct i40e_hw *hw = &pf->hw;
1785 u16 wol_nvm_bits;
1786
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001787 /* WoL not supported if this isn't the controlling PF on the port */
1788 if (hw->partition_id != 1) {
1789 i40e_partition_setting_complaint(pf);
1790 return -EOPNOTSUPP;
1791 }
1792
1793 if (vsi != pf->vsi[pf->lan_vsi])
1794 return -EOPNOTSUPP;
1795
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001796 /* NVM bit on means WoL disabled for the port */
1797 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001798 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001799 return -EOPNOTSUPP;
1800
1801 /* only magic packet is supported */
1802 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1803 return -EOPNOTSUPP;
1804
1805 /* is this a new value? */
1806 if (pf->wol_en != !!wol->wolopts) {
1807 pf->wol_en = !!wol->wolopts;
1808 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1809 }
1810
1811 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812}
1813
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001814static int i40e_set_phys_id(struct net_device *netdev,
1815 enum ethtool_phys_id_state state)
1816{
1817 struct i40e_netdev_priv *np = netdev_priv(netdev);
1818 struct i40e_pf *pf = np->vsi->back;
1819 struct i40e_hw *hw = &pf->hw;
1820 int blink_freq = 2;
1821
1822 switch (state) {
1823 case ETHTOOL_ID_ACTIVE:
1824 pf->led_status = i40e_led_get(hw);
1825 return blink_freq;
1826 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001827 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001828 break;
1829 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001830 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001831 break;
1832 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001833 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001834 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001835 default:
1836 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001837 }
1838
1839 return 0;
1840}
1841
1842/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1843 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1844 * 125us (8000 interrupts per second) == ITR(62)
1845 */
1846
1847static int i40e_get_coalesce(struct net_device *netdev,
1848 struct ethtool_coalesce *ec)
1849{
1850 struct i40e_netdev_priv *np = netdev_priv(netdev);
1851 struct i40e_vsi *vsi = np->vsi;
1852
1853 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1854 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1855
1856 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001857 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001858
1859 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001860 ec->use_adaptive_tx_coalesce = 1;
1861
1862 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1863 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001864 /* we use the _usecs_high to store/set the interrupt rate limit
1865 * that the hardware supports, that almost but not quite
1866 * fits the original intent of the ethtool variable,
1867 * the rx_coalesce_usecs_high limits total interrupts
1868 * per second from both tx/rx sources.
1869 */
1870 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1871 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001872
1873 return 0;
1874}
1875
1876static int i40e_set_coalesce(struct net_device *netdev,
1877 struct ethtool_coalesce *ec)
1878{
1879 struct i40e_netdev_priv *np = netdev_priv(netdev);
1880 struct i40e_q_vector *q_vector;
1881 struct i40e_vsi *vsi = np->vsi;
1882 struct i40e_pf *pf = vsi->back;
1883 struct i40e_hw *hw = &pf->hw;
1884 u16 vector;
1885 int i;
1886
1887 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1888 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1889
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001890 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1891 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1892 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1893 return -EINVAL;
1894 }
1895
1896 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1897 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1898 return -EINVAL;
1899 }
1900
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001901 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001902 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001903 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001904 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001905 } else if (ec->rx_coalesce_usecs == 0) {
1906 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001907 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001908 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 +00001909 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001910 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001911 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001912 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001913
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001914 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1915
Mitch Williams32f5f542014-04-04 04:43:10 +00001916 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001917 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001918 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001919 } else if (ec->tx_coalesce_usecs == 0) {
1920 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001921 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001922 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 +00001923 } else {
1924 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001925 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001926 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001927 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001928
1929 if (ec->use_adaptive_rx_coalesce)
1930 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1931 else
1932 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1933
1934 if (ec->use_adaptive_tx_coalesce)
1935 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1936 else
1937 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001938
Alexander Duyck493fb302013-09-28 07:01:44 +00001939 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001940 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1941
Alexander Duyck493fb302013-09-28 07:01:44 +00001942 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001943 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1944 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1945 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1946 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001947 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948 i40e_flush(hw);
1949 }
1950
1951 return 0;
1952}
1953
1954/**
1955 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1956 * @pf: pointer to the physical function struct
1957 * @cmd: ethtool rxnfc command
1958 *
1959 * Returns Success if the flow is supported, else Invalid Input.
1960 **/
1961static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1962{
1963 cmd->data = 0;
1964
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001965 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1966 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1967 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1968 return 0;
1969 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001970 /* Report default options for RSS on i40e */
1971 switch (cmd->flow_type) {
1972 case TCP_V4_FLOW:
1973 case UDP_V4_FLOW:
1974 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1975 /* fall through to add IP fields */
1976 case SCTP_V4_FLOW:
1977 case AH_ESP_V4_FLOW:
1978 case AH_V4_FLOW:
1979 case ESP_V4_FLOW:
1980 case IPV4_FLOW:
1981 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1982 break;
1983 case TCP_V6_FLOW:
1984 case UDP_V6_FLOW:
1985 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1986 /* fall through to add IP fields */
1987 case SCTP_V6_FLOW:
1988 case AH_ESP_V6_FLOW:
1989 case AH_V6_FLOW:
1990 case ESP_V6_FLOW:
1991 case IPV6_FLOW:
1992 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1993 break;
1994 default:
1995 return -EINVAL;
1996 }
1997
1998 return 0;
1999}
2000
2001/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002002 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2003 * @pf: Pointer to the physical function struct
2004 * @cmd: The command to get or set Rx flow classification rules
2005 * @rule_locs: Array of used rule locations
2006 *
2007 * This function populates both the total and actual rule count of
2008 * the ethtool flow classification command
2009 *
2010 * Returns 0 on success or -EMSGSIZE if entry not found
2011 **/
2012static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2013 struct ethtool_rxnfc *cmd,
2014 u32 *rule_locs)
2015{
2016 struct i40e_fdir_filter *rule;
2017 struct hlist_node *node2;
2018 int cnt = 0;
2019
2020 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002021 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002022
2023 hlist_for_each_entry_safe(rule, node2,
2024 &pf->fdir_filter_list, fdir_node) {
2025 if (cnt == cmd->rule_cnt)
2026 return -EMSGSIZE;
2027
2028 rule_locs[cnt] = rule->fd_id;
2029 cnt++;
2030 }
2031
2032 cmd->rule_cnt = cnt;
2033
2034 return 0;
2035}
2036
2037/**
2038 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2039 * @pf: Pointer to the physical function struct
2040 * @cmd: The command to get or set Rx flow classification rules
2041 *
2042 * This function looks up a filter based on the Rx flow classification
2043 * command and fills the flow spec info for it if found
2044 *
2045 * Returns 0 on success or -EINVAL if filter not found
2046 **/
2047static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2048 struct ethtool_rxnfc *cmd)
2049{
2050 struct ethtool_rx_flow_spec *fsp =
2051 (struct ethtool_rx_flow_spec *)&cmd->fs;
2052 struct i40e_fdir_filter *rule = NULL;
2053 struct hlist_node *node2;
2054
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002055 hlist_for_each_entry_safe(rule, node2,
2056 &pf->fdir_filter_list, fdir_node) {
2057 if (fsp->location <= rule->fd_id)
2058 break;
2059 }
2060
2061 if (!rule || fsp->location != rule->fd_id)
2062 return -EINVAL;
2063
2064 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002065 if (fsp->flow_type == IP_USER_FLOW) {
2066 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2067 fsp->h_u.usr_ip4_spec.proto = 0;
2068 fsp->m_u.usr_ip4_spec.proto = 0;
2069 }
2070
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002071 /* Reverse the src and dest notion, since the HW views them from
2072 * Tx perspective where as the user expects it from Rx filter view.
2073 */
2074 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2075 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2076 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2077 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002078
2079 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2080 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2081 else
2082 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002083
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002084 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2085 struct i40e_vsi *vsi;
2086
2087 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2088 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2089 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2090 fsp->m_ext.data[1] = htonl(0x1);
2091 }
2092 }
2093
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002094 return 0;
2095}
2096
2097/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002098 * i40e_get_rxnfc - command to get RX flow classification rules
2099 * @netdev: network interface device structure
2100 * @cmd: ethtool rxnfc command
2101 *
2102 * Returns Success if the command is supported.
2103 **/
2104static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2105 u32 *rule_locs)
2106{
2107 struct i40e_netdev_priv *np = netdev_priv(netdev);
2108 struct i40e_vsi *vsi = np->vsi;
2109 struct i40e_pf *pf = vsi->back;
2110 int ret = -EOPNOTSUPP;
2111
2112 switch (cmd->cmd) {
2113 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002114 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002115 ret = 0;
2116 break;
2117 case ETHTOOL_GRXFH:
2118 ret = i40e_get_rss_hash_opts(pf, cmd);
2119 break;
2120 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002121 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002122 /* report total rule count */
2123 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002124 ret = 0;
2125 break;
2126 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002127 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002128 break;
2129 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002130 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2131 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002132 default:
2133 break;
2134 }
2135
2136 return ret;
2137}
2138
2139/**
2140 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2141 * @pf: pointer to the physical function struct
2142 * @cmd: ethtool rxnfc command
2143 *
2144 * Returns Success if the flow input set is supported.
2145 **/
2146static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2147{
2148 struct i40e_hw *hw = &pf->hw;
2149 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2150 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2151
2152 /* RSS does not support anything other than hashing
2153 * to queues on src and dst IPs and ports
2154 */
2155 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2156 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2157 return -EINVAL;
2158
2159 /* We need at least the IP SRC and DEST fields for hashing */
2160 if (!(nfc->data & RXH_IP_SRC) ||
2161 !(nfc->data & RXH_IP_DST))
2162 return -EINVAL;
2163
2164 switch (nfc->flow_type) {
2165 case TCP_V4_FLOW:
2166 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2167 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002168 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002169 break;
2170 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002171 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 break;
2173 default:
2174 return -EINVAL;
2175 }
2176 break;
2177 case TCP_V6_FLOW:
2178 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2179 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002180 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002181 break;
2182 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002183 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 break;
2185 default:
2186 return -EINVAL;
2187 }
2188 break;
2189 case UDP_V4_FLOW:
2190 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2191 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002192 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2193 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002194 break;
2195 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002196 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2197 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198 break;
2199 default:
2200 return -EINVAL;
2201 }
2202 break;
2203 case UDP_V6_FLOW:
2204 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2205 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002206 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2207 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002208 break;
2209 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002210 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2211 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212 break;
2213 default:
2214 return -EINVAL;
2215 }
2216 break;
2217 case AH_ESP_V4_FLOW:
2218 case AH_V4_FLOW:
2219 case ESP_V4_FLOW:
2220 case SCTP_V4_FLOW:
2221 if ((nfc->data & RXH_L4_B_0_1) ||
2222 (nfc->data & RXH_L4_B_2_3))
2223 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002224 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225 break;
2226 case AH_ESP_V6_FLOW:
2227 case AH_V6_FLOW:
2228 case ESP_V6_FLOW:
2229 case SCTP_V6_FLOW:
2230 if ((nfc->data & RXH_L4_B_0_1) ||
2231 (nfc->data & RXH_L4_B_2_3))
2232 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002233 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002234 break;
2235 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002236 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2237 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002238 break;
2239 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002240 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2241 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242 break;
2243 default:
2244 return -EINVAL;
2245 }
2246
2247 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2248 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2249 i40e_flush(hw);
2250
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002251 /* Save setting for future output/update */
2252 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2253
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002254 return 0;
2255}
2256
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002257/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002258 * i40e_match_fdir_input_set - Match a new filter against an existing one
2259 * @rule: The filter already added
2260 * @input: The new filter to comapre against
2261 *
2262 * Returns true if the two input set match
2263 **/
2264static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2265 struct i40e_fdir_filter *input)
2266{
2267 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2268 (rule->src_ip[0] != input->src_ip[0]) ||
2269 (rule->dst_port != input->dst_port) ||
2270 (rule->src_port != input->src_port))
2271 return false;
2272 return true;
2273}
2274
2275/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002276 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2277 * @vsi: Pointer to the targeted VSI
2278 * @input: The filter to update or NULL to indicate deletion
2279 * @sw_idx: Software index to the filter
2280 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002282 * This function updates (or deletes) a Flow Director entry from
2283 * the hlist of the corresponding PF
2284 *
2285 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002286 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002287static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2288 struct i40e_fdir_filter *input,
2289 u16 sw_idx,
2290 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002291{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002292 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002293 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002294 struct hlist_node *node2;
2295 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002296
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002297 parent = NULL;
2298 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002299
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002300 hlist_for_each_entry_safe(rule, node2,
2301 &pf->fdir_filter_list, fdir_node) {
2302 /* hash found, or no matching entry */
2303 if (rule->fd_id >= sw_idx)
2304 break;
2305 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002306 }
2307
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002308 /* if there is an old rule occupying our place remove it */
2309 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002310 if (input && !i40e_match_fdir_input_set(rule, input))
2311 err = i40e_add_del_fdir(vsi, rule, false);
2312 else if (!input)
2313 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002314 hlist_del(&rule->fdir_node);
2315 kfree(rule);
2316 pf->fdir_pf_active_filters--;
2317 }
2318
2319 /* If no input this was a delete, err should be 0 if a rule was
2320 * successfully found and removed from the list else -EINVAL
2321 */
2322 if (!input)
2323 return err;
2324
2325 /* initialize node and set software index */
2326 INIT_HLIST_NODE(&input->fdir_node);
2327
2328 /* add filter to the list */
2329 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002330 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002331 else
2332 hlist_add_head(&input->fdir_node,
2333 &pf->fdir_filter_list);
2334
2335 /* update counts */
2336 pf->fdir_pf_active_filters++;
2337
2338 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002339}
2340
2341/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002342 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2343 * @vsi: Pointer to the targeted VSI
2344 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002345 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002346 * The function removes a Flow Director filter entry from the
2347 * hlist of the corresponding PF
2348 *
2349 * Returns 0 on success
2350 */
2351static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2352 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002353{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002354 struct ethtool_rx_flow_spec *fsp =
2355 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002356 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002357 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002358
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002359 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2360 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2361 return -EBUSY;
2362
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002363 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2364 return -EBUSY;
2365
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002366 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002367
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002368 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002369 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002370}
2371
2372/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002373 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002374 * @vsi: pointer to the targeted VSI
2375 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002376 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002377 * Add Flow Director filters for a specific flow spec based on their
2378 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002379 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002380static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2381 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002382{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002383 struct ethtool_rx_flow_spec *fsp;
2384 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002385 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002386 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002387 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002388
2389 if (!vsi)
2390 return -EINVAL;
2391
2392 pf = vsi->back;
2393
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002394 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2395 return -EOPNOTSUPP;
2396
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002397 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002398 return -ENOSPC;
2399
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002400 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2401 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2402 return -EBUSY;
2403
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002404 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2405 return -EBUSY;
2406
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002407 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2408
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002409 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2410 pf->hw.func_caps.fd_filters_guaranteed)) {
2411 return -EINVAL;
2412 }
2413
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002414 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2415 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002416 return -EINVAL;
2417
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002418 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002419
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002420 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002421 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002422
2423 input->fd_id = fsp->location;
2424
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002425 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2426 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2427 else
2428 input->dest_ctl =
2429 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2430
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002431 input->q_index = fsp->ring_cookie;
2432 input->flex_off = 0;
2433 input->pctype = 0;
2434 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002435 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002436 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002437 input->flow_type = fsp->flow_type;
2438 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002439
2440 /* Reverse the src and dest notion, since the HW expects them to be from
2441 * Tx perspective where as the input from user is from Rx filter view.
2442 */
2443 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2444 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2445 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2446 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002447
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002448 if (ntohl(fsp->m_ext.data[1])) {
2449 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2450 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2451 goto free_input;
2452 }
2453 vf_id = ntohl(fsp->h_ext.data[1]);
2454 /* Find vsi id from vf id and override dest vsi */
2455 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2456 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2457 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2458 goto free_input;
2459 }
2460 }
2461
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002462 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002463free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002464 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002465 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002466 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002467 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002468
2469 return ret;
2470}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002471
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002472/**
2473 * i40e_set_rxnfc - command to set RX flow classification rules
2474 * @netdev: network interface device structure
2475 * @cmd: ethtool rxnfc command
2476 *
2477 * Returns Success if the command is supported.
2478 **/
2479static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2480{
2481 struct i40e_netdev_priv *np = netdev_priv(netdev);
2482 struct i40e_vsi *vsi = np->vsi;
2483 struct i40e_pf *pf = vsi->back;
2484 int ret = -EOPNOTSUPP;
2485
2486 switch (cmd->cmd) {
2487 case ETHTOOL_SRXFH:
2488 ret = i40e_set_rss_hash_opt(pf, cmd);
2489 break;
2490 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002491 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002492 break;
2493 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002494 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002495 break;
2496 default:
2497 break;
2498 }
2499
2500 return ret;
2501}
2502
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002503/**
2504 * i40e_max_channels - get Max number of combined channels supported
2505 * @vsi: vsi pointer
2506 **/
2507static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2508{
2509 /* TODO: This code assumes DCB and FD is disabled for now. */
2510 return vsi->alloc_queue_pairs;
2511}
2512
2513/**
2514 * i40e_get_channels - Get the current channels enabled and max supported etc.
2515 * @netdev: network interface device structure
2516 * @ch: ethtool channels structure
2517 *
2518 * We don't support separate tx and rx queues as channels. The other count
2519 * represents how many queues are being used for control. max_combined counts
2520 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2521 * q_vectors since we support a lot more queue pairs than q_vectors.
2522 **/
2523static void i40e_get_channels(struct net_device *dev,
2524 struct ethtool_channels *ch)
2525{
2526 struct i40e_netdev_priv *np = netdev_priv(dev);
2527 struct i40e_vsi *vsi = np->vsi;
2528 struct i40e_pf *pf = vsi->back;
2529
2530 /* report maximum channels */
2531 ch->max_combined = i40e_max_channels(vsi);
2532
2533 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002534 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002535 ch->max_other = ch->other_count;
2536
2537 /* Note: This code assumes DCB is disabled for now. */
2538 ch->combined_count = vsi->num_queue_pairs;
2539}
2540
2541/**
2542 * i40e_set_channels - Set the new channels count.
2543 * @netdev: network interface device structure
2544 * @ch: ethtool channels structure
2545 *
2546 * The new channels count may not be the same as requested by the user
2547 * since it gets rounded down to a power of 2 value.
2548 **/
2549static int i40e_set_channels(struct net_device *dev,
2550 struct ethtool_channels *ch)
2551{
2552 struct i40e_netdev_priv *np = netdev_priv(dev);
2553 unsigned int count = ch->combined_count;
2554 struct i40e_vsi *vsi = np->vsi;
2555 struct i40e_pf *pf = vsi->back;
2556 int new_count;
2557
2558 /* We do not support setting channels for any other VSI at present */
2559 if (vsi->type != I40E_VSI_MAIN)
2560 return -EINVAL;
2561
2562 /* verify they are not requesting separate vectors */
2563 if (!count || ch->rx_count || ch->tx_count)
2564 return -EINVAL;
2565
2566 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002567 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002568 return -EINVAL;
2569
2570 /* verify the number of channels does not exceed hardware limits */
2571 if (count > i40e_max_channels(vsi))
2572 return -EINVAL;
2573
2574 /* update feature limits from largest to smallest supported values */
2575 /* TODO: Flow director limit, DCB etc */
2576
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002577 /* use rss_reconfig to rebuild with new queue count and update traffic
2578 * class queue mapping
2579 */
2580 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002581 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002582 return 0;
2583 else
2584 return -EINVAL;
2585}
2586
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002587#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2588/**
2589 * i40e_get_rxfh_key_size - get the RSS hash key size
2590 * @netdev: network interface device structure
2591 *
2592 * Returns the table size.
2593 **/
2594static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2595{
2596 return I40E_HKEY_ARRAY_SIZE;
2597}
2598
2599/**
2600 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2601 * @netdev: network interface device structure
2602 *
2603 * Returns the table size.
2604 **/
2605static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2606{
2607 return I40E_HLUT_ARRAY_SIZE;
2608}
2609
2610static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2611 u8 *hfunc)
2612{
2613 struct i40e_netdev_priv *np = netdev_priv(netdev);
2614 struct i40e_vsi *vsi = np->vsi;
2615 struct i40e_pf *pf = vsi->back;
2616 struct i40e_hw *hw = &pf->hw;
2617 u32 reg_val;
2618 int i, j;
2619
2620 if (hfunc)
2621 *hfunc = ETH_RSS_HASH_TOP;
2622
2623 if (!indir)
2624 return 0;
2625
2626 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2627 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2628 indir[j++] = reg_val & 0xff;
2629 indir[j++] = (reg_val >> 8) & 0xff;
2630 indir[j++] = (reg_val >> 16) & 0xff;
2631 indir[j++] = (reg_val >> 24) & 0xff;
2632 }
2633
2634 if (key) {
2635 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2636 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2637 key[j++] = (u8)(reg_val & 0xff);
2638 key[j++] = (u8)((reg_val >> 8) & 0xff);
2639 key[j++] = (u8)((reg_val >> 16) & 0xff);
2640 key[j++] = (u8)((reg_val >> 24) & 0xff);
2641 }
2642 }
2643 return 0;
2644}
2645
2646/**
2647 * i40e_set_rxfh - set the rx flow hash indirection table
2648 * @netdev: network interface device structure
2649 * @indir: indirection table
2650 * @key: hash key
2651 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002652 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002653 * returns 0 after programming the table.
2654 **/
2655static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2656 const u8 *key, const u8 hfunc)
2657{
2658 struct i40e_netdev_priv *np = netdev_priv(netdev);
2659 struct i40e_vsi *vsi = np->vsi;
2660 struct i40e_pf *pf = vsi->back;
2661 struct i40e_hw *hw = &pf->hw;
2662 u32 reg_val;
2663 int i, j;
2664
2665 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2666 return -EOPNOTSUPP;
2667
2668 if (!indir)
2669 return 0;
2670
2671 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2672 reg_val = indir[j++];
2673 reg_val |= indir[j++] << 8;
2674 reg_val |= indir[j++] << 16;
2675 reg_val |= indir[j++] << 24;
2676 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2677 }
2678
2679 if (key) {
2680 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2681 reg_val = key[j++];
2682 reg_val |= key[j++] << 8;
2683 reg_val |= key[j++] << 16;
2684 reg_val |= key[j++] << 24;
2685 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2686 }
2687 }
2688 return 0;
2689}
2690
Greg Rose7e45ab42015-02-06 08:52:19 +00002691/**
2692 * i40e_get_priv_flags - report device private flags
2693 * @dev: network interface device structure
2694 *
2695 * The get string set count and the string set should be matched for each
2696 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2697 * array.
2698 *
2699 * Returns a u32 bitmap of flags.
2700 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002701static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002702{
2703 struct i40e_netdev_priv *np = netdev_priv(dev);
2704 struct i40e_vsi *vsi = np->vsi;
2705 struct i40e_pf *pf = vsi->back;
2706 u32 ret_flags = 0;
2707
2708 ret_flags |= pf->hw.func_caps.npar_enable ?
2709 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002710 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2711 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002712 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2713 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002714 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2715 I40E_PRIV_FLAGS_VEB_STATS : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002716
2717 return ret_flags;
2718}
2719
Shannon Nelson9ac77262015-08-27 11:42:40 -04002720/**
2721 * i40e_set_priv_flags - set private flags
2722 * @dev: network interface device structure
2723 * @flags: bit flags to be set
2724 **/
2725static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2726{
2727 struct i40e_netdev_priv *np = netdev_priv(dev);
2728 struct i40e_vsi *vsi = np->vsi;
2729 struct i40e_pf *pf = vsi->back;
2730
2731 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2732 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2733 else
2734 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2735
Jesse Brandeburgef171782015-09-03 17:18:49 -04002736 /* allow the user to control the state of the Flow
2737 * Director ATR (Application Targeted Routing) feature
2738 * of the driver
2739 */
2740 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2741 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2742 } else {
2743 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2744 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2745 }
2746
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002747 if (flags & I40E_PRIV_FLAGS_VEB_STATS)
2748 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2749 else
2750 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2751
Shannon Nelson9ac77262015-08-27 11:42:40 -04002752 return 0;
2753}
2754
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002755static const struct ethtool_ops i40e_ethtool_ops = {
2756 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002757 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002758 .get_drvinfo = i40e_get_drvinfo,
2759 .get_regs_len = i40e_get_regs_len,
2760 .get_regs = i40e_get_regs,
2761 .nway_reset = i40e_nway_reset,
2762 .get_link = ethtool_op_get_link,
2763 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002764 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002765 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002766 .get_eeprom_len = i40e_get_eeprom_len,
2767 .get_eeprom = i40e_get_eeprom,
2768 .get_ringparam = i40e_get_ringparam,
2769 .set_ringparam = i40e_set_ringparam,
2770 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002771 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002772 .get_msglevel = i40e_get_msglevel,
2773 .set_msglevel = i40e_set_msglevel,
2774 .get_rxnfc = i40e_get_rxnfc,
2775 .set_rxnfc = i40e_set_rxnfc,
2776 .self_test = i40e_diag_test,
2777 .get_strings = i40e_get_strings,
2778 .set_phys_id = i40e_set_phys_id,
2779 .get_sset_count = i40e_get_sset_count,
2780 .get_ethtool_stats = i40e_get_ethtool_stats,
2781 .get_coalesce = i40e_get_coalesce,
2782 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002783 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2784 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2785 .get_rxfh = i40e_get_rxfh,
2786 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002787 .get_channels = i40e_get_channels,
2788 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002789 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002790 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002791 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002792};
2793
2794void i40e_set_ethtool_ops(struct net_device *netdev)
2795{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002796 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002797}