blob: 1fa38f6e0e194fc46511f0b297b020cf309bcd75 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Shannon Nelson41a9e552014-04-23 04:50:20 +000090};
91
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000092static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
93 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000094
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000095/* These PF_STATs might look like duplicates of some NETDEV_STATs,
96 * but they are separate. This device supports Virtualization, and
97 * as such might have several netdevs supporting VMDq and FCoE going
98 * through a single port. The NETDEV_STATs are for individual netdevs
99 * seen at the top of the stack, and the PF_STATs are for the physical
100 * function at the bottom of the stack hosting those netdevs.
101 *
102 * The PF_STATs are appended to the netdev stats only when ethtool -S
103 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104 */
105static struct i40e_stats i40e_gstrings_stats[] = {
106 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
107 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000108 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
109 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
110 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
111 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
112 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
113 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000114 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
115 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400117 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400150 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400151 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400153 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000154
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000155 /* LPI stats */
156 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
157 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
158 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
159 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000160};
161
Vasu Dev38e00432014-08-01 13:27:03 -0700162#ifdef I40E_FCOE
163static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
164 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
165 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
166 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
167 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
168 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
169 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
170 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
171 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
172};
173
174#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000175#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000176 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
177 * 2 /* Tx and Rx together */ \
178 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000179#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
180#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000181#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700182#ifdef I40E_FCOE
183#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
184#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
185 I40E_FCOE_STATS_LEN + \
186 I40E_MISC_STATS_LEN + \
187 I40E_QUEUE_STATS_LEN((n)))
188#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000190 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700192#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000193#define I40E_PFC_STATS_LEN ( \
194 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
199 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400200#define I40E_VEB_TC_STATS_LEN ( \
201 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
205 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000206#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400207#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000208#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
209 I40E_PFC_STATS_LEN + \
210 I40E_VSI_STATS_LEN((n)))
211
212enum i40e_ethtool_test_id {
213 I40E_ETH_TEST_REG = 0,
214 I40E_ETH_TEST_EEPROM,
215 I40E_ETH_TEST_INTR,
216 I40E_ETH_TEST_LOOPBACK,
217 I40E_ETH_TEST_LINK,
218};
219
220static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
221 "Register test (offline)",
222 "Eeprom test (offline)",
223 "Interrupt test (offline)",
224 "Loopback test (offline)",
225 "Link test (on/offline)"
226};
227
228#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
229
Greg Rose7e45ab42015-02-06 08:52:19 +0000230static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
231 "NPAR",
232};
233
234#define I40E_PRIV_FLAGS_STR_LEN \
235 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
236
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000237/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000238 * i40e_partition_setting_complaint - generic complaint for MFP restriction
239 * @pf: the PF struct
240 **/
241static void i40e_partition_setting_complaint(struct i40e_pf *pf)
242{
243 dev_info(&pf->pdev->dev,
244 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
245}
246
247/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000248 * i40e_get_settings_link_up - Get the Link settings for when link is up
249 * @hw: hw structure
250 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000254static void i40e_get_settings_link_up(struct i40e_hw *hw,
255 struct ethtool_cmd *ecmd,
256 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000257{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 u32 link_speed = hw_link_info->link_speed;
260
Catherine Sullivane8278452015-02-06 08:52:08 +0000261 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 switch (hw_link_info->phy_type) {
263 case I40E_PHY_TYPE_40GBASE_CR4:
264 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000265 ecmd->supported = SUPPORTED_Autoneg |
266 SUPPORTED_40000baseCR4_Full;
267 ecmd->advertising = ADVERTISED_Autoneg |
268 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000269 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000270 case I40E_PHY_TYPE_XLAUI:
271 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000272 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000273 ecmd->supported = SUPPORTED_40000baseCR4_Full;
274 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000275 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000276 ecmd->supported = SUPPORTED_Autoneg |
277 SUPPORTED_40000baseKR4_Full;
278 ecmd->advertising = ADVERTISED_Autoneg |
279 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 break;
281 case I40E_PHY_TYPE_40GBASE_SR4:
282 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 break;
284 case I40E_PHY_TYPE_40GBASE_LR4:
285 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000286 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700287 case I40E_PHY_TYPE_20GBASE_KR2:
288 ecmd->supported = SUPPORTED_Autoneg |
289 SUPPORTED_20000baseKR2_Full;
290 ecmd->advertising = ADVERTISED_Autoneg |
291 ADVERTISED_20000baseKR2_Full;
292 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000293 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000294 ecmd->supported = SUPPORTED_Autoneg |
295 SUPPORTED_10000baseKX4_Full;
296 ecmd->advertising = ADVERTISED_Autoneg |
297 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000298 break;
299 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000300 ecmd->supported = SUPPORTED_Autoneg |
301 SUPPORTED_10000baseKR_Full;
302 ecmd->advertising = ADVERTISED_Autoneg |
303 ADVERTISED_10000baseKR_Full;
304 break;
305 case I40E_PHY_TYPE_10GBASE_SR:
306 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000307 case I40E_PHY_TYPE_1000BASE_SX:
308 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000309 ecmd->supported = SUPPORTED_10000baseT_Full |
310 SUPPORTED_1000baseT_Full;
311 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
312 ecmd->advertising |= ADVERTISED_10000baseT_Full;
313 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
314 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000315 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000316 case I40E_PHY_TYPE_1000BASE_KX:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_1000baseKX_Full;
319 ecmd->advertising = ADVERTISED_Autoneg |
320 ADVERTISED_1000baseKX_Full;
321 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000322 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000323 case I40E_PHY_TYPE_1000BASE_T:
324 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000325 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000326 SUPPORTED_10000baseT_Full |
327 SUPPORTED_1000baseT_Full |
328 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000329 ecmd->advertising = ADVERTISED_Autoneg;
330 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
331 ecmd->advertising |= ADVERTISED_10000baseT_Full;
332 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
333 ecmd->advertising |= ADVERTISED_1000baseT_Full;
334 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
335 ecmd->advertising |= ADVERTISED_100baseT_Full;
336 break;
337 case I40E_PHY_TYPE_10GBASE_CR1_CU:
338 case I40E_PHY_TYPE_10GBASE_CR1:
339 ecmd->supported = SUPPORTED_Autoneg |
340 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000341 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000342 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000343 break;
344 case I40E_PHY_TYPE_XAUI:
345 case I40E_PHY_TYPE_XFI:
346 case I40E_PHY_TYPE_SFI:
347 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000348 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000349 ecmd->supported = SUPPORTED_10000baseT_Full;
350 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000351 case I40E_PHY_TYPE_SGMII:
352 ecmd->supported = SUPPORTED_Autoneg |
353 SUPPORTED_1000baseT_Full |
354 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000355 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
356 ecmd->advertising |= ADVERTISED_1000baseT_Full;
357 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
358 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000359 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000360 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000361 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000362 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
363 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000364 }
365
Catherine Sullivane8278452015-02-06 08:52:08 +0000366 /* Set speed and duplex */
367 switch (link_speed) {
368 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400369 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000370 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700371 case I40E_LINK_SPEED_20GB:
372 ethtool_cmd_speed_set(ecmd, SPEED_20000);
373 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000374 case I40E_LINK_SPEED_10GB:
375 ethtool_cmd_speed_set(ecmd, SPEED_10000);
376 break;
377 case I40E_LINK_SPEED_1GB:
378 ethtool_cmd_speed_set(ecmd, SPEED_1000);
379 break;
380 case I40E_LINK_SPEED_100MB:
381 ethtool_cmd_speed_set(ecmd, SPEED_100);
382 break;
383 default:
384 break;
385 }
386 ecmd->duplex = DUPLEX_FULL;
387}
388
389/**
390 * i40e_get_settings_link_down - Get the Link settings for when link is down
391 * @hw: hw structure
392 * @ecmd: ethtool command to fill in
393 *
394 * Reports link settings that can be determined when link is down
395 **/
396static void i40e_get_settings_link_down(struct i40e_hw *hw,
397 struct ethtool_cmd *ecmd)
398{
399 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
400
401 /* link is down and the driver needs to fall back on
402 * device ID to determine what kinds of info to display,
403 * it's mostly a guess that may change when link is up
404 */
405 switch (hw->device_id) {
406 case I40E_DEV_ID_QSFP_A:
407 case I40E_DEV_ID_QSFP_B:
408 case I40E_DEV_ID_QSFP_C:
409 /* pluggable QSFP */
410 ecmd->supported = SUPPORTED_40000baseSR4_Full |
411 SUPPORTED_40000baseCR4_Full |
412 SUPPORTED_40000baseLR4_Full;
413 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
414 ADVERTISED_40000baseCR4_Full |
415 ADVERTISED_40000baseLR4_Full;
416 break;
417 case I40E_DEV_ID_KX_B:
418 /* backplane 40G */
419 ecmd->supported = SUPPORTED_40000baseKR4_Full;
420 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
421 break;
422 case I40E_DEV_ID_KX_C:
423 /* backplane 10G */
424 ecmd->supported = SUPPORTED_10000baseKR_Full;
425 ecmd->advertising = ADVERTISED_10000baseKR_Full;
426 break;
427 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -0400428 case I40E_DEV_ID_10G_BASE_T4:
Catherine Sullivane8278452015-02-06 08:52:08 +0000429 ecmd->supported = SUPPORTED_10000baseT_Full |
430 SUPPORTED_1000baseT_Full |
431 SUPPORTED_100baseT_Full;
432 /* Figure out what has been requested */
433 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
434 ecmd->advertising |= ADVERTISED_10000baseT_Full;
435 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
436 ecmd->advertising |= ADVERTISED_1000baseT_Full;
437 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
438 ecmd->advertising |= ADVERTISED_100baseT_Full;
439 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700440 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -0400441 case I40E_DEV_ID_20G_KR2_A:
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700442 /* backplane 20G */
443 ecmd->supported = SUPPORTED_20000baseKR2_Full;
444 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
445 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000446 default:
447 /* all the rest are 10G/1G */
448 ecmd->supported = SUPPORTED_10000baseT_Full |
449 SUPPORTED_1000baseT_Full;
450 /* Figure out what has been requested */
451 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
452 ecmd->advertising |= ADVERTISED_10000baseT_Full;
453 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
454 ecmd->advertising |= ADVERTISED_1000baseT_Full;
455 break;
456 }
457
458 /* With no link speed and duplex are unknown */
459 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
460 ecmd->duplex = DUPLEX_UNKNOWN;
461}
462
463/**
464 * i40e_get_settings - Get Link Speed and Duplex settings
465 * @netdev: network interface device structure
466 * @ecmd: ethtool command
467 *
468 * Reports speed/duplex settings based on media_type
469 **/
470static int i40e_get_settings(struct net_device *netdev,
471 struct ethtool_cmd *ecmd)
472{
473 struct i40e_netdev_priv *np = netdev_priv(netdev);
474 struct i40e_pf *pf = np->vsi->back;
475 struct i40e_hw *hw = &pf->hw;
476 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
477 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
478
479 if (link_up)
480 i40e_get_settings_link_up(hw, ecmd, netdev);
481 else
482 i40e_get_settings_link_down(hw, ecmd);
483
484 /* Now set the settings that don't rely on link being up/down */
485
486 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000487 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
488 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000489
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000490 switch (hw->phy.media_type) {
491 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000492 ecmd->supported |= SUPPORTED_Autoneg |
493 SUPPORTED_Backplane;
494 ecmd->advertising |= ADVERTISED_Autoneg |
495 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000496 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000497 break;
498 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000499 ecmd->supported |= SUPPORTED_TP;
500 ecmd->advertising |= ADVERTISED_TP;
501 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000502 break;
503 case I40E_MEDIA_TYPE_DA:
504 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000505 ecmd->supported |= SUPPORTED_FIBRE;
506 ecmd->advertising |= ADVERTISED_FIBRE;
507 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000508 break;
509 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000510 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000511 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000512 break;
513 case I40E_MEDIA_TYPE_UNKNOWN:
514 default:
515 ecmd->port = PORT_OTHER;
516 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000517 }
518
Catherine Sullivane8278452015-02-06 08:52:08 +0000519 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000520 ecmd->transceiver = XCVR_EXTERNAL;
521
Catherine Sullivane8278452015-02-06 08:52:08 +0000522 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000523 ecmd->supported |= SUPPORTED_Pause;
524
Catherine Sullivane8278452015-02-06 08:52:08 +0000525 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000526 case I40E_FC_FULL:
527 ecmd->advertising |= ADVERTISED_Pause;
528 break;
529 case I40E_FC_TX_PAUSE:
530 ecmd->advertising |= ADVERTISED_Asym_Pause;
531 break;
532 case I40E_FC_RX_PAUSE:
533 ecmd->advertising |= (ADVERTISED_Pause |
534 ADVERTISED_Asym_Pause);
535 break;
536 default:
537 ecmd->advertising &= ~(ADVERTISED_Pause |
538 ADVERTISED_Asym_Pause);
539 break;
540 }
541
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000542 return 0;
543}
544
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000545/**
546 * i40e_set_settings - Set Speed and Duplex
547 * @netdev: network interface device structure
548 * @ecmd: ethtool command
549 *
550 * Set speed/duplex per media_types advertised/forced
551 **/
552static int i40e_set_settings(struct net_device *netdev,
553 struct ethtool_cmd *ecmd)
554{
555 struct i40e_netdev_priv *np = netdev_priv(netdev);
556 struct i40e_aq_get_phy_abilities_resp abilities;
557 struct i40e_aq_set_phy_config config;
558 struct i40e_pf *pf = np->vsi->back;
559 struct i40e_vsi *vsi = np->vsi;
560 struct i40e_hw *hw = &pf->hw;
561 struct ethtool_cmd safe_ecmd;
562 i40e_status status = 0;
563 bool change = false;
564 int err = 0;
565 u8 autoneg;
566 u32 advertise;
567
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000568 /* Changing port settings is not supported if this isn't the
569 * port's controlling PF
570 */
571 if (hw->partition_id != 1) {
572 i40e_partition_setting_complaint(pf);
573 return -EOPNOTSUPP;
574 }
575
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000576 if (vsi != pf->vsi[pf->lan_vsi])
577 return -EOPNOTSUPP;
578
579 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
580 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000581 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
582 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000583 return -EOPNOTSUPP;
584
585 /* get our own copy of the bits to check against */
586 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
587 i40e_get_settings(netdev, &safe_ecmd);
588
589 /* save autoneg and speed out of ecmd */
590 autoneg = ecmd->autoneg;
591 advertise = ecmd->advertising;
592
593 /* set autoneg and speed back to what they currently are */
594 ecmd->autoneg = safe_ecmd.autoneg;
595 ecmd->advertising = safe_ecmd.advertising;
596
597 ecmd->cmd = safe_ecmd.cmd;
598 /* If ecmd and safe_ecmd are not the same now, then they are
599 * trying to set something that we do not support
600 */
601 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
602 return -EOPNOTSUPP;
603
604 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
605 usleep_range(1000, 2000);
606
607 /* Get the current phy config */
608 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
609 NULL);
610 if (status)
611 return -EAGAIN;
612
Catherine Sullivan124ed152014-07-12 07:28:12 +0000613 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000614 * set below
615 */
616 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000617 config.abilities = abilities.abilities;
618
619 /* Check autoneg */
620 if (autoneg == AUTONEG_ENABLE) {
621 /* If autoneg is not supported, return error */
622 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
623 netdev_info(netdev, "Autoneg not supported on this phy\n");
624 return -EINVAL;
625 }
626 /* If autoneg was not already enabled */
627 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
628 config.abilities = abilities.abilities |
629 I40E_AQ_PHY_ENABLE_AN;
630 change = true;
631 }
632 } else {
633 /* If autoneg is supported 10GBASE_T is the only phy that
634 * can disable it, so otherwise return error
635 */
636 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
637 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
638 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
639 return -EINVAL;
640 }
641 /* If autoneg is currently enabled */
642 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000643 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000644 ~I40E_AQ_PHY_ENABLE_AN;
645 change = true;
646 }
647 }
648
649 if (advertise & ~safe_ecmd.supported)
650 return -EINVAL;
651
652 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000653 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000654 if (advertise & ADVERTISED_1000baseT_Full ||
655 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000656 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000657 if (advertise & ADVERTISED_10000baseT_Full ||
658 advertise & ADVERTISED_10000baseKX4_Full ||
659 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000660 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700661 if (advertise & ADVERTISED_20000baseKR2_Full)
662 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000663 if (advertise & ADVERTISED_40000baseKR4_Full ||
664 advertise & ADVERTISED_40000baseCR4_Full ||
665 advertise & ADVERTISED_40000baseSR4_Full ||
666 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000667 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000668
Catherine Sullivan0002e112015-08-26 15:14:16 -0400669 /* If speed didn't get set, set it to what it currently is.
670 * This is needed because if advertise is 0 (as it is when autoneg
671 * is disabled) then speed won't get set.
672 */
673 if (!config.link_speed)
674 config.link_speed = abilities.link_speed;
675
Catherine Sullivan124ed152014-07-12 07:28:12 +0000676 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000677 /* copy over the rest of the abilities */
678 config.phy_type = abilities.phy_type;
679 config.eee_capability = abilities.eee_capability;
680 config.eeer = abilities.eeer_val;
681 config.low_power_ctrl = abilities.d3_lpan;
682
Catherine Sullivane8278452015-02-06 08:52:08 +0000683 /* save the requested speeds */
684 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000685 /* set link and auto negotiation so changes take effect */
686 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
687 /* If link is up put link down */
688 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
689 /* Tell the OS link is going down, the link will go
690 * back up when fw says it is ready asynchronously
691 */
692 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
693 netif_carrier_off(netdev);
694 netif_tx_stop_all_queues(netdev);
695 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000696
697 /* make the aq call */
698 status = i40e_aq_set_phy_config(hw, &config, NULL);
699 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400700 netdev_info(netdev, "Set phy config failed, 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 return -EAGAIN;
704 }
705
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000706 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000707 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400708 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
709 i40e_stat_str(hw, status),
710 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000711
712 } else {
713 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
714 }
715
716 return err;
717}
718
Jesse Brandeburga6599722014-06-04 08:45:25 +0000719static int i40e_nway_reset(struct net_device *netdev)
720{
721 /* restart autonegotiation */
722 struct i40e_netdev_priv *np = netdev_priv(netdev);
723 struct i40e_pf *pf = np->vsi->back;
724 struct i40e_hw *hw = &pf->hw;
725 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
726 i40e_status ret = 0;
727
728 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
729 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400730 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
731 i40e_stat_str(hw, ret),
732 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000733 return -EIO;
734 }
735
736 return 0;
737}
738
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000739/**
740 * i40e_get_pauseparam - Get Flow Control status
741 * Return tx/rx-pause status
742 **/
743static void i40e_get_pauseparam(struct net_device *netdev,
744 struct ethtool_pauseparam *pause)
745{
746 struct i40e_netdev_priv *np = netdev_priv(netdev);
747 struct i40e_pf *pf = np->vsi->back;
748 struct i40e_hw *hw = &pf->hw;
749 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000750 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000751
752 pause->autoneg =
753 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
754 AUTONEG_ENABLE : AUTONEG_DISABLE);
755
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000756 /* PFC enabled so report LFC as off */
757 if (dcbx_cfg->pfc.pfcenable) {
758 pause->rx_pause = 0;
759 pause->tx_pause = 0;
760 return;
761 }
762
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000763 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000764 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000765 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000766 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000767 } else if (hw->fc.current_mode == I40E_FC_FULL) {
768 pause->rx_pause = 1;
769 pause->tx_pause = 1;
770 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000771}
772
Catherine Sullivan2becc352014-06-04 08:45:27 +0000773/**
774 * i40e_set_pauseparam - Set Flow Control parameter
775 * @netdev: network interface device structure
776 * @pause: return tx/rx flow control status
777 **/
778static int i40e_set_pauseparam(struct net_device *netdev,
779 struct ethtool_pauseparam *pause)
780{
781 struct i40e_netdev_priv *np = netdev_priv(netdev);
782 struct i40e_pf *pf = np->vsi->back;
783 struct i40e_vsi *vsi = np->vsi;
784 struct i40e_hw *hw = &pf->hw;
785 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000786 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000787 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
788 i40e_status status;
789 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000790 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000791
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000792 /* Changing the port's flow control is not supported if this isn't the
793 * port's controlling PF
794 */
795 if (hw->partition_id != 1) {
796 i40e_partition_setting_complaint(pf);
797 return -EOPNOTSUPP;
798 }
799
Catherine Sullivan2becc352014-06-04 08:45:27 +0000800 if (vsi != pf->vsi[pf->lan_vsi])
801 return -EOPNOTSUPP;
802
803 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
804 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
805 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
806 return -EOPNOTSUPP;
807 }
808
809 /* If we have link and don't have autoneg */
810 if (!test_bit(__I40E_DOWN, &pf->state) &&
811 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
812 /* Send message that it might not necessarily work*/
813 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
814 }
815
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000816 if (dcbx_cfg->pfc.pfcenable) {
817 netdev_info(netdev,
818 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000819 return -EOPNOTSUPP;
820 }
821
822 if (pause->rx_pause && pause->tx_pause)
823 hw->fc.requested_mode = I40E_FC_FULL;
824 else if (pause->rx_pause && !pause->tx_pause)
825 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
826 else if (!pause->rx_pause && pause->tx_pause)
827 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
828 else if (!pause->rx_pause && !pause->tx_pause)
829 hw->fc.requested_mode = I40E_FC_NONE;
830 else
831 return -EINVAL;
832
Catherine Sullivan94128512014-07-12 07:28:16 +0000833 /* Tell the OS link is going down, the link will go back up when fw
834 * says it is ready asynchronously
835 */
836 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
837 netif_carrier_off(netdev);
838 netif_tx_stop_all_queues(netdev);
839
Catherine Sullivan2becc352014-06-04 08:45:27 +0000840 /* Set the fc mode and only restart an if link is up*/
841 status = i40e_set_fc(hw, &aq_failures, link_up);
842
843 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400844 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
845 i40e_stat_str(hw, status),
846 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000847 err = -EAGAIN;
848 }
849 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400850 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
851 i40e_stat_str(hw, status),
852 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000853 err = -EAGAIN;
854 }
855 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400856 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
857 i40e_stat_str(hw, status),
858 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000859 err = -EAGAIN;
860 }
861
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000862 if (!test_bit(__I40E_DOWN, &pf->state)) {
863 /* Give it a little more time to try to come back */
864 msleep(75);
865 if (!test_bit(__I40E_DOWN, &pf->state))
866 return i40e_nway_reset(netdev);
867 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000868
869 return err;
870}
871
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000872static u32 i40e_get_msglevel(struct net_device *netdev)
873{
874 struct i40e_netdev_priv *np = netdev_priv(netdev);
875 struct i40e_pf *pf = np->vsi->back;
876
877 return pf->msg_enable;
878}
879
880static void i40e_set_msglevel(struct net_device *netdev, u32 data)
881{
882 struct i40e_netdev_priv *np = netdev_priv(netdev);
883 struct i40e_pf *pf = np->vsi->back;
884
885 if (I40E_DEBUG_USER & data)
886 pf->hw.debug_mask = data;
887 pf->msg_enable = data;
888}
889
890static int i40e_get_regs_len(struct net_device *netdev)
891{
892 int reg_count = 0;
893 int i;
894
895 for (i = 0; i40e_reg_list[i].offset != 0; i++)
896 reg_count += i40e_reg_list[i].elements;
897
898 return reg_count * sizeof(u32);
899}
900
901static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
902 void *p)
903{
904 struct i40e_netdev_priv *np = netdev_priv(netdev);
905 struct i40e_pf *pf = np->vsi->back;
906 struct i40e_hw *hw = &pf->hw;
907 u32 *reg_buf = p;
908 int i, j, ri;
909 u32 reg;
910
911 /* Tell ethtool which driver-version-specific regs output we have.
912 *
913 * At some point, if we have ethtool doing special formatting of
914 * this data, it will rely on this version number to know how to
915 * interpret things. Hence, this needs to be updated if/when the
916 * diags register table is changed.
917 */
918 regs->version = 1;
919
920 /* loop through the diags reg table for what to print */
921 ri = 0;
922 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
923 for (j = 0; j < i40e_reg_list[i].elements; j++) {
924 reg = i40e_reg_list[i].offset
925 + (j * i40e_reg_list[i].stride);
926 reg_buf[ri++] = rd32(hw, reg);
927 }
928 }
929
930}
931
932static int i40e_get_eeprom(struct net_device *netdev,
933 struct ethtool_eeprom *eeprom, u8 *bytes)
934{
935 struct i40e_netdev_priv *np = netdev_priv(netdev);
936 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000937 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000938 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000939 u8 *eeprom_buff;
940 u16 i, sectors;
941 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000942 u32 magic;
943
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000944#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000945 if (eeprom->len == 0)
946 return -EINVAL;
947
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000948 /* check for NVMUpdate access method */
949 magic = hw->vendor_id | (hw->device_id << 16);
950 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000951 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000952 int errno;
953
954 /* make sure it is the right magic for NVMUpdate */
955 if ((eeprom->magic >> 16) != hw->device_id)
956 return -EINVAL;
957
Shannon Nelsonc150a502014-11-13 08:23:13 +0000958 cmd = (struct i40e_nvm_access *)eeprom;
959 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000960 if (ret_val &&
961 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
962 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000963 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000964 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
965 ret_val, hw->aq.asq_last_status, errno,
966 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
967 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000968
969 return errno;
970 }
971
972 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000973 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
974
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000975 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000976 if (!eeprom_buff)
977 return -ENOMEM;
978
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000979 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
980 if (ret_val) {
981 dev_info(&pf->pdev->dev,
982 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
983 ret_val, hw->aq.asq_last_status);
984 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000985 }
986
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000987 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
988 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
989 len = I40E_NVM_SECTOR_SIZE;
990 last = false;
991 for (i = 0; i < sectors; i++) {
992 if (i == (sectors - 1)) {
993 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
994 last = true;
995 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000996 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
997 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000998 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000999 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001000 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001001 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001002 "read NVM failed, invalid offset 0x%x\n",
1003 offset);
1004 break;
1005 } else if (ret_val &&
1006 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1007 dev_info(&pf->pdev->dev,
1008 "read NVM failed, access, offset 0x%x\n",
1009 offset);
1010 break;
1011 } else if (ret_val) {
1012 dev_info(&pf->pdev->dev,
1013 "read NVM failed offset %d err=%d status=0x%x\n",
1014 offset, ret_val, hw->aq.asq_last_status);
1015 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001016 }
1017 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001018
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001019 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001020 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001021free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001022 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023 return ret_val;
1024}
1025
1026static int i40e_get_eeprom_len(struct net_device *netdev)
1027{
1028 struct i40e_netdev_priv *np = netdev_priv(netdev);
1029 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001030 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001031
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001032 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1033 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1034 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1035 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001036 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001037 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001038}
1039
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001040static int i40e_set_eeprom(struct net_device *netdev,
1041 struct ethtool_eeprom *eeprom, u8 *bytes)
1042{
1043 struct i40e_netdev_priv *np = netdev_priv(netdev);
1044 struct i40e_hw *hw = &np->vsi->back->hw;
1045 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001046 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001047 int ret_val = 0;
1048 int errno;
1049 u32 magic;
1050
1051 /* normal ethtool set_eeprom is not supported */
1052 magic = hw->vendor_id | (hw->device_id << 16);
1053 if (eeprom->magic == magic)
1054 return -EOPNOTSUPP;
1055
1056 /* check for NVMUpdate access method */
1057 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1058 return -EINVAL;
1059
1060 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1061 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1062 return -EBUSY;
1063
Shannon Nelsonc150a502014-11-13 08:23:13 +00001064 cmd = (struct i40e_nvm_access *)eeprom;
1065 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001066 if (ret_val &&
1067 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1068 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1069 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001070 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001071 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1072 ret_val, hw->aq.asq_last_status, errno,
1073 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1074 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001075
1076 return errno;
1077}
1078
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001079static void i40e_get_drvinfo(struct net_device *netdev,
1080 struct ethtool_drvinfo *drvinfo)
1081{
1082 struct i40e_netdev_priv *np = netdev_priv(netdev);
1083 struct i40e_vsi *vsi = np->vsi;
1084 struct i40e_pf *pf = vsi->back;
1085
1086 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1087 strlcpy(drvinfo->version, i40e_driver_version_str,
1088 sizeof(drvinfo->version));
1089 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1090 sizeof(drvinfo->fw_version));
1091 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1092 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001093 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001094}
1095
1096static void i40e_get_ringparam(struct net_device *netdev,
1097 struct ethtool_ringparam *ring)
1098{
1099 struct i40e_netdev_priv *np = netdev_priv(netdev);
1100 struct i40e_pf *pf = np->vsi->back;
1101 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1102
1103 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1104 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1105 ring->rx_mini_max_pending = 0;
1106 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001107 ring->rx_pending = vsi->rx_rings[0]->count;
1108 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001109 ring->rx_mini_pending = 0;
1110 ring->rx_jumbo_pending = 0;
1111}
1112
1113static int i40e_set_ringparam(struct net_device *netdev,
1114 struct ethtool_ringparam *ring)
1115{
1116 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1117 struct i40e_netdev_priv *np = netdev_priv(netdev);
1118 struct i40e_vsi *vsi = np->vsi;
1119 struct i40e_pf *pf = vsi->back;
1120 u32 new_rx_count, new_tx_count;
1121 int i, err = 0;
1122
1123 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1124 return -EINVAL;
1125
Shannon Nelson1fa18372013-11-20 10:03:08 +00001126 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1127 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1128 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1129 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1130 netdev_info(netdev,
1131 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1132 ring->tx_pending, ring->rx_pending,
1133 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1134 return -EINVAL;
1135 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001136
Shannon Nelson1fa18372013-11-20 10:03:08 +00001137 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1138 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001139
1140 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001141 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1142 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001143 return 0;
1144
1145 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1146 usleep_range(1000, 2000);
1147
1148 if (!netif_running(vsi->netdev)) {
1149 /* simple case - set for the next time the netdev is started */
1150 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001151 vsi->tx_rings[i]->count = new_tx_count;
1152 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001153 }
1154 goto done;
1155 }
1156
1157 /* We can't just free everything and then setup again,
1158 * because the ISRs in MSI-X mode get passed pointers
1159 * to the Tx and Rx ring structs.
1160 */
1161
1162 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001163 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001164 netdev_info(netdev,
1165 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001166 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001167 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1168 sizeof(struct i40e_ring), GFP_KERNEL);
1169 if (!tx_rings) {
1170 err = -ENOMEM;
1171 goto done;
1172 }
1173
1174 for (i = 0; i < vsi->num_queue_pairs; i++) {
1175 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001176 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001177 tx_rings[i].count = new_tx_count;
1178 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1179 if (err) {
1180 while (i) {
1181 i--;
1182 i40e_free_tx_resources(&tx_rings[i]);
1183 }
1184 kfree(tx_rings);
1185 tx_rings = NULL;
1186
1187 goto done;
1188 }
1189 }
1190 }
1191
1192 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001193 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001194 netdev_info(netdev,
1195 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001196 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001197 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1198 sizeof(struct i40e_ring), GFP_KERNEL);
1199 if (!rx_rings) {
1200 err = -ENOMEM;
1201 goto free_tx;
1202 }
1203
1204 for (i = 0; i < vsi->num_queue_pairs; i++) {
1205 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001206 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001207 rx_rings[i].count = new_rx_count;
1208 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1209 if (err) {
1210 while (i) {
1211 i--;
1212 i40e_free_rx_resources(&rx_rings[i]);
1213 }
1214 kfree(rx_rings);
1215 rx_rings = NULL;
1216
1217 goto free_tx;
1218 }
1219 }
1220 }
1221
1222 /* Bring interface down, copy in the new ring info,
1223 * then restore the interface
1224 */
1225 i40e_down(vsi);
1226
1227 if (tx_rings) {
1228 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001229 i40e_free_tx_resources(vsi->tx_rings[i]);
1230 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001231 }
1232 kfree(tx_rings);
1233 tx_rings = NULL;
1234 }
1235
1236 if (rx_rings) {
1237 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001238 i40e_free_rx_resources(vsi->rx_rings[i]);
1239 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001240 }
1241 kfree(rx_rings);
1242 rx_rings = NULL;
1243 }
1244
1245 i40e_up(vsi);
1246
1247free_tx:
1248 /* error cleanup if the Rx allocations failed after getting Tx */
1249 if (tx_rings) {
1250 for (i = 0; i < vsi->num_queue_pairs; i++)
1251 i40e_free_tx_resources(&tx_rings[i]);
1252 kfree(tx_rings);
1253 tx_rings = NULL;
1254 }
1255
1256done:
1257 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1258
1259 return err;
1260}
1261
1262static int i40e_get_sset_count(struct net_device *netdev, int sset)
1263{
1264 struct i40e_netdev_priv *np = netdev_priv(netdev);
1265 struct i40e_vsi *vsi = np->vsi;
1266 struct i40e_pf *pf = vsi->back;
1267
1268 switch (sset) {
1269 case ETH_SS_TEST:
1270 return I40E_TEST_LEN;
1271 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001272 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001273 int len = I40E_PF_STATS_LEN(netdev);
1274
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001275 if ((pf->lan_veb != I40E_NO_VEB) &&
1276 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001277 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001278 return len;
1279 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001280 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001281 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001282 case ETH_SS_PRIV_FLAGS:
1283 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001284 default:
1285 return -EOPNOTSUPP;
1286 }
1287}
1288
1289static void i40e_get_ethtool_stats(struct net_device *netdev,
1290 struct ethtool_stats *stats, u64 *data)
1291{
1292 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001293 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001294 struct i40e_vsi *vsi = np->vsi;
1295 struct i40e_pf *pf = vsi->back;
1296 int i = 0;
1297 char *p;
1298 int j;
1299 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001300 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301
1302 i40e_update_stats(vsi);
1303
1304 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1305 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1306 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1307 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1308 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001309 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1310 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1311 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1312 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1313 }
Vasu Dev38e00432014-08-01 13:27:03 -07001314#ifdef I40E_FCOE
1315 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1316 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1317 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1318 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1319 }
1320#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001321 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001322 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001323 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001324
1325 if (!tx_ring)
1326 continue;
1327
1328 /* process Tx ring statistics */
1329 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001330 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001331 data[i] = tx_ring->stats.packets;
1332 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001333 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001334 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001335
1336 /* Rx ring is the 2nd half of the queue pair */
1337 rx_ring = &tx_ring[1];
1338 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001339 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001340 data[i] = rx_ring->stats.packets;
1341 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001342 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001343 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001344 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001345 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001346 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001347 return;
1348
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001349 if ((pf->lan_veb != I40E_NO_VEB) &&
1350 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001351 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1352 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1353 p = (char *)veb;
1354 p += i40e_gstrings_veb_stats[j].stat_offset;
1355 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1356 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001357 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001358 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001359 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1360 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1361 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1362 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1363 }
1364 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1365 data[i++] = pf->stats.priority_xon_tx[j];
1366 data[i++] = pf->stats.priority_xoff_tx[j];
1367 }
1368 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1369 data[i++] = pf->stats.priority_xon_rx[j];
1370 data[i++] = pf->stats.priority_xoff_rx[j];
1371 }
1372 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1373 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001374}
1375
1376static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1377 u8 *data)
1378{
1379 struct i40e_netdev_priv *np = netdev_priv(netdev);
1380 struct i40e_vsi *vsi = np->vsi;
1381 struct i40e_pf *pf = vsi->back;
1382 char *p = (char *)data;
1383 int i;
1384
1385 switch (stringset) {
1386 case ETH_SS_TEST:
1387 for (i = 0; i < I40E_TEST_LEN; i++) {
1388 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1389 data += ETH_GSTRING_LEN;
1390 }
1391 break;
1392 case ETH_SS_STATS:
1393 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1394 snprintf(p, ETH_GSTRING_LEN, "%s",
1395 i40e_gstrings_net_stats[i].stat_string);
1396 p += ETH_GSTRING_LEN;
1397 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001398 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1399 snprintf(p, ETH_GSTRING_LEN, "%s",
1400 i40e_gstrings_misc_stats[i].stat_string);
1401 p += ETH_GSTRING_LEN;
1402 }
Vasu Dev38e00432014-08-01 13:27:03 -07001403#ifdef I40E_FCOE
1404 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1405 snprintf(p, ETH_GSTRING_LEN, "%s",
1406 i40e_gstrings_fcoe_stats[i].stat_string);
1407 p += ETH_GSTRING_LEN;
1408 }
1409#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001410 for (i = 0; i < vsi->num_queue_pairs; i++) {
1411 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1412 p += ETH_GSTRING_LEN;
1413 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1414 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001415 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1416 p += ETH_GSTRING_LEN;
1417 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1418 p += ETH_GSTRING_LEN;
1419 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001420 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001421 return;
1422
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001423 if ((pf->lan_veb != I40E_NO_VEB) &&
1424 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001425 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1426 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1427 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001428 p += ETH_GSTRING_LEN;
1429 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001430 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1431 snprintf(p, ETH_GSTRING_LEN,
1432 "veb.tc_%u_tx_packets", i);
1433 p += ETH_GSTRING_LEN;
1434 snprintf(p, ETH_GSTRING_LEN,
1435 "veb.tc_%u_tx_bytes", i);
1436 p += ETH_GSTRING_LEN;
1437 snprintf(p, ETH_GSTRING_LEN,
1438 "veb.tc_%u_rx_packets", i);
1439 p += ETH_GSTRING_LEN;
1440 snprintf(p, ETH_GSTRING_LEN,
1441 "veb.tc_%u_rx_bytes", i);
1442 p += ETH_GSTRING_LEN;
1443 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001444 }
1445 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1446 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1447 i40e_gstrings_stats[i].stat_string);
1448 p += ETH_GSTRING_LEN;
1449 }
1450 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1451 snprintf(p, ETH_GSTRING_LEN,
1452 "port.tx_priority_%u_xon", i);
1453 p += ETH_GSTRING_LEN;
1454 snprintf(p, ETH_GSTRING_LEN,
1455 "port.tx_priority_%u_xoff", i);
1456 p += ETH_GSTRING_LEN;
1457 }
1458 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1459 snprintf(p, ETH_GSTRING_LEN,
1460 "port.rx_priority_%u_xon", i);
1461 p += ETH_GSTRING_LEN;
1462 snprintf(p, ETH_GSTRING_LEN,
1463 "port.rx_priority_%u_xoff", i);
1464 p += ETH_GSTRING_LEN;
1465 }
1466 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1467 snprintf(p, ETH_GSTRING_LEN,
1468 "port.rx_priority_%u_xon_2_xoff", i);
1469 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470 }
1471 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1472 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001473 case ETH_SS_PRIV_FLAGS:
1474 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1475 memcpy(data, i40e_priv_flags_strings[i],
1476 ETH_GSTRING_LEN);
1477 data += ETH_GSTRING_LEN;
1478 }
1479 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001480 default:
1481 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 }
1483}
1484
1485static int i40e_get_ts_info(struct net_device *dev,
1486 struct ethtool_ts_info *info)
1487{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001488 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1489
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001490 /* only report HW timestamping if PTP is enabled */
1491 if (!(pf->flags & I40E_FLAG_PTP))
1492 return ethtool_op_get_ts_info(dev, info);
1493
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001494 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1495 SOF_TIMESTAMPING_RX_SOFTWARE |
1496 SOF_TIMESTAMPING_SOFTWARE |
1497 SOF_TIMESTAMPING_TX_HARDWARE |
1498 SOF_TIMESTAMPING_RX_HARDWARE |
1499 SOF_TIMESTAMPING_RAW_HARDWARE;
1500
1501 if (pf->ptp_clock)
1502 info->phc_index = ptp_clock_index(pf->ptp_clock);
1503 else
1504 info->phc_index = -1;
1505
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001506 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001507
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001508 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1509 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1510 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001511
1512 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513}
1514
Shannon Nelson7b086392013-11-20 10:02:59 +00001515static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516{
Shannon Nelson7b086392013-11-20 10:02:59 +00001517 struct i40e_netdev_priv *np = netdev_priv(netdev);
1518 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001519 i40e_status status;
1520 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001521
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001522 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001523 status = i40e_get_link_status(&pf->hw, &link_up);
1524 if (status) {
1525 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1526 *data = 1;
1527 return *data;
1528 }
1529
1530 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001531 *data = 0;
1532 else
1533 *data = 1;
1534
1535 return *data;
1536}
1537
Shannon Nelson7b086392013-11-20 10:02:59 +00001538static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001539{
Shannon Nelson7b086392013-11-20 10:02:59 +00001540 struct i40e_netdev_priv *np = netdev_priv(netdev);
1541 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001542
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001543 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001544 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545
Shannon Nelson7b086392013-11-20 10:02:59 +00001546 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001547}
1548
Shannon Nelson7b086392013-11-20 10:02:59 +00001549static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001550{
Shannon Nelson7b086392013-11-20 10:02:59 +00001551 struct i40e_netdev_priv *np = netdev_priv(netdev);
1552 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001553
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001554 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001555 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556
Shannon Nelson4443ec92014-11-13 08:23:12 +00001557 /* forcebly clear the NVM Update state machine */
1558 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1559
Shannon Nelson7b086392013-11-20 10:02:59 +00001560 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001561}
1562
Shannon Nelson7b086392013-11-20 10:02:59 +00001563static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001564{
Shannon Nelson7b086392013-11-20 10:02:59 +00001565 struct i40e_netdev_priv *np = netdev_priv(netdev);
1566 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001567 u16 swc_old = pf->sw_int_count;
1568
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001569 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001570 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1571 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001572 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1573 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1574 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1575 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001576 usleep_range(1000, 2000);
1577 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001578
1579 return *data;
1580}
1581
Shannon Nelson7b086392013-11-20 10:02:59 +00001582static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001583{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001584 struct i40e_netdev_priv *np = netdev_priv(netdev);
1585 struct i40e_pf *pf = np->vsi->back;
1586
1587 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001588 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001589
1590 return *data;
1591}
1592
Greg Rosee17bc412015-04-16 20:05:59 -04001593static inline bool i40e_active_vfs(struct i40e_pf *pf)
1594{
1595 struct i40e_vf *vfs = pf->vf;
1596 int i;
1597
1598 for (i = 0; i < pf->num_alloc_vfs; i++)
1599 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1600 return true;
1601 return false;
1602}
1603
Greg Rose510efb22015-07-10 19:36:01 -04001604static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1605{
1606 struct i40e_vsi **vsi = pf->vsi;
1607 int i;
1608
1609 for (i = 0; i < pf->num_alloc_vsi; i++) {
1610 if (!vsi[i])
1611 continue;
1612 if (vsi[i]->type == I40E_VSI_VMDQ2)
1613 return true;
1614 }
1615
1616 return false;
1617}
1618
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619static void i40e_diag_test(struct net_device *netdev,
1620 struct ethtool_test *eth_test, u64 *data)
1621{
1622 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001623 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624 struct i40e_pf *pf = np->vsi->back;
1625
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001626 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1627 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001628 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001629
Shannon Nelsonf551b432013-11-26 10:49:12 +00001630 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001631
Greg Rose510efb22015-07-10 19:36:01 -04001632 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001633 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001634 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001635 data[I40E_ETH_TEST_REG] = 1;
1636 data[I40E_ETH_TEST_EEPROM] = 1;
1637 data[I40E_ETH_TEST_INTR] = 1;
1638 data[I40E_ETH_TEST_LOOPBACK] = 1;
1639 data[I40E_ETH_TEST_LINK] = 1;
1640 eth_test->flags |= ETH_TEST_FL_FAILED;
1641 clear_bit(__I40E_TESTING, &pf->state);
1642 goto skip_ol_tests;
1643 }
1644
Greg Rose5b86c5c2015-02-26 16:14:35 +00001645 /* If the device is online then take it offline */
1646 if (if_running)
1647 /* indicate we're in test mode */
1648 dev_close(netdev);
1649 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001650 /* This reset does not affect link - if it is
1651 * changed to a type of reset that does affect
1652 * link then the following link test would have
1653 * to be moved to before the reset
1654 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001655 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001656
Shannon Nelson7b086392013-11-20 10:02:59 +00001657 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658 eth_test->flags |= ETH_TEST_FL_FAILED;
1659
Shannon Nelson7b086392013-11-20 10:02:59 +00001660 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661 eth_test->flags |= ETH_TEST_FL_FAILED;
1662
Shannon Nelson7b086392013-11-20 10:02:59 +00001663 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001664 eth_test->flags |= ETH_TEST_FL_FAILED;
1665
Shannon Nelson7b086392013-11-20 10:02:59 +00001666 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667 eth_test->flags |= ETH_TEST_FL_FAILED;
1668
Shannon Nelsonf551b432013-11-26 10:49:12 +00001669 /* run reg test last, a reset is required after it */
1670 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1671 eth_test->flags |= ETH_TEST_FL_FAILED;
1672
1673 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001674 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001675
1676 if (if_running)
1677 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001678 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001679 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001680 netif_info(pf, drv, netdev, "online testing starting\n");
1681
Shannon Nelson7b086392013-11-20 10:02:59 +00001682 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001683 eth_test->flags |= ETH_TEST_FL_FAILED;
1684
1685 /* Offline only tests, not run in online; pass by default */
1686 data[I40E_ETH_TEST_REG] = 0;
1687 data[I40E_ETH_TEST_EEPROM] = 0;
1688 data[I40E_ETH_TEST_INTR] = 0;
1689 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001690 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001691
Greg Rosee17bc412015-04-16 20:05:59 -04001692skip_ol_tests:
1693
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001694 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695}
1696
1697static void i40e_get_wol(struct net_device *netdev,
1698 struct ethtool_wolinfo *wol)
1699{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001700 struct i40e_netdev_priv *np = netdev_priv(netdev);
1701 struct i40e_pf *pf = np->vsi->back;
1702 struct i40e_hw *hw = &pf->hw;
1703 u16 wol_nvm_bits;
1704
1705 /* NVM bit on means WoL disabled for the port */
1706 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001707 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001708 wol->supported = 0;
1709 wol->wolopts = 0;
1710 } else {
1711 wol->supported = WAKE_MAGIC;
1712 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1713 }
1714}
1715
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001716/**
1717 * i40e_set_wol - set the WakeOnLAN configuration
1718 * @netdev: the netdev in question
1719 * @wol: the ethtool WoL setting data
1720 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001721static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1722{
1723 struct i40e_netdev_priv *np = netdev_priv(netdev);
1724 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001725 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001726 struct i40e_hw *hw = &pf->hw;
1727 u16 wol_nvm_bits;
1728
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001729 /* WoL not supported if this isn't the controlling PF on the port */
1730 if (hw->partition_id != 1) {
1731 i40e_partition_setting_complaint(pf);
1732 return -EOPNOTSUPP;
1733 }
1734
1735 if (vsi != pf->vsi[pf->lan_vsi])
1736 return -EOPNOTSUPP;
1737
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001738 /* NVM bit on means WoL disabled for the port */
1739 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001740 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001741 return -EOPNOTSUPP;
1742
1743 /* only magic packet is supported */
1744 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1745 return -EOPNOTSUPP;
1746
1747 /* is this a new value? */
1748 if (pf->wol_en != !!wol->wolopts) {
1749 pf->wol_en = !!wol->wolopts;
1750 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1751 }
1752
1753 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001754}
1755
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001756static int i40e_set_phys_id(struct net_device *netdev,
1757 enum ethtool_phys_id_state state)
1758{
1759 struct i40e_netdev_priv *np = netdev_priv(netdev);
1760 struct i40e_pf *pf = np->vsi->back;
1761 struct i40e_hw *hw = &pf->hw;
1762 int blink_freq = 2;
1763
1764 switch (state) {
1765 case ETHTOOL_ID_ACTIVE:
1766 pf->led_status = i40e_led_get(hw);
1767 return blink_freq;
1768 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001769 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001770 break;
1771 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001772 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001773 break;
1774 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001775 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001776 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001777 default:
1778 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001779 }
1780
1781 return 0;
1782}
1783
1784/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1785 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1786 * 125us (8000 interrupts per second) == ITR(62)
1787 */
1788
1789static int i40e_get_coalesce(struct net_device *netdev,
1790 struct ethtool_coalesce *ec)
1791{
1792 struct i40e_netdev_priv *np = netdev_priv(netdev);
1793 struct i40e_vsi *vsi = np->vsi;
1794
1795 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1796 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1797
1798 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001799 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001800
1801 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001802 ec->use_adaptive_tx_coalesce = 1;
1803
1804 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1805 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001806
1807 return 0;
1808}
1809
1810static int i40e_set_coalesce(struct net_device *netdev,
1811 struct ethtool_coalesce *ec)
1812{
1813 struct i40e_netdev_priv *np = netdev_priv(netdev);
1814 struct i40e_q_vector *q_vector;
1815 struct i40e_vsi *vsi = np->vsi;
1816 struct i40e_pf *pf = vsi->back;
1817 struct i40e_hw *hw = &pf->hw;
1818 u16 vector;
1819 int i;
1820
1821 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1822 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1823
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001824 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001825 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001826 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001827 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001828 } else if (ec->rx_coalesce_usecs == 0) {
1829 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001830 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001831 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 +00001832 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001833 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001834 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001835 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001836
Mitch Williams32f5f542014-04-04 04:43:10 +00001837 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001838 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001839 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001840 } else if (ec->tx_coalesce_usecs == 0) {
1841 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001842 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001843 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 +00001844 } else {
1845 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001846 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001847 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001848 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001849
1850 if (ec->use_adaptive_rx_coalesce)
1851 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1852 else
1853 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1854
1855 if (ec->use_adaptive_tx_coalesce)
1856 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1857 else
1858 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001859
Alexander Duyck493fb302013-09-28 07:01:44 +00001860 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1861 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001862 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1863 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1864 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1865 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1866 i40e_flush(hw);
1867 }
1868
1869 return 0;
1870}
1871
1872/**
1873 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1874 * @pf: pointer to the physical function struct
1875 * @cmd: ethtool rxnfc command
1876 *
1877 * Returns Success if the flow is supported, else Invalid Input.
1878 **/
1879static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1880{
1881 cmd->data = 0;
1882
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001883 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1884 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1885 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1886 return 0;
1887 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001888 /* Report default options for RSS on i40e */
1889 switch (cmd->flow_type) {
1890 case TCP_V4_FLOW:
1891 case UDP_V4_FLOW:
1892 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1893 /* fall through to add IP fields */
1894 case SCTP_V4_FLOW:
1895 case AH_ESP_V4_FLOW:
1896 case AH_V4_FLOW:
1897 case ESP_V4_FLOW:
1898 case IPV4_FLOW:
1899 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1900 break;
1901 case TCP_V6_FLOW:
1902 case UDP_V6_FLOW:
1903 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1904 /* fall through to add IP fields */
1905 case SCTP_V6_FLOW:
1906 case AH_ESP_V6_FLOW:
1907 case AH_V6_FLOW:
1908 case ESP_V6_FLOW:
1909 case IPV6_FLOW:
1910 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1911 break;
1912 default:
1913 return -EINVAL;
1914 }
1915
1916 return 0;
1917}
1918
1919/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001920 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1921 * @pf: Pointer to the physical function struct
1922 * @cmd: The command to get or set Rx flow classification rules
1923 * @rule_locs: Array of used rule locations
1924 *
1925 * This function populates both the total and actual rule count of
1926 * the ethtool flow classification command
1927 *
1928 * Returns 0 on success or -EMSGSIZE if entry not found
1929 **/
1930static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1931 struct ethtool_rxnfc *cmd,
1932 u32 *rule_locs)
1933{
1934 struct i40e_fdir_filter *rule;
1935 struct hlist_node *node2;
1936 int cnt = 0;
1937
1938 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001939 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001940
1941 hlist_for_each_entry_safe(rule, node2,
1942 &pf->fdir_filter_list, fdir_node) {
1943 if (cnt == cmd->rule_cnt)
1944 return -EMSGSIZE;
1945
1946 rule_locs[cnt] = rule->fd_id;
1947 cnt++;
1948 }
1949
1950 cmd->rule_cnt = cnt;
1951
1952 return 0;
1953}
1954
1955/**
1956 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1957 * @pf: Pointer to the physical function struct
1958 * @cmd: The command to get or set Rx flow classification rules
1959 *
1960 * This function looks up a filter based on the Rx flow classification
1961 * command and fills the flow spec info for it if found
1962 *
1963 * Returns 0 on success or -EINVAL if filter not found
1964 **/
1965static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1966 struct ethtool_rxnfc *cmd)
1967{
1968 struct ethtool_rx_flow_spec *fsp =
1969 (struct ethtool_rx_flow_spec *)&cmd->fs;
1970 struct i40e_fdir_filter *rule = NULL;
1971 struct hlist_node *node2;
1972
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001973 hlist_for_each_entry_safe(rule, node2,
1974 &pf->fdir_filter_list, fdir_node) {
1975 if (fsp->location <= rule->fd_id)
1976 break;
1977 }
1978
1979 if (!rule || fsp->location != rule->fd_id)
1980 return -EINVAL;
1981
1982 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001983 if (fsp->flow_type == IP_USER_FLOW) {
1984 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1985 fsp->h_u.usr_ip4_spec.proto = 0;
1986 fsp->m_u.usr_ip4_spec.proto = 0;
1987 }
1988
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001989 /* Reverse the src and dest notion, since the HW views them from
1990 * Tx perspective where as the user expects it from Rx filter view.
1991 */
1992 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1993 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1994 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1995 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001996
1997 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1998 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1999 else
2000 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002001
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002002 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2003 struct i40e_vsi *vsi;
2004
2005 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2006 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2007 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2008 fsp->m_ext.data[1] = htonl(0x1);
2009 }
2010 }
2011
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002012 return 0;
2013}
2014
2015/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002016 * i40e_get_rxnfc - command to get RX flow classification rules
2017 * @netdev: network interface device structure
2018 * @cmd: ethtool rxnfc command
2019 *
2020 * Returns Success if the command is supported.
2021 **/
2022static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2023 u32 *rule_locs)
2024{
2025 struct i40e_netdev_priv *np = netdev_priv(netdev);
2026 struct i40e_vsi *vsi = np->vsi;
2027 struct i40e_pf *pf = vsi->back;
2028 int ret = -EOPNOTSUPP;
2029
2030 switch (cmd->cmd) {
2031 case ETHTOOL_GRXRINGS:
2032 cmd->data = vsi->alloc_queue_pairs;
2033 ret = 0;
2034 break;
2035 case ETHTOOL_GRXFH:
2036 ret = i40e_get_rss_hash_opts(pf, cmd);
2037 break;
2038 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002039 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002040 /* report total rule count */
2041 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002042 ret = 0;
2043 break;
2044 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002045 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002046 break;
2047 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002048 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2049 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002050 default:
2051 break;
2052 }
2053
2054 return ret;
2055}
2056
2057/**
2058 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2059 * @pf: pointer to the physical function struct
2060 * @cmd: ethtool rxnfc command
2061 *
2062 * Returns Success if the flow input set is supported.
2063 **/
2064static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2065{
2066 struct i40e_hw *hw = &pf->hw;
2067 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2068 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2069
2070 /* RSS does not support anything other than hashing
2071 * to queues on src and dst IPs and ports
2072 */
2073 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2074 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2075 return -EINVAL;
2076
2077 /* We need at least the IP SRC and DEST fields for hashing */
2078 if (!(nfc->data & RXH_IP_SRC) ||
2079 !(nfc->data & RXH_IP_DST))
2080 return -EINVAL;
2081
2082 switch (nfc->flow_type) {
2083 case TCP_V4_FLOW:
2084 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2085 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002086 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002087 break;
2088 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002089 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002090 break;
2091 default:
2092 return -EINVAL;
2093 }
2094 break;
2095 case TCP_V6_FLOW:
2096 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2097 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002098 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002099 break;
2100 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002101 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002102 break;
2103 default:
2104 return -EINVAL;
2105 }
2106 break;
2107 case UDP_V4_FLOW:
2108 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2109 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002110 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2111 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002112 break;
2113 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002114 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2115 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002116 break;
2117 default:
2118 return -EINVAL;
2119 }
2120 break;
2121 case UDP_V6_FLOW:
2122 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2123 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002124 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2125 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002126 break;
2127 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002128 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2129 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002130 break;
2131 default:
2132 return -EINVAL;
2133 }
2134 break;
2135 case AH_ESP_V4_FLOW:
2136 case AH_V4_FLOW:
2137 case ESP_V4_FLOW:
2138 case SCTP_V4_FLOW:
2139 if ((nfc->data & RXH_L4_B_0_1) ||
2140 (nfc->data & RXH_L4_B_2_3))
2141 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002142 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002143 break;
2144 case AH_ESP_V6_FLOW:
2145 case AH_V6_FLOW:
2146 case ESP_V6_FLOW:
2147 case SCTP_V6_FLOW:
2148 if ((nfc->data & RXH_L4_B_0_1) ||
2149 (nfc->data & RXH_L4_B_2_3))
2150 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002151 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002152 break;
2153 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002154 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2155 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002156 break;
2157 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002158 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2159 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002160 break;
2161 default:
2162 return -EINVAL;
2163 }
2164
2165 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2166 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2167 i40e_flush(hw);
2168
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002169 /* Save setting for future output/update */
2170 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2171
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 return 0;
2173}
2174
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002175/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002176 * i40e_match_fdir_input_set - Match a new filter against an existing one
2177 * @rule: The filter already added
2178 * @input: The new filter to comapre against
2179 *
2180 * Returns true if the two input set match
2181 **/
2182static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2183 struct i40e_fdir_filter *input)
2184{
2185 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2186 (rule->src_ip[0] != input->src_ip[0]) ||
2187 (rule->dst_port != input->dst_port) ||
2188 (rule->src_port != input->src_port))
2189 return false;
2190 return true;
2191}
2192
2193/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002194 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2195 * @vsi: Pointer to the targeted VSI
2196 * @input: The filter to update or NULL to indicate deletion
2197 * @sw_idx: Software index to the filter
2198 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002199 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002200 * This function updates (or deletes) a Flow Director entry from
2201 * the hlist of the corresponding PF
2202 *
2203 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002205static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2206 struct i40e_fdir_filter *input,
2207 u16 sw_idx,
2208 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002209{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002210 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002211 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002212 struct hlist_node *node2;
2213 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002214
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002215 parent = NULL;
2216 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002217
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002218 hlist_for_each_entry_safe(rule, node2,
2219 &pf->fdir_filter_list, fdir_node) {
2220 /* hash found, or no matching entry */
2221 if (rule->fd_id >= sw_idx)
2222 break;
2223 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002224 }
2225
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002226 /* if there is an old rule occupying our place remove it */
2227 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002228 if (input && !i40e_match_fdir_input_set(rule, input))
2229 err = i40e_add_del_fdir(vsi, rule, false);
2230 else if (!input)
2231 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002232 hlist_del(&rule->fdir_node);
2233 kfree(rule);
2234 pf->fdir_pf_active_filters--;
2235 }
2236
2237 /* If no input this was a delete, err should be 0 if a rule was
2238 * successfully found and removed from the list else -EINVAL
2239 */
2240 if (!input)
2241 return err;
2242
2243 /* initialize node and set software index */
2244 INIT_HLIST_NODE(&input->fdir_node);
2245
2246 /* add filter to the list */
2247 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002248 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002249 else
2250 hlist_add_head(&input->fdir_node,
2251 &pf->fdir_filter_list);
2252
2253 /* update counts */
2254 pf->fdir_pf_active_filters++;
2255
2256 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002257}
2258
2259/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002260 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2261 * @vsi: Pointer to the targeted VSI
2262 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002263 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002264 * The function removes a Flow Director filter entry from the
2265 * hlist of the corresponding PF
2266 *
2267 * Returns 0 on success
2268 */
2269static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2270 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002271{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002272 struct ethtool_rx_flow_spec *fsp =
2273 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002274 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002275 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002276
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002277 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2278 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2279 return -EBUSY;
2280
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002281 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2282 return -EBUSY;
2283
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002284 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002285
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002286 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002287 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002288}
2289
2290/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002291 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002292 * @vsi: pointer to the targeted VSI
2293 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002294 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002295 * Add Flow Director filters for a specific flow spec based on their
2296 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002297 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002298static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2299 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002300{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002301 struct ethtool_rx_flow_spec *fsp;
2302 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002303 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002304 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002305 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002306
2307 if (!vsi)
2308 return -EINVAL;
2309
2310 pf = vsi->back;
2311
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002312 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2313 return -EOPNOTSUPP;
2314
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002315 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002316 return -ENOSPC;
2317
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002318 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2319 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2320 return -EBUSY;
2321
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002322 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2323 return -EBUSY;
2324
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002325 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2326
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002327 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2328 pf->hw.func_caps.fd_filters_guaranteed)) {
2329 return -EINVAL;
2330 }
2331
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002332 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2333 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002334 return -EINVAL;
2335
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002336 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002337
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002338 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002339 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002340
2341 input->fd_id = fsp->location;
2342
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002343 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2344 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2345 else
2346 input->dest_ctl =
2347 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2348
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002349 input->q_index = fsp->ring_cookie;
2350 input->flex_off = 0;
2351 input->pctype = 0;
2352 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002353 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002354 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002355 input->flow_type = fsp->flow_type;
2356 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002357
2358 /* Reverse the src and dest notion, since the HW expects them to be from
2359 * Tx perspective where as the input from user is from Rx filter view.
2360 */
2361 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2362 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2363 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2364 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002365
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002366 if (ntohl(fsp->m_ext.data[1])) {
2367 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2368 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2369 goto free_input;
2370 }
2371 vf_id = ntohl(fsp->h_ext.data[1]);
2372 /* Find vsi id from vf id and override dest vsi */
2373 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2374 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2375 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2376 goto free_input;
2377 }
2378 }
2379
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002380 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002381free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002382 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002383 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002384 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002385 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002386
2387 return ret;
2388}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002389
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002390/**
2391 * i40e_set_rxnfc - command to set RX flow classification rules
2392 * @netdev: network interface device structure
2393 * @cmd: ethtool rxnfc command
2394 *
2395 * Returns Success if the command is supported.
2396 **/
2397static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2398{
2399 struct i40e_netdev_priv *np = netdev_priv(netdev);
2400 struct i40e_vsi *vsi = np->vsi;
2401 struct i40e_pf *pf = vsi->back;
2402 int ret = -EOPNOTSUPP;
2403
2404 switch (cmd->cmd) {
2405 case ETHTOOL_SRXFH:
2406 ret = i40e_set_rss_hash_opt(pf, cmd);
2407 break;
2408 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002409 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002410 break;
2411 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002412 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002413 break;
2414 default:
2415 break;
2416 }
2417
2418 return ret;
2419}
2420
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002421/**
2422 * i40e_max_channels - get Max number of combined channels supported
2423 * @vsi: vsi pointer
2424 **/
2425static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2426{
2427 /* TODO: This code assumes DCB and FD is disabled for now. */
2428 return vsi->alloc_queue_pairs;
2429}
2430
2431/**
2432 * i40e_get_channels - Get the current channels enabled and max supported etc.
2433 * @netdev: network interface device structure
2434 * @ch: ethtool channels structure
2435 *
2436 * We don't support separate tx and rx queues as channels. The other count
2437 * represents how many queues are being used for control. max_combined counts
2438 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2439 * q_vectors since we support a lot more queue pairs than q_vectors.
2440 **/
2441static void i40e_get_channels(struct net_device *dev,
2442 struct ethtool_channels *ch)
2443{
2444 struct i40e_netdev_priv *np = netdev_priv(dev);
2445 struct i40e_vsi *vsi = np->vsi;
2446 struct i40e_pf *pf = vsi->back;
2447
2448 /* report maximum channels */
2449 ch->max_combined = i40e_max_channels(vsi);
2450
2451 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002452 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002453 ch->max_other = ch->other_count;
2454
2455 /* Note: This code assumes DCB is disabled for now. */
2456 ch->combined_count = vsi->num_queue_pairs;
2457}
2458
2459/**
2460 * i40e_set_channels - Set the new channels count.
2461 * @netdev: network interface device structure
2462 * @ch: ethtool channels structure
2463 *
2464 * The new channels count may not be the same as requested by the user
2465 * since it gets rounded down to a power of 2 value.
2466 **/
2467static int i40e_set_channels(struct net_device *dev,
2468 struct ethtool_channels *ch)
2469{
2470 struct i40e_netdev_priv *np = netdev_priv(dev);
2471 unsigned int count = ch->combined_count;
2472 struct i40e_vsi *vsi = np->vsi;
2473 struct i40e_pf *pf = vsi->back;
2474 int new_count;
2475
2476 /* We do not support setting channels for any other VSI at present */
2477 if (vsi->type != I40E_VSI_MAIN)
2478 return -EINVAL;
2479
2480 /* verify they are not requesting separate vectors */
2481 if (!count || ch->rx_count || ch->tx_count)
2482 return -EINVAL;
2483
2484 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002485 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002486 return -EINVAL;
2487
2488 /* verify the number of channels does not exceed hardware limits */
2489 if (count > i40e_max_channels(vsi))
2490 return -EINVAL;
2491
2492 /* update feature limits from largest to smallest supported values */
2493 /* TODO: Flow director limit, DCB etc */
2494
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002495 /* use rss_reconfig to rebuild with new queue count and update traffic
2496 * class queue mapping
2497 */
2498 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002499 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002500 return 0;
2501 else
2502 return -EINVAL;
2503}
2504
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002505#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2506/**
2507 * i40e_get_rxfh_key_size - get the RSS hash key size
2508 * @netdev: network interface device structure
2509 *
2510 * Returns the table size.
2511 **/
2512static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2513{
2514 return I40E_HKEY_ARRAY_SIZE;
2515}
2516
2517/**
2518 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2519 * @netdev: network interface device structure
2520 *
2521 * Returns the table size.
2522 **/
2523static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2524{
2525 return I40E_HLUT_ARRAY_SIZE;
2526}
2527
2528static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2529 u8 *hfunc)
2530{
2531 struct i40e_netdev_priv *np = netdev_priv(netdev);
2532 struct i40e_vsi *vsi = np->vsi;
2533 struct i40e_pf *pf = vsi->back;
2534 struct i40e_hw *hw = &pf->hw;
2535 u32 reg_val;
2536 int i, j;
2537
2538 if (hfunc)
2539 *hfunc = ETH_RSS_HASH_TOP;
2540
2541 if (!indir)
2542 return 0;
2543
2544 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2545 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2546 indir[j++] = reg_val & 0xff;
2547 indir[j++] = (reg_val >> 8) & 0xff;
2548 indir[j++] = (reg_val >> 16) & 0xff;
2549 indir[j++] = (reg_val >> 24) & 0xff;
2550 }
2551
2552 if (key) {
2553 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2554 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2555 key[j++] = (u8)(reg_val & 0xff);
2556 key[j++] = (u8)((reg_val >> 8) & 0xff);
2557 key[j++] = (u8)((reg_val >> 16) & 0xff);
2558 key[j++] = (u8)((reg_val >> 24) & 0xff);
2559 }
2560 }
2561 return 0;
2562}
2563
2564/**
2565 * i40e_set_rxfh - set the rx flow hash indirection table
2566 * @netdev: network interface device structure
2567 * @indir: indirection table
2568 * @key: hash key
2569 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002570 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002571 * returns 0 after programming the table.
2572 **/
2573static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2574 const u8 *key, const u8 hfunc)
2575{
2576 struct i40e_netdev_priv *np = netdev_priv(netdev);
2577 struct i40e_vsi *vsi = np->vsi;
2578 struct i40e_pf *pf = vsi->back;
2579 struct i40e_hw *hw = &pf->hw;
2580 u32 reg_val;
2581 int i, j;
2582
2583 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2584 return -EOPNOTSUPP;
2585
2586 if (!indir)
2587 return 0;
2588
2589 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2590 reg_val = indir[j++];
2591 reg_val |= indir[j++] << 8;
2592 reg_val |= indir[j++] << 16;
2593 reg_val |= indir[j++] << 24;
2594 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2595 }
2596
2597 if (key) {
2598 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2599 reg_val = key[j++];
2600 reg_val |= key[j++] << 8;
2601 reg_val |= key[j++] << 16;
2602 reg_val |= key[j++] << 24;
2603 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2604 }
2605 }
2606 return 0;
2607}
2608
Greg Rose7e45ab42015-02-06 08:52:19 +00002609/**
2610 * i40e_get_priv_flags - report device private flags
2611 * @dev: network interface device structure
2612 *
2613 * The get string set count and the string set should be matched for each
2614 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2615 * array.
2616 *
2617 * Returns a u32 bitmap of flags.
2618 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002619static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002620{
2621 struct i40e_netdev_priv *np = netdev_priv(dev);
2622 struct i40e_vsi *vsi = np->vsi;
2623 struct i40e_pf *pf = vsi->back;
2624 u32 ret_flags = 0;
2625
2626 ret_flags |= pf->hw.func_caps.npar_enable ?
2627 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2628
2629 return ret_flags;
2630}
2631
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002632static const struct ethtool_ops i40e_ethtool_ops = {
2633 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002634 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002635 .get_drvinfo = i40e_get_drvinfo,
2636 .get_regs_len = i40e_get_regs_len,
2637 .get_regs = i40e_get_regs,
2638 .nway_reset = i40e_nway_reset,
2639 .get_link = ethtool_op_get_link,
2640 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002641 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002642 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002643 .get_eeprom_len = i40e_get_eeprom_len,
2644 .get_eeprom = i40e_get_eeprom,
2645 .get_ringparam = i40e_get_ringparam,
2646 .set_ringparam = i40e_set_ringparam,
2647 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002648 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002649 .get_msglevel = i40e_get_msglevel,
2650 .set_msglevel = i40e_set_msglevel,
2651 .get_rxnfc = i40e_get_rxnfc,
2652 .set_rxnfc = i40e_set_rxnfc,
2653 .self_test = i40e_diag_test,
2654 .get_strings = i40e_get_strings,
2655 .set_phys_id = i40e_set_phys_id,
2656 .get_sset_count = i40e_get_sset_count,
2657 .get_ethtool_stats = i40e_get_ethtool_stats,
2658 .get_coalesce = i40e_get_coalesce,
2659 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002660 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2661 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2662 .get_rxfh = i40e_get_rxfh,
2663 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002664 .get_channels = i40e_get_channels,
2665 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002666 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002667 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002668};
2669
2670void i40e_set_ethtool_ops(struct net_device *netdev)
2671{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002672 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002673}