blob: 7d60587850d9ca422594e8698e7658c5da0539db [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;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700277 case I40E_PHY_TYPE_20GBASE_KR2:
278 ecmd->supported = SUPPORTED_Autoneg |
279 SUPPORTED_20000baseKR2_Full;
280 ecmd->advertising = ADVERTISED_Autoneg |
281 ADVERTISED_20000baseKR2_Full;
282 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000284 ecmd->supported = SUPPORTED_Autoneg |
285 SUPPORTED_10000baseKX4_Full;
286 ecmd->advertising = ADVERTISED_Autoneg |
287 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000288 break;
289 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000290 ecmd->supported = SUPPORTED_Autoneg |
291 SUPPORTED_10000baseKR_Full;
292 ecmd->advertising = ADVERTISED_Autoneg |
293 ADVERTISED_10000baseKR_Full;
294 break;
295 case I40E_PHY_TYPE_10GBASE_SR:
296 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000297 case I40E_PHY_TYPE_1000BASE_SX:
298 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000299 ecmd->supported = SUPPORTED_10000baseT_Full |
300 SUPPORTED_1000baseT_Full;
301 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
302 ecmd->advertising |= ADVERTISED_10000baseT_Full;
303 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
304 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000305 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000306 case I40E_PHY_TYPE_1000BASE_KX:
307 ecmd->supported = SUPPORTED_Autoneg |
308 SUPPORTED_1000baseKX_Full;
309 ecmd->advertising = ADVERTISED_Autoneg |
310 ADVERTISED_1000baseKX_Full;
311 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000312 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000313 case I40E_PHY_TYPE_1000BASE_T:
314 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000315 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000316 SUPPORTED_10000baseT_Full |
317 SUPPORTED_1000baseT_Full |
318 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000319 ecmd->advertising = ADVERTISED_Autoneg;
320 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
321 ecmd->advertising |= ADVERTISED_10000baseT_Full;
322 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
323 ecmd->advertising |= ADVERTISED_1000baseT_Full;
324 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
325 ecmd->advertising |= ADVERTISED_100baseT_Full;
326 break;
327 case I40E_PHY_TYPE_10GBASE_CR1_CU:
328 case I40E_PHY_TYPE_10GBASE_CR1:
329 ecmd->supported = SUPPORTED_Autoneg |
330 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000331 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000332 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000333 break;
334 case I40E_PHY_TYPE_XAUI:
335 case I40E_PHY_TYPE_XFI:
336 case I40E_PHY_TYPE_SFI:
337 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000338 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000339 ecmd->supported = SUPPORTED_10000baseT_Full;
340 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000341 case I40E_PHY_TYPE_SGMII:
342 ecmd->supported = SUPPORTED_Autoneg |
343 SUPPORTED_1000baseT_Full |
344 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000345 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
346 ecmd->advertising |= ADVERTISED_1000baseT_Full;
347 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
348 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000349 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000350 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000351 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000352 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
353 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000354 }
355
Catherine Sullivane8278452015-02-06 08:52:08 +0000356 /* Set speed and duplex */
357 switch (link_speed) {
358 case I40E_LINK_SPEED_40GB:
359 /* need a SPEED_40000 in ethtool.h */
360 ethtool_cmd_speed_set(ecmd, 40000);
361 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700362 case I40E_LINK_SPEED_20GB:
363 ethtool_cmd_speed_set(ecmd, SPEED_20000);
364 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000365 case I40E_LINK_SPEED_10GB:
366 ethtool_cmd_speed_set(ecmd, SPEED_10000);
367 break;
368 case I40E_LINK_SPEED_1GB:
369 ethtool_cmd_speed_set(ecmd, SPEED_1000);
370 break;
371 case I40E_LINK_SPEED_100MB:
372 ethtool_cmd_speed_set(ecmd, SPEED_100);
373 break;
374 default:
375 break;
376 }
377 ecmd->duplex = DUPLEX_FULL;
378}
379
380/**
381 * i40e_get_settings_link_down - Get the Link settings for when link is down
382 * @hw: hw structure
383 * @ecmd: ethtool command to fill in
384 *
385 * Reports link settings that can be determined when link is down
386 **/
387static void i40e_get_settings_link_down(struct i40e_hw *hw,
388 struct ethtool_cmd *ecmd)
389{
390 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
391
392 /* link is down and the driver needs to fall back on
393 * device ID to determine what kinds of info to display,
394 * it's mostly a guess that may change when link is up
395 */
396 switch (hw->device_id) {
397 case I40E_DEV_ID_QSFP_A:
398 case I40E_DEV_ID_QSFP_B:
399 case I40E_DEV_ID_QSFP_C:
400 /* pluggable QSFP */
401 ecmd->supported = SUPPORTED_40000baseSR4_Full |
402 SUPPORTED_40000baseCR4_Full |
403 SUPPORTED_40000baseLR4_Full;
404 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
405 ADVERTISED_40000baseCR4_Full |
406 ADVERTISED_40000baseLR4_Full;
407 break;
408 case I40E_DEV_ID_KX_B:
409 /* backplane 40G */
410 ecmd->supported = SUPPORTED_40000baseKR4_Full;
411 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
412 break;
413 case I40E_DEV_ID_KX_C:
414 /* backplane 10G */
415 ecmd->supported = SUPPORTED_10000baseKR_Full;
416 ecmd->advertising = ADVERTISED_10000baseKR_Full;
417 break;
418 case I40E_DEV_ID_10G_BASE_T:
419 ecmd->supported = SUPPORTED_10000baseT_Full |
420 SUPPORTED_1000baseT_Full |
421 SUPPORTED_100baseT_Full;
422 /* Figure out what has been requested */
423 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
424 ecmd->advertising |= ADVERTISED_10000baseT_Full;
425 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
426 ecmd->advertising |= ADVERTISED_1000baseT_Full;
427 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
428 ecmd->advertising |= ADVERTISED_100baseT_Full;
429 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700430 case I40E_DEV_ID_20G_KR2:
431 /* backplane 20G */
432 ecmd->supported = SUPPORTED_20000baseKR2_Full;
433 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
434 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000435 default:
436 /* all the rest are 10G/1G */
437 ecmd->supported = SUPPORTED_10000baseT_Full |
438 SUPPORTED_1000baseT_Full;
439 /* Figure out what has been requested */
440 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
441 ecmd->advertising |= ADVERTISED_10000baseT_Full;
442 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
443 ecmd->advertising |= ADVERTISED_1000baseT_Full;
444 break;
445 }
446
447 /* With no link speed and duplex are unknown */
448 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
449 ecmd->duplex = DUPLEX_UNKNOWN;
450}
451
452/**
453 * i40e_get_settings - Get Link Speed and Duplex settings
454 * @netdev: network interface device structure
455 * @ecmd: ethtool command
456 *
457 * Reports speed/duplex settings based on media_type
458 **/
459static int i40e_get_settings(struct net_device *netdev,
460 struct ethtool_cmd *ecmd)
461{
462 struct i40e_netdev_priv *np = netdev_priv(netdev);
463 struct i40e_pf *pf = np->vsi->back;
464 struct i40e_hw *hw = &pf->hw;
465 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
466 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
467
468 if (link_up)
469 i40e_get_settings_link_up(hw, ecmd, netdev);
470 else
471 i40e_get_settings_link_down(hw, ecmd);
472
473 /* Now set the settings that don't rely on link being up/down */
474
475 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000476 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
477 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000478
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000479 switch (hw->phy.media_type) {
480 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000481 ecmd->supported |= SUPPORTED_Autoneg |
482 SUPPORTED_Backplane;
483 ecmd->advertising |= ADVERTISED_Autoneg |
484 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000486 break;
487 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000488 ecmd->supported |= SUPPORTED_TP;
489 ecmd->advertising |= ADVERTISED_TP;
490 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000491 break;
492 case I40E_MEDIA_TYPE_DA:
493 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000494 ecmd->supported |= SUPPORTED_FIBRE;
495 ecmd->advertising |= ADVERTISED_FIBRE;
496 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000497 break;
498 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000499 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000500 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000501 break;
502 case I40E_MEDIA_TYPE_UNKNOWN:
503 default:
504 ecmd->port = PORT_OTHER;
505 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000506 }
507
Catherine Sullivane8278452015-02-06 08:52:08 +0000508 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000509 ecmd->transceiver = XCVR_EXTERNAL;
510
Catherine Sullivane8278452015-02-06 08:52:08 +0000511 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000512 ecmd->supported |= SUPPORTED_Pause;
513
Catherine Sullivane8278452015-02-06 08:52:08 +0000514 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000515 case I40E_FC_FULL:
516 ecmd->advertising |= ADVERTISED_Pause;
517 break;
518 case I40E_FC_TX_PAUSE:
519 ecmd->advertising |= ADVERTISED_Asym_Pause;
520 break;
521 case I40E_FC_RX_PAUSE:
522 ecmd->advertising |= (ADVERTISED_Pause |
523 ADVERTISED_Asym_Pause);
524 break;
525 default:
526 ecmd->advertising &= ~(ADVERTISED_Pause |
527 ADVERTISED_Asym_Pause);
528 break;
529 }
530
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000531 return 0;
532}
533
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000534/**
535 * i40e_set_settings - Set Speed and Duplex
536 * @netdev: network interface device structure
537 * @ecmd: ethtool command
538 *
539 * Set speed/duplex per media_types advertised/forced
540 **/
541static int i40e_set_settings(struct net_device *netdev,
542 struct ethtool_cmd *ecmd)
543{
544 struct i40e_netdev_priv *np = netdev_priv(netdev);
545 struct i40e_aq_get_phy_abilities_resp abilities;
546 struct i40e_aq_set_phy_config config;
547 struct i40e_pf *pf = np->vsi->back;
548 struct i40e_vsi *vsi = np->vsi;
549 struct i40e_hw *hw = &pf->hw;
550 struct ethtool_cmd safe_ecmd;
551 i40e_status status = 0;
552 bool change = false;
553 int err = 0;
554 u8 autoneg;
555 u32 advertise;
556
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000557 /* Changing port settings is not supported if this isn't the
558 * port's controlling PF
559 */
560 if (hw->partition_id != 1) {
561 i40e_partition_setting_complaint(pf);
562 return -EOPNOTSUPP;
563 }
564
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000565 if (vsi != pf->vsi[pf->lan_vsi])
566 return -EOPNOTSUPP;
567
568 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
569 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000570 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
571 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000572 return -EOPNOTSUPP;
573
574 /* get our own copy of the bits to check against */
575 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
576 i40e_get_settings(netdev, &safe_ecmd);
577
578 /* save autoneg and speed out of ecmd */
579 autoneg = ecmd->autoneg;
580 advertise = ecmd->advertising;
581
582 /* set autoneg and speed back to what they currently are */
583 ecmd->autoneg = safe_ecmd.autoneg;
584 ecmd->advertising = safe_ecmd.advertising;
585
586 ecmd->cmd = safe_ecmd.cmd;
587 /* If ecmd and safe_ecmd are not the same now, then they are
588 * trying to set something that we do not support
589 */
590 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
591 return -EOPNOTSUPP;
592
593 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
594 usleep_range(1000, 2000);
595
596 /* Get the current phy config */
597 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
598 NULL);
599 if (status)
600 return -EAGAIN;
601
Catherine Sullivan124ed152014-07-12 07:28:12 +0000602 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000603 * set below
604 */
605 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000606 config.abilities = abilities.abilities;
607
608 /* Check autoneg */
609 if (autoneg == AUTONEG_ENABLE) {
610 /* If autoneg is not supported, return error */
611 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
612 netdev_info(netdev, "Autoneg not supported on this phy\n");
613 return -EINVAL;
614 }
615 /* If autoneg was not already enabled */
616 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
617 config.abilities = abilities.abilities |
618 I40E_AQ_PHY_ENABLE_AN;
619 change = true;
620 }
621 } else {
622 /* If autoneg is supported 10GBASE_T is the only phy that
623 * can disable it, so otherwise return error
624 */
625 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
626 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
627 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
628 return -EINVAL;
629 }
630 /* If autoneg is currently enabled */
631 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000632 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000633 ~I40E_AQ_PHY_ENABLE_AN;
634 change = true;
635 }
636 }
637
638 if (advertise & ~safe_ecmd.supported)
639 return -EINVAL;
640
641 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000642 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000643 if (advertise & ADVERTISED_1000baseT_Full ||
644 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000645 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000646 if (advertise & ADVERTISED_10000baseT_Full ||
647 advertise & ADVERTISED_10000baseKX4_Full ||
648 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000649 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700650 if (advertise & ADVERTISED_20000baseKR2_Full)
651 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000652 if (advertise & ADVERTISED_40000baseKR4_Full ||
653 advertise & ADVERTISED_40000baseCR4_Full ||
654 advertise & ADVERTISED_40000baseSR4_Full ||
655 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000656 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000657
Catherine Sullivan124ed152014-07-12 07:28:12 +0000658 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000659 /* copy over the rest of the abilities */
660 config.phy_type = abilities.phy_type;
661 config.eee_capability = abilities.eee_capability;
662 config.eeer = abilities.eeer_val;
663 config.low_power_ctrl = abilities.d3_lpan;
664
Catherine Sullivane8278452015-02-06 08:52:08 +0000665 /* save the requested speeds */
666 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000667 /* set link and auto negotiation so changes take effect */
668 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
669 /* If link is up put link down */
670 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
671 /* Tell the OS link is going down, the link will go
672 * back up when fw says it is ready asynchronously
673 */
674 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
675 netif_carrier_off(netdev);
676 netif_tx_stop_all_queues(netdev);
677 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000678
679 /* make the aq call */
680 status = i40e_aq_set_phy_config(hw, &config, NULL);
681 if (status) {
682 netdev_info(netdev, "Set phy config failed with error %d.\n",
683 status);
684 return -EAGAIN;
685 }
686
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000687 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000688 if (status)
689 netdev_info(netdev, "Updating link info failed with error %d\n",
690 status);
691
692 } else {
693 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
694 }
695
696 return err;
697}
698
Jesse Brandeburga6599722014-06-04 08:45:25 +0000699static int i40e_nway_reset(struct net_device *netdev)
700{
701 /* restart autonegotiation */
702 struct i40e_netdev_priv *np = netdev_priv(netdev);
703 struct i40e_pf *pf = np->vsi->back;
704 struct i40e_hw *hw = &pf->hw;
705 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
706 i40e_status ret = 0;
707
708 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
709 if (ret) {
710 netdev_info(netdev, "link restart failed, aq_err=%d\n",
711 pf->hw.aq.asq_last_status);
712 return -EIO;
713 }
714
715 return 0;
716}
717
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000718/**
719 * i40e_get_pauseparam - Get Flow Control status
720 * Return tx/rx-pause status
721 **/
722static void i40e_get_pauseparam(struct net_device *netdev,
723 struct ethtool_pauseparam *pause)
724{
725 struct i40e_netdev_priv *np = netdev_priv(netdev);
726 struct i40e_pf *pf = np->vsi->back;
727 struct i40e_hw *hw = &pf->hw;
728 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000729 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000730
731 pause->autoneg =
732 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
733 AUTONEG_ENABLE : AUTONEG_DISABLE);
734
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000735 /* PFC enabled so report LFC as off */
736 if (dcbx_cfg->pfc.pfcenable) {
737 pause->rx_pause = 0;
738 pause->tx_pause = 0;
739 return;
740 }
741
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000742 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000743 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000744 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000745 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000746 } else if (hw->fc.current_mode == I40E_FC_FULL) {
747 pause->rx_pause = 1;
748 pause->tx_pause = 1;
749 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000750}
751
Catherine Sullivan2becc352014-06-04 08:45:27 +0000752/**
753 * i40e_set_pauseparam - Set Flow Control parameter
754 * @netdev: network interface device structure
755 * @pause: return tx/rx flow control status
756 **/
757static int i40e_set_pauseparam(struct net_device *netdev,
758 struct ethtool_pauseparam *pause)
759{
760 struct i40e_netdev_priv *np = netdev_priv(netdev);
761 struct i40e_pf *pf = np->vsi->back;
762 struct i40e_vsi *vsi = np->vsi;
763 struct i40e_hw *hw = &pf->hw;
764 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000765 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000766 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
767 i40e_status status;
768 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000769 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000770
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000771 /* Changing the port's flow control is not supported if this isn't the
772 * port's controlling PF
773 */
774 if (hw->partition_id != 1) {
775 i40e_partition_setting_complaint(pf);
776 return -EOPNOTSUPP;
777 }
778
Catherine Sullivan2becc352014-06-04 08:45:27 +0000779 if (vsi != pf->vsi[pf->lan_vsi])
780 return -EOPNOTSUPP;
781
782 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
783 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
784 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
785 return -EOPNOTSUPP;
786 }
787
788 /* If we have link and don't have autoneg */
789 if (!test_bit(__I40E_DOWN, &pf->state) &&
790 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
791 /* Send message that it might not necessarily work*/
792 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
793 }
794
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000795 if (dcbx_cfg->pfc.pfcenable) {
796 netdev_info(netdev,
797 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000798 return -EOPNOTSUPP;
799 }
800
801 if (pause->rx_pause && pause->tx_pause)
802 hw->fc.requested_mode = I40E_FC_FULL;
803 else if (pause->rx_pause && !pause->tx_pause)
804 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
805 else if (!pause->rx_pause && pause->tx_pause)
806 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
807 else if (!pause->rx_pause && !pause->tx_pause)
808 hw->fc.requested_mode = I40E_FC_NONE;
809 else
810 return -EINVAL;
811
Catherine Sullivan94128512014-07-12 07:28:16 +0000812 /* Tell the OS link is going down, the link will go back up when fw
813 * says it is ready asynchronously
814 */
815 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
816 netif_carrier_off(netdev);
817 netif_tx_stop_all_queues(netdev);
818
Catherine Sullivan2becc352014-06-04 08:45:27 +0000819 /* Set the fc mode and only restart an if link is up*/
820 status = i40e_set_fc(hw, &aq_failures, link_up);
821
822 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
823 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
824 status, hw->aq.asq_last_status);
825 err = -EAGAIN;
826 }
827 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
828 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
829 status, hw->aq.asq_last_status);
830 err = -EAGAIN;
831 }
832 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000833 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 +0000834 status, hw->aq.asq_last_status);
835 err = -EAGAIN;
836 }
837
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000838 if (!test_bit(__I40E_DOWN, &pf->state)) {
839 /* Give it a little more time to try to come back */
840 msleep(75);
841 if (!test_bit(__I40E_DOWN, &pf->state))
842 return i40e_nway_reset(netdev);
843 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000844
845 return err;
846}
847
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000848static u32 i40e_get_msglevel(struct net_device *netdev)
849{
850 struct i40e_netdev_priv *np = netdev_priv(netdev);
851 struct i40e_pf *pf = np->vsi->back;
852
853 return pf->msg_enable;
854}
855
856static void i40e_set_msglevel(struct net_device *netdev, u32 data)
857{
858 struct i40e_netdev_priv *np = netdev_priv(netdev);
859 struct i40e_pf *pf = np->vsi->back;
860
861 if (I40E_DEBUG_USER & data)
862 pf->hw.debug_mask = data;
863 pf->msg_enable = data;
864}
865
866static int i40e_get_regs_len(struct net_device *netdev)
867{
868 int reg_count = 0;
869 int i;
870
871 for (i = 0; i40e_reg_list[i].offset != 0; i++)
872 reg_count += i40e_reg_list[i].elements;
873
874 return reg_count * sizeof(u32);
875}
876
877static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
878 void *p)
879{
880 struct i40e_netdev_priv *np = netdev_priv(netdev);
881 struct i40e_pf *pf = np->vsi->back;
882 struct i40e_hw *hw = &pf->hw;
883 u32 *reg_buf = p;
884 int i, j, ri;
885 u32 reg;
886
887 /* Tell ethtool which driver-version-specific regs output we have.
888 *
889 * At some point, if we have ethtool doing special formatting of
890 * this data, it will rely on this version number to know how to
891 * interpret things. Hence, this needs to be updated if/when the
892 * diags register table is changed.
893 */
894 regs->version = 1;
895
896 /* loop through the diags reg table for what to print */
897 ri = 0;
898 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
899 for (j = 0; j < i40e_reg_list[i].elements; j++) {
900 reg = i40e_reg_list[i].offset
901 + (j * i40e_reg_list[i].stride);
902 reg_buf[ri++] = rd32(hw, reg);
903 }
904 }
905
906}
907
908static int i40e_get_eeprom(struct net_device *netdev,
909 struct ethtool_eeprom *eeprom, u8 *bytes)
910{
911 struct i40e_netdev_priv *np = netdev_priv(netdev);
912 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000913 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000914 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000915 u8 *eeprom_buff;
916 u16 i, sectors;
917 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000918 u32 magic;
919
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000920#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000921 if (eeprom->len == 0)
922 return -EINVAL;
923
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000924 /* check for NVMUpdate access method */
925 magic = hw->vendor_id | (hw->device_id << 16);
926 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000927 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000928 int errno;
929
930 /* make sure it is the right magic for NVMUpdate */
931 if ((eeprom->magic >> 16) != hw->device_id)
932 return -EINVAL;
933
Shannon Nelsonc150a502014-11-13 08:23:13 +0000934 cmd = (struct i40e_nvm_access *)eeprom;
935 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000936 if (ret_val &&
937 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
938 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000939 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000940 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
941 ret_val, hw->aq.asq_last_status, errno,
942 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
943 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000944
945 return errno;
946 }
947
948 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000949 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
950
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000951 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000952 if (!eeprom_buff)
953 return -ENOMEM;
954
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000955 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
956 if (ret_val) {
957 dev_info(&pf->pdev->dev,
958 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
959 ret_val, hw->aq.asq_last_status);
960 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000961 }
962
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000963 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
964 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
965 len = I40E_NVM_SECTOR_SIZE;
966 last = false;
967 for (i = 0; i < sectors; i++) {
968 if (i == (sectors - 1)) {
969 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
970 last = true;
971 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000972 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
973 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000974 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000975 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000976 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000977 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000978 "read NVM failed, invalid offset 0x%x\n",
979 offset);
980 break;
981 } else if (ret_val &&
982 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
983 dev_info(&pf->pdev->dev,
984 "read NVM failed, access, offset 0x%x\n",
985 offset);
986 break;
987 } else if (ret_val) {
988 dev_info(&pf->pdev->dev,
989 "read NVM failed offset %d err=%d status=0x%x\n",
990 offset, ret_val, hw->aq.asq_last_status);
991 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000992 }
993 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000994
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000995 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000996 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000997free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000998 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000999 return ret_val;
1000}
1001
1002static int i40e_get_eeprom_len(struct net_device *netdev)
1003{
1004 struct i40e_netdev_priv *np = netdev_priv(netdev);
1005 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001006 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001007
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001008 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1009 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1010 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1011 /* register returns value in power of 2, 64Kbyte chunks. */
1012 val = (64 * 1024) * (1 << val);
1013 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001014}
1015
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001016static int i40e_set_eeprom(struct net_device *netdev,
1017 struct ethtool_eeprom *eeprom, u8 *bytes)
1018{
1019 struct i40e_netdev_priv *np = netdev_priv(netdev);
1020 struct i40e_hw *hw = &np->vsi->back->hw;
1021 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001022 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001023 int ret_val = 0;
1024 int errno;
1025 u32 magic;
1026
1027 /* normal ethtool set_eeprom is not supported */
1028 magic = hw->vendor_id | (hw->device_id << 16);
1029 if (eeprom->magic == magic)
1030 return -EOPNOTSUPP;
1031
1032 /* check for NVMUpdate access method */
1033 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1034 return -EINVAL;
1035
1036 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1037 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1038 return -EBUSY;
1039
Shannon Nelsonc150a502014-11-13 08:23:13 +00001040 cmd = (struct i40e_nvm_access *)eeprom;
1041 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001042 if (ret_val &&
1043 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1044 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1045 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001046 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001047 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1048 ret_val, hw->aq.asq_last_status, errno,
1049 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1050 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001051
1052 return errno;
1053}
1054
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001055static void i40e_get_drvinfo(struct net_device *netdev,
1056 struct ethtool_drvinfo *drvinfo)
1057{
1058 struct i40e_netdev_priv *np = netdev_priv(netdev);
1059 struct i40e_vsi *vsi = np->vsi;
1060 struct i40e_pf *pf = vsi->back;
1061
1062 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1063 strlcpy(drvinfo->version, i40e_driver_version_str,
1064 sizeof(drvinfo->version));
1065 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1066 sizeof(drvinfo->fw_version));
1067 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1068 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001069 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001070}
1071
1072static void i40e_get_ringparam(struct net_device *netdev,
1073 struct ethtool_ringparam *ring)
1074{
1075 struct i40e_netdev_priv *np = netdev_priv(netdev);
1076 struct i40e_pf *pf = np->vsi->back;
1077 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1078
1079 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1080 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1081 ring->rx_mini_max_pending = 0;
1082 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001083 ring->rx_pending = vsi->rx_rings[0]->count;
1084 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085 ring->rx_mini_pending = 0;
1086 ring->rx_jumbo_pending = 0;
1087}
1088
1089static int i40e_set_ringparam(struct net_device *netdev,
1090 struct ethtool_ringparam *ring)
1091{
1092 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1093 struct i40e_netdev_priv *np = netdev_priv(netdev);
1094 struct i40e_vsi *vsi = np->vsi;
1095 struct i40e_pf *pf = vsi->back;
1096 u32 new_rx_count, new_tx_count;
1097 int i, err = 0;
1098
1099 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1100 return -EINVAL;
1101
Shannon Nelson1fa18372013-11-20 10:03:08 +00001102 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1103 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1104 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1105 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1106 netdev_info(netdev,
1107 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1108 ring->tx_pending, ring->rx_pending,
1109 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1110 return -EINVAL;
1111 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001112
Shannon Nelson1fa18372013-11-20 10:03:08 +00001113 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1114 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001115
1116 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001117 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1118 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001119 return 0;
1120
1121 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1122 usleep_range(1000, 2000);
1123
1124 if (!netif_running(vsi->netdev)) {
1125 /* simple case - set for the next time the netdev is started */
1126 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001127 vsi->tx_rings[i]->count = new_tx_count;
1128 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001129 }
1130 goto done;
1131 }
1132
1133 /* We can't just free everything and then setup again,
1134 * because the ISRs in MSI-X mode get passed pointers
1135 * to the Tx and Rx ring structs.
1136 */
1137
1138 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001139 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001140 netdev_info(netdev,
1141 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001142 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001143 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1144 sizeof(struct i40e_ring), GFP_KERNEL);
1145 if (!tx_rings) {
1146 err = -ENOMEM;
1147 goto done;
1148 }
1149
1150 for (i = 0; i < vsi->num_queue_pairs; i++) {
1151 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001152 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001153 tx_rings[i].count = new_tx_count;
1154 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1155 if (err) {
1156 while (i) {
1157 i--;
1158 i40e_free_tx_resources(&tx_rings[i]);
1159 }
1160 kfree(tx_rings);
1161 tx_rings = NULL;
1162
1163 goto done;
1164 }
1165 }
1166 }
1167
1168 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001169 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001170 netdev_info(netdev,
1171 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001172 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001173 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1174 sizeof(struct i40e_ring), GFP_KERNEL);
1175 if (!rx_rings) {
1176 err = -ENOMEM;
1177 goto free_tx;
1178 }
1179
1180 for (i = 0; i < vsi->num_queue_pairs; i++) {
1181 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001182 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001183 rx_rings[i].count = new_rx_count;
1184 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1185 if (err) {
1186 while (i) {
1187 i--;
1188 i40e_free_rx_resources(&rx_rings[i]);
1189 }
1190 kfree(rx_rings);
1191 rx_rings = NULL;
1192
1193 goto free_tx;
1194 }
1195 }
1196 }
1197
1198 /* Bring interface down, copy in the new ring info,
1199 * then restore the interface
1200 */
1201 i40e_down(vsi);
1202
1203 if (tx_rings) {
1204 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001205 i40e_free_tx_resources(vsi->tx_rings[i]);
1206 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001207 }
1208 kfree(tx_rings);
1209 tx_rings = NULL;
1210 }
1211
1212 if (rx_rings) {
1213 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001214 i40e_free_rx_resources(vsi->rx_rings[i]);
1215 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001216 }
1217 kfree(rx_rings);
1218 rx_rings = NULL;
1219 }
1220
1221 i40e_up(vsi);
1222
1223free_tx:
1224 /* error cleanup if the Rx allocations failed after getting Tx */
1225 if (tx_rings) {
1226 for (i = 0; i < vsi->num_queue_pairs; i++)
1227 i40e_free_tx_resources(&tx_rings[i]);
1228 kfree(tx_rings);
1229 tx_rings = NULL;
1230 }
1231
1232done:
1233 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1234
1235 return err;
1236}
1237
1238static int i40e_get_sset_count(struct net_device *netdev, int sset)
1239{
1240 struct i40e_netdev_priv *np = netdev_priv(netdev);
1241 struct i40e_vsi *vsi = np->vsi;
1242 struct i40e_pf *pf = vsi->back;
1243
1244 switch (sset) {
1245 case ETH_SS_TEST:
1246 return I40E_TEST_LEN;
1247 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001248 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001249 int len = I40E_PF_STATS_LEN(netdev);
1250
1251 if (pf->lan_veb != I40E_NO_VEB)
1252 len += I40E_VEB_STATS_LEN;
1253 return len;
1254 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001255 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001256 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001257 case ETH_SS_PRIV_FLAGS:
1258 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001259 default:
1260 return -EOPNOTSUPP;
1261 }
1262}
1263
1264static void i40e_get_ethtool_stats(struct net_device *netdev,
1265 struct ethtool_stats *stats, u64 *data)
1266{
1267 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001268 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 struct i40e_vsi *vsi = np->vsi;
1270 struct i40e_pf *pf = vsi->back;
1271 int i = 0;
1272 char *p;
1273 int j;
1274 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001275 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001276
1277 i40e_update_stats(vsi);
1278
1279 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1280 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1281 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1282 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1283 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001284 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1285 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1286 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1287 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1288 }
Vasu Dev38e00432014-08-01 13:27:03 -07001289#ifdef I40E_FCOE
1290 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1291 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1292 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1293 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1294 }
1295#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001296 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001297 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001298 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001299
1300 if (!tx_ring)
1301 continue;
1302
1303 /* process Tx ring statistics */
1304 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001305 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001306 data[i] = tx_ring->stats.packets;
1307 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001308 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001309 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001310
1311 /* Rx ring is the 2nd half of the queue pair */
1312 rx_ring = &tx_ring[1];
1313 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001314 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001315 data[i] = rx_ring->stats.packets;
1316 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001317 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001318 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001320 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001321 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001322 return;
1323
1324 if (pf->lan_veb != I40E_NO_VEB) {
1325 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1326 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1327 p = (char *)veb;
1328 p += i40e_gstrings_veb_stats[j].stat_offset;
1329 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1330 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001332 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001333 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1334 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1335 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1336 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1337 }
1338 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1339 data[i++] = pf->stats.priority_xon_tx[j];
1340 data[i++] = pf->stats.priority_xoff_tx[j];
1341 }
1342 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1343 data[i++] = pf->stats.priority_xon_rx[j];
1344 data[i++] = pf->stats.priority_xoff_rx[j];
1345 }
1346 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1347 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348}
1349
1350static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1351 u8 *data)
1352{
1353 struct i40e_netdev_priv *np = netdev_priv(netdev);
1354 struct i40e_vsi *vsi = np->vsi;
1355 struct i40e_pf *pf = vsi->back;
1356 char *p = (char *)data;
1357 int i;
1358
1359 switch (stringset) {
1360 case ETH_SS_TEST:
1361 for (i = 0; i < I40E_TEST_LEN; i++) {
1362 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1363 data += ETH_GSTRING_LEN;
1364 }
1365 break;
1366 case ETH_SS_STATS:
1367 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1368 snprintf(p, ETH_GSTRING_LEN, "%s",
1369 i40e_gstrings_net_stats[i].stat_string);
1370 p += ETH_GSTRING_LEN;
1371 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001372 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1373 snprintf(p, ETH_GSTRING_LEN, "%s",
1374 i40e_gstrings_misc_stats[i].stat_string);
1375 p += ETH_GSTRING_LEN;
1376 }
Vasu Dev38e00432014-08-01 13:27:03 -07001377#ifdef I40E_FCOE
1378 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1379 snprintf(p, ETH_GSTRING_LEN, "%s",
1380 i40e_gstrings_fcoe_stats[i].stat_string);
1381 p += ETH_GSTRING_LEN;
1382 }
1383#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001384 for (i = 0; i < vsi->num_queue_pairs; i++) {
1385 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1386 p += ETH_GSTRING_LEN;
1387 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1388 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001389 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1390 p += ETH_GSTRING_LEN;
1391 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1392 p += ETH_GSTRING_LEN;
1393 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001394 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001395 return;
1396
1397 if (pf->lan_veb != I40E_NO_VEB) {
1398 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1399 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1400 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001401 p += ETH_GSTRING_LEN;
1402 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001403 }
1404 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1405 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1406 i40e_gstrings_stats[i].stat_string);
1407 p += ETH_GSTRING_LEN;
1408 }
1409 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1410 snprintf(p, ETH_GSTRING_LEN,
1411 "port.tx_priority_%u_xon", i);
1412 p += ETH_GSTRING_LEN;
1413 snprintf(p, ETH_GSTRING_LEN,
1414 "port.tx_priority_%u_xoff", i);
1415 p += ETH_GSTRING_LEN;
1416 }
1417 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1418 snprintf(p, ETH_GSTRING_LEN,
1419 "port.rx_priority_%u_xon", i);
1420 p += ETH_GSTRING_LEN;
1421 snprintf(p, ETH_GSTRING_LEN,
1422 "port.rx_priority_%u_xoff", i);
1423 p += ETH_GSTRING_LEN;
1424 }
1425 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1426 snprintf(p, ETH_GSTRING_LEN,
1427 "port.rx_priority_%u_xon_2_xoff", i);
1428 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 }
1430 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1431 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001432 case ETH_SS_PRIV_FLAGS:
1433 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1434 memcpy(data, i40e_priv_flags_strings[i],
1435 ETH_GSTRING_LEN);
1436 data += ETH_GSTRING_LEN;
1437 }
1438 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001439 default:
1440 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441 }
1442}
1443
1444static int i40e_get_ts_info(struct net_device *dev,
1445 struct ethtool_ts_info *info)
1446{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001447 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1448
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001449 /* only report HW timestamping if PTP is enabled */
1450 if (!(pf->flags & I40E_FLAG_PTP))
1451 return ethtool_op_get_ts_info(dev, info);
1452
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001453 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1454 SOF_TIMESTAMPING_RX_SOFTWARE |
1455 SOF_TIMESTAMPING_SOFTWARE |
1456 SOF_TIMESTAMPING_TX_HARDWARE |
1457 SOF_TIMESTAMPING_RX_HARDWARE |
1458 SOF_TIMESTAMPING_RAW_HARDWARE;
1459
1460 if (pf->ptp_clock)
1461 info->phc_index = ptp_clock_index(pf->ptp_clock);
1462 else
1463 info->phc_index = -1;
1464
1465 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1466
1467 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1468 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1469 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1470 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1471 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1472 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1473 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1474 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1475 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1476 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1477 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1478 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1479
1480 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481}
1482
Shannon Nelson7b086392013-11-20 10:02:59 +00001483static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001484{
Shannon Nelson7b086392013-11-20 10:02:59 +00001485 struct i40e_netdev_priv *np = netdev_priv(netdev);
1486 struct i40e_pf *pf = np->vsi->back;
1487
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001488 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489 if (i40e_get_link_status(&pf->hw))
1490 *data = 0;
1491 else
1492 *data = 1;
1493
1494 return *data;
1495}
1496
Shannon Nelson7b086392013-11-20 10:02:59 +00001497static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001498{
Shannon Nelson7b086392013-11-20 10:02:59 +00001499 struct i40e_netdev_priv *np = netdev_priv(netdev);
1500 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001501
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001502 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001503 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504
Shannon Nelson7b086392013-11-20 10:02:59 +00001505 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506}
1507
Shannon Nelson7b086392013-11-20 10:02:59 +00001508static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001509{
Shannon Nelson7b086392013-11-20 10:02:59 +00001510 struct i40e_netdev_priv *np = netdev_priv(netdev);
1511 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001512
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001513 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001514 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001515
Shannon Nelson4443ec92014-11-13 08:23:12 +00001516 /* forcebly clear the NVM Update state machine */
1517 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1518
Shannon Nelson7b086392013-11-20 10:02:59 +00001519 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520}
1521
Shannon Nelson7b086392013-11-20 10:02:59 +00001522static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523{
Shannon Nelson7b086392013-11-20 10:02:59 +00001524 struct i40e_netdev_priv *np = netdev_priv(netdev);
1525 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001526 u16 swc_old = pf->sw_int_count;
1527
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001528 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001529 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1530 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001531 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1532 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1533 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1534 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001535 usleep_range(1000, 2000);
1536 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537
1538 return *data;
1539}
1540
Shannon Nelson7b086392013-11-20 10:02:59 +00001541static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001542{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001543 struct i40e_netdev_priv *np = netdev_priv(netdev);
1544 struct i40e_pf *pf = np->vsi->back;
1545
1546 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001547 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548
1549 return *data;
1550}
1551
1552static void i40e_diag_test(struct net_device *netdev,
1553 struct ethtool_test *eth_test, u64 *data)
1554{
1555 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001556 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557 struct i40e_pf *pf = np->vsi->back;
1558
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001559 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1560 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001561 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562
Shannon Nelsonf551b432013-11-26 10:49:12 +00001563 set_bit(__I40E_TESTING, &pf->state);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001564 /* If the device is online then take it offline */
1565 if (if_running)
1566 /* indicate we're in test mode */
1567 dev_close(netdev);
1568 else
1569 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001570
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571 /* Link test performed before hardware reset
1572 * so autoneg doesn't interfere with test result
1573 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001574 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001575 eth_test->flags |= ETH_TEST_FL_FAILED;
1576
Shannon Nelson7b086392013-11-20 10:02:59 +00001577 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001578 eth_test->flags |= ETH_TEST_FL_FAILED;
1579
Shannon Nelson7b086392013-11-20 10:02:59 +00001580 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001581 eth_test->flags |= ETH_TEST_FL_FAILED;
1582
Shannon Nelson7b086392013-11-20 10:02:59 +00001583 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 eth_test->flags |= ETH_TEST_FL_FAILED;
1585
Shannon Nelsonf551b432013-11-26 10:49:12 +00001586 /* run reg test last, a reset is required after it */
1587 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1588 eth_test->flags |= ETH_TEST_FL_FAILED;
1589
1590 clear_bit(__I40E_TESTING, &pf->state);
1591 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001592
1593 if (if_running)
1594 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001597 netif_info(pf, drv, netdev, "online testing starting\n");
1598
Shannon Nelson7b086392013-11-20 10:02:59 +00001599 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 eth_test->flags |= ETH_TEST_FL_FAILED;
1601
1602 /* Offline only tests, not run in online; pass by default */
1603 data[I40E_ETH_TEST_REG] = 0;
1604 data[I40E_ETH_TEST_EEPROM] = 0;
1605 data[I40E_ETH_TEST_INTR] = 0;
1606 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001607 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001608
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001609 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001610}
1611
1612static void i40e_get_wol(struct net_device *netdev,
1613 struct ethtool_wolinfo *wol)
1614{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001615 struct i40e_netdev_priv *np = netdev_priv(netdev);
1616 struct i40e_pf *pf = np->vsi->back;
1617 struct i40e_hw *hw = &pf->hw;
1618 u16 wol_nvm_bits;
1619
1620 /* NVM bit on means WoL disabled for the port */
1621 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001622 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001623 wol->supported = 0;
1624 wol->wolopts = 0;
1625 } else {
1626 wol->supported = WAKE_MAGIC;
1627 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1628 }
1629}
1630
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001631/**
1632 * i40e_set_wol - set the WakeOnLAN configuration
1633 * @netdev: the netdev in question
1634 * @wol: the ethtool WoL setting data
1635 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001636static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1637{
1638 struct i40e_netdev_priv *np = netdev_priv(netdev);
1639 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001640 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001641 struct i40e_hw *hw = &pf->hw;
1642 u16 wol_nvm_bits;
1643
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001644 /* WoL not supported if this isn't the controlling PF on the port */
1645 if (hw->partition_id != 1) {
1646 i40e_partition_setting_complaint(pf);
1647 return -EOPNOTSUPP;
1648 }
1649
1650 if (vsi != pf->vsi[pf->lan_vsi])
1651 return -EOPNOTSUPP;
1652
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001653 /* NVM bit on means WoL disabled for the port */
1654 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1655 if (((1 << hw->port) & wol_nvm_bits))
1656 return -EOPNOTSUPP;
1657
1658 /* only magic packet is supported */
1659 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1660 return -EOPNOTSUPP;
1661
1662 /* is this a new value? */
1663 if (pf->wol_en != !!wol->wolopts) {
1664 pf->wol_en = !!wol->wolopts;
1665 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1666 }
1667
1668 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001669}
1670
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001671static int i40e_set_phys_id(struct net_device *netdev,
1672 enum ethtool_phys_id_state state)
1673{
1674 struct i40e_netdev_priv *np = netdev_priv(netdev);
1675 struct i40e_pf *pf = np->vsi->back;
1676 struct i40e_hw *hw = &pf->hw;
1677 int blink_freq = 2;
1678
1679 switch (state) {
1680 case ETHTOOL_ID_ACTIVE:
1681 pf->led_status = i40e_led_get(hw);
1682 return blink_freq;
1683 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001684 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001685 break;
1686 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001687 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001688 break;
1689 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001690 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001691 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001692 default:
1693 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694 }
1695
1696 return 0;
1697}
1698
1699/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1700 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1701 * 125us (8000 interrupts per second) == ITR(62)
1702 */
1703
1704static int i40e_get_coalesce(struct net_device *netdev,
1705 struct ethtool_coalesce *ec)
1706{
1707 struct i40e_netdev_priv *np = netdev_priv(netdev);
1708 struct i40e_vsi *vsi = np->vsi;
1709
1710 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1711 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1712
1713 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001714 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715
1716 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001717 ec->use_adaptive_tx_coalesce = 1;
1718
1719 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1720 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721
1722 return 0;
1723}
1724
1725static int i40e_set_coalesce(struct net_device *netdev,
1726 struct ethtool_coalesce *ec)
1727{
1728 struct i40e_netdev_priv *np = netdev_priv(netdev);
1729 struct i40e_q_vector *q_vector;
1730 struct i40e_vsi *vsi = np->vsi;
1731 struct i40e_pf *pf = vsi->back;
1732 struct i40e_hw *hw = &pf->hw;
1733 u16 vector;
1734 int i;
1735
1736 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1737 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1738
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001739 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001740 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001741 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001742 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001743 } else if (ec->rx_coalesce_usecs == 0) {
1744 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001745 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001746 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 +00001747 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001748 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001749 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001750 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001751
Mitch Williams32f5f542014-04-04 04:43:10 +00001752 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001753 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001754 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001755 } else if (ec->tx_coalesce_usecs == 0) {
1756 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001757 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001758 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 +00001759 } else {
1760 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001761 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001762 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001763 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001764
1765 if (ec->use_adaptive_rx_coalesce)
1766 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1767 else
1768 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1769
1770 if (ec->use_adaptive_tx_coalesce)
1771 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1772 else
1773 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774
Alexander Duyck493fb302013-09-28 07:01:44 +00001775 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1776 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001777 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1778 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1779 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1780 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1781 i40e_flush(hw);
1782 }
1783
1784 return 0;
1785}
1786
1787/**
1788 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1789 * @pf: pointer to the physical function struct
1790 * @cmd: ethtool rxnfc command
1791 *
1792 * Returns Success if the flow is supported, else Invalid Input.
1793 **/
1794static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1795{
1796 cmd->data = 0;
1797
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001798 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1799 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1800 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1801 return 0;
1802 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001803 /* Report default options for RSS on i40e */
1804 switch (cmd->flow_type) {
1805 case TCP_V4_FLOW:
1806 case UDP_V4_FLOW:
1807 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1808 /* fall through to add IP fields */
1809 case SCTP_V4_FLOW:
1810 case AH_ESP_V4_FLOW:
1811 case AH_V4_FLOW:
1812 case ESP_V4_FLOW:
1813 case IPV4_FLOW:
1814 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1815 break;
1816 case TCP_V6_FLOW:
1817 case UDP_V6_FLOW:
1818 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1819 /* fall through to add IP fields */
1820 case SCTP_V6_FLOW:
1821 case AH_ESP_V6_FLOW:
1822 case AH_V6_FLOW:
1823 case ESP_V6_FLOW:
1824 case IPV6_FLOW:
1825 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1826 break;
1827 default:
1828 return -EINVAL;
1829 }
1830
1831 return 0;
1832}
1833
1834/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001835 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1836 * @pf: Pointer to the physical function struct
1837 * @cmd: The command to get or set Rx flow classification rules
1838 * @rule_locs: Array of used rule locations
1839 *
1840 * This function populates both the total and actual rule count of
1841 * the ethtool flow classification command
1842 *
1843 * Returns 0 on success or -EMSGSIZE if entry not found
1844 **/
1845static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1846 struct ethtool_rxnfc *cmd,
1847 u32 *rule_locs)
1848{
1849 struct i40e_fdir_filter *rule;
1850 struct hlist_node *node2;
1851 int cnt = 0;
1852
1853 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001854 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001855
1856 hlist_for_each_entry_safe(rule, node2,
1857 &pf->fdir_filter_list, fdir_node) {
1858 if (cnt == cmd->rule_cnt)
1859 return -EMSGSIZE;
1860
1861 rule_locs[cnt] = rule->fd_id;
1862 cnt++;
1863 }
1864
1865 cmd->rule_cnt = cnt;
1866
1867 return 0;
1868}
1869
1870/**
1871 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1872 * @pf: Pointer to the physical function struct
1873 * @cmd: The command to get or set Rx flow classification rules
1874 *
1875 * This function looks up a filter based on the Rx flow classification
1876 * command and fills the flow spec info for it if found
1877 *
1878 * Returns 0 on success or -EINVAL if filter not found
1879 **/
1880static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1881 struct ethtool_rxnfc *cmd)
1882{
1883 struct ethtool_rx_flow_spec *fsp =
1884 (struct ethtool_rx_flow_spec *)&cmd->fs;
1885 struct i40e_fdir_filter *rule = NULL;
1886 struct hlist_node *node2;
1887
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001888 hlist_for_each_entry_safe(rule, node2,
1889 &pf->fdir_filter_list, fdir_node) {
1890 if (fsp->location <= rule->fd_id)
1891 break;
1892 }
1893
1894 if (!rule || fsp->location != rule->fd_id)
1895 return -EINVAL;
1896
1897 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001898 if (fsp->flow_type == IP_USER_FLOW) {
1899 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1900 fsp->h_u.usr_ip4_spec.proto = 0;
1901 fsp->m_u.usr_ip4_spec.proto = 0;
1902 }
1903
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001904 /* Reverse the src and dest notion, since the HW views them from
1905 * Tx perspective where as the user expects it from Rx filter view.
1906 */
1907 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1908 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1909 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1910 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001911
1912 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1913 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1914 else
1915 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001916
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04001917 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1918 struct i40e_vsi *vsi;
1919
1920 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1921 if (vsi && vsi->type == I40E_VSI_SRIOV) {
1922 fsp->h_ext.data[1] = htonl(vsi->vf_id);
1923 fsp->m_ext.data[1] = htonl(0x1);
1924 }
1925 }
1926
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001927 return 0;
1928}
1929
1930/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001931 * i40e_get_rxnfc - command to get RX flow classification rules
1932 * @netdev: network interface device structure
1933 * @cmd: ethtool rxnfc command
1934 *
1935 * Returns Success if the command is supported.
1936 **/
1937static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1938 u32 *rule_locs)
1939{
1940 struct i40e_netdev_priv *np = netdev_priv(netdev);
1941 struct i40e_vsi *vsi = np->vsi;
1942 struct i40e_pf *pf = vsi->back;
1943 int ret = -EOPNOTSUPP;
1944
1945 switch (cmd->cmd) {
1946 case ETHTOOL_GRXRINGS:
1947 cmd->data = vsi->alloc_queue_pairs;
1948 ret = 0;
1949 break;
1950 case ETHTOOL_GRXFH:
1951 ret = i40e_get_rss_hash_opts(pf, cmd);
1952 break;
1953 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001954 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001955 /* report total rule count */
1956 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001957 ret = 0;
1958 break;
1959 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001960 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001961 break;
1962 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001963 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1964 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001965 default:
1966 break;
1967 }
1968
1969 return ret;
1970}
1971
1972/**
1973 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1974 * @pf: pointer to the physical function struct
1975 * @cmd: ethtool rxnfc command
1976 *
1977 * Returns Success if the flow input set is supported.
1978 **/
1979static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1980{
1981 struct i40e_hw *hw = &pf->hw;
1982 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1983 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1984
1985 /* RSS does not support anything other than hashing
1986 * to queues on src and dst IPs and ports
1987 */
1988 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1989 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1990 return -EINVAL;
1991
1992 /* We need at least the IP SRC and DEST fields for hashing */
1993 if (!(nfc->data & RXH_IP_SRC) ||
1994 !(nfc->data & RXH_IP_DST))
1995 return -EINVAL;
1996
1997 switch (nfc->flow_type) {
1998 case TCP_V4_FLOW:
1999 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2000 case 0:
2001 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2002 break;
2003 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2004 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2005 break;
2006 default:
2007 return -EINVAL;
2008 }
2009 break;
2010 case TCP_V6_FLOW:
2011 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2012 case 0:
2013 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2014 break;
2015 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2016 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2017 break;
2018 default:
2019 return -EINVAL;
2020 }
2021 break;
2022 case UDP_V4_FLOW:
2023 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2024 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002025 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2026 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002027 break;
2028 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002029 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2030 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002031 break;
2032 default:
2033 return -EINVAL;
2034 }
2035 break;
2036 case UDP_V6_FLOW:
2037 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2038 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002039 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2040 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002041 break;
2042 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002043 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2044 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002045 break;
2046 default:
2047 return -EINVAL;
2048 }
2049 break;
2050 case AH_ESP_V4_FLOW:
2051 case AH_V4_FLOW:
2052 case ESP_V4_FLOW:
2053 case SCTP_V4_FLOW:
2054 if ((nfc->data & RXH_L4_B_0_1) ||
2055 (nfc->data & RXH_L4_B_2_3))
2056 return -EINVAL;
2057 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2058 break;
2059 case AH_ESP_V6_FLOW:
2060 case AH_V6_FLOW:
2061 case ESP_V6_FLOW:
2062 case SCTP_V6_FLOW:
2063 if ((nfc->data & RXH_L4_B_0_1) ||
2064 (nfc->data & RXH_L4_B_2_3))
2065 return -EINVAL;
2066 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2067 break;
2068 case IPV4_FLOW:
2069 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2070 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2071 break;
2072 case IPV6_FLOW:
2073 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2074 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2075 break;
2076 default:
2077 return -EINVAL;
2078 }
2079
2080 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2081 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2082 i40e_flush(hw);
2083
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002084 /* Save setting for future output/update */
2085 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2086
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002087 return 0;
2088}
2089
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002090/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002091 * i40e_match_fdir_input_set - Match a new filter against an existing one
2092 * @rule: The filter already added
2093 * @input: The new filter to comapre against
2094 *
2095 * Returns true if the two input set match
2096 **/
2097static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2098 struct i40e_fdir_filter *input)
2099{
2100 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2101 (rule->src_ip[0] != input->src_ip[0]) ||
2102 (rule->dst_port != input->dst_port) ||
2103 (rule->src_port != input->src_port))
2104 return false;
2105 return true;
2106}
2107
2108/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002109 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2110 * @vsi: Pointer to the targeted VSI
2111 * @input: The filter to update or NULL to indicate deletion
2112 * @sw_idx: Software index to the filter
2113 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002114 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002115 * This function updates (or deletes) a Flow Director entry from
2116 * the hlist of the corresponding PF
2117 *
2118 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002119 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002120static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2121 struct i40e_fdir_filter *input,
2122 u16 sw_idx,
2123 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002124{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002125 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002126 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002127 struct hlist_node *node2;
2128 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002129
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002130 parent = NULL;
2131 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002132
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002133 hlist_for_each_entry_safe(rule, node2,
2134 &pf->fdir_filter_list, fdir_node) {
2135 /* hash found, or no matching entry */
2136 if (rule->fd_id >= sw_idx)
2137 break;
2138 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002139 }
2140
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002141 /* if there is an old rule occupying our place remove it */
2142 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002143 if (input && !i40e_match_fdir_input_set(rule, input))
2144 err = i40e_add_del_fdir(vsi, rule, false);
2145 else if (!input)
2146 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002147 hlist_del(&rule->fdir_node);
2148 kfree(rule);
2149 pf->fdir_pf_active_filters--;
2150 }
2151
2152 /* If no input this was a delete, err should be 0 if a rule was
2153 * successfully found and removed from the list else -EINVAL
2154 */
2155 if (!input)
2156 return err;
2157
2158 /* initialize node and set software index */
2159 INIT_HLIST_NODE(&input->fdir_node);
2160
2161 /* add filter to the list */
2162 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002163 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002164 else
2165 hlist_add_head(&input->fdir_node,
2166 &pf->fdir_filter_list);
2167
2168 /* update counts */
2169 pf->fdir_pf_active_filters++;
2170
2171 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172}
2173
2174/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002175 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2176 * @vsi: Pointer to the targeted VSI
2177 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002179 * The function removes a Flow Director filter entry from the
2180 * hlist of the corresponding PF
2181 *
2182 * Returns 0 on success
2183 */
2184static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2185 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002186{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002187 struct ethtool_rx_flow_spec *fsp =
2188 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002189 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002190 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002191
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002192 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2193 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2194 return -EBUSY;
2195
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002196 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2197 return -EBUSY;
2198
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002199 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002201 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002202 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002203}
2204
2205/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002206 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002207 * @vsi: pointer to the targeted VSI
2208 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002209 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002210 * Add Flow Director filters for a specific flow spec based on their
2211 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002213static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2214 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002215{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002216 struct ethtool_rx_flow_spec *fsp;
2217 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002218 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002219 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002220 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002221
2222 if (!vsi)
2223 return -EINVAL;
2224
2225 pf = vsi->back;
2226
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002227 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2228 return -EOPNOTSUPP;
2229
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002230 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002231 return -ENOSPC;
2232
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002233 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2234 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2235 return -EBUSY;
2236
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002237 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2238 return -EBUSY;
2239
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002240 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2241
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002242 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2243 pf->hw.func_caps.fd_filters_guaranteed)) {
2244 return -EINVAL;
2245 }
2246
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002247 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2248 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002249 return -EINVAL;
2250
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002251 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002252
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002253 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002254 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002255
2256 input->fd_id = fsp->location;
2257
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002258 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2259 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2260 else
2261 input->dest_ctl =
2262 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2263
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002264 input->q_index = fsp->ring_cookie;
2265 input->flex_off = 0;
2266 input->pctype = 0;
2267 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002268 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002269 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002270 input->flow_type = fsp->flow_type;
2271 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002272
2273 /* Reverse the src and dest notion, since the HW expects them to be from
2274 * Tx perspective where as the input from user is from Rx filter view.
2275 */
2276 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2277 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2278 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2279 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002280
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002281 if (ntohl(fsp->m_ext.data[1])) {
2282 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2283 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2284 goto free_input;
2285 }
2286 vf_id = ntohl(fsp->h_ext.data[1]);
2287 /* Find vsi id from vf id and override dest vsi */
2288 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2289 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2290 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2291 goto free_input;
2292 }
2293 }
2294
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002295 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002296free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002297 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002298 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002299 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002300 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002301
2302 return ret;
2303}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002304
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002305/**
2306 * i40e_set_rxnfc - command to set RX flow classification rules
2307 * @netdev: network interface device structure
2308 * @cmd: ethtool rxnfc command
2309 *
2310 * Returns Success if the command is supported.
2311 **/
2312static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2313{
2314 struct i40e_netdev_priv *np = netdev_priv(netdev);
2315 struct i40e_vsi *vsi = np->vsi;
2316 struct i40e_pf *pf = vsi->back;
2317 int ret = -EOPNOTSUPP;
2318
2319 switch (cmd->cmd) {
2320 case ETHTOOL_SRXFH:
2321 ret = i40e_set_rss_hash_opt(pf, cmd);
2322 break;
2323 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002324 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002325 break;
2326 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002327 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002328 break;
2329 default:
2330 break;
2331 }
2332
2333 return ret;
2334}
2335
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002336/**
2337 * i40e_max_channels - get Max number of combined channels supported
2338 * @vsi: vsi pointer
2339 **/
2340static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2341{
2342 /* TODO: This code assumes DCB and FD is disabled for now. */
2343 return vsi->alloc_queue_pairs;
2344}
2345
2346/**
2347 * i40e_get_channels - Get the current channels enabled and max supported etc.
2348 * @netdev: network interface device structure
2349 * @ch: ethtool channels structure
2350 *
2351 * We don't support separate tx and rx queues as channels. The other count
2352 * represents how many queues are being used for control. max_combined counts
2353 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2354 * q_vectors since we support a lot more queue pairs than q_vectors.
2355 **/
2356static void i40e_get_channels(struct net_device *dev,
2357 struct ethtool_channels *ch)
2358{
2359 struct i40e_netdev_priv *np = netdev_priv(dev);
2360 struct i40e_vsi *vsi = np->vsi;
2361 struct i40e_pf *pf = vsi->back;
2362
2363 /* report maximum channels */
2364 ch->max_combined = i40e_max_channels(vsi);
2365
2366 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002367 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002368 ch->max_other = ch->other_count;
2369
2370 /* Note: This code assumes DCB is disabled for now. */
2371 ch->combined_count = vsi->num_queue_pairs;
2372}
2373
2374/**
2375 * i40e_set_channels - Set the new channels count.
2376 * @netdev: network interface device structure
2377 * @ch: ethtool channels structure
2378 *
2379 * The new channels count may not be the same as requested by the user
2380 * since it gets rounded down to a power of 2 value.
2381 **/
2382static int i40e_set_channels(struct net_device *dev,
2383 struct ethtool_channels *ch)
2384{
2385 struct i40e_netdev_priv *np = netdev_priv(dev);
2386 unsigned int count = ch->combined_count;
2387 struct i40e_vsi *vsi = np->vsi;
2388 struct i40e_pf *pf = vsi->back;
2389 int new_count;
2390
2391 /* We do not support setting channels for any other VSI at present */
2392 if (vsi->type != I40E_VSI_MAIN)
2393 return -EINVAL;
2394
2395 /* verify they are not requesting separate vectors */
2396 if (!count || ch->rx_count || ch->tx_count)
2397 return -EINVAL;
2398
2399 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002400 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002401 return -EINVAL;
2402
2403 /* verify the number of channels does not exceed hardware limits */
2404 if (count > i40e_max_channels(vsi))
2405 return -EINVAL;
2406
2407 /* update feature limits from largest to smallest supported values */
2408 /* TODO: Flow director limit, DCB etc */
2409
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002410 /* use rss_reconfig to rebuild with new queue count and update traffic
2411 * class queue mapping
2412 */
2413 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002414 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002415 return 0;
2416 else
2417 return -EINVAL;
2418}
2419
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002420#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2421/**
2422 * i40e_get_rxfh_key_size - get the RSS hash key size
2423 * @netdev: network interface device structure
2424 *
2425 * Returns the table size.
2426 **/
2427static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2428{
2429 return I40E_HKEY_ARRAY_SIZE;
2430}
2431
2432/**
2433 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2434 * @netdev: network interface device structure
2435 *
2436 * Returns the table size.
2437 **/
2438static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2439{
2440 return I40E_HLUT_ARRAY_SIZE;
2441}
2442
2443static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2444 u8 *hfunc)
2445{
2446 struct i40e_netdev_priv *np = netdev_priv(netdev);
2447 struct i40e_vsi *vsi = np->vsi;
2448 struct i40e_pf *pf = vsi->back;
2449 struct i40e_hw *hw = &pf->hw;
2450 u32 reg_val;
2451 int i, j;
2452
2453 if (hfunc)
2454 *hfunc = ETH_RSS_HASH_TOP;
2455
2456 if (!indir)
2457 return 0;
2458
2459 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2460 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2461 indir[j++] = reg_val & 0xff;
2462 indir[j++] = (reg_val >> 8) & 0xff;
2463 indir[j++] = (reg_val >> 16) & 0xff;
2464 indir[j++] = (reg_val >> 24) & 0xff;
2465 }
2466
2467 if (key) {
2468 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2469 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2470 key[j++] = (u8)(reg_val & 0xff);
2471 key[j++] = (u8)((reg_val >> 8) & 0xff);
2472 key[j++] = (u8)((reg_val >> 16) & 0xff);
2473 key[j++] = (u8)((reg_val >> 24) & 0xff);
2474 }
2475 }
2476 return 0;
2477}
2478
2479/**
2480 * i40e_set_rxfh - set the rx flow hash indirection table
2481 * @netdev: network interface device structure
2482 * @indir: indirection table
2483 * @key: hash key
2484 *
2485 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
2486 * returns 0 after programming the table.
2487 **/
2488static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2489 const u8 *key, const u8 hfunc)
2490{
2491 struct i40e_netdev_priv *np = netdev_priv(netdev);
2492 struct i40e_vsi *vsi = np->vsi;
2493 struct i40e_pf *pf = vsi->back;
2494 struct i40e_hw *hw = &pf->hw;
2495 u32 reg_val;
2496 int i, j;
2497
2498 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2499 return -EOPNOTSUPP;
2500
2501 if (!indir)
2502 return 0;
2503
2504 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2505 reg_val = indir[j++];
2506 reg_val |= indir[j++] << 8;
2507 reg_val |= indir[j++] << 16;
2508 reg_val |= indir[j++] << 24;
2509 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2510 }
2511
2512 if (key) {
2513 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2514 reg_val = key[j++];
2515 reg_val |= key[j++] << 8;
2516 reg_val |= key[j++] << 16;
2517 reg_val |= key[j++] << 24;
2518 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2519 }
2520 }
2521 return 0;
2522}
2523
Greg Rose7e45ab42015-02-06 08:52:19 +00002524/**
2525 * i40e_get_priv_flags - report device private flags
2526 * @dev: network interface device structure
2527 *
2528 * The get string set count and the string set should be matched for each
2529 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2530 * array.
2531 *
2532 * Returns a u32 bitmap of flags.
2533 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002534static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002535{
2536 struct i40e_netdev_priv *np = netdev_priv(dev);
2537 struct i40e_vsi *vsi = np->vsi;
2538 struct i40e_pf *pf = vsi->back;
2539 u32 ret_flags = 0;
2540
2541 ret_flags |= pf->hw.func_caps.npar_enable ?
2542 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2543
2544 return ret_flags;
2545}
2546
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002547static const struct ethtool_ops i40e_ethtool_ops = {
2548 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002549 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002550 .get_drvinfo = i40e_get_drvinfo,
2551 .get_regs_len = i40e_get_regs_len,
2552 .get_regs = i40e_get_regs,
2553 .nway_reset = i40e_nway_reset,
2554 .get_link = ethtool_op_get_link,
2555 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002556 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002557 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002558 .get_eeprom_len = i40e_get_eeprom_len,
2559 .get_eeprom = i40e_get_eeprom,
2560 .get_ringparam = i40e_get_ringparam,
2561 .set_ringparam = i40e_set_ringparam,
2562 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002563 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002564 .get_msglevel = i40e_get_msglevel,
2565 .set_msglevel = i40e_set_msglevel,
2566 .get_rxnfc = i40e_get_rxnfc,
2567 .set_rxnfc = i40e_set_rxnfc,
2568 .self_test = i40e_diag_test,
2569 .get_strings = i40e_get_strings,
2570 .set_phys_id = i40e_set_phys_id,
2571 .get_sset_count = i40e_get_sset_count,
2572 .get_ethtool_stats = i40e_get_ethtool_stats,
2573 .get_coalesce = i40e_get_coalesce,
2574 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002575 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2576 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2577 .get_rxfh = i40e_get_rxfh,
2578 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002579 .get_channels = i40e_get_channels,
2580 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002581 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002582 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002583};
2584
2585void i40e_set_ethtool_ops(struct net_device *netdev)
2586{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002587 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002588}