blob: 928bd5abbaedcb72739914cc412a1df7eee00a90 [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),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400117 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000118 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))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400200#define I40E_VEB_TC_STATS_LEN ( \
201 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
205 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000206#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400207#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000208#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
209 I40E_PFC_STATS_LEN + \
210 I40E_VSI_STATS_LEN((n)))
211
212enum i40e_ethtool_test_id {
213 I40E_ETH_TEST_REG = 0,
214 I40E_ETH_TEST_EEPROM,
215 I40E_ETH_TEST_INTR,
216 I40E_ETH_TEST_LOOPBACK,
217 I40E_ETH_TEST_LINK,
218};
219
220static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
221 "Register test (offline)",
222 "Eeprom test (offline)",
223 "Interrupt test (offline)",
224 "Loopback test (offline)",
225 "Link test (on/offline)"
226};
227
228#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
229
Greg Rose7e45ab42015-02-06 08:52:19 +0000230static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
231 "NPAR",
232};
233
234#define I40E_PRIV_FLAGS_STR_LEN \
235 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
236
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000237/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000238 * i40e_partition_setting_complaint - generic complaint for MFP restriction
239 * @pf: the PF struct
240 **/
241static void i40e_partition_setting_complaint(struct i40e_pf *pf)
242{
243 dev_info(&pf->pdev->dev,
244 "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");
245}
246
247/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000248 * i40e_get_settings_link_up - Get the Link settings for when link is up
249 * @hw: hw structure
250 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000254static void i40e_get_settings_link_up(struct i40e_hw *hw,
255 struct ethtool_cmd *ecmd,
256 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000257{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 u32 link_speed = hw_link_info->link_speed;
260
Catherine Sullivane8278452015-02-06 08:52:08 +0000261 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 switch (hw_link_info->phy_type) {
263 case I40E_PHY_TYPE_40GBASE_CR4:
264 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000265 ecmd->supported = SUPPORTED_Autoneg |
266 SUPPORTED_40000baseCR4_Full;
267 ecmd->advertising = ADVERTISED_Autoneg |
268 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000269 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000270 case I40E_PHY_TYPE_XLAUI:
271 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000272 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000273 ecmd->supported = SUPPORTED_40000baseCR4_Full;
274 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000275 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000276 ecmd->supported = SUPPORTED_Autoneg |
277 SUPPORTED_40000baseKR4_Full;
278 ecmd->advertising = ADVERTISED_Autoneg |
279 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 break;
281 case I40E_PHY_TYPE_40GBASE_SR4:
282 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 break;
284 case I40E_PHY_TYPE_40GBASE_LR4:
285 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000286 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700287 case I40E_PHY_TYPE_20GBASE_KR2:
288 ecmd->supported = SUPPORTED_Autoneg |
289 SUPPORTED_20000baseKR2_Full;
290 ecmd->advertising = ADVERTISED_Autoneg |
291 ADVERTISED_20000baseKR2_Full;
292 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000293 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000294 ecmd->supported = SUPPORTED_Autoneg |
295 SUPPORTED_10000baseKX4_Full;
296 ecmd->advertising = ADVERTISED_Autoneg |
297 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000298 break;
299 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000300 ecmd->supported = SUPPORTED_Autoneg |
301 SUPPORTED_10000baseKR_Full;
302 ecmd->advertising = ADVERTISED_Autoneg |
303 ADVERTISED_10000baseKR_Full;
304 break;
305 case I40E_PHY_TYPE_10GBASE_SR:
306 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000307 case I40E_PHY_TYPE_1000BASE_SX:
308 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000309 ecmd->supported = SUPPORTED_10000baseT_Full |
310 SUPPORTED_1000baseT_Full;
311 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
312 ecmd->advertising |= ADVERTISED_10000baseT_Full;
313 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
314 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000315 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000316 case I40E_PHY_TYPE_1000BASE_KX:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_1000baseKX_Full;
319 ecmd->advertising = ADVERTISED_Autoneg |
320 ADVERTISED_1000baseKX_Full;
321 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000322 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000323 case I40E_PHY_TYPE_1000BASE_T:
324 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000325 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000326 SUPPORTED_10000baseT_Full |
327 SUPPORTED_1000baseT_Full |
328 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000329 ecmd->advertising = ADVERTISED_Autoneg;
330 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
331 ecmd->advertising |= ADVERTISED_10000baseT_Full;
332 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
333 ecmd->advertising |= ADVERTISED_1000baseT_Full;
334 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
335 ecmd->advertising |= ADVERTISED_100baseT_Full;
336 break;
337 case I40E_PHY_TYPE_10GBASE_CR1_CU:
338 case I40E_PHY_TYPE_10GBASE_CR1:
339 ecmd->supported = SUPPORTED_Autoneg |
340 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000341 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000342 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000343 break;
344 case I40E_PHY_TYPE_XAUI:
345 case I40E_PHY_TYPE_XFI:
346 case I40E_PHY_TYPE_SFI:
347 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000348 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000349 ecmd->supported = SUPPORTED_10000baseT_Full;
350 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000351 case I40E_PHY_TYPE_SGMII:
352 ecmd->supported = SUPPORTED_Autoneg |
353 SUPPORTED_1000baseT_Full |
354 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000355 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
356 ecmd->advertising |= ADVERTISED_1000baseT_Full;
357 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
358 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000359 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000360 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000361 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000362 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
363 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000364 }
365
Catherine Sullivane8278452015-02-06 08:52:08 +0000366 /* Set speed and duplex */
367 switch (link_speed) {
368 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400369 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000370 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700371 case I40E_LINK_SPEED_20GB:
372 ethtool_cmd_speed_set(ecmd, SPEED_20000);
373 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000374 case I40E_LINK_SPEED_10GB:
375 ethtool_cmd_speed_set(ecmd, SPEED_10000);
376 break;
377 case I40E_LINK_SPEED_1GB:
378 ethtool_cmd_speed_set(ecmd, SPEED_1000);
379 break;
380 case I40E_LINK_SPEED_100MB:
381 ethtool_cmd_speed_set(ecmd, SPEED_100);
382 break;
383 default:
384 break;
385 }
386 ecmd->duplex = DUPLEX_FULL;
387}
388
389/**
390 * i40e_get_settings_link_down - Get the Link settings for when link is down
391 * @hw: hw structure
392 * @ecmd: ethtool command to fill in
393 *
394 * Reports link settings that can be determined when link is down
395 **/
396static void i40e_get_settings_link_down(struct i40e_hw *hw,
397 struct ethtool_cmd *ecmd)
398{
399 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
400
401 /* link is down and the driver needs to fall back on
402 * device ID to determine what kinds of info to display,
403 * it's mostly a guess that may change when link is up
404 */
405 switch (hw->device_id) {
406 case I40E_DEV_ID_QSFP_A:
407 case I40E_DEV_ID_QSFP_B:
408 case I40E_DEV_ID_QSFP_C:
409 /* pluggable QSFP */
410 ecmd->supported = SUPPORTED_40000baseSR4_Full |
411 SUPPORTED_40000baseCR4_Full |
412 SUPPORTED_40000baseLR4_Full;
413 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
414 ADVERTISED_40000baseCR4_Full |
415 ADVERTISED_40000baseLR4_Full;
416 break;
417 case I40E_DEV_ID_KX_B:
418 /* backplane 40G */
419 ecmd->supported = SUPPORTED_40000baseKR4_Full;
420 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
421 break;
422 case I40E_DEV_ID_KX_C:
423 /* backplane 10G */
424 ecmd->supported = SUPPORTED_10000baseKR_Full;
425 ecmd->advertising = ADVERTISED_10000baseKR_Full;
426 break;
427 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -0400428 case I40E_DEV_ID_10G_BASE_T4:
Catherine Sullivane8278452015-02-06 08:52:08 +0000429 ecmd->supported = SUPPORTED_10000baseT_Full |
430 SUPPORTED_1000baseT_Full |
431 SUPPORTED_100baseT_Full;
432 /* Figure out what has been requested */
433 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
434 ecmd->advertising |= ADVERTISED_10000baseT_Full;
435 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
436 ecmd->advertising |= ADVERTISED_1000baseT_Full;
437 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
438 ecmd->advertising |= ADVERTISED_100baseT_Full;
439 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700440 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -0400441 case I40E_DEV_ID_20G_KR2_A:
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700442 /* backplane 20G */
443 ecmd->supported = SUPPORTED_20000baseKR2_Full;
444 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
445 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000446 default:
447 /* all the rest are 10G/1G */
448 ecmd->supported = SUPPORTED_10000baseT_Full |
449 SUPPORTED_1000baseT_Full;
450 /* Figure out what has been requested */
451 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
452 ecmd->advertising |= ADVERTISED_10000baseT_Full;
453 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
454 ecmd->advertising |= ADVERTISED_1000baseT_Full;
455 break;
456 }
457
458 /* With no link speed and duplex are unknown */
459 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
460 ecmd->duplex = DUPLEX_UNKNOWN;
461}
462
463/**
464 * i40e_get_settings - Get Link Speed and Duplex settings
465 * @netdev: network interface device structure
466 * @ecmd: ethtool command
467 *
468 * Reports speed/duplex settings based on media_type
469 **/
470static int i40e_get_settings(struct net_device *netdev,
471 struct ethtool_cmd *ecmd)
472{
473 struct i40e_netdev_priv *np = netdev_priv(netdev);
474 struct i40e_pf *pf = np->vsi->back;
475 struct i40e_hw *hw = &pf->hw;
476 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
477 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
478
479 if (link_up)
480 i40e_get_settings_link_up(hw, ecmd, netdev);
481 else
482 i40e_get_settings_link_down(hw, ecmd);
483
484 /* Now set the settings that don't rely on link being up/down */
485
486 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000487 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
488 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000489
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000490 switch (hw->phy.media_type) {
491 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000492 ecmd->supported |= SUPPORTED_Autoneg |
493 SUPPORTED_Backplane;
494 ecmd->advertising |= ADVERTISED_Autoneg |
495 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000496 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000497 break;
498 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000499 ecmd->supported |= SUPPORTED_TP;
500 ecmd->advertising |= ADVERTISED_TP;
501 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000502 break;
503 case I40E_MEDIA_TYPE_DA:
504 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000505 ecmd->supported |= SUPPORTED_FIBRE;
506 ecmd->advertising |= ADVERTISED_FIBRE;
507 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000508 break;
509 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000510 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000511 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000512 break;
513 case I40E_MEDIA_TYPE_UNKNOWN:
514 default:
515 ecmd->port = PORT_OTHER;
516 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000517 }
518
Catherine Sullivane8278452015-02-06 08:52:08 +0000519 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000520 ecmd->transceiver = XCVR_EXTERNAL;
521
Catherine Sullivane8278452015-02-06 08:52:08 +0000522 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000523 ecmd->supported |= SUPPORTED_Pause;
524
Catherine Sullivane8278452015-02-06 08:52:08 +0000525 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000526 case I40E_FC_FULL:
527 ecmd->advertising |= ADVERTISED_Pause;
528 break;
529 case I40E_FC_TX_PAUSE:
530 ecmd->advertising |= ADVERTISED_Asym_Pause;
531 break;
532 case I40E_FC_RX_PAUSE:
533 ecmd->advertising |= (ADVERTISED_Pause |
534 ADVERTISED_Asym_Pause);
535 break;
536 default:
537 ecmd->advertising &= ~(ADVERTISED_Pause |
538 ADVERTISED_Asym_Pause);
539 break;
540 }
541
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000542 return 0;
543}
544
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000545/**
546 * i40e_set_settings - Set Speed and Duplex
547 * @netdev: network interface device structure
548 * @ecmd: ethtool command
549 *
550 * Set speed/duplex per media_types advertised/forced
551 **/
552static int i40e_set_settings(struct net_device *netdev,
553 struct ethtool_cmd *ecmd)
554{
555 struct i40e_netdev_priv *np = netdev_priv(netdev);
556 struct i40e_aq_get_phy_abilities_resp abilities;
557 struct i40e_aq_set_phy_config config;
558 struct i40e_pf *pf = np->vsi->back;
559 struct i40e_vsi *vsi = np->vsi;
560 struct i40e_hw *hw = &pf->hw;
561 struct ethtool_cmd safe_ecmd;
562 i40e_status status = 0;
563 bool change = false;
564 int err = 0;
565 u8 autoneg;
566 u32 advertise;
567
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000568 /* Changing port settings is not supported if this isn't the
569 * port's controlling PF
570 */
571 if (hw->partition_id != 1) {
572 i40e_partition_setting_complaint(pf);
573 return -EOPNOTSUPP;
574 }
575
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000576 if (vsi != pf->vsi[pf->lan_vsi])
577 return -EOPNOTSUPP;
578
579 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
580 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000581 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
582 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000583 return -EOPNOTSUPP;
584
585 /* get our own copy of the bits to check against */
586 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
587 i40e_get_settings(netdev, &safe_ecmd);
588
589 /* save autoneg and speed out of ecmd */
590 autoneg = ecmd->autoneg;
591 advertise = ecmd->advertising;
592
593 /* set autoneg and speed back to what they currently are */
594 ecmd->autoneg = safe_ecmd.autoneg;
595 ecmd->advertising = safe_ecmd.advertising;
596
597 ecmd->cmd = safe_ecmd.cmd;
598 /* If ecmd and safe_ecmd are not the same now, then they are
599 * trying to set something that we do not support
600 */
601 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
602 return -EOPNOTSUPP;
603
604 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
605 usleep_range(1000, 2000);
606
607 /* Get the current phy config */
608 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
609 NULL);
610 if (status)
611 return -EAGAIN;
612
Catherine Sullivan124ed152014-07-12 07:28:12 +0000613 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000614 * set below
615 */
616 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000617 config.abilities = abilities.abilities;
618
619 /* Check autoneg */
620 if (autoneg == AUTONEG_ENABLE) {
621 /* If autoneg is not supported, return error */
622 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
623 netdev_info(netdev, "Autoneg not supported on this phy\n");
624 return -EINVAL;
625 }
626 /* If autoneg was not already enabled */
627 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
628 config.abilities = abilities.abilities |
629 I40E_AQ_PHY_ENABLE_AN;
630 change = true;
631 }
632 } else {
633 /* If autoneg is supported 10GBASE_T is the only phy that
634 * can disable it, so otherwise return error
635 */
636 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
637 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
638 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
639 return -EINVAL;
640 }
641 /* If autoneg is currently enabled */
642 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000643 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000644 ~I40E_AQ_PHY_ENABLE_AN;
645 change = true;
646 }
647 }
648
649 if (advertise & ~safe_ecmd.supported)
650 return -EINVAL;
651
652 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000653 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000654 if (advertise & ADVERTISED_1000baseT_Full ||
655 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000656 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000657 if (advertise & ADVERTISED_10000baseT_Full ||
658 advertise & ADVERTISED_10000baseKX4_Full ||
659 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000660 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700661 if (advertise & ADVERTISED_20000baseKR2_Full)
662 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000663 if (advertise & ADVERTISED_40000baseKR4_Full ||
664 advertise & ADVERTISED_40000baseCR4_Full ||
665 advertise & ADVERTISED_40000baseSR4_Full ||
666 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000667 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000668
Catherine Sullivan124ed152014-07-12 07:28:12 +0000669 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000670 /* copy over the rest of the abilities */
671 config.phy_type = abilities.phy_type;
672 config.eee_capability = abilities.eee_capability;
673 config.eeer = abilities.eeer_val;
674 config.low_power_ctrl = abilities.d3_lpan;
675
Catherine Sullivane8278452015-02-06 08:52:08 +0000676 /* save the requested speeds */
677 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000678 /* set link and auto negotiation so changes take effect */
679 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
680 /* If link is up put link down */
681 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
682 /* Tell the OS link is going down, the link will go
683 * back up when fw says it is ready asynchronously
684 */
685 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
686 netif_carrier_off(netdev);
687 netif_tx_stop_all_queues(netdev);
688 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000689
690 /* make the aq call */
691 status = i40e_aq_set_phy_config(hw, &config, NULL);
692 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400693 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
694 i40e_stat_str(hw, status),
695 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000696 return -EAGAIN;
697 }
698
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000699 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000700 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400701 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
702 i40e_stat_str(hw, status),
703 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000704
705 } else {
706 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
707 }
708
709 return err;
710}
711
Jesse Brandeburga6599722014-06-04 08:45:25 +0000712static int i40e_nway_reset(struct net_device *netdev)
713{
714 /* restart autonegotiation */
715 struct i40e_netdev_priv *np = netdev_priv(netdev);
716 struct i40e_pf *pf = np->vsi->back;
717 struct i40e_hw *hw = &pf->hw;
718 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
719 i40e_status ret = 0;
720
721 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
722 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400723 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
724 i40e_stat_str(hw, ret),
725 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000726 return -EIO;
727 }
728
729 return 0;
730}
731
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000732/**
733 * i40e_get_pauseparam - Get Flow Control status
734 * Return tx/rx-pause status
735 **/
736static void i40e_get_pauseparam(struct net_device *netdev,
737 struct ethtool_pauseparam *pause)
738{
739 struct i40e_netdev_priv *np = netdev_priv(netdev);
740 struct i40e_pf *pf = np->vsi->back;
741 struct i40e_hw *hw = &pf->hw;
742 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000743 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000744
745 pause->autoneg =
746 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
747 AUTONEG_ENABLE : AUTONEG_DISABLE);
748
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000749 /* PFC enabled so report LFC as off */
750 if (dcbx_cfg->pfc.pfcenable) {
751 pause->rx_pause = 0;
752 pause->tx_pause = 0;
753 return;
754 }
755
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000756 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000757 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000758 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000759 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000760 } else if (hw->fc.current_mode == I40E_FC_FULL) {
761 pause->rx_pause = 1;
762 pause->tx_pause = 1;
763 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000764}
765
Catherine Sullivan2becc352014-06-04 08:45:27 +0000766/**
767 * i40e_set_pauseparam - Set Flow Control parameter
768 * @netdev: network interface device structure
769 * @pause: return tx/rx flow control status
770 **/
771static int i40e_set_pauseparam(struct net_device *netdev,
772 struct ethtool_pauseparam *pause)
773{
774 struct i40e_netdev_priv *np = netdev_priv(netdev);
775 struct i40e_pf *pf = np->vsi->back;
776 struct i40e_vsi *vsi = np->vsi;
777 struct i40e_hw *hw = &pf->hw;
778 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000779 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000780 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
781 i40e_status status;
782 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000783 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000784
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000785 /* Changing the port's flow control is not supported if this isn't the
786 * port's controlling PF
787 */
788 if (hw->partition_id != 1) {
789 i40e_partition_setting_complaint(pf);
790 return -EOPNOTSUPP;
791 }
792
Catherine Sullivan2becc352014-06-04 08:45:27 +0000793 if (vsi != pf->vsi[pf->lan_vsi])
794 return -EOPNOTSUPP;
795
796 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
797 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
798 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
799 return -EOPNOTSUPP;
800 }
801
802 /* If we have link and don't have autoneg */
803 if (!test_bit(__I40E_DOWN, &pf->state) &&
804 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
805 /* Send message that it might not necessarily work*/
806 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
807 }
808
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000809 if (dcbx_cfg->pfc.pfcenable) {
810 netdev_info(netdev,
811 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000812 return -EOPNOTSUPP;
813 }
814
815 if (pause->rx_pause && pause->tx_pause)
816 hw->fc.requested_mode = I40E_FC_FULL;
817 else if (pause->rx_pause && !pause->tx_pause)
818 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
819 else if (!pause->rx_pause && pause->tx_pause)
820 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
821 else if (!pause->rx_pause && !pause->tx_pause)
822 hw->fc.requested_mode = I40E_FC_NONE;
823 else
824 return -EINVAL;
825
Catherine Sullivan94128512014-07-12 07:28:16 +0000826 /* Tell the OS link is going down, the link will go back up when fw
827 * says it is ready asynchronously
828 */
829 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
830 netif_carrier_off(netdev);
831 netif_tx_stop_all_queues(netdev);
832
Catherine Sullivan2becc352014-06-04 08:45:27 +0000833 /* Set the fc mode and only restart an if link is up*/
834 status = i40e_set_fc(hw, &aq_failures, link_up);
835
836 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400837 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
838 i40e_stat_str(hw, status),
839 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000840 err = -EAGAIN;
841 }
842 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400843 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
844 i40e_stat_str(hw, status),
845 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000846 err = -EAGAIN;
847 }
848 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400849 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
850 i40e_stat_str(hw, status),
851 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000852 err = -EAGAIN;
853 }
854
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000855 if (!test_bit(__I40E_DOWN, &pf->state)) {
856 /* Give it a little more time to try to come back */
857 msleep(75);
858 if (!test_bit(__I40E_DOWN, &pf->state))
859 return i40e_nway_reset(netdev);
860 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000861
862 return err;
863}
864
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000865static u32 i40e_get_msglevel(struct net_device *netdev)
866{
867 struct i40e_netdev_priv *np = netdev_priv(netdev);
868 struct i40e_pf *pf = np->vsi->back;
869
870 return pf->msg_enable;
871}
872
873static void i40e_set_msglevel(struct net_device *netdev, u32 data)
874{
875 struct i40e_netdev_priv *np = netdev_priv(netdev);
876 struct i40e_pf *pf = np->vsi->back;
877
878 if (I40E_DEBUG_USER & data)
879 pf->hw.debug_mask = data;
880 pf->msg_enable = data;
881}
882
883static int i40e_get_regs_len(struct net_device *netdev)
884{
885 int reg_count = 0;
886 int i;
887
888 for (i = 0; i40e_reg_list[i].offset != 0; i++)
889 reg_count += i40e_reg_list[i].elements;
890
891 return reg_count * sizeof(u32);
892}
893
894static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
895 void *p)
896{
897 struct i40e_netdev_priv *np = netdev_priv(netdev);
898 struct i40e_pf *pf = np->vsi->back;
899 struct i40e_hw *hw = &pf->hw;
900 u32 *reg_buf = p;
901 int i, j, ri;
902 u32 reg;
903
904 /* Tell ethtool which driver-version-specific regs output we have.
905 *
906 * At some point, if we have ethtool doing special formatting of
907 * this data, it will rely on this version number to know how to
908 * interpret things. Hence, this needs to be updated if/when the
909 * diags register table is changed.
910 */
911 regs->version = 1;
912
913 /* loop through the diags reg table for what to print */
914 ri = 0;
915 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
916 for (j = 0; j < i40e_reg_list[i].elements; j++) {
917 reg = i40e_reg_list[i].offset
918 + (j * i40e_reg_list[i].stride);
919 reg_buf[ri++] = rd32(hw, reg);
920 }
921 }
922
923}
924
925static int i40e_get_eeprom(struct net_device *netdev,
926 struct ethtool_eeprom *eeprom, u8 *bytes)
927{
928 struct i40e_netdev_priv *np = netdev_priv(netdev);
929 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000930 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000931 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000932 u8 *eeprom_buff;
933 u16 i, sectors;
934 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000935 u32 magic;
936
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000937#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000938 if (eeprom->len == 0)
939 return -EINVAL;
940
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000941 /* check for NVMUpdate access method */
942 magic = hw->vendor_id | (hw->device_id << 16);
943 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000944 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000945 int errno;
946
947 /* make sure it is the right magic for NVMUpdate */
948 if ((eeprom->magic >> 16) != hw->device_id)
949 return -EINVAL;
950
Shannon Nelsonc150a502014-11-13 08:23:13 +0000951 cmd = (struct i40e_nvm_access *)eeprom;
952 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000953 if (ret_val &&
954 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
955 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000956 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000957 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
958 ret_val, hw->aq.asq_last_status, errno,
959 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
960 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000961
962 return errno;
963 }
964
965 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000966 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
967
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000968 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000969 if (!eeprom_buff)
970 return -ENOMEM;
971
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000972 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
973 if (ret_val) {
974 dev_info(&pf->pdev->dev,
975 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
976 ret_val, hw->aq.asq_last_status);
977 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000978 }
979
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000980 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
981 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
982 len = I40E_NVM_SECTOR_SIZE;
983 last = false;
984 for (i = 0; i < sectors; i++) {
985 if (i == (sectors - 1)) {
986 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
987 last = true;
988 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000989 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
990 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000991 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000992 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000993 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000994 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000995 "read NVM failed, invalid offset 0x%x\n",
996 offset);
997 break;
998 } else if (ret_val &&
999 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1000 dev_info(&pf->pdev->dev,
1001 "read NVM failed, access, offset 0x%x\n",
1002 offset);
1003 break;
1004 } else if (ret_val) {
1005 dev_info(&pf->pdev->dev,
1006 "read NVM failed offset %d err=%d status=0x%x\n",
1007 offset, ret_val, hw->aq.asq_last_status);
1008 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001009 }
1010 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001011
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001012 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001013 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001014free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001015 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001016 return ret_val;
1017}
1018
1019static int i40e_get_eeprom_len(struct net_device *netdev)
1020{
1021 struct i40e_netdev_priv *np = netdev_priv(netdev);
1022 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001023 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001024
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001025 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1026 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1027 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1028 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001029 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001030 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001031}
1032
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001033static int i40e_set_eeprom(struct net_device *netdev,
1034 struct ethtool_eeprom *eeprom, u8 *bytes)
1035{
1036 struct i40e_netdev_priv *np = netdev_priv(netdev);
1037 struct i40e_hw *hw = &np->vsi->back->hw;
1038 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001039 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001040 int ret_val = 0;
1041 int errno;
1042 u32 magic;
1043
1044 /* normal ethtool set_eeprom is not supported */
1045 magic = hw->vendor_id | (hw->device_id << 16);
1046 if (eeprom->magic == magic)
1047 return -EOPNOTSUPP;
1048
1049 /* check for NVMUpdate access method */
1050 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1051 return -EINVAL;
1052
1053 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1054 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1055 return -EBUSY;
1056
Shannon Nelsonc150a502014-11-13 08:23:13 +00001057 cmd = (struct i40e_nvm_access *)eeprom;
1058 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001059 if (ret_val &&
1060 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1061 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1062 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001063 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001064 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1065 ret_val, hw->aq.asq_last_status, errno,
1066 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1067 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001068
1069 return errno;
1070}
1071
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072static void i40e_get_drvinfo(struct net_device *netdev,
1073 struct ethtool_drvinfo *drvinfo)
1074{
1075 struct i40e_netdev_priv *np = netdev_priv(netdev);
1076 struct i40e_vsi *vsi = np->vsi;
1077 struct i40e_pf *pf = vsi->back;
1078
1079 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1080 strlcpy(drvinfo->version, i40e_driver_version_str,
1081 sizeof(drvinfo->version));
1082 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1083 sizeof(drvinfo->fw_version));
1084 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1085 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001086 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001087}
1088
1089static void i40e_get_ringparam(struct net_device *netdev,
1090 struct ethtool_ringparam *ring)
1091{
1092 struct i40e_netdev_priv *np = netdev_priv(netdev);
1093 struct i40e_pf *pf = np->vsi->back;
1094 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1095
1096 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1097 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1098 ring->rx_mini_max_pending = 0;
1099 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001100 ring->rx_pending = vsi->rx_rings[0]->count;
1101 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001102 ring->rx_mini_pending = 0;
1103 ring->rx_jumbo_pending = 0;
1104}
1105
1106static int i40e_set_ringparam(struct net_device *netdev,
1107 struct ethtool_ringparam *ring)
1108{
1109 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1110 struct i40e_netdev_priv *np = netdev_priv(netdev);
1111 struct i40e_vsi *vsi = np->vsi;
1112 struct i40e_pf *pf = vsi->back;
1113 u32 new_rx_count, new_tx_count;
1114 int i, err = 0;
1115
1116 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1117 return -EINVAL;
1118
Shannon Nelson1fa18372013-11-20 10:03:08 +00001119 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1120 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1121 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1122 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1123 netdev_info(netdev,
1124 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1125 ring->tx_pending, ring->rx_pending,
1126 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1127 return -EINVAL;
1128 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001129
Shannon Nelson1fa18372013-11-20 10:03:08 +00001130 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1131 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001132
1133 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001134 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1135 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001136 return 0;
1137
1138 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1139 usleep_range(1000, 2000);
1140
1141 if (!netif_running(vsi->netdev)) {
1142 /* simple case - set for the next time the netdev is started */
1143 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001144 vsi->tx_rings[i]->count = new_tx_count;
1145 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001146 }
1147 goto done;
1148 }
1149
1150 /* We can't just free everything and then setup again,
1151 * because the ISRs in MSI-X mode get passed pointers
1152 * to the Tx and Rx ring structs.
1153 */
1154
1155 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001156 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001157 netdev_info(netdev,
1158 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001159 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001160 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1161 sizeof(struct i40e_ring), GFP_KERNEL);
1162 if (!tx_rings) {
1163 err = -ENOMEM;
1164 goto done;
1165 }
1166
1167 for (i = 0; i < vsi->num_queue_pairs; i++) {
1168 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001169 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001170 tx_rings[i].count = new_tx_count;
1171 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1172 if (err) {
1173 while (i) {
1174 i--;
1175 i40e_free_tx_resources(&tx_rings[i]);
1176 }
1177 kfree(tx_rings);
1178 tx_rings = NULL;
1179
1180 goto done;
1181 }
1182 }
1183 }
1184
1185 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001186 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001187 netdev_info(netdev,
1188 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001189 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001190 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1191 sizeof(struct i40e_ring), GFP_KERNEL);
1192 if (!rx_rings) {
1193 err = -ENOMEM;
1194 goto free_tx;
1195 }
1196
1197 for (i = 0; i < vsi->num_queue_pairs; i++) {
1198 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001199 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001200 rx_rings[i].count = new_rx_count;
1201 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1202 if (err) {
1203 while (i) {
1204 i--;
1205 i40e_free_rx_resources(&rx_rings[i]);
1206 }
1207 kfree(rx_rings);
1208 rx_rings = NULL;
1209
1210 goto free_tx;
1211 }
1212 }
1213 }
1214
1215 /* Bring interface down, copy in the new ring info,
1216 * then restore the interface
1217 */
1218 i40e_down(vsi);
1219
1220 if (tx_rings) {
1221 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001222 i40e_free_tx_resources(vsi->tx_rings[i]);
1223 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001224 }
1225 kfree(tx_rings);
1226 tx_rings = NULL;
1227 }
1228
1229 if (rx_rings) {
1230 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001231 i40e_free_rx_resources(vsi->rx_rings[i]);
1232 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001233 }
1234 kfree(rx_rings);
1235 rx_rings = NULL;
1236 }
1237
1238 i40e_up(vsi);
1239
1240free_tx:
1241 /* error cleanup if the Rx allocations failed after getting Tx */
1242 if (tx_rings) {
1243 for (i = 0; i < vsi->num_queue_pairs; i++)
1244 i40e_free_tx_resources(&tx_rings[i]);
1245 kfree(tx_rings);
1246 tx_rings = NULL;
1247 }
1248
1249done:
1250 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1251
1252 return err;
1253}
1254
1255static int i40e_get_sset_count(struct net_device *netdev, int sset)
1256{
1257 struct i40e_netdev_priv *np = netdev_priv(netdev);
1258 struct i40e_vsi *vsi = np->vsi;
1259 struct i40e_pf *pf = vsi->back;
1260
1261 switch (sset) {
1262 case ETH_SS_TEST:
1263 return I40E_TEST_LEN;
1264 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001265 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001266 int len = I40E_PF_STATS_LEN(netdev);
1267
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001268 if ((pf->lan_veb != I40E_NO_VEB) &&
1269 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001270 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001271 return len;
1272 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001273 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001274 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001275 case ETH_SS_PRIV_FLAGS:
1276 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 default:
1278 return -EOPNOTSUPP;
1279 }
1280}
1281
1282static void i40e_get_ethtool_stats(struct net_device *netdev,
1283 struct ethtool_stats *stats, u64 *data)
1284{
1285 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001286 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001287 struct i40e_vsi *vsi = np->vsi;
1288 struct i40e_pf *pf = vsi->back;
1289 int i = 0;
1290 char *p;
1291 int j;
1292 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001293 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001294
1295 i40e_update_stats(vsi);
1296
1297 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1298 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1299 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1300 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1301 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001302 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1303 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1304 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1305 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1306 }
Vasu Dev38e00432014-08-01 13:27:03 -07001307#ifdef I40E_FCOE
1308 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1309 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1310 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1311 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1312 }
1313#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001314 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001315 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001316 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001317
1318 if (!tx_ring)
1319 continue;
1320
1321 /* process Tx ring statistics */
1322 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001323 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001324 data[i] = tx_ring->stats.packets;
1325 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001326 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001327 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001328
1329 /* Rx ring is the 2nd half of the queue pair */
1330 rx_ring = &tx_ring[1];
1331 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001332 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001333 data[i] = rx_ring->stats.packets;
1334 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001335 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001336 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001337 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001338 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001339 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001340 return;
1341
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001342 if ((pf->lan_veb != I40E_NO_VEB) &&
1343 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001344 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1345 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1346 p = (char *)veb;
1347 p += i40e_gstrings_veb_stats[j].stat_offset;
1348 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1349 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001351 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001352 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1353 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1354 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1355 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1356 }
1357 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1358 data[i++] = pf->stats.priority_xon_tx[j];
1359 data[i++] = pf->stats.priority_xoff_tx[j];
1360 }
1361 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1362 data[i++] = pf->stats.priority_xon_rx[j];
1363 data[i++] = pf->stats.priority_xoff_rx[j];
1364 }
1365 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1366 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001367}
1368
1369static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1370 u8 *data)
1371{
1372 struct i40e_netdev_priv *np = netdev_priv(netdev);
1373 struct i40e_vsi *vsi = np->vsi;
1374 struct i40e_pf *pf = vsi->back;
1375 char *p = (char *)data;
1376 int i;
1377
1378 switch (stringset) {
1379 case ETH_SS_TEST:
1380 for (i = 0; i < I40E_TEST_LEN; i++) {
1381 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1382 data += ETH_GSTRING_LEN;
1383 }
1384 break;
1385 case ETH_SS_STATS:
1386 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1387 snprintf(p, ETH_GSTRING_LEN, "%s",
1388 i40e_gstrings_net_stats[i].stat_string);
1389 p += ETH_GSTRING_LEN;
1390 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001391 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1392 snprintf(p, ETH_GSTRING_LEN, "%s",
1393 i40e_gstrings_misc_stats[i].stat_string);
1394 p += ETH_GSTRING_LEN;
1395 }
Vasu Dev38e00432014-08-01 13:27:03 -07001396#ifdef I40E_FCOE
1397 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1398 snprintf(p, ETH_GSTRING_LEN, "%s",
1399 i40e_gstrings_fcoe_stats[i].stat_string);
1400 p += ETH_GSTRING_LEN;
1401 }
1402#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001403 for (i = 0; i < vsi->num_queue_pairs; i++) {
1404 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1405 p += ETH_GSTRING_LEN;
1406 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1407 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001408 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1409 p += ETH_GSTRING_LEN;
1410 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1411 p += ETH_GSTRING_LEN;
1412 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001413 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001414 return;
1415
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001416 if ((pf->lan_veb != I40E_NO_VEB) &&
1417 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001418 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1419 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1420 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421 p += ETH_GSTRING_LEN;
1422 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001423 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1424 snprintf(p, ETH_GSTRING_LEN,
1425 "veb.tc_%u_tx_packets", i);
1426 p += ETH_GSTRING_LEN;
1427 snprintf(p, ETH_GSTRING_LEN,
1428 "veb.tc_%u_tx_bytes", i);
1429 p += ETH_GSTRING_LEN;
1430 snprintf(p, ETH_GSTRING_LEN,
1431 "veb.tc_%u_rx_packets", i);
1432 p += ETH_GSTRING_LEN;
1433 snprintf(p, ETH_GSTRING_LEN,
1434 "veb.tc_%u_rx_bytes", i);
1435 p += ETH_GSTRING_LEN;
1436 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001437 }
1438 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1439 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1440 i40e_gstrings_stats[i].stat_string);
1441 p += ETH_GSTRING_LEN;
1442 }
1443 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1444 snprintf(p, ETH_GSTRING_LEN,
1445 "port.tx_priority_%u_xon", i);
1446 p += ETH_GSTRING_LEN;
1447 snprintf(p, ETH_GSTRING_LEN,
1448 "port.tx_priority_%u_xoff", i);
1449 p += ETH_GSTRING_LEN;
1450 }
1451 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1452 snprintf(p, ETH_GSTRING_LEN,
1453 "port.rx_priority_%u_xon", i);
1454 p += ETH_GSTRING_LEN;
1455 snprintf(p, ETH_GSTRING_LEN,
1456 "port.rx_priority_%u_xoff", i);
1457 p += ETH_GSTRING_LEN;
1458 }
1459 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1460 snprintf(p, ETH_GSTRING_LEN,
1461 "port.rx_priority_%u_xon_2_xoff", i);
1462 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001463 }
1464 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1465 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001466 case ETH_SS_PRIV_FLAGS:
1467 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1468 memcpy(data, i40e_priv_flags_strings[i],
1469 ETH_GSTRING_LEN);
1470 data += ETH_GSTRING_LEN;
1471 }
1472 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001473 default:
1474 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001475 }
1476}
1477
1478static int i40e_get_ts_info(struct net_device *dev,
1479 struct ethtool_ts_info *info)
1480{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001481 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1482
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001483 /* only report HW timestamping if PTP is enabled */
1484 if (!(pf->flags & I40E_FLAG_PTP))
1485 return ethtool_op_get_ts_info(dev, info);
1486
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001487 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1488 SOF_TIMESTAMPING_RX_SOFTWARE |
1489 SOF_TIMESTAMPING_SOFTWARE |
1490 SOF_TIMESTAMPING_TX_HARDWARE |
1491 SOF_TIMESTAMPING_RX_HARDWARE |
1492 SOF_TIMESTAMPING_RAW_HARDWARE;
1493
1494 if (pf->ptp_clock)
1495 info->phc_index = ptp_clock_index(pf->ptp_clock);
1496 else
1497 info->phc_index = -1;
1498
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001499 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001500
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001501 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1502 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1503 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001504
1505 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506}
1507
Shannon Nelson7b086392013-11-20 10:02:59 +00001508static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001509{
Shannon Nelson7b086392013-11-20 10:02:59 +00001510 struct i40e_netdev_priv *np = netdev_priv(netdev);
1511 struct i40e_pf *pf = np->vsi->back;
1512
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001513 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514 if (i40e_get_link_status(&pf->hw))
1515 *data = 0;
1516 else
1517 *data = 1;
1518
1519 return *data;
1520}
1521
Shannon Nelson7b086392013-11-20 10:02:59 +00001522static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523{
Shannon Nelson7b086392013-11-20 10:02:59 +00001524 struct i40e_netdev_priv *np = netdev_priv(netdev);
1525 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001526
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001527 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001528 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001529
Shannon Nelson7b086392013-11-20 10:02:59 +00001530 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001531}
1532
Shannon Nelson7b086392013-11-20 10:02:59 +00001533static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534{
Shannon Nelson7b086392013-11-20 10:02:59 +00001535 struct i40e_netdev_priv *np = netdev_priv(netdev);
1536 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001538 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001539 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001540
Shannon Nelson4443ec92014-11-13 08:23:12 +00001541 /* forcebly clear the NVM Update state machine */
1542 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1543
Shannon Nelson7b086392013-11-20 10:02:59 +00001544 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545}
1546
Shannon Nelson7b086392013-11-20 10:02:59 +00001547static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548{
Shannon Nelson7b086392013-11-20 10:02:59 +00001549 struct i40e_netdev_priv *np = netdev_priv(netdev);
1550 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001551 u16 swc_old = pf->sw_int_count;
1552
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001553 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001554 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1555 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001556 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1557 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1558 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1559 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001560 usleep_range(1000, 2000);
1561 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562
1563 return *data;
1564}
1565
Shannon Nelson7b086392013-11-20 10:02:59 +00001566static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001567{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001568 struct i40e_netdev_priv *np = netdev_priv(netdev);
1569 struct i40e_pf *pf = np->vsi->back;
1570
1571 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001572 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573
1574 return *data;
1575}
1576
Greg Rosee17bc412015-04-16 20:05:59 -04001577static inline bool i40e_active_vfs(struct i40e_pf *pf)
1578{
1579 struct i40e_vf *vfs = pf->vf;
1580 int i;
1581
1582 for (i = 0; i < pf->num_alloc_vfs; i++)
1583 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1584 return true;
1585 return false;
1586}
1587
Greg Rose510efb22015-07-10 19:36:01 -04001588static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1589{
1590 struct i40e_vsi **vsi = pf->vsi;
1591 int i;
1592
1593 for (i = 0; i < pf->num_alloc_vsi; i++) {
1594 if (!vsi[i])
1595 continue;
1596 if (vsi[i]->type == I40E_VSI_VMDQ2)
1597 return true;
1598 }
1599
1600 return false;
1601}
1602
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001603static void i40e_diag_test(struct net_device *netdev,
1604 struct ethtool_test *eth_test, u64 *data)
1605{
1606 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001607 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608 struct i40e_pf *pf = np->vsi->back;
1609
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001610 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1611 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001612 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001613
Shannon Nelsonf551b432013-11-26 10:49:12 +00001614 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001615
Greg Rose510efb22015-07-10 19:36:01 -04001616 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001617 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001618 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001619 data[I40E_ETH_TEST_REG] = 1;
1620 data[I40E_ETH_TEST_EEPROM] = 1;
1621 data[I40E_ETH_TEST_INTR] = 1;
1622 data[I40E_ETH_TEST_LOOPBACK] = 1;
1623 data[I40E_ETH_TEST_LINK] = 1;
1624 eth_test->flags |= ETH_TEST_FL_FAILED;
1625 clear_bit(__I40E_TESTING, &pf->state);
1626 goto skip_ol_tests;
1627 }
1628
Greg Rose5b86c5c2015-02-26 16:14:35 +00001629 /* If the device is online then take it offline */
1630 if (if_running)
1631 /* indicate we're in test mode */
1632 dev_close(netdev);
1633 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001634 /* This reset does not affect link - if it is
1635 * changed to a type of reset that does affect
1636 * link then the following link test would have
1637 * to be moved to before the reset
1638 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001639 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001640
Shannon Nelson7b086392013-11-20 10:02:59 +00001641 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001642 eth_test->flags |= ETH_TEST_FL_FAILED;
1643
Shannon Nelson7b086392013-11-20 10:02:59 +00001644 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001645 eth_test->flags |= ETH_TEST_FL_FAILED;
1646
Shannon Nelson7b086392013-11-20 10:02:59 +00001647 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001648 eth_test->flags |= ETH_TEST_FL_FAILED;
1649
Shannon Nelson7b086392013-11-20 10:02:59 +00001650 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001651 eth_test->flags |= ETH_TEST_FL_FAILED;
1652
Shannon Nelsonf551b432013-11-26 10:49:12 +00001653 /* run reg test last, a reset is required after it */
1654 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1655 eth_test->flags |= ETH_TEST_FL_FAILED;
1656
1657 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001658 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001659
1660 if (if_running)
1661 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001663 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001664 netif_info(pf, drv, netdev, "online testing starting\n");
1665
Shannon Nelson7b086392013-11-20 10:02:59 +00001666 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667 eth_test->flags |= ETH_TEST_FL_FAILED;
1668
1669 /* Offline only tests, not run in online; pass by default */
1670 data[I40E_ETH_TEST_REG] = 0;
1671 data[I40E_ETH_TEST_EEPROM] = 0;
1672 data[I40E_ETH_TEST_INTR] = 0;
1673 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001674 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001675
Greg Rosee17bc412015-04-16 20:05:59 -04001676skip_ol_tests:
1677
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001678 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001679}
1680
1681static void i40e_get_wol(struct net_device *netdev,
1682 struct ethtool_wolinfo *wol)
1683{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001684 struct i40e_netdev_priv *np = netdev_priv(netdev);
1685 struct i40e_pf *pf = np->vsi->back;
1686 struct i40e_hw *hw = &pf->hw;
1687 u16 wol_nvm_bits;
1688
1689 /* NVM bit on means WoL disabled for the port */
1690 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001691 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001692 wol->supported = 0;
1693 wol->wolopts = 0;
1694 } else {
1695 wol->supported = WAKE_MAGIC;
1696 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1697 }
1698}
1699
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001700/**
1701 * i40e_set_wol - set the WakeOnLAN configuration
1702 * @netdev: the netdev in question
1703 * @wol: the ethtool WoL setting data
1704 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001705static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1706{
1707 struct i40e_netdev_priv *np = netdev_priv(netdev);
1708 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001709 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001710 struct i40e_hw *hw = &pf->hw;
1711 u16 wol_nvm_bits;
1712
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001713 /* WoL not supported if this isn't the controlling PF on the port */
1714 if (hw->partition_id != 1) {
1715 i40e_partition_setting_complaint(pf);
1716 return -EOPNOTSUPP;
1717 }
1718
1719 if (vsi != pf->vsi[pf->lan_vsi])
1720 return -EOPNOTSUPP;
1721
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001722 /* NVM bit on means WoL disabled for the port */
1723 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001724 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001725 return -EOPNOTSUPP;
1726
1727 /* only magic packet is supported */
1728 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1729 return -EOPNOTSUPP;
1730
1731 /* is this a new value? */
1732 if (pf->wol_en != !!wol->wolopts) {
1733 pf->wol_en = !!wol->wolopts;
1734 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1735 }
1736
1737 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001738}
1739
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001740static int i40e_set_phys_id(struct net_device *netdev,
1741 enum ethtool_phys_id_state state)
1742{
1743 struct i40e_netdev_priv *np = netdev_priv(netdev);
1744 struct i40e_pf *pf = np->vsi->back;
1745 struct i40e_hw *hw = &pf->hw;
1746 int blink_freq = 2;
1747
1748 switch (state) {
1749 case ETHTOOL_ID_ACTIVE:
1750 pf->led_status = i40e_led_get(hw);
1751 return blink_freq;
1752 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001753 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001754 break;
1755 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001756 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001757 break;
1758 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001759 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001760 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001761 default:
1762 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001763 }
1764
1765 return 0;
1766}
1767
1768/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1769 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1770 * 125us (8000 interrupts per second) == ITR(62)
1771 */
1772
1773static int i40e_get_coalesce(struct net_device *netdev,
1774 struct ethtool_coalesce *ec)
1775{
1776 struct i40e_netdev_priv *np = netdev_priv(netdev);
1777 struct i40e_vsi *vsi = np->vsi;
1778
1779 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1780 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1781
1782 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001783 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001784
1785 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001786 ec->use_adaptive_tx_coalesce = 1;
1787
1788 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1789 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001790
1791 return 0;
1792}
1793
1794static int i40e_set_coalesce(struct net_device *netdev,
1795 struct ethtool_coalesce *ec)
1796{
1797 struct i40e_netdev_priv *np = netdev_priv(netdev);
1798 struct i40e_q_vector *q_vector;
1799 struct i40e_vsi *vsi = np->vsi;
1800 struct i40e_pf *pf = vsi->back;
1801 struct i40e_hw *hw = &pf->hw;
1802 u16 vector;
1803 int i;
1804
1805 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1806 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1807
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001808 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001809 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001810 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001812 } else if (ec->rx_coalesce_usecs == 0) {
1813 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001814 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001815 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 +00001816 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001817 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001818 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001819 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820
Mitch Williams32f5f542014-04-04 04:43:10 +00001821 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001822 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001824 } else if (ec->tx_coalesce_usecs == 0) {
1825 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001826 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001827 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 +00001828 } else {
1829 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001830 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001831 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001832 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001833
1834 if (ec->use_adaptive_rx_coalesce)
1835 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1836 else
1837 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1838
1839 if (ec->use_adaptive_tx_coalesce)
1840 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1841 else
1842 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001843
Alexander Duyck493fb302013-09-28 07:01:44 +00001844 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1845 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001846 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1847 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1848 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1849 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1850 i40e_flush(hw);
1851 }
1852
1853 return 0;
1854}
1855
1856/**
1857 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1858 * @pf: pointer to the physical function struct
1859 * @cmd: ethtool rxnfc command
1860 *
1861 * Returns Success if the flow is supported, else Invalid Input.
1862 **/
1863static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1864{
1865 cmd->data = 0;
1866
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001867 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1868 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1869 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1870 return 0;
1871 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001872 /* Report default options for RSS on i40e */
1873 switch (cmd->flow_type) {
1874 case TCP_V4_FLOW:
1875 case UDP_V4_FLOW:
1876 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1877 /* fall through to add IP fields */
1878 case SCTP_V4_FLOW:
1879 case AH_ESP_V4_FLOW:
1880 case AH_V4_FLOW:
1881 case ESP_V4_FLOW:
1882 case IPV4_FLOW:
1883 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1884 break;
1885 case TCP_V6_FLOW:
1886 case UDP_V6_FLOW:
1887 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1888 /* fall through to add IP fields */
1889 case SCTP_V6_FLOW:
1890 case AH_ESP_V6_FLOW:
1891 case AH_V6_FLOW:
1892 case ESP_V6_FLOW:
1893 case IPV6_FLOW:
1894 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1895 break;
1896 default:
1897 return -EINVAL;
1898 }
1899
1900 return 0;
1901}
1902
1903/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001904 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1905 * @pf: Pointer to the physical function struct
1906 * @cmd: The command to get or set Rx flow classification rules
1907 * @rule_locs: Array of used rule locations
1908 *
1909 * This function populates both the total and actual rule count of
1910 * the ethtool flow classification command
1911 *
1912 * Returns 0 on success or -EMSGSIZE if entry not found
1913 **/
1914static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1915 struct ethtool_rxnfc *cmd,
1916 u32 *rule_locs)
1917{
1918 struct i40e_fdir_filter *rule;
1919 struct hlist_node *node2;
1920 int cnt = 0;
1921
1922 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001923 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001924
1925 hlist_for_each_entry_safe(rule, node2,
1926 &pf->fdir_filter_list, fdir_node) {
1927 if (cnt == cmd->rule_cnt)
1928 return -EMSGSIZE;
1929
1930 rule_locs[cnt] = rule->fd_id;
1931 cnt++;
1932 }
1933
1934 cmd->rule_cnt = cnt;
1935
1936 return 0;
1937}
1938
1939/**
1940 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1941 * @pf: Pointer to the physical function struct
1942 * @cmd: The command to get or set Rx flow classification rules
1943 *
1944 * This function looks up a filter based on the Rx flow classification
1945 * command and fills the flow spec info for it if found
1946 *
1947 * Returns 0 on success or -EINVAL if filter not found
1948 **/
1949static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1950 struct ethtool_rxnfc *cmd)
1951{
1952 struct ethtool_rx_flow_spec *fsp =
1953 (struct ethtool_rx_flow_spec *)&cmd->fs;
1954 struct i40e_fdir_filter *rule = NULL;
1955 struct hlist_node *node2;
1956
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001957 hlist_for_each_entry_safe(rule, node2,
1958 &pf->fdir_filter_list, fdir_node) {
1959 if (fsp->location <= rule->fd_id)
1960 break;
1961 }
1962
1963 if (!rule || fsp->location != rule->fd_id)
1964 return -EINVAL;
1965
1966 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001967 if (fsp->flow_type == IP_USER_FLOW) {
1968 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1969 fsp->h_u.usr_ip4_spec.proto = 0;
1970 fsp->m_u.usr_ip4_spec.proto = 0;
1971 }
1972
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001973 /* Reverse the src and dest notion, since the HW views them from
1974 * Tx perspective where as the user expects it from Rx filter view.
1975 */
1976 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1977 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1978 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1979 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001980
1981 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1982 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1983 else
1984 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001985
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04001986 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1987 struct i40e_vsi *vsi;
1988
1989 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1990 if (vsi && vsi->type == I40E_VSI_SRIOV) {
1991 fsp->h_ext.data[1] = htonl(vsi->vf_id);
1992 fsp->m_ext.data[1] = htonl(0x1);
1993 }
1994 }
1995
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001996 return 0;
1997}
1998
1999/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002000 * i40e_get_rxnfc - command to get RX flow classification rules
2001 * @netdev: network interface device structure
2002 * @cmd: ethtool rxnfc command
2003 *
2004 * Returns Success if the command is supported.
2005 **/
2006static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2007 u32 *rule_locs)
2008{
2009 struct i40e_netdev_priv *np = netdev_priv(netdev);
2010 struct i40e_vsi *vsi = np->vsi;
2011 struct i40e_pf *pf = vsi->back;
2012 int ret = -EOPNOTSUPP;
2013
2014 switch (cmd->cmd) {
2015 case ETHTOOL_GRXRINGS:
2016 cmd->data = vsi->alloc_queue_pairs;
2017 ret = 0;
2018 break;
2019 case ETHTOOL_GRXFH:
2020 ret = i40e_get_rss_hash_opts(pf, cmd);
2021 break;
2022 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002023 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002024 /* report total rule count */
2025 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002026 ret = 0;
2027 break;
2028 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002029 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002030 break;
2031 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002032 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2033 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002034 default:
2035 break;
2036 }
2037
2038 return ret;
2039}
2040
2041/**
2042 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2043 * @pf: pointer to the physical function struct
2044 * @cmd: ethtool rxnfc command
2045 *
2046 * Returns Success if the flow input set is supported.
2047 **/
2048static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2049{
2050 struct i40e_hw *hw = &pf->hw;
2051 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2052 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2053
2054 /* RSS does not support anything other than hashing
2055 * to queues on src and dst IPs and ports
2056 */
2057 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2058 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2059 return -EINVAL;
2060
2061 /* We need at least the IP SRC and DEST fields for hashing */
2062 if (!(nfc->data & RXH_IP_SRC) ||
2063 !(nfc->data & RXH_IP_DST))
2064 return -EINVAL;
2065
2066 switch (nfc->flow_type) {
2067 case TCP_V4_FLOW:
2068 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2069 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002070 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002071 break;
2072 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002073 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002074 break;
2075 default:
2076 return -EINVAL;
2077 }
2078 break;
2079 case TCP_V6_FLOW:
2080 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2081 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002082 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002083 break;
2084 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002085 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002086 break;
2087 default:
2088 return -EINVAL;
2089 }
2090 break;
2091 case UDP_V4_FLOW:
2092 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2093 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002094 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2095 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002096 break;
2097 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002098 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2099 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002100 break;
2101 default:
2102 return -EINVAL;
2103 }
2104 break;
2105 case UDP_V6_FLOW:
2106 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2107 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002108 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2109 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002110 break;
2111 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002112 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2113 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002114 break;
2115 default:
2116 return -EINVAL;
2117 }
2118 break;
2119 case AH_ESP_V4_FLOW:
2120 case AH_V4_FLOW:
2121 case ESP_V4_FLOW:
2122 case SCTP_V4_FLOW:
2123 if ((nfc->data & RXH_L4_B_0_1) ||
2124 (nfc->data & RXH_L4_B_2_3))
2125 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002126 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002127 break;
2128 case AH_ESP_V6_FLOW:
2129 case AH_V6_FLOW:
2130 case ESP_V6_FLOW:
2131 case SCTP_V6_FLOW:
2132 if ((nfc->data & RXH_L4_B_0_1) ||
2133 (nfc->data & RXH_L4_B_2_3))
2134 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002135 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002136 break;
2137 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002138 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2139 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140 break;
2141 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002142 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2143 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144 break;
2145 default:
2146 return -EINVAL;
2147 }
2148
2149 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2150 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2151 i40e_flush(hw);
2152
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002153 /* Save setting for future output/update */
2154 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2155
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002156 return 0;
2157}
2158
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002159/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002160 * i40e_match_fdir_input_set - Match a new filter against an existing one
2161 * @rule: The filter already added
2162 * @input: The new filter to comapre against
2163 *
2164 * Returns true if the two input set match
2165 **/
2166static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2167 struct i40e_fdir_filter *input)
2168{
2169 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2170 (rule->src_ip[0] != input->src_ip[0]) ||
2171 (rule->dst_port != input->dst_port) ||
2172 (rule->src_port != input->src_port))
2173 return false;
2174 return true;
2175}
2176
2177/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002178 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2179 * @vsi: Pointer to the targeted VSI
2180 * @input: The filter to update or NULL to indicate deletion
2181 * @sw_idx: Software index to the filter
2182 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002183 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002184 * This function updates (or deletes) a Flow Director entry from
2185 * the hlist of the corresponding PF
2186 *
2187 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002188 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002189static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2190 struct i40e_fdir_filter *input,
2191 u16 sw_idx,
2192 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002193{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002194 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002195 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002196 struct hlist_node *node2;
2197 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002198
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002199 parent = NULL;
2200 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002201
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002202 hlist_for_each_entry_safe(rule, node2,
2203 &pf->fdir_filter_list, fdir_node) {
2204 /* hash found, or no matching entry */
2205 if (rule->fd_id >= sw_idx)
2206 break;
2207 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002208 }
2209
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002210 /* if there is an old rule occupying our place remove it */
2211 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002212 if (input && !i40e_match_fdir_input_set(rule, input))
2213 err = i40e_add_del_fdir(vsi, rule, false);
2214 else if (!input)
2215 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002216 hlist_del(&rule->fdir_node);
2217 kfree(rule);
2218 pf->fdir_pf_active_filters--;
2219 }
2220
2221 /* If no input this was a delete, err should be 0 if a rule was
2222 * successfully found and removed from the list else -EINVAL
2223 */
2224 if (!input)
2225 return err;
2226
2227 /* initialize node and set software index */
2228 INIT_HLIST_NODE(&input->fdir_node);
2229
2230 /* add filter to the list */
2231 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002232 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002233 else
2234 hlist_add_head(&input->fdir_node,
2235 &pf->fdir_filter_list);
2236
2237 /* update counts */
2238 pf->fdir_pf_active_filters++;
2239
2240 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002241}
2242
2243/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002244 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2245 * @vsi: Pointer to the targeted VSI
2246 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002247 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002248 * The function removes a Flow Director filter entry from the
2249 * hlist of the corresponding PF
2250 *
2251 * Returns 0 on success
2252 */
2253static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2254 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002255{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002256 struct ethtool_rx_flow_spec *fsp =
2257 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002258 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002259 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002260
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002261 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2262 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2263 return -EBUSY;
2264
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002265 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2266 return -EBUSY;
2267
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002268 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002269
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002270 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002271 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002272}
2273
2274/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002275 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002276 * @vsi: pointer to the targeted VSI
2277 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002278 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002279 * Add Flow Director filters for a specific flow spec based on their
2280 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002282static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2283 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002284{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002285 struct ethtool_rx_flow_spec *fsp;
2286 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002287 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002288 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002289 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002290
2291 if (!vsi)
2292 return -EINVAL;
2293
2294 pf = vsi->back;
2295
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002296 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2297 return -EOPNOTSUPP;
2298
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002299 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002300 return -ENOSPC;
2301
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002302 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2303 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2304 return -EBUSY;
2305
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002306 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2307 return -EBUSY;
2308
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002309 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2310
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002311 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2312 pf->hw.func_caps.fd_filters_guaranteed)) {
2313 return -EINVAL;
2314 }
2315
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002316 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2317 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002318 return -EINVAL;
2319
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002320 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002321
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002322 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002323 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002324
2325 input->fd_id = fsp->location;
2326
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002327 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2328 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2329 else
2330 input->dest_ctl =
2331 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2332
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002333 input->q_index = fsp->ring_cookie;
2334 input->flex_off = 0;
2335 input->pctype = 0;
2336 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002337 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002338 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002339 input->flow_type = fsp->flow_type;
2340 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002341
2342 /* Reverse the src and dest notion, since the HW expects them to be from
2343 * Tx perspective where as the input from user is from Rx filter view.
2344 */
2345 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2346 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2347 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2348 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002349
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002350 if (ntohl(fsp->m_ext.data[1])) {
2351 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2352 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2353 goto free_input;
2354 }
2355 vf_id = ntohl(fsp->h_ext.data[1]);
2356 /* Find vsi id from vf id and override dest vsi */
2357 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2358 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2359 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2360 goto free_input;
2361 }
2362 }
2363
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002364 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002365free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002366 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002367 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002368 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002369 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002370
2371 return ret;
2372}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002373
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002374/**
2375 * i40e_set_rxnfc - command to set RX flow classification rules
2376 * @netdev: network interface device structure
2377 * @cmd: ethtool rxnfc command
2378 *
2379 * Returns Success if the command is supported.
2380 **/
2381static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2382{
2383 struct i40e_netdev_priv *np = netdev_priv(netdev);
2384 struct i40e_vsi *vsi = np->vsi;
2385 struct i40e_pf *pf = vsi->back;
2386 int ret = -EOPNOTSUPP;
2387
2388 switch (cmd->cmd) {
2389 case ETHTOOL_SRXFH:
2390 ret = i40e_set_rss_hash_opt(pf, cmd);
2391 break;
2392 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002393 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002394 break;
2395 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002396 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002397 break;
2398 default:
2399 break;
2400 }
2401
2402 return ret;
2403}
2404
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002405/**
2406 * i40e_max_channels - get Max number of combined channels supported
2407 * @vsi: vsi pointer
2408 **/
2409static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2410{
2411 /* TODO: This code assumes DCB and FD is disabled for now. */
2412 return vsi->alloc_queue_pairs;
2413}
2414
2415/**
2416 * i40e_get_channels - Get the current channels enabled and max supported etc.
2417 * @netdev: network interface device structure
2418 * @ch: ethtool channels structure
2419 *
2420 * We don't support separate tx and rx queues as channels. The other count
2421 * represents how many queues are being used for control. max_combined counts
2422 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2423 * q_vectors since we support a lot more queue pairs than q_vectors.
2424 **/
2425static void i40e_get_channels(struct net_device *dev,
2426 struct ethtool_channels *ch)
2427{
2428 struct i40e_netdev_priv *np = netdev_priv(dev);
2429 struct i40e_vsi *vsi = np->vsi;
2430 struct i40e_pf *pf = vsi->back;
2431
2432 /* report maximum channels */
2433 ch->max_combined = i40e_max_channels(vsi);
2434
2435 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002436 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002437 ch->max_other = ch->other_count;
2438
2439 /* Note: This code assumes DCB is disabled for now. */
2440 ch->combined_count = vsi->num_queue_pairs;
2441}
2442
2443/**
2444 * i40e_set_channels - Set the new channels count.
2445 * @netdev: network interface device structure
2446 * @ch: ethtool channels structure
2447 *
2448 * The new channels count may not be the same as requested by the user
2449 * since it gets rounded down to a power of 2 value.
2450 **/
2451static int i40e_set_channels(struct net_device *dev,
2452 struct ethtool_channels *ch)
2453{
2454 struct i40e_netdev_priv *np = netdev_priv(dev);
2455 unsigned int count = ch->combined_count;
2456 struct i40e_vsi *vsi = np->vsi;
2457 struct i40e_pf *pf = vsi->back;
2458 int new_count;
2459
2460 /* We do not support setting channels for any other VSI at present */
2461 if (vsi->type != I40E_VSI_MAIN)
2462 return -EINVAL;
2463
2464 /* verify they are not requesting separate vectors */
2465 if (!count || ch->rx_count || ch->tx_count)
2466 return -EINVAL;
2467
2468 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002469 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002470 return -EINVAL;
2471
2472 /* verify the number of channels does not exceed hardware limits */
2473 if (count > i40e_max_channels(vsi))
2474 return -EINVAL;
2475
2476 /* update feature limits from largest to smallest supported values */
2477 /* TODO: Flow director limit, DCB etc */
2478
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002479 /* use rss_reconfig to rebuild with new queue count and update traffic
2480 * class queue mapping
2481 */
2482 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002483 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002484 return 0;
2485 else
2486 return -EINVAL;
2487}
2488
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002489#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2490/**
2491 * i40e_get_rxfh_key_size - get the RSS hash key size
2492 * @netdev: network interface device structure
2493 *
2494 * Returns the table size.
2495 **/
2496static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2497{
2498 return I40E_HKEY_ARRAY_SIZE;
2499}
2500
2501/**
2502 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2503 * @netdev: network interface device structure
2504 *
2505 * Returns the table size.
2506 **/
2507static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2508{
2509 return I40E_HLUT_ARRAY_SIZE;
2510}
2511
2512static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2513 u8 *hfunc)
2514{
2515 struct i40e_netdev_priv *np = netdev_priv(netdev);
2516 struct i40e_vsi *vsi = np->vsi;
2517 struct i40e_pf *pf = vsi->back;
2518 struct i40e_hw *hw = &pf->hw;
2519 u32 reg_val;
2520 int i, j;
2521
2522 if (hfunc)
2523 *hfunc = ETH_RSS_HASH_TOP;
2524
2525 if (!indir)
2526 return 0;
2527
2528 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2529 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2530 indir[j++] = reg_val & 0xff;
2531 indir[j++] = (reg_val >> 8) & 0xff;
2532 indir[j++] = (reg_val >> 16) & 0xff;
2533 indir[j++] = (reg_val >> 24) & 0xff;
2534 }
2535
2536 if (key) {
2537 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2538 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2539 key[j++] = (u8)(reg_val & 0xff);
2540 key[j++] = (u8)((reg_val >> 8) & 0xff);
2541 key[j++] = (u8)((reg_val >> 16) & 0xff);
2542 key[j++] = (u8)((reg_val >> 24) & 0xff);
2543 }
2544 }
2545 return 0;
2546}
2547
2548/**
2549 * i40e_set_rxfh - set the rx flow hash indirection table
2550 * @netdev: network interface device structure
2551 * @indir: indirection table
2552 * @key: hash key
2553 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002554 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002555 * returns 0 after programming the table.
2556 **/
2557static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2558 const u8 *key, const u8 hfunc)
2559{
2560 struct i40e_netdev_priv *np = netdev_priv(netdev);
2561 struct i40e_vsi *vsi = np->vsi;
2562 struct i40e_pf *pf = vsi->back;
2563 struct i40e_hw *hw = &pf->hw;
2564 u32 reg_val;
2565 int i, j;
2566
2567 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2568 return -EOPNOTSUPP;
2569
2570 if (!indir)
2571 return 0;
2572
2573 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2574 reg_val = indir[j++];
2575 reg_val |= indir[j++] << 8;
2576 reg_val |= indir[j++] << 16;
2577 reg_val |= indir[j++] << 24;
2578 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2579 }
2580
2581 if (key) {
2582 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2583 reg_val = key[j++];
2584 reg_val |= key[j++] << 8;
2585 reg_val |= key[j++] << 16;
2586 reg_val |= key[j++] << 24;
2587 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2588 }
2589 }
2590 return 0;
2591}
2592
Greg Rose7e45ab42015-02-06 08:52:19 +00002593/**
2594 * i40e_get_priv_flags - report device private flags
2595 * @dev: network interface device structure
2596 *
2597 * The get string set count and the string set should be matched for each
2598 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2599 * array.
2600 *
2601 * Returns a u32 bitmap of flags.
2602 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002603static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002604{
2605 struct i40e_netdev_priv *np = netdev_priv(dev);
2606 struct i40e_vsi *vsi = np->vsi;
2607 struct i40e_pf *pf = vsi->back;
2608 u32 ret_flags = 0;
2609
2610 ret_flags |= pf->hw.func_caps.npar_enable ?
2611 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2612
2613 return ret_flags;
2614}
2615
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002616static const struct ethtool_ops i40e_ethtool_ops = {
2617 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002618 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002619 .get_drvinfo = i40e_get_drvinfo,
2620 .get_regs_len = i40e_get_regs_len,
2621 .get_regs = i40e_get_regs,
2622 .nway_reset = i40e_nway_reset,
2623 .get_link = ethtool_op_get_link,
2624 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002625 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002626 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002627 .get_eeprom_len = i40e_get_eeprom_len,
2628 .get_eeprom = i40e_get_eeprom,
2629 .get_ringparam = i40e_get_ringparam,
2630 .set_ringparam = i40e_set_ringparam,
2631 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002632 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002633 .get_msglevel = i40e_get_msglevel,
2634 .set_msglevel = i40e_set_msglevel,
2635 .get_rxnfc = i40e_get_rxnfc,
2636 .set_rxnfc = i40e_set_rxnfc,
2637 .self_test = i40e_diag_test,
2638 .get_strings = i40e_get_strings,
2639 .set_phys_id = i40e_set_phys_id,
2640 .get_sset_count = i40e_get_sset_count,
2641 .get_ethtool_stats = i40e_get_ethtool_stats,
2642 .get_coalesce = i40e_get_coalesce,
2643 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002644 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2645 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2646 .get_rxfh = i40e_get_rxfh,
2647 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002648 .get_channels = i40e_get_channels,
2649 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002650 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002651 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002652};
2653
2654void i40e_set_ethtool_ops(struct net_device *netdev)
2655{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002656 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002657}