blob: dd2b6208d91abaea87d2c84c6b57ff685131e894 [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:
428 ecmd->supported = SUPPORTED_10000baseT_Full |
429 SUPPORTED_1000baseT_Full |
430 SUPPORTED_100baseT_Full;
431 /* Figure out what has been requested */
432 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
433 ecmd->advertising |= ADVERTISED_10000baseT_Full;
434 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
435 ecmd->advertising |= ADVERTISED_1000baseT_Full;
436 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
437 ecmd->advertising |= ADVERTISED_100baseT_Full;
438 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700439 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -0400440 case I40E_DEV_ID_20G_KR2_A:
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700441 /* backplane 20G */
442 ecmd->supported = SUPPORTED_20000baseKR2_Full;
443 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
444 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000445 default:
446 /* all the rest are 10G/1G */
447 ecmd->supported = SUPPORTED_10000baseT_Full |
448 SUPPORTED_1000baseT_Full;
449 /* Figure out what has been requested */
450 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
451 ecmd->advertising |= ADVERTISED_10000baseT_Full;
452 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
453 ecmd->advertising |= ADVERTISED_1000baseT_Full;
454 break;
455 }
456
457 /* With no link speed and duplex are unknown */
458 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
459 ecmd->duplex = DUPLEX_UNKNOWN;
460}
461
462/**
463 * i40e_get_settings - Get Link Speed and Duplex settings
464 * @netdev: network interface device structure
465 * @ecmd: ethtool command
466 *
467 * Reports speed/duplex settings based on media_type
468 **/
469static int i40e_get_settings(struct net_device *netdev,
470 struct ethtool_cmd *ecmd)
471{
472 struct i40e_netdev_priv *np = netdev_priv(netdev);
473 struct i40e_pf *pf = np->vsi->back;
474 struct i40e_hw *hw = &pf->hw;
475 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
476 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
477
478 if (link_up)
479 i40e_get_settings_link_up(hw, ecmd, netdev);
480 else
481 i40e_get_settings_link_down(hw, ecmd);
482
483 /* Now set the settings that don't rely on link being up/down */
484
485 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000486 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
487 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000488
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000489 switch (hw->phy.media_type) {
490 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000491 ecmd->supported |= SUPPORTED_Autoneg |
492 SUPPORTED_Backplane;
493 ecmd->advertising |= ADVERTISED_Autoneg |
494 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000495 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000496 break;
497 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 ecmd->supported |= SUPPORTED_TP;
499 ecmd->advertising |= ADVERTISED_TP;
500 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000501 break;
502 case I40E_MEDIA_TYPE_DA:
503 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000504 ecmd->supported |= SUPPORTED_FIBRE;
505 ecmd->advertising |= ADVERTISED_FIBRE;
506 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000507 break;
508 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000509 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000510 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000511 break;
512 case I40E_MEDIA_TYPE_UNKNOWN:
513 default:
514 ecmd->port = PORT_OTHER;
515 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000516 }
517
Catherine Sullivane8278452015-02-06 08:52:08 +0000518 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000519 ecmd->transceiver = XCVR_EXTERNAL;
520
Catherine Sullivane8278452015-02-06 08:52:08 +0000521 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000522 ecmd->supported |= SUPPORTED_Pause;
523
Catherine Sullivane8278452015-02-06 08:52:08 +0000524 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000525 case I40E_FC_FULL:
526 ecmd->advertising |= ADVERTISED_Pause;
527 break;
528 case I40E_FC_TX_PAUSE:
529 ecmd->advertising |= ADVERTISED_Asym_Pause;
530 break;
531 case I40E_FC_RX_PAUSE:
532 ecmd->advertising |= (ADVERTISED_Pause |
533 ADVERTISED_Asym_Pause);
534 break;
535 default:
536 ecmd->advertising &= ~(ADVERTISED_Pause |
537 ADVERTISED_Asym_Pause);
538 break;
539 }
540
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000541 return 0;
542}
543
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000544/**
545 * i40e_set_settings - Set Speed and Duplex
546 * @netdev: network interface device structure
547 * @ecmd: ethtool command
548 *
549 * Set speed/duplex per media_types advertised/forced
550 **/
551static int i40e_set_settings(struct net_device *netdev,
552 struct ethtool_cmd *ecmd)
553{
554 struct i40e_netdev_priv *np = netdev_priv(netdev);
555 struct i40e_aq_get_phy_abilities_resp abilities;
556 struct i40e_aq_set_phy_config config;
557 struct i40e_pf *pf = np->vsi->back;
558 struct i40e_vsi *vsi = np->vsi;
559 struct i40e_hw *hw = &pf->hw;
560 struct ethtool_cmd safe_ecmd;
561 i40e_status status = 0;
562 bool change = false;
563 int err = 0;
564 u8 autoneg;
565 u32 advertise;
566
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000567 /* Changing port settings is not supported if this isn't the
568 * port's controlling PF
569 */
570 if (hw->partition_id != 1) {
571 i40e_partition_setting_complaint(pf);
572 return -EOPNOTSUPP;
573 }
574
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000575 if (vsi != pf->vsi[pf->lan_vsi])
576 return -EOPNOTSUPP;
577
578 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
579 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000580 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
581 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000582 return -EOPNOTSUPP;
583
584 /* get our own copy of the bits to check against */
585 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
586 i40e_get_settings(netdev, &safe_ecmd);
587
588 /* save autoneg and speed out of ecmd */
589 autoneg = ecmd->autoneg;
590 advertise = ecmd->advertising;
591
592 /* set autoneg and speed back to what they currently are */
593 ecmd->autoneg = safe_ecmd.autoneg;
594 ecmd->advertising = safe_ecmd.advertising;
595
596 ecmd->cmd = safe_ecmd.cmd;
597 /* If ecmd and safe_ecmd are not the same now, then they are
598 * trying to set something that we do not support
599 */
600 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
601 return -EOPNOTSUPP;
602
603 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
604 usleep_range(1000, 2000);
605
606 /* Get the current phy config */
607 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
608 NULL);
609 if (status)
610 return -EAGAIN;
611
Catherine Sullivan124ed152014-07-12 07:28:12 +0000612 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000613 * set below
614 */
615 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000616 config.abilities = abilities.abilities;
617
618 /* Check autoneg */
619 if (autoneg == AUTONEG_ENABLE) {
620 /* If autoneg is not supported, return error */
621 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
622 netdev_info(netdev, "Autoneg not supported on this phy\n");
623 return -EINVAL;
624 }
625 /* If autoneg was not already enabled */
626 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
627 config.abilities = abilities.abilities |
628 I40E_AQ_PHY_ENABLE_AN;
629 change = true;
630 }
631 } else {
632 /* If autoneg is supported 10GBASE_T is the only phy that
633 * can disable it, so otherwise return error
634 */
635 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
636 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
637 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
638 return -EINVAL;
639 }
640 /* If autoneg is currently enabled */
641 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000642 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000643 ~I40E_AQ_PHY_ENABLE_AN;
644 change = true;
645 }
646 }
647
648 if (advertise & ~safe_ecmd.supported)
649 return -EINVAL;
650
651 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000652 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000653 if (advertise & ADVERTISED_1000baseT_Full ||
654 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000655 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000656 if (advertise & ADVERTISED_10000baseT_Full ||
657 advertise & ADVERTISED_10000baseKX4_Full ||
658 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000659 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700660 if (advertise & ADVERTISED_20000baseKR2_Full)
661 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000662 if (advertise & ADVERTISED_40000baseKR4_Full ||
663 advertise & ADVERTISED_40000baseCR4_Full ||
664 advertise & ADVERTISED_40000baseSR4_Full ||
665 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000666 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000667
Catherine Sullivan124ed152014-07-12 07:28:12 +0000668 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000669 /* copy over the rest of the abilities */
670 config.phy_type = abilities.phy_type;
671 config.eee_capability = abilities.eee_capability;
672 config.eeer = abilities.eeer_val;
673 config.low_power_ctrl = abilities.d3_lpan;
674
Catherine Sullivane8278452015-02-06 08:52:08 +0000675 /* save the requested speeds */
676 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000677 /* set link and auto negotiation so changes take effect */
678 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
679 /* If link is up put link down */
680 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
681 /* Tell the OS link is going down, the link will go
682 * back up when fw says it is ready asynchronously
683 */
684 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
685 netif_carrier_off(netdev);
686 netif_tx_stop_all_queues(netdev);
687 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000688
689 /* make the aq call */
690 status = i40e_aq_set_phy_config(hw, &config, NULL);
691 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400692 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
693 i40e_stat_str(hw, status),
694 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000695 return -EAGAIN;
696 }
697
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000698 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000699 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400700 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
701 i40e_stat_str(hw, status),
702 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000703
704 } else {
705 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
706 }
707
708 return err;
709}
710
Jesse Brandeburga6599722014-06-04 08:45:25 +0000711static int i40e_nway_reset(struct net_device *netdev)
712{
713 /* restart autonegotiation */
714 struct i40e_netdev_priv *np = netdev_priv(netdev);
715 struct i40e_pf *pf = np->vsi->back;
716 struct i40e_hw *hw = &pf->hw;
717 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
718 i40e_status ret = 0;
719
720 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
721 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400722 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
723 i40e_stat_str(hw, ret),
724 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000725 return -EIO;
726 }
727
728 return 0;
729}
730
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000731/**
732 * i40e_get_pauseparam - Get Flow Control status
733 * Return tx/rx-pause status
734 **/
735static void i40e_get_pauseparam(struct net_device *netdev,
736 struct ethtool_pauseparam *pause)
737{
738 struct i40e_netdev_priv *np = netdev_priv(netdev);
739 struct i40e_pf *pf = np->vsi->back;
740 struct i40e_hw *hw = &pf->hw;
741 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000742 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000743
744 pause->autoneg =
745 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
746 AUTONEG_ENABLE : AUTONEG_DISABLE);
747
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000748 /* PFC enabled so report LFC as off */
749 if (dcbx_cfg->pfc.pfcenable) {
750 pause->rx_pause = 0;
751 pause->tx_pause = 0;
752 return;
753 }
754
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000755 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000756 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000757 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000758 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000759 } else if (hw->fc.current_mode == I40E_FC_FULL) {
760 pause->rx_pause = 1;
761 pause->tx_pause = 1;
762 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000763}
764
Catherine Sullivan2becc352014-06-04 08:45:27 +0000765/**
766 * i40e_set_pauseparam - Set Flow Control parameter
767 * @netdev: network interface device structure
768 * @pause: return tx/rx flow control status
769 **/
770static int i40e_set_pauseparam(struct net_device *netdev,
771 struct ethtool_pauseparam *pause)
772{
773 struct i40e_netdev_priv *np = netdev_priv(netdev);
774 struct i40e_pf *pf = np->vsi->back;
775 struct i40e_vsi *vsi = np->vsi;
776 struct i40e_hw *hw = &pf->hw;
777 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000778 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000779 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
780 i40e_status status;
781 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000782 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000783
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000784 /* Changing the port's flow control is not supported if this isn't the
785 * port's controlling PF
786 */
787 if (hw->partition_id != 1) {
788 i40e_partition_setting_complaint(pf);
789 return -EOPNOTSUPP;
790 }
791
Catherine Sullivan2becc352014-06-04 08:45:27 +0000792 if (vsi != pf->vsi[pf->lan_vsi])
793 return -EOPNOTSUPP;
794
795 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
796 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
797 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
798 return -EOPNOTSUPP;
799 }
800
801 /* If we have link and don't have autoneg */
802 if (!test_bit(__I40E_DOWN, &pf->state) &&
803 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
804 /* Send message that it might not necessarily work*/
805 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
806 }
807
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000808 if (dcbx_cfg->pfc.pfcenable) {
809 netdev_info(netdev,
810 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000811 return -EOPNOTSUPP;
812 }
813
814 if (pause->rx_pause && pause->tx_pause)
815 hw->fc.requested_mode = I40E_FC_FULL;
816 else if (pause->rx_pause && !pause->tx_pause)
817 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
818 else if (!pause->rx_pause && pause->tx_pause)
819 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
820 else if (!pause->rx_pause && !pause->tx_pause)
821 hw->fc.requested_mode = I40E_FC_NONE;
822 else
823 return -EINVAL;
824
Catherine Sullivan94128512014-07-12 07:28:16 +0000825 /* Tell the OS link is going down, the link will go back up when fw
826 * says it is ready asynchronously
827 */
828 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
829 netif_carrier_off(netdev);
830 netif_tx_stop_all_queues(netdev);
831
Catherine Sullivan2becc352014-06-04 08:45:27 +0000832 /* Set the fc mode and only restart an if link is up*/
833 status = i40e_set_fc(hw, &aq_failures, link_up);
834
835 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400836 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
837 i40e_stat_str(hw, status),
838 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000839 err = -EAGAIN;
840 }
841 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400842 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
843 i40e_stat_str(hw, status),
844 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000845 err = -EAGAIN;
846 }
847 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400848 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
849 i40e_stat_str(hw, status),
850 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000851 err = -EAGAIN;
852 }
853
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000854 if (!test_bit(__I40E_DOWN, &pf->state)) {
855 /* Give it a little more time to try to come back */
856 msleep(75);
857 if (!test_bit(__I40E_DOWN, &pf->state))
858 return i40e_nway_reset(netdev);
859 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000860
861 return err;
862}
863
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000864static u32 i40e_get_msglevel(struct net_device *netdev)
865{
866 struct i40e_netdev_priv *np = netdev_priv(netdev);
867 struct i40e_pf *pf = np->vsi->back;
868
869 return pf->msg_enable;
870}
871
872static void i40e_set_msglevel(struct net_device *netdev, u32 data)
873{
874 struct i40e_netdev_priv *np = netdev_priv(netdev);
875 struct i40e_pf *pf = np->vsi->back;
876
877 if (I40E_DEBUG_USER & data)
878 pf->hw.debug_mask = data;
879 pf->msg_enable = data;
880}
881
882static int i40e_get_regs_len(struct net_device *netdev)
883{
884 int reg_count = 0;
885 int i;
886
887 for (i = 0; i40e_reg_list[i].offset != 0; i++)
888 reg_count += i40e_reg_list[i].elements;
889
890 return reg_count * sizeof(u32);
891}
892
893static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
894 void *p)
895{
896 struct i40e_netdev_priv *np = netdev_priv(netdev);
897 struct i40e_pf *pf = np->vsi->back;
898 struct i40e_hw *hw = &pf->hw;
899 u32 *reg_buf = p;
900 int i, j, ri;
901 u32 reg;
902
903 /* Tell ethtool which driver-version-specific regs output we have.
904 *
905 * At some point, if we have ethtool doing special formatting of
906 * this data, it will rely on this version number to know how to
907 * interpret things. Hence, this needs to be updated if/when the
908 * diags register table is changed.
909 */
910 regs->version = 1;
911
912 /* loop through the diags reg table for what to print */
913 ri = 0;
914 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
915 for (j = 0; j < i40e_reg_list[i].elements; j++) {
916 reg = i40e_reg_list[i].offset
917 + (j * i40e_reg_list[i].stride);
918 reg_buf[ri++] = rd32(hw, reg);
919 }
920 }
921
922}
923
924static int i40e_get_eeprom(struct net_device *netdev,
925 struct ethtool_eeprom *eeprom, u8 *bytes)
926{
927 struct i40e_netdev_priv *np = netdev_priv(netdev);
928 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000929 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000930 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000931 u8 *eeprom_buff;
932 u16 i, sectors;
933 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000934 u32 magic;
935
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000936#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000937 if (eeprom->len == 0)
938 return -EINVAL;
939
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000940 /* check for NVMUpdate access method */
941 magic = hw->vendor_id | (hw->device_id << 16);
942 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000943 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000944 int errno;
945
946 /* make sure it is the right magic for NVMUpdate */
947 if ((eeprom->magic >> 16) != hw->device_id)
948 return -EINVAL;
949
Shannon Nelsonc150a502014-11-13 08:23:13 +0000950 cmd = (struct i40e_nvm_access *)eeprom;
951 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000952 if (ret_val &&
953 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
954 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000955 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000956 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
957 ret_val, hw->aq.asq_last_status, errno,
958 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
959 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000960
961 return errno;
962 }
963
964 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000965 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
966
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000967 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000968 if (!eeprom_buff)
969 return -ENOMEM;
970
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000971 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
972 if (ret_val) {
973 dev_info(&pf->pdev->dev,
974 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
975 ret_val, hw->aq.asq_last_status);
976 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000977 }
978
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000979 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
980 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
981 len = I40E_NVM_SECTOR_SIZE;
982 last = false;
983 for (i = 0; i < sectors; i++) {
984 if (i == (sectors - 1)) {
985 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
986 last = true;
987 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000988 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
989 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000990 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000991 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000992 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000993 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000994 "read NVM failed, invalid offset 0x%x\n",
995 offset);
996 break;
997 } else if (ret_val &&
998 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
999 dev_info(&pf->pdev->dev,
1000 "read NVM failed, access, offset 0x%x\n",
1001 offset);
1002 break;
1003 } else if (ret_val) {
1004 dev_info(&pf->pdev->dev,
1005 "read NVM failed offset %d err=%d status=0x%x\n",
1006 offset, ret_val, hw->aq.asq_last_status);
1007 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001008 }
1009 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001010
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001011 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001012 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001013free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001014 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001015 return ret_val;
1016}
1017
1018static int i40e_get_eeprom_len(struct net_device *netdev)
1019{
1020 struct i40e_netdev_priv *np = netdev_priv(netdev);
1021 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001022 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001024 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1025 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1026 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1027 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001028 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001029 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001030}
1031
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001032static int i40e_set_eeprom(struct net_device *netdev,
1033 struct ethtool_eeprom *eeprom, u8 *bytes)
1034{
1035 struct i40e_netdev_priv *np = netdev_priv(netdev);
1036 struct i40e_hw *hw = &np->vsi->back->hw;
1037 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001038 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001039 int ret_val = 0;
1040 int errno;
1041 u32 magic;
1042
1043 /* normal ethtool set_eeprom is not supported */
1044 magic = hw->vendor_id | (hw->device_id << 16);
1045 if (eeprom->magic == magic)
1046 return -EOPNOTSUPP;
1047
1048 /* check for NVMUpdate access method */
1049 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1050 return -EINVAL;
1051
1052 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1053 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1054 return -EBUSY;
1055
Shannon Nelsonc150a502014-11-13 08:23:13 +00001056 cmd = (struct i40e_nvm_access *)eeprom;
1057 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001058 if (ret_val &&
1059 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1060 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1061 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001062 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001063 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1064 ret_val, hw->aq.asq_last_status, errno,
1065 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1066 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001067
1068 return errno;
1069}
1070
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001071static void i40e_get_drvinfo(struct net_device *netdev,
1072 struct ethtool_drvinfo *drvinfo)
1073{
1074 struct i40e_netdev_priv *np = netdev_priv(netdev);
1075 struct i40e_vsi *vsi = np->vsi;
1076 struct i40e_pf *pf = vsi->back;
1077
1078 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1079 strlcpy(drvinfo->version, i40e_driver_version_str,
1080 sizeof(drvinfo->version));
1081 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1082 sizeof(drvinfo->fw_version));
1083 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1084 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001085 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001086}
1087
1088static void i40e_get_ringparam(struct net_device *netdev,
1089 struct ethtool_ringparam *ring)
1090{
1091 struct i40e_netdev_priv *np = netdev_priv(netdev);
1092 struct i40e_pf *pf = np->vsi->back;
1093 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1094
1095 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1096 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1097 ring->rx_mini_max_pending = 0;
1098 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001099 ring->rx_pending = vsi->rx_rings[0]->count;
1100 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001101 ring->rx_mini_pending = 0;
1102 ring->rx_jumbo_pending = 0;
1103}
1104
1105static int i40e_set_ringparam(struct net_device *netdev,
1106 struct ethtool_ringparam *ring)
1107{
1108 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1109 struct i40e_netdev_priv *np = netdev_priv(netdev);
1110 struct i40e_vsi *vsi = np->vsi;
1111 struct i40e_pf *pf = vsi->back;
1112 u32 new_rx_count, new_tx_count;
1113 int i, err = 0;
1114
1115 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1116 return -EINVAL;
1117
Shannon Nelson1fa18372013-11-20 10:03:08 +00001118 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1119 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1120 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1121 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1122 netdev_info(netdev,
1123 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1124 ring->tx_pending, ring->rx_pending,
1125 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1126 return -EINVAL;
1127 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001128
Shannon Nelson1fa18372013-11-20 10:03:08 +00001129 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1130 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001131
1132 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001133 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1134 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001135 return 0;
1136
1137 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1138 usleep_range(1000, 2000);
1139
1140 if (!netif_running(vsi->netdev)) {
1141 /* simple case - set for the next time the netdev is started */
1142 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001143 vsi->tx_rings[i]->count = new_tx_count;
1144 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001145 }
1146 goto done;
1147 }
1148
1149 /* We can't just free everything and then setup again,
1150 * because the ISRs in MSI-X mode get passed pointers
1151 * to the Tx and Rx ring structs.
1152 */
1153
1154 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001155 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001156 netdev_info(netdev,
1157 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001158 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001159 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1160 sizeof(struct i40e_ring), GFP_KERNEL);
1161 if (!tx_rings) {
1162 err = -ENOMEM;
1163 goto done;
1164 }
1165
1166 for (i = 0; i < vsi->num_queue_pairs; i++) {
1167 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001168 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001169 tx_rings[i].count = new_tx_count;
1170 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1171 if (err) {
1172 while (i) {
1173 i--;
1174 i40e_free_tx_resources(&tx_rings[i]);
1175 }
1176 kfree(tx_rings);
1177 tx_rings = NULL;
1178
1179 goto done;
1180 }
1181 }
1182 }
1183
1184 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001185 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001186 netdev_info(netdev,
1187 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001188 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001189 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1190 sizeof(struct i40e_ring), GFP_KERNEL);
1191 if (!rx_rings) {
1192 err = -ENOMEM;
1193 goto free_tx;
1194 }
1195
1196 for (i = 0; i < vsi->num_queue_pairs; i++) {
1197 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001198 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001199 rx_rings[i].count = new_rx_count;
1200 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1201 if (err) {
1202 while (i) {
1203 i--;
1204 i40e_free_rx_resources(&rx_rings[i]);
1205 }
1206 kfree(rx_rings);
1207 rx_rings = NULL;
1208
1209 goto free_tx;
1210 }
1211 }
1212 }
1213
1214 /* Bring interface down, copy in the new ring info,
1215 * then restore the interface
1216 */
1217 i40e_down(vsi);
1218
1219 if (tx_rings) {
1220 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001221 i40e_free_tx_resources(vsi->tx_rings[i]);
1222 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001223 }
1224 kfree(tx_rings);
1225 tx_rings = NULL;
1226 }
1227
1228 if (rx_rings) {
1229 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001230 i40e_free_rx_resources(vsi->rx_rings[i]);
1231 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 }
1233 kfree(rx_rings);
1234 rx_rings = NULL;
1235 }
1236
1237 i40e_up(vsi);
1238
1239free_tx:
1240 /* error cleanup if the Rx allocations failed after getting Tx */
1241 if (tx_rings) {
1242 for (i = 0; i < vsi->num_queue_pairs; i++)
1243 i40e_free_tx_resources(&tx_rings[i]);
1244 kfree(tx_rings);
1245 tx_rings = NULL;
1246 }
1247
1248done:
1249 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1250
1251 return err;
1252}
1253
1254static int i40e_get_sset_count(struct net_device *netdev, int sset)
1255{
1256 struct i40e_netdev_priv *np = netdev_priv(netdev);
1257 struct i40e_vsi *vsi = np->vsi;
1258 struct i40e_pf *pf = vsi->back;
1259
1260 switch (sset) {
1261 case ETH_SS_TEST:
1262 return I40E_TEST_LEN;
1263 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001264 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001265 int len = I40E_PF_STATS_LEN(netdev);
1266
1267 if (pf->lan_veb != I40E_NO_VEB)
Neerav Parikhfe860af2015-07-10 19:36:02 -04001268 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001269 return len;
1270 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001271 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001272 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001273 case ETH_SS_PRIV_FLAGS:
1274 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001275 default:
1276 return -EOPNOTSUPP;
1277 }
1278}
1279
1280static void i40e_get_ethtool_stats(struct net_device *netdev,
1281 struct ethtool_stats *stats, u64 *data)
1282{
1283 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001284 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001285 struct i40e_vsi *vsi = np->vsi;
1286 struct i40e_pf *pf = vsi->back;
1287 int i = 0;
1288 char *p;
1289 int j;
1290 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001291 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001292
1293 i40e_update_stats(vsi);
1294
1295 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1296 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1297 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1298 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1299 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001300 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1301 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1302 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1303 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1304 }
Vasu Dev38e00432014-08-01 13:27:03 -07001305#ifdef I40E_FCOE
1306 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1307 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1308 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1309 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1310 }
1311#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001312 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001313 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001314 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001315
1316 if (!tx_ring)
1317 continue;
1318
1319 /* process Tx ring statistics */
1320 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001321 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001322 data[i] = tx_ring->stats.packets;
1323 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001324 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001325 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001326
1327 /* Rx ring is the 2nd half of the queue pair */
1328 rx_ring = &tx_ring[1];
1329 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001330 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001331 data[i] = rx_ring->stats.packets;
1332 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001333 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001334 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001335 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001336 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001337 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001338 return;
1339
1340 if (pf->lan_veb != I40E_NO_VEB) {
1341 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1342 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1343 p = (char *)veb;
1344 p += i40e_gstrings_veb_stats[j].stat_offset;
1345 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1346 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001347 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001349 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1350 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1351 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1352 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1353 }
1354 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1355 data[i++] = pf->stats.priority_xon_tx[j];
1356 data[i++] = pf->stats.priority_xoff_tx[j];
1357 }
1358 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1359 data[i++] = pf->stats.priority_xon_rx[j];
1360 data[i++] = pf->stats.priority_xoff_rx[j];
1361 }
1362 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1363 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364}
1365
1366static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1367 u8 *data)
1368{
1369 struct i40e_netdev_priv *np = netdev_priv(netdev);
1370 struct i40e_vsi *vsi = np->vsi;
1371 struct i40e_pf *pf = vsi->back;
1372 char *p = (char *)data;
1373 int i;
1374
1375 switch (stringset) {
1376 case ETH_SS_TEST:
1377 for (i = 0; i < I40E_TEST_LEN; i++) {
1378 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1379 data += ETH_GSTRING_LEN;
1380 }
1381 break;
1382 case ETH_SS_STATS:
1383 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1384 snprintf(p, ETH_GSTRING_LEN, "%s",
1385 i40e_gstrings_net_stats[i].stat_string);
1386 p += ETH_GSTRING_LEN;
1387 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001388 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1389 snprintf(p, ETH_GSTRING_LEN, "%s",
1390 i40e_gstrings_misc_stats[i].stat_string);
1391 p += ETH_GSTRING_LEN;
1392 }
Vasu Dev38e00432014-08-01 13:27:03 -07001393#ifdef I40E_FCOE
1394 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1395 snprintf(p, ETH_GSTRING_LEN, "%s",
1396 i40e_gstrings_fcoe_stats[i].stat_string);
1397 p += ETH_GSTRING_LEN;
1398 }
1399#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400 for (i = 0; i < vsi->num_queue_pairs; i++) {
1401 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1402 p += ETH_GSTRING_LEN;
1403 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1404 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001405 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1406 p += ETH_GSTRING_LEN;
1407 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1408 p += ETH_GSTRING_LEN;
1409 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001410 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001411 return;
1412
1413 if (pf->lan_veb != I40E_NO_VEB) {
1414 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1415 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1416 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417 p += ETH_GSTRING_LEN;
1418 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001419 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1420 snprintf(p, ETH_GSTRING_LEN,
1421 "veb.tc_%u_tx_packets", i);
1422 p += ETH_GSTRING_LEN;
1423 snprintf(p, ETH_GSTRING_LEN,
1424 "veb.tc_%u_tx_bytes", i);
1425 p += ETH_GSTRING_LEN;
1426 snprintf(p, ETH_GSTRING_LEN,
1427 "veb.tc_%u_rx_packets", i);
1428 p += ETH_GSTRING_LEN;
1429 snprintf(p, ETH_GSTRING_LEN,
1430 "veb.tc_%u_rx_bytes", i);
1431 p += ETH_GSTRING_LEN;
1432 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001433 }
1434 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1435 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1436 i40e_gstrings_stats[i].stat_string);
1437 p += ETH_GSTRING_LEN;
1438 }
1439 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1440 snprintf(p, ETH_GSTRING_LEN,
1441 "port.tx_priority_%u_xon", i);
1442 p += ETH_GSTRING_LEN;
1443 snprintf(p, ETH_GSTRING_LEN,
1444 "port.tx_priority_%u_xoff", i);
1445 p += ETH_GSTRING_LEN;
1446 }
1447 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1448 snprintf(p, ETH_GSTRING_LEN,
1449 "port.rx_priority_%u_xon", i);
1450 p += ETH_GSTRING_LEN;
1451 snprintf(p, ETH_GSTRING_LEN,
1452 "port.rx_priority_%u_xoff", i);
1453 p += ETH_GSTRING_LEN;
1454 }
1455 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1456 snprintf(p, ETH_GSTRING_LEN,
1457 "port.rx_priority_%u_xon_2_xoff", i);
1458 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001459 }
1460 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1461 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001462 case ETH_SS_PRIV_FLAGS:
1463 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1464 memcpy(data, i40e_priv_flags_strings[i],
1465 ETH_GSTRING_LEN);
1466 data += ETH_GSTRING_LEN;
1467 }
1468 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001469 default:
1470 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001471 }
1472}
1473
1474static int i40e_get_ts_info(struct net_device *dev,
1475 struct ethtool_ts_info *info)
1476{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001477 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1478
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001479 /* only report HW timestamping if PTP is enabled */
1480 if (!(pf->flags & I40E_FLAG_PTP))
1481 return ethtool_op_get_ts_info(dev, info);
1482
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001483 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1484 SOF_TIMESTAMPING_RX_SOFTWARE |
1485 SOF_TIMESTAMPING_SOFTWARE |
1486 SOF_TIMESTAMPING_TX_HARDWARE |
1487 SOF_TIMESTAMPING_RX_HARDWARE |
1488 SOF_TIMESTAMPING_RAW_HARDWARE;
1489
1490 if (pf->ptp_clock)
1491 info->phc_index = ptp_clock_index(pf->ptp_clock);
1492 else
1493 info->phc_index = -1;
1494
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001495 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001496
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001497 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1498 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1499 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001500
1501 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001502}
1503
Shannon Nelson7b086392013-11-20 10:02:59 +00001504static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505{
Shannon Nelson7b086392013-11-20 10:02:59 +00001506 struct i40e_netdev_priv *np = netdev_priv(netdev);
1507 struct i40e_pf *pf = np->vsi->back;
1508
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001509 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001510 if (i40e_get_link_status(&pf->hw))
1511 *data = 0;
1512 else
1513 *data = 1;
1514
1515 return *data;
1516}
1517
Shannon Nelson7b086392013-11-20 10:02:59 +00001518static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519{
Shannon Nelson7b086392013-11-20 10:02:59 +00001520 struct i40e_netdev_priv *np = netdev_priv(netdev);
1521 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001523 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001524 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001525
Shannon Nelson7b086392013-11-20 10:02:59 +00001526 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001527}
1528
Shannon Nelson7b086392013-11-20 10:02:59 +00001529static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001530{
Shannon Nelson7b086392013-11-20 10:02:59 +00001531 struct i40e_netdev_priv *np = netdev_priv(netdev);
1532 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001533
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001534 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001535 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536
Shannon Nelson4443ec92014-11-13 08:23:12 +00001537 /* forcebly clear the NVM Update state machine */
1538 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1539
Shannon Nelson7b086392013-11-20 10:02:59 +00001540 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001541}
1542
Shannon Nelson7b086392013-11-20 10:02:59 +00001543static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001544{
Shannon Nelson7b086392013-11-20 10:02:59 +00001545 struct i40e_netdev_priv *np = netdev_priv(netdev);
1546 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001547 u16 swc_old = pf->sw_int_count;
1548
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001549 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001550 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1551 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001552 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1553 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1554 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1555 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001556 usleep_range(1000, 2000);
1557 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558
1559 return *data;
1560}
1561
Shannon Nelson7b086392013-11-20 10:02:59 +00001562static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001564 struct i40e_netdev_priv *np = netdev_priv(netdev);
1565 struct i40e_pf *pf = np->vsi->back;
1566
1567 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001568 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001569
1570 return *data;
1571}
1572
Greg Rosee17bc412015-04-16 20:05:59 -04001573static inline bool i40e_active_vfs(struct i40e_pf *pf)
1574{
1575 struct i40e_vf *vfs = pf->vf;
1576 int i;
1577
1578 for (i = 0; i < pf->num_alloc_vfs; i++)
1579 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1580 return true;
1581 return false;
1582}
1583
Greg Rose510efb22015-07-10 19:36:01 -04001584static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1585{
1586 struct i40e_vsi **vsi = pf->vsi;
1587 int i;
1588
1589 for (i = 0; i < pf->num_alloc_vsi; i++) {
1590 if (!vsi[i])
1591 continue;
1592 if (vsi[i]->type == I40E_VSI_VMDQ2)
1593 return true;
1594 }
1595
1596 return false;
1597}
1598
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001599static void i40e_diag_test(struct net_device *netdev,
1600 struct ethtool_test *eth_test, u64 *data)
1601{
1602 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001603 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001604 struct i40e_pf *pf = np->vsi->back;
1605
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001606 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1607 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001608 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609
Shannon Nelsonf551b432013-11-26 10:49:12 +00001610 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001611
Greg Rose510efb22015-07-10 19:36:01 -04001612 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001613 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001614 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001615 data[I40E_ETH_TEST_REG] = 1;
1616 data[I40E_ETH_TEST_EEPROM] = 1;
1617 data[I40E_ETH_TEST_INTR] = 1;
1618 data[I40E_ETH_TEST_LOOPBACK] = 1;
1619 data[I40E_ETH_TEST_LINK] = 1;
1620 eth_test->flags |= ETH_TEST_FL_FAILED;
1621 clear_bit(__I40E_TESTING, &pf->state);
1622 goto skip_ol_tests;
1623 }
1624
Greg Rose5b86c5c2015-02-26 16:14:35 +00001625 /* If the device is online then take it offline */
1626 if (if_running)
1627 /* indicate we're in test mode */
1628 dev_close(netdev);
1629 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001630 /* This reset does not affect link - if it is
1631 * changed to a type of reset that does affect
1632 * link then the following link test would have
1633 * to be moved to before the reset
1634 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001635 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001636
Shannon Nelson7b086392013-11-20 10:02:59 +00001637 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001638 eth_test->flags |= ETH_TEST_FL_FAILED;
1639
Shannon Nelson7b086392013-11-20 10:02:59 +00001640 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001641 eth_test->flags |= ETH_TEST_FL_FAILED;
1642
Shannon Nelson7b086392013-11-20 10:02:59 +00001643 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001644 eth_test->flags |= ETH_TEST_FL_FAILED;
1645
Shannon Nelson7b086392013-11-20 10:02:59 +00001646 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001647 eth_test->flags |= ETH_TEST_FL_FAILED;
1648
Shannon Nelsonf551b432013-11-26 10:49:12 +00001649 /* run reg test last, a reset is required after it */
1650 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1651 eth_test->flags |= ETH_TEST_FL_FAILED;
1652
1653 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001654 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001655
1656 if (if_running)
1657 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001659 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001660 netif_info(pf, drv, netdev, "online testing starting\n");
1661
Shannon Nelson7b086392013-11-20 10:02:59 +00001662 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001663 eth_test->flags |= ETH_TEST_FL_FAILED;
1664
1665 /* Offline only tests, not run in online; pass by default */
1666 data[I40E_ETH_TEST_REG] = 0;
1667 data[I40E_ETH_TEST_EEPROM] = 0;
1668 data[I40E_ETH_TEST_INTR] = 0;
1669 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001670 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001671
Greg Rosee17bc412015-04-16 20:05:59 -04001672skip_ol_tests:
1673
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001674 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001675}
1676
1677static void i40e_get_wol(struct net_device *netdev,
1678 struct ethtool_wolinfo *wol)
1679{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001680 struct i40e_netdev_priv *np = netdev_priv(netdev);
1681 struct i40e_pf *pf = np->vsi->back;
1682 struct i40e_hw *hw = &pf->hw;
1683 u16 wol_nvm_bits;
1684
1685 /* NVM bit on means WoL disabled for the port */
1686 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001687 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001688 wol->supported = 0;
1689 wol->wolopts = 0;
1690 } else {
1691 wol->supported = WAKE_MAGIC;
1692 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1693 }
1694}
1695
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001696/**
1697 * i40e_set_wol - set the WakeOnLAN configuration
1698 * @netdev: the netdev in question
1699 * @wol: the ethtool WoL setting data
1700 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001701static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1702{
1703 struct i40e_netdev_priv *np = netdev_priv(netdev);
1704 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001705 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001706 struct i40e_hw *hw = &pf->hw;
1707 u16 wol_nvm_bits;
1708
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001709 /* WoL not supported if this isn't the controlling PF on the port */
1710 if (hw->partition_id != 1) {
1711 i40e_partition_setting_complaint(pf);
1712 return -EOPNOTSUPP;
1713 }
1714
1715 if (vsi != pf->vsi[pf->lan_vsi])
1716 return -EOPNOTSUPP;
1717
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001718 /* NVM bit on means WoL disabled for the port */
1719 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001720 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001721 return -EOPNOTSUPP;
1722
1723 /* only magic packet is supported */
1724 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1725 return -EOPNOTSUPP;
1726
1727 /* is this a new value? */
1728 if (pf->wol_en != !!wol->wolopts) {
1729 pf->wol_en = !!wol->wolopts;
1730 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1731 }
1732
1733 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001734}
1735
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001736static int i40e_set_phys_id(struct net_device *netdev,
1737 enum ethtool_phys_id_state state)
1738{
1739 struct i40e_netdev_priv *np = netdev_priv(netdev);
1740 struct i40e_pf *pf = np->vsi->back;
1741 struct i40e_hw *hw = &pf->hw;
1742 int blink_freq = 2;
1743
1744 switch (state) {
1745 case ETHTOOL_ID_ACTIVE:
1746 pf->led_status = i40e_led_get(hw);
1747 return blink_freq;
1748 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001749 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001750 break;
1751 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001752 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001753 break;
1754 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001755 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001756 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001757 default:
1758 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001759 }
1760
1761 return 0;
1762}
1763
1764/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1765 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1766 * 125us (8000 interrupts per second) == ITR(62)
1767 */
1768
1769static int i40e_get_coalesce(struct net_device *netdev,
1770 struct ethtool_coalesce *ec)
1771{
1772 struct i40e_netdev_priv *np = netdev_priv(netdev);
1773 struct i40e_vsi *vsi = np->vsi;
1774
1775 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1776 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1777
1778 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001779 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001780
1781 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001782 ec->use_adaptive_tx_coalesce = 1;
1783
1784 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1785 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001786
1787 return 0;
1788}
1789
1790static int i40e_set_coalesce(struct net_device *netdev,
1791 struct ethtool_coalesce *ec)
1792{
1793 struct i40e_netdev_priv *np = netdev_priv(netdev);
1794 struct i40e_q_vector *q_vector;
1795 struct i40e_vsi *vsi = np->vsi;
1796 struct i40e_pf *pf = vsi->back;
1797 struct i40e_hw *hw = &pf->hw;
1798 u16 vector;
1799 int i;
1800
1801 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1802 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1803
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001804 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001805 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001806 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001808 } else if (ec->rx_coalesce_usecs == 0) {
1809 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001810 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001811 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 +00001812 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001813 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001814 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001815 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001816
Mitch Williams32f5f542014-04-04 04:43:10 +00001817 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001818 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001820 } else if (ec->tx_coalesce_usecs == 0) {
1821 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001822 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001823 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 +00001824 } else {
1825 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001826 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001827 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001828 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001829
1830 if (ec->use_adaptive_rx_coalesce)
1831 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1832 else
1833 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1834
1835 if (ec->use_adaptive_tx_coalesce)
1836 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1837 else
1838 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001839
Alexander Duyck493fb302013-09-28 07:01:44 +00001840 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1841 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001842 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1843 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1844 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1845 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1846 i40e_flush(hw);
1847 }
1848
1849 return 0;
1850}
1851
1852/**
1853 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1854 * @pf: pointer to the physical function struct
1855 * @cmd: ethtool rxnfc command
1856 *
1857 * Returns Success if the flow is supported, else Invalid Input.
1858 **/
1859static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1860{
1861 cmd->data = 0;
1862
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001863 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1864 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1865 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1866 return 0;
1867 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001868 /* Report default options for RSS on i40e */
1869 switch (cmd->flow_type) {
1870 case TCP_V4_FLOW:
1871 case UDP_V4_FLOW:
1872 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1873 /* fall through to add IP fields */
1874 case SCTP_V4_FLOW:
1875 case AH_ESP_V4_FLOW:
1876 case AH_V4_FLOW:
1877 case ESP_V4_FLOW:
1878 case IPV4_FLOW:
1879 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1880 break;
1881 case TCP_V6_FLOW:
1882 case UDP_V6_FLOW:
1883 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1884 /* fall through to add IP fields */
1885 case SCTP_V6_FLOW:
1886 case AH_ESP_V6_FLOW:
1887 case AH_V6_FLOW:
1888 case ESP_V6_FLOW:
1889 case IPV6_FLOW:
1890 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1891 break;
1892 default:
1893 return -EINVAL;
1894 }
1895
1896 return 0;
1897}
1898
1899/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001900 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1901 * @pf: Pointer to the physical function struct
1902 * @cmd: The command to get or set Rx flow classification rules
1903 * @rule_locs: Array of used rule locations
1904 *
1905 * This function populates both the total and actual rule count of
1906 * the ethtool flow classification command
1907 *
1908 * Returns 0 on success or -EMSGSIZE if entry not found
1909 **/
1910static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1911 struct ethtool_rxnfc *cmd,
1912 u32 *rule_locs)
1913{
1914 struct i40e_fdir_filter *rule;
1915 struct hlist_node *node2;
1916 int cnt = 0;
1917
1918 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001919 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001920
1921 hlist_for_each_entry_safe(rule, node2,
1922 &pf->fdir_filter_list, fdir_node) {
1923 if (cnt == cmd->rule_cnt)
1924 return -EMSGSIZE;
1925
1926 rule_locs[cnt] = rule->fd_id;
1927 cnt++;
1928 }
1929
1930 cmd->rule_cnt = cnt;
1931
1932 return 0;
1933}
1934
1935/**
1936 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1937 * @pf: Pointer to the physical function struct
1938 * @cmd: The command to get or set Rx flow classification rules
1939 *
1940 * This function looks up a filter based on the Rx flow classification
1941 * command and fills the flow spec info for it if found
1942 *
1943 * Returns 0 on success or -EINVAL if filter not found
1944 **/
1945static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1946 struct ethtool_rxnfc *cmd)
1947{
1948 struct ethtool_rx_flow_spec *fsp =
1949 (struct ethtool_rx_flow_spec *)&cmd->fs;
1950 struct i40e_fdir_filter *rule = NULL;
1951 struct hlist_node *node2;
1952
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001953 hlist_for_each_entry_safe(rule, node2,
1954 &pf->fdir_filter_list, fdir_node) {
1955 if (fsp->location <= rule->fd_id)
1956 break;
1957 }
1958
1959 if (!rule || fsp->location != rule->fd_id)
1960 return -EINVAL;
1961
1962 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001963 if (fsp->flow_type == IP_USER_FLOW) {
1964 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1965 fsp->h_u.usr_ip4_spec.proto = 0;
1966 fsp->m_u.usr_ip4_spec.proto = 0;
1967 }
1968
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001969 /* Reverse the src and dest notion, since the HW views them from
1970 * Tx perspective where as the user expects it from Rx filter view.
1971 */
1972 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1973 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1974 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1975 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001976
1977 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1978 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1979 else
1980 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001981
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04001982 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1983 struct i40e_vsi *vsi;
1984
1985 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1986 if (vsi && vsi->type == I40E_VSI_SRIOV) {
1987 fsp->h_ext.data[1] = htonl(vsi->vf_id);
1988 fsp->m_ext.data[1] = htonl(0x1);
1989 }
1990 }
1991
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001992 return 0;
1993}
1994
1995/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001996 * i40e_get_rxnfc - command to get RX flow classification rules
1997 * @netdev: network interface device structure
1998 * @cmd: ethtool rxnfc command
1999 *
2000 * Returns Success if the command is supported.
2001 **/
2002static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2003 u32 *rule_locs)
2004{
2005 struct i40e_netdev_priv *np = netdev_priv(netdev);
2006 struct i40e_vsi *vsi = np->vsi;
2007 struct i40e_pf *pf = vsi->back;
2008 int ret = -EOPNOTSUPP;
2009
2010 switch (cmd->cmd) {
2011 case ETHTOOL_GRXRINGS:
2012 cmd->data = vsi->alloc_queue_pairs;
2013 ret = 0;
2014 break;
2015 case ETHTOOL_GRXFH:
2016 ret = i40e_get_rss_hash_opts(pf, cmd);
2017 break;
2018 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002019 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002020 /* report total rule count */
2021 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002022 ret = 0;
2023 break;
2024 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002025 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002026 break;
2027 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002028 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2029 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002030 default:
2031 break;
2032 }
2033
2034 return ret;
2035}
2036
2037/**
2038 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2039 * @pf: pointer to the physical function struct
2040 * @cmd: ethtool rxnfc command
2041 *
2042 * Returns Success if the flow input set is supported.
2043 **/
2044static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2045{
2046 struct i40e_hw *hw = &pf->hw;
2047 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2048 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2049
2050 /* RSS does not support anything other than hashing
2051 * to queues on src and dst IPs and ports
2052 */
2053 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2054 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2055 return -EINVAL;
2056
2057 /* We need at least the IP SRC and DEST fields for hashing */
2058 if (!(nfc->data & RXH_IP_SRC) ||
2059 !(nfc->data & RXH_IP_DST))
2060 return -EINVAL;
2061
2062 switch (nfc->flow_type) {
2063 case TCP_V4_FLOW:
2064 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2065 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002066 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002067 break;
2068 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002069 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002070 break;
2071 default:
2072 return -EINVAL;
2073 }
2074 break;
2075 case TCP_V6_FLOW:
2076 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2077 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002078 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002079 break;
2080 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002081 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002082 break;
2083 default:
2084 return -EINVAL;
2085 }
2086 break;
2087 case UDP_V4_FLOW:
2088 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2089 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002090 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2091 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002092 break;
2093 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
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 default:
2098 return -EINVAL;
2099 }
2100 break;
2101 case UDP_V6_FLOW:
2102 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2103 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002104 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2105 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002106 break;
2107 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
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 default:
2112 return -EINVAL;
2113 }
2114 break;
2115 case AH_ESP_V4_FLOW:
2116 case AH_V4_FLOW:
2117 case ESP_V4_FLOW:
2118 case SCTP_V4_FLOW:
2119 if ((nfc->data & RXH_L4_B_0_1) ||
2120 (nfc->data & RXH_L4_B_2_3))
2121 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002122 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002123 break;
2124 case AH_ESP_V6_FLOW:
2125 case AH_V6_FLOW:
2126 case ESP_V6_FLOW:
2127 case SCTP_V6_FLOW:
2128 if ((nfc->data & RXH_L4_B_0_1) ||
2129 (nfc->data & RXH_L4_B_2_3))
2130 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002131 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002132 break;
2133 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002134 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2135 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002136 break;
2137 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002138 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2139 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140 break;
2141 default:
2142 return -EINVAL;
2143 }
2144
2145 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2146 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2147 i40e_flush(hw);
2148
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002149 /* Save setting for future output/update */
2150 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2151
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002152 return 0;
2153}
2154
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002156 * i40e_match_fdir_input_set - Match a new filter against an existing one
2157 * @rule: The filter already added
2158 * @input: The new filter to comapre against
2159 *
2160 * Returns true if the two input set match
2161 **/
2162static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2163 struct i40e_fdir_filter *input)
2164{
2165 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2166 (rule->src_ip[0] != input->src_ip[0]) ||
2167 (rule->dst_port != input->dst_port) ||
2168 (rule->src_port != input->src_port))
2169 return false;
2170 return true;
2171}
2172
2173/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002174 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2175 * @vsi: Pointer to the targeted VSI
2176 * @input: The filter to update or NULL to indicate deletion
2177 * @sw_idx: Software index to the filter
2178 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002179 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002180 * This function updates (or deletes) a Flow Director entry from
2181 * the hlist of the corresponding PF
2182 *
2183 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002185static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2186 struct i40e_fdir_filter *input,
2187 u16 sw_idx,
2188 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002189{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002190 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002191 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002192 struct hlist_node *node2;
2193 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002194
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002195 parent = NULL;
2196 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002197
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002198 hlist_for_each_entry_safe(rule, node2,
2199 &pf->fdir_filter_list, fdir_node) {
2200 /* hash found, or no matching entry */
2201 if (rule->fd_id >= sw_idx)
2202 break;
2203 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204 }
2205
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002206 /* if there is an old rule occupying our place remove it */
2207 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002208 if (input && !i40e_match_fdir_input_set(rule, input))
2209 err = i40e_add_del_fdir(vsi, rule, false);
2210 else if (!input)
2211 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002212 hlist_del(&rule->fdir_node);
2213 kfree(rule);
2214 pf->fdir_pf_active_filters--;
2215 }
2216
2217 /* If no input this was a delete, err should be 0 if a rule was
2218 * successfully found and removed from the list else -EINVAL
2219 */
2220 if (!input)
2221 return err;
2222
2223 /* initialize node and set software index */
2224 INIT_HLIST_NODE(&input->fdir_node);
2225
2226 /* add filter to the list */
2227 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002228 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002229 else
2230 hlist_add_head(&input->fdir_node,
2231 &pf->fdir_filter_list);
2232
2233 /* update counts */
2234 pf->fdir_pf_active_filters++;
2235
2236 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002237}
2238
2239/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002240 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2241 * @vsi: Pointer to the targeted VSI
2242 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002243 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002244 * The function removes a Flow Director filter entry from the
2245 * hlist of the corresponding PF
2246 *
2247 * Returns 0 on success
2248 */
2249static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2250 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002251{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002252 struct ethtool_rx_flow_spec *fsp =
2253 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002254 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002255 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002256
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002257 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2258 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2259 return -EBUSY;
2260
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002261 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2262 return -EBUSY;
2263
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002264 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002265
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002266 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002267 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002268}
2269
2270/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002271 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002272 * @vsi: pointer to the targeted VSI
2273 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002274 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002275 * Add Flow Director filters for a specific flow spec based on their
2276 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002277 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002278static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2279 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002280{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002281 struct ethtool_rx_flow_spec *fsp;
2282 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002283 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002284 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002285 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002286
2287 if (!vsi)
2288 return -EINVAL;
2289
2290 pf = vsi->back;
2291
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002292 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2293 return -EOPNOTSUPP;
2294
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002295 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002296 return -ENOSPC;
2297
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002298 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2299 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2300 return -EBUSY;
2301
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002302 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2303 return -EBUSY;
2304
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002305 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2306
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002307 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2308 pf->hw.func_caps.fd_filters_guaranteed)) {
2309 return -EINVAL;
2310 }
2311
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002312 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2313 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002314 return -EINVAL;
2315
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002316 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002317
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002318 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002319 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002320
2321 input->fd_id = fsp->location;
2322
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002323 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2324 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2325 else
2326 input->dest_ctl =
2327 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2328
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002329 input->q_index = fsp->ring_cookie;
2330 input->flex_off = 0;
2331 input->pctype = 0;
2332 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002333 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002334 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002335 input->flow_type = fsp->flow_type;
2336 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002337
2338 /* Reverse the src and dest notion, since the HW expects them to be from
2339 * Tx perspective where as the input from user is from Rx filter view.
2340 */
2341 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2342 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2343 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2344 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002345
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002346 if (ntohl(fsp->m_ext.data[1])) {
2347 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2348 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2349 goto free_input;
2350 }
2351 vf_id = ntohl(fsp->h_ext.data[1]);
2352 /* Find vsi id from vf id and override dest vsi */
2353 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2354 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2355 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2356 goto free_input;
2357 }
2358 }
2359
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002360 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002361free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002362 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002363 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002364 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002365 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002366
2367 return ret;
2368}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002369
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002370/**
2371 * i40e_set_rxnfc - command to set RX flow classification rules
2372 * @netdev: network interface device structure
2373 * @cmd: ethtool rxnfc command
2374 *
2375 * Returns Success if the command is supported.
2376 **/
2377static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2378{
2379 struct i40e_netdev_priv *np = netdev_priv(netdev);
2380 struct i40e_vsi *vsi = np->vsi;
2381 struct i40e_pf *pf = vsi->back;
2382 int ret = -EOPNOTSUPP;
2383
2384 switch (cmd->cmd) {
2385 case ETHTOOL_SRXFH:
2386 ret = i40e_set_rss_hash_opt(pf, cmd);
2387 break;
2388 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002389 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002390 break;
2391 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002392 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002393 break;
2394 default:
2395 break;
2396 }
2397
2398 return ret;
2399}
2400
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002401/**
2402 * i40e_max_channels - get Max number of combined channels supported
2403 * @vsi: vsi pointer
2404 **/
2405static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2406{
2407 /* TODO: This code assumes DCB and FD is disabled for now. */
2408 return vsi->alloc_queue_pairs;
2409}
2410
2411/**
2412 * i40e_get_channels - Get the current channels enabled and max supported etc.
2413 * @netdev: network interface device structure
2414 * @ch: ethtool channels structure
2415 *
2416 * We don't support separate tx and rx queues as channels. The other count
2417 * represents how many queues are being used for control. max_combined counts
2418 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2419 * q_vectors since we support a lot more queue pairs than q_vectors.
2420 **/
2421static void i40e_get_channels(struct net_device *dev,
2422 struct ethtool_channels *ch)
2423{
2424 struct i40e_netdev_priv *np = netdev_priv(dev);
2425 struct i40e_vsi *vsi = np->vsi;
2426 struct i40e_pf *pf = vsi->back;
2427
2428 /* report maximum channels */
2429 ch->max_combined = i40e_max_channels(vsi);
2430
2431 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002432 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002433 ch->max_other = ch->other_count;
2434
2435 /* Note: This code assumes DCB is disabled for now. */
2436 ch->combined_count = vsi->num_queue_pairs;
2437}
2438
2439/**
2440 * i40e_set_channels - Set the new channels count.
2441 * @netdev: network interface device structure
2442 * @ch: ethtool channels structure
2443 *
2444 * The new channels count may not be the same as requested by the user
2445 * since it gets rounded down to a power of 2 value.
2446 **/
2447static int i40e_set_channels(struct net_device *dev,
2448 struct ethtool_channels *ch)
2449{
2450 struct i40e_netdev_priv *np = netdev_priv(dev);
2451 unsigned int count = ch->combined_count;
2452 struct i40e_vsi *vsi = np->vsi;
2453 struct i40e_pf *pf = vsi->back;
2454 int new_count;
2455
2456 /* We do not support setting channels for any other VSI at present */
2457 if (vsi->type != I40E_VSI_MAIN)
2458 return -EINVAL;
2459
2460 /* verify they are not requesting separate vectors */
2461 if (!count || ch->rx_count || ch->tx_count)
2462 return -EINVAL;
2463
2464 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002465 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002466 return -EINVAL;
2467
2468 /* verify the number of channels does not exceed hardware limits */
2469 if (count > i40e_max_channels(vsi))
2470 return -EINVAL;
2471
2472 /* update feature limits from largest to smallest supported values */
2473 /* TODO: Flow director limit, DCB etc */
2474
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002475 /* use rss_reconfig to rebuild with new queue count and update traffic
2476 * class queue mapping
2477 */
2478 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002479 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002480 return 0;
2481 else
2482 return -EINVAL;
2483}
2484
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002485#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2486/**
2487 * i40e_get_rxfh_key_size - get the RSS hash key size
2488 * @netdev: network interface device structure
2489 *
2490 * Returns the table size.
2491 **/
2492static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2493{
2494 return I40E_HKEY_ARRAY_SIZE;
2495}
2496
2497/**
2498 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2499 * @netdev: network interface device structure
2500 *
2501 * Returns the table size.
2502 **/
2503static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2504{
2505 return I40E_HLUT_ARRAY_SIZE;
2506}
2507
2508static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2509 u8 *hfunc)
2510{
2511 struct i40e_netdev_priv *np = netdev_priv(netdev);
2512 struct i40e_vsi *vsi = np->vsi;
2513 struct i40e_pf *pf = vsi->back;
2514 struct i40e_hw *hw = &pf->hw;
2515 u32 reg_val;
2516 int i, j;
2517
2518 if (hfunc)
2519 *hfunc = ETH_RSS_HASH_TOP;
2520
2521 if (!indir)
2522 return 0;
2523
2524 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2525 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2526 indir[j++] = reg_val & 0xff;
2527 indir[j++] = (reg_val >> 8) & 0xff;
2528 indir[j++] = (reg_val >> 16) & 0xff;
2529 indir[j++] = (reg_val >> 24) & 0xff;
2530 }
2531
2532 if (key) {
2533 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2534 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2535 key[j++] = (u8)(reg_val & 0xff);
2536 key[j++] = (u8)((reg_val >> 8) & 0xff);
2537 key[j++] = (u8)((reg_val >> 16) & 0xff);
2538 key[j++] = (u8)((reg_val >> 24) & 0xff);
2539 }
2540 }
2541 return 0;
2542}
2543
2544/**
2545 * i40e_set_rxfh - set the rx flow hash indirection table
2546 * @netdev: network interface device structure
2547 * @indir: indirection table
2548 * @key: hash key
2549 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002550 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002551 * returns 0 after programming the table.
2552 **/
2553static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2554 const u8 *key, const u8 hfunc)
2555{
2556 struct i40e_netdev_priv *np = netdev_priv(netdev);
2557 struct i40e_vsi *vsi = np->vsi;
2558 struct i40e_pf *pf = vsi->back;
2559 struct i40e_hw *hw = &pf->hw;
2560 u32 reg_val;
2561 int i, j;
2562
2563 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2564 return -EOPNOTSUPP;
2565
2566 if (!indir)
2567 return 0;
2568
2569 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2570 reg_val = indir[j++];
2571 reg_val |= indir[j++] << 8;
2572 reg_val |= indir[j++] << 16;
2573 reg_val |= indir[j++] << 24;
2574 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2575 }
2576
2577 if (key) {
2578 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2579 reg_val = key[j++];
2580 reg_val |= key[j++] << 8;
2581 reg_val |= key[j++] << 16;
2582 reg_val |= key[j++] << 24;
2583 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2584 }
2585 }
2586 return 0;
2587}
2588
Greg Rose7e45ab42015-02-06 08:52:19 +00002589/**
2590 * i40e_get_priv_flags - report device private flags
2591 * @dev: network interface device structure
2592 *
2593 * The get string set count and the string set should be matched for each
2594 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2595 * array.
2596 *
2597 * Returns a u32 bitmap of flags.
2598 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002599static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002600{
2601 struct i40e_netdev_priv *np = netdev_priv(dev);
2602 struct i40e_vsi *vsi = np->vsi;
2603 struct i40e_pf *pf = vsi->back;
2604 u32 ret_flags = 0;
2605
2606 ret_flags |= pf->hw.func_caps.npar_enable ?
2607 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2608
2609 return ret_flags;
2610}
2611
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002612static const struct ethtool_ops i40e_ethtool_ops = {
2613 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002614 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002615 .get_drvinfo = i40e_get_drvinfo,
2616 .get_regs_len = i40e_get_regs_len,
2617 .get_regs = i40e_get_regs,
2618 .nway_reset = i40e_nway_reset,
2619 .get_link = ethtool_op_get_link,
2620 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002621 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002622 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002623 .get_eeprom_len = i40e_get_eeprom_len,
2624 .get_eeprom = i40e_get_eeprom,
2625 .get_ringparam = i40e_get_ringparam,
2626 .set_ringparam = i40e_set_ringparam,
2627 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002628 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002629 .get_msglevel = i40e_get_msglevel,
2630 .set_msglevel = i40e_set_msglevel,
2631 .get_rxnfc = i40e_get_rxnfc,
2632 .set_rxnfc = i40e_set_rxnfc,
2633 .self_test = i40e_diag_test,
2634 .get_strings = i40e_get_strings,
2635 .set_phys_id = i40e_set_phys_id,
2636 .get_sset_count = i40e_get_sset_count,
2637 .get_ethtool_stats = i40e_get_ethtool_stats,
2638 .get_coalesce = i40e_get_coalesce,
2639 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002640 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2641 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2642 .get_rxfh = i40e_get_rxfh,
2643 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002644 .get_channels = i40e_get_channels,
2645 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002646 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002647 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002648};
2649
2650void i40e_set_ethtool_ops(struct net_device *netdev)
2651{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002652 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002653}