blob: 415aebceed9ab2abd322dabc7b45b3a513286a3d [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),
Shannon Nelson41a9e552014-04-23 04:50:20 +000090};
91
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000092static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
93 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000094
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000095/* These PF_STATs might look like duplicates of some NETDEV_STATs,
96 * but they are separate. This device supports Virtualization, and
97 * as such might have several netdevs supporting VMDq and FCoE going
98 * through a single port. The NETDEV_STATs are for individual netdevs
99 * seen at the top of the stack, and the PF_STATs are for the physical
100 * function at the bottom of the stack hosting those netdevs.
101 *
102 * The PF_STATs are appended to the netdev stats only when ethtool -S
103 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104 */
105static struct i40e_stats i40e_gstrings_stats[] = {
106 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
107 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000108 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
109 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
110 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
111 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
112 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
113 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000114 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
115 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000152 /* LPI stats */
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000157};
158
Vasu Dev38e00432014-08-01 13:27:03 -0700159#ifdef I40E_FCOE
160static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
169};
170
171#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000178#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700179#ifdef I40E_FCOE
180#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
185#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000187 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700189#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
196 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000197#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
201
202enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
205 I40E_ETH_TEST_INTR,
206 I40E_ETH_TEST_LOOPBACK,
207 I40E_ETH_TEST_LINK,
208};
209
210static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
216};
217
218#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
219
Greg Rose7e45ab42015-02-06 08:52:19 +0000220static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
221 "NPAR",
222};
223
224#define I40E_PRIV_FLAGS_STR_LEN \
225 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
226
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000227/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000228 * i40e_partition_setting_complaint - generic complaint for MFP restriction
229 * @pf: the PF struct
230 **/
231static void i40e_partition_setting_complaint(struct i40e_pf *pf)
232{
233 dev_info(&pf->pdev->dev,
234 "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");
235}
236
237/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000238 * i40e_get_settings_link_up - Get the Link settings for when link is up
239 * @hw: hw structure
240 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000241 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000243 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000244static void i40e_get_settings_link_up(struct i40e_hw *hw,
245 struct ethtool_cmd *ecmd,
246 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000247{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000248 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000249 u32 link_speed = hw_link_info->link_speed;
250
Catherine Sullivane8278452015-02-06 08:52:08 +0000251 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 switch (hw_link_info->phy_type) {
253 case I40E_PHY_TYPE_40GBASE_CR4:
254 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000255 ecmd->supported = SUPPORTED_Autoneg |
256 SUPPORTED_40000baseCR4_Full;
257 ecmd->advertising = ADVERTISED_Autoneg |
258 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000260 case I40E_PHY_TYPE_XLAUI:
261 case I40E_PHY_TYPE_XLPPI:
262 ecmd->supported = SUPPORTED_40000baseCR4_Full;
263 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000264 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000265 ecmd->supported = SUPPORTED_Autoneg |
266 SUPPORTED_40000baseKR4_Full;
267 ecmd->advertising = ADVERTISED_Autoneg |
268 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000269 break;
270 case I40E_PHY_TYPE_40GBASE_SR4:
271 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000272 break;
273 case I40E_PHY_TYPE_40GBASE_LR4:
274 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000275 break;
276 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000277 ecmd->supported = SUPPORTED_Autoneg |
278 SUPPORTED_10000baseKX4_Full;
279 ecmd->advertising = ADVERTISED_Autoneg |
280 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000281 break;
282 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000283 ecmd->supported = SUPPORTED_Autoneg |
284 SUPPORTED_10000baseKR_Full;
285 ecmd->advertising = ADVERTISED_Autoneg |
286 ADVERTISED_10000baseKR_Full;
287 break;
288 case I40E_PHY_TYPE_10GBASE_SR:
289 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000290 case I40E_PHY_TYPE_1000BASE_SX:
291 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000292 ecmd->supported = SUPPORTED_10000baseT_Full |
293 SUPPORTED_1000baseT_Full;
294 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
295 ecmd->advertising |= ADVERTISED_10000baseT_Full;
296 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
297 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000298 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000299 case I40E_PHY_TYPE_1000BASE_KX:
300 ecmd->supported = SUPPORTED_Autoneg |
301 SUPPORTED_1000baseKX_Full;
302 ecmd->advertising = ADVERTISED_Autoneg |
303 ADVERTISED_1000baseKX_Full;
304 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000305 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000306 case I40E_PHY_TYPE_1000BASE_T:
307 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000308 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000309 SUPPORTED_10000baseT_Full |
310 SUPPORTED_1000baseT_Full |
311 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000312 ecmd->advertising = ADVERTISED_Autoneg;
313 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
314 ecmd->advertising |= ADVERTISED_10000baseT_Full;
315 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
316 ecmd->advertising |= ADVERTISED_1000baseT_Full;
317 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
318 ecmd->advertising |= ADVERTISED_100baseT_Full;
319 break;
320 case I40E_PHY_TYPE_10GBASE_CR1_CU:
321 case I40E_PHY_TYPE_10GBASE_CR1:
322 ecmd->supported = SUPPORTED_Autoneg |
323 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000324 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000325 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000326 break;
327 case I40E_PHY_TYPE_XAUI:
328 case I40E_PHY_TYPE_XFI:
329 case I40E_PHY_TYPE_SFI:
330 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
331 ecmd->supported = SUPPORTED_10000baseT_Full;
332 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000333 case I40E_PHY_TYPE_SGMII:
334 ecmd->supported = SUPPORTED_Autoneg |
335 SUPPORTED_1000baseT_Full |
336 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000337 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
338 ecmd->advertising |= ADVERTISED_1000baseT_Full;
339 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
340 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000341 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000342 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000343 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000344 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
345 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000346 }
347
Catherine Sullivane8278452015-02-06 08:52:08 +0000348 /* Set speed and duplex */
349 switch (link_speed) {
350 case I40E_LINK_SPEED_40GB:
351 /* need a SPEED_40000 in ethtool.h */
352 ethtool_cmd_speed_set(ecmd, 40000);
353 break;
354 case I40E_LINK_SPEED_10GB:
355 ethtool_cmd_speed_set(ecmd, SPEED_10000);
356 break;
357 case I40E_LINK_SPEED_1GB:
358 ethtool_cmd_speed_set(ecmd, SPEED_1000);
359 break;
360 case I40E_LINK_SPEED_100MB:
361 ethtool_cmd_speed_set(ecmd, SPEED_100);
362 break;
363 default:
364 break;
365 }
366 ecmd->duplex = DUPLEX_FULL;
367}
368
369/**
370 * i40e_get_settings_link_down - Get the Link settings for when link is down
371 * @hw: hw structure
372 * @ecmd: ethtool command to fill in
373 *
374 * Reports link settings that can be determined when link is down
375 **/
376static void i40e_get_settings_link_down(struct i40e_hw *hw,
377 struct ethtool_cmd *ecmd)
378{
379 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
380
381 /* link is down and the driver needs to fall back on
382 * device ID to determine what kinds of info to display,
383 * it's mostly a guess that may change when link is up
384 */
385 switch (hw->device_id) {
386 case I40E_DEV_ID_QSFP_A:
387 case I40E_DEV_ID_QSFP_B:
388 case I40E_DEV_ID_QSFP_C:
389 /* pluggable QSFP */
390 ecmd->supported = SUPPORTED_40000baseSR4_Full |
391 SUPPORTED_40000baseCR4_Full |
392 SUPPORTED_40000baseLR4_Full;
393 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
394 ADVERTISED_40000baseCR4_Full |
395 ADVERTISED_40000baseLR4_Full;
396 break;
397 case I40E_DEV_ID_KX_B:
398 /* backplane 40G */
399 ecmd->supported = SUPPORTED_40000baseKR4_Full;
400 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
401 break;
402 case I40E_DEV_ID_KX_C:
403 /* backplane 10G */
404 ecmd->supported = SUPPORTED_10000baseKR_Full;
405 ecmd->advertising = ADVERTISED_10000baseKR_Full;
406 break;
407 case I40E_DEV_ID_10G_BASE_T:
408 ecmd->supported = SUPPORTED_10000baseT_Full |
409 SUPPORTED_1000baseT_Full |
410 SUPPORTED_100baseT_Full;
411 /* Figure out what has been requested */
412 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
413 ecmd->advertising |= ADVERTISED_10000baseT_Full;
414 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
415 ecmd->advertising |= ADVERTISED_1000baseT_Full;
416 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
417 ecmd->advertising |= ADVERTISED_100baseT_Full;
418 break;
419 default:
420 /* all the rest are 10G/1G */
421 ecmd->supported = SUPPORTED_10000baseT_Full |
422 SUPPORTED_1000baseT_Full;
423 /* Figure out what has been requested */
424 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
425 ecmd->advertising |= ADVERTISED_10000baseT_Full;
426 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
427 ecmd->advertising |= ADVERTISED_1000baseT_Full;
428 break;
429 }
430
431 /* With no link speed and duplex are unknown */
432 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
433 ecmd->duplex = DUPLEX_UNKNOWN;
434}
435
436/**
437 * i40e_get_settings - Get Link Speed and Duplex settings
438 * @netdev: network interface device structure
439 * @ecmd: ethtool command
440 *
441 * Reports speed/duplex settings based on media_type
442 **/
443static int i40e_get_settings(struct net_device *netdev,
444 struct ethtool_cmd *ecmd)
445{
446 struct i40e_netdev_priv *np = netdev_priv(netdev);
447 struct i40e_pf *pf = np->vsi->back;
448 struct i40e_hw *hw = &pf->hw;
449 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
450 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
451
452 if (link_up)
453 i40e_get_settings_link_up(hw, ecmd, netdev);
454 else
455 i40e_get_settings_link_down(hw, ecmd);
456
457 /* Now set the settings that don't rely on link being up/down */
458
459 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000460 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
461 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000462
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000463 switch (hw->phy.media_type) {
464 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000465 ecmd->supported |= SUPPORTED_Autoneg |
466 SUPPORTED_Backplane;
467 ecmd->advertising |= ADVERTISED_Autoneg |
468 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000469 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000470 break;
471 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000472 ecmd->supported |= SUPPORTED_TP;
473 ecmd->advertising |= ADVERTISED_TP;
474 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000475 break;
476 case I40E_MEDIA_TYPE_DA:
477 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000478 ecmd->supported |= SUPPORTED_FIBRE;
479 ecmd->advertising |= ADVERTISED_FIBRE;
480 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000481 break;
482 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000484 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000485 break;
486 case I40E_MEDIA_TYPE_UNKNOWN:
487 default:
488 ecmd->port = PORT_OTHER;
489 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490 }
491
Catherine Sullivane8278452015-02-06 08:52:08 +0000492 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000493 ecmd->transceiver = XCVR_EXTERNAL;
494
Catherine Sullivane8278452015-02-06 08:52:08 +0000495 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000496 ecmd->supported |= SUPPORTED_Pause;
497
Catherine Sullivane8278452015-02-06 08:52:08 +0000498 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000499 case I40E_FC_FULL:
500 ecmd->advertising |= ADVERTISED_Pause;
501 break;
502 case I40E_FC_TX_PAUSE:
503 ecmd->advertising |= ADVERTISED_Asym_Pause;
504 break;
505 case I40E_FC_RX_PAUSE:
506 ecmd->advertising |= (ADVERTISED_Pause |
507 ADVERTISED_Asym_Pause);
508 break;
509 default:
510 ecmd->advertising &= ~(ADVERTISED_Pause |
511 ADVERTISED_Asym_Pause);
512 break;
513 }
514
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000515 return 0;
516}
517
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000518/**
519 * i40e_set_settings - Set Speed and Duplex
520 * @netdev: network interface device structure
521 * @ecmd: ethtool command
522 *
523 * Set speed/duplex per media_types advertised/forced
524 **/
525static int i40e_set_settings(struct net_device *netdev,
526 struct ethtool_cmd *ecmd)
527{
528 struct i40e_netdev_priv *np = netdev_priv(netdev);
529 struct i40e_aq_get_phy_abilities_resp abilities;
530 struct i40e_aq_set_phy_config config;
531 struct i40e_pf *pf = np->vsi->back;
532 struct i40e_vsi *vsi = np->vsi;
533 struct i40e_hw *hw = &pf->hw;
534 struct ethtool_cmd safe_ecmd;
535 i40e_status status = 0;
536 bool change = false;
537 int err = 0;
538 u8 autoneg;
539 u32 advertise;
540
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000541 /* Changing port settings is not supported if this isn't the
542 * port's controlling PF
543 */
544 if (hw->partition_id != 1) {
545 i40e_partition_setting_complaint(pf);
546 return -EOPNOTSUPP;
547 }
548
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000549 if (vsi != pf->vsi[pf->lan_vsi])
550 return -EOPNOTSUPP;
551
552 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
553 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000554 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
555 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000556 return -EOPNOTSUPP;
557
558 /* get our own copy of the bits to check against */
559 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
560 i40e_get_settings(netdev, &safe_ecmd);
561
562 /* save autoneg and speed out of ecmd */
563 autoneg = ecmd->autoneg;
564 advertise = ecmd->advertising;
565
566 /* set autoneg and speed back to what they currently are */
567 ecmd->autoneg = safe_ecmd.autoneg;
568 ecmd->advertising = safe_ecmd.advertising;
569
570 ecmd->cmd = safe_ecmd.cmd;
571 /* If ecmd and safe_ecmd are not the same now, then they are
572 * trying to set something that we do not support
573 */
574 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
575 return -EOPNOTSUPP;
576
577 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
578 usleep_range(1000, 2000);
579
580 /* Get the current phy config */
581 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
582 NULL);
583 if (status)
584 return -EAGAIN;
585
Catherine Sullivan124ed152014-07-12 07:28:12 +0000586 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000587 * set below
588 */
589 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000590 config.abilities = abilities.abilities;
591
592 /* Check autoneg */
593 if (autoneg == AUTONEG_ENABLE) {
594 /* If autoneg is not supported, return error */
595 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
596 netdev_info(netdev, "Autoneg not supported on this phy\n");
597 return -EINVAL;
598 }
599 /* If autoneg was not already enabled */
600 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
601 config.abilities = abilities.abilities |
602 I40E_AQ_PHY_ENABLE_AN;
603 change = true;
604 }
605 } else {
606 /* If autoneg is supported 10GBASE_T is the only phy that
607 * can disable it, so otherwise return error
608 */
609 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
610 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
611 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
612 return -EINVAL;
613 }
614 /* If autoneg is currently enabled */
615 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000616 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000617 ~I40E_AQ_PHY_ENABLE_AN;
618 change = true;
619 }
620 }
621
622 if (advertise & ~safe_ecmd.supported)
623 return -EINVAL;
624
625 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000626 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000627 if (advertise & ADVERTISED_1000baseT_Full ||
628 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000629 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000630 if (advertise & ADVERTISED_10000baseT_Full ||
631 advertise & ADVERTISED_10000baseKX4_Full ||
632 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000633 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000634 if (advertise & ADVERTISED_40000baseKR4_Full ||
635 advertise & ADVERTISED_40000baseCR4_Full ||
636 advertise & ADVERTISED_40000baseSR4_Full ||
637 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000638 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000639
Catherine Sullivan124ed152014-07-12 07:28:12 +0000640 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000641 /* copy over the rest of the abilities */
642 config.phy_type = abilities.phy_type;
643 config.eee_capability = abilities.eee_capability;
644 config.eeer = abilities.eeer_val;
645 config.low_power_ctrl = abilities.d3_lpan;
646
Catherine Sullivane8278452015-02-06 08:52:08 +0000647 /* save the requested speeds */
648 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000649 /* set link and auto negotiation so changes take effect */
650 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
651 /* If link is up put link down */
652 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
653 /* Tell the OS link is going down, the link will go
654 * back up when fw says it is ready asynchronously
655 */
656 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
657 netif_carrier_off(netdev);
658 netif_tx_stop_all_queues(netdev);
659 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000660
661 /* make the aq call */
662 status = i40e_aq_set_phy_config(hw, &config, NULL);
663 if (status) {
664 netdev_info(netdev, "Set phy config failed with error %d.\n",
665 status);
666 return -EAGAIN;
667 }
668
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000669 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000670 if (status)
671 netdev_info(netdev, "Updating link info failed with error %d\n",
672 status);
673
674 } else {
675 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
676 }
677
678 return err;
679}
680
Jesse Brandeburga6599722014-06-04 08:45:25 +0000681static int i40e_nway_reset(struct net_device *netdev)
682{
683 /* restart autonegotiation */
684 struct i40e_netdev_priv *np = netdev_priv(netdev);
685 struct i40e_pf *pf = np->vsi->back;
686 struct i40e_hw *hw = &pf->hw;
687 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
688 i40e_status ret = 0;
689
690 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
691 if (ret) {
692 netdev_info(netdev, "link restart failed, aq_err=%d\n",
693 pf->hw.aq.asq_last_status);
694 return -EIO;
695 }
696
697 return 0;
698}
699
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000700/**
701 * i40e_get_pauseparam - Get Flow Control status
702 * Return tx/rx-pause status
703 **/
704static void i40e_get_pauseparam(struct net_device *netdev,
705 struct ethtool_pauseparam *pause)
706{
707 struct i40e_netdev_priv *np = netdev_priv(netdev);
708 struct i40e_pf *pf = np->vsi->back;
709 struct i40e_hw *hw = &pf->hw;
710 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000711 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000712
713 pause->autoneg =
714 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
715 AUTONEG_ENABLE : AUTONEG_DISABLE);
716
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000717 /* PFC enabled so report LFC as off */
718 if (dcbx_cfg->pfc.pfcenable) {
719 pause->rx_pause = 0;
720 pause->tx_pause = 0;
721 return;
722 }
723
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000724 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000725 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000726 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000727 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000728 } else if (hw->fc.current_mode == I40E_FC_FULL) {
729 pause->rx_pause = 1;
730 pause->tx_pause = 1;
731 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000732}
733
Catherine Sullivan2becc352014-06-04 08:45:27 +0000734/**
735 * i40e_set_pauseparam - Set Flow Control parameter
736 * @netdev: network interface device structure
737 * @pause: return tx/rx flow control status
738 **/
739static int i40e_set_pauseparam(struct net_device *netdev,
740 struct ethtool_pauseparam *pause)
741{
742 struct i40e_netdev_priv *np = netdev_priv(netdev);
743 struct i40e_pf *pf = np->vsi->back;
744 struct i40e_vsi *vsi = np->vsi;
745 struct i40e_hw *hw = &pf->hw;
746 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000747 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000748 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
749 i40e_status status;
750 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000751 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000752
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000753 /* Changing the port's flow control is not supported if this isn't the
754 * port's controlling PF
755 */
756 if (hw->partition_id != 1) {
757 i40e_partition_setting_complaint(pf);
758 return -EOPNOTSUPP;
759 }
760
Catherine Sullivan2becc352014-06-04 08:45:27 +0000761 if (vsi != pf->vsi[pf->lan_vsi])
762 return -EOPNOTSUPP;
763
764 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
765 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
766 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
767 return -EOPNOTSUPP;
768 }
769
770 /* If we have link and don't have autoneg */
771 if (!test_bit(__I40E_DOWN, &pf->state) &&
772 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
773 /* Send message that it might not necessarily work*/
774 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
775 }
776
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000777 if (dcbx_cfg->pfc.pfcenable) {
778 netdev_info(netdev,
779 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000780 return -EOPNOTSUPP;
781 }
782
783 if (pause->rx_pause && pause->tx_pause)
784 hw->fc.requested_mode = I40E_FC_FULL;
785 else if (pause->rx_pause && !pause->tx_pause)
786 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
787 else if (!pause->rx_pause && pause->tx_pause)
788 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
789 else if (!pause->rx_pause && !pause->tx_pause)
790 hw->fc.requested_mode = I40E_FC_NONE;
791 else
792 return -EINVAL;
793
Catherine Sullivan94128512014-07-12 07:28:16 +0000794 /* Tell the OS link is going down, the link will go back up when fw
795 * says it is ready asynchronously
796 */
797 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
798 netif_carrier_off(netdev);
799 netif_tx_stop_all_queues(netdev);
800
Catherine Sullivan2becc352014-06-04 08:45:27 +0000801 /* Set the fc mode and only restart an if link is up*/
802 status = i40e_set_fc(hw, &aq_failures, link_up);
803
804 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
805 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
806 status, hw->aq.asq_last_status);
807 err = -EAGAIN;
808 }
809 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
810 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
811 status, hw->aq.asq_last_status);
812 err = -EAGAIN;
813 }
814 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000815 netdev_info(netdev, "Set fc failed on the get_link_info call with error %d and status %d\n",
Catherine Sullivan2becc352014-06-04 08:45:27 +0000816 status, hw->aq.asq_last_status);
817 err = -EAGAIN;
818 }
819
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000820 if (!test_bit(__I40E_DOWN, &pf->state)) {
821 /* Give it a little more time to try to come back */
822 msleep(75);
823 if (!test_bit(__I40E_DOWN, &pf->state))
824 return i40e_nway_reset(netdev);
825 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000826
827 return err;
828}
829
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000830static u32 i40e_get_msglevel(struct net_device *netdev)
831{
832 struct i40e_netdev_priv *np = netdev_priv(netdev);
833 struct i40e_pf *pf = np->vsi->back;
834
835 return pf->msg_enable;
836}
837
838static void i40e_set_msglevel(struct net_device *netdev, u32 data)
839{
840 struct i40e_netdev_priv *np = netdev_priv(netdev);
841 struct i40e_pf *pf = np->vsi->back;
842
843 if (I40E_DEBUG_USER & data)
844 pf->hw.debug_mask = data;
845 pf->msg_enable = data;
846}
847
848static int i40e_get_regs_len(struct net_device *netdev)
849{
850 int reg_count = 0;
851 int i;
852
853 for (i = 0; i40e_reg_list[i].offset != 0; i++)
854 reg_count += i40e_reg_list[i].elements;
855
856 return reg_count * sizeof(u32);
857}
858
859static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
860 void *p)
861{
862 struct i40e_netdev_priv *np = netdev_priv(netdev);
863 struct i40e_pf *pf = np->vsi->back;
864 struct i40e_hw *hw = &pf->hw;
865 u32 *reg_buf = p;
866 int i, j, ri;
867 u32 reg;
868
869 /* Tell ethtool which driver-version-specific regs output we have.
870 *
871 * At some point, if we have ethtool doing special formatting of
872 * this data, it will rely on this version number to know how to
873 * interpret things. Hence, this needs to be updated if/when the
874 * diags register table is changed.
875 */
876 regs->version = 1;
877
878 /* loop through the diags reg table for what to print */
879 ri = 0;
880 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
881 for (j = 0; j < i40e_reg_list[i].elements; j++) {
882 reg = i40e_reg_list[i].offset
883 + (j * i40e_reg_list[i].stride);
884 reg_buf[ri++] = rd32(hw, reg);
885 }
886 }
887
888}
889
890static int i40e_get_eeprom(struct net_device *netdev,
891 struct ethtool_eeprom *eeprom, u8 *bytes)
892{
893 struct i40e_netdev_priv *np = netdev_priv(netdev);
894 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000895 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000896 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000897 u8 *eeprom_buff;
898 u16 i, sectors;
899 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000900 u32 magic;
901
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000902#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000903 if (eeprom->len == 0)
904 return -EINVAL;
905
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000906 /* check for NVMUpdate access method */
907 magic = hw->vendor_id | (hw->device_id << 16);
908 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000909 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000910 int errno;
911
912 /* make sure it is the right magic for NVMUpdate */
913 if ((eeprom->magic >> 16) != hw->device_id)
914 return -EINVAL;
915
Shannon Nelsonc150a502014-11-13 08:23:13 +0000916 cmd = (struct i40e_nvm_access *)eeprom;
917 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000918 if (ret_val)
919 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000920 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
921 ret_val, hw->aq.asq_last_status, errno,
922 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
923 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000924
925 return errno;
926 }
927
928 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000929 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
930
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000931 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000932 if (!eeprom_buff)
933 return -ENOMEM;
934
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000935 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
936 if (ret_val) {
937 dev_info(&pf->pdev->dev,
938 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
939 ret_val, hw->aq.asq_last_status);
940 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000941 }
942
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000943 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
944 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
945 len = I40E_NVM_SECTOR_SIZE;
946 last = false;
947 for (i = 0; i < sectors; i++) {
948 if (i == (sectors - 1)) {
949 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
950 last = true;
951 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000952 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
953 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000954 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000955 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000956 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000957 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000958 "read NVM failed, invalid offset 0x%x\n",
959 offset);
960 break;
961 } else if (ret_val &&
962 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
963 dev_info(&pf->pdev->dev,
964 "read NVM failed, access, offset 0x%x\n",
965 offset);
966 break;
967 } else if (ret_val) {
968 dev_info(&pf->pdev->dev,
969 "read NVM failed offset %d err=%d status=0x%x\n",
970 offset, ret_val, hw->aq.asq_last_status);
971 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000972 }
973 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000974
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000975 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000976 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000977free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000978 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000979 return ret_val;
980}
981
982static int i40e_get_eeprom_len(struct net_device *netdev)
983{
984 struct i40e_netdev_priv *np = netdev_priv(netdev);
985 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000986 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000987
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000988 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
989 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
990 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
991 /* register returns value in power of 2, 64Kbyte chunks. */
992 val = (64 * 1024) * (1 << val);
993 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000994}
995
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000996static int i40e_set_eeprom(struct net_device *netdev,
997 struct ethtool_eeprom *eeprom, u8 *bytes)
998{
999 struct i40e_netdev_priv *np = netdev_priv(netdev);
1000 struct i40e_hw *hw = &np->vsi->back->hw;
1001 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001002 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001003 int ret_val = 0;
1004 int errno;
1005 u32 magic;
1006
1007 /* normal ethtool set_eeprom is not supported */
1008 magic = hw->vendor_id | (hw->device_id << 16);
1009 if (eeprom->magic == magic)
1010 return -EOPNOTSUPP;
1011
1012 /* check for NVMUpdate access method */
1013 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1014 return -EINVAL;
1015
1016 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1017 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1018 return -EBUSY;
1019
Shannon Nelsonc150a502014-11-13 08:23:13 +00001020 cmd = (struct i40e_nvm_access *)eeprom;
1021 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1022 if (ret_val && hw->aq.asq_last_status != I40E_AQ_RC_EBUSY)
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001023 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001024 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1025 ret_val, hw->aq.asq_last_status, errno,
1026 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1027 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001028
1029 return errno;
1030}
1031
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001032static void i40e_get_drvinfo(struct net_device *netdev,
1033 struct ethtool_drvinfo *drvinfo)
1034{
1035 struct i40e_netdev_priv *np = netdev_priv(netdev);
1036 struct i40e_vsi *vsi = np->vsi;
1037 struct i40e_pf *pf = vsi->back;
1038
1039 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1040 strlcpy(drvinfo->version, i40e_driver_version_str,
1041 sizeof(drvinfo->version));
1042 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1043 sizeof(drvinfo->fw_version));
1044 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1045 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001046 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001047}
1048
1049static void i40e_get_ringparam(struct net_device *netdev,
1050 struct ethtool_ringparam *ring)
1051{
1052 struct i40e_netdev_priv *np = netdev_priv(netdev);
1053 struct i40e_pf *pf = np->vsi->back;
1054 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1055
1056 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1057 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1058 ring->rx_mini_max_pending = 0;
1059 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001060 ring->rx_pending = vsi->rx_rings[0]->count;
1061 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001062 ring->rx_mini_pending = 0;
1063 ring->rx_jumbo_pending = 0;
1064}
1065
1066static int i40e_set_ringparam(struct net_device *netdev,
1067 struct ethtool_ringparam *ring)
1068{
1069 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1070 struct i40e_netdev_priv *np = netdev_priv(netdev);
1071 struct i40e_vsi *vsi = np->vsi;
1072 struct i40e_pf *pf = vsi->back;
1073 u32 new_rx_count, new_tx_count;
1074 int i, err = 0;
1075
1076 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1077 return -EINVAL;
1078
Shannon Nelson1fa18372013-11-20 10:03:08 +00001079 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1080 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1081 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1082 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1083 netdev_info(netdev,
1084 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1085 ring->tx_pending, ring->rx_pending,
1086 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1087 return -EINVAL;
1088 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001089
Shannon Nelson1fa18372013-11-20 10:03:08 +00001090 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1091 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001092
1093 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001094 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1095 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001096 return 0;
1097
1098 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1099 usleep_range(1000, 2000);
1100
1101 if (!netif_running(vsi->netdev)) {
1102 /* simple case - set for the next time the netdev is started */
1103 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001104 vsi->tx_rings[i]->count = new_tx_count;
1105 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001106 }
1107 goto done;
1108 }
1109
1110 /* We can't just free everything and then setup again,
1111 * because the ISRs in MSI-X mode get passed pointers
1112 * to the Tx and Rx ring structs.
1113 */
1114
1115 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001116 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001117 netdev_info(netdev,
1118 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001119 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001120 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1121 sizeof(struct i40e_ring), GFP_KERNEL);
1122 if (!tx_rings) {
1123 err = -ENOMEM;
1124 goto done;
1125 }
1126
1127 for (i = 0; i < vsi->num_queue_pairs; i++) {
1128 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001129 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001130 tx_rings[i].count = new_tx_count;
1131 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1132 if (err) {
1133 while (i) {
1134 i--;
1135 i40e_free_tx_resources(&tx_rings[i]);
1136 }
1137 kfree(tx_rings);
1138 tx_rings = NULL;
1139
1140 goto done;
1141 }
1142 }
1143 }
1144
1145 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001146 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001147 netdev_info(netdev,
1148 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001149 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001150 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1151 sizeof(struct i40e_ring), GFP_KERNEL);
1152 if (!rx_rings) {
1153 err = -ENOMEM;
1154 goto free_tx;
1155 }
1156
1157 for (i = 0; i < vsi->num_queue_pairs; i++) {
1158 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001159 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001160 rx_rings[i].count = new_rx_count;
1161 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1162 if (err) {
1163 while (i) {
1164 i--;
1165 i40e_free_rx_resources(&rx_rings[i]);
1166 }
1167 kfree(rx_rings);
1168 rx_rings = NULL;
1169
1170 goto free_tx;
1171 }
1172 }
1173 }
1174
1175 /* Bring interface down, copy in the new ring info,
1176 * then restore the interface
1177 */
1178 i40e_down(vsi);
1179
1180 if (tx_rings) {
1181 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001182 i40e_free_tx_resources(vsi->tx_rings[i]);
1183 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001184 }
1185 kfree(tx_rings);
1186 tx_rings = NULL;
1187 }
1188
1189 if (rx_rings) {
1190 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001191 i40e_free_rx_resources(vsi->rx_rings[i]);
1192 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001193 }
1194 kfree(rx_rings);
1195 rx_rings = NULL;
1196 }
1197
1198 i40e_up(vsi);
1199
1200free_tx:
1201 /* error cleanup if the Rx allocations failed after getting Tx */
1202 if (tx_rings) {
1203 for (i = 0; i < vsi->num_queue_pairs; i++)
1204 i40e_free_tx_resources(&tx_rings[i]);
1205 kfree(tx_rings);
1206 tx_rings = NULL;
1207 }
1208
1209done:
1210 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1211
1212 return err;
1213}
1214
1215static int i40e_get_sset_count(struct net_device *netdev, int sset)
1216{
1217 struct i40e_netdev_priv *np = netdev_priv(netdev);
1218 struct i40e_vsi *vsi = np->vsi;
1219 struct i40e_pf *pf = vsi->back;
1220
1221 switch (sset) {
1222 case ETH_SS_TEST:
1223 return I40E_TEST_LEN;
1224 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001225 if (vsi == pf->vsi[pf->lan_vsi]) {
1226 int len = I40E_PF_STATS_LEN(netdev);
1227
1228 if (pf->lan_veb != I40E_NO_VEB)
1229 len += I40E_VEB_STATS_LEN;
1230 return len;
1231 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001233 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001234 case ETH_SS_PRIV_FLAGS:
1235 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001236 default:
1237 return -EOPNOTSUPP;
1238 }
1239}
1240
1241static void i40e_get_ethtool_stats(struct net_device *netdev,
1242 struct ethtool_stats *stats, u64 *data)
1243{
1244 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001245 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001246 struct i40e_vsi *vsi = np->vsi;
1247 struct i40e_pf *pf = vsi->back;
1248 int i = 0;
1249 char *p;
1250 int j;
1251 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001252 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001253
1254 i40e_update_stats(vsi);
1255
1256 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1257 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1258 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1259 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1260 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001261 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1262 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1263 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1264 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1265 }
Vasu Dev38e00432014-08-01 13:27:03 -07001266#ifdef I40E_FCOE
1267 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1268 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1269 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1270 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1271 }
1272#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001273 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001274 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001275 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001276
1277 if (!tx_ring)
1278 continue;
1279
1280 /* process Tx ring statistics */
1281 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001282 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001283 data[i] = tx_ring->stats.packets;
1284 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001285 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001286 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001287
1288 /* Rx ring is the 2nd half of the queue pair */
1289 rx_ring = &tx_ring[1];
1290 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001291 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001292 data[i] = rx_ring->stats.packets;
1293 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001294 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001295 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001296 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001297 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001298 if (vsi != pf->vsi[pf->lan_vsi])
1299 return;
1300
1301 if (pf->lan_veb != I40E_NO_VEB) {
1302 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1303 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1304 p = (char *)veb;
1305 p += i40e_gstrings_veb_stats[j].stat_offset;
1306 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1307 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001308 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001309 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001310 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1311 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1312 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1313 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1314 }
1315 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1316 data[i++] = pf->stats.priority_xon_tx[j];
1317 data[i++] = pf->stats.priority_xoff_tx[j];
1318 }
1319 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1320 data[i++] = pf->stats.priority_xon_rx[j];
1321 data[i++] = pf->stats.priority_xoff_rx[j];
1322 }
1323 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1324 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001325}
1326
1327static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1328 u8 *data)
1329{
1330 struct i40e_netdev_priv *np = netdev_priv(netdev);
1331 struct i40e_vsi *vsi = np->vsi;
1332 struct i40e_pf *pf = vsi->back;
1333 char *p = (char *)data;
1334 int i;
1335
1336 switch (stringset) {
1337 case ETH_SS_TEST:
1338 for (i = 0; i < I40E_TEST_LEN; i++) {
1339 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1340 data += ETH_GSTRING_LEN;
1341 }
1342 break;
1343 case ETH_SS_STATS:
1344 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1345 snprintf(p, ETH_GSTRING_LEN, "%s",
1346 i40e_gstrings_net_stats[i].stat_string);
1347 p += ETH_GSTRING_LEN;
1348 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001349 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1350 snprintf(p, ETH_GSTRING_LEN, "%s",
1351 i40e_gstrings_misc_stats[i].stat_string);
1352 p += ETH_GSTRING_LEN;
1353 }
Vasu Dev38e00432014-08-01 13:27:03 -07001354#ifdef I40E_FCOE
1355 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1356 snprintf(p, ETH_GSTRING_LEN, "%s",
1357 i40e_gstrings_fcoe_stats[i].stat_string);
1358 p += ETH_GSTRING_LEN;
1359 }
1360#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361 for (i = 0; i < vsi->num_queue_pairs; i++) {
1362 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1363 p += ETH_GSTRING_LEN;
1364 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1365 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001366 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1367 p += ETH_GSTRING_LEN;
1368 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1369 p += ETH_GSTRING_LEN;
1370 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001371 if (vsi != pf->vsi[pf->lan_vsi])
1372 return;
1373
1374 if (pf->lan_veb != I40E_NO_VEB) {
1375 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1376 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1377 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001378 p += ETH_GSTRING_LEN;
1379 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001380 }
1381 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1382 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1383 i40e_gstrings_stats[i].stat_string);
1384 p += ETH_GSTRING_LEN;
1385 }
1386 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1387 snprintf(p, ETH_GSTRING_LEN,
1388 "port.tx_priority_%u_xon", i);
1389 p += ETH_GSTRING_LEN;
1390 snprintf(p, ETH_GSTRING_LEN,
1391 "port.tx_priority_%u_xoff", i);
1392 p += ETH_GSTRING_LEN;
1393 }
1394 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1395 snprintf(p, ETH_GSTRING_LEN,
1396 "port.rx_priority_%u_xon", i);
1397 p += ETH_GSTRING_LEN;
1398 snprintf(p, ETH_GSTRING_LEN,
1399 "port.rx_priority_%u_xoff", i);
1400 p += ETH_GSTRING_LEN;
1401 }
1402 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1403 snprintf(p, ETH_GSTRING_LEN,
1404 "port.rx_priority_%u_xon_2_xoff", i);
1405 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 }
1407 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1408 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001409 case ETH_SS_PRIV_FLAGS:
1410 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1411 memcpy(data, i40e_priv_flags_strings[i],
1412 ETH_GSTRING_LEN);
1413 data += ETH_GSTRING_LEN;
1414 }
1415 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001416 default:
1417 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001418 }
1419}
1420
1421static int i40e_get_ts_info(struct net_device *dev,
1422 struct ethtool_ts_info *info)
1423{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001424 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1425
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001426 /* only report HW timestamping if PTP is enabled */
1427 if (!(pf->flags & I40E_FLAG_PTP))
1428 return ethtool_op_get_ts_info(dev, info);
1429
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001430 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1431 SOF_TIMESTAMPING_RX_SOFTWARE |
1432 SOF_TIMESTAMPING_SOFTWARE |
1433 SOF_TIMESTAMPING_TX_HARDWARE |
1434 SOF_TIMESTAMPING_RX_HARDWARE |
1435 SOF_TIMESTAMPING_RAW_HARDWARE;
1436
1437 if (pf->ptp_clock)
1438 info->phc_index = ptp_clock_index(pf->ptp_clock);
1439 else
1440 info->phc_index = -1;
1441
1442 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1443
1444 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1445 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1446 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1447 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1448 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1449 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1450 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1451 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1452 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1453 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1454 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1455 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1456
1457 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001458}
1459
Shannon Nelson7b086392013-11-20 10:02:59 +00001460static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001461{
Shannon Nelson7b086392013-11-20 10:02:59 +00001462 struct i40e_netdev_priv *np = netdev_priv(netdev);
1463 struct i40e_pf *pf = np->vsi->back;
1464
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001465 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001466 if (i40e_get_link_status(&pf->hw))
1467 *data = 0;
1468 else
1469 *data = 1;
1470
1471 return *data;
1472}
1473
Shannon Nelson7b086392013-11-20 10:02:59 +00001474static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001475{
Shannon Nelson7b086392013-11-20 10:02:59 +00001476 struct i40e_netdev_priv *np = netdev_priv(netdev);
1477 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001479 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001480 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481
Shannon Nelson7b086392013-11-20 10:02:59 +00001482 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483}
1484
Shannon Nelson7b086392013-11-20 10:02:59 +00001485static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001486{
Shannon Nelson7b086392013-11-20 10:02:59 +00001487 struct i40e_netdev_priv *np = netdev_priv(netdev);
1488 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001490 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001491 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001492
Shannon Nelson4443ec92014-11-13 08:23:12 +00001493 /* forcebly clear the NVM Update state machine */
1494 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1495
Shannon Nelson7b086392013-11-20 10:02:59 +00001496 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497}
1498
Shannon Nelson7b086392013-11-20 10:02:59 +00001499static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500{
Shannon Nelson7b086392013-11-20 10:02:59 +00001501 struct i40e_netdev_priv *np = netdev_priv(netdev);
1502 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001503 u16 swc_old = pf->sw_int_count;
1504
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001505 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001506 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1507 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001508 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1509 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1510 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1511 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001512 usleep_range(1000, 2000);
1513 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514
1515 return *data;
1516}
1517
Shannon Nelson7b086392013-11-20 10:02:59 +00001518static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001520 struct i40e_netdev_priv *np = netdev_priv(netdev);
1521 struct i40e_pf *pf = np->vsi->back;
1522
1523 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001524 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001525
1526 return *data;
1527}
1528
1529static void i40e_diag_test(struct net_device *netdev,
1530 struct ethtool_test *eth_test, u64 *data)
1531{
1532 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001533 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534 struct i40e_pf *pf = np->vsi->back;
1535
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1537 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001538 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001539
Shannon Nelsonf551b432013-11-26 10:49:12 +00001540 set_bit(__I40E_TESTING, &pf->state);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001541 /* If the device is online then take it offline */
1542 if (if_running)
1543 /* indicate we're in test mode */
1544 dev_close(netdev);
1545 else
1546 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001547
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 /* Link test performed before hardware reset
1549 * so autoneg doesn't interfere with test result
1550 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001551 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001552 eth_test->flags |= ETH_TEST_FL_FAILED;
1553
Shannon Nelson7b086392013-11-20 10:02:59 +00001554 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555 eth_test->flags |= ETH_TEST_FL_FAILED;
1556
Shannon Nelson7b086392013-11-20 10:02:59 +00001557 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558 eth_test->flags |= ETH_TEST_FL_FAILED;
1559
Shannon Nelson7b086392013-11-20 10:02:59 +00001560 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001561 eth_test->flags |= ETH_TEST_FL_FAILED;
1562
Shannon Nelsonf551b432013-11-26 10:49:12 +00001563 /* run reg test last, a reset is required after it */
1564 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1565 eth_test->flags |= ETH_TEST_FL_FAILED;
1566
1567 clear_bit(__I40E_TESTING, &pf->state);
1568 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001569
1570 if (if_running)
1571 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001572 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001574 netif_info(pf, drv, netdev, "online testing starting\n");
1575
Shannon Nelson7b086392013-11-20 10:02:59 +00001576 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001577 eth_test->flags |= ETH_TEST_FL_FAILED;
1578
1579 /* Offline only tests, not run in online; pass by default */
1580 data[I40E_ETH_TEST_REG] = 0;
1581 data[I40E_ETH_TEST_EEPROM] = 0;
1582 data[I40E_ETH_TEST_INTR] = 0;
1583 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001585
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001586 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001587}
1588
1589static void i40e_get_wol(struct net_device *netdev,
1590 struct ethtool_wolinfo *wol)
1591{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001592 struct i40e_netdev_priv *np = netdev_priv(netdev);
1593 struct i40e_pf *pf = np->vsi->back;
1594 struct i40e_hw *hw = &pf->hw;
1595 u16 wol_nvm_bits;
1596
1597 /* NVM bit on means WoL disabled for the port */
1598 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001599 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001600 wol->supported = 0;
1601 wol->wolopts = 0;
1602 } else {
1603 wol->supported = WAKE_MAGIC;
1604 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1605 }
1606}
1607
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001608/**
1609 * i40e_set_wol - set the WakeOnLAN configuration
1610 * @netdev: the netdev in question
1611 * @wol: the ethtool WoL setting data
1612 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001613static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1614{
1615 struct i40e_netdev_priv *np = netdev_priv(netdev);
1616 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001617 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001618 struct i40e_hw *hw = &pf->hw;
1619 u16 wol_nvm_bits;
1620
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001621 /* WoL not supported if this isn't the controlling PF on the port */
1622 if (hw->partition_id != 1) {
1623 i40e_partition_setting_complaint(pf);
1624 return -EOPNOTSUPP;
1625 }
1626
1627 if (vsi != pf->vsi[pf->lan_vsi])
1628 return -EOPNOTSUPP;
1629
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001630 /* NVM bit on means WoL disabled for the port */
1631 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1632 if (((1 << hw->port) & wol_nvm_bits))
1633 return -EOPNOTSUPP;
1634
1635 /* only magic packet is supported */
1636 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1637 return -EOPNOTSUPP;
1638
1639 /* is this a new value? */
1640 if (pf->wol_en != !!wol->wolopts) {
1641 pf->wol_en = !!wol->wolopts;
1642 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1643 }
1644
1645 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001646}
1647
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001648static int i40e_set_phys_id(struct net_device *netdev,
1649 enum ethtool_phys_id_state state)
1650{
1651 struct i40e_netdev_priv *np = netdev_priv(netdev);
1652 struct i40e_pf *pf = np->vsi->back;
1653 struct i40e_hw *hw = &pf->hw;
1654 int blink_freq = 2;
1655
1656 switch (state) {
1657 case ETHTOOL_ID_ACTIVE:
1658 pf->led_status = i40e_led_get(hw);
1659 return blink_freq;
1660 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001661 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 break;
1663 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001664 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001665 break;
1666 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001667 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001669 default:
1670 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001671 }
1672
1673 return 0;
1674}
1675
1676/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1677 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1678 * 125us (8000 interrupts per second) == ITR(62)
1679 */
1680
1681static int i40e_get_coalesce(struct net_device *netdev,
1682 struct ethtool_coalesce *ec)
1683{
1684 struct i40e_netdev_priv *np = netdev_priv(netdev);
1685 struct i40e_vsi *vsi = np->vsi;
1686
1687 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1688 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1689
1690 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001691 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001692
1693 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001694 ec->use_adaptive_tx_coalesce = 1;
1695
1696 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1697 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001698
1699 return 0;
1700}
1701
1702static int i40e_set_coalesce(struct net_device *netdev,
1703 struct ethtool_coalesce *ec)
1704{
1705 struct i40e_netdev_priv *np = netdev_priv(netdev);
1706 struct i40e_q_vector *q_vector;
1707 struct i40e_vsi *vsi = np->vsi;
1708 struct i40e_pf *pf = vsi->back;
1709 struct i40e_hw *hw = &pf->hw;
1710 u16 vector;
1711 int i;
1712
1713 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1714 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1715
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001716 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001717 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001718 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001719 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001720 } else if (ec->rx_coalesce_usecs == 0) {
1721 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001722 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001723 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 +00001724 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001725 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001726 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001727 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001728
Mitch Williams32f5f542014-04-04 04:43:10 +00001729 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001730 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001731 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001732 } else if (ec->tx_coalesce_usecs == 0) {
1733 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001734 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001735 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 +00001736 } else {
1737 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001738 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001739 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001740 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001741
1742 if (ec->use_adaptive_rx_coalesce)
1743 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1744 else
1745 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1746
1747 if (ec->use_adaptive_tx_coalesce)
1748 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1749 else
1750 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001751
Alexander Duyck493fb302013-09-28 07:01:44 +00001752 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1753 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001754 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1755 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1756 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1757 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1758 i40e_flush(hw);
1759 }
1760
1761 return 0;
1762}
1763
1764/**
1765 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1766 * @pf: pointer to the physical function struct
1767 * @cmd: ethtool rxnfc command
1768 *
1769 * Returns Success if the flow is supported, else Invalid Input.
1770 **/
1771static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1772{
1773 cmd->data = 0;
1774
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001775 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1776 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1777 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1778 return 0;
1779 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001780 /* Report default options for RSS on i40e */
1781 switch (cmd->flow_type) {
1782 case TCP_V4_FLOW:
1783 case UDP_V4_FLOW:
1784 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1785 /* fall through to add IP fields */
1786 case SCTP_V4_FLOW:
1787 case AH_ESP_V4_FLOW:
1788 case AH_V4_FLOW:
1789 case ESP_V4_FLOW:
1790 case IPV4_FLOW:
1791 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1792 break;
1793 case TCP_V6_FLOW:
1794 case UDP_V6_FLOW:
1795 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1796 /* fall through to add IP fields */
1797 case SCTP_V6_FLOW:
1798 case AH_ESP_V6_FLOW:
1799 case AH_V6_FLOW:
1800 case ESP_V6_FLOW:
1801 case IPV6_FLOW:
1802 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1803 break;
1804 default:
1805 return -EINVAL;
1806 }
1807
1808 return 0;
1809}
1810
1811/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001812 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1813 * @pf: Pointer to the physical function struct
1814 * @cmd: The command to get or set Rx flow classification rules
1815 * @rule_locs: Array of used rule locations
1816 *
1817 * This function populates both the total and actual rule count of
1818 * the ethtool flow classification command
1819 *
1820 * Returns 0 on success or -EMSGSIZE if entry not found
1821 **/
1822static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1823 struct ethtool_rxnfc *cmd,
1824 u32 *rule_locs)
1825{
1826 struct i40e_fdir_filter *rule;
1827 struct hlist_node *node2;
1828 int cnt = 0;
1829
1830 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001831 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001832
1833 hlist_for_each_entry_safe(rule, node2,
1834 &pf->fdir_filter_list, fdir_node) {
1835 if (cnt == cmd->rule_cnt)
1836 return -EMSGSIZE;
1837
1838 rule_locs[cnt] = rule->fd_id;
1839 cnt++;
1840 }
1841
1842 cmd->rule_cnt = cnt;
1843
1844 return 0;
1845}
1846
1847/**
1848 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1849 * @pf: Pointer to the physical function struct
1850 * @cmd: The command to get or set Rx flow classification rules
1851 *
1852 * This function looks up a filter based on the Rx flow classification
1853 * command and fills the flow spec info for it if found
1854 *
1855 * Returns 0 on success or -EINVAL if filter not found
1856 **/
1857static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1858 struct ethtool_rxnfc *cmd)
1859{
1860 struct ethtool_rx_flow_spec *fsp =
1861 (struct ethtool_rx_flow_spec *)&cmd->fs;
1862 struct i40e_fdir_filter *rule = NULL;
1863 struct hlist_node *node2;
1864
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001865 hlist_for_each_entry_safe(rule, node2,
1866 &pf->fdir_filter_list, fdir_node) {
1867 if (fsp->location <= rule->fd_id)
1868 break;
1869 }
1870
1871 if (!rule || fsp->location != rule->fd_id)
1872 return -EINVAL;
1873
1874 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001875 if (fsp->flow_type == IP_USER_FLOW) {
1876 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1877 fsp->h_u.usr_ip4_spec.proto = 0;
1878 fsp->m_u.usr_ip4_spec.proto = 0;
1879 }
1880
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001881 /* Reverse the src and dest notion, since the HW views them from
1882 * Tx perspective where as the user expects it from Rx filter view.
1883 */
1884 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1885 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1886 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1887 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001888
1889 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1890 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1891 else
1892 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001893
1894 return 0;
1895}
1896
1897/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001898 * i40e_get_rxnfc - command to get RX flow classification rules
1899 * @netdev: network interface device structure
1900 * @cmd: ethtool rxnfc command
1901 *
1902 * Returns Success if the command is supported.
1903 **/
1904static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1905 u32 *rule_locs)
1906{
1907 struct i40e_netdev_priv *np = netdev_priv(netdev);
1908 struct i40e_vsi *vsi = np->vsi;
1909 struct i40e_pf *pf = vsi->back;
1910 int ret = -EOPNOTSUPP;
1911
1912 switch (cmd->cmd) {
1913 case ETHTOOL_GRXRINGS:
1914 cmd->data = vsi->alloc_queue_pairs;
1915 ret = 0;
1916 break;
1917 case ETHTOOL_GRXFH:
1918 ret = i40e_get_rss_hash_opts(pf, cmd);
1919 break;
1920 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001921 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001922 /* report total rule count */
1923 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001924 ret = 0;
1925 break;
1926 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001927 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001928 break;
1929 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001930 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1931 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001932 default:
1933 break;
1934 }
1935
1936 return ret;
1937}
1938
1939/**
1940 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1941 * @pf: pointer to the physical function struct
1942 * @cmd: ethtool rxnfc command
1943 *
1944 * Returns Success if the flow input set is supported.
1945 **/
1946static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1947{
1948 struct i40e_hw *hw = &pf->hw;
1949 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1950 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1951
1952 /* RSS does not support anything other than hashing
1953 * to queues on src and dst IPs and ports
1954 */
1955 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1956 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1957 return -EINVAL;
1958
1959 /* We need at least the IP SRC and DEST fields for hashing */
1960 if (!(nfc->data & RXH_IP_SRC) ||
1961 !(nfc->data & RXH_IP_DST))
1962 return -EINVAL;
1963
1964 switch (nfc->flow_type) {
1965 case TCP_V4_FLOW:
1966 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1967 case 0:
1968 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1969 break;
1970 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1971 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1972 break;
1973 default:
1974 return -EINVAL;
1975 }
1976 break;
1977 case TCP_V6_FLOW:
1978 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1979 case 0:
1980 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1981 break;
1982 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1983 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1984 break;
1985 default:
1986 return -EINVAL;
1987 }
1988 break;
1989 case UDP_V4_FLOW:
1990 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1991 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001992 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1993 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001994 break;
1995 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001996 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1997 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998 break;
1999 default:
2000 return -EINVAL;
2001 }
2002 break;
2003 case UDP_V6_FLOW:
2004 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2005 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002006 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2007 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002008 break;
2009 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002010 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2011 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002012 break;
2013 default:
2014 return -EINVAL;
2015 }
2016 break;
2017 case AH_ESP_V4_FLOW:
2018 case AH_V4_FLOW:
2019 case ESP_V4_FLOW:
2020 case SCTP_V4_FLOW:
2021 if ((nfc->data & RXH_L4_B_0_1) ||
2022 (nfc->data & RXH_L4_B_2_3))
2023 return -EINVAL;
2024 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2025 break;
2026 case AH_ESP_V6_FLOW:
2027 case AH_V6_FLOW:
2028 case ESP_V6_FLOW:
2029 case SCTP_V6_FLOW:
2030 if ((nfc->data & RXH_L4_B_0_1) ||
2031 (nfc->data & RXH_L4_B_2_3))
2032 return -EINVAL;
2033 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2034 break;
2035 case IPV4_FLOW:
2036 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2037 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2038 break;
2039 case IPV6_FLOW:
2040 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2041 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2042 break;
2043 default:
2044 return -EINVAL;
2045 }
2046
2047 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2048 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2049 i40e_flush(hw);
2050
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002051 /* Save setting for future output/update */
2052 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2053
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002054 return 0;
2055}
2056
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002057/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002058 * i40e_match_fdir_input_set - Match a new filter against an existing one
2059 * @rule: The filter already added
2060 * @input: The new filter to comapre against
2061 *
2062 * Returns true if the two input set match
2063 **/
2064static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2065 struct i40e_fdir_filter *input)
2066{
2067 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2068 (rule->src_ip[0] != input->src_ip[0]) ||
2069 (rule->dst_port != input->dst_port) ||
2070 (rule->src_port != input->src_port))
2071 return false;
2072 return true;
2073}
2074
2075/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002076 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2077 * @vsi: Pointer to the targeted VSI
2078 * @input: The filter to update or NULL to indicate deletion
2079 * @sw_idx: Software index to the filter
2080 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002081 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002082 * This function updates (or deletes) a Flow Director entry from
2083 * the hlist of the corresponding PF
2084 *
2085 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002086 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002087static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2088 struct i40e_fdir_filter *input,
2089 u16 sw_idx,
2090 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002091{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002092 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002093 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002094 struct hlist_node *node2;
2095 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002096
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002097 parent = NULL;
2098 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002099
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002100 hlist_for_each_entry_safe(rule, node2,
2101 &pf->fdir_filter_list, fdir_node) {
2102 /* hash found, or no matching entry */
2103 if (rule->fd_id >= sw_idx)
2104 break;
2105 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002106 }
2107
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002108 /* if there is an old rule occupying our place remove it */
2109 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002110 if (input && !i40e_match_fdir_input_set(rule, input))
2111 err = i40e_add_del_fdir(vsi, rule, false);
2112 else if (!input)
2113 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002114 hlist_del(&rule->fdir_node);
2115 kfree(rule);
2116 pf->fdir_pf_active_filters--;
2117 }
2118
2119 /* If no input this was a delete, err should be 0 if a rule was
2120 * successfully found and removed from the list else -EINVAL
2121 */
2122 if (!input)
2123 return err;
2124
2125 /* initialize node and set software index */
2126 INIT_HLIST_NODE(&input->fdir_node);
2127
2128 /* add filter to the list */
2129 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002130 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002131 else
2132 hlist_add_head(&input->fdir_node,
2133 &pf->fdir_filter_list);
2134
2135 /* update counts */
2136 pf->fdir_pf_active_filters++;
2137
2138 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002139}
2140
2141/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002142 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2143 * @vsi: Pointer to the targeted VSI
2144 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002145 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002146 * The function removes a Flow Director filter entry from the
2147 * hlist of the corresponding PF
2148 *
2149 * Returns 0 on success
2150 */
2151static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2152 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002153{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002154 struct ethtool_rx_flow_spec *fsp =
2155 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002156 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002157 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002158
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002159 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2160 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2161 return -EBUSY;
2162
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002163 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2164 return -EBUSY;
2165
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002166 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002167
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002168 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002169 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002170}
2171
2172/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002173 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002174 * @vsi: pointer to the targeted VSI
2175 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002176 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002177 * Add Flow Director filters for a specific flow spec based on their
2178 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002179 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002180static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2181 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002182{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002183 struct ethtool_rx_flow_spec *fsp;
2184 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002185 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002186 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187
2188 if (!vsi)
2189 return -EINVAL;
2190
2191 pf = vsi->back;
2192
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002193 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2194 return -EOPNOTSUPP;
2195
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002196 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002197 return -ENOSPC;
2198
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002199 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2200 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2201 return -EBUSY;
2202
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002203 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2204 return -EBUSY;
2205
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002206 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2207
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002208 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2209 pf->hw.func_caps.fd_filters_guaranteed)) {
2210 return -EINVAL;
2211 }
2212
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002213 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2214 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002215 return -EINVAL;
2216
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002217 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002218
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002219 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002220 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002221
2222 input->fd_id = fsp->location;
2223
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002224 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2225 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2226 else
2227 input->dest_ctl =
2228 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2229
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002230 input->q_index = fsp->ring_cookie;
2231 input->flex_off = 0;
2232 input->pctype = 0;
2233 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002234 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002235 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002236 input->flow_type = fsp->flow_type;
2237 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002238
2239 /* Reverse the src and dest notion, since the HW expects them to be from
2240 * Tx perspective where as the input from user is from Rx filter view.
2241 */
2242 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2243 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2244 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2245 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002246
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002247 ret = i40e_add_del_fdir(vsi, input, true);
2248 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002249 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002250 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002251 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002252
2253 return ret;
2254}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002255
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002256/**
2257 * i40e_set_rxnfc - command to set RX flow classification rules
2258 * @netdev: network interface device structure
2259 * @cmd: ethtool rxnfc command
2260 *
2261 * Returns Success if the command is supported.
2262 **/
2263static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2264{
2265 struct i40e_netdev_priv *np = netdev_priv(netdev);
2266 struct i40e_vsi *vsi = np->vsi;
2267 struct i40e_pf *pf = vsi->back;
2268 int ret = -EOPNOTSUPP;
2269
2270 switch (cmd->cmd) {
2271 case ETHTOOL_SRXFH:
2272 ret = i40e_set_rss_hash_opt(pf, cmd);
2273 break;
2274 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002275 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002276 break;
2277 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002278 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002279 break;
2280 default:
2281 break;
2282 }
2283
2284 return ret;
2285}
2286
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002287/**
2288 * i40e_max_channels - get Max number of combined channels supported
2289 * @vsi: vsi pointer
2290 **/
2291static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2292{
2293 /* TODO: This code assumes DCB and FD is disabled for now. */
2294 return vsi->alloc_queue_pairs;
2295}
2296
2297/**
2298 * i40e_get_channels - Get the current channels enabled and max supported etc.
2299 * @netdev: network interface device structure
2300 * @ch: ethtool channels structure
2301 *
2302 * We don't support separate tx and rx queues as channels. The other count
2303 * represents how many queues are being used for control. max_combined counts
2304 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2305 * q_vectors since we support a lot more queue pairs than q_vectors.
2306 **/
2307static void i40e_get_channels(struct net_device *dev,
2308 struct ethtool_channels *ch)
2309{
2310 struct i40e_netdev_priv *np = netdev_priv(dev);
2311 struct i40e_vsi *vsi = np->vsi;
2312 struct i40e_pf *pf = vsi->back;
2313
2314 /* report maximum channels */
2315 ch->max_combined = i40e_max_channels(vsi);
2316
2317 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002318 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002319 ch->max_other = ch->other_count;
2320
2321 /* Note: This code assumes DCB is disabled for now. */
2322 ch->combined_count = vsi->num_queue_pairs;
2323}
2324
2325/**
2326 * i40e_set_channels - Set the new channels count.
2327 * @netdev: network interface device structure
2328 * @ch: ethtool channels structure
2329 *
2330 * The new channels count may not be the same as requested by the user
2331 * since it gets rounded down to a power of 2 value.
2332 **/
2333static int i40e_set_channels(struct net_device *dev,
2334 struct ethtool_channels *ch)
2335{
2336 struct i40e_netdev_priv *np = netdev_priv(dev);
2337 unsigned int count = ch->combined_count;
2338 struct i40e_vsi *vsi = np->vsi;
2339 struct i40e_pf *pf = vsi->back;
2340 int new_count;
2341
2342 /* We do not support setting channels for any other VSI at present */
2343 if (vsi->type != I40E_VSI_MAIN)
2344 return -EINVAL;
2345
2346 /* verify they are not requesting separate vectors */
2347 if (!count || ch->rx_count || ch->tx_count)
2348 return -EINVAL;
2349
2350 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002351 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002352 return -EINVAL;
2353
2354 /* verify the number of channels does not exceed hardware limits */
2355 if (count > i40e_max_channels(vsi))
2356 return -EINVAL;
2357
2358 /* update feature limits from largest to smallest supported values */
2359 /* TODO: Flow director limit, DCB etc */
2360
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002361 /* use rss_reconfig to rebuild with new queue count and update traffic
2362 * class queue mapping
2363 */
2364 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002365 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002366 return 0;
2367 else
2368 return -EINVAL;
2369}
2370
Greg Rose7e45ab42015-02-06 08:52:19 +00002371/**
2372 * i40e_get_priv_flags - report device private flags
2373 * @dev: network interface device structure
2374 *
2375 * The get string set count and the string set should be matched for each
2376 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2377 * array.
2378 *
2379 * Returns a u32 bitmap of flags.
2380 **/
2381u32 i40e_get_priv_flags(struct net_device *dev)
2382{
2383 struct i40e_netdev_priv *np = netdev_priv(dev);
2384 struct i40e_vsi *vsi = np->vsi;
2385 struct i40e_pf *pf = vsi->back;
2386 u32 ret_flags = 0;
2387
2388 ret_flags |= pf->hw.func_caps.npar_enable ?
2389 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2390
2391 return ret_flags;
2392}
2393
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002394static const struct ethtool_ops i40e_ethtool_ops = {
2395 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002396 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002397 .get_drvinfo = i40e_get_drvinfo,
2398 .get_regs_len = i40e_get_regs_len,
2399 .get_regs = i40e_get_regs,
2400 .nway_reset = i40e_nway_reset,
2401 .get_link = ethtool_op_get_link,
2402 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002403 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002404 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002405 .get_eeprom_len = i40e_get_eeprom_len,
2406 .get_eeprom = i40e_get_eeprom,
2407 .get_ringparam = i40e_get_ringparam,
2408 .set_ringparam = i40e_set_ringparam,
2409 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002410 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002411 .get_msglevel = i40e_get_msglevel,
2412 .set_msglevel = i40e_set_msglevel,
2413 .get_rxnfc = i40e_get_rxnfc,
2414 .set_rxnfc = i40e_set_rxnfc,
2415 .self_test = i40e_diag_test,
2416 .get_strings = i40e_get_strings,
2417 .set_phys_id = i40e_set_phys_id,
2418 .get_sset_count = i40e_get_sset_count,
2419 .get_ethtool_stats = i40e_get_ethtool_stats,
2420 .get_coalesce = i40e_get_coalesce,
2421 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002422 .get_channels = i40e_get_channels,
2423 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002424 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002425 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002426};
2427
2428void i40e_set_ethtool_ops(struct net_device *netdev)
2429{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002430 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002431}