blob: ffa943164b42c916214e825dab5131b851651b0d [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),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Shannon Nelson41a9e552014-04-23 04:50:20 +000091};
92
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000093static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
94 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000095
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096/* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
102 *
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
105 */
106static struct i40e_stats i40e_gstrings_stats[] = {
107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000148 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000149 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000150 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400151 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400152 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000153 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000156 /* LPI stats */
157 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
158 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
159 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
160 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000161};
162
Vasu Dev38e00432014-08-01 13:27:03 -0700163#ifdef I40E_FCOE
164static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
165 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
166 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
167 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
168 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
169 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
170 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
171 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
172 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
173};
174
175#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000177 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
178 * 2 /* Tx and Rx together */ \
179 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000180#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
181#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000182#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700183#ifdef I40E_FCOE
184#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
185#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
186 I40E_FCOE_STATS_LEN + \
187 I40E_MISC_STATS_LEN + \
188 I40E_QUEUE_STATS_LEN((n)))
189#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000191 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700193#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194#define I40E_PFC_STATS_LEN ( \
195 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
200 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400201#define I40E_VEB_TC_STATS_LEN ( \
202 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
206 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000207#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400208#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000209#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
210 I40E_PFC_STATS_LEN + \
211 I40E_VSI_STATS_LEN((n)))
212
213enum i40e_ethtool_test_id {
214 I40E_ETH_TEST_REG = 0,
215 I40E_ETH_TEST_EEPROM,
216 I40E_ETH_TEST_INTR,
217 I40E_ETH_TEST_LOOPBACK,
218 I40E_ETH_TEST_LINK,
219};
220
221static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
222 "Register test (offline)",
223 "Eeprom test (offline)",
224 "Interrupt test (offline)",
225 "Loopback test (offline)",
226 "Link test (on/offline)"
227};
228
229#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
230
Greg Rose7e45ab42015-02-06 08:52:19 +0000231static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
232 "NPAR",
233};
234
235#define I40E_PRIV_FLAGS_STR_LEN \
236 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
237
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000238/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000239 * i40e_partition_setting_complaint - generic complaint for MFP restriction
240 * @pf: the PF struct
241 **/
242static void i40e_partition_setting_complaint(struct i40e_pf *pf)
243{
244 dev_info(&pf->pdev->dev,
245 "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");
246}
247
248/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000249 * i40e_get_settings_link_up - Get the Link settings for when link is up
250 * @hw: hw structure
251 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000255static void i40e_get_settings_link_up(struct i40e_hw *hw,
256 struct ethtool_cmd *ecmd,
257 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260 u32 link_speed = hw_link_info->link_speed;
261
Catherine Sullivane8278452015-02-06 08:52:08 +0000262 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000263 switch (hw_link_info->phy_type) {
264 case I40E_PHY_TYPE_40GBASE_CR4:
265 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000266 ecmd->supported = SUPPORTED_Autoneg |
267 SUPPORTED_40000baseCR4_Full;
268 ecmd->advertising = ADVERTISED_Autoneg |
269 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000270 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000271 case I40E_PHY_TYPE_XLAUI:
272 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000273 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000274 ecmd->supported = SUPPORTED_40000baseCR4_Full;
275 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000277 ecmd->supported = SUPPORTED_Autoneg |
278 SUPPORTED_40000baseKR4_Full;
279 ecmd->advertising = ADVERTISED_Autoneg |
280 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000281 break;
282 case I40E_PHY_TYPE_40GBASE_SR4:
283 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000284 break;
285 case I40E_PHY_TYPE_40GBASE_LR4:
286 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000287 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700288 case I40E_PHY_TYPE_20GBASE_KR2:
289 ecmd->supported = SUPPORTED_Autoneg |
290 SUPPORTED_20000baseKR2_Full;
291 ecmd->advertising = ADVERTISED_Autoneg |
292 ADVERTISED_20000baseKR2_Full;
293 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000294 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000295 ecmd->supported = SUPPORTED_Autoneg |
296 SUPPORTED_10000baseKX4_Full;
297 ecmd->advertising = ADVERTISED_Autoneg |
298 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000299 break;
300 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 ecmd->supported = SUPPORTED_Autoneg |
302 SUPPORTED_10000baseKR_Full;
303 ecmd->advertising = ADVERTISED_Autoneg |
304 ADVERTISED_10000baseKR_Full;
305 break;
306 case I40E_PHY_TYPE_10GBASE_SR:
307 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000308 case I40E_PHY_TYPE_1000BASE_SX:
309 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000310 ecmd->supported = SUPPORTED_10000baseT_Full |
311 SUPPORTED_1000baseT_Full;
312 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
313 ecmd->advertising |= ADVERTISED_10000baseT_Full;
314 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
315 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000316 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000317 case I40E_PHY_TYPE_1000BASE_KX:
318 ecmd->supported = SUPPORTED_Autoneg |
319 SUPPORTED_1000baseKX_Full;
320 ecmd->advertising = ADVERTISED_Autoneg |
321 ADVERTISED_1000baseKX_Full;
322 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000323 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000324 case I40E_PHY_TYPE_1000BASE_T:
325 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000326 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000327 SUPPORTED_10000baseT_Full |
328 SUPPORTED_1000baseT_Full |
329 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000330 ecmd->advertising = ADVERTISED_Autoneg;
331 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
332 ecmd->advertising |= ADVERTISED_10000baseT_Full;
333 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
334 ecmd->advertising |= ADVERTISED_1000baseT_Full;
335 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
336 ecmd->advertising |= ADVERTISED_100baseT_Full;
337 break;
338 case I40E_PHY_TYPE_10GBASE_CR1_CU:
339 case I40E_PHY_TYPE_10GBASE_CR1:
340 ecmd->supported = SUPPORTED_Autoneg |
341 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000342 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000343 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000344 break;
345 case I40E_PHY_TYPE_XAUI:
346 case I40E_PHY_TYPE_XFI:
347 case I40E_PHY_TYPE_SFI:
348 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000349 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000350 ecmd->supported = SUPPORTED_10000baseT_Full;
351 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000352 case I40E_PHY_TYPE_SGMII:
353 ecmd->supported = SUPPORTED_Autoneg |
354 SUPPORTED_1000baseT_Full |
355 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000356 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
357 ecmd->advertising |= ADVERTISED_1000baseT_Full;
358 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
359 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000360 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000361 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000362 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000363 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
364 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000365 }
366
Catherine Sullivane8278452015-02-06 08:52:08 +0000367 /* Set speed and duplex */
368 switch (link_speed) {
369 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400370 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000371 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700372 case I40E_LINK_SPEED_20GB:
373 ethtool_cmd_speed_set(ecmd, SPEED_20000);
374 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000375 case I40E_LINK_SPEED_10GB:
376 ethtool_cmd_speed_set(ecmd, SPEED_10000);
377 break;
378 case I40E_LINK_SPEED_1GB:
379 ethtool_cmd_speed_set(ecmd, SPEED_1000);
380 break;
381 case I40E_LINK_SPEED_100MB:
382 ethtool_cmd_speed_set(ecmd, SPEED_100);
383 break;
384 default:
385 break;
386 }
387 ecmd->duplex = DUPLEX_FULL;
388}
389
390/**
391 * i40e_get_settings_link_down - Get the Link settings for when link is down
392 * @hw: hw structure
393 * @ecmd: ethtool command to fill in
394 *
395 * Reports link settings that can be determined when link is down
396 **/
397static void i40e_get_settings_link_down(struct i40e_hw *hw,
398 struct ethtool_cmd *ecmd)
399{
400 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
401
402 /* link is down and the driver needs to fall back on
403 * device ID to determine what kinds of info to display,
404 * it's mostly a guess that may change when link is up
405 */
406 switch (hw->device_id) {
407 case I40E_DEV_ID_QSFP_A:
408 case I40E_DEV_ID_QSFP_B:
409 case I40E_DEV_ID_QSFP_C:
410 /* pluggable QSFP */
411 ecmd->supported = SUPPORTED_40000baseSR4_Full |
412 SUPPORTED_40000baseCR4_Full |
413 SUPPORTED_40000baseLR4_Full;
414 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
415 ADVERTISED_40000baseCR4_Full |
416 ADVERTISED_40000baseLR4_Full;
417 break;
418 case I40E_DEV_ID_KX_B:
419 /* backplane 40G */
420 ecmd->supported = SUPPORTED_40000baseKR4_Full;
421 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
422 break;
423 case I40E_DEV_ID_KX_C:
424 /* backplane 10G */
425 ecmd->supported = SUPPORTED_10000baseKR_Full;
426 ecmd->advertising = ADVERTISED_10000baseKR_Full;
427 break;
428 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -0400429 case I40E_DEV_ID_10G_BASE_T4:
Catherine Sullivane8278452015-02-06 08:52:08 +0000430 ecmd->supported = SUPPORTED_10000baseT_Full |
431 SUPPORTED_1000baseT_Full |
432 SUPPORTED_100baseT_Full;
433 /* Figure out what has been requested */
434 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
435 ecmd->advertising |= ADVERTISED_10000baseT_Full;
436 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
437 ecmd->advertising |= ADVERTISED_1000baseT_Full;
438 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
439 ecmd->advertising |= ADVERTISED_100baseT_Full;
440 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700441 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -0400442 case I40E_DEV_ID_20G_KR2_A:
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700443 /* backplane 20G */
444 ecmd->supported = SUPPORTED_20000baseKR2_Full;
445 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
446 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000447 default:
448 /* all the rest are 10G/1G */
449 ecmd->supported = SUPPORTED_10000baseT_Full |
450 SUPPORTED_1000baseT_Full;
451 /* Figure out what has been requested */
452 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
453 ecmd->advertising |= ADVERTISED_10000baseT_Full;
454 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
455 ecmd->advertising |= ADVERTISED_1000baseT_Full;
456 break;
457 }
458
459 /* With no link speed and duplex are unknown */
460 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
461 ecmd->duplex = DUPLEX_UNKNOWN;
462}
463
464/**
465 * i40e_get_settings - Get Link Speed and Duplex settings
466 * @netdev: network interface device structure
467 * @ecmd: ethtool command
468 *
469 * Reports speed/duplex settings based on media_type
470 **/
471static int i40e_get_settings(struct net_device *netdev,
472 struct ethtool_cmd *ecmd)
473{
474 struct i40e_netdev_priv *np = netdev_priv(netdev);
475 struct i40e_pf *pf = np->vsi->back;
476 struct i40e_hw *hw = &pf->hw;
477 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
478 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
479
480 if (link_up)
481 i40e_get_settings_link_up(hw, ecmd, netdev);
482 else
483 i40e_get_settings_link_down(hw, ecmd);
484
485 /* Now set the settings that don't rely on link being up/down */
486
487 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000488 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
489 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000491 switch (hw->phy.media_type) {
492 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000493 ecmd->supported |= SUPPORTED_Autoneg |
494 SUPPORTED_Backplane;
495 ecmd->advertising |= ADVERTISED_Autoneg |
496 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000497 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000498 break;
499 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000500 ecmd->supported |= SUPPORTED_TP;
501 ecmd->advertising |= ADVERTISED_TP;
502 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000503 break;
504 case I40E_MEDIA_TYPE_DA:
505 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000506 ecmd->supported |= SUPPORTED_FIBRE;
507 ecmd->advertising |= ADVERTISED_FIBRE;
508 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000509 break;
510 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000511 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000512 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000513 break;
514 case I40E_MEDIA_TYPE_UNKNOWN:
515 default:
516 ecmd->port = PORT_OTHER;
517 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000518 }
519
Catherine Sullivane8278452015-02-06 08:52:08 +0000520 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000521 ecmd->transceiver = XCVR_EXTERNAL;
522
Catherine Sullivane8278452015-02-06 08:52:08 +0000523 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000524 ecmd->supported |= SUPPORTED_Pause;
525
Catherine Sullivane8278452015-02-06 08:52:08 +0000526 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000527 case I40E_FC_FULL:
528 ecmd->advertising |= ADVERTISED_Pause;
529 break;
530 case I40E_FC_TX_PAUSE:
531 ecmd->advertising |= ADVERTISED_Asym_Pause;
532 break;
533 case I40E_FC_RX_PAUSE:
534 ecmd->advertising |= (ADVERTISED_Pause |
535 ADVERTISED_Asym_Pause);
536 break;
537 default:
538 ecmd->advertising &= ~(ADVERTISED_Pause |
539 ADVERTISED_Asym_Pause);
540 break;
541 }
542
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000543 return 0;
544}
545
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000546/**
547 * i40e_set_settings - Set Speed and Duplex
548 * @netdev: network interface device structure
549 * @ecmd: ethtool command
550 *
551 * Set speed/duplex per media_types advertised/forced
552 **/
553static int i40e_set_settings(struct net_device *netdev,
554 struct ethtool_cmd *ecmd)
555{
556 struct i40e_netdev_priv *np = netdev_priv(netdev);
557 struct i40e_aq_get_phy_abilities_resp abilities;
558 struct i40e_aq_set_phy_config config;
559 struct i40e_pf *pf = np->vsi->back;
560 struct i40e_vsi *vsi = np->vsi;
561 struct i40e_hw *hw = &pf->hw;
562 struct ethtool_cmd safe_ecmd;
563 i40e_status status = 0;
564 bool change = false;
565 int err = 0;
566 u8 autoneg;
567 u32 advertise;
568
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000569 /* Changing port settings is not supported if this isn't the
570 * port's controlling PF
571 */
572 if (hw->partition_id != 1) {
573 i40e_partition_setting_complaint(pf);
574 return -EOPNOTSUPP;
575 }
576
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000577 if (vsi != pf->vsi[pf->lan_vsi])
578 return -EOPNOTSUPP;
579
580 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
581 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000582 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
583 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000584 return -EOPNOTSUPP;
585
586 /* get our own copy of the bits to check against */
587 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
588 i40e_get_settings(netdev, &safe_ecmd);
589
590 /* save autoneg and speed out of ecmd */
591 autoneg = ecmd->autoneg;
592 advertise = ecmd->advertising;
593
594 /* set autoneg and speed back to what they currently are */
595 ecmd->autoneg = safe_ecmd.autoneg;
596 ecmd->advertising = safe_ecmd.advertising;
597
598 ecmd->cmd = safe_ecmd.cmd;
599 /* If ecmd and safe_ecmd are not the same now, then they are
600 * trying to set something that we do not support
601 */
602 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
603 return -EOPNOTSUPP;
604
605 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
606 usleep_range(1000, 2000);
607
608 /* Get the current phy config */
609 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
610 NULL);
611 if (status)
612 return -EAGAIN;
613
Catherine Sullivan124ed152014-07-12 07:28:12 +0000614 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000615 * set below
616 */
617 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000618 config.abilities = abilities.abilities;
619
620 /* Check autoneg */
621 if (autoneg == AUTONEG_ENABLE) {
622 /* If autoneg is not supported, return error */
623 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
624 netdev_info(netdev, "Autoneg not supported on this phy\n");
625 return -EINVAL;
626 }
627 /* If autoneg was not already enabled */
628 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
629 config.abilities = abilities.abilities |
630 I40E_AQ_PHY_ENABLE_AN;
631 change = true;
632 }
633 } else {
634 /* If autoneg is supported 10GBASE_T is the only phy that
635 * can disable it, so otherwise return error
636 */
637 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
638 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
639 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
640 return -EINVAL;
641 }
642 /* If autoneg is currently enabled */
643 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000644 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000645 ~I40E_AQ_PHY_ENABLE_AN;
646 change = true;
647 }
648 }
649
650 if (advertise & ~safe_ecmd.supported)
651 return -EINVAL;
652
653 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000654 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000655 if (advertise & ADVERTISED_1000baseT_Full ||
656 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000657 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000658 if (advertise & ADVERTISED_10000baseT_Full ||
659 advertise & ADVERTISED_10000baseKX4_Full ||
660 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000661 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700662 if (advertise & ADVERTISED_20000baseKR2_Full)
663 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000664 if (advertise & ADVERTISED_40000baseKR4_Full ||
665 advertise & ADVERTISED_40000baseCR4_Full ||
666 advertise & ADVERTISED_40000baseSR4_Full ||
667 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000668 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000669
Catherine Sullivan0002e112015-08-26 15:14:16 -0400670 /* If speed didn't get set, set it to what it currently is.
671 * This is needed because if advertise is 0 (as it is when autoneg
672 * is disabled) then speed won't get set.
673 */
674 if (!config.link_speed)
675 config.link_speed = abilities.link_speed;
676
Catherine Sullivan124ed152014-07-12 07:28:12 +0000677 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000678 /* copy over the rest of the abilities */
679 config.phy_type = abilities.phy_type;
680 config.eee_capability = abilities.eee_capability;
681 config.eeer = abilities.eeer_val;
682 config.low_power_ctrl = abilities.d3_lpan;
683
Catherine Sullivane8278452015-02-06 08:52:08 +0000684 /* save the requested speeds */
685 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000686 /* set link and auto negotiation so changes take effect */
687 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
688 /* If link is up put link down */
689 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
690 /* Tell the OS link is going down, the link will go
691 * back up when fw says it is ready asynchronously
692 */
693 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
694 netif_carrier_off(netdev);
695 netif_tx_stop_all_queues(netdev);
696 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000697
698 /* make the aq call */
699 status = i40e_aq_set_phy_config(hw, &config, NULL);
700 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400701 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
702 i40e_stat_str(hw, status),
703 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000704 return -EAGAIN;
705 }
706
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000707 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000708 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400709 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
710 i40e_stat_str(hw, status),
711 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000712
713 } else {
714 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
715 }
716
717 return err;
718}
719
Jesse Brandeburga6599722014-06-04 08:45:25 +0000720static int i40e_nway_reset(struct net_device *netdev)
721{
722 /* restart autonegotiation */
723 struct i40e_netdev_priv *np = netdev_priv(netdev);
724 struct i40e_pf *pf = np->vsi->back;
725 struct i40e_hw *hw = &pf->hw;
726 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
727 i40e_status ret = 0;
728
729 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
730 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400731 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
732 i40e_stat_str(hw, ret),
733 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000734 return -EIO;
735 }
736
737 return 0;
738}
739
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000740/**
741 * i40e_get_pauseparam - Get Flow Control status
742 * Return tx/rx-pause status
743 **/
744static void i40e_get_pauseparam(struct net_device *netdev,
745 struct ethtool_pauseparam *pause)
746{
747 struct i40e_netdev_priv *np = netdev_priv(netdev);
748 struct i40e_pf *pf = np->vsi->back;
749 struct i40e_hw *hw = &pf->hw;
750 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000751 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000752
753 pause->autoneg =
754 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
755 AUTONEG_ENABLE : AUTONEG_DISABLE);
756
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000757 /* PFC enabled so report LFC as off */
758 if (dcbx_cfg->pfc.pfcenable) {
759 pause->rx_pause = 0;
760 pause->tx_pause = 0;
761 return;
762 }
763
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000764 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000765 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000766 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000767 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000768 } else if (hw->fc.current_mode == I40E_FC_FULL) {
769 pause->rx_pause = 1;
770 pause->tx_pause = 1;
771 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000772}
773
Catherine Sullivan2becc352014-06-04 08:45:27 +0000774/**
775 * i40e_set_pauseparam - Set Flow Control parameter
776 * @netdev: network interface device structure
777 * @pause: return tx/rx flow control status
778 **/
779static int i40e_set_pauseparam(struct net_device *netdev,
780 struct ethtool_pauseparam *pause)
781{
782 struct i40e_netdev_priv *np = netdev_priv(netdev);
783 struct i40e_pf *pf = np->vsi->back;
784 struct i40e_vsi *vsi = np->vsi;
785 struct i40e_hw *hw = &pf->hw;
786 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000787 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000788 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
789 i40e_status status;
790 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000791 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000792
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000793 /* Changing the port's flow control is not supported if this isn't the
794 * port's controlling PF
795 */
796 if (hw->partition_id != 1) {
797 i40e_partition_setting_complaint(pf);
798 return -EOPNOTSUPP;
799 }
800
Catherine Sullivan2becc352014-06-04 08:45:27 +0000801 if (vsi != pf->vsi[pf->lan_vsi])
802 return -EOPNOTSUPP;
803
804 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
805 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
806 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
807 return -EOPNOTSUPP;
808 }
809
810 /* If we have link and don't have autoneg */
811 if (!test_bit(__I40E_DOWN, &pf->state) &&
812 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
813 /* Send message that it might not necessarily work*/
814 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
815 }
816
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000817 if (dcbx_cfg->pfc.pfcenable) {
818 netdev_info(netdev,
819 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000820 return -EOPNOTSUPP;
821 }
822
823 if (pause->rx_pause && pause->tx_pause)
824 hw->fc.requested_mode = I40E_FC_FULL;
825 else if (pause->rx_pause && !pause->tx_pause)
826 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
827 else if (!pause->rx_pause && pause->tx_pause)
828 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
829 else if (!pause->rx_pause && !pause->tx_pause)
830 hw->fc.requested_mode = I40E_FC_NONE;
831 else
832 return -EINVAL;
833
Catherine Sullivan94128512014-07-12 07:28:16 +0000834 /* Tell the OS link is going down, the link will go back up when fw
835 * says it is ready asynchronously
836 */
837 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
838 netif_carrier_off(netdev);
839 netif_tx_stop_all_queues(netdev);
840
Catherine Sullivan2becc352014-06-04 08:45:27 +0000841 /* Set the fc mode and only restart an if link is up*/
842 status = i40e_set_fc(hw, &aq_failures, link_up);
843
844 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400845 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
846 i40e_stat_str(hw, status),
847 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000848 err = -EAGAIN;
849 }
850 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400851 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
852 i40e_stat_str(hw, status),
853 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000854 err = -EAGAIN;
855 }
856 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400857 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
858 i40e_stat_str(hw, status),
859 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000860 err = -EAGAIN;
861 }
862
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000863 if (!test_bit(__I40E_DOWN, &pf->state)) {
864 /* Give it a little more time to try to come back */
865 msleep(75);
866 if (!test_bit(__I40E_DOWN, &pf->state))
867 return i40e_nway_reset(netdev);
868 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000869
870 return err;
871}
872
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000873static u32 i40e_get_msglevel(struct net_device *netdev)
874{
875 struct i40e_netdev_priv *np = netdev_priv(netdev);
876 struct i40e_pf *pf = np->vsi->back;
877
878 return pf->msg_enable;
879}
880
881static void i40e_set_msglevel(struct net_device *netdev, u32 data)
882{
883 struct i40e_netdev_priv *np = netdev_priv(netdev);
884 struct i40e_pf *pf = np->vsi->back;
885
886 if (I40E_DEBUG_USER & data)
887 pf->hw.debug_mask = data;
888 pf->msg_enable = data;
889}
890
891static int i40e_get_regs_len(struct net_device *netdev)
892{
893 int reg_count = 0;
894 int i;
895
896 for (i = 0; i40e_reg_list[i].offset != 0; i++)
897 reg_count += i40e_reg_list[i].elements;
898
899 return reg_count * sizeof(u32);
900}
901
902static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
903 void *p)
904{
905 struct i40e_netdev_priv *np = netdev_priv(netdev);
906 struct i40e_pf *pf = np->vsi->back;
907 struct i40e_hw *hw = &pf->hw;
908 u32 *reg_buf = p;
909 int i, j, ri;
910 u32 reg;
911
912 /* Tell ethtool which driver-version-specific regs output we have.
913 *
914 * At some point, if we have ethtool doing special formatting of
915 * this data, it will rely on this version number to know how to
916 * interpret things. Hence, this needs to be updated if/when the
917 * diags register table is changed.
918 */
919 regs->version = 1;
920
921 /* loop through the diags reg table for what to print */
922 ri = 0;
923 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
924 for (j = 0; j < i40e_reg_list[i].elements; j++) {
925 reg = i40e_reg_list[i].offset
926 + (j * i40e_reg_list[i].stride);
927 reg_buf[ri++] = rd32(hw, reg);
928 }
929 }
930
931}
932
933static int i40e_get_eeprom(struct net_device *netdev,
934 struct ethtool_eeprom *eeprom, u8 *bytes)
935{
936 struct i40e_netdev_priv *np = netdev_priv(netdev);
937 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000938 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000939 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000940 u8 *eeprom_buff;
941 u16 i, sectors;
942 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000943 u32 magic;
944
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000945#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000946 if (eeprom->len == 0)
947 return -EINVAL;
948
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000949 /* check for NVMUpdate access method */
950 magic = hw->vendor_id | (hw->device_id << 16);
951 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000952 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000953 int errno;
954
955 /* make sure it is the right magic for NVMUpdate */
956 if ((eeprom->magic >> 16) != hw->device_id)
957 return -EINVAL;
958
Shannon Nelsonc150a502014-11-13 08:23:13 +0000959 cmd = (struct i40e_nvm_access *)eeprom;
960 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000961 if (ret_val &&
962 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
963 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000964 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000965 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
966 ret_val, hw->aq.asq_last_status, errno,
967 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
968 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000969
970 return errno;
971 }
972
973 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000974 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
975
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000976 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000977 if (!eeprom_buff)
978 return -ENOMEM;
979
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000980 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
981 if (ret_val) {
982 dev_info(&pf->pdev->dev,
983 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
984 ret_val, hw->aq.asq_last_status);
985 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000986 }
987
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000988 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
989 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
990 len = I40E_NVM_SECTOR_SIZE;
991 last = false;
992 for (i = 0; i < sectors; i++) {
993 if (i == (sectors - 1)) {
994 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
995 last = true;
996 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000997 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
998 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000999 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001000 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001001 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001002 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001003 "read NVM failed, invalid offset 0x%x\n",
1004 offset);
1005 break;
1006 } else if (ret_val &&
1007 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1008 dev_info(&pf->pdev->dev,
1009 "read NVM failed, access, offset 0x%x\n",
1010 offset);
1011 break;
1012 } else if (ret_val) {
1013 dev_info(&pf->pdev->dev,
1014 "read NVM failed offset %d err=%d status=0x%x\n",
1015 offset, ret_val, hw->aq.asq_last_status);
1016 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001017 }
1018 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001019
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001020 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001021 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001022free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001024 return ret_val;
1025}
1026
1027static int i40e_get_eeprom_len(struct net_device *netdev)
1028{
1029 struct i40e_netdev_priv *np = netdev_priv(netdev);
1030 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001031 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001032
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001033 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1034 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1035 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1036 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001037 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001038 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001039}
1040
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001041static int i40e_set_eeprom(struct net_device *netdev,
1042 struct ethtool_eeprom *eeprom, u8 *bytes)
1043{
1044 struct i40e_netdev_priv *np = netdev_priv(netdev);
1045 struct i40e_hw *hw = &np->vsi->back->hw;
1046 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001047 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001048 int ret_val = 0;
1049 int errno;
1050 u32 magic;
1051
1052 /* normal ethtool set_eeprom is not supported */
1053 magic = hw->vendor_id | (hw->device_id << 16);
1054 if (eeprom->magic == magic)
1055 return -EOPNOTSUPP;
1056
1057 /* check for NVMUpdate access method */
1058 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1059 return -EINVAL;
1060
1061 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1062 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1063 return -EBUSY;
1064
Shannon Nelsonc150a502014-11-13 08:23:13 +00001065 cmd = (struct i40e_nvm_access *)eeprom;
1066 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001067 if (ret_val &&
1068 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1069 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1070 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001071 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001072 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1073 ret_val, hw->aq.asq_last_status, errno,
1074 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1075 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001076
1077 return errno;
1078}
1079
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001080static void i40e_get_drvinfo(struct net_device *netdev,
1081 struct ethtool_drvinfo *drvinfo)
1082{
1083 struct i40e_netdev_priv *np = netdev_priv(netdev);
1084 struct i40e_vsi *vsi = np->vsi;
1085 struct i40e_pf *pf = vsi->back;
1086
1087 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1088 strlcpy(drvinfo->version, i40e_driver_version_str,
1089 sizeof(drvinfo->version));
1090 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1091 sizeof(drvinfo->fw_version));
1092 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1093 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001094 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001095}
1096
1097static void i40e_get_ringparam(struct net_device *netdev,
1098 struct ethtool_ringparam *ring)
1099{
1100 struct i40e_netdev_priv *np = netdev_priv(netdev);
1101 struct i40e_pf *pf = np->vsi->back;
1102 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1103
1104 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1105 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1106 ring->rx_mini_max_pending = 0;
1107 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001108 ring->rx_pending = vsi->rx_rings[0]->count;
1109 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001110 ring->rx_mini_pending = 0;
1111 ring->rx_jumbo_pending = 0;
1112}
1113
1114static int i40e_set_ringparam(struct net_device *netdev,
1115 struct ethtool_ringparam *ring)
1116{
1117 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1118 struct i40e_netdev_priv *np = netdev_priv(netdev);
1119 struct i40e_vsi *vsi = np->vsi;
1120 struct i40e_pf *pf = vsi->back;
1121 u32 new_rx_count, new_tx_count;
1122 int i, err = 0;
1123
1124 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1125 return -EINVAL;
1126
Shannon Nelson1fa18372013-11-20 10:03:08 +00001127 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1128 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1129 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1130 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1131 netdev_info(netdev,
1132 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1133 ring->tx_pending, ring->rx_pending,
1134 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1135 return -EINVAL;
1136 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001137
Shannon Nelson1fa18372013-11-20 10:03:08 +00001138 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1139 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001140
1141 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001142 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1143 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001144 return 0;
1145
1146 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1147 usleep_range(1000, 2000);
1148
1149 if (!netif_running(vsi->netdev)) {
1150 /* simple case - set for the next time the netdev is started */
1151 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001152 vsi->tx_rings[i]->count = new_tx_count;
1153 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001154 }
1155 goto done;
1156 }
1157
1158 /* We can't just free everything and then setup again,
1159 * because the ISRs in MSI-X mode get passed pointers
1160 * to the Tx and Rx ring structs.
1161 */
1162
1163 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001164 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001165 netdev_info(netdev,
1166 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001167 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001168 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1169 sizeof(struct i40e_ring), GFP_KERNEL);
1170 if (!tx_rings) {
1171 err = -ENOMEM;
1172 goto done;
1173 }
1174
1175 for (i = 0; i < vsi->num_queue_pairs; i++) {
1176 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001177 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001178 tx_rings[i].count = new_tx_count;
1179 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1180 if (err) {
1181 while (i) {
1182 i--;
1183 i40e_free_tx_resources(&tx_rings[i]);
1184 }
1185 kfree(tx_rings);
1186 tx_rings = NULL;
1187
1188 goto done;
1189 }
1190 }
1191 }
1192
1193 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001194 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001195 netdev_info(netdev,
1196 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001197 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001198 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1199 sizeof(struct i40e_ring), GFP_KERNEL);
1200 if (!rx_rings) {
1201 err = -ENOMEM;
1202 goto free_tx;
1203 }
1204
1205 for (i = 0; i < vsi->num_queue_pairs; i++) {
1206 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001207 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001208 rx_rings[i].count = new_rx_count;
1209 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1210 if (err) {
1211 while (i) {
1212 i--;
1213 i40e_free_rx_resources(&rx_rings[i]);
1214 }
1215 kfree(rx_rings);
1216 rx_rings = NULL;
1217
1218 goto free_tx;
1219 }
1220 }
1221 }
1222
1223 /* Bring interface down, copy in the new ring info,
1224 * then restore the interface
1225 */
1226 i40e_down(vsi);
1227
1228 if (tx_rings) {
1229 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001230 i40e_free_tx_resources(vsi->tx_rings[i]);
1231 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 }
1233 kfree(tx_rings);
1234 tx_rings = NULL;
1235 }
1236
1237 if (rx_rings) {
1238 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001239 i40e_free_rx_resources(vsi->rx_rings[i]);
1240 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001241 }
1242 kfree(rx_rings);
1243 rx_rings = NULL;
1244 }
1245
1246 i40e_up(vsi);
1247
1248free_tx:
1249 /* error cleanup if the Rx allocations failed after getting Tx */
1250 if (tx_rings) {
1251 for (i = 0; i < vsi->num_queue_pairs; i++)
1252 i40e_free_tx_resources(&tx_rings[i]);
1253 kfree(tx_rings);
1254 tx_rings = NULL;
1255 }
1256
1257done:
1258 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1259
1260 return err;
1261}
1262
1263static int i40e_get_sset_count(struct net_device *netdev, int sset)
1264{
1265 struct i40e_netdev_priv *np = netdev_priv(netdev);
1266 struct i40e_vsi *vsi = np->vsi;
1267 struct i40e_pf *pf = vsi->back;
1268
1269 switch (sset) {
1270 case ETH_SS_TEST:
1271 return I40E_TEST_LEN;
1272 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001273 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001274 int len = I40E_PF_STATS_LEN(netdev);
1275
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001276 if ((pf->lan_veb != I40E_NO_VEB) &&
1277 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001278 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001279 return len;
1280 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001281 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001282 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001283 case ETH_SS_PRIV_FLAGS:
1284 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001285 default:
1286 return -EOPNOTSUPP;
1287 }
1288}
1289
1290static void i40e_get_ethtool_stats(struct net_device *netdev,
1291 struct ethtool_stats *stats, u64 *data)
1292{
1293 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001294 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001295 struct i40e_vsi *vsi = np->vsi;
1296 struct i40e_pf *pf = vsi->back;
1297 int i = 0;
1298 char *p;
1299 int j;
1300 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001301 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001302
1303 i40e_update_stats(vsi);
1304
1305 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1306 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1307 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1308 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1309 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001310 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1311 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1312 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1313 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1314 }
Vasu Dev38e00432014-08-01 13:27:03 -07001315#ifdef I40E_FCOE
1316 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1317 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1318 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1319 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1320 }
1321#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001322 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001323 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001324 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001325
1326 if (!tx_ring)
1327 continue;
1328
1329 /* process Tx ring statistics */
1330 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001331 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001332 data[i] = tx_ring->stats.packets;
1333 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001334 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001335 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001336
1337 /* Rx ring is the 2nd half of the queue pair */
1338 rx_ring = &tx_ring[1];
1339 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001340 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001341 data[i] = rx_ring->stats.packets;
1342 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001343 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001344 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001345 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001346 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001347 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001348 return;
1349
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001350 if ((pf->lan_veb != I40E_NO_VEB) &&
1351 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001352 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1353 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1354 p = (char *)veb;
1355 p += i40e_gstrings_veb_stats[j].stat_offset;
1356 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1357 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001358 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001359 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001360 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1361 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1362 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1363 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1364 }
1365 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1366 data[i++] = pf->stats.priority_xon_tx[j];
1367 data[i++] = pf->stats.priority_xoff_tx[j];
1368 }
1369 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1370 data[i++] = pf->stats.priority_xon_rx[j];
1371 data[i++] = pf->stats.priority_xoff_rx[j];
1372 }
1373 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1374 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001375}
1376
1377static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1378 u8 *data)
1379{
1380 struct i40e_netdev_priv *np = netdev_priv(netdev);
1381 struct i40e_vsi *vsi = np->vsi;
1382 struct i40e_pf *pf = vsi->back;
1383 char *p = (char *)data;
1384 int i;
1385
1386 switch (stringset) {
1387 case ETH_SS_TEST:
1388 for (i = 0; i < I40E_TEST_LEN; i++) {
1389 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1390 data += ETH_GSTRING_LEN;
1391 }
1392 break;
1393 case ETH_SS_STATS:
1394 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1395 snprintf(p, ETH_GSTRING_LEN, "%s",
1396 i40e_gstrings_net_stats[i].stat_string);
1397 p += ETH_GSTRING_LEN;
1398 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001399 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1400 snprintf(p, ETH_GSTRING_LEN, "%s",
1401 i40e_gstrings_misc_stats[i].stat_string);
1402 p += ETH_GSTRING_LEN;
1403 }
Vasu Dev38e00432014-08-01 13:27:03 -07001404#ifdef I40E_FCOE
1405 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1406 snprintf(p, ETH_GSTRING_LEN, "%s",
1407 i40e_gstrings_fcoe_stats[i].stat_string);
1408 p += ETH_GSTRING_LEN;
1409 }
1410#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001411 for (i = 0; i < vsi->num_queue_pairs; i++) {
1412 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1413 p += ETH_GSTRING_LEN;
1414 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1415 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001416 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1417 p += ETH_GSTRING_LEN;
1418 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1419 p += ETH_GSTRING_LEN;
1420 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001421 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001422 return;
1423
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001424 if ((pf->lan_veb != I40E_NO_VEB) &&
1425 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001426 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1427 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1428 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 p += ETH_GSTRING_LEN;
1430 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001431 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1432 snprintf(p, ETH_GSTRING_LEN,
1433 "veb.tc_%u_tx_packets", i);
1434 p += ETH_GSTRING_LEN;
1435 snprintf(p, ETH_GSTRING_LEN,
1436 "veb.tc_%u_tx_bytes", i);
1437 p += ETH_GSTRING_LEN;
1438 snprintf(p, ETH_GSTRING_LEN,
1439 "veb.tc_%u_rx_packets", i);
1440 p += ETH_GSTRING_LEN;
1441 snprintf(p, ETH_GSTRING_LEN,
1442 "veb.tc_%u_rx_bytes", i);
1443 p += ETH_GSTRING_LEN;
1444 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001445 }
1446 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1447 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1448 i40e_gstrings_stats[i].stat_string);
1449 p += ETH_GSTRING_LEN;
1450 }
1451 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1452 snprintf(p, ETH_GSTRING_LEN,
1453 "port.tx_priority_%u_xon", i);
1454 p += ETH_GSTRING_LEN;
1455 snprintf(p, ETH_GSTRING_LEN,
1456 "port.tx_priority_%u_xoff", i);
1457 p += ETH_GSTRING_LEN;
1458 }
1459 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1460 snprintf(p, ETH_GSTRING_LEN,
1461 "port.rx_priority_%u_xon", i);
1462 p += ETH_GSTRING_LEN;
1463 snprintf(p, ETH_GSTRING_LEN,
1464 "port.rx_priority_%u_xoff", i);
1465 p += ETH_GSTRING_LEN;
1466 }
1467 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1468 snprintf(p, ETH_GSTRING_LEN,
1469 "port.rx_priority_%u_xon_2_xoff", i);
1470 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001471 }
1472 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1473 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001474 case ETH_SS_PRIV_FLAGS:
1475 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1476 memcpy(data, i40e_priv_flags_strings[i],
1477 ETH_GSTRING_LEN);
1478 data += ETH_GSTRING_LEN;
1479 }
1480 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001481 default:
1482 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483 }
1484}
1485
1486static int i40e_get_ts_info(struct net_device *dev,
1487 struct ethtool_ts_info *info)
1488{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001489 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1490
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001491 /* only report HW timestamping if PTP is enabled */
1492 if (!(pf->flags & I40E_FLAG_PTP))
1493 return ethtool_op_get_ts_info(dev, info);
1494
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001495 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1496 SOF_TIMESTAMPING_RX_SOFTWARE |
1497 SOF_TIMESTAMPING_SOFTWARE |
1498 SOF_TIMESTAMPING_TX_HARDWARE |
1499 SOF_TIMESTAMPING_RX_HARDWARE |
1500 SOF_TIMESTAMPING_RAW_HARDWARE;
1501
1502 if (pf->ptp_clock)
1503 info->phc_index = ptp_clock_index(pf->ptp_clock);
1504 else
1505 info->phc_index = -1;
1506
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001507 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001508
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001509 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1510 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1511 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001512
1513 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514}
1515
Shannon Nelson7b086392013-11-20 10:02:59 +00001516static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001517{
Shannon Nelson7b086392013-11-20 10:02:59 +00001518 struct i40e_netdev_priv *np = netdev_priv(netdev);
1519 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001520 i40e_status status;
1521 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001522
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001523 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001524 status = i40e_get_link_status(&pf->hw, &link_up);
1525 if (status) {
1526 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1527 *data = 1;
1528 return *data;
1529 }
1530
1531 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001532 *data = 0;
1533 else
1534 *data = 1;
1535
1536 return *data;
1537}
1538
Shannon Nelson7b086392013-11-20 10:02:59 +00001539static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001540{
Shannon Nelson7b086392013-11-20 10:02:59 +00001541 struct i40e_netdev_priv *np = netdev_priv(netdev);
1542 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001544 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001545 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001546
Shannon Nelson7b086392013-11-20 10:02:59 +00001547 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548}
1549
Shannon Nelson7b086392013-11-20 10:02:59 +00001550static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001551{
Shannon Nelson7b086392013-11-20 10:02:59 +00001552 struct i40e_netdev_priv *np = netdev_priv(netdev);
1553 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001555 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001556 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557
Shannon Nelson4443ec92014-11-13 08:23:12 +00001558 /* forcebly clear the NVM Update state machine */
1559 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1560
Shannon Nelson7b086392013-11-20 10:02:59 +00001561 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562}
1563
Shannon Nelson7b086392013-11-20 10:02:59 +00001564static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001565{
Shannon Nelson7b086392013-11-20 10:02:59 +00001566 struct i40e_netdev_priv *np = netdev_priv(netdev);
1567 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001568 u16 swc_old = pf->sw_int_count;
1569
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001570 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001571 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1572 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001573 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1574 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1575 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1576 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001577 usleep_range(1000, 2000);
1578 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001579
1580 return *data;
1581}
1582
Shannon Nelson7b086392013-11-20 10:02:59 +00001583static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001585 struct i40e_netdev_priv *np = netdev_priv(netdev);
1586 struct i40e_pf *pf = np->vsi->back;
1587
1588 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001589 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001590
1591 return *data;
1592}
1593
Greg Rosee17bc412015-04-16 20:05:59 -04001594static inline bool i40e_active_vfs(struct i40e_pf *pf)
1595{
1596 struct i40e_vf *vfs = pf->vf;
1597 int i;
1598
1599 for (i = 0; i < pf->num_alloc_vfs; i++)
1600 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1601 return true;
1602 return false;
1603}
1604
Greg Rose510efb22015-07-10 19:36:01 -04001605static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1606{
1607 struct i40e_vsi **vsi = pf->vsi;
1608 int i;
1609
1610 for (i = 0; i < pf->num_alloc_vsi; i++) {
1611 if (!vsi[i])
1612 continue;
1613 if (vsi[i]->type == I40E_VSI_VMDQ2)
1614 return true;
1615 }
1616
1617 return false;
1618}
1619
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001620static void i40e_diag_test(struct net_device *netdev,
1621 struct ethtool_test *eth_test, u64 *data)
1622{
1623 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001624 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001625 struct i40e_pf *pf = np->vsi->back;
1626
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1628 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001629 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001630
Shannon Nelsonf551b432013-11-26 10:49:12 +00001631 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001632
Greg Rose510efb22015-07-10 19:36:01 -04001633 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001634 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001635 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001636 data[I40E_ETH_TEST_REG] = 1;
1637 data[I40E_ETH_TEST_EEPROM] = 1;
1638 data[I40E_ETH_TEST_INTR] = 1;
1639 data[I40E_ETH_TEST_LOOPBACK] = 1;
1640 data[I40E_ETH_TEST_LINK] = 1;
1641 eth_test->flags |= ETH_TEST_FL_FAILED;
1642 clear_bit(__I40E_TESTING, &pf->state);
1643 goto skip_ol_tests;
1644 }
1645
Greg Rose5b86c5c2015-02-26 16:14:35 +00001646 /* If the device is online then take it offline */
1647 if (if_running)
1648 /* indicate we're in test mode */
1649 dev_close(netdev);
1650 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001651 /* This reset does not affect link - if it is
1652 * changed to a type of reset that does affect
1653 * link then the following link test would have
1654 * to be moved to before the reset
1655 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001656 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001657
Shannon Nelson7b086392013-11-20 10:02:59 +00001658 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001659 eth_test->flags |= ETH_TEST_FL_FAILED;
1660
Shannon Nelson7b086392013-11-20 10:02:59 +00001661 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 eth_test->flags |= ETH_TEST_FL_FAILED;
1663
Shannon Nelson7b086392013-11-20 10:02:59 +00001664 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001665 eth_test->flags |= ETH_TEST_FL_FAILED;
1666
Shannon Nelson7b086392013-11-20 10:02:59 +00001667 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668 eth_test->flags |= ETH_TEST_FL_FAILED;
1669
Shannon Nelsonf551b432013-11-26 10:49:12 +00001670 /* run reg test last, a reset is required after it */
1671 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1672 eth_test->flags |= ETH_TEST_FL_FAILED;
1673
1674 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001675 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001676
1677 if (if_running)
1678 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001679 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001680 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001681 netif_info(pf, drv, netdev, "online testing starting\n");
1682
Shannon Nelson7b086392013-11-20 10:02:59 +00001683 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001684 eth_test->flags |= ETH_TEST_FL_FAILED;
1685
1686 /* Offline only tests, not run in online; pass by default */
1687 data[I40E_ETH_TEST_REG] = 0;
1688 data[I40E_ETH_TEST_EEPROM] = 0;
1689 data[I40E_ETH_TEST_INTR] = 0;
1690 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001691 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001692
Greg Rosee17bc412015-04-16 20:05:59 -04001693skip_ol_tests:
1694
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001695 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001696}
1697
1698static void i40e_get_wol(struct net_device *netdev,
1699 struct ethtool_wolinfo *wol)
1700{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001701 struct i40e_netdev_priv *np = netdev_priv(netdev);
1702 struct i40e_pf *pf = np->vsi->back;
1703 struct i40e_hw *hw = &pf->hw;
1704 u16 wol_nvm_bits;
1705
1706 /* NVM bit on means WoL disabled for the port */
1707 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001708 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001709 wol->supported = 0;
1710 wol->wolopts = 0;
1711 } else {
1712 wol->supported = WAKE_MAGIC;
1713 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1714 }
1715}
1716
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001717/**
1718 * i40e_set_wol - set the WakeOnLAN configuration
1719 * @netdev: the netdev in question
1720 * @wol: the ethtool WoL setting data
1721 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001722static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1723{
1724 struct i40e_netdev_priv *np = netdev_priv(netdev);
1725 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001726 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001727 struct i40e_hw *hw = &pf->hw;
1728 u16 wol_nvm_bits;
1729
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001730 /* WoL not supported if this isn't the controlling PF on the port */
1731 if (hw->partition_id != 1) {
1732 i40e_partition_setting_complaint(pf);
1733 return -EOPNOTSUPP;
1734 }
1735
1736 if (vsi != pf->vsi[pf->lan_vsi])
1737 return -EOPNOTSUPP;
1738
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001739 /* NVM bit on means WoL disabled for the port */
1740 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001741 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001742 return -EOPNOTSUPP;
1743
1744 /* only magic packet is supported */
1745 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1746 return -EOPNOTSUPP;
1747
1748 /* is this a new value? */
1749 if (pf->wol_en != !!wol->wolopts) {
1750 pf->wol_en = !!wol->wolopts;
1751 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1752 }
1753
1754 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001755}
1756
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001757static int i40e_set_phys_id(struct net_device *netdev,
1758 enum ethtool_phys_id_state state)
1759{
1760 struct i40e_netdev_priv *np = netdev_priv(netdev);
1761 struct i40e_pf *pf = np->vsi->back;
1762 struct i40e_hw *hw = &pf->hw;
1763 int blink_freq = 2;
1764
1765 switch (state) {
1766 case ETHTOOL_ID_ACTIVE:
1767 pf->led_status = i40e_led_get(hw);
1768 return blink_freq;
1769 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001770 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001771 break;
1772 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001773 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774 break;
1775 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001776 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001777 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001778 default:
1779 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001780 }
1781
1782 return 0;
1783}
1784
1785/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1786 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1787 * 125us (8000 interrupts per second) == ITR(62)
1788 */
1789
1790static int i40e_get_coalesce(struct net_device *netdev,
1791 struct ethtool_coalesce *ec)
1792{
1793 struct i40e_netdev_priv *np = netdev_priv(netdev);
1794 struct i40e_vsi *vsi = np->vsi;
1795
1796 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1797 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1798
1799 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001800 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001801
1802 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001803 ec->use_adaptive_tx_coalesce = 1;
1804
1805 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1806 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807
1808 return 0;
1809}
1810
1811static int i40e_set_coalesce(struct net_device *netdev,
1812 struct ethtool_coalesce *ec)
1813{
1814 struct i40e_netdev_priv *np = netdev_priv(netdev);
1815 struct i40e_q_vector *q_vector;
1816 struct i40e_vsi *vsi = np->vsi;
1817 struct i40e_pf *pf = vsi->back;
1818 struct i40e_hw *hw = &pf->hw;
1819 u16 vector;
1820 int i;
1821
1822 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1823 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1824
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001825 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001826 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001827 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001828 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001829 } else if (ec->rx_coalesce_usecs == 0) {
1830 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001831 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001832 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 +00001833 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001834 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001835 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001836 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001837
Mitch Williams32f5f542014-04-04 04:43:10 +00001838 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001839 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001840 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001841 } else if (ec->tx_coalesce_usecs == 0) {
1842 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001843 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001844 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 +00001845 } else {
1846 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001847 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001848 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001849 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001850
1851 if (ec->use_adaptive_rx_coalesce)
1852 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1853 else
1854 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1855
1856 if (ec->use_adaptive_tx_coalesce)
1857 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1858 else
1859 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001860
Alexander Duyck493fb302013-09-28 07:01:44 +00001861 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1862 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001863 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1864 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1865 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1866 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1867 i40e_flush(hw);
1868 }
1869
1870 return 0;
1871}
1872
1873/**
1874 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1875 * @pf: pointer to the physical function struct
1876 * @cmd: ethtool rxnfc command
1877 *
1878 * Returns Success if the flow is supported, else Invalid Input.
1879 **/
1880static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1881{
1882 cmd->data = 0;
1883
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001884 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1885 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1886 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1887 return 0;
1888 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001889 /* Report default options for RSS on i40e */
1890 switch (cmd->flow_type) {
1891 case TCP_V4_FLOW:
1892 case UDP_V4_FLOW:
1893 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1894 /* fall through to add IP fields */
1895 case SCTP_V4_FLOW:
1896 case AH_ESP_V4_FLOW:
1897 case AH_V4_FLOW:
1898 case ESP_V4_FLOW:
1899 case IPV4_FLOW:
1900 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1901 break;
1902 case TCP_V6_FLOW:
1903 case UDP_V6_FLOW:
1904 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1905 /* fall through to add IP fields */
1906 case SCTP_V6_FLOW:
1907 case AH_ESP_V6_FLOW:
1908 case AH_V6_FLOW:
1909 case ESP_V6_FLOW:
1910 case IPV6_FLOW:
1911 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1912 break;
1913 default:
1914 return -EINVAL;
1915 }
1916
1917 return 0;
1918}
1919
1920/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001921 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1922 * @pf: Pointer to the physical function struct
1923 * @cmd: The command to get or set Rx flow classification rules
1924 * @rule_locs: Array of used rule locations
1925 *
1926 * This function populates both the total and actual rule count of
1927 * the ethtool flow classification command
1928 *
1929 * Returns 0 on success or -EMSGSIZE if entry not found
1930 **/
1931static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1932 struct ethtool_rxnfc *cmd,
1933 u32 *rule_locs)
1934{
1935 struct i40e_fdir_filter *rule;
1936 struct hlist_node *node2;
1937 int cnt = 0;
1938
1939 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001940 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001941
1942 hlist_for_each_entry_safe(rule, node2,
1943 &pf->fdir_filter_list, fdir_node) {
1944 if (cnt == cmd->rule_cnt)
1945 return -EMSGSIZE;
1946
1947 rule_locs[cnt] = rule->fd_id;
1948 cnt++;
1949 }
1950
1951 cmd->rule_cnt = cnt;
1952
1953 return 0;
1954}
1955
1956/**
1957 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1958 * @pf: Pointer to the physical function struct
1959 * @cmd: The command to get or set Rx flow classification rules
1960 *
1961 * This function looks up a filter based on the Rx flow classification
1962 * command and fills the flow spec info for it if found
1963 *
1964 * Returns 0 on success or -EINVAL if filter not found
1965 **/
1966static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1967 struct ethtool_rxnfc *cmd)
1968{
1969 struct ethtool_rx_flow_spec *fsp =
1970 (struct ethtool_rx_flow_spec *)&cmd->fs;
1971 struct i40e_fdir_filter *rule = NULL;
1972 struct hlist_node *node2;
1973
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001974 hlist_for_each_entry_safe(rule, node2,
1975 &pf->fdir_filter_list, fdir_node) {
1976 if (fsp->location <= rule->fd_id)
1977 break;
1978 }
1979
1980 if (!rule || fsp->location != rule->fd_id)
1981 return -EINVAL;
1982
1983 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001984 if (fsp->flow_type == IP_USER_FLOW) {
1985 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1986 fsp->h_u.usr_ip4_spec.proto = 0;
1987 fsp->m_u.usr_ip4_spec.proto = 0;
1988 }
1989
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001990 /* Reverse the src and dest notion, since the HW views them from
1991 * Tx perspective where as the user expects it from Rx filter view.
1992 */
1993 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1994 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1995 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1996 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001997
1998 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1999 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2000 else
2001 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002002
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002003 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2004 struct i40e_vsi *vsi;
2005
2006 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2007 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2008 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2009 fsp->m_ext.data[1] = htonl(0x1);
2010 }
2011 }
2012
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002013 return 0;
2014}
2015
2016/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002017 * i40e_get_rxnfc - command to get RX flow classification rules
2018 * @netdev: network interface device structure
2019 * @cmd: ethtool rxnfc command
2020 *
2021 * Returns Success if the command is supported.
2022 **/
2023static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2024 u32 *rule_locs)
2025{
2026 struct i40e_netdev_priv *np = netdev_priv(netdev);
2027 struct i40e_vsi *vsi = np->vsi;
2028 struct i40e_pf *pf = vsi->back;
2029 int ret = -EOPNOTSUPP;
2030
2031 switch (cmd->cmd) {
2032 case ETHTOOL_GRXRINGS:
2033 cmd->data = vsi->alloc_queue_pairs;
2034 ret = 0;
2035 break;
2036 case ETHTOOL_GRXFH:
2037 ret = i40e_get_rss_hash_opts(pf, cmd);
2038 break;
2039 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002040 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002041 /* report total rule count */
2042 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002043 ret = 0;
2044 break;
2045 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002046 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002047 break;
2048 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002049 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2050 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002051 default:
2052 break;
2053 }
2054
2055 return ret;
2056}
2057
2058/**
2059 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2060 * @pf: pointer to the physical function struct
2061 * @cmd: ethtool rxnfc command
2062 *
2063 * Returns Success if the flow input set is supported.
2064 **/
2065static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2066{
2067 struct i40e_hw *hw = &pf->hw;
2068 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2069 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2070
2071 /* RSS does not support anything other than hashing
2072 * to queues on src and dst IPs and ports
2073 */
2074 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2075 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2076 return -EINVAL;
2077
2078 /* We need at least the IP SRC and DEST fields for hashing */
2079 if (!(nfc->data & RXH_IP_SRC) ||
2080 !(nfc->data & RXH_IP_DST))
2081 return -EINVAL;
2082
2083 switch (nfc->flow_type) {
2084 case TCP_V4_FLOW:
2085 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2086 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002087 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002088 break;
2089 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002090 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002091 break;
2092 default:
2093 return -EINVAL;
2094 }
2095 break;
2096 case TCP_V6_FLOW:
2097 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2098 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002099 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002100 break;
2101 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002102 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002103 break;
2104 default:
2105 return -EINVAL;
2106 }
2107 break;
2108 case UDP_V4_FLOW:
2109 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2110 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002111 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2112 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002113 break;
2114 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002115 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2116 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002117 break;
2118 default:
2119 return -EINVAL;
2120 }
2121 break;
2122 case UDP_V6_FLOW:
2123 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2124 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002125 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2126 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002127 break;
2128 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002129 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2130 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002131 break;
2132 default:
2133 return -EINVAL;
2134 }
2135 break;
2136 case AH_ESP_V4_FLOW:
2137 case AH_V4_FLOW:
2138 case ESP_V4_FLOW:
2139 case SCTP_V4_FLOW:
2140 if ((nfc->data & RXH_L4_B_0_1) ||
2141 (nfc->data & RXH_L4_B_2_3))
2142 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002143 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144 break;
2145 case AH_ESP_V6_FLOW:
2146 case AH_V6_FLOW:
2147 case ESP_V6_FLOW:
2148 case SCTP_V6_FLOW:
2149 if ((nfc->data & RXH_L4_B_0_1) ||
2150 (nfc->data & RXH_L4_B_2_3))
2151 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002152 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002153 break;
2154 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002155 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2156 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002157 break;
2158 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002159 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2160 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002161 break;
2162 default:
2163 return -EINVAL;
2164 }
2165
2166 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2167 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2168 i40e_flush(hw);
2169
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002170 /* Save setting for future output/update */
2171 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2172
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002173 return 0;
2174}
2175
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002176/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002177 * i40e_match_fdir_input_set - Match a new filter against an existing one
2178 * @rule: The filter already added
2179 * @input: The new filter to comapre against
2180 *
2181 * Returns true if the two input set match
2182 **/
2183static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2184 struct i40e_fdir_filter *input)
2185{
2186 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2187 (rule->src_ip[0] != input->src_ip[0]) ||
2188 (rule->dst_port != input->dst_port) ||
2189 (rule->src_port != input->src_port))
2190 return false;
2191 return true;
2192}
2193
2194/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002195 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2196 * @vsi: Pointer to the targeted VSI
2197 * @input: The filter to update or NULL to indicate deletion
2198 * @sw_idx: Software index to the filter
2199 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002201 * This function updates (or deletes) a Flow Director entry from
2202 * the hlist of the corresponding PF
2203 *
2204 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002206static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2207 struct i40e_fdir_filter *input,
2208 u16 sw_idx,
2209 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002210{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002211 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002213 struct hlist_node *node2;
2214 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002215
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002216 parent = NULL;
2217 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002218
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002219 hlist_for_each_entry_safe(rule, node2,
2220 &pf->fdir_filter_list, fdir_node) {
2221 /* hash found, or no matching entry */
2222 if (rule->fd_id >= sw_idx)
2223 break;
2224 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225 }
2226
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002227 /* if there is an old rule occupying our place remove it */
2228 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002229 if (input && !i40e_match_fdir_input_set(rule, input))
2230 err = i40e_add_del_fdir(vsi, rule, false);
2231 else if (!input)
2232 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002233 hlist_del(&rule->fdir_node);
2234 kfree(rule);
2235 pf->fdir_pf_active_filters--;
2236 }
2237
2238 /* If no input this was a delete, err should be 0 if a rule was
2239 * successfully found and removed from the list else -EINVAL
2240 */
2241 if (!input)
2242 return err;
2243
2244 /* initialize node and set software index */
2245 INIT_HLIST_NODE(&input->fdir_node);
2246
2247 /* add filter to the list */
2248 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002249 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002250 else
2251 hlist_add_head(&input->fdir_node,
2252 &pf->fdir_filter_list);
2253
2254 /* update counts */
2255 pf->fdir_pf_active_filters++;
2256
2257 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002258}
2259
2260/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002261 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2262 * @vsi: Pointer to the targeted VSI
2263 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002264 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002265 * The function removes a Flow Director filter entry from the
2266 * hlist of the corresponding PF
2267 *
2268 * Returns 0 on success
2269 */
2270static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2271 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002272{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002273 struct ethtool_rx_flow_spec *fsp =
2274 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002276 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002277
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002278 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2279 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2280 return -EBUSY;
2281
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002282 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2283 return -EBUSY;
2284
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002285 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002286
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002287 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002288 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002289}
2290
2291/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002292 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002293 * @vsi: pointer to the targeted VSI
2294 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002295 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002296 * Add Flow Director filters for a specific flow spec based on their
2297 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002298 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002299static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2300 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002301{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002302 struct ethtool_rx_flow_spec *fsp;
2303 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002304 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002305 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002306 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002307
2308 if (!vsi)
2309 return -EINVAL;
2310
2311 pf = vsi->back;
2312
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002313 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2314 return -EOPNOTSUPP;
2315
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002316 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002317 return -ENOSPC;
2318
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002319 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2320 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2321 return -EBUSY;
2322
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002323 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2324 return -EBUSY;
2325
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002326 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2327
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002328 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2329 pf->hw.func_caps.fd_filters_guaranteed)) {
2330 return -EINVAL;
2331 }
2332
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002333 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2334 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002335 return -EINVAL;
2336
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002337 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002338
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002339 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002340 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002341
2342 input->fd_id = fsp->location;
2343
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002344 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2345 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2346 else
2347 input->dest_ctl =
2348 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2349
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002350 input->q_index = fsp->ring_cookie;
2351 input->flex_off = 0;
2352 input->pctype = 0;
2353 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002354 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002355 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002356 input->flow_type = fsp->flow_type;
2357 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002358
2359 /* Reverse the src and dest notion, since the HW expects them to be from
2360 * Tx perspective where as the input from user is from Rx filter view.
2361 */
2362 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2363 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2364 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2365 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002366
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002367 if (ntohl(fsp->m_ext.data[1])) {
2368 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2369 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2370 goto free_input;
2371 }
2372 vf_id = ntohl(fsp->h_ext.data[1]);
2373 /* Find vsi id from vf id and override dest vsi */
2374 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2375 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2376 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2377 goto free_input;
2378 }
2379 }
2380
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002381 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002382free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002383 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002384 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002385 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002386 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002387
2388 return ret;
2389}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002390
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002391/**
2392 * i40e_set_rxnfc - command to set RX flow classification rules
2393 * @netdev: network interface device structure
2394 * @cmd: ethtool rxnfc command
2395 *
2396 * Returns Success if the command is supported.
2397 **/
2398static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2399{
2400 struct i40e_netdev_priv *np = netdev_priv(netdev);
2401 struct i40e_vsi *vsi = np->vsi;
2402 struct i40e_pf *pf = vsi->back;
2403 int ret = -EOPNOTSUPP;
2404
2405 switch (cmd->cmd) {
2406 case ETHTOOL_SRXFH:
2407 ret = i40e_set_rss_hash_opt(pf, cmd);
2408 break;
2409 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002410 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002411 break;
2412 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002413 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002414 break;
2415 default:
2416 break;
2417 }
2418
2419 return ret;
2420}
2421
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002422/**
2423 * i40e_max_channels - get Max number of combined channels supported
2424 * @vsi: vsi pointer
2425 **/
2426static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2427{
2428 /* TODO: This code assumes DCB and FD is disabled for now. */
2429 return vsi->alloc_queue_pairs;
2430}
2431
2432/**
2433 * i40e_get_channels - Get the current channels enabled and max supported etc.
2434 * @netdev: network interface device structure
2435 * @ch: ethtool channels structure
2436 *
2437 * We don't support separate tx and rx queues as channels. The other count
2438 * represents how many queues are being used for control. max_combined counts
2439 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2440 * q_vectors since we support a lot more queue pairs than q_vectors.
2441 **/
2442static void i40e_get_channels(struct net_device *dev,
2443 struct ethtool_channels *ch)
2444{
2445 struct i40e_netdev_priv *np = netdev_priv(dev);
2446 struct i40e_vsi *vsi = np->vsi;
2447 struct i40e_pf *pf = vsi->back;
2448
2449 /* report maximum channels */
2450 ch->max_combined = i40e_max_channels(vsi);
2451
2452 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002453 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002454 ch->max_other = ch->other_count;
2455
2456 /* Note: This code assumes DCB is disabled for now. */
2457 ch->combined_count = vsi->num_queue_pairs;
2458}
2459
2460/**
2461 * i40e_set_channels - Set the new channels count.
2462 * @netdev: network interface device structure
2463 * @ch: ethtool channels structure
2464 *
2465 * The new channels count may not be the same as requested by the user
2466 * since it gets rounded down to a power of 2 value.
2467 **/
2468static int i40e_set_channels(struct net_device *dev,
2469 struct ethtool_channels *ch)
2470{
2471 struct i40e_netdev_priv *np = netdev_priv(dev);
2472 unsigned int count = ch->combined_count;
2473 struct i40e_vsi *vsi = np->vsi;
2474 struct i40e_pf *pf = vsi->back;
2475 int new_count;
2476
2477 /* We do not support setting channels for any other VSI at present */
2478 if (vsi->type != I40E_VSI_MAIN)
2479 return -EINVAL;
2480
2481 /* verify they are not requesting separate vectors */
2482 if (!count || ch->rx_count || ch->tx_count)
2483 return -EINVAL;
2484
2485 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002486 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002487 return -EINVAL;
2488
2489 /* verify the number of channels does not exceed hardware limits */
2490 if (count > i40e_max_channels(vsi))
2491 return -EINVAL;
2492
2493 /* update feature limits from largest to smallest supported values */
2494 /* TODO: Flow director limit, DCB etc */
2495
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002496 /* use rss_reconfig to rebuild with new queue count and update traffic
2497 * class queue mapping
2498 */
2499 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002500 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002501 return 0;
2502 else
2503 return -EINVAL;
2504}
2505
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002506#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2507/**
2508 * i40e_get_rxfh_key_size - get the RSS hash key size
2509 * @netdev: network interface device structure
2510 *
2511 * Returns the table size.
2512 **/
2513static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2514{
2515 return I40E_HKEY_ARRAY_SIZE;
2516}
2517
2518/**
2519 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2520 * @netdev: network interface device structure
2521 *
2522 * Returns the table size.
2523 **/
2524static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2525{
2526 return I40E_HLUT_ARRAY_SIZE;
2527}
2528
2529static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2530 u8 *hfunc)
2531{
2532 struct i40e_netdev_priv *np = netdev_priv(netdev);
2533 struct i40e_vsi *vsi = np->vsi;
2534 struct i40e_pf *pf = vsi->back;
2535 struct i40e_hw *hw = &pf->hw;
2536 u32 reg_val;
2537 int i, j;
2538
2539 if (hfunc)
2540 *hfunc = ETH_RSS_HASH_TOP;
2541
2542 if (!indir)
2543 return 0;
2544
2545 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2546 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2547 indir[j++] = reg_val & 0xff;
2548 indir[j++] = (reg_val >> 8) & 0xff;
2549 indir[j++] = (reg_val >> 16) & 0xff;
2550 indir[j++] = (reg_val >> 24) & 0xff;
2551 }
2552
2553 if (key) {
2554 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2555 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2556 key[j++] = (u8)(reg_val & 0xff);
2557 key[j++] = (u8)((reg_val >> 8) & 0xff);
2558 key[j++] = (u8)((reg_val >> 16) & 0xff);
2559 key[j++] = (u8)((reg_val >> 24) & 0xff);
2560 }
2561 }
2562 return 0;
2563}
2564
2565/**
2566 * i40e_set_rxfh - set the rx flow hash indirection table
2567 * @netdev: network interface device structure
2568 * @indir: indirection table
2569 * @key: hash key
2570 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002571 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002572 * returns 0 after programming the table.
2573 **/
2574static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2575 const u8 *key, const u8 hfunc)
2576{
2577 struct i40e_netdev_priv *np = netdev_priv(netdev);
2578 struct i40e_vsi *vsi = np->vsi;
2579 struct i40e_pf *pf = vsi->back;
2580 struct i40e_hw *hw = &pf->hw;
2581 u32 reg_val;
2582 int i, j;
2583
2584 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2585 return -EOPNOTSUPP;
2586
2587 if (!indir)
2588 return 0;
2589
2590 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2591 reg_val = indir[j++];
2592 reg_val |= indir[j++] << 8;
2593 reg_val |= indir[j++] << 16;
2594 reg_val |= indir[j++] << 24;
2595 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2596 }
2597
2598 if (key) {
2599 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2600 reg_val = key[j++];
2601 reg_val |= key[j++] << 8;
2602 reg_val |= key[j++] << 16;
2603 reg_val |= key[j++] << 24;
2604 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2605 }
2606 }
2607 return 0;
2608}
2609
Greg Rose7e45ab42015-02-06 08:52:19 +00002610/**
2611 * i40e_get_priv_flags - report device private flags
2612 * @dev: network interface device structure
2613 *
2614 * The get string set count and the string set should be matched for each
2615 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2616 * array.
2617 *
2618 * Returns a u32 bitmap of flags.
2619 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002620static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002621{
2622 struct i40e_netdev_priv *np = netdev_priv(dev);
2623 struct i40e_vsi *vsi = np->vsi;
2624 struct i40e_pf *pf = vsi->back;
2625 u32 ret_flags = 0;
2626
2627 ret_flags |= pf->hw.func_caps.npar_enable ?
2628 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2629
2630 return ret_flags;
2631}
2632
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002633static const struct ethtool_ops i40e_ethtool_ops = {
2634 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002635 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002636 .get_drvinfo = i40e_get_drvinfo,
2637 .get_regs_len = i40e_get_regs_len,
2638 .get_regs = i40e_get_regs,
2639 .nway_reset = i40e_nway_reset,
2640 .get_link = ethtool_op_get_link,
2641 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002642 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002643 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002644 .get_eeprom_len = i40e_get_eeprom_len,
2645 .get_eeprom = i40e_get_eeprom,
2646 .get_ringparam = i40e_get_ringparam,
2647 .set_ringparam = i40e_set_ringparam,
2648 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002649 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002650 .get_msglevel = i40e_get_msglevel,
2651 .set_msglevel = i40e_set_msglevel,
2652 .get_rxnfc = i40e_get_rxnfc,
2653 .set_rxnfc = i40e_set_rxnfc,
2654 .self_test = i40e_diag_test,
2655 .get_strings = i40e_get_strings,
2656 .set_phys_id = i40e_set_phys_id,
2657 .get_sset_count = i40e_get_sset_count,
2658 .get_ethtool_stats = i40e_get_ethtool_stats,
2659 .get_coalesce = i40e_get_coalesce,
2660 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002661 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2662 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2663 .get_rxfh = i40e_get_rxfh,
2664 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002665 .get_channels = i40e_get_channels,
2666 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002667 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002668 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002669};
2670
2671void i40e_set_ethtool_ops(struct net_device *netdev)
2672{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002673 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002674}