blob: 148f61461076ecb933140a41086f52cfd7812862 [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",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400233 "LinkPolling",
Greg Rose7e45ab42015-02-06 08:52:19 +0000234};
235
Shannon Nelson9ac77262015-08-27 11:42:40 -0400236#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000237
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 */
Matt Jaredc156f852015-08-27 11:42:39 -0400693 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000694 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 */
Matt Jaredc156f852015-08-27 11:42:39 -0400837 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000838 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;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001179 /* the desc and bi pointers will be reallocated in the
1180 * setup call
1181 */
1182 tx_rings[i].desc = NULL;
1183 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001184 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1185 if (err) {
1186 while (i) {
1187 i--;
1188 i40e_free_tx_resources(&tx_rings[i]);
1189 }
1190 kfree(tx_rings);
1191 tx_rings = NULL;
1192
1193 goto done;
1194 }
1195 }
1196 }
1197
1198 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001199 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001200 netdev_info(netdev,
1201 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001202 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001203 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1204 sizeof(struct i40e_ring), GFP_KERNEL);
1205 if (!rx_rings) {
1206 err = -ENOMEM;
1207 goto free_tx;
1208 }
1209
1210 for (i = 0; i < vsi->num_queue_pairs; i++) {
1211 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001212 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001213 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001214 /* the desc and bi pointers will be reallocated in the
1215 * setup call
1216 */
1217 rx_rings[i].desc = NULL;
1218 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001219 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1220 if (err) {
1221 while (i) {
1222 i--;
1223 i40e_free_rx_resources(&rx_rings[i]);
1224 }
1225 kfree(rx_rings);
1226 rx_rings = NULL;
1227
1228 goto free_tx;
1229 }
1230 }
1231 }
1232
1233 /* Bring interface down, copy in the new ring info,
1234 * then restore the interface
1235 */
1236 i40e_down(vsi);
1237
1238 if (tx_rings) {
1239 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001240 i40e_free_tx_resources(vsi->tx_rings[i]);
1241 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001242 }
1243 kfree(tx_rings);
1244 tx_rings = NULL;
1245 }
1246
1247 if (rx_rings) {
1248 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001249 i40e_free_rx_resources(vsi->rx_rings[i]);
1250 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001251 }
1252 kfree(rx_rings);
1253 rx_rings = NULL;
1254 }
1255
1256 i40e_up(vsi);
1257
1258free_tx:
1259 /* error cleanup if the Rx allocations failed after getting Tx */
1260 if (tx_rings) {
1261 for (i = 0; i < vsi->num_queue_pairs; i++)
1262 i40e_free_tx_resources(&tx_rings[i]);
1263 kfree(tx_rings);
1264 tx_rings = NULL;
1265 }
1266
1267done:
1268 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1269
1270 return err;
1271}
1272
1273static int i40e_get_sset_count(struct net_device *netdev, int sset)
1274{
1275 struct i40e_netdev_priv *np = netdev_priv(netdev);
1276 struct i40e_vsi *vsi = np->vsi;
1277 struct i40e_pf *pf = vsi->back;
1278
1279 switch (sset) {
1280 case ETH_SS_TEST:
1281 return I40E_TEST_LEN;
1282 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001283 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001284 int len = I40E_PF_STATS_LEN(netdev);
1285
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001286 if ((pf->lan_veb != I40E_NO_VEB) &&
1287 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001288 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001289 return len;
1290 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001291 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001292 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001293 case ETH_SS_PRIV_FLAGS:
1294 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001295 default:
1296 return -EOPNOTSUPP;
1297 }
1298}
1299
1300static void i40e_get_ethtool_stats(struct net_device *netdev,
1301 struct ethtool_stats *stats, u64 *data)
1302{
1303 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001304 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001305 struct i40e_vsi *vsi = np->vsi;
1306 struct i40e_pf *pf = vsi->back;
1307 int i = 0;
1308 char *p;
1309 int j;
1310 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001311 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001312
1313 i40e_update_stats(vsi);
1314
1315 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1316 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1317 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1318 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1319 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001320 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1321 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1322 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1323 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1324 }
Vasu Dev38e00432014-08-01 13:27:03 -07001325#ifdef I40E_FCOE
1326 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1327 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1328 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1329 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1330 }
1331#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001332 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001333 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001334 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001335
1336 if (!tx_ring)
1337 continue;
1338
1339 /* process Tx ring statistics */
1340 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001341 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001342 data[i] = tx_ring->stats.packets;
1343 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001344 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001345 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001346
1347 /* Rx ring is the 2nd half of the queue pair */
1348 rx_ring = &tx_ring[1];
1349 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001350 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001351 data[i] = rx_ring->stats.packets;
1352 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001353 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001354 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001355 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001356 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001357 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001358 return;
1359
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001360 if ((pf->lan_veb != I40E_NO_VEB) &&
1361 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001362 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001363
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001364 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1365 p = (char *)veb;
1366 p += i40e_gstrings_veb_stats[j].stat_offset;
1367 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1368 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001369 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001370 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001371 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1372 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1373 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1374 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1375 }
1376 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1377 data[i++] = pf->stats.priority_xon_tx[j];
1378 data[i++] = pf->stats.priority_xoff_tx[j];
1379 }
1380 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1381 data[i++] = pf->stats.priority_xon_rx[j];
1382 data[i++] = pf->stats.priority_xoff_rx[j];
1383 }
1384 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1385 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001386}
1387
1388static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1389 u8 *data)
1390{
1391 struct i40e_netdev_priv *np = netdev_priv(netdev);
1392 struct i40e_vsi *vsi = np->vsi;
1393 struct i40e_pf *pf = vsi->back;
1394 char *p = (char *)data;
1395 int i;
1396
1397 switch (stringset) {
1398 case ETH_SS_TEST:
1399 for (i = 0; i < I40E_TEST_LEN; i++) {
1400 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1401 data += ETH_GSTRING_LEN;
1402 }
1403 break;
1404 case ETH_SS_STATS:
1405 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1406 snprintf(p, ETH_GSTRING_LEN, "%s",
1407 i40e_gstrings_net_stats[i].stat_string);
1408 p += ETH_GSTRING_LEN;
1409 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001410 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1411 snprintf(p, ETH_GSTRING_LEN, "%s",
1412 i40e_gstrings_misc_stats[i].stat_string);
1413 p += ETH_GSTRING_LEN;
1414 }
Vasu Dev38e00432014-08-01 13:27:03 -07001415#ifdef I40E_FCOE
1416 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1417 snprintf(p, ETH_GSTRING_LEN, "%s",
1418 i40e_gstrings_fcoe_stats[i].stat_string);
1419 p += ETH_GSTRING_LEN;
1420 }
1421#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001422 for (i = 0; i < vsi->num_queue_pairs; i++) {
1423 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1424 p += ETH_GSTRING_LEN;
1425 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1426 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001427 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1428 p += ETH_GSTRING_LEN;
1429 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1430 p += ETH_GSTRING_LEN;
1431 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001432 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001433 return;
1434
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001435 if ((pf->lan_veb != I40E_NO_VEB) &&
1436 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001437 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1438 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1439 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001440 p += ETH_GSTRING_LEN;
1441 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001442 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1443 snprintf(p, ETH_GSTRING_LEN,
1444 "veb.tc_%u_tx_packets", i);
1445 p += ETH_GSTRING_LEN;
1446 snprintf(p, ETH_GSTRING_LEN,
1447 "veb.tc_%u_tx_bytes", i);
1448 p += ETH_GSTRING_LEN;
1449 snprintf(p, ETH_GSTRING_LEN,
1450 "veb.tc_%u_rx_packets", i);
1451 p += ETH_GSTRING_LEN;
1452 snprintf(p, ETH_GSTRING_LEN,
1453 "veb.tc_%u_rx_bytes", i);
1454 p += ETH_GSTRING_LEN;
1455 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001456 }
1457 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1458 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1459 i40e_gstrings_stats[i].stat_string);
1460 p += ETH_GSTRING_LEN;
1461 }
1462 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1463 snprintf(p, ETH_GSTRING_LEN,
1464 "port.tx_priority_%u_xon", i);
1465 p += ETH_GSTRING_LEN;
1466 snprintf(p, ETH_GSTRING_LEN,
1467 "port.tx_priority_%u_xoff", i);
1468 p += ETH_GSTRING_LEN;
1469 }
1470 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1471 snprintf(p, ETH_GSTRING_LEN,
1472 "port.rx_priority_%u_xon", i);
1473 p += ETH_GSTRING_LEN;
1474 snprintf(p, ETH_GSTRING_LEN,
1475 "port.rx_priority_%u_xoff", i);
1476 p += ETH_GSTRING_LEN;
1477 }
1478 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1479 snprintf(p, ETH_GSTRING_LEN,
1480 "port.rx_priority_%u_xon_2_xoff", i);
1481 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482 }
1483 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1484 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001485 case ETH_SS_PRIV_FLAGS:
1486 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1487 memcpy(data, i40e_priv_flags_strings[i],
1488 ETH_GSTRING_LEN);
1489 data += ETH_GSTRING_LEN;
1490 }
1491 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001492 default:
1493 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494 }
1495}
1496
1497static int i40e_get_ts_info(struct net_device *dev,
1498 struct ethtool_ts_info *info)
1499{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001500 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1501
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001502 /* only report HW timestamping if PTP is enabled */
1503 if (!(pf->flags & I40E_FLAG_PTP))
1504 return ethtool_op_get_ts_info(dev, info);
1505
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001506 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1507 SOF_TIMESTAMPING_RX_SOFTWARE |
1508 SOF_TIMESTAMPING_SOFTWARE |
1509 SOF_TIMESTAMPING_TX_HARDWARE |
1510 SOF_TIMESTAMPING_RX_HARDWARE |
1511 SOF_TIMESTAMPING_RAW_HARDWARE;
1512
1513 if (pf->ptp_clock)
1514 info->phc_index = ptp_clock_index(pf->ptp_clock);
1515 else
1516 info->phc_index = -1;
1517
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001518 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001519
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001520 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1521 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1522 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001523
1524 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001525}
1526
Shannon Nelson7b086392013-11-20 10:02:59 +00001527static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001528{
Shannon Nelson7b086392013-11-20 10:02:59 +00001529 struct i40e_netdev_priv *np = netdev_priv(netdev);
1530 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001531 i40e_status status;
1532 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001533
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001534 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001535 status = i40e_get_link_status(&pf->hw, &link_up);
1536 if (status) {
1537 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1538 *data = 1;
1539 return *data;
1540 }
1541
1542 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543 *data = 0;
1544 else
1545 *data = 1;
1546
1547 return *data;
1548}
1549
Shannon Nelson7b086392013-11-20 10:02:59 +00001550static int i40e_reg_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, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001556 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557
Shannon Nelson7b086392013-11-20 10:02:59 +00001558 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001559}
1560
Shannon Nelson7b086392013-11-20 10:02:59 +00001561static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562{
Shannon Nelson7b086392013-11-20 10:02:59 +00001563 struct i40e_netdev_priv *np = netdev_priv(netdev);
1564 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001565
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001566 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001567 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568
Shannon Nelson4443ec92014-11-13 08:23:12 +00001569 /* forcebly clear the NVM Update state machine */
1570 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1571
Shannon Nelson7b086392013-11-20 10:02:59 +00001572 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573}
1574
Shannon Nelson7b086392013-11-20 10:02:59 +00001575static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001576{
Shannon Nelson7b086392013-11-20 10:02:59 +00001577 struct i40e_netdev_priv *np = netdev_priv(netdev);
1578 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001579 u16 swc_old = pf->sw_int_count;
1580
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001581 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001582 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1583 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001584 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1585 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1586 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1587 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001588 usleep_range(1000, 2000);
1589 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001590
1591 return *data;
1592}
1593
Shannon Nelson7b086392013-11-20 10:02:59 +00001594static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001596 struct i40e_netdev_priv *np = netdev_priv(netdev);
1597 struct i40e_pf *pf = np->vsi->back;
1598
1599 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001600 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001601
1602 return *data;
1603}
1604
Greg Rosee17bc412015-04-16 20:05:59 -04001605static inline bool i40e_active_vfs(struct i40e_pf *pf)
1606{
1607 struct i40e_vf *vfs = pf->vf;
1608 int i;
1609
1610 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001611 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001612 return true;
1613 return false;
1614}
1615
Greg Rose510efb22015-07-10 19:36:01 -04001616static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1617{
1618 struct i40e_vsi **vsi = pf->vsi;
1619 int i;
1620
1621 for (i = 0; i < pf->num_alloc_vsi; i++) {
1622 if (!vsi[i])
1623 continue;
1624 if (vsi[i]->type == I40E_VSI_VMDQ2)
1625 return true;
1626 }
1627
1628 return false;
1629}
1630
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001631static void i40e_diag_test(struct net_device *netdev,
1632 struct ethtool_test *eth_test, u64 *data)
1633{
1634 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001635 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001636 struct i40e_pf *pf = np->vsi->back;
1637
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001638 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1639 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001640 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001641
Shannon Nelsonf551b432013-11-26 10:49:12 +00001642 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001643
Greg Rose510efb22015-07-10 19:36:01 -04001644 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001645 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001646 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001647 data[I40E_ETH_TEST_REG] = 1;
1648 data[I40E_ETH_TEST_EEPROM] = 1;
1649 data[I40E_ETH_TEST_INTR] = 1;
1650 data[I40E_ETH_TEST_LOOPBACK] = 1;
1651 data[I40E_ETH_TEST_LINK] = 1;
1652 eth_test->flags |= ETH_TEST_FL_FAILED;
1653 clear_bit(__I40E_TESTING, &pf->state);
1654 goto skip_ol_tests;
1655 }
1656
Greg Rose5b86c5c2015-02-26 16:14:35 +00001657 /* If the device is online then take it offline */
1658 if (if_running)
1659 /* indicate we're in test mode */
1660 dev_close(netdev);
1661 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001662 /* This reset does not affect link - if it is
1663 * changed to a type of reset that does affect
1664 * link then the following link test would have
1665 * to be moved to before the reset
1666 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001667 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001668
Shannon Nelson7b086392013-11-20 10:02:59 +00001669 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001670 eth_test->flags |= ETH_TEST_FL_FAILED;
1671
Shannon Nelson7b086392013-11-20 10:02:59 +00001672 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001673 eth_test->flags |= ETH_TEST_FL_FAILED;
1674
Shannon Nelson7b086392013-11-20 10:02:59 +00001675 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001676 eth_test->flags |= ETH_TEST_FL_FAILED;
1677
Shannon Nelson7b086392013-11-20 10:02:59 +00001678 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001679 eth_test->flags |= ETH_TEST_FL_FAILED;
1680
Shannon Nelsonf551b432013-11-26 10:49:12 +00001681 /* run reg test last, a reset is required after it */
1682 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1683 eth_test->flags |= ETH_TEST_FL_FAILED;
1684
1685 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001686 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001687
1688 if (if_running)
1689 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001690 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001691 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001692 netif_info(pf, drv, netdev, "online testing starting\n");
1693
Shannon Nelson7b086392013-11-20 10:02:59 +00001694 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695 eth_test->flags |= ETH_TEST_FL_FAILED;
1696
1697 /* Offline only tests, not run in online; pass by default */
1698 data[I40E_ETH_TEST_REG] = 0;
1699 data[I40E_ETH_TEST_EEPROM] = 0;
1700 data[I40E_ETH_TEST_INTR] = 0;
1701 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001702 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001703
Greg Rosee17bc412015-04-16 20:05:59 -04001704skip_ol_tests:
1705
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001706 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001707}
1708
1709static void i40e_get_wol(struct net_device *netdev,
1710 struct ethtool_wolinfo *wol)
1711{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001712 struct i40e_netdev_priv *np = netdev_priv(netdev);
1713 struct i40e_pf *pf = np->vsi->back;
1714 struct i40e_hw *hw = &pf->hw;
1715 u16 wol_nvm_bits;
1716
1717 /* NVM bit on means WoL disabled for the port */
1718 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001719 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001720 wol->supported = 0;
1721 wol->wolopts = 0;
1722 } else {
1723 wol->supported = WAKE_MAGIC;
1724 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1725 }
1726}
1727
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001728/**
1729 * i40e_set_wol - set the WakeOnLAN configuration
1730 * @netdev: the netdev in question
1731 * @wol: the ethtool WoL setting data
1732 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001733static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1734{
1735 struct i40e_netdev_priv *np = netdev_priv(netdev);
1736 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001737 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001738 struct i40e_hw *hw = &pf->hw;
1739 u16 wol_nvm_bits;
1740
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001741 /* WoL not supported if this isn't the controlling PF on the port */
1742 if (hw->partition_id != 1) {
1743 i40e_partition_setting_complaint(pf);
1744 return -EOPNOTSUPP;
1745 }
1746
1747 if (vsi != pf->vsi[pf->lan_vsi])
1748 return -EOPNOTSUPP;
1749
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001750 /* NVM bit on means WoL disabled for the port */
1751 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001752 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001753 return -EOPNOTSUPP;
1754
1755 /* only magic packet is supported */
1756 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1757 return -EOPNOTSUPP;
1758
1759 /* is this a new value? */
1760 if (pf->wol_en != !!wol->wolopts) {
1761 pf->wol_en = !!wol->wolopts;
1762 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1763 }
1764
1765 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001766}
1767
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001768static int i40e_set_phys_id(struct net_device *netdev,
1769 enum ethtool_phys_id_state state)
1770{
1771 struct i40e_netdev_priv *np = netdev_priv(netdev);
1772 struct i40e_pf *pf = np->vsi->back;
1773 struct i40e_hw *hw = &pf->hw;
1774 int blink_freq = 2;
1775
1776 switch (state) {
1777 case ETHTOOL_ID_ACTIVE:
1778 pf->led_status = i40e_led_get(hw);
1779 return blink_freq;
1780 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001781 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001782 break;
1783 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001784 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001785 break;
1786 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001787 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001788 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001789 default:
1790 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791 }
1792
1793 return 0;
1794}
1795
1796/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1797 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1798 * 125us (8000 interrupts per second) == ITR(62)
1799 */
1800
1801static int i40e_get_coalesce(struct net_device *netdev,
1802 struct ethtool_coalesce *ec)
1803{
1804 struct i40e_netdev_priv *np = netdev_priv(netdev);
1805 struct i40e_vsi *vsi = np->vsi;
1806
1807 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1808 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1809
1810 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001811 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812
1813 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001814 ec->use_adaptive_tx_coalesce = 1;
1815
1816 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1817 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818
1819 return 0;
1820}
1821
1822static int i40e_set_coalesce(struct net_device *netdev,
1823 struct ethtool_coalesce *ec)
1824{
1825 struct i40e_netdev_priv *np = netdev_priv(netdev);
1826 struct i40e_q_vector *q_vector;
1827 struct i40e_vsi *vsi = np->vsi;
1828 struct i40e_pf *pf = vsi->back;
1829 struct i40e_hw *hw = &pf->hw;
1830 u16 vector;
1831 int i;
1832
1833 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1834 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1835
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001836 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001837 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001838 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001839 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001840 } else if (ec->rx_coalesce_usecs == 0) {
1841 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001842 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001843 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 +00001844 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001845 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001846 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001847 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001848
Mitch Williams32f5f542014-04-04 04:43:10 +00001849 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001850 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001851 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001852 } else if (ec->tx_coalesce_usecs == 0) {
1853 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001854 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001855 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 +00001856 } else {
1857 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001858 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001859 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001860 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001861
1862 if (ec->use_adaptive_rx_coalesce)
1863 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1864 else
1865 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1866
1867 if (ec->use_adaptive_tx_coalesce)
1868 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1869 else
1870 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001871
Alexander Duyck493fb302013-09-28 07:01:44 +00001872 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1873 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001874 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1875 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1876 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1877 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1878 i40e_flush(hw);
1879 }
1880
1881 return 0;
1882}
1883
1884/**
1885 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1886 * @pf: pointer to the physical function struct
1887 * @cmd: ethtool rxnfc command
1888 *
1889 * Returns Success if the flow is supported, else Invalid Input.
1890 **/
1891static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1892{
1893 cmd->data = 0;
1894
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001895 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1896 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1897 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1898 return 0;
1899 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001900 /* Report default options for RSS on i40e */
1901 switch (cmd->flow_type) {
1902 case TCP_V4_FLOW:
1903 case UDP_V4_FLOW:
1904 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1905 /* fall through to add IP fields */
1906 case SCTP_V4_FLOW:
1907 case AH_ESP_V4_FLOW:
1908 case AH_V4_FLOW:
1909 case ESP_V4_FLOW:
1910 case IPV4_FLOW:
1911 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1912 break;
1913 case TCP_V6_FLOW:
1914 case UDP_V6_FLOW:
1915 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1916 /* fall through to add IP fields */
1917 case SCTP_V6_FLOW:
1918 case AH_ESP_V6_FLOW:
1919 case AH_V6_FLOW:
1920 case ESP_V6_FLOW:
1921 case IPV6_FLOW:
1922 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1923 break;
1924 default:
1925 return -EINVAL;
1926 }
1927
1928 return 0;
1929}
1930
1931/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001932 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1933 * @pf: Pointer to the physical function struct
1934 * @cmd: The command to get or set Rx flow classification rules
1935 * @rule_locs: Array of used rule locations
1936 *
1937 * This function populates both the total and actual rule count of
1938 * the ethtool flow classification command
1939 *
1940 * Returns 0 on success or -EMSGSIZE if entry not found
1941 **/
1942static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1943 struct ethtool_rxnfc *cmd,
1944 u32 *rule_locs)
1945{
1946 struct i40e_fdir_filter *rule;
1947 struct hlist_node *node2;
1948 int cnt = 0;
1949
1950 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001951 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001952
1953 hlist_for_each_entry_safe(rule, node2,
1954 &pf->fdir_filter_list, fdir_node) {
1955 if (cnt == cmd->rule_cnt)
1956 return -EMSGSIZE;
1957
1958 rule_locs[cnt] = rule->fd_id;
1959 cnt++;
1960 }
1961
1962 cmd->rule_cnt = cnt;
1963
1964 return 0;
1965}
1966
1967/**
1968 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1969 * @pf: Pointer to the physical function struct
1970 * @cmd: The command to get or set Rx flow classification rules
1971 *
1972 * This function looks up a filter based on the Rx flow classification
1973 * command and fills the flow spec info for it if found
1974 *
1975 * Returns 0 on success or -EINVAL if filter not found
1976 **/
1977static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1978 struct ethtool_rxnfc *cmd)
1979{
1980 struct ethtool_rx_flow_spec *fsp =
1981 (struct ethtool_rx_flow_spec *)&cmd->fs;
1982 struct i40e_fdir_filter *rule = NULL;
1983 struct hlist_node *node2;
1984
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001985 hlist_for_each_entry_safe(rule, node2,
1986 &pf->fdir_filter_list, fdir_node) {
1987 if (fsp->location <= rule->fd_id)
1988 break;
1989 }
1990
1991 if (!rule || fsp->location != rule->fd_id)
1992 return -EINVAL;
1993
1994 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001995 if (fsp->flow_type == IP_USER_FLOW) {
1996 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1997 fsp->h_u.usr_ip4_spec.proto = 0;
1998 fsp->m_u.usr_ip4_spec.proto = 0;
1999 }
2000
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002001 /* Reverse the src and dest notion, since the HW views them from
2002 * Tx perspective where as the user expects it from Rx filter view.
2003 */
2004 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2005 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2006 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2007 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002008
2009 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2010 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2011 else
2012 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002013
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002014 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2015 struct i40e_vsi *vsi;
2016
2017 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2018 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2019 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2020 fsp->m_ext.data[1] = htonl(0x1);
2021 }
2022 }
2023
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002024 return 0;
2025}
2026
2027/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002028 * i40e_get_rxnfc - command to get RX flow classification rules
2029 * @netdev: network interface device structure
2030 * @cmd: ethtool rxnfc command
2031 *
2032 * Returns Success if the command is supported.
2033 **/
2034static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2035 u32 *rule_locs)
2036{
2037 struct i40e_netdev_priv *np = netdev_priv(netdev);
2038 struct i40e_vsi *vsi = np->vsi;
2039 struct i40e_pf *pf = vsi->back;
2040 int ret = -EOPNOTSUPP;
2041
2042 switch (cmd->cmd) {
2043 case ETHTOOL_GRXRINGS:
2044 cmd->data = vsi->alloc_queue_pairs;
2045 ret = 0;
2046 break;
2047 case ETHTOOL_GRXFH:
2048 ret = i40e_get_rss_hash_opts(pf, cmd);
2049 break;
2050 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002051 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002052 /* report total rule count */
2053 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002054 ret = 0;
2055 break;
2056 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002057 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002058 break;
2059 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002060 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2061 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062 default:
2063 break;
2064 }
2065
2066 return ret;
2067}
2068
2069/**
2070 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2071 * @pf: pointer to the physical function struct
2072 * @cmd: ethtool rxnfc command
2073 *
2074 * Returns Success if the flow input set is supported.
2075 **/
2076static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2077{
2078 struct i40e_hw *hw = &pf->hw;
2079 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2080 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2081
2082 /* RSS does not support anything other than hashing
2083 * to queues on src and dst IPs and ports
2084 */
2085 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2086 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2087 return -EINVAL;
2088
2089 /* We need at least the IP SRC and DEST fields for hashing */
2090 if (!(nfc->data & RXH_IP_SRC) ||
2091 !(nfc->data & RXH_IP_DST))
2092 return -EINVAL;
2093
2094 switch (nfc->flow_type) {
2095 case TCP_V4_FLOW:
2096 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2097 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002098 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002099 break;
2100 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002101 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002102 break;
2103 default:
2104 return -EINVAL;
2105 }
2106 break;
2107 case TCP_V6_FLOW:
2108 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2109 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002110 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002111 break;
2112 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002113 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002114 break;
2115 default:
2116 return -EINVAL;
2117 }
2118 break;
2119 case UDP_V4_FLOW:
2120 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2121 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002122 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2123 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002124 break;
2125 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002126 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2127 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002128 break;
2129 default:
2130 return -EINVAL;
2131 }
2132 break;
2133 case UDP_V6_FLOW:
2134 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2135 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002136 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2137 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002138 break;
2139 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002140 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2141 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142 break;
2143 default:
2144 return -EINVAL;
2145 }
2146 break;
2147 case AH_ESP_V4_FLOW:
2148 case AH_V4_FLOW:
2149 case ESP_V4_FLOW:
2150 case SCTP_V4_FLOW:
2151 if ((nfc->data & RXH_L4_B_0_1) ||
2152 (nfc->data & RXH_L4_B_2_3))
2153 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002154 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155 break;
2156 case AH_ESP_V6_FLOW:
2157 case AH_V6_FLOW:
2158 case ESP_V6_FLOW:
2159 case SCTP_V6_FLOW:
2160 if ((nfc->data & RXH_L4_B_0_1) ||
2161 (nfc->data & RXH_L4_B_2_3))
2162 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002163 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002164 break;
2165 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002166 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2167 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002168 break;
2169 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002170 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2171 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 break;
2173 default:
2174 return -EINVAL;
2175 }
2176
2177 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2178 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2179 i40e_flush(hw);
2180
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002181 /* Save setting for future output/update */
2182 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2183
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 return 0;
2185}
2186
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002188 * i40e_match_fdir_input_set - Match a new filter against an existing one
2189 * @rule: The filter already added
2190 * @input: The new filter to comapre against
2191 *
2192 * Returns true if the two input set match
2193 **/
2194static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2195 struct i40e_fdir_filter *input)
2196{
2197 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2198 (rule->src_ip[0] != input->src_ip[0]) ||
2199 (rule->dst_port != input->dst_port) ||
2200 (rule->src_port != input->src_port))
2201 return false;
2202 return true;
2203}
2204
2205/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002206 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2207 * @vsi: Pointer to the targeted VSI
2208 * @input: The filter to update or NULL to indicate deletion
2209 * @sw_idx: Software index to the filter
2210 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002211 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002212 * This function updates (or deletes) a Flow Director entry from
2213 * the hlist of the corresponding PF
2214 *
2215 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002216 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002217static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2218 struct i40e_fdir_filter *input,
2219 u16 sw_idx,
2220 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002221{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002222 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002223 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002224 struct hlist_node *node2;
2225 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002226
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002227 parent = NULL;
2228 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002230 hlist_for_each_entry_safe(rule, node2,
2231 &pf->fdir_filter_list, fdir_node) {
2232 /* hash found, or no matching entry */
2233 if (rule->fd_id >= sw_idx)
2234 break;
2235 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002236 }
2237
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002238 /* if there is an old rule occupying our place remove it */
2239 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002240 if (input && !i40e_match_fdir_input_set(rule, input))
2241 err = i40e_add_del_fdir(vsi, rule, false);
2242 else if (!input)
2243 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002244 hlist_del(&rule->fdir_node);
2245 kfree(rule);
2246 pf->fdir_pf_active_filters--;
2247 }
2248
2249 /* If no input this was a delete, err should be 0 if a rule was
2250 * successfully found and removed from the list else -EINVAL
2251 */
2252 if (!input)
2253 return err;
2254
2255 /* initialize node and set software index */
2256 INIT_HLIST_NODE(&input->fdir_node);
2257
2258 /* add filter to the list */
2259 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002260 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002261 else
2262 hlist_add_head(&input->fdir_node,
2263 &pf->fdir_filter_list);
2264
2265 /* update counts */
2266 pf->fdir_pf_active_filters++;
2267
2268 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002269}
2270
2271/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002272 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2273 * @vsi: Pointer to the targeted VSI
2274 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002276 * The function removes a Flow Director filter entry from the
2277 * hlist of the corresponding PF
2278 *
2279 * Returns 0 on success
2280 */
2281static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2282 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002283{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002284 struct ethtool_rx_flow_spec *fsp =
2285 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002286 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002287 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002288
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002289 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2290 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2291 return -EBUSY;
2292
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002293 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2294 return -EBUSY;
2295
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002296 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002297
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002298 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002299 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002300}
2301
2302/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002303 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002304 * @vsi: pointer to the targeted VSI
2305 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002306 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002307 * Add Flow Director filters for a specific flow spec based on their
2308 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002309 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002310static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2311 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002312{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002313 struct ethtool_rx_flow_spec *fsp;
2314 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002315 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002316 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002317 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002318
2319 if (!vsi)
2320 return -EINVAL;
2321
2322 pf = vsi->back;
2323
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002324 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2325 return -EOPNOTSUPP;
2326
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002327 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002328 return -ENOSPC;
2329
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002330 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2331 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2332 return -EBUSY;
2333
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002334 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2335 return -EBUSY;
2336
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002337 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2338
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002339 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2340 pf->hw.func_caps.fd_filters_guaranteed)) {
2341 return -EINVAL;
2342 }
2343
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002344 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2345 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002346 return -EINVAL;
2347
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002348 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002349
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002350 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002351 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002352
2353 input->fd_id = fsp->location;
2354
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002355 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2356 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2357 else
2358 input->dest_ctl =
2359 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2360
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002361 input->q_index = fsp->ring_cookie;
2362 input->flex_off = 0;
2363 input->pctype = 0;
2364 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002365 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002366 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002367 input->flow_type = fsp->flow_type;
2368 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002369
2370 /* Reverse the src and dest notion, since the HW expects them to be from
2371 * Tx perspective where as the input from user is from Rx filter view.
2372 */
2373 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2374 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2375 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2376 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002377
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002378 if (ntohl(fsp->m_ext.data[1])) {
2379 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2380 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2381 goto free_input;
2382 }
2383 vf_id = ntohl(fsp->h_ext.data[1]);
2384 /* Find vsi id from vf id and override dest vsi */
2385 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2386 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2387 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2388 goto free_input;
2389 }
2390 }
2391
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002392 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002393free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002394 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002395 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002396 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002397 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002398
2399 return ret;
2400}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002401
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002402/**
2403 * i40e_set_rxnfc - command to set RX flow classification rules
2404 * @netdev: network interface device structure
2405 * @cmd: ethtool rxnfc command
2406 *
2407 * Returns Success if the command is supported.
2408 **/
2409static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2410{
2411 struct i40e_netdev_priv *np = netdev_priv(netdev);
2412 struct i40e_vsi *vsi = np->vsi;
2413 struct i40e_pf *pf = vsi->back;
2414 int ret = -EOPNOTSUPP;
2415
2416 switch (cmd->cmd) {
2417 case ETHTOOL_SRXFH:
2418 ret = i40e_set_rss_hash_opt(pf, cmd);
2419 break;
2420 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002421 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002422 break;
2423 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002424 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002425 break;
2426 default:
2427 break;
2428 }
2429
2430 return ret;
2431}
2432
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002433/**
2434 * i40e_max_channels - get Max number of combined channels supported
2435 * @vsi: vsi pointer
2436 **/
2437static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2438{
2439 /* TODO: This code assumes DCB and FD is disabled for now. */
2440 return vsi->alloc_queue_pairs;
2441}
2442
2443/**
2444 * i40e_get_channels - Get the current channels enabled and max supported etc.
2445 * @netdev: network interface device structure
2446 * @ch: ethtool channels structure
2447 *
2448 * We don't support separate tx and rx queues as channels. The other count
2449 * represents how many queues are being used for control. max_combined counts
2450 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2451 * q_vectors since we support a lot more queue pairs than q_vectors.
2452 **/
2453static void i40e_get_channels(struct net_device *dev,
2454 struct ethtool_channels *ch)
2455{
2456 struct i40e_netdev_priv *np = netdev_priv(dev);
2457 struct i40e_vsi *vsi = np->vsi;
2458 struct i40e_pf *pf = vsi->back;
2459
2460 /* report maximum channels */
2461 ch->max_combined = i40e_max_channels(vsi);
2462
2463 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002464 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002465 ch->max_other = ch->other_count;
2466
2467 /* Note: This code assumes DCB is disabled for now. */
2468 ch->combined_count = vsi->num_queue_pairs;
2469}
2470
2471/**
2472 * i40e_set_channels - Set the new channels count.
2473 * @netdev: network interface device structure
2474 * @ch: ethtool channels structure
2475 *
2476 * The new channels count may not be the same as requested by the user
2477 * since it gets rounded down to a power of 2 value.
2478 **/
2479static int i40e_set_channels(struct net_device *dev,
2480 struct ethtool_channels *ch)
2481{
2482 struct i40e_netdev_priv *np = netdev_priv(dev);
2483 unsigned int count = ch->combined_count;
2484 struct i40e_vsi *vsi = np->vsi;
2485 struct i40e_pf *pf = vsi->back;
2486 int new_count;
2487
2488 /* We do not support setting channels for any other VSI at present */
2489 if (vsi->type != I40E_VSI_MAIN)
2490 return -EINVAL;
2491
2492 /* verify they are not requesting separate vectors */
2493 if (!count || ch->rx_count || ch->tx_count)
2494 return -EINVAL;
2495
2496 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002497 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002498 return -EINVAL;
2499
2500 /* verify the number of channels does not exceed hardware limits */
2501 if (count > i40e_max_channels(vsi))
2502 return -EINVAL;
2503
2504 /* update feature limits from largest to smallest supported values */
2505 /* TODO: Flow director limit, DCB etc */
2506
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002507 /* use rss_reconfig to rebuild with new queue count and update traffic
2508 * class queue mapping
2509 */
2510 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002511 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002512 return 0;
2513 else
2514 return -EINVAL;
2515}
2516
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002517#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2518/**
2519 * i40e_get_rxfh_key_size - get the RSS hash key size
2520 * @netdev: network interface device structure
2521 *
2522 * Returns the table size.
2523 **/
2524static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2525{
2526 return I40E_HKEY_ARRAY_SIZE;
2527}
2528
2529/**
2530 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2531 * @netdev: network interface device structure
2532 *
2533 * Returns the table size.
2534 **/
2535static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2536{
2537 return I40E_HLUT_ARRAY_SIZE;
2538}
2539
2540static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2541 u8 *hfunc)
2542{
2543 struct i40e_netdev_priv *np = netdev_priv(netdev);
2544 struct i40e_vsi *vsi = np->vsi;
2545 struct i40e_pf *pf = vsi->back;
2546 struct i40e_hw *hw = &pf->hw;
2547 u32 reg_val;
2548 int i, j;
2549
2550 if (hfunc)
2551 *hfunc = ETH_RSS_HASH_TOP;
2552
2553 if (!indir)
2554 return 0;
2555
2556 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2557 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2558 indir[j++] = reg_val & 0xff;
2559 indir[j++] = (reg_val >> 8) & 0xff;
2560 indir[j++] = (reg_val >> 16) & 0xff;
2561 indir[j++] = (reg_val >> 24) & 0xff;
2562 }
2563
2564 if (key) {
2565 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2566 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2567 key[j++] = (u8)(reg_val & 0xff);
2568 key[j++] = (u8)((reg_val >> 8) & 0xff);
2569 key[j++] = (u8)((reg_val >> 16) & 0xff);
2570 key[j++] = (u8)((reg_val >> 24) & 0xff);
2571 }
2572 }
2573 return 0;
2574}
2575
2576/**
2577 * i40e_set_rxfh - set the rx flow hash indirection table
2578 * @netdev: network interface device structure
2579 * @indir: indirection table
2580 * @key: hash key
2581 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002582 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002583 * returns 0 after programming the table.
2584 **/
2585static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2586 const u8 *key, const u8 hfunc)
2587{
2588 struct i40e_netdev_priv *np = netdev_priv(netdev);
2589 struct i40e_vsi *vsi = np->vsi;
2590 struct i40e_pf *pf = vsi->back;
2591 struct i40e_hw *hw = &pf->hw;
2592 u32 reg_val;
2593 int i, j;
2594
2595 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2596 return -EOPNOTSUPP;
2597
2598 if (!indir)
2599 return 0;
2600
2601 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2602 reg_val = indir[j++];
2603 reg_val |= indir[j++] << 8;
2604 reg_val |= indir[j++] << 16;
2605 reg_val |= indir[j++] << 24;
2606 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2607 }
2608
2609 if (key) {
2610 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2611 reg_val = key[j++];
2612 reg_val |= key[j++] << 8;
2613 reg_val |= key[j++] << 16;
2614 reg_val |= key[j++] << 24;
2615 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2616 }
2617 }
2618 return 0;
2619}
2620
Greg Rose7e45ab42015-02-06 08:52:19 +00002621/**
2622 * i40e_get_priv_flags - report device private flags
2623 * @dev: network interface device structure
2624 *
2625 * The get string set count and the string set should be matched for each
2626 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2627 * array.
2628 *
2629 * Returns a u32 bitmap of flags.
2630 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002631static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002632{
2633 struct i40e_netdev_priv *np = netdev_priv(dev);
2634 struct i40e_vsi *vsi = np->vsi;
2635 struct i40e_pf *pf = vsi->back;
2636 u32 ret_flags = 0;
2637
2638 ret_flags |= pf->hw.func_caps.npar_enable ?
2639 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002640 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2641 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002642
2643 return ret_flags;
2644}
2645
Shannon Nelson9ac77262015-08-27 11:42:40 -04002646/**
2647 * i40e_set_priv_flags - set private flags
2648 * @dev: network interface device structure
2649 * @flags: bit flags to be set
2650 **/
2651static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2652{
2653 struct i40e_netdev_priv *np = netdev_priv(dev);
2654 struct i40e_vsi *vsi = np->vsi;
2655 struct i40e_pf *pf = vsi->back;
2656
2657 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2658 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2659 else
2660 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2661
2662 return 0;
2663}
2664
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002665static const struct ethtool_ops i40e_ethtool_ops = {
2666 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002667 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002668 .get_drvinfo = i40e_get_drvinfo,
2669 .get_regs_len = i40e_get_regs_len,
2670 .get_regs = i40e_get_regs,
2671 .nway_reset = i40e_nway_reset,
2672 .get_link = ethtool_op_get_link,
2673 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002674 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002675 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002676 .get_eeprom_len = i40e_get_eeprom_len,
2677 .get_eeprom = i40e_get_eeprom,
2678 .get_ringparam = i40e_get_ringparam,
2679 .set_ringparam = i40e_set_ringparam,
2680 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002681 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002682 .get_msglevel = i40e_get_msglevel,
2683 .set_msglevel = i40e_set_msglevel,
2684 .get_rxnfc = i40e_get_rxnfc,
2685 .set_rxnfc = i40e_set_rxnfc,
2686 .self_test = i40e_diag_test,
2687 .get_strings = i40e_get_strings,
2688 .set_phys_id = i40e_set_phys_id,
2689 .get_sset_count = i40e_get_sset_count,
2690 .get_ethtool_stats = i40e_get_ethtool_stats,
2691 .get_coalesce = i40e_get_coalesce,
2692 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002693 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2694 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2695 .get_rxfh = i40e_get_rxfh,
2696 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002697 .get_channels = i40e_get_channels,
2698 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002699 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002700 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002701 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002702};
2703
2704void i40e_set_ethtool_ops(struct net_device *netdev)
2705{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002706 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002707}