blob: 01c811c99ff752fc6df4a733934176941259e414 [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:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000262 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000263 ecmd->supported = SUPPORTED_40000baseCR4_Full;
264 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000266 ecmd->supported = SUPPORTED_Autoneg |
267 SUPPORTED_40000baseKR4_Full;
268 ecmd->advertising = ADVERTISED_Autoneg |
269 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000270 break;
271 case I40E_PHY_TYPE_40GBASE_SR4:
272 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000273 break;
274 case I40E_PHY_TYPE_40GBASE_LR4:
275 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 break;
277 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000278 ecmd->supported = SUPPORTED_Autoneg |
279 SUPPORTED_10000baseKX4_Full;
280 ecmd->advertising = ADVERTISED_Autoneg |
281 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000282 break;
283 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000284 ecmd->supported = SUPPORTED_Autoneg |
285 SUPPORTED_10000baseKR_Full;
286 ecmd->advertising = ADVERTISED_Autoneg |
287 ADVERTISED_10000baseKR_Full;
288 break;
289 case I40E_PHY_TYPE_10GBASE_SR:
290 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000291 case I40E_PHY_TYPE_1000BASE_SX:
292 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000293 ecmd->supported = SUPPORTED_10000baseT_Full |
294 SUPPORTED_1000baseT_Full;
295 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
296 ecmd->advertising |= ADVERTISED_10000baseT_Full;
297 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
298 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000299 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000300 case I40E_PHY_TYPE_1000BASE_KX:
301 ecmd->supported = SUPPORTED_Autoneg |
302 SUPPORTED_1000baseKX_Full;
303 ecmd->advertising = ADVERTISED_Autoneg |
304 ADVERTISED_1000baseKX_Full;
305 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000306 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000307 case I40E_PHY_TYPE_1000BASE_T:
308 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000309 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000310 SUPPORTED_10000baseT_Full |
311 SUPPORTED_1000baseT_Full |
312 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000313 ecmd->advertising = ADVERTISED_Autoneg;
314 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
315 ecmd->advertising |= ADVERTISED_10000baseT_Full;
316 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
317 ecmd->advertising |= ADVERTISED_1000baseT_Full;
318 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
319 ecmd->advertising |= ADVERTISED_100baseT_Full;
320 break;
321 case I40E_PHY_TYPE_10GBASE_CR1_CU:
322 case I40E_PHY_TYPE_10GBASE_CR1:
323 ecmd->supported = SUPPORTED_Autoneg |
324 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000325 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000326 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000327 break;
328 case I40E_PHY_TYPE_XAUI:
329 case I40E_PHY_TYPE_XFI:
330 case I40E_PHY_TYPE_SFI:
331 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000332 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000333 ecmd->supported = SUPPORTED_10000baseT_Full;
334 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000335 case I40E_PHY_TYPE_SGMII:
336 ecmd->supported = SUPPORTED_Autoneg |
337 SUPPORTED_1000baseT_Full |
338 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000339 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
340 ecmd->advertising |= ADVERTISED_1000baseT_Full;
341 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
342 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000343 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000344 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000345 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000346 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
347 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000348 }
349
Catherine Sullivane8278452015-02-06 08:52:08 +0000350 /* Set speed and duplex */
351 switch (link_speed) {
352 case I40E_LINK_SPEED_40GB:
353 /* need a SPEED_40000 in ethtool.h */
354 ethtool_cmd_speed_set(ecmd, 40000);
355 break;
356 case I40E_LINK_SPEED_10GB:
357 ethtool_cmd_speed_set(ecmd, SPEED_10000);
358 break;
359 case I40E_LINK_SPEED_1GB:
360 ethtool_cmd_speed_set(ecmd, SPEED_1000);
361 break;
362 case I40E_LINK_SPEED_100MB:
363 ethtool_cmd_speed_set(ecmd, SPEED_100);
364 break;
365 default:
366 break;
367 }
368 ecmd->duplex = DUPLEX_FULL;
369}
370
371/**
372 * i40e_get_settings_link_down - Get the Link settings for when link is down
373 * @hw: hw structure
374 * @ecmd: ethtool command to fill in
375 *
376 * Reports link settings that can be determined when link is down
377 **/
378static void i40e_get_settings_link_down(struct i40e_hw *hw,
379 struct ethtool_cmd *ecmd)
380{
381 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
382
383 /* link is down and the driver needs to fall back on
384 * device ID to determine what kinds of info to display,
385 * it's mostly a guess that may change when link is up
386 */
387 switch (hw->device_id) {
388 case I40E_DEV_ID_QSFP_A:
389 case I40E_DEV_ID_QSFP_B:
390 case I40E_DEV_ID_QSFP_C:
391 /* pluggable QSFP */
392 ecmd->supported = SUPPORTED_40000baseSR4_Full |
393 SUPPORTED_40000baseCR4_Full |
394 SUPPORTED_40000baseLR4_Full;
395 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
396 ADVERTISED_40000baseCR4_Full |
397 ADVERTISED_40000baseLR4_Full;
398 break;
399 case I40E_DEV_ID_KX_B:
400 /* backplane 40G */
401 ecmd->supported = SUPPORTED_40000baseKR4_Full;
402 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
403 break;
404 case I40E_DEV_ID_KX_C:
405 /* backplane 10G */
406 ecmd->supported = SUPPORTED_10000baseKR_Full;
407 ecmd->advertising = ADVERTISED_10000baseKR_Full;
408 break;
409 case I40E_DEV_ID_10G_BASE_T:
410 ecmd->supported = SUPPORTED_10000baseT_Full |
411 SUPPORTED_1000baseT_Full |
412 SUPPORTED_100baseT_Full;
413 /* Figure out what has been requested */
414 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
415 ecmd->advertising |= ADVERTISED_10000baseT_Full;
416 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
417 ecmd->advertising |= ADVERTISED_1000baseT_Full;
418 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
419 ecmd->advertising |= ADVERTISED_100baseT_Full;
420 break;
421 default:
422 /* all the rest are 10G/1G */
423 ecmd->supported = SUPPORTED_10000baseT_Full |
424 SUPPORTED_1000baseT_Full;
425 /* Figure out what has been requested */
426 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
427 ecmd->advertising |= ADVERTISED_10000baseT_Full;
428 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
429 ecmd->advertising |= ADVERTISED_1000baseT_Full;
430 break;
431 }
432
433 /* With no link speed and duplex are unknown */
434 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
435 ecmd->duplex = DUPLEX_UNKNOWN;
436}
437
438/**
439 * i40e_get_settings - Get Link Speed and Duplex settings
440 * @netdev: network interface device structure
441 * @ecmd: ethtool command
442 *
443 * Reports speed/duplex settings based on media_type
444 **/
445static int i40e_get_settings(struct net_device *netdev,
446 struct ethtool_cmd *ecmd)
447{
448 struct i40e_netdev_priv *np = netdev_priv(netdev);
449 struct i40e_pf *pf = np->vsi->back;
450 struct i40e_hw *hw = &pf->hw;
451 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
452 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
453
454 if (link_up)
455 i40e_get_settings_link_up(hw, ecmd, netdev);
456 else
457 i40e_get_settings_link_down(hw, ecmd);
458
459 /* Now set the settings that don't rely on link being up/down */
460
461 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000462 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
463 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000464
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000465 switch (hw->phy.media_type) {
466 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000467 ecmd->supported |= SUPPORTED_Autoneg |
468 SUPPORTED_Backplane;
469 ecmd->advertising |= ADVERTISED_Autoneg |
470 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000471 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000472 break;
473 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000474 ecmd->supported |= SUPPORTED_TP;
475 ecmd->advertising |= ADVERTISED_TP;
476 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000477 break;
478 case I40E_MEDIA_TYPE_DA:
479 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000480 ecmd->supported |= SUPPORTED_FIBRE;
481 ecmd->advertising |= ADVERTISED_FIBRE;
482 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000483 break;
484 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000486 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000487 break;
488 case I40E_MEDIA_TYPE_UNKNOWN:
489 default:
490 ecmd->port = PORT_OTHER;
491 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000492 }
493
Catherine Sullivane8278452015-02-06 08:52:08 +0000494 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000495 ecmd->transceiver = XCVR_EXTERNAL;
496
Catherine Sullivane8278452015-02-06 08:52:08 +0000497 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000498 ecmd->supported |= SUPPORTED_Pause;
499
Catherine Sullivane8278452015-02-06 08:52:08 +0000500 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000501 case I40E_FC_FULL:
502 ecmd->advertising |= ADVERTISED_Pause;
503 break;
504 case I40E_FC_TX_PAUSE:
505 ecmd->advertising |= ADVERTISED_Asym_Pause;
506 break;
507 case I40E_FC_RX_PAUSE:
508 ecmd->advertising |= (ADVERTISED_Pause |
509 ADVERTISED_Asym_Pause);
510 break;
511 default:
512 ecmd->advertising &= ~(ADVERTISED_Pause |
513 ADVERTISED_Asym_Pause);
514 break;
515 }
516
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000517 return 0;
518}
519
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000520/**
521 * i40e_set_settings - Set Speed and Duplex
522 * @netdev: network interface device structure
523 * @ecmd: ethtool command
524 *
525 * Set speed/duplex per media_types advertised/forced
526 **/
527static int i40e_set_settings(struct net_device *netdev,
528 struct ethtool_cmd *ecmd)
529{
530 struct i40e_netdev_priv *np = netdev_priv(netdev);
531 struct i40e_aq_get_phy_abilities_resp abilities;
532 struct i40e_aq_set_phy_config config;
533 struct i40e_pf *pf = np->vsi->back;
534 struct i40e_vsi *vsi = np->vsi;
535 struct i40e_hw *hw = &pf->hw;
536 struct ethtool_cmd safe_ecmd;
537 i40e_status status = 0;
538 bool change = false;
539 int err = 0;
540 u8 autoneg;
541 u32 advertise;
542
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000543 /* Changing port settings is not supported if this isn't the
544 * port's controlling PF
545 */
546 if (hw->partition_id != 1) {
547 i40e_partition_setting_complaint(pf);
548 return -EOPNOTSUPP;
549 }
550
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000551 if (vsi != pf->vsi[pf->lan_vsi])
552 return -EOPNOTSUPP;
553
554 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
555 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000556 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
557 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000558 return -EOPNOTSUPP;
559
560 /* get our own copy of the bits to check against */
561 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
562 i40e_get_settings(netdev, &safe_ecmd);
563
564 /* save autoneg and speed out of ecmd */
565 autoneg = ecmd->autoneg;
566 advertise = ecmd->advertising;
567
568 /* set autoneg and speed back to what they currently are */
569 ecmd->autoneg = safe_ecmd.autoneg;
570 ecmd->advertising = safe_ecmd.advertising;
571
572 ecmd->cmd = safe_ecmd.cmd;
573 /* If ecmd and safe_ecmd are not the same now, then they are
574 * trying to set something that we do not support
575 */
576 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
577 return -EOPNOTSUPP;
578
579 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
580 usleep_range(1000, 2000);
581
582 /* Get the current phy config */
583 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
584 NULL);
585 if (status)
586 return -EAGAIN;
587
Catherine Sullivan124ed152014-07-12 07:28:12 +0000588 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000589 * set below
590 */
591 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000592 config.abilities = abilities.abilities;
593
594 /* Check autoneg */
595 if (autoneg == AUTONEG_ENABLE) {
596 /* If autoneg is not supported, return error */
597 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
598 netdev_info(netdev, "Autoneg not supported on this phy\n");
599 return -EINVAL;
600 }
601 /* If autoneg was not already enabled */
602 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
603 config.abilities = abilities.abilities |
604 I40E_AQ_PHY_ENABLE_AN;
605 change = true;
606 }
607 } else {
608 /* If autoneg is supported 10GBASE_T is the only phy that
609 * can disable it, so otherwise return error
610 */
611 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
612 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
613 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
614 return -EINVAL;
615 }
616 /* If autoneg is currently enabled */
617 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000618 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000619 ~I40E_AQ_PHY_ENABLE_AN;
620 change = true;
621 }
622 }
623
624 if (advertise & ~safe_ecmd.supported)
625 return -EINVAL;
626
627 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000628 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000629 if (advertise & ADVERTISED_1000baseT_Full ||
630 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000631 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000632 if (advertise & ADVERTISED_10000baseT_Full ||
633 advertise & ADVERTISED_10000baseKX4_Full ||
634 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000635 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000636 if (advertise & ADVERTISED_40000baseKR4_Full ||
637 advertise & ADVERTISED_40000baseCR4_Full ||
638 advertise & ADVERTISED_40000baseSR4_Full ||
639 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000640 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000641
Catherine Sullivan124ed152014-07-12 07:28:12 +0000642 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000643 /* copy over the rest of the abilities */
644 config.phy_type = abilities.phy_type;
645 config.eee_capability = abilities.eee_capability;
646 config.eeer = abilities.eeer_val;
647 config.low_power_ctrl = abilities.d3_lpan;
648
Catherine Sullivane8278452015-02-06 08:52:08 +0000649 /* save the requested speeds */
650 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000651 /* set link and auto negotiation so changes take effect */
652 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
653 /* If link is up put link down */
654 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
655 /* Tell the OS link is going down, the link will go
656 * back up when fw says it is ready asynchronously
657 */
658 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
659 netif_carrier_off(netdev);
660 netif_tx_stop_all_queues(netdev);
661 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000662
663 /* make the aq call */
664 status = i40e_aq_set_phy_config(hw, &config, NULL);
665 if (status) {
666 netdev_info(netdev, "Set phy config failed with error %d.\n",
667 status);
668 return -EAGAIN;
669 }
670
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000671 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000672 if (status)
673 netdev_info(netdev, "Updating link info failed with error %d\n",
674 status);
675
676 } else {
677 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
678 }
679
680 return err;
681}
682
Jesse Brandeburga6599722014-06-04 08:45:25 +0000683static int i40e_nway_reset(struct net_device *netdev)
684{
685 /* restart autonegotiation */
686 struct i40e_netdev_priv *np = netdev_priv(netdev);
687 struct i40e_pf *pf = np->vsi->back;
688 struct i40e_hw *hw = &pf->hw;
689 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
690 i40e_status ret = 0;
691
692 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
693 if (ret) {
694 netdev_info(netdev, "link restart failed, aq_err=%d\n",
695 pf->hw.aq.asq_last_status);
696 return -EIO;
697 }
698
699 return 0;
700}
701
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000702/**
703 * i40e_get_pauseparam - Get Flow Control status
704 * Return tx/rx-pause status
705 **/
706static void i40e_get_pauseparam(struct net_device *netdev,
707 struct ethtool_pauseparam *pause)
708{
709 struct i40e_netdev_priv *np = netdev_priv(netdev);
710 struct i40e_pf *pf = np->vsi->back;
711 struct i40e_hw *hw = &pf->hw;
712 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000713 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000714
715 pause->autoneg =
716 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
717 AUTONEG_ENABLE : AUTONEG_DISABLE);
718
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000719 /* PFC enabled so report LFC as off */
720 if (dcbx_cfg->pfc.pfcenable) {
721 pause->rx_pause = 0;
722 pause->tx_pause = 0;
723 return;
724 }
725
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000726 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000727 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000728 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000729 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000730 } else if (hw->fc.current_mode == I40E_FC_FULL) {
731 pause->rx_pause = 1;
732 pause->tx_pause = 1;
733 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000734}
735
Catherine Sullivan2becc352014-06-04 08:45:27 +0000736/**
737 * i40e_set_pauseparam - Set Flow Control parameter
738 * @netdev: network interface device structure
739 * @pause: return tx/rx flow control status
740 **/
741static int i40e_set_pauseparam(struct net_device *netdev,
742 struct ethtool_pauseparam *pause)
743{
744 struct i40e_netdev_priv *np = netdev_priv(netdev);
745 struct i40e_pf *pf = np->vsi->back;
746 struct i40e_vsi *vsi = np->vsi;
747 struct i40e_hw *hw = &pf->hw;
748 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000749 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000750 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
751 i40e_status status;
752 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000753 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000754
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000755 /* Changing the port's flow control is not supported if this isn't the
756 * port's controlling PF
757 */
758 if (hw->partition_id != 1) {
759 i40e_partition_setting_complaint(pf);
760 return -EOPNOTSUPP;
761 }
762
Catherine Sullivan2becc352014-06-04 08:45:27 +0000763 if (vsi != pf->vsi[pf->lan_vsi])
764 return -EOPNOTSUPP;
765
766 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
767 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
768 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
769 return -EOPNOTSUPP;
770 }
771
772 /* If we have link and don't have autoneg */
773 if (!test_bit(__I40E_DOWN, &pf->state) &&
774 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
775 /* Send message that it might not necessarily work*/
776 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
777 }
778
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000779 if (dcbx_cfg->pfc.pfcenable) {
780 netdev_info(netdev,
781 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000782 return -EOPNOTSUPP;
783 }
784
785 if (pause->rx_pause && pause->tx_pause)
786 hw->fc.requested_mode = I40E_FC_FULL;
787 else if (pause->rx_pause && !pause->tx_pause)
788 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
789 else if (!pause->rx_pause && pause->tx_pause)
790 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
791 else if (!pause->rx_pause && !pause->tx_pause)
792 hw->fc.requested_mode = I40E_FC_NONE;
793 else
794 return -EINVAL;
795
Catherine Sullivan94128512014-07-12 07:28:16 +0000796 /* Tell the OS link is going down, the link will go back up when fw
797 * says it is ready asynchronously
798 */
799 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
800 netif_carrier_off(netdev);
801 netif_tx_stop_all_queues(netdev);
802
Catherine Sullivan2becc352014-06-04 08:45:27 +0000803 /* Set the fc mode and only restart an if link is up*/
804 status = i40e_set_fc(hw, &aq_failures, link_up);
805
806 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
807 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
808 status, hw->aq.asq_last_status);
809 err = -EAGAIN;
810 }
811 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
812 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
813 status, hw->aq.asq_last_status);
814 err = -EAGAIN;
815 }
816 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000817 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 +0000818 status, hw->aq.asq_last_status);
819 err = -EAGAIN;
820 }
821
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000822 if (!test_bit(__I40E_DOWN, &pf->state)) {
823 /* Give it a little more time to try to come back */
824 msleep(75);
825 if (!test_bit(__I40E_DOWN, &pf->state))
826 return i40e_nway_reset(netdev);
827 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000828
829 return err;
830}
831
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000832static u32 i40e_get_msglevel(struct net_device *netdev)
833{
834 struct i40e_netdev_priv *np = netdev_priv(netdev);
835 struct i40e_pf *pf = np->vsi->back;
836
837 return pf->msg_enable;
838}
839
840static void i40e_set_msglevel(struct net_device *netdev, u32 data)
841{
842 struct i40e_netdev_priv *np = netdev_priv(netdev);
843 struct i40e_pf *pf = np->vsi->back;
844
845 if (I40E_DEBUG_USER & data)
846 pf->hw.debug_mask = data;
847 pf->msg_enable = data;
848}
849
850static int i40e_get_regs_len(struct net_device *netdev)
851{
852 int reg_count = 0;
853 int i;
854
855 for (i = 0; i40e_reg_list[i].offset != 0; i++)
856 reg_count += i40e_reg_list[i].elements;
857
858 return reg_count * sizeof(u32);
859}
860
861static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
862 void *p)
863{
864 struct i40e_netdev_priv *np = netdev_priv(netdev);
865 struct i40e_pf *pf = np->vsi->back;
866 struct i40e_hw *hw = &pf->hw;
867 u32 *reg_buf = p;
868 int i, j, ri;
869 u32 reg;
870
871 /* Tell ethtool which driver-version-specific regs output we have.
872 *
873 * At some point, if we have ethtool doing special formatting of
874 * this data, it will rely on this version number to know how to
875 * interpret things. Hence, this needs to be updated if/when the
876 * diags register table is changed.
877 */
878 regs->version = 1;
879
880 /* loop through the diags reg table for what to print */
881 ri = 0;
882 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
883 for (j = 0; j < i40e_reg_list[i].elements; j++) {
884 reg = i40e_reg_list[i].offset
885 + (j * i40e_reg_list[i].stride);
886 reg_buf[ri++] = rd32(hw, reg);
887 }
888 }
889
890}
891
892static int i40e_get_eeprom(struct net_device *netdev,
893 struct ethtool_eeprom *eeprom, u8 *bytes)
894{
895 struct i40e_netdev_priv *np = netdev_priv(netdev);
896 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000897 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000898 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000899 u8 *eeprom_buff;
900 u16 i, sectors;
901 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000902 u32 magic;
903
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000904#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000905 if (eeprom->len == 0)
906 return -EINVAL;
907
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000908 /* check for NVMUpdate access method */
909 magic = hw->vendor_id | (hw->device_id << 16);
910 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000911 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000912 int errno;
913
914 /* make sure it is the right magic for NVMUpdate */
915 if ((eeprom->magic >> 16) != hw->device_id)
916 return -EINVAL;
917
Shannon Nelsonc150a502014-11-13 08:23:13 +0000918 cmd = (struct i40e_nvm_access *)eeprom;
919 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000920 if (ret_val)
921 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000922 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
923 ret_val, hw->aq.asq_last_status, errno,
924 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
925 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000926
927 return errno;
928 }
929
930 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000931 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
932
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000933 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000934 if (!eeprom_buff)
935 return -ENOMEM;
936
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000937 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
938 if (ret_val) {
939 dev_info(&pf->pdev->dev,
940 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
941 ret_val, hw->aq.asq_last_status);
942 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000943 }
944
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000945 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
946 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
947 len = I40E_NVM_SECTOR_SIZE;
948 last = false;
949 for (i = 0; i < sectors; i++) {
950 if (i == (sectors - 1)) {
951 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
952 last = true;
953 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000954 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
955 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000956 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000957 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000958 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000959 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000960 "read NVM failed, invalid offset 0x%x\n",
961 offset);
962 break;
963 } else if (ret_val &&
964 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
965 dev_info(&pf->pdev->dev,
966 "read NVM failed, access, offset 0x%x\n",
967 offset);
968 break;
969 } else if (ret_val) {
970 dev_info(&pf->pdev->dev,
971 "read NVM failed offset %d err=%d status=0x%x\n",
972 offset, ret_val, hw->aq.asq_last_status);
973 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000974 }
975 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000976
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000977 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000978 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000979free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000980 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000981 return ret_val;
982}
983
984static int i40e_get_eeprom_len(struct net_device *netdev)
985{
986 struct i40e_netdev_priv *np = netdev_priv(netdev);
987 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000988 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000989
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000990 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
991 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
992 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
993 /* register returns value in power of 2, 64Kbyte chunks. */
994 val = (64 * 1024) * (1 << val);
995 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000996}
997
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000998static int i40e_set_eeprom(struct net_device *netdev,
999 struct ethtool_eeprom *eeprom, u8 *bytes)
1000{
1001 struct i40e_netdev_priv *np = netdev_priv(netdev);
1002 struct i40e_hw *hw = &np->vsi->back->hw;
1003 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001004 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001005 int ret_val = 0;
1006 int errno;
1007 u32 magic;
1008
1009 /* normal ethtool set_eeprom is not supported */
1010 magic = hw->vendor_id | (hw->device_id << 16);
1011 if (eeprom->magic == magic)
1012 return -EOPNOTSUPP;
1013
1014 /* check for NVMUpdate access method */
1015 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1016 return -EINVAL;
1017
1018 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1019 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1020 return -EBUSY;
1021
Shannon Nelsonc150a502014-11-13 08:23:13 +00001022 cmd = (struct i40e_nvm_access *)eeprom;
1023 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1024 if (ret_val && hw->aq.asq_last_status != I40E_AQ_RC_EBUSY)
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001025 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001026 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1027 ret_val, hw->aq.asq_last_status, errno,
1028 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1029 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001030
1031 return errno;
1032}
1033
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001034static void i40e_get_drvinfo(struct net_device *netdev,
1035 struct ethtool_drvinfo *drvinfo)
1036{
1037 struct i40e_netdev_priv *np = netdev_priv(netdev);
1038 struct i40e_vsi *vsi = np->vsi;
1039 struct i40e_pf *pf = vsi->back;
1040
1041 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1042 strlcpy(drvinfo->version, i40e_driver_version_str,
1043 sizeof(drvinfo->version));
1044 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1045 sizeof(drvinfo->fw_version));
1046 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1047 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001048 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001049}
1050
1051static void i40e_get_ringparam(struct net_device *netdev,
1052 struct ethtool_ringparam *ring)
1053{
1054 struct i40e_netdev_priv *np = netdev_priv(netdev);
1055 struct i40e_pf *pf = np->vsi->back;
1056 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1057
1058 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1059 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1060 ring->rx_mini_max_pending = 0;
1061 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001062 ring->rx_pending = vsi->rx_rings[0]->count;
1063 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001064 ring->rx_mini_pending = 0;
1065 ring->rx_jumbo_pending = 0;
1066}
1067
1068static int i40e_set_ringparam(struct net_device *netdev,
1069 struct ethtool_ringparam *ring)
1070{
1071 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1072 struct i40e_netdev_priv *np = netdev_priv(netdev);
1073 struct i40e_vsi *vsi = np->vsi;
1074 struct i40e_pf *pf = vsi->back;
1075 u32 new_rx_count, new_tx_count;
1076 int i, err = 0;
1077
1078 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1079 return -EINVAL;
1080
Shannon Nelson1fa18372013-11-20 10:03:08 +00001081 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1082 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1083 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1084 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1085 netdev_info(netdev,
1086 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1087 ring->tx_pending, ring->rx_pending,
1088 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1089 return -EINVAL;
1090 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001091
Shannon Nelson1fa18372013-11-20 10:03:08 +00001092 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1093 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001094
1095 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001096 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1097 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001098 return 0;
1099
1100 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1101 usleep_range(1000, 2000);
1102
1103 if (!netif_running(vsi->netdev)) {
1104 /* simple case - set for the next time the netdev is started */
1105 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001106 vsi->tx_rings[i]->count = new_tx_count;
1107 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001108 }
1109 goto done;
1110 }
1111
1112 /* We can't just free everything and then setup again,
1113 * because the ISRs in MSI-X mode get passed pointers
1114 * to the Tx and Rx ring structs.
1115 */
1116
1117 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001118 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001119 netdev_info(netdev,
1120 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001121 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001122 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1123 sizeof(struct i40e_ring), GFP_KERNEL);
1124 if (!tx_rings) {
1125 err = -ENOMEM;
1126 goto done;
1127 }
1128
1129 for (i = 0; i < vsi->num_queue_pairs; i++) {
1130 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001131 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001132 tx_rings[i].count = new_tx_count;
1133 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1134 if (err) {
1135 while (i) {
1136 i--;
1137 i40e_free_tx_resources(&tx_rings[i]);
1138 }
1139 kfree(tx_rings);
1140 tx_rings = NULL;
1141
1142 goto done;
1143 }
1144 }
1145 }
1146
1147 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001148 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001149 netdev_info(netdev,
1150 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001151 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001152 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1153 sizeof(struct i40e_ring), GFP_KERNEL);
1154 if (!rx_rings) {
1155 err = -ENOMEM;
1156 goto free_tx;
1157 }
1158
1159 for (i = 0; i < vsi->num_queue_pairs; i++) {
1160 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001161 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001162 rx_rings[i].count = new_rx_count;
1163 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1164 if (err) {
1165 while (i) {
1166 i--;
1167 i40e_free_rx_resources(&rx_rings[i]);
1168 }
1169 kfree(rx_rings);
1170 rx_rings = NULL;
1171
1172 goto free_tx;
1173 }
1174 }
1175 }
1176
1177 /* Bring interface down, copy in the new ring info,
1178 * then restore the interface
1179 */
1180 i40e_down(vsi);
1181
1182 if (tx_rings) {
1183 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001184 i40e_free_tx_resources(vsi->tx_rings[i]);
1185 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001186 }
1187 kfree(tx_rings);
1188 tx_rings = NULL;
1189 }
1190
1191 if (rx_rings) {
1192 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001193 i40e_free_rx_resources(vsi->rx_rings[i]);
1194 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001195 }
1196 kfree(rx_rings);
1197 rx_rings = NULL;
1198 }
1199
1200 i40e_up(vsi);
1201
1202free_tx:
1203 /* error cleanup if the Rx allocations failed after getting Tx */
1204 if (tx_rings) {
1205 for (i = 0; i < vsi->num_queue_pairs; i++)
1206 i40e_free_tx_resources(&tx_rings[i]);
1207 kfree(tx_rings);
1208 tx_rings = NULL;
1209 }
1210
1211done:
1212 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1213
1214 return err;
1215}
1216
1217static int i40e_get_sset_count(struct net_device *netdev, int sset)
1218{
1219 struct i40e_netdev_priv *np = netdev_priv(netdev);
1220 struct i40e_vsi *vsi = np->vsi;
1221 struct i40e_pf *pf = vsi->back;
1222
1223 switch (sset) {
1224 case ETH_SS_TEST:
1225 return I40E_TEST_LEN;
1226 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001227 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001228 int len = I40E_PF_STATS_LEN(netdev);
1229
1230 if (pf->lan_veb != I40E_NO_VEB)
1231 len += I40E_VEB_STATS_LEN;
1232 return len;
1233 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001234 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001235 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001236 case ETH_SS_PRIV_FLAGS:
1237 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001238 default:
1239 return -EOPNOTSUPP;
1240 }
1241}
1242
1243static void i40e_get_ethtool_stats(struct net_device *netdev,
1244 struct ethtool_stats *stats, u64 *data)
1245{
1246 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001247 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248 struct i40e_vsi *vsi = np->vsi;
1249 struct i40e_pf *pf = vsi->back;
1250 int i = 0;
1251 char *p;
1252 int j;
1253 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001254 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001255
1256 i40e_update_stats(vsi);
1257
1258 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1259 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1260 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1261 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1262 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001263 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1264 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1265 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1266 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1267 }
Vasu Dev38e00432014-08-01 13:27:03 -07001268#ifdef I40E_FCOE
1269 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1270 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1271 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1272 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1273 }
1274#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001275 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001276 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001277 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001278
1279 if (!tx_ring)
1280 continue;
1281
1282 /* process Tx ring statistics */
1283 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001284 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001285 data[i] = tx_ring->stats.packets;
1286 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001287 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001288 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001289
1290 /* Rx ring is the 2nd half of the queue pair */
1291 rx_ring = &tx_ring[1];
1292 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001293 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001294 data[i] = rx_ring->stats.packets;
1295 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001296 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001297 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001298 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001299 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001300 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001301 return;
1302
1303 if (pf->lan_veb != I40E_NO_VEB) {
1304 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1305 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1306 p = (char *)veb;
1307 p += i40e_gstrings_veb_stats[j].stat_offset;
1308 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1309 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001310 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001311 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001312 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1313 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1314 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1315 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1316 }
1317 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1318 data[i++] = pf->stats.priority_xon_tx[j];
1319 data[i++] = pf->stats.priority_xoff_tx[j];
1320 }
1321 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1322 data[i++] = pf->stats.priority_xon_rx[j];
1323 data[i++] = pf->stats.priority_xoff_rx[j];
1324 }
1325 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1326 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001327}
1328
1329static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1330 u8 *data)
1331{
1332 struct i40e_netdev_priv *np = netdev_priv(netdev);
1333 struct i40e_vsi *vsi = np->vsi;
1334 struct i40e_pf *pf = vsi->back;
1335 char *p = (char *)data;
1336 int i;
1337
1338 switch (stringset) {
1339 case ETH_SS_TEST:
1340 for (i = 0; i < I40E_TEST_LEN; i++) {
1341 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1342 data += ETH_GSTRING_LEN;
1343 }
1344 break;
1345 case ETH_SS_STATS:
1346 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1347 snprintf(p, ETH_GSTRING_LEN, "%s",
1348 i40e_gstrings_net_stats[i].stat_string);
1349 p += ETH_GSTRING_LEN;
1350 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001351 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1352 snprintf(p, ETH_GSTRING_LEN, "%s",
1353 i40e_gstrings_misc_stats[i].stat_string);
1354 p += ETH_GSTRING_LEN;
1355 }
Vasu Dev38e00432014-08-01 13:27:03 -07001356#ifdef I40E_FCOE
1357 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1358 snprintf(p, ETH_GSTRING_LEN, "%s",
1359 i40e_gstrings_fcoe_stats[i].stat_string);
1360 p += ETH_GSTRING_LEN;
1361 }
1362#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001363 for (i = 0; i < vsi->num_queue_pairs; i++) {
1364 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1365 p += ETH_GSTRING_LEN;
1366 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1367 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001368 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1369 p += ETH_GSTRING_LEN;
1370 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1371 p += ETH_GSTRING_LEN;
1372 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001373 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001374 return;
1375
1376 if (pf->lan_veb != I40E_NO_VEB) {
1377 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1378 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1379 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001380 p += ETH_GSTRING_LEN;
1381 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001382 }
1383 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1384 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1385 i40e_gstrings_stats[i].stat_string);
1386 p += ETH_GSTRING_LEN;
1387 }
1388 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1389 snprintf(p, ETH_GSTRING_LEN,
1390 "port.tx_priority_%u_xon", i);
1391 p += ETH_GSTRING_LEN;
1392 snprintf(p, ETH_GSTRING_LEN,
1393 "port.tx_priority_%u_xoff", i);
1394 p += ETH_GSTRING_LEN;
1395 }
1396 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1397 snprintf(p, ETH_GSTRING_LEN,
1398 "port.rx_priority_%u_xon", i);
1399 p += ETH_GSTRING_LEN;
1400 snprintf(p, ETH_GSTRING_LEN,
1401 "port.rx_priority_%u_xoff", i);
1402 p += ETH_GSTRING_LEN;
1403 }
1404 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1405 snprintf(p, ETH_GSTRING_LEN,
1406 "port.rx_priority_%u_xon_2_xoff", i);
1407 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001408 }
1409 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1410 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001411 case ETH_SS_PRIV_FLAGS:
1412 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1413 memcpy(data, i40e_priv_flags_strings[i],
1414 ETH_GSTRING_LEN);
1415 data += ETH_GSTRING_LEN;
1416 }
1417 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001418 default:
1419 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 }
1421}
1422
1423static int i40e_get_ts_info(struct net_device *dev,
1424 struct ethtool_ts_info *info)
1425{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001426 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1427
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001428 /* only report HW timestamping if PTP is enabled */
1429 if (!(pf->flags & I40E_FLAG_PTP))
1430 return ethtool_op_get_ts_info(dev, info);
1431
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001432 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1433 SOF_TIMESTAMPING_RX_SOFTWARE |
1434 SOF_TIMESTAMPING_SOFTWARE |
1435 SOF_TIMESTAMPING_TX_HARDWARE |
1436 SOF_TIMESTAMPING_RX_HARDWARE |
1437 SOF_TIMESTAMPING_RAW_HARDWARE;
1438
1439 if (pf->ptp_clock)
1440 info->phc_index = ptp_clock_index(pf->ptp_clock);
1441 else
1442 info->phc_index = -1;
1443
1444 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1445
1446 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1447 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1448 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1449 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1450 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1451 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1452 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1453 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1454 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1455 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1456 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1457 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1458
1459 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001460}
1461
Shannon Nelson7b086392013-11-20 10:02:59 +00001462static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001463{
Shannon Nelson7b086392013-11-20 10:02:59 +00001464 struct i40e_netdev_priv *np = netdev_priv(netdev);
1465 struct i40e_pf *pf = np->vsi->back;
1466
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001467 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001468 if (i40e_get_link_status(&pf->hw))
1469 *data = 0;
1470 else
1471 *data = 1;
1472
1473 return *data;
1474}
1475
Shannon Nelson7b086392013-11-20 10:02:59 +00001476static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477{
Shannon Nelson7b086392013-11-20 10:02:59 +00001478 struct i40e_netdev_priv *np = netdev_priv(netdev);
1479 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001481 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001482 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483
Shannon Nelson7b086392013-11-20 10:02:59 +00001484 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001485}
1486
Shannon Nelson7b086392013-11-20 10:02:59 +00001487static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001488{
Shannon Nelson7b086392013-11-20 10:02:59 +00001489 struct i40e_netdev_priv *np = netdev_priv(netdev);
1490 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001491
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001492 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001493 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494
Shannon Nelson4443ec92014-11-13 08:23:12 +00001495 /* forcebly clear the NVM Update state machine */
1496 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1497
Shannon Nelson7b086392013-11-20 10:02:59 +00001498 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001499}
1500
Shannon Nelson7b086392013-11-20 10:02:59 +00001501static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001502{
Shannon Nelson7b086392013-11-20 10:02:59 +00001503 struct i40e_netdev_priv *np = netdev_priv(netdev);
1504 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001505 u16 swc_old = pf->sw_int_count;
1506
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001507 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001508 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1509 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001510 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1511 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1512 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1513 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001514 usleep_range(1000, 2000);
1515 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516
1517 return *data;
1518}
1519
Shannon Nelson7b086392013-11-20 10:02:59 +00001520static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001521{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001522 struct i40e_netdev_priv *np = netdev_priv(netdev);
1523 struct i40e_pf *pf = np->vsi->back;
1524
1525 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001526 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001527
1528 return *data;
1529}
1530
1531static void i40e_diag_test(struct net_device *netdev,
1532 struct ethtool_test *eth_test, u64 *data)
1533{
1534 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001535 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536 struct i40e_pf *pf = np->vsi->back;
1537
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001538 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1539 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001540 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001541
Shannon Nelsonf551b432013-11-26 10:49:12 +00001542 set_bit(__I40E_TESTING, &pf->state);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001543 /* If the device is online then take it offline */
1544 if (if_running)
1545 /* indicate we're in test mode */
1546 dev_close(netdev);
1547 else
1548 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001549
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001550 /* Link test performed before hardware reset
1551 * so autoneg doesn't interfere with test result
1552 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001553 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554 eth_test->flags |= ETH_TEST_FL_FAILED;
1555
Shannon Nelson7b086392013-11-20 10:02:59 +00001556 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557 eth_test->flags |= ETH_TEST_FL_FAILED;
1558
Shannon Nelson7b086392013-11-20 10:02:59 +00001559 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001560 eth_test->flags |= ETH_TEST_FL_FAILED;
1561
Shannon Nelson7b086392013-11-20 10:02:59 +00001562 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563 eth_test->flags |= ETH_TEST_FL_FAILED;
1564
Shannon Nelsonf551b432013-11-26 10:49:12 +00001565 /* run reg test last, a reset is required after it */
1566 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1567 eth_test->flags |= ETH_TEST_FL_FAILED;
1568
1569 clear_bit(__I40E_TESTING, &pf->state);
1570 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001571
1572 if (if_running)
1573 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001574 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001575 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001576 netif_info(pf, drv, netdev, "online testing starting\n");
1577
Shannon Nelson7b086392013-11-20 10:02:59 +00001578 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001579 eth_test->flags |= ETH_TEST_FL_FAILED;
1580
1581 /* Offline only tests, not run in online; pass by default */
1582 data[I40E_ETH_TEST_REG] = 0;
1583 data[I40E_ETH_TEST_EEPROM] = 0;
1584 data[I40E_ETH_TEST_INTR] = 0;
1585 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001586 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001587
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001588 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001589}
1590
1591static void i40e_get_wol(struct net_device *netdev,
1592 struct ethtool_wolinfo *wol)
1593{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001594 struct i40e_netdev_priv *np = netdev_priv(netdev);
1595 struct i40e_pf *pf = np->vsi->back;
1596 struct i40e_hw *hw = &pf->hw;
1597 u16 wol_nvm_bits;
1598
1599 /* NVM bit on means WoL disabled for the port */
1600 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001601 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001602 wol->supported = 0;
1603 wol->wolopts = 0;
1604 } else {
1605 wol->supported = WAKE_MAGIC;
1606 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1607 }
1608}
1609
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001610/**
1611 * i40e_set_wol - set the WakeOnLAN configuration
1612 * @netdev: the netdev in question
1613 * @wol: the ethtool WoL setting data
1614 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001615static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1616{
1617 struct i40e_netdev_priv *np = netdev_priv(netdev);
1618 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001619 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001620 struct i40e_hw *hw = &pf->hw;
1621 u16 wol_nvm_bits;
1622
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001623 /* WoL not supported if this isn't the controlling PF on the port */
1624 if (hw->partition_id != 1) {
1625 i40e_partition_setting_complaint(pf);
1626 return -EOPNOTSUPP;
1627 }
1628
1629 if (vsi != pf->vsi[pf->lan_vsi])
1630 return -EOPNOTSUPP;
1631
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001632 /* NVM bit on means WoL disabled for the port */
1633 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1634 if (((1 << hw->port) & wol_nvm_bits))
1635 return -EOPNOTSUPP;
1636
1637 /* only magic packet is supported */
1638 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1639 return -EOPNOTSUPP;
1640
1641 /* is this a new value? */
1642 if (pf->wol_en != !!wol->wolopts) {
1643 pf->wol_en = !!wol->wolopts;
1644 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1645 }
1646
1647 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001648}
1649
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001650static int i40e_set_phys_id(struct net_device *netdev,
1651 enum ethtool_phys_id_state state)
1652{
1653 struct i40e_netdev_priv *np = netdev_priv(netdev);
1654 struct i40e_pf *pf = np->vsi->back;
1655 struct i40e_hw *hw = &pf->hw;
1656 int blink_freq = 2;
1657
1658 switch (state) {
1659 case ETHTOOL_ID_ACTIVE:
1660 pf->led_status = i40e_led_get(hw);
1661 return blink_freq;
1662 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001663 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001664 break;
1665 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001666 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667 break;
1668 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001669 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001670 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001671 default:
1672 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001673 }
1674
1675 return 0;
1676}
1677
1678/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1679 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1680 * 125us (8000 interrupts per second) == ITR(62)
1681 */
1682
1683static int i40e_get_coalesce(struct net_device *netdev,
1684 struct ethtool_coalesce *ec)
1685{
1686 struct i40e_netdev_priv *np = netdev_priv(netdev);
1687 struct i40e_vsi *vsi = np->vsi;
1688
1689 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1690 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1691
1692 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001693 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694
1695 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001696 ec->use_adaptive_tx_coalesce = 1;
1697
1698 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1699 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001700
1701 return 0;
1702}
1703
1704static int i40e_set_coalesce(struct net_device *netdev,
1705 struct ethtool_coalesce *ec)
1706{
1707 struct i40e_netdev_priv *np = netdev_priv(netdev);
1708 struct i40e_q_vector *q_vector;
1709 struct i40e_vsi *vsi = np->vsi;
1710 struct i40e_pf *pf = vsi->back;
1711 struct i40e_hw *hw = &pf->hw;
1712 u16 vector;
1713 int i;
1714
1715 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1716 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1717
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001718 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001719 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001720 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001722 } else if (ec->rx_coalesce_usecs == 0) {
1723 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001724 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001725 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 +00001726 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001727 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001728 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001729 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001730
Mitch Williams32f5f542014-04-04 04:43:10 +00001731 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001732 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001734 } else if (ec->tx_coalesce_usecs == 0) {
1735 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001736 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001737 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 +00001738 } else {
1739 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001740 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001741 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001742 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001743
1744 if (ec->use_adaptive_rx_coalesce)
1745 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1746 else
1747 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1748
1749 if (ec->use_adaptive_tx_coalesce)
1750 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1751 else
1752 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001753
Alexander Duyck493fb302013-09-28 07:01:44 +00001754 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1755 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001756 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1757 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1758 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1759 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1760 i40e_flush(hw);
1761 }
1762
1763 return 0;
1764}
1765
1766/**
1767 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1768 * @pf: pointer to the physical function struct
1769 * @cmd: ethtool rxnfc command
1770 *
1771 * Returns Success if the flow is supported, else Invalid Input.
1772 **/
1773static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1774{
1775 cmd->data = 0;
1776
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001777 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1778 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1779 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1780 return 0;
1781 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001782 /* Report default options for RSS on i40e */
1783 switch (cmd->flow_type) {
1784 case TCP_V4_FLOW:
1785 case UDP_V4_FLOW:
1786 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1787 /* fall through to add IP fields */
1788 case SCTP_V4_FLOW:
1789 case AH_ESP_V4_FLOW:
1790 case AH_V4_FLOW:
1791 case ESP_V4_FLOW:
1792 case IPV4_FLOW:
1793 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1794 break;
1795 case TCP_V6_FLOW:
1796 case UDP_V6_FLOW:
1797 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1798 /* fall through to add IP fields */
1799 case SCTP_V6_FLOW:
1800 case AH_ESP_V6_FLOW:
1801 case AH_V6_FLOW:
1802 case ESP_V6_FLOW:
1803 case IPV6_FLOW:
1804 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1805 break;
1806 default:
1807 return -EINVAL;
1808 }
1809
1810 return 0;
1811}
1812
1813/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001814 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1815 * @pf: Pointer to the physical function struct
1816 * @cmd: The command to get or set Rx flow classification rules
1817 * @rule_locs: Array of used rule locations
1818 *
1819 * This function populates both the total and actual rule count of
1820 * the ethtool flow classification command
1821 *
1822 * Returns 0 on success or -EMSGSIZE if entry not found
1823 **/
1824static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1825 struct ethtool_rxnfc *cmd,
1826 u32 *rule_locs)
1827{
1828 struct i40e_fdir_filter *rule;
1829 struct hlist_node *node2;
1830 int cnt = 0;
1831
1832 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001833 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001834
1835 hlist_for_each_entry_safe(rule, node2,
1836 &pf->fdir_filter_list, fdir_node) {
1837 if (cnt == cmd->rule_cnt)
1838 return -EMSGSIZE;
1839
1840 rule_locs[cnt] = rule->fd_id;
1841 cnt++;
1842 }
1843
1844 cmd->rule_cnt = cnt;
1845
1846 return 0;
1847}
1848
1849/**
1850 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1851 * @pf: Pointer to the physical function struct
1852 * @cmd: The command to get or set Rx flow classification rules
1853 *
1854 * This function looks up a filter based on the Rx flow classification
1855 * command and fills the flow spec info for it if found
1856 *
1857 * Returns 0 on success or -EINVAL if filter not found
1858 **/
1859static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1860 struct ethtool_rxnfc *cmd)
1861{
1862 struct ethtool_rx_flow_spec *fsp =
1863 (struct ethtool_rx_flow_spec *)&cmd->fs;
1864 struct i40e_fdir_filter *rule = NULL;
1865 struct hlist_node *node2;
1866
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001867 hlist_for_each_entry_safe(rule, node2,
1868 &pf->fdir_filter_list, fdir_node) {
1869 if (fsp->location <= rule->fd_id)
1870 break;
1871 }
1872
1873 if (!rule || fsp->location != rule->fd_id)
1874 return -EINVAL;
1875
1876 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001877 if (fsp->flow_type == IP_USER_FLOW) {
1878 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1879 fsp->h_u.usr_ip4_spec.proto = 0;
1880 fsp->m_u.usr_ip4_spec.proto = 0;
1881 }
1882
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001883 /* Reverse the src and dest notion, since the HW views them from
1884 * Tx perspective where as the user expects it from Rx filter view.
1885 */
1886 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1887 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1888 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1889 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001890
1891 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1892 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1893 else
1894 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001895
1896 return 0;
1897}
1898
1899/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001900 * i40e_get_rxnfc - command to get RX flow classification rules
1901 * @netdev: network interface device structure
1902 * @cmd: ethtool rxnfc command
1903 *
1904 * Returns Success if the command is supported.
1905 **/
1906static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1907 u32 *rule_locs)
1908{
1909 struct i40e_netdev_priv *np = netdev_priv(netdev);
1910 struct i40e_vsi *vsi = np->vsi;
1911 struct i40e_pf *pf = vsi->back;
1912 int ret = -EOPNOTSUPP;
1913
1914 switch (cmd->cmd) {
1915 case ETHTOOL_GRXRINGS:
1916 cmd->data = vsi->alloc_queue_pairs;
1917 ret = 0;
1918 break;
1919 case ETHTOOL_GRXFH:
1920 ret = i40e_get_rss_hash_opts(pf, cmd);
1921 break;
1922 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001923 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001924 /* report total rule count */
1925 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001926 ret = 0;
1927 break;
1928 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001929 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930 break;
1931 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001932 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1933 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001934 default:
1935 break;
1936 }
1937
1938 return ret;
1939}
1940
1941/**
1942 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1943 * @pf: pointer to the physical function struct
1944 * @cmd: ethtool rxnfc command
1945 *
1946 * Returns Success if the flow input set is supported.
1947 **/
1948static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1949{
1950 struct i40e_hw *hw = &pf->hw;
1951 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1952 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1953
1954 /* RSS does not support anything other than hashing
1955 * to queues on src and dst IPs and ports
1956 */
1957 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1958 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1959 return -EINVAL;
1960
1961 /* We need at least the IP SRC and DEST fields for hashing */
1962 if (!(nfc->data & RXH_IP_SRC) ||
1963 !(nfc->data & RXH_IP_DST))
1964 return -EINVAL;
1965
1966 switch (nfc->flow_type) {
1967 case TCP_V4_FLOW:
1968 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1969 case 0:
1970 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1971 break;
1972 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1973 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1974 break;
1975 default:
1976 return -EINVAL;
1977 }
1978 break;
1979 case TCP_V6_FLOW:
1980 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1981 case 0:
1982 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1983 break;
1984 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1985 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1986 break;
1987 default:
1988 return -EINVAL;
1989 }
1990 break;
1991 case UDP_V4_FLOW:
1992 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1993 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001994 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1995 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001996 break;
1997 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001998 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1999 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002000 break;
2001 default:
2002 return -EINVAL;
2003 }
2004 break;
2005 case UDP_V6_FLOW:
2006 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2007 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002008 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2009 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002010 break;
2011 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002012 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2013 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002014 break;
2015 default:
2016 return -EINVAL;
2017 }
2018 break;
2019 case AH_ESP_V4_FLOW:
2020 case AH_V4_FLOW:
2021 case ESP_V4_FLOW:
2022 case SCTP_V4_FLOW:
2023 if ((nfc->data & RXH_L4_B_0_1) ||
2024 (nfc->data & RXH_L4_B_2_3))
2025 return -EINVAL;
2026 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2027 break;
2028 case AH_ESP_V6_FLOW:
2029 case AH_V6_FLOW:
2030 case ESP_V6_FLOW:
2031 case SCTP_V6_FLOW:
2032 if ((nfc->data & RXH_L4_B_0_1) ||
2033 (nfc->data & RXH_L4_B_2_3))
2034 return -EINVAL;
2035 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2036 break;
2037 case IPV4_FLOW:
2038 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2039 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2040 break;
2041 case IPV6_FLOW:
2042 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2043 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2044 break;
2045 default:
2046 return -EINVAL;
2047 }
2048
2049 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2050 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2051 i40e_flush(hw);
2052
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002053 /* Save setting for future output/update */
2054 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2055
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002056 return 0;
2057}
2058
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002059/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002060 * i40e_match_fdir_input_set - Match a new filter against an existing one
2061 * @rule: The filter already added
2062 * @input: The new filter to comapre against
2063 *
2064 * Returns true if the two input set match
2065 **/
2066static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2067 struct i40e_fdir_filter *input)
2068{
2069 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2070 (rule->src_ip[0] != input->src_ip[0]) ||
2071 (rule->dst_port != input->dst_port) ||
2072 (rule->src_port != input->src_port))
2073 return false;
2074 return true;
2075}
2076
2077/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002078 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2079 * @vsi: Pointer to the targeted VSI
2080 * @input: The filter to update or NULL to indicate deletion
2081 * @sw_idx: Software index to the filter
2082 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002083 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002084 * This function updates (or deletes) a Flow Director entry from
2085 * the hlist of the corresponding PF
2086 *
2087 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002088 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002089static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2090 struct i40e_fdir_filter *input,
2091 u16 sw_idx,
2092 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002093{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002094 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002095 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002096 struct hlist_node *node2;
2097 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002098
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002099 parent = NULL;
2100 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002101
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002102 hlist_for_each_entry_safe(rule, node2,
2103 &pf->fdir_filter_list, fdir_node) {
2104 /* hash found, or no matching entry */
2105 if (rule->fd_id >= sw_idx)
2106 break;
2107 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002108 }
2109
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002110 /* if there is an old rule occupying our place remove it */
2111 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002112 if (input && !i40e_match_fdir_input_set(rule, input))
2113 err = i40e_add_del_fdir(vsi, rule, false);
2114 else if (!input)
2115 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002116 hlist_del(&rule->fdir_node);
2117 kfree(rule);
2118 pf->fdir_pf_active_filters--;
2119 }
2120
2121 /* If no input this was a delete, err should be 0 if a rule was
2122 * successfully found and removed from the list else -EINVAL
2123 */
2124 if (!input)
2125 return err;
2126
2127 /* initialize node and set software index */
2128 INIT_HLIST_NODE(&input->fdir_node);
2129
2130 /* add filter to the list */
2131 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002132 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002133 else
2134 hlist_add_head(&input->fdir_node,
2135 &pf->fdir_filter_list);
2136
2137 /* update counts */
2138 pf->fdir_pf_active_filters++;
2139
2140 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002141}
2142
2143/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002144 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2145 * @vsi: Pointer to the targeted VSI
2146 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002147 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002148 * The function removes a Flow Director filter entry from the
2149 * hlist of the corresponding PF
2150 *
2151 * Returns 0 on success
2152 */
2153static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2154 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002156 struct ethtool_rx_flow_spec *fsp =
2157 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002158 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002159 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002160
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002161 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2162 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2163 return -EBUSY;
2164
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002165 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2166 return -EBUSY;
2167
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002168 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002169
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002170 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002171 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172}
2173
2174/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002175 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002176 * @vsi: pointer to the targeted VSI
2177 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002179 * Add Flow Director filters for a specific flow spec based on their
2180 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002181 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002182static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2183 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002185 struct ethtool_rx_flow_spec *fsp;
2186 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002188 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002189
2190 if (!vsi)
2191 return -EINVAL;
2192
2193 pf = vsi->back;
2194
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002195 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2196 return -EOPNOTSUPP;
2197
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002198 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002199 return -ENOSPC;
2200
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002201 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2202 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2203 return -EBUSY;
2204
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002205 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2206 return -EBUSY;
2207
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002208 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2209
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002210 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2211 pf->hw.func_caps.fd_filters_guaranteed)) {
2212 return -EINVAL;
2213 }
2214
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002215 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2216 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002217 return -EINVAL;
2218
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002219 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002220
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002221 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002222 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002223
2224 input->fd_id = fsp->location;
2225
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002226 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2227 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2228 else
2229 input->dest_ctl =
2230 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2231
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002232 input->q_index = fsp->ring_cookie;
2233 input->flex_off = 0;
2234 input->pctype = 0;
2235 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002236 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002237 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002238 input->flow_type = fsp->flow_type;
2239 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002240
2241 /* Reverse the src and dest notion, since the HW expects them to be from
2242 * Tx perspective where as the input from user is from Rx filter view.
2243 */
2244 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2245 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2246 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2247 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002248
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002249 ret = i40e_add_del_fdir(vsi, input, true);
2250 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002251 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002252 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002253 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002254
2255 return ret;
2256}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002257
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002258/**
2259 * i40e_set_rxnfc - command to set RX flow classification rules
2260 * @netdev: network interface device structure
2261 * @cmd: ethtool rxnfc command
2262 *
2263 * Returns Success if the command is supported.
2264 **/
2265static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2266{
2267 struct i40e_netdev_priv *np = netdev_priv(netdev);
2268 struct i40e_vsi *vsi = np->vsi;
2269 struct i40e_pf *pf = vsi->back;
2270 int ret = -EOPNOTSUPP;
2271
2272 switch (cmd->cmd) {
2273 case ETHTOOL_SRXFH:
2274 ret = i40e_set_rss_hash_opt(pf, cmd);
2275 break;
2276 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002277 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002278 break;
2279 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002280 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 break;
2282 default:
2283 break;
2284 }
2285
2286 return ret;
2287}
2288
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002289/**
2290 * i40e_max_channels - get Max number of combined channels supported
2291 * @vsi: vsi pointer
2292 **/
2293static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2294{
2295 /* TODO: This code assumes DCB and FD is disabled for now. */
2296 return vsi->alloc_queue_pairs;
2297}
2298
2299/**
2300 * i40e_get_channels - Get the current channels enabled and max supported etc.
2301 * @netdev: network interface device structure
2302 * @ch: ethtool channels structure
2303 *
2304 * We don't support separate tx and rx queues as channels. The other count
2305 * represents how many queues are being used for control. max_combined counts
2306 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2307 * q_vectors since we support a lot more queue pairs than q_vectors.
2308 **/
2309static void i40e_get_channels(struct net_device *dev,
2310 struct ethtool_channels *ch)
2311{
2312 struct i40e_netdev_priv *np = netdev_priv(dev);
2313 struct i40e_vsi *vsi = np->vsi;
2314 struct i40e_pf *pf = vsi->back;
2315
2316 /* report maximum channels */
2317 ch->max_combined = i40e_max_channels(vsi);
2318
2319 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002320 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002321 ch->max_other = ch->other_count;
2322
2323 /* Note: This code assumes DCB is disabled for now. */
2324 ch->combined_count = vsi->num_queue_pairs;
2325}
2326
2327/**
2328 * i40e_set_channels - Set the new channels count.
2329 * @netdev: network interface device structure
2330 * @ch: ethtool channels structure
2331 *
2332 * The new channels count may not be the same as requested by the user
2333 * since it gets rounded down to a power of 2 value.
2334 **/
2335static int i40e_set_channels(struct net_device *dev,
2336 struct ethtool_channels *ch)
2337{
2338 struct i40e_netdev_priv *np = netdev_priv(dev);
2339 unsigned int count = ch->combined_count;
2340 struct i40e_vsi *vsi = np->vsi;
2341 struct i40e_pf *pf = vsi->back;
2342 int new_count;
2343
2344 /* We do not support setting channels for any other VSI at present */
2345 if (vsi->type != I40E_VSI_MAIN)
2346 return -EINVAL;
2347
2348 /* verify they are not requesting separate vectors */
2349 if (!count || ch->rx_count || ch->tx_count)
2350 return -EINVAL;
2351
2352 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002353 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002354 return -EINVAL;
2355
2356 /* verify the number of channels does not exceed hardware limits */
2357 if (count > i40e_max_channels(vsi))
2358 return -EINVAL;
2359
2360 /* update feature limits from largest to smallest supported values */
2361 /* TODO: Flow director limit, DCB etc */
2362
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002363 /* use rss_reconfig to rebuild with new queue count and update traffic
2364 * class queue mapping
2365 */
2366 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002367 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002368 return 0;
2369 else
2370 return -EINVAL;
2371}
2372
Greg Rose7e45ab42015-02-06 08:52:19 +00002373/**
2374 * i40e_get_priv_flags - report device private flags
2375 * @dev: network interface device structure
2376 *
2377 * The get string set count and the string set should be matched for each
2378 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2379 * array.
2380 *
2381 * Returns a u32 bitmap of flags.
2382 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002383static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002384{
2385 struct i40e_netdev_priv *np = netdev_priv(dev);
2386 struct i40e_vsi *vsi = np->vsi;
2387 struct i40e_pf *pf = vsi->back;
2388 u32 ret_flags = 0;
2389
2390 ret_flags |= pf->hw.func_caps.npar_enable ?
2391 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2392
2393 return ret_flags;
2394}
2395
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002396static const struct ethtool_ops i40e_ethtool_ops = {
2397 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002398 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002399 .get_drvinfo = i40e_get_drvinfo,
2400 .get_regs_len = i40e_get_regs_len,
2401 .get_regs = i40e_get_regs,
2402 .nway_reset = i40e_nway_reset,
2403 .get_link = ethtool_op_get_link,
2404 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002405 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002406 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002407 .get_eeprom_len = i40e_get_eeprom_len,
2408 .get_eeprom = i40e_get_eeprom,
2409 .get_ringparam = i40e_get_ringparam,
2410 .set_ringparam = i40e_set_ringparam,
2411 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002412 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002413 .get_msglevel = i40e_get_msglevel,
2414 .set_msglevel = i40e_set_msglevel,
2415 .get_rxnfc = i40e_get_rxnfc,
2416 .set_rxnfc = i40e_set_rxnfc,
2417 .self_test = i40e_diag_test,
2418 .get_strings = i40e_get_strings,
2419 .set_phys_id = i40e_set_phys_id,
2420 .get_sset_count = i40e_get_sset_count,
2421 .get_ethtool_stats = i40e_get_ethtool_stats,
2422 .get_coalesce = i40e_get_coalesce,
2423 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002424 .get_channels = i40e_get_channels,
2425 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002426 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002427 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002428};
2429
2430void i40e_set_ethtool_ops(struct net_device *netdev)
2431{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002432 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002433}