blob: 46019e9c489e5b375d89843f730e42ddc2d562bc [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 Sullivan0a862b42015-08-31 19:54:53 -0400310 ecmd->supported = SUPPORTED_10000baseT_Full;
311 if (hw_link_info->module_type[2] &
312 I40E_MODULE_TYPE_1000BASE_SX ||
313 hw_link_info->module_type[2] &
314 I40E_MODULE_TYPE_1000BASE_LX) {
315 ecmd->supported |= SUPPORTED_1000baseT_Full;
316 if (hw_link_info->requested_speeds &
317 I40E_LINK_SPEED_1GB)
318 ecmd->advertising |= ADVERTISED_1000baseT_Full;
319 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000320 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
321 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000322 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000323 case I40E_PHY_TYPE_1000BASE_KX:
324 ecmd->supported = SUPPORTED_Autoneg |
325 SUPPORTED_1000baseKX_Full;
326 ecmd->advertising = ADVERTISED_Autoneg |
327 ADVERTISED_1000baseKX_Full;
328 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000329 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000330 case I40E_PHY_TYPE_1000BASE_T:
331 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000332 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000333 SUPPORTED_10000baseT_Full |
334 SUPPORTED_1000baseT_Full |
335 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000336 ecmd->advertising = ADVERTISED_Autoneg;
337 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
338 ecmd->advertising |= ADVERTISED_10000baseT_Full;
339 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
340 ecmd->advertising |= ADVERTISED_1000baseT_Full;
341 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
342 ecmd->advertising |= ADVERTISED_100baseT_Full;
343 break;
344 case I40E_PHY_TYPE_10GBASE_CR1_CU:
345 case I40E_PHY_TYPE_10GBASE_CR1:
346 ecmd->supported = SUPPORTED_Autoneg |
347 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000348 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000349 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000350 break;
351 case I40E_PHY_TYPE_XAUI:
352 case I40E_PHY_TYPE_XFI:
353 case I40E_PHY_TYPE_SFI:
354 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000355 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000356 ecmd->supported = SUPPORTED_10000baseT_Full;
357 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000358 case I40E_PHY_TYPE_SGMII:
359 ecmd->supported = SUPPORTED_Autoneg |
360 SUPPORTED_1000baseT_Full |
361 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000362 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
363 ecmd->advertising |= ADVERTISED_1000baseT_Full;
364 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
365 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000366 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000367 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000368 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000369 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
370 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000371 }
372
Catherine Sullivane8278452015-02-06 08:52:08 +0000373 /* Set speed and duplex */
374 switch (link_speed) {
375 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400376 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000377 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700378 case I40E_LINK_SPEED_20GB:
379 ethtool_cmd_speed_set(ecmd, SPEED_20000);
380 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000381 case I40E_LINK_SPEED_10GB:
382 ethtool_cmd_speed_set(ecmd, SPEED_10000);
383 break;
384 case I40E_LINK_SPEED_1GB:
385 ethtool_cmd_speed_set(ecmd, SPEED_1000);
386 break;
387 case I40E_LINK_SPEED_100MB:
388 ethtool_cmd_speed_set(ecmd, SPEED_100);
389 break;
390 default:
391 break;
392 }
393 ecmd->duplex = DUPLEX_FULL;
394}
395
396/**
397 * i40e_get_settings_link_down - Get the Link settings for when link is down
398 * @hw: hw structure
399 * @ecmd: ethtool command to fill in
400 *
401 * Reports link settings that can be determined when link is down
402 **/
403static void i40e_get_settings_link_down(struct i40e_hw *hw,
404 struct ethtool_cmd *ecmd)
405{
406 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
407
408 /* link is down and the driver needs to fall back on
409 * device ID to determine what kinds of info to display,
410 * it's mostly a guess that may change when link is up
411 */
412 switch (hw->device_id) {
413 case I40E_DEV_ID_QSFP_A:
414 case I40E_DEV_ID_QSFP_B:
415 case I40E_DEV_ID_QSFP_C:
416 /* pluggable QSFP */
417 ecmd->supported = SUPPORTED_40000baseSR4_Full |
418 SUPPORTED_40000baseCR4_Full |
419 SUPPORTED_40000baseLR4_Full;
420 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
421 ADVERTISED_40000baseCR4_Full |
422 ADVERTISED_40000baseLR4_Full;
423 break;
424 case I40E_DEV_ID_KX_B:
425 /* backplane 40G */
426 ecmd->supported = SUPPORTED_40000baseKR4_Full;
427 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
428 break;
429 case I40E_DEV_ID_KX_C:
430 /* backplane 10G */
431 ecmd->supported = SUPPORTED_10000baseKR_Full;
432 ecmd->advertising = ADVERTISED_10000baseKR_Full;
433 break;
434 case I40E_DEV_ID_10G_BASE_T:
Shannon Nelsonbc5166b92015-08-26 15:14:10 -0400435 case I40E_DEV_ID_10G_BASE_T4:
Catherine Sullivane8278452015-02-06 08:52:08 +0000436 ecmd->supported = SUPPORTED_10000baseT_Full |
437 SUPPORTED_1000baseT_Full |
438 SUPPORTED_100baseT_Full;
439 /* Figure out what has been requested */
440 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
441 ecmd->advertising |= ADVERTISED_10000baseT_Full;
442 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
443 ecmd->advertising |= ADVERTISED_1000baseT_Full;
444 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
445 ecmd->advertising |= ADVERTISED_100baseT_Full;
446 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700447 case I40E_DEV_ID_20G_KR2:
Shannon Nelson48a3b512015-07-23 16:54:39 -0400448 case I40E_DEV_ID_20G_KR2_A:
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700449 /* backplane 20G */
450 ecmd->supported = SUPPORTED_20000baseKR2_Full;
451 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
452 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000453 default:
454 /* all the rest are 10G/1G */
455 ecmd->supported = SUPPORTED_10000baseT_Full |
456 SUPPORTED_1000baseT_Full;
457 /* Figure out what has been requested */
458 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
459 ecmd->advertising |= ADVERTISED_10000baseT_Full;
460 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
461 ecmd->advertising |= ADVERTISED_1000baseT_Full;
462 break;
463 }
464
465 /* With no link speed and duplex are unknown */
466 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
467 ecmd->duplex = DUPLEX_UNKNOWN;
468}
469
470/**
471 * i40e_get_settings - Get Link Speed and Duplex settings
472 * @netdev: network interface device structure
473 * @ecmd: ethtool command
474 *
475 * Reports speed/duplex settings based on media_type
476 **/
477static int i40e_get_settings(struct net_device *netdev,
478 struct ethtool_cmd *ecmd)
479{
480 struct i40e_netdev_priv *np = netdev_priv(netdev);
481 struct i40e_pf *pf = np->vsi->back;
482 struct i40e_hw *hw = &pf->hw;
483 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
484 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
485
486 if (link_up)
487 i40e_get_settings_link_up(hw, ecmd, netdev);
488 else
489 i40e_get_settings_link_down(hw, ecmd);
490
491 /* Now set the settings that don't rely on link being up/down */
492
493 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000494 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
495 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000496
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000497 switch (hw->phy.media_type) {
498 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000499 ecmd->supported |= SUPPORTED_Autoneg |
500 SUPPORTED_Backplane;
501 ecmd->advertising |= ADVERTISED_Autoneg |
502 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000503 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000504 break;
505 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000506 ecmd->supported |= SUPPORTED_TP;
507 ecmd->advertising |= ADVERTISED_TP;
508 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000509 break;
510 case I40E_MEDIA_TYPE_DA:
511 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000512 ecmd->supported |= SUPPORTED_FIBRE;
513 ecmd->advertising |= ADVERTISED_FIBRE;
514 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000515 break;
516 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000517 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000518 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000519 break;
520 case I40E_MEDIA_TYPE_UNKNOWN:
521 default:
522 ecmd->port = PORT_OTHER;
523 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000524 }
525
Catherine Sullivane8278452015-02-06 08:52:08 +0000526 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000527 ecmd->transceiver = XCVR_EXTERNAL;
528
Catherine Sullivane8278452015-02-06 08:52:08 +0000529 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000530 ecmd->supported |= SUPPORTED_Pause;
531
Catherine Sullivane8278452015-02-06 08:52:08 +0000532 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000533 case I40E_FC_FULL:
534 ecmd->advertising |= ADVERTISED_Pause;
535 break;
536 case I40E_FC_TX_PAUSE:
537 ecmd->advertising |= ADVERTISED_Asym_Pause;
538 break;
539 case I40E_FC_RX_PAUSE:
540 ecmd->advertising |= (ADVERTISED_Pause |
541 ADVERTISED_Asym_Pause);
542 break;
543 default:
544 ecmd->advertising &= ~(ADVERTISED_Pause |
545 ADVERTISED_Asym_Pause);
546 break;
547 }
548
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000549 return 0;
550}
551
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000552/**
553 * i40e_set_settings - Set Speed and Duplex
554 * @netdev: network interface device structure
555 * @ecmd: ethtool command
556 *
557 * Set speed/duplex per media_types advertised/forced
558 **/
559static int i40e_set_settings(struct net_device *netdev,
560 struct ethtool_cmd *ecmd)
561{
562 struct i40e_netdev_priv *np = netdev_priv(netdev);
563 struct i40e_aq_get_phy_abilities_resp abilities;
564 struct i40e_aq_set_phy_config config;
565 struct i40e_pf *pf = np->vsi->back;
566 struct i40e_vsi *vsi = np->vsi;
567 struct i40e_hw *hw = &pf->hw;
568 struct ethtool_cmd safe_ecmd;
569 i40e_status status = 0;
570 bool change = false;
571 int err = 0;
572 u8 autoneg;
573 u32 advertise;
574
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000575 /* Changing port settings is not supported if this isn't the
576 * port's controlling PF
577 */
578 if (hw->partition_id != 1) {
579 i40e_partition_setting_complaint(pf);
580 return -EOPNOTSUPP;
581 }
582
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000583 if (vsi != pf->vsi[pf->lan_vsi])
584 return -EOPNOTSUPP;
585
586 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
587 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000588 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
589 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000590 return -EOPNOTSUPP;
591
592 /* get our own copy of the bits to check against */
593 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
594 i40e_get_settings(netdev, &safe_ecmd);
595
596 /* save autoneg and speed out of ecmd */
597 autoneg = ecmd->autoneg;
598 advertise = ecmd->advertising;
599
600 /* set autoneg and speed back to what they currently are */
601 ecmd->autoneg = safe_ecmd.autoneg;
602 ecmd->advertising = safe_ecmd.advertising;
603
604 ecmd->cmd = safe_ecmd.cmd;
605 /* If ecmd and safe_ecmd are not the same now, then they are
606 * trying to set something that we do not support
607 */
608 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
609 return -EOPNOTSUPP;
610
611 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
612 usleep_range(1000, 2000);
613
614 /* Get the current phy config */
615 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
616 NULL);
617 if (status)
618 return -EAGAIN;
619
Catherine Sullivan124ed152014-07-12 07:28:12 +0000620 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000621 * set below
622 */
623 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000624 config.abilities = abilities.abilities;
625
626 /* Check autoneg */
627 if (autoneg == AUTONEG_ENABLE) {
628 /* If autoneg is not supported, return error */
629 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
630 netdev_info(netdev, "Autoneg not supported on this phy\n");
631 return -EINVAL;
632 }
633 /* If autoneg was not already enabled */
634 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
635 config.abilities = abilities.abilities |
636 I40E_AQ_PHY_ENABLE_AN;
637 change = true;
638 }
639 } else {
640 /* If autoneg is supported 10GBASE_T is the only phy that
641 * can disable it, so otherwise return error
642 */
643 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
644 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
645 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
646 return -EINVAL;
647 }
648 /* If autoneg is currently enabled */
649 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000650 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000651 ~I40E_AQ_PHY_ENABLE_AN;
652 change = true;
653 }
654 }
655
656 if (advertise & ~safe_ecmd.supported)
657 return -EINVAL;
658
659 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000660 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000661 if (advertise & ADVERTISED_1000baseT_Full ||
662 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000663 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000664 if (advertise & ADVERTISED_10000baseT_Full ||
665 advertise & ADVERTISED_10000baseKX4_Full ||
666 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000667 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700668 if (advertise & ADVERTISED_20000baseKR2_Full)
669 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000670 if (advertise & ADVERTISED_40000baseKR4_Full ||
671 advertise & ADVERTISED_40000baseCR4_Full ||
672 advertise & ADVERTISED_40000baseSR4_Full ||
673 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000674 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000675
Catherine Sullivan0002e112015-08-26 15:14:16 -0400676 /* If speed didn't get set, set it to what it currently is.
677 * This is needed because if advertise is 0 (as it is when autoneg
678 * is disabled) then speed won't get set.
679 */
680 if (!config.link_speed)
681 config.link_speed = abilities.link_speed;
682
Catherine Sullivan124ed152014-07-12 07:28:12 +0000683 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000684 /* copy over the rest of the abilities */
685 config.phy_type = abilities.phy_type;
686 config.eee_capability = abilities.eee_capability;
687 config.eeer = abilities.eeer_val;
688 config.low_power_ctrl = abilities.d3_lpan;
689
Catherine Sullivane8278452015-02-06 08:52:08 +0000690 /* save the requested speeds */
691 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000692 /* set link and auto negotiation so changes take effect */
693 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
694 /* If link is up put link down */
695 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
696 /* Tell the OS link is going down, the link will go
697 * back up when fw says it is ready asynchronously
698 */
Matt Jaredc156f852015-08-27 11:42:39 -0400699 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000700 netif_carrier_off(netdev);
701 netif_tx_stop_all_queues(netdev);
702 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000703
704 /* make the aq call */
705 status = i40e_aq_set_phy_config(hw, &config, NULL);
706 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400707 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
708 i40e_stat_str(hw, status),
709 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000710 return -EAGAIN;
711 }
712
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400713 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000714 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400715 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
716 i40e_stat_str(hw, status),
717 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000718
719 } else {
720 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
721 }
722
723 return err;
724}
725
Jesse Brandeburga6599722014-06-04 08:45:25 +0000726static int i40e_nway_reset(struct net_device *netdev)
727{
728 /* restart autonegotiation */
729 struct i40e_netdev_priv *np = netdev_priv(netdev);
730 struct i40e_pf *pf = np->vsi->back;
731 struct i40e_hw *hw = &pf->hw;
732 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
733 i40e_status ret = 0;
734
735 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
736 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400737 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
738 i40e_stat_str(hw, ret),
739 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000740 return -EIO;
741 }
742
743 return 0;
744}
745
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000746/**
747 * i40e_get_pauseparam - Get Flow Control status
748 * Return tx/rx-pause status
749 **/
750static void i40e_get_pauseparam(struct net_device *netdev,
751 struct ethtool_pauseparam *pause)
752{
753 struct i40e_netdev_priv *np = netdev_priv(netdev);
754 struct i40e_pf *pf = np->vsi->back;
755 struct i40e_hw *hw = &pf->hw;
756 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000757 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000758
759 pause->autoneg =
760 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
761 AUTONEG_ENABLE : AUTONEG_DISABLE);
762
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000763 /* PFC enabled so report LFC as off */
764 if (dcbx_cfg->pfc.pfcenable) {
765 pause->rx_pause = 0;
766 pause->tx_pause = 0;
767 return;
768 }
769
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000770 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000771 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000772 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000773 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000774 } else if (hw->fc.current_mode == I40E_FC_FULL) {
775 pause->rx_pause = 1;
776 pause->tx_pause = 1;
777 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000778}
779
Catherine Sullivan2becc352014-06-04 08:45:27 +0000780/**
781 * i40e_set_pauseparam - Set Flow Control parameter
782 * @netdev: network interface device structure
783 * @pause: return tx/rx flow control status
784 **/
785static int i40e_set_pauseparam(struct net_device *netdev,
786 struct ethtool_pauseparam *pause)
787{
788 struct i40e_netdev_priv *np = netdev_priv(netdev);
789 struct i40e_pf *pf = np->vsi->back;
790 struct i40e_vsi *vsi = np->vsi;
791 struct i40e_hw *hw = &pf->hw;
792 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000793 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000794 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
795 i40e_status status;
796 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000797 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000798
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000799 /* Changing the port's flow control is not supported if this isn't the
800 * port's controlling PF
801 */
802 if (hw->partition_id != 1) {
803 i40e_partition_setting_complaint(pf);
804 return -EOPNOTSUPP;
805 }
806
Catherine Sullivan2becc352014-06-04 08:45:27 +0000807 if (vsi != pf->vsi[pf->lan_vsi])
808 return -EOPNOTSUPP;
809
810 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
811 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
812 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
813 return -EOPNOTSUPP;
814 }
815
816 /* If we have link and don't have autoneg */
817 if (!test_bit(__I40E_DOWN, &pf->state) &&
818 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
819 /* Send message that it might not necessarily work*/
820 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
821 }
822
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000823 if (dcbx_cfg->pfc.pfcenable) {
824 netdev_info(netdev,
825 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000826 return -EOPNOTSUPP;
827 }
828
829 if (pause->rx_pause && pause->tx_pause)
830 hw->fc.requested_mode = I40E_FC_FULL;
831 else if (pause->rx_pause && !pause->tx_pause)
832 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
833 else if (!pause->rx_pause && pause->tx_pause)
834 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
835 else if (!pause->rx_pause && !pause->tx_pause)
836 hw->fc.requested_mode = I40E_FC_NONE;
837 else
838 return -EINVAL;
839
Catherine Sullivan94128512014-07-12 07:28:16 +0000840 /* Tell the OS link is going down, the link will go back up when fw
841 * says it is ready asynchronously
842 */
Matt Jaredc156f852015-08-27 11:42:39 -0400843 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000844 netif_carrier_off(netdev);
845 netif_tx_stop_all_queues(netdev);
846
Catherine Sullivan2becc352014-06-04 08:45:27 +0000847 /* Set the fc mode and only restart an if link is up*/
848 status = i40e_set_fc(hw, &aq_failures, link_up);
849
850 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400851 netdev_info(netdev, "Set fc failed on the get_phy_capabilities 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_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400857 netdev_info(netdev, "Set fc failed on the set_phy_config 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 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400863 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
864 i40e_stat_str(hw, status),
865 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000866 err = -EAGAIN;
867 }
868
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000869 if (!test_bit(__I40E_DOWN, &pf->state)) {
870 /* Give it a little more time to try to come back */
871 msleep(75);
872 if (!test_bit(__I40E_DOWN, &pf->state))
873 return i40e_nway_reset(netdev);
874 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000875
876 return err;
877}
878
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000879static u32 i40e_get_msglevel(struct net_device *netdev)
880{
881 struct i40e_netdev_priv *np = netdev_priv(netdev);
882 struct i40e_pf *pf = np->vsi->back;
883
884 return pf->msg_enable;
885}
886
887static void i40e_set_msglevel(struct net_device *netdev, u32 data)
888{
889 struct i40e_netdev_priv *np = netdev_priv(netdev);
890 struct i40e_pf *pf = np->vsi->back;
891
892 if (I40E_DEBUG_USER & data)
893 pf->hw.debug_mask = data;
894 pf->msg_enable = data;
895}
896
897static int i40e_get_regs_len(struct net_device *netdev)
898{
899 int reg_count = 0;
900 int i;
901
902 for (i = 0; i40e_reg_list[i].offset != 0; i++)
903 reg_count += i40e_reg_list[i].elements;
904
905 return reg_count * sizeof(u32);
906}
907
908static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
909 void *p)
910{
911 struct i40e_netdev_priv *np = netdev_priv(netdev);
912 struct i40e_pf *pf = np->vsi->back;
913 struct i40e_hw *hw = &pf->hw;
914 u32 *reg_buf = p;
915 int i, j, ri;
916 u32 reg;
917
918 /* Tell ethtool which driver-version-specific regs output we have.
919 *
920 * At some point, if we have ethtool doing special formatting of
921 * this data, it will rely on this version number to know how to
922 * interpret things. Hence, this needs to be updated if/when the
923 * diags register table is changed.
924 */
925 regs->version = 1;
926
927 /* loop through the diags reg table for what to print */
928 ri = 0;
929 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
930 for (j = 0; j < i40e_reg_list[i].elements; j++) {
931 reg = i40e_reg_list[i].offset
932 + (j * i40e_reg_list[i].stride);
933 reg_buf[ri++] = rd32(hw, reg);
934 }
935 }
936
937}
938
939static int i40e_get_eeprom(struct net_device *netdev,
940 struct ethtool_eeprom *eeprom, u8 *bytes)
941{
942 struct i40e_netdev_priv *np = netdev_priv(netdev);
943 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000944 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000945 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000946 u8 *eeprom_buff;
947 u16 i, sectors;
948 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000949 u32 magic;
950
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000951#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000952 if (eeprom->len == 0)
953 return -EINVAL;
954
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000955 /* check for NVMUpdate access method */
956 magic = hw->vendor_id | (hw->device_id << 16);
957 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000958 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000959 int errno;
960
961 /* make sure it is the right magic for NVMUpdate */
962 if ((eeprom->magic >> 16) != hw->device_id)
963 return -EINVAL;
964
Shannon Nelsonc150a502014-11-13 08:23:13 +0000965 cmd = (struct i40e_nvm_access *)eeprom;
966 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000967 if (ret_val &&
968 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
969 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000970 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000971 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
972 ret_val, hw->aq.asq_last_status, errno,
973 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
974 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000975
976 return errno;
977 }
978
979 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000980 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
981
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000982 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000983 if (!eeprom_buff)
984 return -ENOMEM;
985
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000986 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
987 if (ret_val) {
988 dev_info(&pf->pdev->dev,
989 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
990 ret_val, hw->aq.asq_last_status);
991 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000992 }
993
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000994 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
995 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
996 len = I40E_NVM_SECTOR_SIZE;
997 last = false;
998 for (i = 0; i < sectors; i++) {
999 if (i == (sectors - 1)) {
1000 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1001 last = true;
1002 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001003 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1004 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001005 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001006 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001007 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001008 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001009 "read NVM failed, invalid offset 0x%x\n",
1010 offset);
1011 break;
1012 } else if (ret_val &&
1013 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1014 dev_info(&pf->pdev->dev,
1015 "read NVM failed, access, offset 0x%x\n",
1016 offset);
1017 break;
1018 } else if (ret_val) {
1019 dev_info(&pf->pdev->dev,
1020 "read NVM failed offset %d err=%d status=0x%x\n",
1021 offset, ret_val, hw->aq.asq_last_status);
1022 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001023 }
1024 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001025
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001026 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001027 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001028free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001029 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001030 return ret_val;
1031}
1032
1033static int i40e_get_eeprom_len(struct net_device *netdev)
1034{
1035 struct i40e_netdev_priv *np = netdev_priv(netdev);
1036 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001037 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001038
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001039 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1040 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1041 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1042 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001043 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001044 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001045}
1046
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001047static int i40e_set_eeprom(struct net_device *netdev,
1048 struct ethtool_eeprom *eeprom, u8 *bytes)
1049{
1050 struct i40e_netdev_priv *np = netdev_priv(netdev);
1051 struct i40e_hw *hw = &np->vsi->back->hw;
1052 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001053 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001054 int ret_val = 0;
1055 int errno;
1056 u32 magic;
1057
1058 /* normal ethtool set_eeprom is not supported */
1059 magic = hw->vendor_id | (hw->device_id << 16);
1060 if (eeprom->magic == magic)
1061 return -EOPNOTSUPP;
1062
1063 /* check for NVMUpdate access method */
1064 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1065 return -EINVAL;
1066
1067 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1068 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1069 return -EBUSY;
1070
Shannon Nelsonc150a502014-11-13 08:23:13 +00001071 cmd = (struct i40e_nvm_access *)eeprom;
1072 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001073 if (ret_val &&
1074 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1075 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1076 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001077 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001078 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1079 ret_val, hw->aq.asq_last_status, errno,
1080 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1081 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001082
1083 return errno;
1084}
1085
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001086static void i40e_get_drvinfo(struct net_device *netdev,
1087 struct ethtool_drvinfo *drvinfo)
1088{
1089 struct i40e_netdev_priv *np = netdev_priv(netdev);
1090 struct i40e_vsi *vsi = np->vsi;
1091 struct i40e_pf *pf = vsi->back;
1092
1093 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1094 strlcpy(drvinfo->version, i40e_driver_version_str,
1095 sizeof(drvinfo->version));
1096 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1097 sizeof(drvinfo->fw_version));
1098 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1099 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001100 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001101}
1102
1103static void i40e_get_ringparam(struct net_device *netdev,
1104 struct ethtool_ringparam *ring)
1105{
1106 struct i40e_netdev_priv *np = netdev_priv(netdev);
1107 struct i40e_pf *pf = np->vsi->back;
1108 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1109
1110 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1111 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1112 ring->rx_mini_max_pending = 0;
1113 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001114 ring->rx_pending = vsi->rx_rings[0]->count;
1115 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001116 ring->rx_mini_pending = 0;
1117 ring->rx_jumbo_pending = 0;
1118}
1119
1120static int i40e_set_ringparam(struct net_device *netdev,
1121 struct ethtool_ringparam *ring)
1122{
1123 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1124 struct i40e_netdev_priv *np = netdev_priv(netdev);
1125 struct i40e_vsi *vsi = np->vsi;
1126 struct i40e_pf *pf = vsi->back;
1127 u32 new_rx_count, new_tx_count;
1128 int i, err = 0;
1129
1130 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1131 return -EINVAL;
1132
Shannon Nelson1fa18372013-11-20 10:03:08 +00001133 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1134 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1135 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1136 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1137 netdev_info(netdev,
1138 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1139 ring->tx_pending, ring->rx_pending,
1140 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1141 return -EINVAL;
1142 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001143
Shannon Nelson1fa18372013-11-20 10:03:08 +00001144 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1145 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001146
1147 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001148 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1149 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001150 return 0;
1151
1152 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1153 usleep_range(1000, 2000);
1154
1155 if (!netif_running(vsi->netdev)) {
1156 /* simple case - set for the next time the netdev is started */
1157 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001158 vsi->tx_rings[i]->count = new_tx_count;
1159 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001160 }
1161 goto done;
1162 }
1163
1164 /* We can't just free everything and then setup again,
1165 * because the ISRs in MSI-X mode get passed pointers
1166 * to the Tx and Rx ring structs.
1167 */
1168
1169 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001170 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001171 netdev_info(netdev,
1172 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001173 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001174 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1175 sizeof(struct i40e_ring), GFP_KERNEL);
1176 if (!tx_rings) {
1177 err = -ENOMEM;
1178 goto done;
1179 }
1180
1181 for (i = 0; i < vsi->num_queue_pairs; i++) {
1182 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001183 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001184 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001185 /* the desc and bi pointers will be reallocated in the
1186 * setup call
1187 */
1188 tx_rings[i].desc = NULL;
1189 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001190 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1191 if (err) {
1192 while (i) {
1193 i--;
1194 i40e_free_tx_resources(&tx_rings[i]);
1195 }
1196 kfree(tx_rings);
1197 tx_rings = NULL;
1198
1199 goto done;
1200 }
1201 }
1202 }
1203
1204 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001205 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001206 netdev_info(netdev,
1207 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001208 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001209 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1210 sizeof(struct i40e_ring), GFP_KERNEL);
1211 if (!rx_rings) {
1212 err = -ENOMEM;
1213 goto free_tx;
1214 }
1215
1216 for (i = 0; i < vsi->num_queue_pairs; i++) {
1217 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001218 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001219 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001220 /* the desc and bi pointers will be reallocated in the
1221 * setup call
1222 */
1223 rx_rings[i].desc = NULL;
1224 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001225 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1226 if (err) {
1227 while (i) {
1228 i--;
1229 i40e_free_rx_resources(&rx_rings[i]);
1230 }
1231 kfree(rx_rings);
1232 rx_rings = NULL;
1233
1234 goto free_tx;
1235 }
1236 }
1237 }
1238
1239 /* Bring interface down, copy in the new ring info,
1240 * then restore the interface
1241 */
1242 i40e_down(vsi);
1243
1244 if (tx_rings) {
1245 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001246 i40e_free_tx_resources(vsi->tx_rings[i]);
1247 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248 }
1249 kfree(tx_rings);
1250 tx_rings = NULL;
1251 }
1252
1253 if (rx_rings) {
1254 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001255 i40e_free_rx_resources(vsi->rx_rings[i]);
1256 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001257 }
1258 kfree(rx_rings);
1259 rx_rings = NULL;
1260 }
1261
1262 i40e_up(vsi);
1263
1264free_tx:
1265 /* error cleanup if the Rx allocations failed after getting Tx */
1266 if (tx_rings) {
1267 for (i = 0; i < vsi->num_queue_pairs; i++)
1268 i40e_free_tx_resources(&tx_rings[i]);
1269 kfree(tx_rings);
1270 tx_rings = NULL;
1271 }
1272
1273done:
1274 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1275
1276 return err;
1277}
1278
1279static int i40e_get_sset_count(struct net_device *netdev, int sset)
1280{
1281 struct i40e_netdev_priv *np = netdev_priv(netdev);
1282 struct i40e_vsi *vsi = np->vsi;
1283 struct i40e_pf *pf = vsi->back;
1284
1285 switch (sset) {
1286 case ETH_SS_TEST:
1287 return I40E_TEST_LEN;
1288 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001289 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001290 int len = I40E_PF_STATS_LEN(netdev);
1291
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001292 if ((pf->lan_veb != I40E_NO_VEB) &&
1293 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001294 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001295 return len;
1296 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001297 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001298 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001299 case ETH_SS_PRIV_FLAGS:
1300 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301 default:
1302 return -EOPNOTSUPP;
1303 }
1304}
1305
1306static void i40e_get_ethtool_stats(struct net_device *netdev,
1307 struct ethtool_stats *stats, u64 *data)
1308{
1309 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001310 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001311 struct i40e_vsi *vsi = np->vsi;
1312 struct i40e_pf *pf = vsi->back;
1313 int i = 0;
1314 char *p;
1315 int j;
1316 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001317 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001318
1319 i40e_update_stats(vsi);
1320
1321 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1322 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1323 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1324 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1325 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001326 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1327 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1328 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1329 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1330 }
Vasu Dev38e00432014-08-01 13:27:03 -07001331#ifdef I40E_FCOE
1332 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1333 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1334 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1335 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1336 }
1337#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001338 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001339 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001340 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001341
1342 if (!tx_ring)
1343 continue;
1344
1345 /* process Tx ring statistics */
1346 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001347 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001348 data[i] = tx_ring->stats.packets;
1349 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001350 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001351 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001352
1353 /* Rx ring is the 2nd half of the queue pair */
1354 rx_ring = &tx_ring[1];
1355 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001356 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001357 data[i] = rx_ring->stats.packets;
1358 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001359 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001360 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001362 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001363 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001364 return;
1365
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001366 if ((pf->lan_veb != I40E_NO_VEB) &&
1367 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001368 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001369
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001370 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1371 p = (char *)veb;
1372 p += i40e_gstrings_veb_stats[j].stat_offset;
1373 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1374 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001375 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001376 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001377 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1378 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1379 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1380 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1381 }
1382 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1383 data[i++] = pf->stats.priority_xon_tx[j];
1384 data[i++] = pf->stats.priority_xoff_tx[j];
1385 }
1386 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1387 data[i++] = pf->stats.priority_xon_rx[j];
1388 data[i++] = pf->stats.priority_xoff_rx[j];
1389 }
1390 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1391 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392}
1393
1394static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1395 u8 *data)
1396{
1397 struct i40e_netdev_priv *np = netdev_priv(netdev);
1398 struct i40e_vsi *vsi = np->vsi;
1399 struct i40e_pf *pf = vsi->back;
1400 char *p = (char *)data;
1401 int i;
1402
1403 switch (stringset) {
1404 case ETH_SS_TEST:
1405 for (i = 0; i < I40E_TEST_LEN; i++) {
1406 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1407 data += ETH_GSTRING_LEN;
1408 }
1409 break;
1410 case ETH_SS_STATS:
1411 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1412 snprintf(p, ETH_GSTRING_LEN, "%s",
1413 i40e_gstrings_net_stats[i].stat_string);
1414 p += ETH_GSTRING_LEN;
1415 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001416 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1417 snprintf(p, ETH_GSTRING_LEN, "%s",
1418 i40e_gstrings_misc_stats[i].stat_string);
1419 p += ETH_GSTRING_LEN;
1420 }
Vasu Dev38e00432014-08-01 13:27:03 -07001421#ifdef I40E_FCOE
1422 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1423 snprintf(p, ETH_GSTRING_LEN, "%s",
1424 i40e_gstrings_fcoe_stats[i].stat_string);
1425 p += ETH_GSTRING_LEN;
1426 }
1427#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001428 for (i = 0; i < vsi->num_queue_pairs; i++) {
1429 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1430 p += ETH_GSTRING_LEN;
1431 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1432 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001433 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1434 p += ETH_GSTRING_LEN;
1435 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1436 p += ETH_GSTRING_LEN;
1437 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001438 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001439 return;
1440
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001441 if ((pf->lan_veb != I40E_NO_VEB) &&
1442 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001443 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1444 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1445 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001446 p += ETH_GSTRING_LEN;
1447 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001448 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1449 snprintf(p, ETH_GSTRING_LEN,
1450 "veb.tc_%u_tx_packets", i);
1451 p += ETH_GSTRING_LEN;
1452 snprintf(p, ETH_GSTRING_LEN,
1453 "veb.tc_%u_tx_bytes", i);
1454 p += ETH_GSTRING_LEN;
1455 snprintf(p, ETH_GSTRING_LEN,
1456 "veb.tc_%u_rx_packets", i);
1457 p += ETH_GSTRING_LEN;
1458 snprintf(p, ETH_GSTRING_LEN,
1459 "veb.tc_%u_rx_bytes", i);
1460 p += ETH_GSTRING_LEN;
1461 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001462 }
1463 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1464 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1465 i40e_gstrings_stats[i].stat_string);
1466 p += ETH_GSTRING_LEN;
1467 }
1468 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1469 snprintf(p, ETH_GSTRING_LEN,
1470 "port.tx_priority_%u_xon", i);
1471 p += ETH_GSTRING_LEN;
1472 snprintf(p, ETH_GSTRING_LEN,
1473 "port.tx_priority_%u_xoff", i);
1474 p += ETH_GSTRING_LEN;
1475 }
1476 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1477 snprintf(p, ETH_GSTRING_LEN,
1478 "port.rx_priority_%u_xon", i);
1479 p += ETH_GSTRING_LEN;
1480 snprintf(p, ETH_GSTRING_LEN,
1481 "port.rx_priority_%u_xoff", i);
1482 p += ETH_GSTRING_LEN;
1483 }
1484 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1485 snprintf(p, ETH_GSTRING_LEN,
1486 "port.rx_priority_%u_xon_2_xoff", i);
1487 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001488 }
1489 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1490 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001491 case ETH_SS_PRIV_FLAGS:
1492 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1493 memcpy(data, i40e_priv_flags_strings[i],
1494 ETH_GSTRING_LEN);
1495 data += ETH_GSTRING_LEN;
1496 }
1497 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001498 default:
1499 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500 }
1501}
1502
1503static int i40e_get_ts_info(struct net_device *dev,
1504 struct ethtool_ts_info *info)
1505{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001506 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1507
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001508 /* only report HW timestamping if PTP is enabled */
1509 if (!(pf->flags & I40E_FLAG_PTP))
1510 return ethtool_op_get_ts_info(dev, info);
1511
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001512 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1513 SOF_TIMESTAMPING_RX_SOFTWARE |
1514 SOF_TIMESTAMPING_SOFTWARE |
1515 SOF_TIMESTAMPING_TX_HARDWARE |
1516 SOF_TIMESTAMPING_RX_HARDWARE |
1517 SOF_TIMESTAMPING_RAW_HARDWARE;
1518
1519 if (pf->ptp_clock)
1520 info->phc_index = ptp_clock_index(pf->ptp_clock);
1521 else
1522 info->phc_index = -1;
1523
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001524 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001525
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001526 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1527 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1528 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001529
1530 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001531}
1532
Shannon Nelson7b086392013-11-20 10:02:59 +00001533static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534{
Shannon Nelson7b086392013-11-20 10:02:59 +00001535 struct i40e_netdev_priv *np = netdev_priv(netdev);
1536 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001537 i40e_status status;
1538 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001539
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001540 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001541 status = i40e_get_link_status(&pf->hw, &link_up);
1542 if (status) {
1543 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1544 *data = 1;
1545 return *data;
1546 }
1547
1548 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001549 *data = 0;
1550 else
1551 *data = 1;
1552
1553 return *data;
1554}
1555
Shannon Nelson7b086392013-11-20 10:02:59 +00001556static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557{
Shannon Nelson7b086392013-11-20 10:02:59 +00001558 struct i40e_netdev_priv *np = netdev_priv(netdev);
1559 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001560
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001561 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001562 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563
Shannon Nelson7b086392013-11-20 10:02:59 +00001564 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001565}
1566
Shannon Nelson7b086392013-11-20 10:02:59 +00001567static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568{
Shannon Nelson7b086392013-11-20 10:02:59 +00001569 struct i40e_netdev_priv *np = netdev_priv(netdev);
1570 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001572 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001573 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001574
Shannon Nelson4443ec92014-11-13 08:23:12 +00001575 /* forcebly clear the NVM Update state machine */
1576 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1577
Shannon Nelson7b086392013-11-20 10:02:59 +00001578 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001579}
1580
Shannon Nelson7b086392013-11-20 10:02:59 +00001581static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001582{
Shannon Nelson7b086392013-11-20 10:02:59 +00001583 struct i40e_netdev_priv *np = netdev_priv(netdev);
1584 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001585 u16 swc_old = pf->sw_int_count;
1586
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001587 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001588 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1589 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001590 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1591 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1592 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1593 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001594 usleep_range(1000, 2000);
1595 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596
1597 return *data;
1598}
1599
Shannon Nelson7b086392013-11-20 10:02:59 +00001600static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001601{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001602 struct i40e_netdev_priv *np = netdev_priv(netdev);
1603 struct i40e_pf *pf = np->vsi->back;
1604
1605 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001606 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001607
1608 return *data;
1609}
1610
Greg Rosee17bc412015-04-16 20:05:59 -04001611static inline bool i40e_active_vfs(struct i40e_pf *pf)
1612{
1613 struct i40e_vf *vfs = pf->vf;
1614 int i;
1615
1616 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001617 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001618 return true;
1619 return false;
1620}
1621
Greg Rose510efb22015-07-10 19:36:01 -04001622static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1623{
1624 struct i40e_vsi **vsi = pf->vsi;
1625 int i;
1626
1627 for (i = 0; i < pf->num_alloc_vsi; i++) {
1628 if (!vsi[i])
1629 continue;
1630 if (vsi[i]->type == I40E_VSI_VMDQ2)
1631 return true;
1632 }
1633
1634 return false;
1635}
1636
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001637static void i40e_diag_test(struct net_device *netdev,
1638 struct ethtool_test *eth_test, u64 *data)
1639{
1640 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001641 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001642 struct i40e_pf *pf = np->vsi->back;
1643
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001644 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1645 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001646 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001647
Shannon Nelsonf551b432013-11-26 10:49:12 +00001648 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001649
Greg Rose510efb22015-07-10 19:36:01 -04001650 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001651 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001652 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001653 data[I40E_ETH_TEST_REG] = 1;
1654 data[I40E_ETH_TEST_EEPROM] = 1;
1655 data[I40E_ETH_TEST_INTR] = 1;
1656 data[I40E_ETH_TEST_LOOPBACK] = 1;
1657 data[I40E_ETH_TEST_LINK] = 1;
1658 eth_test->flags |= ETH_TEST_FL_FAILED;
1659 clear_bit(__I40E_TESTING, &pf->state);
1660 goto skip_ol_tests;
1661 }
1662
Greg Rose5b86c5c2015-02-26 16:14:35 +00001663 /* If the device is online then take it offline */
1664 if (if_running)
1665 /* indicate we're in test mode */
1666 dev_close(netdev);
1667 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001668 /* This reset does not affect link - if it is
1669 * changed to a type of reset that does affect
1670 * link then the following link test would have
1671 * to be moved to before the reset
1672 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001673 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001674
Shannon Nelson7b086392013-11-20 10:02:59 +00001675 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
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_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001679 eth_test->flags |= ETH_TEST_FL_FAILED;
1680
Shannon Nelson7b086392013-11-20 10:02:59 +00001681 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001682 eth_test->flags |= ETH_TEST_FL_FAILED;
1683
Shannon Nelson7b086392013-11-20 10:02:59 +00001684 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001685 eth_test->flags |= ETH_TEST_FL_FAILED;
1686
Shannon Nelsonf551b432013-11-26 10:49:12 +00001687 /* run reg test last, a reset is required after it */
1688 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1689 eth_test->flags |= ETH_TEST_FL_FAILED;
1690
1691 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001692 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001693
1694 if (if_running)
1695 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001696 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001698 netif_info(pf, drv, netdev, "online testing starting\n");
1699
Shannon Nelson7b086392013-11-20 10:02:59 +00001700 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001701 eth_test->flags |= ETH_TEST_FL_FAILED;
1702
1703 /* Offline only tests, not run in online; pass by default */
1704 data[I40E_ETH_TEST_REG] = 0;
1705 data[I40E_ETH_TEST_EEPROM] = 0;
1706 data[I40E_ETH_TEST_INTR] = 0;
1707 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001708 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001709
Greg Rosee17bc412015-04-16 20:05:59 -04001710skip_ol_tests:
1711
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001712 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001713}
1714
1715static void i40e_get_wol(struct net_device *netdev,
1716 struct ethtool_wolinfo *wol)
1717{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001718 struct i40e_netdev_priv *np = netdev_priv(netdev);
1719 struct i40e_pf *pf = np->vsi->back;
1720 struct i40e_hw *hw = &pf->hw;
1721 u16 wol_nvm_bits;
1722
1723 /* NVM bit on means WoL disabled for the port */
1724 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001725 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001726 wol->supported = 0;
1727 wol->wolopts = 0;
1728 } else {
1729 wol->supported = WAKE_MAGIC;
1730 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1731 }
1732}
1733
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001734/**
1735 * i40e_set_wol - set the WakeOnLAN configuration
1736 * @netdev: the netdev in question
1737 * @wol: the ethtool WoL setting data
1738 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001739static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1740{
1741 struct i40e_netdev_priv *np = netdev_priv(netdev);
1742 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001743 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001744 struct i40e_hw *hw = &pf->hw;
1745 u16 wol_nvm_bits;
1746
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001747 /* WoL not supported if this isn't the controlling PF on the port */
1748 if (hw->partition_id != 1) {
1749 i40e_partition_setting_complaint(pf);
1750 return -EOPNOTSUPP;
1751 }
1752
1753 if (vsi != pf->vsi[pf->lan_vsi])
1754 return -EOPNOTSUPP;
1755
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001756 /* NVM bit on means WoL disabled for the port */
1757 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001758 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001759 return -EOPNOTSUPP;
1760
1761 /* only magic packet is supported */
1762 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1763 return -EOPNOTSUPP;
1764
1765 /* is this a new value? */
1766 if (pf->wol_en != !!wol->wolopts) {
1767 pf->wol_en = !!wol->wolopts;
1768 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1769 }
1770
1771 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001772}
1773
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774static int i40e_set_phys_id(struct net_device *netdev,
1775 enum ethtool_phys_id_state state)
1776{
1777 struct i40e_netdev_priv *np = netdev_priv(netdev);
1778 struct i40e_pf *pf = np->vsi->back;
1779 struct i40e_hw *hw = &pf->hw;
1780 int blink_freq = 2;
1781
1782 switch (state) {
1783 case ETHTOOL_ID_ACTIVE:
1784 pf->led_status = i40e_led_get(hw);
1785 return blink_freq;
1786 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001787 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001788 break;
1789 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001790 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791 break;
1792 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001793 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001794 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001795 default:
1796 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797 }
1798
1799 return 0;
1800}
1801
1802/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1803 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1804 * 125us (8000 interrupts per second) == ITR(62)
1805 */
1806
1807static int i40e_get_coalesce(struct net_device *netdev,
1808 struct ethtool_coalesce *ec)
1809{
1810 struct i40e_netdev_priv *np = netdev_priv(netdev);
1811 struct i40e_vsi *vsi = np->vsi;
1812
1813 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1814 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1815
1816 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001817 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818
1819 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001820 ec->use_adaptive_tx_coalesce = 1;
1821
1822 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1823 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001824
1825 return 0;
1826}
1827
1828static int i40e_set_coalesce(struct net_device *netdev,
1829 struct ethtool_coalesce *ec)
1830{
1831 struct i40e_netdev_priv *np = netdev_priv(netdev);
1832 struct i40e_q_vector *q_vector;
1833 struct i40e_vsi *vsi = np->vsi;
1834 struct i40e_pf *pf = vsi->back;
1835 struct i40e_hw *hw = &pf->hw;
1836 u16 vector;
1837 int i;
1838
1839 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1840 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1841
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001842 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001843 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001844 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001845 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001846 } else if (ec->rx_coalesce_usecs == 0) {
1847 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001848 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001849 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 +00001850 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001851 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001852 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001853 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001854
Mitch Williams32f5f542014-04-04 04:43:10 +00001855 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001856 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001857 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001858 } else if (ec->tx_coalesce_usecs == 0) {
1859 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001860 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001861 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 +00001862 } else {
1863 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001864 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001865 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001866 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001867
1868 if (ec->use_adaptive_rx_coalesce)
1869 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1870 else
1871 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1872
1873 if (ec->use_adaptive_tx_coalesce)
1874 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1875 else
1876 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001877
Alexander Duyck493fb302013-09-28 07:01:44 +00001878 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1879 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001880 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1881 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1882 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1883 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1884 i40e_flush(hw);
1885 }
1886
1887 return 0;
1888}
1889
1890/**
1891 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1892 * @pf: pointer to the physical function struct
1893 * @cmd: ethtool rxnfc command
1894 *
1895 * Returns Success if the flow is supported, else Invalid Input.
1896 **/
1897static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1898{
1899 cmd->data = 0;
1900
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001901 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1902 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1903 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1904 return 0;
1905 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001906 /* Report default options for RSS on i40e */
1907 switch (cmd->flow_type) {
1908 case TCP_V4_FLOW:
1909 case UDP_V4_FLOW:
1910 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1911 /* fall through to add IP fields */
1912 case SCTP_V4_FLOW:
1913 case AH_ESP_V4_FLOW:
1914 case AH_V4_FLOW:
1915 case ESP_V4_FLOW:
1916 case IPV4_FLOW:
1917 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1918 break;
1919 case TCP_V6_FLOW:
1920 case UDP_V6_FLOW:
1921 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1922 /* fall through to add IP fields */
1923 case SCTP_V6_FLOW:
1924 case AH_ESP_V6_FLOW:
1925 case AH_V6_FLOW:
1926 case ESP_V6_FLOW:
1927 case IPV6_FLOW:
1928 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1929 break;
1930 default:
1931 return -EINVAL;
1932 }
1933
1934 return 0;
1935}
1936
1937/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001938 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1939 * @pf: Pointer to the physical function struct
1940 * @cmd: The command to get or set Rx flow classification rules
1941 * @rule_locs: Array of used rule locations
1942 *
1943 * This function populates both the total and actual rule count of
1944 * the ethtool flow classification command
1945 *
1946 * Returns 0 on success or -EMSGSIZE if entry not found
1947 **/
1948static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1949 struct ethtool_rxnfc *cmd,
1950 u32 *rule_locs)
1951{
1952 struct i40e_fdir_filter *rule;
1953 struct hlist_node *node2;
1954 int cnt = 0;
1955
1956 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001957 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001958
1959 hlist_for_each_entry_safe(rule, node2,
1960 &pf->fdir_filter_list, fdir_node) {
1961 if (cnt == cmd->rule_cnt)
1962 return -EMSGSIZE;
1963
1964 rule_locs[cnt] = rule->fd_id;
1965 cnt++;
1966 }
1967
1968 cmd->rule_cnt = cnt;
1969
1970 return 0;
1971}
1972
1973/**
1974 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1975 * @pf: Pointer to the physical function struct
1976 * @cmd: The command to get or set Rx flow classification rules
1977 *
1978 * This function looks up a filter based on the Rx flow classification
1979 * command and fills the flow spec info for it if found
1980 *
1981 * Returns 0 on success or -EINVAL if filter not found
1982 **/
1983static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1984 struct ethtool_rxnfc *cmd)
1985{
1986 struct ethtool_rx_flow_spec *fsp =
1987 (struct ethtool_rx_flow_spec *)&cmd->fs;
1988 struct i40e_fdir_filter *rule = NULL;
1989 struct hlist_node *node2;
1990
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001991 hlist_for_each_entry_safe(rule, node2,
1992 &pf->fdir_filter_list, fdir_node) {
1993 if (fsp->location <= rule->fd_id)
1994 break;
1995 }
1996
1997 if (!rule || fsp->location != rule->fd_id)
1998 return -EINVAL;
1999
2000 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002001 if (fsp->flow_type == IP_USER_FLOW) {
2002 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2003 fsp->h_u.usr_ip4_spec.proto = 0;
2004 fsp->m_u.usr_ip4_spec.proto = 0;
2005 }
2006
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002007 /* Reverse the src and dest notion, since the HW views them from
2008 * Tx perspective where as the user expects it from Rx filter view.
2009 */
2010 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2011 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2012 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2013 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002014
2015 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2016 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2017 else
2018 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002019
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002020 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2021 struct i40e_vsi *vsi;
2022
2023 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2024 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2025 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2026 fsp->m_ext.data[1] = htonl(0x1);
2027 }
2028 }
2029
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002030 return 0;
2031}
2032
2033/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002034 * i40e_get_rxnfc - command to get RX flow classification rules
2035 * @netdev: network interface device structure
2036 * @cmd: ethtool rxnfc command
2037 *
2038 * Returns Success if the command is supported.
2039 **/
2040static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2041 u32 *rule_locs)
2042{
2043 struct i40e_netdev_priv *np = netdev_priv(netdev);
2044 struct i40e_vsi *vsi = np->vsi;
2045 struct i40e_pf *pf = vsi->back;
2046 int ret = -EOPNOTSUPP;
2047
2048 switch (cmd->cmd) {
2049 case ETHTOOL_GRXRINGS:
2050 cmd->data = vsi->alloc_queue_pairs;
2051 ret = 0;
2052 break;
2053 case ETHTOOL_GRXFH:
2054 ret = i40e_get_rss_hash_opts(pf, cmd);
2055 break;
2056 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002057 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002058 /* report total rule count */
2059 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002060 ret = 0;
2061 break;
2062 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002063 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002064 break;
2065 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002066 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2067 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002068 default:
2069 break;
2070 }
2071
2072 return ret;
2073}
2074
2075/**
2076 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2077 * @pf: pointer to the physical function struct
2078 * @cmd: ethtool rxnfc command
2079 *
2080 * Returns Success if the flow input set is supported.
2081 **/
2082static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2083{
2084 struct i40e_hw *hw = &pf->hw;
2085 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2086 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2087
2088 /* RSS does not support anything other than hashing
2089 * to queues on src and dst IPs and ports
2090 */
2091 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2092 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2093 return -EINVAL;
2094
2095 /* We need at least the IP SRC and DEST fields for hashing */
2096 if (!(nfc->data & RXH_IP_SRC) ||
2097 !(nfc->data & RXH_IP_DST))
2098 return -EINVAL;
2099
2100 switch (nfc->flow_type) {
2101 case TCP_V4_FLOW:
2102 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2103 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002104 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002105 break;
2106 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002107 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002108 break;
2109 default:
2110 return -EINVAL;
2111 }
2112 break;
2113 case TCP_V6_FLOW:
2114 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2115 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002116 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002117 break;
2118 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002119 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002120 break;
2121 default:
2122 return -EINVAL;
2123 }
2124 break;
2125 case UDP_V4_FLOW:
2126 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2127 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002128 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2129 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002130 break;
2131 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002132 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2133 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002134 break;
2135 default:
2136 return -EINVAL;
2137 }
2138 break;
2139 case UDP_V6_FLOW:
2140 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2141 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002142 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2143 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144 break;
2145 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002146 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2147 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002148 break;
2149 default:
2150 return -EINVAL;
2151 }
2152 break;
2153 case AH_ESP_V4_FLOW:
2154 case AH_V4_FLOW:
2155 case ESP_V4_FLOW:
2156 case SCTP_V4_FLOW:
2157 if ((nfc->data & RXH_L4_B_0_1) ||
2158 (nfc->data & RXH_L4_B_2_3))
2159 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002160 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002161 break;
2162 case AH_ESP_V6_FLOW:
2163 case AH_V6_FLOW:
2164 case ESP_V6_FLOW:
2165 case SCTP_V6_FLOW:
2166 if ((nfc->data & RXH_L4_B_0_1) ||
2167 (nfc->data & RXH_L4_B_2_3))
2168 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002169 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002170 break;
2171 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002172 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2173 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002174 break;
2175 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002176 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2177 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178 break;
2179 default:
2180 return -EINVAL;
2181 }
2182
2183 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2184 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2185 i40e_flush(hw);
2186
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002187 /* Save setting for future output/update */
2188 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2189
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002190 return 0;
2191}
2192
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002193/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002194 * i40e_match_fdir_input_set - Match a new filter against an existing one
2195 * @rule: The filter already added
2196 * @input: The new filter to comapre against
2197 *
2198 * Returns true if the two input set match
2199 **/
2200static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2201 struct i40e_fdir_filter *input)
2202{
2203 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2204 (rule->src_ip[0] != input->src_ip[0]) ||
2205 (rule->dst_port != input->dst_port) ||
2206 (rule->src_port != input->src_port))
2207 return false;
2208 return true;
2209}
2210
2211/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002212 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2213 * @vsi: Pointer to the targeted VSI
2214 * @input: The filter to update or NULL to indicate deletion
2215 * @sw_idx: Software index to the filter
2216 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002217 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002218 * This function updates (or deletes) a Flow Director entry from
2219 * the hlist of the corresponding PF
2220 *
2221 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002222 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002223static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2224 struct i40e_fdir_filter *input,
2225 u16 sw_idx,
2226 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002227{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002228 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002230 struct hlist_node *node2;
2231 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002232
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002233 parent = NULL;
2234 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002235
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002236 hlist_for_each_entry_safe(rule, node2,
2237 &pf->fdir_filter_list, fdir_node) {
2238 /* hash found, or no matching entry */
2239 if (rule->fd_id >= sw_idx)
2240 break;
2241 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242 }
2243
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002244 /* if there is an old rule occupying our place remove it */
2245 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002246 if (input && !i40e_match_fdir_input_set(rule, input))
2247 err = i40e_add_del_fdir(vsi, rule, false);
2248 else if (!input)
2249 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002250 hlist_del(&rule->fdir_node);
2251 kfree(rule);
2252 pf->fdir_pf_active_filters--;
2253 }
2254
2255 /* If no input this was a delete, err should be 0 if a rule was
2256 * successfully found and removed from the list else -EINVAL
2257 */
2258 if (!input)
2259 return err;
2260
2261 /* initialize node and set software index */
2262 INIT_HLIST_NODE(&input->fdir_node);
2263
2264 /* add filter to the list */
2265 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002266 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002267 else
2268 hlist_add_head(&input->fdir_node,
2269 &pf->fdir_filter_list);
2270
2271 /* update counts */
2272 pf->fdir_pf_active_filters++;
2273
2274 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275}
2276
2277/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002278 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2279 * @vsi: Pointer to the targeted VSI
2280 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002282 * The function removes a Flow Director filter entry from the
2283 * hlist of the corresponding PF
2284 *
2285 * Returns 0 on success
2286 */
2287static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2288 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002289{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002290 struct ethtool_rx_flow_spec *fsp =
2291 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002292 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002293 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002294
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002295 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2296 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2297 return -EBUSY;
2298
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002299 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2300 return -EBUSY;
2301
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002302 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002303
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002304 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002305 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002306}
2307
2308/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002309 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002310 * @vsi: pointer to the targeted VSI
2311 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002312 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002313 * Add Flow Director filters for a specific flow spec based on their
2314 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002315 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002316static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2317 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002318{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002319 struct ethtool_rx_flow_spec *fsp;
2320 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002321 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002322 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002323 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002324
2325 if (!vsi)
2326 return -EINVAL;
2327
2328 pf = vsi->back;
2329
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002330 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2331 return -EOPNOTSUPP;
2332
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002333 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002334 return -ENOSPC;
2335
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002336 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2337 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2338 return -EBUSY;
2339
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002340 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2341 return -EBUSY;
2342
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002343 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2344
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002345 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2346 pf->hw.func_caps.fd_filters_guaranteed)) {
2347 return -EINVAL;
2348 }
2349
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002350 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2351 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002352 return -EINVAL;
2353
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002354 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002355
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002356 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002357 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002358
2359 input->fd_id = fsp->location;
2360
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002361 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2362 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2363 else
2364 input->dest_ctl =
2365 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2366
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002367 input->q_index = fsp->ring_cookie;
2368 input->flex_off = 0;
2369 input->pctype = 0;
2370 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002371 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002372 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002373 input->flow_type = fsp->flow_type;
2374 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002375
2376 /* Reverse the src and dest notion, since the HW expects them to be from
2377 * Tx perspective where as the input from user is from Rx filter view.
2378 */
2379 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2380 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2381 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2382 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002383
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002384 if (ntohl(fsp->m_ext.data[1])) {
2385 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2386 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2387 goto free_input;
2388 }
2389 vf_id = ntohl(fsp->h_ext.data[1]);
2390 /* Find vsi id from vf id and override dest vsi */
2391 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2392 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2393 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2394 goto free_input;
2395 }
2396 }
2397
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002398 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002399free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002400 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002401 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002402 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002403 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002404
2405 return ret;
2406}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002407
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002408/**
2409 * i40e_set_rxnfc - command to set RX flow classification rules
2410 * @netdev: network interface device structure
2411 * @cmd: ethtool rxnfc command
2412 *
2413 * Returns Success if the command is supported.
2414 **/
2415static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2416{
2417 struct i40e_netdev_priv *np = netdev_priv(netdev);
2418 struct i40e_vsi *vsi = np->vsi;
2419 struct i40e_pf *pf = vsi->back;
2420 int ret = -EOPNOTSUPP;
2421
2422 switch (cmd->cmd) {
2423 case ETHTOOL_SRXFH:
2424 ret = i40e_set_rss_hash_opt(pf, cmd);
2425 break;
2426 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002427 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002428 break;
2429 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002430 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002431 break;
2432 default:
2433 break;
2434 }
2435
2436 return ret;
2437}
2438
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002439/**
2440 * i40e_max_channels - get Max number of combined channels supported
2441 * @vsi: vsi pointer
2442 **/
2443static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2444{
2445 /* TODO: This code assumes DCB and FD is disabled for now. */
2446 return vsi->alloc_queue_pairs;
2447}
2448
2449/**
2450 * i40e_get_channels - Get the current channels enabled and max supported etc.
2451 * @netdev: network interface device structure
2452 * @ch: ethtool channels structure
2453 *
2454 * We don't support separate tx and rx queues as channels. The other count
2455 * represents how many queues are being used for control. max_combined counts
2456 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2457 * q_vectors since we support a lot more queue pairs than q_vectors.
2458 **/
2459static void i40e_get_channels(struct net_device *dev,
2460 struct ethtool_channels *ch)
2461{
2462 struct i40e_netdev_priv *np = netdev_priv(dev);
2463 struct i40e_vsi *vsi = np->vsi;
2464 struct i40e_pf *pf = vsi->back;
2465
2466 /* report maximum channels */
2467 ch->max_combined = i40e_max_channels(vsi);
2468
2469 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002470 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002471 ch->max_other = ch->other_count;
2472
2473 /* Note: This code assumes DCB is disabled for now. */
2474 ch->combined_count = vsi->num_queue_pairs;
2475}
2476
2477/**
2478 * i40e_set_channels - Set the new channels count.
2479 * @netdev: network interface device structure
2480 * @ch: ethtool channels structure
2481 *
2482 * The new channels count may not be the same as requested by the user
2483 * since it gets rounded down to a power of 2 value.
2484 **/
2485static int i40e_set_channels(struct net_device *dev,
2486 struct ethtool_channels *ch)
2487{
2488 struct i40e_netdev_priv *np = netdev_priv(dev);
2489 unsigned int count = ch->combined_count;
2490 struct i40e_vsi *vsi = np->vsi;
2491 struct i40e_pf *pf = vsi->back;
2492 int new_count;
2493
2494 /* We do not support setting channels for any other VSI at present */
2495 if (vsi->type != I40E_VSI_MAIN)
2496 return -EINVAL;
2497
2498 /* verify they are not requesting separate vectors */
2499 if (!count || ch->rx_count || ch->tx_count)
2500 return -EINVAL;
2501
2502 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002503 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002504 return -EINVAL;
2505
2506 /* verify the number of channels does not exceed hardware limits */
2507 if (count > i40e_max_channels(vsi))
2508 return -EINVAL;
2509
2510 /* update feature limits from largest to smallest supported values */
2511 /* TODO: Flow director limit, DCB etc */
2512
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002513 /* use rss_reconfig to rebuild with new queue count and update traffic
2514 * class queue mapping
2515 */
2516 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002517 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002518 return 0;
2519 else
2520 return -EINVAL;
2521}
2522
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002523#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2524/**
2525 * i40e_get_rxfh_key_size - get the RSS hash key size
2526 * @netdev: network interface device structure
2527 *
2528 * Returns the table size.
2529 **/
2530static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2531{
2532 return I40E_HKEY_ARRAY_SIZE;
2533}
2534
2535/**
2536 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2537 * @netdev: network interface device structure
2538 *
2539 * Returns the table size.
2540 **/
2541static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2542{
2543 return I40E_HLUT_ARRAY_SIZE;
2544}
2545
2546static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2547 u8 *hfunc)
2548{
2549 struct i40e_netdev_priv *np = netdev_priv(netdev);
2550 struct i40e_vsi *vsi = np->vsi;
2551 struct i40e_pf *pf = vsi->back;
2552 struct i40e_hw *hw = &pf->hw;
2553 u32 reg_val;
2554 int i, j;
2555
2556 if (hfunc)
2557 *hfunc = ETH_RSS_HASH_TOP;
2558
2559 if (!indir)
2560 return 0;
2561
2562 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2563 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2564 indir[j++] = reg_val & 0xff;
2565 indir[j++] = (reg_val >> 8) & 0xff;
2566 indir[j++] = (reg_val >> 16) & 0xff;
2567 indir[j++] = (reg_val >> 24) & 0xff;
2568 }
2569
2570 if (key) {
2571 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2572 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2573 key[j++] = (u8)(reg_val & 0xff);
2574 key[j++] = (u8)((reg_val >> 8) & 0xff);
2575 key[j++] = (u8)((reg_val >> 16) & 0xff);
2576 key[j++] = (u8)((reg_val >> 24) & 0xff);
2577 }
2578 }
2579 return 0;
2580}
2581
2582/**
2583 * i40e_set_rxfh - set the rx flow hash indirection table
2584 * @netdev: network interface device structure
2585 * @indir: indirection table
2586 * @key: hash key
2587 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002588 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002589 * returns 0 after programming the table.
2590 **/
2591static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2592 const u8 *key, const u8 hfunc)
2593{
2594 struct i40e_netdev_priv *np = netdev_priv(netdev);
2595 struct i40e_vsi *vsi = np->vsi;
2596 struct i40e_pf *pf = vsi->back;
2597 struct i40e_hw *hw = &pf->hw;
2598 u32 reg_val;
2599 int i, j;
2600
2601 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2602 return -EOPNOTSUPP;
2603
2604 if (!indir)
2605 return 0;
2606
2607 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2608 reg_val = indir[j++];
2609 reg_val |= indir[j++] << 8;
2610 reg_val |= indir[j++] << 16;
2611 reg_val |= indir[j++] << 24;
2612 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2613 }
2614
2615 if (key) {
2616 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2617 reg_val = key[j++];
2618 reg_val |= key[j++] << 8;
2619 reg_val |= key[j++] << 16;
2620 reg_val |= key[j++] << 24;
2621 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2622 }
2623 }
2624 return 0;
2625}
2626
Greg Rose7e45ab42015-02-06 08:52:19 +00002627/**
2628 * i40e_get_priv_flags - report device private flags
2629 * @dev: network interface device structure
2630 *
2631 * The get string set count and the string set should be matched for each
2632 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2633 * array.
2634 *
2635 * Returns a u32 bitmap of flags.
2636 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002637static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002638{
2639 struct i40e_netdev_priv *np = netdev_priv(dev);
2640 struct i40e_vsi *vsi = np->vsi;
2641 struct i40e_pf *pf = vsi->back;
2642 u32 ret_flags = 0;
2643
2644 ret_flags |= pf->hw.func_caps.npar_enable ?
2645 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002646 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2647 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002648
2649 return ret_flags;
2650}
2651
Shannon Nelson9ac77262015-08-27 11:42:40 -04002652/**
2653 * i40e_set_priv_flags - set private flags
2654 * @dev: network interface device structure
2655 * @flags: bit flags to be set
2656 **/
2657static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2658{
2659 struct i40e_netdev_priv *np = netdev_priv(dev);
2660 struct i40e_vsi *vsi = np->vsi;
2661 struct i40e_pf *pf = vsi->back;
2662
2663 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2664 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2665 else
2666 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2667
2668 return 0;
2669}
2670
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002671static const struct ethtool_ops i40e_ethtool_ops = {
2672 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002673 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002674 .get_drvinfo = i40e_get_drvinfo,
2675 .get_regs_len = i40e_get_regs_len,
2676 .get_regs = i40e_get_regs,
2677 .nway_reset = i40e_nway_reset,
2678 .get_link = ethtool_op_get_link,
2679 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002680 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002681 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002682 .get_eeprom_len = i40e_get_eeprom_len,
2683 .get_eeprom = i40e_get_eeprom,
2684 .get_ringparam = i40e_get_ringparam,
2685 .set_ringparam = i40e_set_ringparam,
2686 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002687 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002688 .get_msglevel = i40e_get_msglevel,
2689 .set_msglevel = i40e_set_msglevel,
2690 .get_rxnfc = i40e_get_rxnfc,
2691 .set_rxnfc = i40e_set_rxnfc,
2692 .self_test = i40e_diag_test,
2693 .get_strings = i40e_get_strings,
2694 .set_phys_id = i40e_set_phys_id,
2695 .get_sset_count = i40e_get_sset_count,
2696 .get_ethtool_stats = i40e_get_ethtool_stats,
2697 .get_coalesce = i40e_get_coalesce,
2698 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002699 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2700 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2701 .get_rxfh = i40e_get_rxfh,
2702 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002703 .get_channels = i40e_get_channels,
2704 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002705 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002706 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002707 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002708};
2709
2710void i40e_set_ethtool_ops(struct net_device *netdev)
2711{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002712 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002713}