blob: f2075d5b800c193747d3faf487cd0d5ce5bec878 [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),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400150 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400151 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400153 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000154
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000155 /* LPI stats */
156 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
157 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
158 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
159 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000160};
161
Vasu Dev38e00432014-08-01 13:27:03 -0700162#ifdef I40E_FCOE
163static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
164 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
165 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
166 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
167 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
168 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
169 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
170 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
171 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
172};
173
174#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000175#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000176 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
177 * 2 /* Tx and Rx together */ \
178 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000179#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
180#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000181#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700182#ifdef I40E_FCOE
183#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
184#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
185 I40E_FCOE_STATS_LEN + \
186 I40E_MISC_STATS_LEN + \
187 I40E_QUEUE_STATS_LEN((n)))
188#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000190 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700192#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000193#define I40E_PFC_STATS_LEN ( \
194 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
199 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000200#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000201#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
202 I40E_PFC_STATS_LEN + \
203 I40E_VSI_STATS_LEN((n)))
204
205enum i40e_ethtool_test_id {
206 I40E_ETH_TEST_REG = 0,
207 I40E_ETH_TEST_EEPROM,
208 I40E_ETH_TEST_INTR,
209 I40E_ETH_TEST_LOOPBACK,
210 I40E_ETH_TEST_LINK,
211};
212
213static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
214 "Register test (offline)",
215 "Eeprom test (offline)",
216 "Interrupt test (offline)",
217 "Loopback test (offline)",
218 "Link test (on/offline)"
219};
220
221#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
222
Greg Rose7e45ab42015-02-06 08:52:19 +0000223static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
224 "NPAR",
225};
226
227#define I40E_PRIV_FLAGS_STR_LEN \
228 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
229
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000230/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000231 * i40e_partition_setting_complaint - generic complaint for MFP restriction
232 * @pf: the PF struct
233 **/
234static void i40e_partition_setting_complaint(struct i40e_pf *pf)
235{
236 dev_info(&pf->pdev->dev,
237 "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");
238}
239
240/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000241 * i40e_get_settings_link_up - Get the Link settings for when link is up
242 * @hw: hw structure
243 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000244 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000245 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000246 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000247static void i40e_get_settings_link_up(struct i40e_hw *hw,
248 struct ethtool_cmd *ecmd,
249 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000250{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 u32 link_speed = hw_link_info->link_speed;
253
Catherine Sullivane8278452015-02-06 08:52:08 +0000254 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000255 switch (hw_link_info->phy_type) {
256 case I40E_PHY_TYPE_40GBASE_CR4:
257 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000258 ecmd->supported = SUPPORTED_Autoneg |
259 SUPPORTED_40000baseCR4_Full;
260 ecmd->advertising = ADVERTISED_Autoneg |
261 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000263 case I40E_PHY_TYPE_XLAUI:
264 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000265 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000266 ecmd->supported = SUPPORTED_40000baseCR4_Full;
267 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000268 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000269 ecmd->supported = SUPPORTED_Autoneg |
270 SUPPORTED_40000baseKR4_Full;
271 ecmd->advertising = ADVERTISED_Autoneg |
272 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000273 break;
274 case I40E_PHY_TYPE_40GBASE_SR4:
275 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 break;
277 case I40E_PHY_TYPE_40GBASE_LR4:
278 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000279 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700280 case I40E_PHY_TYPE_20GBASE_KR2:
281 ecmd->supported = SUPPORTED_Autoneg |
282 SUPPORTED_20000baseKR2_Full;
283 ecmd->advertising = ADVERTISED_Autoneg |
284 ADVERTISED_20000baseKR2_Full;
285 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000286 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000287 ecmd->supported = SUPPORTED_Autoneg |
288 SUPPORTED_10000baseKX4_Full;
289 ecmd->advertising = ADVERTISED_Autoneg |
290 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000291 break;
292 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000293 ecmd->supported = SUPPORTED_Autoneg |
294 SUPPORTED_10000baseKR_Full;
295 ecmd->advertising = ADVERTISED_Autoneg |
296 ADVERTISED_10000baseKR_Full;
297 break;
298 case I40E_PHY_TYPE_10GBASE_SR:
299 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000300 case I40E_PHY_TYPE_1000BASE_SX:
301 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000302 ecmd->supported = SUPPORTED_10000baseT_Full |
303 SUPPORTED_1000baseT_Full;
304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
305 ecmd->advertising |= ADVERTISED_10000baseT_Full;
306 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
307 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000308 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000309 case I40E_PHY_TYPE_1000BASE_KX:
310 ecmd->supported = SUPPORTED_Autoneg |
311 SUPPORTED_1000baseKX_Full;
312 ecmd->advertising = ADVERTISED_Autoneg |
313 ADVERTISED_1000baseKX_Full;
314 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000315 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000316 case I40E_PHY_TYPE_1000BASE_T:
317 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000318 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000319 SUPPORTED_10000baseT_Full |
320 SUPPORTED_1000baseT_Full |
321 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000322 ecmd->advertising = ADVERTISED_Autoneg;
323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
324 ecmd->advertising |= ADVERTISED_10000baseT_Full;
325 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
326 ecmd->advertising |= ADVERTISED_1000baseT_Full;
327 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
328 ecmd->advertising |= ADVERTISED_100baseT_Full;
329 break;
330 case I40E_PHY_TYPE_10GBASE_CR1_CU:
331 case I40E_PHY_TYPE_10GBASE_CR1:
332 ecmd->supported = SUPPORTED_Autoneg |
333 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000334 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000335 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336 break;
337 case I40E_PHY_TYPE_XAUI:
338 case I40E_PHY_TYPE_XFI:
339 case I40E_PHY_TYPE_SFI:
340 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000341 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000342 ecmd->supported = SUPPORTED_10000baseT_Full;
343 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000344 case I40E_PHY_TYPE_SGMII:
345 ecmd->supported = SUPPORTED_Autoneg |
346 SUPPORTED_1000baseT_Full |
347 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000348 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
349 ecmd->advertising |= ADVERTISED_1000baseT_Full;
350 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
351 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000352 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000353 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000354 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000355 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
356 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000357 }
358
Catherine Sullivane8278452015-02-06 08:52:08 +0000359 /* Set speed and duplex */
360 switch (link_speed) {
361 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400362 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000363 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700364 case I40E_LINK_SPEED_20GB:
365 ethtool_cmd_speed_set(ecmd, SPEED_20000);
366 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000367 case I40E_LINK_SPEED_10GB:
368 ethtool_cmd_speed_set(ecmd, SPEED_10000);
369 break;
370 case I40E_LINK_SPEED_1GB:
371 ethtool_cmd_speed_set(ecmd, SPEED_1000);
372 break;
373 case I40E_LINK_SPEED_100MB:
374 ethtool_cmd_speed_set(ecmd, SPEED_100);
375 break;
376 default:
377 break;
378 }
379 ecmd->duplex = DUPLEX_FULL;
380}
381
382/**
383 * i40e_get_settings_link_down - Get the Link settings for when link is down
384 * @hw: hw structure
385 * @ecmd: ethtool command to fill in
386 *
387 * Reports link settings that can be determined when link is down
388 **/
389static void i40e_get_settings_link_down(struct i40e_hw *hw,
390 struct ethtool_cmd *ecmd)
391{
392 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
393
394 /* link is down and the driver needs to fall back on
395 * device ID to determine what kinds of info to display,
396 * it's mostly a guess that may change when link is up
397 */
398 switch (hw->device_id) {
399 case I40E_DEV_ID_QSFP_A:
400 case I40E_DEV_ID_QSFP_B:
401 case I40E_DEV_ID_QSFP_C:
402 /* pluggable QSFP */
403 ecmd->supported = SUPPORTED_40000baseSR4_Full |
404 SUPPORTED_40000baseCR4_Full |
405 SUPPORTED_40000baseLR4_Full;
406 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
407 ADVERTISED_40000baseCR4_Full |
408 ADVERTISED_40000baseLR4_Full;
409 break;
410 case I40E_DEV_ID_KX_B:
411 /* backplane 40G */
412 ecmd->supported = SUPPORTED_40000baseKR4_Full;
413 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
414 break;
415 case I40E_DEV_ID_KX_C:
416 /* backplane 10G */
417 ecmd->supported = SUPPORTED_10000baseKR_Full;
418 ecmd->advertising = ADVERTISED_10000baseKR_Full;
419 break;
420 case I40E_DEV_ID_10G_BASE_T:
421 ecmd->supported = SUPPORTED_10000baseT_Full |
422 SUPPORTED_1000baseT_Full |
423 SUPPORTED_100baseT_Full;
424 /* Figure out what has been requested */
425 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
426 ecmd->advertising |= ADVERTISED_10000baseT_Full;
427 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
428 ecmd->advertising |= ADVERTISED_1000baseT_Full;
429 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
430 ecmd->advertising |= ADVERTISED_100baseT_Full;
431 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700432 case I40E_DEV_ID_20G_KR2:
433 /* backplane 20G */
434 ecmd->supported = SUPPORTED_20000baseKR2_Full;
435 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
436 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000437 default:
438 /* all the rest are 10G/1G */
439 ecmd->supported = SUPPORTED_10000baseT_Full |
440 SUPPORTED_1000baseT_Full;
441 /* Figure out what has been requested */
442 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
443 ecmd->advertising |= ADVERTISED_10000baseT_Full;
444 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
445 ecmd->advertising |= ADVERTISED_1000baseT_Full;
446 break;
447 }
448
449 /* With no link speed and duplex are unknown */
450 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
451 ecmd->duplex = DUPLEX_UNKNOWN;
452}
453
454/**
455 * i40e_get_settings - Get Link Speed and Duplex settings
456 * @netdev: network interface device structure
457 * @ecmd: ethtool command
458 *
459 * Reports speed/duplex settings based on media_type
460 **/
461static int i40e_get_settings(struct net_device *netdev,
462 struct ethtool_cmd *ecmd)
463{
464 struct i40e_netdev_priv *np = netdev_priv(netdev);
465 struct i40e_pf *pf = np->vsi->back;
466 struct i40e_hw *hw = &pf->hw;
467 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
468 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
469
470 if (link_up)
471 i40e_get_settings_link_up(hw, ecmd, netdev);
472 else
473 i40e_get_settings_link_down(hw, ecmd);
474
475 /* Now set the settings that don't rely on link being up/down */
476
477 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000478 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
479 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000480
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000481 switch (hw->phy.media_type) {
482 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000483 ecmd->supported |= SUPPORTED_Autoneg |
484 SUPPORTED_Backplane;
485 ecmd->advertising |= ADVERTISED_Autoneg |
486 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000487 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000488 break;
489 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490 ecmd->supported |= SUPPORTED_TP;
491 ecmd->advertising |= ADVERTISED_TP;
492 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000493 break;
494 case I40E_MEDIA_TYPE_DA:
495 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000496 ecmd->supported |= SUPPORTED_FIBRE;
497 ecmd->advertising |= ADVERTISED_FIBRE;
498 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000499 break;
500 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000501 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000502 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000503 break;
504 case I40E_MEDIA_TYPE_UNKNOWN:
505 default:
506 ecmd->port = PORT_OTHER;
507 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000508 }
509
Catherine Sullivane8278452015-02-06 08:52:08 +0000510 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000511 ecmd->transceiver = XCVR_EXTERNAL;
512
Catherine Sullivane8278452015-02-06 08:52:08 +0000513 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000514 ecmd->supported |= SUPPORTED_Pause;
515
Catherine Sullivane8278452015-02-06 08:52:08 +0000516 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000517 case I40E_FC_FULL:
518 ecmd->advertising |= ADVERTISED_Pause;
519 break;
520 case I40E_FC_TX_PAUSE:
521 ecmd->advertising |= ADVERTISED_Asym_Pause;
522 break;
523 case I40E_FC_RX_PAUSE:
524 ecmd->advertising |= (ADVERTISED_Pause |
525 ADVERTISED_Asym_Pause);
526 break;
527 default:
528 ecmd->advertising &= ~(ADVERTISED_Pause |
529 ADVERTISED_Asym_Pause);
530 break;
531 }
532
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000533 return 0;
534}
535
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000536/**
537 * i40e_set_settings - Set Speed and Duplex
538 * @netdev: network interface device structure
539 * @ecmd: ethtool command
540 *
541 * Set speed/duplex per media_types advertised/forced
542 **/
543static int i40e_set_settings(struct net_device *netdev,
544 struct ethtool_cmd *ecmd)
545{
546 struct i40e_netdev_priv *np = netdev_priv(netdev);
547 struct i40e_aq_get_phy_abilities_resp abilities;
548 struct i40e_aq_set_phy_config config;
549 struct i40e_pf *pf = np->vsi->back;
550 struct i40e_vsi *vsi = np->vsi;
551 struct i40e_hw *hw = &pf->hw;
552 struct ethtool_cmd safe_ecmd;
553 i40e_status status = 0;
554 bool change = false;
555 int err = 0;
556 u8 autoneg;
557 u32 advertise;
558
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000559 /* Changing port settings is not supported if this isn't the
560 * port's controlling PF
561 */
562 if (hw->partition_id != 1) {
563 i40e_partition_setting_complaint(pf);
564 return -EOPNOTSUPP;
565 }
566
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000567 if (vsi != pf->vsi[pf->lan_vsi])
568 return -EOPNOTSUPP;
569
570 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
571 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000572 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
573 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000574 return -EOPNOTSUPP;
575
576 /* get our own copy of the bits to check against */
577 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
578 i40e_get_settings(netdev, &safe_ecmd);
579
580 /* save autoneg and speed out of ecmd */
581 autoneg = ecmd->autoneg;
582 advertise = ecmd->advertising;
583
584 /* set autoneg and speed back to what they currently are */
585 ecmd->autoneg = safe_ecmd.autoneg;
586 ecmd->advertising = safe_ecmd.advertising;
587
588 ecmd->cmd = safe_ecmd.cmd;
589 /* If ecmd and safe_ecmd are not the same now, then they are
590 * trying to set something that we do not support
591 */
592 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
593 return -EOPNOTSUPP;
594
595 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
596 usleep_range(1000, 2000);
597
598 /* Get the current phy config */
599 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
600 NULL);
601 if (status)
602 return -EAGAIN;
603
Catherine Sullivan124ed152014-07-12 07:28:12 +0000604 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000605 * set below
606 */
607 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000608 config.abilities = abilities.abilities;
609
610 /* Check autoneg */
611 if (autoneg == AUTONEG_ENABLE) {
612 /* If autoneg is not supported, return error */
613 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
614 netdev_info(netdev, "Autoneg not supported on this phy\n");
615 return -EINVAL;
616 }
617 /* If autoneg was not already enabled */
618 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
619 config.abilities = abilities.abilities |
620 I40E_AQ_PHY_ENABLE_AN;
621 change = true;
622 }
623 } else {
624 /* If autoneg is supported 10GBASE_T is the only phy that
625 * can disable it, so otherwise return error
626 */
627 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
628 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
629 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
630 return -EINVAL;
631 }
632 /* If autoneg is currently enabled */
633 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000634 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000635 ~I40E_AQ_PHY_ENABLE_AN;
636 change = true;
637 }
638 }
639
640 if (advertise & ~safe_ecmd.supported)
641 return -EINVAL;
642
643 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000644 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000645 if (advertise & ADVERTISED_1000baseT_Full ||
646 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000647 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000648 if (advertise & ADVERTISED_10000baseT_Full ||
649 advertise & ADVERTISED_10000baseKX4_Full ||
650 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000651 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700652 if (advertise & ADVERTISED_20000baseKR2_Full)
653 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000654 if (advertise & ADVERTISED_40000baseKR4_Full ||
655 advertise & ADVERTISED_40000baseCR4_Full ||
656 advertise & ADVERTISED_40000baseSR4_Full ||
657 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000658 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000659
Catherine Sullivan124ed152014-07-12 07:28:12 +0000660 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000661 /* copy over the rest of the abilities */
662 config.phy_type = abilities.phy_type;
663 config.eee_capability = abilities.eee_capability;
664 config.eeer = abilities.eeer_val;
665 config.low_power_ctrl = abilities.d3_lpan;
666
Catherine Sullivane8278452015-02-06 08:52:08 +0000667 /* save the requested speeds */
668 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000669 /* set link and auto negotiation so changes take effect */
670 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
671 /* If link is up put link down */
672 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
673 /* Tell the OS link is going down, the link will go
674 * back up when fw says it is ready asynchronously
675 */
676 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
677 netif_carrier_off(netdev);
678 netif_tx_stop_all_queues(netdev);
679 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000680
681 /* make the aq call */
682 status = i40e_aq_set_phy_config(hw, &config, NULL);
683 if (status) {
684 netdev_info(netdev, "Set phy config failed with error %d.\n",
685 status);
686 return -EAGAIN;
687 }
688
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000689 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000690 if (status)
691 netdev_info(netdev, "Updating link info failed with error %d\n",
692 status);
693
694 } else {
695 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
696 }
697
698 return err;
699}
700
Jesse Brandeburga6599722014-06-04 08:45:25 +0000701static int i40e_nway_reset(struct net_device *netdev)
702{
703 /* restart autonegotiation */
704 struct i40e_netdev_priv *np = netdev_priv(netdev);
705 struct i40e_pf *pf = np->vsi->back;
706 struct i40e_hw *hw = &pf->hw;
707 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
708 i40e_status ret = 0;
709
710 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
711 if (ret) {
712 netdev_info(netdev, "link restart failed, aq_err=%d\n",
713 pf->hw.aq.asq_last_status);
714 return -EIO;
715 }
716
717 return 0;
718}
719
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000720/**
721 * i40e_get_pauseparam - Get Flow Control status
722 * Return tx/rx-pause status
723 **/
724static void i40e_get_pauseparam(struct net_device *netdev,
725 struct ethtool_pauseparam *pause)
726{
727 struct i40e_netdev_priv *np = netdev_priv(netdev);
728 struct i40e_pf *pf = np->vsi->back;
729 struct i40e_hw *hw = &pf->hw;
730 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000731 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000732
733 pause->autoneg =
734 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
735 AUTONEG_ENABLE : AUTONEG_DISABLE);
736
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000737 /* PFC enabled so report LFC as off */
738 if (dcbx_cfg->pfc.pfcenable) {
739 pause->rx_pause = 0;
740 pause->tx_pause = 0;
741 return;
742 }
743
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000744 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000745 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000746 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000747 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000748 } else if (hw->fc.current_mode == I40E_FC_FULL) {
749 pause->rx_pause = 1;
750 pause->tx_pause = 1;
751 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000752}
753
Catherine Sullivan2becc352014-06-04 08:45:27 +0000754/**
755 * i40e_set_pauseparam - Set Flow Control parameter
756 * @netdev: network interface device structure
757 * @pause: return tx/rx flow control status
758 **/
759static int i40e_set_pauseparam(struct net_device *netdev,
760 struct ethtool_pauseparam *pause)
761{
762 struct i40e_netdev_priv *np = netdev_priv(netdev);
763 struct i40e_pf *pf = np->vsi->back;
764 struct i40e_vsi *vsi = np->vsi;
765 struct i40e_hw *hw = &pf->hw;
766 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000767 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000768 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
769 i40e_status status;
770 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000771 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000772
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000773 /* Changing the port's flow control is not supported if this isn't the
774 * port's controlling PF
775 */
776 if (hw->partition_id != 1) {
777 i40e_partition_setting_complaint(pf);
778 return -EOPNOTSUPP;
779 }
780
Catherine Sullivan2becc352014-06-04 08:45:27 +0000781 if (vsi != pf->vsi[pf->lan_vsi])
782 return -EOPNOTSUPP;
783
784 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
785 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
786 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
787 return -EOPNOTSUPP;
788 }
789
790 /* If we have link and don't have autoneg */
791 if (!test_bit(__I40E_DOWN, &pf->state) &&
792 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
793 /* Send message that it might not necessarily work*/
794 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
795 }
796
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000797 if (dcbx_cfg->pfc.pfcenable) {
798 netdev_info(netdev,
799 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000800 return -EOPNOTSUPP;
801 }
802
803 if (pause->rx_pause && pause->tx_pause)
804 hw->fc.requested_mode = I40E_FC_FULL;
805 else if (pause->rx_pause && !pause->tx_pause)
806 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
807 else if (!pause->rx_pause && pause->tx_pause)
808 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
809 else if (!pause->rx_pause && !pause->tx_pause)
810 hw->fc.requested_mode = I40E_FC_NONE;
811 else
812 return -EINVAL;
813
Catherine Sullivan94128512014-07-12 07:28:16 +0000814 /* Tell the OS link is going down, the link will go back up when fw
815 * says it is ready asynchronously
816 */
817 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
818 netif_carrier_off(netdev);
819 netif_tx_stop_all_queues(netdev);
820
Catherine Sullivan2becc352014-06-04 08:45:27 +0000821 /* Set the fc mode and only restart an if link is up*/
822 status = i40e_set_fc(hw, &aq_failures, link_up);
823
824 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
825 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
826 status, hw->aq.asq_last_status);
827 err = -EAGAIN;
828 }
829 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
830 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
831 status, hw->aq.asq_last_status);
832 err = -EAGAIN;
833 }
834 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000835 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 +0000836 status, hw->aq.asq_last_status);
837 err = -EAGAIN;
838 }
839
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000840 if (!test_bit(__I40E_DOWN, &pf->state)) {
841 /* Give it a little more time to try to come back */
842 msleep(75);
843 if (!test_bit(__I40E_DOWN, &pf->state))
844 return i40e_nway_reset(netdev);
845 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000846
847 return err;
848}
849
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000850static u32 i40e_get_msglevel(struct net_device *netdev)
851{
852 struct i40e_netdev_priv *np = netdev_priv(netdev);
853 struct i40e_pf *pf = np->vsi->back;
854
855 return pf->msg_enable;
856}
857
858static void i40e_set_msglevel(struct net_device *netdev, u32 data)
859{
860 struct i40e_netdev_priv *np = netdev_priv(netdev);
861 struct i40e_pf *pf = np->vsi->back;
862
863 if (I40E_DEBUG_USER & data)
864 pf->hw.debug_mask = data;
865 pf->msg_enable = data;
866}
867
868static int i40e_get_regs_len(struct net_device *netdev)
869{
870 int reg_count = 0;
871 int i;
872
873 for (i = 0; i40e_reg_list[i].offset != 0; i++)
874 reg_count += i40e_reg_list[i].elements;
875
876 return reg_count * sizeof(u32);
877}
878
879static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
880 void *p)
881{
882 struct i40e_netdev_priv *np = netdev_priv(netdev);
883 struct i40e_pf *pf = np->vsi->back;
884 struct i40e_hw *hw = &pf->hw;
885 u32 *reg_buf = p;
886 int i, j, ri;
887 u32 reg;
888
889 /* Tell ethtool which driver-version-specific regs output we have.
890 *
891 * At some point, if we have ethtool doing special formatting of
892 * this data, it will rely on this version number to know how to
893 * interpret things. Hence, this needs to be updated if/when the
894 * diags register table is changed.
895 */
896 regs->version = 1;
897
898 /* loop through the diags reg table for what to print */
899 ri = 0;
900 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
901 for (j = 0; j < i40e_reg_list[i].elements; j++) {
902 reg = i40e_reg_list[i].offset
903 + (j * i40e_reg_list[i].stride);
904 reg_buf[ri++] = rd32(hw, reg);
905 }
906 }
907
908}
909
910static int i40e_get_eeprom(struct net_device *netdev,
911 struct ethtool_eeprom *eeprom, u8 *bytes)
912{
913 struct i40e_netdev_priv *np = netdev_priv(netdev);
914 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000915 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000916 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000917 u8 *eeprom_buff;
918 u16 i, sectors;
919 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000920 u32 magic;
921
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000922#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000923 if (eeprom->len == 0)
924 return -EINVAL;
925
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000926 /* check for NVMUpdate access method */
927 magic = hw->vendor_id | (hw->device_id << 16);
928 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000929 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000930 int errno;
931
932 /* make sure it is the right magic for NVMUpdate */
933 if ((eeprom->magic >> 16) != hw->device_id)
934 return -EINVAL;
935
Shannon Nelsonc150a502014-11-13 08:23:13 +0000936 cmd = (struct i40e_nvm_access *)eeprom;
937 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000938 if (ret_val &&
939 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
940 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000941 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000942 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
943 ret_val, hw->aq.asq_last_status, errno,
944 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
945 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000946
947 return errno;
948 }
949
950 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000951 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
952
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000953 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000954 if (!eeprom_buff)
955 return -ENOMEM;
956
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000957 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
958 if (ret_val) {
959 dev_info(&pf->pdev->dev,
960 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
961 ret_val, hw->aq.asq_last_status);
962 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000963 }
964
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000965 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
966 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
967 len = I40E_NVM_SECTOR_SIZE;
968 last = false;
969 for (i = 0; i < sectors; i++) {
970 if (i == (sectors - 1)) {
971 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
972 last = true;
973 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000974 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
975 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000976 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000977 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000978 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000979 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000980 "read NVM failed, invalid offset 0x%x\n",
981 offset);
982 break;
983 } else if (ret_val &&
984 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
985 dev_info(&pf->pdev->dev,
986 "read NVM failed, access, offset 0x%x\n",
987 offset);
988 break;
989 } else if (ret_val) {
990 dev_info(&pf->pdev->dev,
991 "read NVM failed offset %d err=%d status=0x%x\n",
992 offset, ret_val, hw->aq.asq_last_status);
993 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000994 }
995 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000996
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000997 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000998 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000999free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001000 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001001 return ret_val;
1002}
1003
1004static int i40e_get_eeprom_len(struct net_device *netdev)
1005{
1006 struct i40e_netdev_priv *np = netdev_priv(netdev);
1007 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001008 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001009
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001010 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1011 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1012 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1013 /* register returns value in power of 2, 64Kbyte chunks. */
1014 val = (64 * 1024) * (1 << val);
1015 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001016}
1017
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001018static int i40e_set_eeprom(struct net_device *netdev,
1019 struct ethtool_eeprom *eeprom, u8 *bytes)
1020{
1021 struct i40e_netdev_priv *np = netdev_priv(netdev);
1022 struct i40e_hw *hw = &np->vsi->back->hw;
1023 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001024 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001025 int ret_val = 0;
1026 int errno;
1027 u32 magic;
1028
1029 /* normal ethtool set_eeprom is not supported */
1030 magic = hw->vendor_id | (hw->device_id << 16);
1031 if (eeprom->magic == magic)
1032 return -EOPNOTSUPP;
1033
1034 /* check for NVMUpdate access method */
1035 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1036 return -EINVAL;
1037
1038 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1039 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1040 return -EBUSY;
1041
Shannon Nelsonc150a502014-11-13 08:23:13 +00001042 cmd = (struct i40e_nvm_access *)eeprom;
1043 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001044 if (ret_val &&
1045 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1046 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1047 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001048 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001049 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1050 ret_val, hw->aq.asq_last_status, errno,
1051 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1052 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001053
1054 return errno;
1055}
1056
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001057static void i40e_get_drvinfo(struct net_device *netdev,
1058 struct ethtool_drvinfo *drvinfo)
1059{
1060 struct i40e_netdev_priv *np = netdev_priv(netdev);
1061 struct i40e_vsi *vsi = np->vsi;
1062 struct i40e_pf *pf = vsi->back;
1063
1064 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1065 strlcpy(drvinfo->version, i40e_driver_version_str,
1066 sizeof(drvinfo->version));
1067 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1068 sizeof(drvinfo->fw_version));
1069 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1070 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001071 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072}
1073
1074static void i40e_get_ringparam(struct net_device *netdev,
1075 struct ethtool_ringparam *ring)
1076{
1077 struct i40e_netdev_priv *np = netdev_priv(netdev);
1078 struct i40e_pf *pf = np->vsi->back;
1079 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1080
1081 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1082 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1083 ring->rx_mini_max_pending = 0;
1084 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001085 ring->rx_pending = vsi->rx_rings[0]->count;
1086 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001087 ring->rx_mini_pending = 0;
1088 ring->rx_jumbo_pending = 0;
1089}
1090
1091static int i40e_set_ringparam(struct net_device *netdev,
1092 struct ethtool_ringparam *ring)
1093{
1094 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1095 struct i40e_netdev_priv *np = netdev_priv(netdev);
1096 struct i40e_vsi *vsi = np->vsi;
1097 struct i40e_pf *pf = vsi->back;
1098 u32 new_rx_count, new_tx_count;
1099 int i, err = 0;
1100
1101 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1102 return -EINVAL;
1103
Shannon Nelson1fa18372013-11-20 10:03:08 +00001104 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1105 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1106 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1107 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1108 netdev_info(netdev,
1109 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1110 ring->tx_pending, ring->rx_pending,
1111 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1112 return -EINVAL;
1113 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001114
Shannon Nelson1fa18372013-11-20 10:03:08 +00001115 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1116 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001117
1118 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001119 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1120 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001121 return 0;
1122
1123 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1124 usleep_range(1000, 2000);
1125
1126 if (!netif_running(vsi->netdev)) {
1127 /* simple case - set for the next time the netdev is started */
1128 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001129 vsi->tx_rings[i]->count = new_tx_count;
1130 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001131 }
1132 goto done;
1133 }
1134
1135 /* We can't just free everything and then setup again,
1136 * because the ISRs in MSI-X mode get passed pointers
1137 * to the Tx and Rx ring structs.
1138 */
1139
1140 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001141 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001142 netdev_info(netdev,
1143 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001144 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001145 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1146 sizeof(struct i40e_ring), GFP_KERNEL);
1147 if (!tx_rings) {
1148 err = -ENOMEM;
1149 goto done;
1150 }
1151
1152 for (i = 0; i < vsi->num_queue_pairs; i++) {
1153 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001154 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001155 tx_rings[i].count = new_tx_count;
1156 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1157 if (err) {
1158 while (i) {
1159 i--;
1160 i40e_free_tx_resources(&tx_rings[i]);
1161 }
1162 kfree(tx_rings);
1163 tx_rings = NULL;
1164
1165 goto done;
1166 }
1167 }
1168 }
1169
1170 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001171 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001172 netdev_info(netdev,
1173 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001174 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001175 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1176 sizeof(struct i40e_ring), GFP_KERNEL);
1177 if (!rx_rings) {
1178 err = -ENOMEM;
1179 goto free_tx;
1180 }
1181
1182 for (i = 0; i < vsi->num_queue_pairs; i++) {
1183 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001184 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001185 rx_rings[i].count = new_rx_count;
1186 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1187 if (err) {
1188 while (i) {
1189 i--;
1190 i40e_free_rx_resources(&rx_rings[i]);
1191 }
1192 kfree(rx_rings);
1193 rx_rings = NULL;
1194
1195 goto free_tx;
1196 }
1197 }
1198 }
1199
1200 /* Bring interface down, copy in the new ring info,
1201 * then restore the interface
1202 */
1203 i40e_down(vsi);
1204
1205 if (tx_rings) {
1206 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001207 i40e_free_tx_resources(vsi->tx_rings[i]);
1208 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001209 }
1210 kfree(tx_rings);
1211 tx_rings = NULL;
1212 }
1213
1214 if (rx_rings) {
1215 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001216 i40e_free_rx_resources(vsi->rx_rings[i]);
1217 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001218 }
1219 kfree(rx_rings);
1220 rx_rings = NULL;
1221 }
1222
1223 i40e_up(vsi);
1224
1225free_tx:
1226 /* error cleanup if the Rx allocations failed after getting Tx */
1227 if (tx_rings) {
1228 for (i = 0; i < vsi->num_queue_pairs; i++)
1229 i40e_free_tx_resources(&tx_rings[i]);
1230 kfree(tx_rings);
1231 tx_rings = NULL;
1232 }
1233
1234done:
1235 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1236
1237 return err;
1238}
1239
1240static int i40e_get_sset_count(struct net_device *netdev, int sset)
1241{
1242 struct i40e_netdev_priv *np = netdev_priv(netdev);
1243 struct i40e_vsi *vsi = np->vsi;
1244 struct i40e_pf *pf = vsi->back;
1245
1246 switch (sset) {
1247 case ETH_SS_TEST:
1248 return I40E_TEST_LEN;
1249 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001250 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001251 int len = I40E_PF_STATS_LEN(netdev);
1252
1253 if (pf->lan_veb != I40E_NO_VEB)
1254 len += I40E_VEB_STATS_LEN;
1255 return len;
1256 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001257 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001258 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001259 case ETH_SS_PRIV_FLAGS:
1260 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001261 default:
1262 return -EOPNOTSUPP;
1263 }
1264}
1265
1266static void i40e_get_ethtool_stats(struct net_device *netdev,
1267 struct ethtool_stats *stats, u64 *data)
1268{
1269 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001270 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001271 struct i40e_vsi *vsi = np->vsi;
1272 struct i40e_pf *pf = vsi->back;
1273 int i = 0;
1274 char *p;
1275 int j;
1276 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001277 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001278
1279 i40e_update_stats(vsi);
1280
1281 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1282 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1283 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1284 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1285 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001286 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1287 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1288 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1289 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1290 }
Vasu Dev38e00432014-08-01 13:27:03 -07001291#ifdef I40E_FCOE
1292 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1293 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1294 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1295 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1296 }
1297#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001298 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001299 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001300 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001301
1302 if (!tx_ring)
1303 continue;
1304
1305 /* process Tx ring statistics */
1306 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001307 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001308 data[i] = tx_ring->stats.packets;
1309 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001310 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001311 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001312
1313 /* Rx ring is the 2nd half of the queue pair */
1314 rx_ring = &tx_ring[1];
1315 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001316 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001317 data[i] = rx_ring->stats.packets;
1318 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001319 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001320 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001321 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001322 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001323 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001324 return;
1325
1326 if (pf->lan_veb != I40E_NO_VEB) {
1327 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1328 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1329 p = (char *)veb;
1330 p += i40e_gstrings_veb_stats[j].stat_offset;
1331 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1332 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001333 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001334 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001335 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1336 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1337 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1338 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1339 }
1340 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1341 data[i++] = pf->stats.priority_xon_tx[j];
1342 data[i++] = pf->stats.priority_xoff_tx[j];
1343 }
1344 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1345 data[i++] = pf->stats.priority_xon_rx[j];
1346 data[i++] = pf->stats.priority_xoff_rx[j];
1347 }
1348 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1349 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350}
1351
1352static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1353 u8 *data)
1354{
1355 struct i40e_netdev_priv *np = netdev_priv(netdev);
1356 struct i40e_vsi *vsi = np->vsi;
1357 struct i40e_pf *pf = vsi->back;
1358 char *p = (char *)data;
1359 int i;
1360
1361 switch (stringset) {
1362 case ETH_SS_TEST:
1363 for (i = 0; i < I40E_TEST_LEN; i++) {
1364 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1365 data += ETH_GSTRING_LEN;
1366 }
1367 break;
1368 case ETH_SS_STATS:
1369 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1370 snprintf(p, ETH_GSTRING_LEN, "%s",
1371 i40e_gstrings_net_stats[i].stat_string);
1372 p += ETH_GSTRING_LEN;
1373 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001374 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1375 snprintf(p, ETH_GSTRING_LEN, "%s",
1376 i40e_gstrings_misc_stats[i].stat_string);
1377 p += ETH_GSTRING_LEN;
1378 }
Vasu Dev38e00432014-08-01 13:27:03 -07001379#ifdef I40E_FCOE
1380 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1381 snprintf(p, ETH_GSTRING_LEN, "%s",
1382 i40e_gstrings_fcoe_stats[i].stat_string);
1383 p += ETH_GSTRING_LEN;
1384 }
1385#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001386 for (i = 0; i < vsi->num_queue_pairs; i++) {
1387 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1388 p += ETH_GSTRING_LEN;
1389 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1390 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001391 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1392 p += ETH_GSTRING_LEN;
1393 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1394 p += ETH_GSTRING_LEN;
1395 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001396 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001397 return;
1398
1399 if (pf->lan_veb != I40E_NO_VEB) {
1400 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1401 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1402 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001403 p += ETH_GSTRING_LEN;
1404 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001405 }
1406 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1407 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1408 i40e_gstrings_stats[i].stat_string);
1409 p += ETH_GSTRING_LEN;
1410 }
1411 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1412 snprintf(p, ETH_GSTRING_LEN,
1413 "port.tx_priority_%u_xon", i);
1414 p += ETH_GSTRING_LEN;
1415 snprintf(p, ETH_GSTRING_LEN,
1416 "port.tx_priority_%u_xoff", i);
1417 p += ETH_GSTRING_LEN;
1418 }
1419 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1420 snprintf(p, ETH_GSTRING_LEN,
1421 "port.rx_priority_%u_xon", i);
1422 p += ETH_GSTRING_LEN;
1423 snprintf(p, ETH_GSTRING_LEN,
1424 "port.rx_priority_%u_xoff", i);
1425 p += ETH_GSTRING_LEN;
1426 }
1427 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1428 snprintf(p, ETH_GSTRING_LEN,
1429 "port.rx_priority_%u_xon_2_xoff", i);
1430 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001431 }
1432 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1433 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001434 case ETH_SS_PRIV_FLAGS:
1435 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1436 memcpy(data, i40e_priv_flags_strings[i],
1437 ETH_GSTRING_LEN);
1438 data += ETH_GSTRING_LEN;
1439 }
1440 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001441 default:
1442 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001443 }
1444}
1445
1446static int i40e_get_ts_info(struct net_device *dev,
1447 struct ethtool_ts_info *info)
1448{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001449 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1450
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001451 /* only report HW timestamping if PTP is enabled */
1452 if (!(pf->flags & I40E_FLAG_PTP))
1453 return ethtool_op_get_ts_info(dev, info);
1454
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001455 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1456 SOF_TIMESTAMPING_RX_SOFTWARE |
1457 SOF_TIMESTAMPING_SOFTWARE |
1458 SOF_TIMESTAMPING_TX_HARDWARE |
1459 SOF_TIMESTAMPING_RX_HARDWARE |
1460 SOF_TIMESTAMPING_RAW_HARDWARE;
1461
1462 if (pf->ptp_clock)
1463 info->phc_index = ptp_clock_index(pf->ptp_clock);
1464 else
1465 info->phc_index = -1;
1466
1467 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1468
1469 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
Jacob Kellerc583cc42015-04-22 14:40:33 -07001470 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1471 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001472
1473 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001474}
1475
Shannon Nelson7b086392013-11-20 10:02:59 +00001476static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477{
Shannon Nelson7b086392013-11-20 10:02:59 +00001478 struct i40e_netdev_priv *np = netdev_priv(netdev);
1479 struct i40e_pf *pf = np->vsi->back;
1480
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001481 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 if (i40e_get_link_status(&pf->hw))
1483 *data = 0;
1484 else
1485 *data = 1;
1486
1487 return *data;
1488}
1489
Shannon Nelson7b086392013-11-20 10:02:59 +00001490static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001491{
Shannon Nelson7b086392013-11-20 10:02:59 +00001492 struct i40e_netdev_priv *np = netdev_priv(netdev);
1493 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001495 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001496 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497
Shannon Nelson7b086392013-11-20 10:02:59 +00001498 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001499}
1500
Shannon Nelson7b086392013-11-20 10:02:59 +00001501static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001502{
Shannon Nelson7b086392013-11-20 10:02:59 +00001503 struct i40e_netdev_priv *np = netdev_priv(netdev);
1504 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001506 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001507 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001508
Shannon Nelson4443ec92014-11-13 08:23:12 +00001509 /* forcebly clear the NVM Update state machine */
1510 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1511
Shannon Nelson7b086392013-11-20 10:02:59 +00001512 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513}
1514
Shannon Nelson7b086392013-11-20 10:02:59 +00001515static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516{
Shannon Nelson7b086392013-11-20 10:02:59 +00001517 struct i40e_netdev_priv *np = netdev_priv(netdev);
1518 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001519 u16 swc_old = pf->sw_int_count;
1520
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001521 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001522 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1523 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001524 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1525 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1526 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1527 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001528 usleep_range(1000, 2000);
1529 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001530
1531 return *data;
1532}
1533
Shannon Nelson7b086392013-11-20 10:02:59 +00001534static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001535{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001536 struct i40e_netdev_priv *np = netdev_priv(netdev);
1537 struct i40e_pf *pf = np->vsi->back;
1538
1539 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001540 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001541
1542 return *data;
1543}
1544
Greg Rosee17bc412015-04-16 20:05:59 -04001545static inline bool i40e_active_vfs(struct i40e_pf *pf)
1546{
1547 struct i40e_vf *vfs = pf->vf;
1548 int i;
1549
1550 for (i = 0; i < pf->num_alloc_vfs; i++)
1551 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1552 return true;
1553 return false;
1554}
1555
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556static void i40e_diag_test(struct net_device *netdev,
1557 struct ethtool_test *eth_test, u64 *data)
1558{
1559 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001560 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001561 struct i40e_pf *pf = np->vsi->back;
1562
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1564 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001565 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566
Shannon Nelsonf551b432013-11-26 10:49:12 +00001567 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001568
1569 if (i40e_active_vfs(pf)) {
1570 dev_warn(&pf->pdev->dev,
1571 "Please take active VFS offline and restart the adapter before running NIC diagnostics\n");
1572 data[I40E_ETH_TEST_REG] = 1;
1573 data[I40E_ETH_TEST_EEPROM] = 1;
1574 data[I40E_ETH_TEST_INTR] = 1;
1575 data[I40E_ETH_TEST_LOOPBACK] = 1;
1576 data[I40E_ETH_TEST_LINK] = 1;
1577 eth_test->flags |= ETH_TEST_FL_FAILED;
1578 clear_bit(__I40E_TESTING, &pf->state);
1579 goto skip_ol_tests;
1580 }
1581
Greg Rose5b86c5c2015-02-26 16:14:35 +00001582 /* If the device is online then take it offline */
1583 if (if_running)
1584 /* indicate we're in test mode */
1585 dev_close(netdev);
1586 else
1587 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001588
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001589 /* Link test performed before hardware reset
1590 * so autoneg doesn't interfere with test result
1591 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001592 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593 eth_test->flags |= ETH_TEST_FL_FAILED;
1594
Shannon Nelson7b086392013-11-20 10:02:59 +00001595 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 eth_test->flags |= ETH_TEST_FL_FAILED;
1597
Shannon Nelson7b086392013-11-20 10:02:59 +00001598 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001599 eth_test->flags |= ETH_TEST_FL_FAILED;
1600
Shannon Nelson7b086392013-11-20 10:02:59 +00001601 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001602 eth_test->flags |= ETH_TEST_FL_FAILED;
1603
Shannon Nelsonf551b432013-11-26 10:49:12 +00001604 /* run reg test last, a reset is required after it */
1605 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1606 eth_test->flags |= ETH_TEST_FL_FAILED;
1607
1608 clear_bit(__I40E_TESTING, &pf->state);
1609 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001610
1611 if (if_running)
1612 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001613 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001615 netif_info(pf, drv, netdev, "online testing starting\n");
1616
Shannon Nelson7b086392013-11-20 10:02:59 +00001617 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001618 eth_test->flags |= ETH_TEST_FL_FAILED;
1619
1620 /* Offline only tests, not run in online; pass by default */
1621 data[I40E_ETH_TEST_REG] = 0;
1622 data[I40E_ETH_TEST_EEPROM] = 0;
1623 data[I40E_ETH_TEST_INTR] = 0;
1624 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001625 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001626
Greg Rosee17bc412015-04-16 20:05:59 -04001627skip_ol_tests:
1628
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001629 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001630}
1631
1632static void i40e_get_wol(struct net_device *netdev,
1633 struct ethtool_wolinfo *wol)
1634{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001635 struct i40e_netdev_priv *np = netdev_priv(netdev);
1636 struct i40e_pf *pf = np->vsi->back;
1637 struct i40e_hw *hw = &pf->hw;
1638 u16 wol_nvm_bits;
1639
1640 /* NVM bit on means WoL disabled for the port */
1641 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001642 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001643 wol->supported = 0;
1644 wol->wolopts = 0;
1645 } else {
1646 wol->supported = WAKE_MAGIC;
1647 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1648 }
1649}
1650
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001651/**
1652 * i40e_set_wol - set the WakeOnLAN configuration
1653 * @netdev: the netdev in question
1654 * @wol: the ethtool WoL setting data
1655 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001656static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1657{
1658 struct i40e_netdev_priv *np = netdev_priv(netdev);
1659 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001660 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001661 struct i40e_hw *hw = &pf->hw;
1662 u16 wol_nvm_bits;
1663
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001664 /* WoL not supported if this isn't the controlling PF on the port */
1665 if (hw->partition_id != 1) {
1666 i40e_partition_setting_complaint(pf);
1667 return -EOPNOTSUPP;
1668 }
1669
1670 if (vsi != pf->vsi[pf->lan_vsi])
1671 return -EOPNOTSUPP;
1672
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001673 /* NVM bit on means WoL disabled for the port */
1674 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1675 if (((1 << hw->port) & wol_nvm_bits))
1676 return -EOPNOTSUPP;
1677
1678 /* only magic packet is supported */
1679 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1680 return -EOPNOTSUPP;
1681
1682 /* is this a new value? */
1683 if (pf->wol_en != !!wol->wolopts) {
1684 pf->wol_en = !!wol->wolopts;
1685 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1686 }
1687
1688 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001689}
1690
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001691static int i40e_set_phys_id(struct net_device *netdev,
1692 enum ethtool_phys_id_state state)
1693{
1694 struct i40e_netdev_priv *np = netdev_priv(netdev);
1695 struct i40e_pf *pf = np->vsi->back;
1696 struct i40e_hw *hw = &pf->hw;
1697 int blink_freq = 2;
1698
1699 switch (state) {
1700 case ETHTOOL_ID_ACTIVE:
1701 pf->led_status = i40e_led_get(hw);
1702 return blink_freq;
1703 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001704 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001705 break;
1706 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001707 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001708 break;
1709 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001710 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001711 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001712 default:
1713 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714 }
1715
1716 return 0;
1717}
1718
1719/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1720 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1721 * 125us (8000 interrupts per second) == ITR(62)
1722 */
1723
1724static int i40e_get_coalesce(struct net_device *netdev,
1725 struct ethtool_coalesce *ec)
1726{
1727 struct i40e_netdev_priv *np = netdev_priv(netdev);
1728 struct i40e_vsi *vsi = np->vsi;
1729
1730 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1731 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1732
1733 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001734 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001735
1736 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001737 ec->use_adaptive_tx_coalesce = 1;
1738
1739 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1740 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741
1742 return 0;
1743}
1744
1745static int i40e_set_coalesce(struct net_device *netdev,
1746 struct ethtool_coalesce *ec)
1747{
1748 struct i40e_netdev_priv *np = netdev_priv(netdev);
1749 struct i40e_q_vector *q_vector;
1750 struct i40e_vsi *vsi = np->vsi;
1751 struct i40e_pf *pf = vsi->back;
1752 struct i40e_hw *hw = &pf->hw;
1753 u16 vector;
1754 int i;
1755
1756 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1757 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1758
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001759 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001760 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001761 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001762 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001763 } else if (ec->rx_coalesce_usecs == 0) {
1764 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001765 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001766 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 +00001767 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001768 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001769 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001770 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001771
Mitch Williams32f5f542014-04-04 04:43:10 +00001772 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001773 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001775 } else if (ec->tx_coalesce_usecs == 0) {
1776 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001777 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001778 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 +00001779 } else {
1780 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001781 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001782 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001783 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001784
1785 if (ec->use_adaptive_rx_coalesce)
1786 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1787 else
1788 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1789
1790 if (ec->use_adaptive_tx_coalesce)
1791 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1792 else
1793 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001794
Alexander Duyck493fb302013-09-28 07:01:44 +00001795 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1796 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1798 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1799 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1800 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1801 i40e_flush(hw);
1802 }
1803
1804 return 0;
1805}
1806
1807/**
1808 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1809 * @pf: pointer to the physical function struct
1810 * @cmd: ethtool rxnfc command
1811 *
1812 * Returns Success if the flow is supported, else Invalid Input.
1813 **/
1814static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1815{
1816 cmd->data = 0;
1817
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001818 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1819 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1820 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1821 return 0;
1822 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 /* Report default options for RSS on i40e */
1824 switch (cmd->flow_type) {
1825 case TCP_V4_FLOW:
1826 case UDP_V4_FLOW:
1827 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1828 /* fall through to add IP fields */
1829 case SCTP_V4_FLOW:
1830 case AH_ESP_V4_FLOW:
1831 case AH_V4_FLOW:
1832 case ESP_V4_FLOW:
1833 case IPV4_FLOW:
1834 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1835 break;
1836 case TCP_V6_FLOW:
1837 case UDP_V6_FLOW:
1838 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1839 /* fall through to add IP fields */
1840 case SCTP_V6_FLOW:
1841 case AH_ESP_V6_FLOW:
1842 case AH_V6_FLOW:
1843 case ESP_V6_FLOW:
1844 case IPV6_FLOW:
1845 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1846 break;
1847 default:
1848 return -EINVAL;
1849 }
1850
1851 return 0;
1852}
1853
1854/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001855 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1856 * @pf: Pointer to the physical function struct
1857 * @cmd: The command to get or set Rx flow classification rules
1858 * @rule_locs: Array of used rule locations
1859 *
1860 * This function populates both the total and actual rule count of
1861 * the ethtool flow classification command
1862 *
1863 * Returns 0 on success or -EMSGSIZE if entry not found
1864 **/
1865static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1866 struct ethtool_rxnfc *cmd,
1867 u32 *rule_locs)
1868{
1869 struct i40e_fdir_filter *rule;
1870 struct hlist_node *node2;
1871 int cnt = 0;
1872
1873 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001874 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001875
1876 hlist_for_each_entry_safe(rule, node2,
1877 &pf->fdir_filter_list, fdir_node) {
1878 if (cnt == cmd->rule_cnt)
1879 return -EMSGSIZE;
1880
1881 rule_locs[cnt] = rule->fd_id;
1882 cnt++;
1883 }
1884
1885 cmd->rule_cnt = cnt;
1886
1887 return 0;
1888}
1889
1890/**
1891 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1892 * @pf: Pointer to the physical function struct
1893 * @cmd: The command to get or set Rx flow classification rules
1894 *
1895 * This function looks up a filter based on the Rx flow classification
1896 * command and fills the flow spec info for it if found
1897 *
1898 * Returns 0 on success or -EINVAL if filter not found
1899 **/
1900static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1901 struct ethtool_rxnfc *cmd)
1902{
1903 struct ethtool_rx_flow_spec *fsp =
1904 (struct ethtool_rx_flow_spec *)&cmd->fs;
1905 struct i40e_fdir_filter *rule = NULL;
1906 struct hlist_node *node2;
1907
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001908 hlist_for_each_entry_safe(rule, node2,
1909 &pf->fdir_filter_list, fdir_node) {
1910 if (fsp->location <= rule->fd_id)
1911 break;
1912 }
1913
1914 if (!rule || fsp->location != rule->fd_id)
1915 return -EINVAL;
1916
1917 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001918 if (fsp->flow_type == IP_USER_FLOW) {
1919 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1920 fsp->h_u.usr_ip4_spec.proto = 0;
1921 fsp->m_u.usr_ip4_spec.proto = 0;
1922 }
1923
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001924 /* Reverse the src and dest notion, since the HW views them from
1925 * Tx perspective where as the user expects it from Rx filter view.
1926 */
1927 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1928 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1929 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1930 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001931
1932 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1933 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1934 else
1935 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001936
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04001937 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1938 struct i40e_vsi *vsi;
1939
1940 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1941 if (vsi && vsi->type == I40E_VSI_SRIOV) {
1942 fsp->h_ext.data[1] = htonl(vsi->vf_id);
1943 fsp->m_ext.data[1] = htonl(0x1);
1944 }
1945 }
1946
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001947 return 0;
1948}
1949
1950/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001951 * i40e_get_rxnfc - command to get RX flow classification rules
1952 * @netdev: network interface device structure
1953 * @cmd: ethtool rxnfc command
1954 *
1955 * Returns Success if the command is supported.
1956 **/
1957static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1958 u32 *rule_locs)
1959{
1960 struct i40e_netdev_priv *np = netdev_priv(netdev);
1961 struct i40e_vsi *vsi = np->vsi;
1962 struct i40e_pf *pf = vsi->back;
1963 int ret = -EOPNOTSUPP;
1964
1965 switch (cmd->cmd) {
1966 case ETHTOOL_GRXRINGS:
1967 cmd->data = vsi->alloc_queue_pairs;
1968 ret = 0;
1969 break;
1970 case ETHTOOL_GRXFH:
1971 ret = i40e_get_rss_hash_opts(pf, cmd);
1972 break;
1973 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001974 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001975 /* report total rule count */
1976 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001977 ret = 0;
1978 break;
1979 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001980 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001981 break;
1982 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001983 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1984 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001985 default:
1986 break;
1987 }
1988
1989 return ret;
1990}
1991
1992/**
1993 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1994 * @pf: pointer to the physical function struct
1995 * @cmd: ethtool rxnfc command
1996 *
1997 * Returns Success if the flow input set is supported.
1998 **/
1999static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2000{
2001 struct i40e_hw *hw = &pf->hw;
2002 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2003 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2004
2005 /* RSS does not support anything other than hashing
2006 * to queues on src and dst IPs and ports
2007 */
2008 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2009 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2010 return -EINVAL;
2011
2012 /* We need at least the IP SRC and DEST fields for hashing */
2013 if (!(nfc->data & RXH_IP_SRC) ||
2014 !(nfc->data & RXH_IP_DST))
2015 return -EINVAL;
2016
2017 switch (nfc->flow_type) {
2018 case TCP_V4_FLOW:
2019 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2020 case 0:
2021 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2022 break;
2023 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2024 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2025 break;
2026 default:
2027 return -EINVAL;
2028 }
2029 break;
2030 case TCP_V6_FLOW:
2031 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2032 case 0:
2033 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2034 break;
2035 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2036 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2037 break;
2038 default:
2039 return -EINVAL;
2040 }
2041 break;
2042 case UDP_V4_FLOW:
2043 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2044 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002045 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2046 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002047 break;
2048 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002049 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2050 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002051 break;
2052 default:
2053 return -EINVAL;
2054 }
2055 break;
2056 case UDP_V6_FLOW:
2057 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2058 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002059 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2060 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002061 break;
2062 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002063 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2064 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002065 break;
2066 default:
2067 return -EINVAL;
2068 }
2069 break;
2070 case AH_ESP_V4_FLOW:
2071 case AH_V4_FLOW:
2072 case ESP_V4_FLOW:
2073 case SCTP_V4_FLOW:
2074 if ((nfc->data & RXH_L4_B_0_1) ||
2075 (nfc->data & RXH_L4_B_2_3))
2076 return -EINVAL;
2077 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2078 break;
2079 case AH_ESP_V6_FLOW:
2080 case AH_V6_FLOW:
2081 case ESP_V6_FLOW:
2082 case SCTP_V6_FLOW:
2083 if ((nfc->data & RXH_L4_B_0_1) ||
2084 (nfc->data & RXH_L4_B_2_3))
2085 return -EINVAL;
2086 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2087 break;
2088 case IPV4_FLOW:
2089 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2090 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2091 break;
2092 case IPV6_FLOW:
2093 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2094 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2095 break;
2096 default:
2097 return -EINVAL;
2098 }
2099
2100 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2101 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2102 i40e_flush(hw);
2103
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002104 /* Save setting for future output/update */
2105 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2106
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002107 return 0;
2108}
2109
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002110/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002111 * i40e_match_fdir_input_set - Match a new filter against an existing one
2112 * @rule: The filter already added
2113 * @input: The new filter to comapre against
2114 *
2115 * Returns true if the two input set match
2116 **/
2117static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2118 struct i40e_fdir_filter *input)
2119{
2120 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2121 (rule->src_ip[0] != input->src_ip[0]) ||
2122 (rule->dst_port != input->dst_port) ||
2123 (rule->src_port != input->src_port))
2124 return false;
2125 return true;
2126}
2127
2128/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002129 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2130 * @vsi: Pointer to the targeted VSI
2131 * @input: The filter to update or NULL to indicate deletion
2132 * @sw_idx: Software index to the filter
2133 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002134 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002135 * This function updates (or deletes) a Flow Director entry from
2136 * the hlist of the corresponding PF
2137 *
2138 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002139 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002140static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2141 struct i40e_fdir_filter *input,
2142 u16 sw_idx,
2143 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002145 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002146 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002147 struct hlist_node *node2;
2148 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002149
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002150 parent = NULL;
2151 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002152
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002153 hlist_for_each_entry_safe(rule, node2,
2154 &pf->fdir_filter_list, fdir_node) {
2155 /* hash found, or no matching entry */
2156 if (rule->fd_id >= sw_idx)
2157 break;
2158 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002159 }
2160
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002161 /* if there is an old rule occupying our place remove it */
2162 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002163 if (input && !i40e_match_fdir_input_set(rule, input))
2164 err = i40e_add_del_fdir(vsi, rule, false);
2165 else if (!input)
2166 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002167 hlist_del(&rule->fdir_node);
2168 kfree(rule);
2169 pf->fdir_pf_active_filters--;
2170 }
2171
2172 /* If no input this was a delete, err should be 0 if a rule was
2173 * successfully found and removed from the list else -EINVAL
2174 */
2175 if (!input)
2176 return err;
2177
2178 /* initialize node and set software index */
2179 INIT_HLIST_NODE(&input->fdir_node);
2180
2181 /* add filter to the list */
2182 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002183 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002184 else
2185 hlist_add_head(&input->fdir_node,
2186 &pf->fdir_filter_list);
2187
2188 /* update counts */
2189 pf->fdir_pf_active_filters++;
2190
2191 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002192}
2193
2194/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002195 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2196 * @vsi: Pointer to the targeted VSI
2197 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002199 * The function removes a Flow Director filter entry from the
2200 * hlist of the corresponding PF
2201 *
2202 * Returns 0 on success
2203 */
2204static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2205 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002206{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002207 struct ethtool_rx_flow_spec *fsp =
2208 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002209 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002210 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002211
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002212 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2213 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2214 return -EBUSY;
2215
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002216 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2217 return -EBUSY;
2218
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002219 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002220
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002221 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002222 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002223}
2224
2225/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002226 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002227 * @vsi: pointer to the targeted VSI
2228 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002230 * Add Flow Director filters for a specific flow spec based on their
2231 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002233static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2234 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002235{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002236 struct ethtool_rx_flow_spec *fsp;
2237 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002238 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002239 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002240 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002241
2242 if (!vsi)
2243 return -EINVAL;
2244
2245 pf = vsi->back;
2246
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002247 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2248 return -EOPNOTSUPP;
2249
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002250 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002251 return -ENOSPC;
2252
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002253 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2254 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2255 return -EBUSY;
2256
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002257 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2258 return -EBUSY;
2259
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002260 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2261
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002262 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2263 pf->hw.func_caps.fd_filters_guaranteed)) {
2264 return -EINVAL;
2265 }
2266
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002267 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2268 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002269 return -EINVAL;
2270
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002271 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002272
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002273 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002274 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002275
2276 input->fd_id = fsp->location;
2277
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002278 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2279 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2280 else
2281 input->dest_ctl =
2282 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2283
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002284 input->q_index = fsp->ring_cookie;
2285 input->flex_off = 0;
2286 input->pctype = 0;
2287 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002288 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002289 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002290 input->flow_type = fsp->flow_type;
2291 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002292
2293 /* Reverse the src and dest notion, since the HW expects them to be from
2294 * Tx perspective where as the input from user is from Rx filter view.
2295 */
2296 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2297 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2298 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2299 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002300
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002301 if (ntohl(fsp->m_ext.data[1])) {
2302 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2303 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2304 goto free_input;
2305 }
2306 vf_id = ntohl(fsp->h_ext.data[1]);
2307 /* Find vsi id from vf id and override dest vsi */
2308 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2309 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2310 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2311 goto free_input;
2312 }
2313 }
2314
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002315 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002316free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002317 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002318 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002319 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002320 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002321
2322 return ret;
2323}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002324
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002325/**
2326 * i40e_set_rxnfc - command to set RX flow classification rules
2327 * @netdev: network interface device structure
2328 * @cmd: ethtool rxnfc command
2329 *
2330 * Returns Success if the command is supported.
2331 **/
2332static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2333{
2334 struct i40e_netdev_priv *np = netdev_priv(netdev);
2335 struct i40e_vsi *vsi = np->vsi;
2336 struct i40e_pf *pf = vsi->back;
2337 int ret = -EOPNOTSUPP;
2338
2339 switch (cmd->cmd) {
2340 case ETHTOOL_SRXFH:
2341 ret = i40e_set_rss_hash_opt(pf, cmd);
2342 break;
2343 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002344 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002345 break;
2346 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002347 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002348 break;
2349 default:
2350 break;
2351 }
2352
2353 return ret;
2354}
2355
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002356/**
2357 * i40e_max_channels - get Max number of combined channels supported
2358 * @vsi: vsi pointer
2359 **/
2360static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2361{
2362 /* TODO: This code assumes DCB and FD is disabled for now. */
2363 return vsi->alloc_queue_pairs;
2364}
2365
2366/**
2367 * i40e_get_channels - Get the current channels enabled and max supported etc.
2368 * @netdev: network interface device structure
2369 * @ch: ethtool channels structure
2370 *
2371 * We don't support separate tx and rx queues as channels. The other count
2372 * represents how many queues are being used for control. max_combined counts
2373 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2374 * q_vectors since we support a lot more queue pairs than q_vectors.
2375 **/
2376static void i40e_get_channels(struct net_device *dev,
2377 struct ethtool_channels *ch)
2378{
2379 struct i40e_netdev_priv *np = netdev_priv(dev);
2380 struct i40e_vsi *vsi = np->vsi;
2381 struct i40e_pf *pf = vsi->back;
2382
2383 /* report maximum channels */
2384 ch->max_combined = i40e_max_channels(vsi);
2385
2386 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002387 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002388 ch->max_other = ch->other_count;
2389
2390 /* Note: This code assumes DCB is disabled for now. */
2391 ch->combined_count = vsi->num_queue_pairs;
2392}
2393
2394/**
2395 * i40e_set_channels - Set the new channels count.
2396 * @netdev: network interface device structure
2397 * @ch: ethtool channels structure
2398 *
2399 * The new channels count may not be the same as requested by the user
2400 * since it gets rounded down to a power of 2 value.
2401 **/
2402static int i40e_set_channels(struct net_device *dev,
2403 struct ethtool_channels *ch)
2404{
2405 struct i40e_netdev_priv *np = netdev_priv(dev);
2406 unsigned int count = ch->combined_count;
2407 struct i40e_vsi *vsi = np->vsi;
2408 struct i40e_pf *pf = vsi->back;
2409 int new_count;
2410
2411 /* We do not support setting channels for any other VSI at present */
2412 if (vsi->type != I40E_VSI_MAIN)
2413 return -EINVAL;
2414
2415 /* verify they are not requesting separate vectors */
2416 if (!count || ch->rx_count || ch->tx_count)
2417 return -EINVAL;
2418
2419 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002420 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002421 return -EINVAL;
2422
2423 /* verify the number of channels does not exceed hardware limits */
2424 if (count > i40e_max_channels(vsi))
2425 return -EINVAL;
2426
2427 /* update feature limits from largest to smallest supported values */
2428 /* TODO: Flow director limit, DCB etc */
2429
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002430 /* use rss_reconfig to rebuild with new queue count and update traffic
2431 * class queue mapping
2432 */
2433 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002434 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002435 return 0;
2436 else
2437 return -EINVAL;
2438}
2439
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002440#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2441/**
2442 * i40e_get_rxfh_key_size - get the RSS hash key size
2443 * @netdev: network interface device structure
2444 *
2445 * Returns the table size.
2446 **/
2447static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2448{
2449 return I40E_HKEY_ARRAY_SIZE;
2450}
2451
2452/**
2453 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2454 * @netdev: network interface device structure
2455 *
2456 * Returns the table size.
2457 **/
2458static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2459{
2460 return I40E_HLUT_ARRAY_SIZE;
2461}
2462
2463static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2464 u8 *hfunc)
2465{
2466 struct i40e_netdev_priv *np = netdev_priv(netdev);
2467 struct i40e_vsi *vsi = np->vsi;
2468 struct i40e_pf *pf = vsi->back;
2469 struct i40e_hw *hw = &pf->hw;
2470 u32 reg_val;
2471 int i, j;
2472
2473 if (hfunc)
2474 *hfunc = ETH_RSS_HASH_TOP;
2475
2476 if (!indir)
2477 return 0;
2478
2479 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2480 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2481 indir[j++] = reg_val & 0xff;
2482 indir[j++] = (reg_val >> 8) & 0xff;
2483 indir[j++] = (reg_val >> 16) & 0xff;
2484 indir[j++] = (reg_val >> 24) & 0xff;
2485 }
2486
2487 if (key) {
2488 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2489 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2490 key[j++] = (u8)(reg_val & 0xff);
2491 key[j++] = (u8)((reg_val >> 8) & 0xff);
2492 key[j++] = (u8)((reg_val >> 16) & 0xff);
2493 key[j++] = (u8)((reg_val >> 24) & 0xff);
2494 }
2495 }
2496 return 0;
2497}
2498
2499/**
2500 * i40e_set_rxfh - set the rx flow hash indirection table
2501 * @netdev: network interface device structure
2502 * @indir: indirection table
2503 * @key: hash key
2504 *
2505 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
2506 * returns 0 after programming the table.
2507 **/
2508static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2509 const u8 *key, const u8 hfunc)
2510{
2511 struct i40e_netdev_priv *np = netdev_priv(netdev);
2512 struct i40e_vsi *vsi = np->vsi;
2513 struct i40e_pf *pf = vsi->back;
2514 struct i40e_hw *hw = &pf->hw;
2515 u32 reg_val;
2516 int i, j;
2517
2518 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2519 return -EOPNOTSUPP;
2520
2521 if (!indir)
2522 return 0;
2523
2524 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2525 reg_val = indir[j++];
2526 reg_val |= indir[j++] << 8;
2527 reg_val |= indir[j++] << 16;
2528 reg_val |= indir[j++] << 24;
2529 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2530 }
2531
2532 if (key) {
2533 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2534 reg_val = key[j++];
2535 reg_val |= key[j++] << 8;
2536 reg_val |= key[j++] << 16;
2537 reg_val |= key[j++] << 24;
2538 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2539 }
2540 }
2541 return 0;
2542}
2543
Greg Rose7e45ab42015-02-06 08:52:19 +00002544/**
2545 * i40e_get_priv_flags - report device private flags
2546 * @dev: network interface device structure
2547 *
2548 * The get string set count and the string set should be matched for each
2549 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2550 * array.
2551 *
2552 * Returns a u32 bitmap of flags.
2553 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002554static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002555{
2556 struct i40e_netdev_priv *np = netdev_priv(dev);
2557 struct i40e_vsi *vsi = np->vsi;
2558 struct i40e_pf *pf = vsi->back;
2559 u32 ret_flags = 0;
2560
2561 ret_flags |= pf->hw.func_caps.npar_enable ?
2562 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2563
2564 return ret_flags;
2565}
2566
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002567static const struct ethtool_ops i40e_ethtool_ops = {
2568 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002569 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002570 .get_drvinfo = i40e_get_drvinfo,
2571 .get_regs_len = i40e_get_regs_len,
2572 .get_regs = i40e_get_regs,
2573 .nway_reset = i40e_nway_reset,
2574 .get_link = ethtool_op_get_link,
2575 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002576 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002577 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002578 .get_eeprom_len = i40e_get_eeprom_len,
2579 .get_eeprom = i40e_get_eeprom,
2580 .get_ringparam = i40e_get_ringparam,
2581 .set_ringparam = i40e_set_ringparam,
2582 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002583 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002584 .get_msglevel = i40e_get_msglevel,
2585 .set_msglevel = i40e_set_msglevel,
2586 .get_rxnfc = i40e_get_rxnfc,
2587 .set_rxnfc = i40e_set_rxnfc,
2588 .self_test = i40e_diag_test,
2589 .get_strings = i40e_get_strings,
2590 .set_phys_id = i40e_set_phys_id,
2591 .get_sset_count = i40e_get_sset_count,
2592 .get_ethtool_stats = i40e_get_ethtool_stats,
2593 .get_coalesce = i40e_get_coalesce,
2594 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002595 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2596 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2597 .get_rxfh = i40e_get_rxfh,
2598 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002599 .get_channels = i40e_get_channels,
2600 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002601 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002602 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002603};
2604
2605void i40e_set_ethtool_ops(struct net_device *netdev)
2606{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002607 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002608}