blob: e77b6bddd90e9c06d9296c229411aafc165251e8 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Shannon Nelson41a9e552014-04-23 04:50:20 +000090};
91
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000092static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
93 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000094
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000095/* These PF_STATs might look like duplicates of some NETDEV_STATs,
96 * but they are separate. This device supports Virtualization, and
97 * as such might have several netdevs supporting VMDq and FCoE going
98 * through a single port. The NETDEV_STATs are for individual netdevs
99 * seen at the top of the stack, and the PF_STATs are for the physical
100 * function at the bottom of the stack hosting those netdevs.
101 *
102 * The PF_STATs are appended to the netdev stats only when ethtool -S
103 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104 */
105static struct i40e_stats i40e_gstrings_stats[] = {
106 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
107 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000108 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
109 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
110 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
111 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
112 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
113 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000114 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
115 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000152 /* LPI stats */
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000157};
158
Vasu Dev38e00432014-08-01 13:27:03 -0700159#ifdef I40E_FCOE
160static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
169};
170
171#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000178#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700179#ifdef I40E_FCOE
180#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
185#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000187 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700189#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
196 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000197#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
201
202enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
205 I40E_ETH_TEST_INTR,
206 I40E_ETH_TEST_LOOPBACK,
207 I40E_ETH_TEST_LINK,
208};
209
210static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
216};
217
218#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
219
Greg Rose7e45ab42015-02-06 08:52:19 +0000220static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
221 "NPAR",
222};
223
224#define I40E_PRIV_FLAGS_STR_LEN \
225 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
226
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000227/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000228 * i40e_partition_setting_complaint - generic complaint for MFP restriction
229 * @pf: the PF struct
230 **/
231static void i40e_partition_setting_complaint(struct i40e_pf *pf)
232{
233 dev_info(&pf->pdev->dev,
234 "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");
235}
236
237/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000238 * i40e_get_settings_link_up - Get the Link settings for when link is up
239 * @hw: hw structure
240 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000241 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000243 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000244static void i40e_get_settings_link_up(struct i40e_hw *hw,
245 struct ethtool_cmd *ecmd,
246 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000247{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000248 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000249 u32 link_speed = hw_link_info->link_speed;
250
Catherine Sullivane8278452015-02-06 08:52:08 +0000251 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 switch (hw_link_info->phy_type) {
253 case I40E_PHY_TYPE_40GBASE_CR4:
254 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000255 ecmd->supported = SUPPORTED_Autoneg |
256 SUPPORTED_40000baseCR4_Full;
257 ecmd->advertising = ADVERTISED_Autoneg |
258 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000260 case I40E_PHY_TYPE_XLAUI:
261 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000262 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000263 ecmd->supported = SUPPORTED_40000baseCR4_Full;
264 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000266 ecmd->supported = SUPPORTED_Autoneg |
267 SUPPORTED_40000baseKR4_Full;
268 ecmd->advertising = ADVERTISED_Autoneg |
269 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000270 break;
271 case I40E_PHY_TYPE_40GBASE_SR4:
272 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000273 break;
274 case I40E_PHY_TYPE_40GBASE_LR4:
275 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700277 case I40E_PHY_TYPE_20GBASE_KR2:
278 ecmd->supported = SUPPORTED_Autoneg |
279 SUPPORTED_20000baseKR2_Full;
280 ecmd->advertising = ADVERTISED_Autoneg |
281 ADVERTISED_20000baseKR2_Full;
282 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000284 ecmd->supported = SUPPORTED_Autoneg |
285 SUPPORTED_10000baseKX4_Full;
286 ecmd->advertising = ADVERTISED_Autoneg |
287 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000288 break;
289 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000290 ecmd->supported = SUPPORTED_Autoneg |
291 SUPPORTED_10000baseKR_Full;
292 ecmd->advertising = ADVERTISED_Autoneg |
293 ADVERTISED_10000baseKR_Full;
294 break;
295 case I40E_PHY_TYPE_10GBASE_SR:
296 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000297 case I40E_PHY_TYPE_1000BASE_SX:
298 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000299 ecmd->supported = SUPPORTED_10000baseT_Full |
300 SUPPORTED_1000baseT_Full;
301 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
302 ecmd->advertising |= ADVERTISED_10000baseT_Full;
303 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
304 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000305 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000306 case I40E_PHY_TYPE_1000BASE_KX:
307 ecmd->supported = SUPPORTED_Autoneg |
308 SUPPORTED_1000baseKX_Full;
309 ecmd->advertising = ADVERTISED_Autoneg |
310 ADVERTISED_1000baseKX_Full;
311 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000312 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000313 case I40E_PHY_TYPE_1000BASE_T:
314 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000315 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000316 SUPPORTED_10000baseT_Full |
317 SUPPORTED_1000baseT_Full |
318 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000319 ecmd->advertising = ADVERTISED_Autoneg;
320 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
321 ecmd->advertising |= ADVERTISED_10000baseT_Full;
322 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
323 ecmd->advertising |= ADVERTISED_1000baseT_Full;
324 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
325 ecmd->advertising |= ADVERTISED_100baseT_Full;
326 break;
327 case I40E_PHY_TYPE_10GBASE_CR1_CU:
328 case I40E_PHY_TYPE_10GBASE_CR1:
329 ecmd->supported = SUPPORTED_Autoneg |
330 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000331 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000332 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000333 break;
334 case I40E_PHY_TYPE_XAUI:
335 case I40E_PHY_TYPE_XFI:
336 case I40E_PHY_TYPE_SFI:
337 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000338 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000339 ecmd->supported = SUPPORTED_10000baseT_Full;
340 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000341 case I40E_PHY_TYPE_SGMII:
342 ecmd->supported = SUPPORTED_Autoneg |
343 SUPPORTED_1000baseT_Full |
344 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000345 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
346 ecmd->advertising |= ADVERTISED_1000baseT_Full;
347 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
348 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000349 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000350 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000351 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000352 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
353 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000354 }
355
Catherine Sullivane8278452015-02-06 08:52:08 +0000356 /* Set speed and duplex */
357 switch (link_speed) {
358 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400359 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000360 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700361 case I40E_LINK_SPEED_20GB:
362 ethtool_cmd_speed_set(ecmd, SPEED_20000);
363 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000364 case I40E_LINK_SPEED_10GB:
365 ethtool_cmd_speed_set(ecmd, SPEED_10000);
366 break;
367 case I40E_LINK_SPEED_1GB:
368 ethtool_cmd_speed_set(ecmd, SPEED_1000);
369 break;
370 case I40E_LINK_SPEED_100MB:
371 ethtool_cmd_speed_set(ecmd, SPEED_100);
372 break;
373 default:
374 break;
375 }
376 ecmd->duplex = DUPLEX_FULL;
377}
378
379/**
380 * i40e_get_settings_link_down - Get the Link settings for when link is down
381 * @hw: hw structure
382 * @ecmd: ethtool command to fill in
383 *
384 * Reports link settings that can be determined when link is down
385 **/
386static void i40e_get_settings_link_down(struct i40e_hw *hw,
387 struct ethtool_cmd *ecmd)
388{
389 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
390
391 /* link is down and the driver needs to fall back on
392 * device ID to determine what kinds of info to display,
393 * it's mostly a guess that may change when link is up
394 */
395 switch (hw->device_id) {
396 case I40E_DEV_ID_QSFP_A:
397 case I40E_DEV_ID_QSFP_B:
398 case I40E_DEV_ID_QSFP_C:
399 /* pluggable QSFP */
400 ecmd->supported = SUPPORTED_40000baseSR4_Full |
401 SUPPORTED_40000baseCR4_Full |
402 SUPPORTED_40000baseLR4_Full;
403 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
404 ADVERTISED_40000baseCR4_Full |
405 ADVERTISED_40000baseLR4_Full;
406 break;
407 case I40E_DEV_ID_KX_B:
408 /* backplane 40G */
409 ecmd->supported = SUPPORTED_40000baseKR4_Full;
410 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
411 break;
412 case I40E_DEV_ID_KX_C:
413 /* backplane 10G */
414 ecmd->supported = SUPPORTED_10000baseKR_Full;
415 ecmd->advertising = ADVERTISED_10000baseKR_Full;
416 break;
417 case I40E_DEV_ID_10G_BASE_T:
418 ecmd->supported = SUPPORTED_10000baseT_Full |
419 SUPPORTED_1000baseT_Full |
420 SUPPORTED_100baseT_Full;
421 /* Figure out what has been requested */
422 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
423 ecmd->advertising |= ADVERTISED_10000baseT_Full;
424 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
425 ecmd->advertising |= ADVERTISED_1000baseT_Full;
426 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
427 ecmd->advertising |= ADVERTISED_100baseT_Full;
428 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700429 case I40E_DEV_ID_20G_KR2:
430 /* backplane 20G */
431 ecmd->supported = SUPPORTED_20000baseKR2_Full;
432 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
433 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000434 default:
435 /* all the rest are 10G/1G */
436 ecmd->supported = SUPPORTED_10000baseT_Full |
437 SUPPORTED_1000baseT_Full;
438 /* Figure out what has been requested */
439 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
440 ecmd->advertising |= ADVERTISED_10000baseT_Full;
441 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
442 ecmd->advertising |= ADVERTISED_1000baseT_Full;
443 break;
444 }
445
446 /* With no link speed and duplex are unknown */
447 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
448 ecmd->duplex = DUPLEX_UNKNOWN;
449}
450
451/**
452 * i40e_get_settings - Get Link Speed and Duplex settings
453 * @netdev: network interface device structure
454 * @ecmd: ethtool command
455 *
456 * Reports speed/duplex settings based on media_type
457 **/
458static int i40e_get_settings(struct net_device *netdev,
459 struct ethtool_cmd *ecmd)
460{
461 struct i40e_netdev_priv *np = netdev_priv(netdev);
462 struct i40e_pf *pf = np->vsi->back;
463 struct i40e_hw *hw = &pf->hw;
464 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
465 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
466
467 if (link_up)
468 i40e_get_settings_link_up(hw, ecmd, netdev);
469 else
470 i40e_get_settings_link_down(hw, ecmd);
471
472 /* Now set the settings that don't rely on link being up/down */
473
474 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000475 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
476 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000477
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000478 switch (hw->phy.media_type) {
479 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000480 ecmd->supported |= SUPPORTED_Autoneg |
481 SUPPORTED_Backplane;
482 ecmd->advertising |= ADVERTISED_Autoneg |
483 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000484 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000485 break;
486 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000487 ecmd->supported |= SUPPORTED_TP;
488 ecmd->advertising |= ADVERTISED_TP;
489 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000490 break;
491 case I40E_MEDIA_TYPE_DA:
492 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000493 ecmd->supported |= SUPPORTED_FIBRE;
494 ecmd->advertising |= ADVERTISED_FIBRE;
495 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000496 break;
497 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000498 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000499 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000500 break;
501 case I40E_MEDIA_TYPE_UNKNOWN:
502 default:
503 ecmd->port = PORT_OTHER;
504 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000505 }
506
Catherine Sullivane8278452015-02-06 08:52:08 +0000507 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000508 ecmd->transceiver = XCVR_EXTERNAL;
509
Catherine Sullivane8278452015-02-06 08:52:08 +0000510 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000511 ecmd->supported |= SUPPORTED_Pause;
512
Catherine Sullivane8278452015-02-06 08:52:08 +0000513 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000514 case I40E_FC_FULL:
515 ecmd->advertising |= ADVERTISED_Pause;
516 break;
517 case I40E_FC_TX_PAUSE:
518 ecmd->advertising |= ADVERTISED_Asym_Pause;
519 break;
520 case I40E_FC_RX_PAUSE:
521 ecmd->advertising |= (ADVERTISED_Pause |
522 ADVERTISED_Asym_Pause);
523 break;
524 default:
525 ecmd->advertising &= ~(ADVERTISED_Pause |
526 ADVERTISED_Asym_Pause);
527 break;
528 }
529
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000530 return 0;
531}
532
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000533/**
534 * i40e_set_settings - Set Speed and Duplex
535 * @netdev: network interface device structure
536 * @ecmd: ethtool command
537 *
538 * Set speed/duplex per media_types advertised/forced
539 **/
540static int i40e_set_settings(struct net_device *netdev,
541 struct ethtool_cmd *ecmd)
542{
543 struct i40e_netdev_priv *np = netdev_priv(netdev);
544 struct i40e_aq_get_phy_abilities_resp abilities;
545 struct i40e_aq_set_phy_config config;
546 struct i40e_pf *pf = np->vsi->back;
547 struct i40e_vsi *vsi = np->vsi;
548 struct i40e_hw *hw = &pf->hw;
549 struct ethtool_cmd safe_ecmd;
550 i40e_status status = 0;
551 bool change = false;
552 int err = 0;
553 u8 autoneg;
554 u32 advertise;
555
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000556 /* Changing port settings is not supported if this isn't the
557 * port's controlling PF
558 */
559 if (hw->partition_id != 1) {
560 i40e_partition_setting_complaint(pf);
561 return -EOPNOTSUPP;
562 }
563
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000564 if (vsi != pf->vsi[pf->lan_vsi])
565 return -EOPNOTSUPP;
566
567 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
568 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000569 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
570 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000571 return -EOPNOTSUPP;
572
573 /* get our own copy of the bits to check against */
574 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
575 i40e_get_settings(netdev, &safe_ecmd);
576
577 /* save autoneg and speed out of ecmd */
578 autoneg = ecmd->autoneg;
579 advertise = ecmd->advertising;
580
581 /* set autoneg and speed back to what they currently are */
582 ecmd->autoneg = safe_ecmd.autoneg;
583 ecmd->advertising = safe_ecmd.advertising;
584
585 ecmd->cmd = safe_ecmd.cmd;
586 /* If ecmd and safe_ecmd are not the same now, then they are
587 * trying to set something that we do not support
588 */
589 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
590 return -EOPNOTSUPP;
591
592 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
593 usleep_range(1000, 2000);
594
595 /* Get the current phy config */
596 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
597 NULL);
598 if (status)
599 return -EAGAIN;
600
Catherine Sullivan124ed152014-07-12 07:28:12 +0000601 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000602 * set below
603 */
604 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000605 config.abilities = abilities.abilities;
606
607 /* Check autoneg */
608 if (autoneg == AUTONEG_ENABLE) {
609 /* If autoneg is not supported, return error */
610 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
611 netdev_info(netdev, "Autoneg not supported on this phy\n");
612 return -EINVAL;
613 }
614 /* If autoneg was not already enabled */
615 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
616 config.abilities = abilities.abilities |
617 I40E_AQ_PHY_ENABLE_AN;
618 change = true;
619 }
620 } else {
621 /* If autoneg is supported 10GBASE_T is the only phy that
622 * can disable it, so otherwise return error
623 */
624 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
625 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
626 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
627 return -EINVAL;
628 }
629 /* If autoneg is currently enabled */
630 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000631 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000632 ~I40E_AQ_PHY_ENABLE_AN;
633 change = true;
634 }
635 }
636
637 if (advertise & ~safe_ecmd.supported)
638 return -EINVAL;
639
640 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000641 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000642 if (advertise & ADVERTISED_1000baseT_Full ||
643 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000644 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000645 if (advertise & ADVERTISED_10000baseT_Full ||
646 advertise & ADVERTISED_10000baseKX4_Full ||
647 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000648 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700649 if (advertise & ADVERTISED_20000baseKR2_Full)
650 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000651 if (advertise & ADVERTISED_40000baseKR4_Full ||
652 advertise & ADVERTISED_40000baseCR4_Full ||
653 advertise & ADVERTISED_40000baseSR4_Full ||
654 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000655 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000656
Catherine Sullivan124ed152014-07-12 07:28:12 +0000657 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000658 /* copy over the rest of the abilities */
659 config.phy_type = abilities.phy_type;
660 config.eee_capability = abilities.eee_capability;
661 config.eeer = abilities.eeer_val;
662 config.low_power_ctrl = abilities.d3_lpan;
663
Catherine Sullivane8278452015-02-06 08:52:08 +0000664 /* save the requested speeds */
665 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000666 /* set link and auto negotiation so changes take effect */
667 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
668 /* If link is up put link down */
669 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
670 /* Tell the OS link is going down, the link will go
671 * back up when fw says it is ready asynchronously
672 */
673 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
674 netif_carrier_off(netdev);
675 netif_tx_stop_all_queues(netdev);
676 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000677
678 /* make the aq call */
679 status = i40e_aq_set_phy_config(hw, &config, NULL);
680 if (status) {
681 netdev_info(netdev, "Set phy config failed with error %d.\n",
682 status);
683 return -EAGAIN;
684 }
685
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000686 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000687 if (status)
688 netdev_info(netdev, "Updating link info failed with error %d\n",
689 status);
690
691 } else {
692 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
693 }
694
695 return err;
696}
697
Jesse Brandeburga6599722014-06-04 08:45:25 +0000698static int i40e_nway_reset(struct net_device *netdev)
699{
700 /* restart autonegotiation */
701 struct i40e_netdev_priv *np = netdev_priv(netdev);
702 struct i40e_pf *pf = np->vsi->back;
703 struct i40e_hw *hw = &pf->hw;
704 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
705 i40e_status ret = 0;
706
707 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
708 if (ret) {
709 netdev_info(netdev, "link restart failed, aq_err=%d\n",
710 pf->hw.aq.asq_last_status);
711 return -EIO;
712 }
713
714 return 0;
715}
716
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000717/**
718 * i40e_get_pauseparam - Get Flow Control status
719 * Return tx/rx-pause status
720 **/
721static void i40e_get_pauseparam(struct net_device *netdev,
722 struct ethtool_pauseparam *pause)
723{
724 struct i40e_netdev_priv *np = netdev_priv(netdev);
725 struct i40e_pf *pf = np->vsi->back;
726 struct i40e_hw *hw = &pf->hw;
727 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000728 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000729
730 pause->autoneg =
731 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
732 AUTONEG_ENABLE : AUTONEG_DISABLE);
733
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000734 /* PFC enabled so report LFC as off */
735 if (dcbx_cfg->pfc.pfcenable) {
736 pause->rx_pause = 0;
737 pause->tx_pause = 0;
738 return;
739 }
740
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000741 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000742 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000743 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000744 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000745 } else if (hw->fc.current_mode == I40E_FC_FULL) {
746 pause->rx_pause = 1;
747 pause->tx_pause = 1;
748 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000749}
750
Catherine Sullivan2becc352014-06-04 08:45:27 +0000751/**
752 * i40e_set_pauseparam - Set Flow Control parameter
753 * @netdev: network interface device structure
754 * @pause: return tx/rx flow control status
755 **/
756static int i40e_set_pauseparam(struct net_device *netdev,
757 struct ethtool_pauseparam *pause)
758{
759 struct i40e_netdev_priv *np = netdev_priv(netdev);
760 struct i40e_pf *pf = np->vsi->back;
761 struct i40e_vsi *vsi = np->vsi;
762 struct i40e_hw *hw = &pf->hw;
763 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000764 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000765 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
766 i40e_status status;
767 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000768 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000769
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000770 /* Changing the port's flow control is not supported if this isn't the
771 * port's controlling PF
772 */
773 if (hw->partition_id != 1) {
774 i40e_partition_setting_complaint(pf);
775 return -EOPNOTSUPP;
776 }
777
Catherine Sullivan2becc352014-06-04 08:45:27 +0000778 if (vsi != pf->vsi[pf->lan_vsi])
779 return -EOPNOTSUPP;
780
781 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
782 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
783 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
784 return -EOPNOTSUPP;
785 }
786
787 /* If we have link and don't have autoneg */
788 if (!test_bit(__I40E_DOWN, &pf->state) &&
789 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
790 /* Send message that it might not necessarily work*/
791 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
792 }
793
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000794 if (dcbx_cfg->pfc.pfcenable) {
795 netdev_info(netdev,
796 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000797 return -EOPNOTSUPP;
798 }
799
800 if (pause->rx_pause && pause->tx_pause)
801 hw->fc.requested_mode = I40E_FC_FULL;
802 else if (pause->rx_pause && !pause->tx_pause)
803 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
804 else if (!pause->rx_pause && pause->tx_pause)
805 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
806 else if (!pause->rx_pause && !pause->tx_pause)
807 hw->fc.requested_mode = I40E_FC_NONE;
808 else
809 return -EINVAL;
810
Catherine Sullivan94128512014-07-12 07:28:16 +0000811 /* Tell the OS link is going down, the link will go back up when fw
812 * says it is ready asynchronously
813 */
814 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
815 netif_carrier_off(netdev);
816 netif_tx_stop_all_queues(netdev);
817
Catherine Sullivan2becc352014-06-04 08:45:27 +0000818 /* Set the fc mode and only restart an if link is up*/
819 status = i40e_set_fc(hw, &aq_failures, link_up);
820
821 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
822 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
823 status, hw->aq.asq_last_status);
824 err = -EAGAIN;
825 }
826 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
827 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
828 status, hw->aq.asq_last_status);
829 err = -EAGAIN;
830 }
831 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000832 netdev_info(netdev, "Set fc failed on the get_link_info call with error %d and status %d\n",
Catherine Sullivan2becc352014-06-04 08:45:27 +0000833 status, hw->aq.asq_last_status);
834 err = -EAGAIN;
835 }
836
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000837 if (!test_bit(__I40E_DOWN, &pf->state)) {
838 /* Give it a little more time to try to come back */
839 msleep(75);
840 if (!test_bit(__I40E_DOWN, &pf->state))
841 return i40e_nway_reset(netdev);
842 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000843
844 return err;
845}
846
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000847static u32 i40e_get_msglevel(struct net_device *netdev)
848{
849 struct i40e_netdev_priv *np = netdev_priv(netdev);
850 struct i40e_pf *pf = np->vsi->back;
851
852 return pf->msg_enable;
853}
854
855static void i40e_set_msglevel(struct net_device *netdev, u32 data)
856{
857 struct i40e_netdev_priv *np = netdev_priv(netdev);
858 struct i40e_pf *pf = np->vsi->back;
859
860 if (I40E_DEBUG_USER & data)
861 pf->hw.debug_mask = data;
862 pf->msg_enable = data;
863}
864
865static int i40e_get_regs_len(struct net_device *netdev)
866{
867 int reg_count = 0;
868 int i;
869
870 for (i = 0; i40e_reg_list[i].offset != 0; i++)
871 reg_count += i40e_reg_list[i].elements;
872
873 return reg_count * sizeof(u32);
874}
875
876static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
877 void *p)
878{
879 struct i40e_netdev_priv *np = netdev_priv(netdev);
880 struct i40e_pf *pf = np->vsi->back;
881 struct i40e_hw *hw = &pf->hw;
882 u32 *reg_buf = p;
883 int i, j, ri;
884 u32 reg;
885
886 /* Tell ethtool which driver-version-specific regs output we have.
887 *
888 * At some point, if we have ethtool doing special formatting of
889 * this data, it will rely on this version number to know how to
890 * interpret things. Hence, this needs to be updated if/when the
891 * diags register table is changed.
892 */
893 regs->version = 1;
894
895 /* loop through the diags reg table for what to print */
896 ri = 0;
897 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
898 for (j = 0; j < i40e_reg_list[i].elements; j++) {
899 reg = i40e_reg_list[i].offset
900 + (j * i40e_reg_list[i].stride);
901 reg_buf[ri++] = rd32(hw, reg);
902 }
903 }
904
905}
906
907static int i40e_get_eeprom(struct net_device *netdev,
908 struct ethtool_eeprom *eeprom, u8 *bytes)
909{
910 struct i40e_netdev_priv *np = netdev_priv(netdev);
911 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000912 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000913 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000914 u8 *eeprom_buff;
915 u16 i, sectors;
916 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000917 u32 magic;
918
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000919#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000920 if (eeprom->len == 0)
921 return -EINVAL;
922
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000923 /* check for NVMUpdate access method */
924 magic = hw->vendor_id | (hw->device_id << 16);
925 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000926 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000927 int errno;
928
929 /* make sure it is the right magic for NVMUpdate */
930 if ((eeprom->magic >> 16) != hw->device_id)
931 return -EINVAL;
932
Shannon Nelsonc150a502014-11-13 08:23:13 +0000933 cmd = (struct i40e_nvm_access *)eeprom;
934 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000935 if (ret_val &&
936 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
937 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000938 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000939 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
940 ret_val, hw->aq.asq_last_status, errno,
941 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
942 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000943
944 return errno;
945 }
946
947 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000948 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
949
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000950 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000951 if (!eeprom_buff)
952 return -ENOMEM;
953
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000954 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
955 if (ret_val) {
956 dev_info(&pf->pdev->dev,
957 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
958 ret_val, hw->aq.asq_last_status);
959 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000960 }
961
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000962 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
963 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
964 len = I40E_NVM_SECTOR_SIZE;
965 last = false;
966 for (i = 0; i < sectors; i++) {
967 if (i == (sectors - 1)) {
968 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
969 last = true;
970 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000971 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
972 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000973 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000974 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000975 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000976 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000977 "read NVM failed, invalid offset 0x%x\n",
978 offset);
979 break;
980 } else if (ret_val &&
981 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
982 dev_info(&pf->pdev->dev,
983 "read NVM failed, access, offset 0x%x\n",
984 offset);
985 break;
986 } else if (ret_val) {
987 dev_info(&pf->pdev->dev,
988 "read NVM failed offset %d err=%d status=0x%x\n",
989 offset, ret_val, hw->aq.asq_last_status);
990 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000991 }
992 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000993
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000994 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000995 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000996free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000997 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000998 return ret_val;
999}
1000
1001static int i40e_get_eeprom_len(struct net_device *netdev)
1002{
1003 struct i40e_netdev_priv *np = netdev_priv(netdev);
1004 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001005 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001006
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001007 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1008 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1009 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1010 /* register returns value in power of 2, 64Kbyte chunks. */
1011 val = (64 * 1024) * (1 << val);
1012 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001013}
1014
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001015static int i40e_set_eeprom(struct net_device *netdev,
1016 struct ethtool_eeprom *eeprom, u8 *bytes)
1017{
1018 struct i40e_netdev_priv *np = netdev_priv(netdev);
1019 struct i40e_hw *hw = &np->vsi->back->hw;
1020 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001021 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001022 int ret_val = 0;
1023 int errno;
1024 u32 magic;
1025
1026 /* normal ethtool set_eeprom is not supported */
1027 magic = hw->vendor_id | (hw->device_id << 16);
1028 if (eeprom->magic == magic)
1029 return -EOPNOTSUPP;
1030
1031 /* check for NVMUpdate access method */
1032 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1033 return -EINVAL;
1034
1035 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1036 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1037 return -EBUSY;
1038
Shannon Nelsonc150a502014-11-13 08:23:13 +00001039 cmd = (struct i40e_nvm_access *)eeprom;
1040 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001041 if (ret_val &&
1042 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1043 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1044 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001045 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001046 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1047 ret_val, hw->aq.asq_last_status, errno,
1048 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1049 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001050
1051 return errno;
1052}
1053
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001054static void i40e_get_drvinfo(struct net_device *netdev,
1055 struct ethtool_drvinfo *drvinfo)
1056{
1057 struct i40e_netdev_priv *np = netdev_priv(netdev);
1058 struct i40e_vsi *vsi = np->vsi;
1059 struct i40e_pf *pf = vsi->back;
1060
1061 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1062 strlcpy(drvinfo->version, i40e_driver_version_str,
1063 sizeof(drvinfo->version));
1064 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1065 sizeof(drvinfo->fw_version));
1066 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1067 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001068 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001069}
1070
1071static void i40e_get_ringparam(struct net_device *netdev,
1072 struct ethtool_ringparam *ring)
1073{
1074 struct i40e_netdev_priv *np = netdev_priv(netdev);
1075 struct i40e_pf *pf = np->vsi->back;
1076 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1077
1078 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1079 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1080 ring->rx_mini_max_pending = 0;
1081 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001082 ring->rx_pending = vsi->rx_rings[0]->count;
1083 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001084 ring->rx_mini_pending = 0;
1085 ring->rx_jumbo_pending = 0;
1086}
1087
1088static int i40e_set_ringparam(struct net_device *netdev,
1089 struct ethtool_ringparam *ring)
1090{
1091 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1092 struct i40e_netdev_priv *np = netdev_priv(netdev);
1093 struct i40e_vsi *vsi = np->vsi;
1094 struct i40e_pf *pf = vsi->back;
1095 u32 new_rx_count, new_tx_count;
1096 int i, err = 0;
1097
1098 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1099 return -EINVAL;
1100
Shannon Nelson1fa18372013-11-20 10:03:08 +00001101 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1102 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1103 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1104 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1105 netdev_info(netdev,
1106 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1107 ring->tx_pending, ring->rx_pending,
1108 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1109 return -EINVAL;
1110 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001111
Shannon Nelson1fa18372013-11-20 10:03:08 +00001112 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1113 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001114
1115 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001116 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1117 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001118 return 0;
1119
1120 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1121 usleep_range(1000, 2000);
1122
1123 if (!netif_running(vsi->netdev)) {
1124 /* simple case - set for the next time the netdev is started */
1125 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001126 vsi->tx_rings[i]->count = new_tx_count;
1127 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001128 }
1129 goto done;
1130 }
1131
1132 /* We can't just free everything and then setup again,
1133 * because the ISRs in MSI-X mode get passed pointers
1134 * to the Tx and Rx ring structs.
1135 */
1136
1137 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001138 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001139 netdev_info(netdev,
1140 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001141 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001142 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1143 sizeof(struct i40e_ring), GFP_KERNEL);
1144 if (!tx_rings) {
1145 err = -ENOMEM;
1146 goto done;
1147 }
1148
1149 for (i = 0; i < vsi->num_queue_pairs; i++) {
1150 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001151 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001152 tx_rings[i].count = new_tx_count;
1153 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1154 if (err) {
1155 while (i) {
1156 i--;
1157 i40e_free_tx_resources(&tx_rings[i]);
1158 }
1159 kfree(tx_rings);
1160 tx_rings = NULL;
1161
1162 goto done;
1163 }
1164 }
1165 }
1166
1167 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001168 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001169 netdev_info(netdev,
1170 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001171 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001172 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1173 sizeof(struct i40e_ring), GFP_KERNEL);
1174 if (!rx_rings) {
1175 err = -ENOMEM;
1176 goto free_tx;
1177 }
1178
1179 for (i = 0; i < vsi->num_queue_pairs; i++) {
1180 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001181 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001182 rx_rings[i].count = new_rx_count;
1183 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1184 if (err) {
1185 while (i) {
1186 i--;
1187 i40e_free_rx_resources(&rx_rings[i]);
1188 }
1189 kfree(rx_rings);
1190 rx_rings = NULL;
1191
1192 goto free_tx;
1193 }
1194 }
1195 }
1196
1197 /* Bring interface down, copy in the new ring info,
1198 * then restore the interface
1199 */
1200 i40e_down(vsi);
1201
1202 if (tx_rings) {
1203 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001204 i40e_free_tx_resources(vsi->tx_rings[i]);
1205 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001206 }
1207 kfree(tx_rings);
1208 tx_rings = NULL;
1209 }
1210
1211 if (rx_rings) {
1212 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001213 i40e_free_rx_resources(vsi->rx_rings[i]);
1214 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001215 }
1216 kfree(rx_rings);
1217 rx_rings = NULL;
1218 }
1219
1220 i40e_up(vsi);
1221
1222free_tx:
1223 /* error cleanup if the Rx allocations failed after getting Tx */
1224 if (tx_rings) {
1225 for (i = 0; i < vsi->num_queue_pairs; i++)
1226 i40e_free_tx_resources(&tx_rings[i]);
1227 kfree(tx_rings);
1228 tx_rings = NULL;
1229 }
1230
1231done:
1232 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1233
1234 return err;
1235}
1236
1237static int i40e_get_sset_count(struct net_device *netdev, int sset)
1238{
1239 struct i40e_netdev_priv *np = netdev_priv(netdev);
1240 struct i40e_vsi *vsi = np->vsi;
1241 struct i40e_pf *pf = vsi->back;
1242
1243 switch (sset) {
1244 case ETH_SS_TEST:
1245 return I40E_TEST_LEN;
1246 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001247 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001248 int len = I40E_PF_STATS_LEN(netdev);
1249
1250 if (pf->lan_veb != I40E_NO_VEB)
1251 len += I40E_VEB_STATS_LEN;
1252 return len;
1253 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001254 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001255 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001256 case ETH_SS_PRIV_FLAGS:
1257 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001258 default:
1259 return -EOPNOTSUPP;
1260 }
1261}
1262
1263static void i40e_get_ethtool_stats(struct net_device *netdev,
1264 struct ethtool_stats *stats, u64 *data)
1265{
1266 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001267 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001268 struct i40e_vsi *vsi = np->vsi;
1269 struct i40e_pf *pf = vsi->back;
1270 int i = 0;
1271 char *p;
1272 int j;
1273 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001274 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001275
1276 i40e_update_stats(vsi);
1277
1278 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1279 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1280 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1281 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1282 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001283 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1284 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1285 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1286 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1287 }
Vasu Dev38e00432014-08-01 13:27:03 -07001288#ifdef I40E_FCOE
1289 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1290 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1291 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1292 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1293 }
1294#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001295 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001296 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001297 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001298
1299 if (!tx_ring)
1300 continue;
1301
1302 /* process Tx ring statistics */
1303 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001304 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001305 data[i] = tx_ring->stats.packets;
1306 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001307 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001308 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001309
1310 /* Rx ring is the 2nd half of the queue pair */
1311 rx_ring = &tx_ring[1];
1312 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001313 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001314 data[i] = rx_ring->stats.packets;
1315 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001316 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001317 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001318 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001319 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001320 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001321 return;
1322
1323 if (pf->lan_veb != I40E_NO_VEB) {
1324 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1325 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1326 p = (char *)veb;
1327 p += i40e_gstrings_veb_stats[j].stat_offset;
1328 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1329 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001330 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001332 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1333 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1334 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1335 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1336 }
1337 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1338 data[i++] = pf->stats.priority_xon_tx[j];
1339 data[i++] = pf->stats.priority_xoff_tx[j];
1340 }
1341 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1342 data[i++] = pf->stats.priority_xon_rx[j];
1343 data[i++] = pf->stats.priority_xoff_rx[j];
1344 }
1345 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1346 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001347}
1348
1349static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1350 u8 *data)
1351{
1352 struct i40e_netdev_priv *np = netdev_priv(netdev);
1353 struct i40e_vsi *vsi = np->vsi;
1354 struct i40e_pf *pf = vsi->back;
1355 char *p = (char *)data;
1356 int i;
1357
1358 switch (stringset) {
1359 case ETH_SS_TEST:
1360 for (i = 0; i < I40E_TEST_LEN; i++) {
1361 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1362 data += ETH_GSTRING_LEN;
1363 }
1364 break;
1365 case ETH_SS_STATS:
1366 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1367 snprintf(p, ETH_GSTRING_LEN, "%s",
1368 i40e_gstrings_net_stats[i].stat_string);
1369 p += ETH_GSTRING_LEN;
1370 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001371 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1372 snprintf(p, ETH_GSTRING_LEN, "%s",
1373 i40e_gstrings_misc_stats[i].stat_string);
1374 p += ETH_GSTRING_LEN;
1375 }
Vasu Dev38e00432014-08-01 13:27:03 -07001376#ifdef I40E_FCOE
1377 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1378 snprintf(p, ETH_GSTRING_LEN, "%s",
1379 i40e_gstrings_fcoe_stats[i].stat_string);
1380 p += ETH_GSTRING_LEN;
1381 }
1382#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001383 for (i = 0; i < vsi->num_queue_pairs; i++) {
1384 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1385 p += ETH_GSTRING_LEN;
1386 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1387 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001388 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1389 p += ETH_GSTRING_LEN;
1390 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1391 p += ETH_GSTRING_LEN;
1392 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001393 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001394 return;
1395
1396 if (pf->lan_veb != I40E_NO_VEB) {
1397 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1398 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1399 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400 p += ETH_GSTRING_LEN;
1401 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001402 }
1403 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1404 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1405 i40e_gstrings_stats[i].stat_string);
1406 p += ETH_GSTRING_LEN;
1407 }
1408 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1409 snprintf(p, ETH_GSTRING_LEN,
1410 "port.tx_priority_%u_xon", i);
1411 p += ETH_GSTRING_LEN;
1412 snprintf(p, ETH_GSTRING_LEN,
1413 "port.tx_priority_%u_xoff", i);
1414 p += ETH_GSTRING_LEN;
1415 }
1416 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1417 snprintf(p, ETH_GSTRING_LEN,
1418 "port.rx_priority_%u_xon", i);
1419 p += ETH_GSTRING_LEN;
1420 snprintf(p, ETH_GSTRING_LEN,
1421 "port.rx_priority_%u_xoff", i);
1422 p += ETH_GSTRING_LEN;
1423 }
1424 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1425 snprintf(p, ETH_GSTRING_LEN,
1426 "port.rx_priority_%u_xon_2_xoff", i);
1427 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001428 }
1429 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1430 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001431 case ETH_SS_PRIV_FLAGS:
1432 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1433 memcpy(data, i40e_priv_flags_strings[i],
1434 ETH_GSTRING_LEN);
1435 data += ETH_GSTRING_LEN;
1436 }
1437 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001438 default:
1439 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001440 }
1441}
1442
1443static int i40e_get_ts_info(struct net_device *dev,
1444 struct ethtool_ts_info *info)
1445{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001446 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1447
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001448 /* only report HW timestamping if PTP is enabled */
1449 if (!(pf->flags & I40E_FLAG_PTP))
1450 return ethtool_op_get_ts_info(dev, info);
1451
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001452 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1453 SOF_TIMESTAMPING_RX_SOFTWARE |
1454 SOF_TIMESTAMPING_SOFTWARE |
1455 SOF_TIMESTAMPING_TX_HARDWARE |
1456 SOF_TIMESTAMPING_RX_HARDWARE |
1457 SOF_TIMESTAMPING_RAW_HARDWARE;
1458
1459 if (pf->ptp_clock)
1460 info->phc_index = ptp_clock_index(pf->ptp_clock);
1461 else
1462 info->phc_index = -1;
1463
1464 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1465
1466 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1467 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1468 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1469 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1470 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1471 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1472 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1473 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1474 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1475 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1476 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1477 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1478
1479 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480}
1481
Shannon Nelson7b086392013-11-20 10:02:59 +00001482static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483{
Shannon Nelson7b086392013-11-20 10:02:59 +00001484 struct i40e_netdev_priv *np = netdev_priv(netdev);
1485 struct i40e_pf *pf = np->vsi->back;
1486
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001487 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001488 if (i40e_get_link_status(&pf->hw))
1489 *data = 0;
1490 else
1491 *data = 1;
1492
1493 return *data;
1494}
1495
Shannon Nelson7b086392013-11-20 10:02:59 +00001496static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497{
Shannon Nelson7b086392013-11-20 10:02:59 +00001498 struct i40e_netdev_priv *np = netdev_priv(netdev);
1499 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001501 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001502 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001503
Shannon Nelson7b086392013-11-20 10:02:59 +00001504 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505}
1506
Shannon Nelson7b086392013-11-20 10:02:59 +00001507static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001508{
Shannon Nelson7b086392013-11-20 10:02:59 +00001509 struct i40e_netdev_priv *np = netdev_priv(netdev);
1510 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001511
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001512 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001513 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514
Shannon Nelson4443ec92014-11-13 08:23:12 +00001515 /* forcebly clear the NVM Update state machine */
1516 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1517
Shannon Nelson7b086392013-11-20 10:02:59 +00001518 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519}
1520
Shannon Nelson7b086392013-11-20 10:02:59 +00001521static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522{
Shannon Nelson7b086392013-11-20 10:02:59 +00001523 struct i40e_netdev_priv *np = netdev_priv(netdev);
1524 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001525 u16 swc_old = pf->sw_int_count;
1526
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001527 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001528 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1529 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001530 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1531 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1532 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1533 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001534 usleep_range(1000, 2000);
1535 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536
1537 return *data;
1538}
1539
Shannon Nelson7b086392013-11-20 10:02:59 +00001540static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001541{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001542 struct i40e_netdev_priv *np = netdev_priv(netdev);
1543 struct i40e_pf *pf = np->vsi->back;
1544
1545 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001546 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001547
1548 return *data;
1549}
1550
Greg Rosee17bc412015-04-16 20:05:59 -04001551static inline bool i40e_active_vfs(struct i40e_pf *pf)
1552{
1553 struct i40e_vf *vfs = pf->vf;
1554 int i;
1555
1556 for (i = 0; i < pf->num_alloc_vfs; i++)
1557 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1558 return true;
1559 return false;
1560}
1561
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562static void i40e_diag_test(struct net_device *netdev,
1563 struct ethtool_test *eth_test, u64 *data)
1564{
1565 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001566 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001567 struct i40e_pf *pf = np->vsi->back;
1568
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001569 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1570 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001571 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001572
Shannon Nelsonf551b432013-11-26 10:49:12 +00001573 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001574
1575 if (i40e_active_vfs(pf)) {
1576 dev_warn(&pf->pdev->dev,
1577 "Please take active VFS offline and restart the adapter before running NIC diagnostics\n");
1578 data[I40E_ETH_TEST_REG] = 1;
1579 data[I40E_ETH_TEST_EEPROM] = 1;
1580 data[I40E_ETH_TEST_INTR] = 1;
1581 data[I40E_ETH_TEST_LOOPBACK] = 1;
1582 data[I40E_ETH_TEST_LINK] = 1;
1583 eth_test->flags |= ETH_TEST_FL_FAILED;
1584 clear_bit(__I40E_TESTING, &pf->state);
1585 goto skip_ol_tests;
1586 }
1587
Greg Rose5b86c5c2015-02-26 16:14:35 +00001588 /* If the device is online then take it offline */
1589 if (if_running)
1590 /* indicate we're in test mode */
1591 dev_close(netdev);
1592 else
1593 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001594
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595 /* Link test performed before hardware reset
1596 * so autoneg doesn't interfere with test result
1597 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001598 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001599 eth_test->flags |= ETH_TEST_FL_FAILED;
1600
Shannon Nelson7b086392013-11-20 10:02:59 +00001601 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001602 eth_test->flags |= ETH_TEST_FL_FAILED;
1603
Shannon Nelson7b086392013-11-20 10:02:59 +00001604 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001605 eth_test->flags |= ETH_TEST_FL_FAILED;
1606
Shannon Nelson7b086392013-11-20 10:02:59 +00001607 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608 eth_test->flags |= ETH_TEST_FL_FAILED;
1609
Shannon Nelsonf551b432013-11-26 10:49:12 +00001610 /* run reg test last, a reset is required after it */
1611 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1612 eth_test->flags |= ETH_TEST_FL_FAILED;
1613
1614 clear_bit(__I40E_TESTING, &pf->state);
1615 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001616
1617 if (if_running)
1618 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001620 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001621 netif_info(pf, drv, netdev, "online testing starting\n");
1622
Shannon Nelson7b086392013-11-20 10:02:59 +00001623 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624 eth_test->flags |= ETH_TEST_FL_FAILED;
1625
1626 /* Offline only tests, not run in online; pass by default */
1627 data[I40E_ETH_TEST_REG] = 0;
1628 data[I40E_ETH_TEST_EEPROM] = 0;
1629 data[I40E_ETH_TEST_INTR] = 0;
1630 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001631 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001632
Greg Rosee17bc412015-04-16 20:05:59 -04001633skip_ol_tests:
1634
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001635 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001636}
1637
1638static void i40e_get_wol(struct net_device *netdev,
1639 struct ethtool_wolinfo *wol)
1640{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001641 struct i40e_netdev_priv *np = netdev_priv(netdev);
1642 struct i40e_pf *pf = np->vsi->back;
1643 struct i40e_hw *hw = &pf->hw;
1644 u16 wol_nvm_bits;
1645
1646 /* NVM bit on means WoL disabled for the port */
1647 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001648 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001649 wol->supported = 0;
1650 wol->wolopts = 0;
1651 } else {
1652 wol->supported = WAKE_MAGIC;
1653 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1654 }
1655}
1656
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001657/**
1658 * i40e_set_wol - set the WakeOnLAN configuration
1659 * @netdev: the netdev in question
1660 * @wol: the ethtool WoL setting data
1661 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001662static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1663{
1664 struct i40e_netdev_priv *np = netdev_priv(netdev);
1665 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001666 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001667 struct i40e_hw *hw = &pf->hw;
1668 u16 wol_nvm_bits;
1669
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001670 /* WoL not supported if this isn't the controlling PF on the port */
1671 if (hw->partition_id != 1) {
1672 i40e_partition_setting_complaint(pf);
1673 return -EOPNOTSUPP;
1674 }
1675
1676 if (vsi != pf->vsi[pf->lan_vsi])
1677 return -EOPNOTSUPP;
1678
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001679 /* NVM bit on means WoL disabled for the port */
1680 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1681 if (((1 << hw->port) & wol_nvm_bits))
1682 return -EOPNOTSUPP;
1683
1684 /* only magic packet is supported */
1685 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1686 return -EOPNOTSUPP;
1687
1688 /* is this a new value? */
1689 if (pf->wol_en != !!wol->wolopts) {
1690 pf->wol_en = !!wol->wolopts;
1691 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1692 }
1693
1694 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695}
1696
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697static int i40e_set_phys_id(struct net_device *netdev,
1698 enum ethtool_phys_id_state state)
1699{
1700 struct i40e_netdev_priv *np = netdev_priv(netdev);
1701 struct i40e_pf *pf = np->vsi->back;
1702 struct i40e_hw *hw = &pf->hw;
1703 int blink_freq = 2;
1704
1705 switch (state) {
1706 case ETHTOOL_ID_ACTIVE:
1707 pf->led_status = i40e_led_get(hw);
1708 return blink_freq;
1709 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001710 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001711 break;
1712 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001713 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714 break;
1715 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001716 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001717 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001718 default:
1719 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001720 }
1721
1722 return 0;
1723}
1724
1725/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1726 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1727 * 125us (8000 interrupts per second) == ITR(62)
1728 */
1729
1730static int i40e_get_coalesce(struct net_device *netdev,
1731 struct ethtool_coalesce *ec)
1732{
1733 struct i40e_netdev_priv *np = netdev_priv(netdev);
1734 struct i40e_vsi *vsi = np->vsi;
1735
1736 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1737 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1738
1739 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001740 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741
1742 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001743 ec->use_adaptive_tx_coalesce = 1;
1744
1745 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1746 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001747
1748 return 0;
1749}
1750
1751static int i40e_set_coalesce(struct net_device *netdev,
1752 struct ethtool_coalesce *ec)
1753{
1754 struct i40e_netdev_priv *np = netdev_priv(netdev);
1755 struct i40e_q_vector *q_vector;
1756 struct i40e_vsi *vsi = np->vsi;
1757 struct i40e_pf *pf = vsi->back;
1758 struct i40e_hw *hw = &pf->hw;
1759 u16 vector;
1760 int i;
1761
1762 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1763 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1764
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001765 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001766 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001767 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001768 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001769 } else if (ec->rx_coalesce_usecs == 0) {
1770 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001771 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001772 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 +00001773 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001774 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001775 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001776 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001777
Mitch Williams32f5f542014-04-04 04:43:10 +00001778 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001779 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001780 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001781 } else if (ec->tx_coalesce_usecs == 0) {
1782 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001783 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001784 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 +00001785 } else {
1786 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001787 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001788 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001789 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001790
1791 if (ec->use_adaptive_rx_coalesce)
1792 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1793 else
1794 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1795
1796 if (ec->use_adaptive_tx_coalesce)
1797 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1798 else
1799 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001800
Alexander Duyck493fb302013-09-28 07:01:44 +00001801 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1802 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001803 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1804 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1805 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1806 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1807 i40e_flush(hw);
1808 }
1809
1810 return 0;
1811}
1812
1813/**
1814 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1815 * @pf: pointer to the physical function struct
1816 * @cmd: ethtool rxnfc command
1817 *
1818 * Returns Success if the flow is supported, else Invalid Input.
1819 **/
1820static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1821{
1822 cmd->data = 0;
1823
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001824 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1825 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1826 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1827 return 0;
1828 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829 /* Report default options for RSS on i40e */
1830 switch (cmd->flow_type) {
1831 case TCP_V4_FLOW:
1832 case UDP_V4_FLOW:
1833 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1834 /* fall through to add IP fields */
1835 case SCTP_V4_FLOW:
1836 case AH_ESP_V4_FLOW:
1837 case AH_V4_FLOW:
1838 case ESP_V4_FLOW:
1839 case IPV4_FLOW:
1840 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1841 break;
1842 case TCP_V6_FLOW:
1843 case UDP_V6_FLOW:
1844 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1845 /* fall through to add IP fields */
1846 case SCTP_V6_FLOW:
1847 case AH_ESP_V6_FLOW:
1848 case AH_V6_FLOW:
1849 case ESP_V6_FLOW:
1850 case IPV6_FLOW:
1851 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1852 break;
1853 default:
1854 return -EINVAL;
1855 }
1856
1857 return 0;
1858}
1859
1860/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001861 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1862 * @pf: Pointer to the physical function struct
1863 * @cmd: The command to get or set Rx flow classification rules
1864 * @rule_locs: Array of used rule locations
1865 *
1866 * This function populates both the total and actual rule count of
1867 * the ethtool flow classification command
1868 *
1869 * Returns 0 on success or -EMSGSIZE if entry not found
1870 **/
1871static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1872 struct ethtool_rxnfc *cmd,
1873 u32 *rule_locs)
1874{
1875 struct i40e_fdir_filter *rule;
1876 struct hlist_node *node2;
1877 int cnt = 0;
1878
1879 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001880 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001881
1882 hlist_for_each_entry_safe(rule, node2,
1883 &pf->fdir_filter_list, fdir_node) {
1884 if (cnt == cmd->rule_cnt)
1885 return -EMSGSIZE;
1886
1887 rule_locs[cnt] = rule->fd_id;
1888 cnt++;
1889 }
1890
1891 cmd->rule_cnt = cnt;
1892
1893 return 0;
1894}
1895
1896/**
1897 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1898 * @pf: Pointer to the physical function struct
1899 * @cmd: The command to get or set Rx flow classification rules
1900 *
1901 * This function looks up a filter based on the Rx flow classification
1902 * command and fills the flow spec info for it if found
1903 *
1904 * Returns 0 on success or -EINVAL if filter not found
1905 **/
1906static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1907 struct ethtool_rxnfc *cmd)
1908{
1909 struct ethtool_rx_flow_spec *fsp =
1910 (struct ethtool_rx_flow_spec *)&cmd->fs;
1911 struct i40e_fdir_filter *rule = NULL;
1912 struct hlist_node *node2;
1913
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001914 hlist_for_each_entry_safe(rule, node2,
1915 &pf->fdir_filter_list, fdir_node) {
1916 if (fsp->location <= rule->fd_id)
1917 break;
1918 }
1919
1920 if (!rule || fsp->location != rule->fd_id)
1921 return -EINVAL;
1922
1923 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001924 if (fsp->flow_type == IP_USER_FLOW) {
1925 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1926 fsp->h_u.usr_ip4_spec.proto = 0;
1927 fsp->m_u.usr_ip4_spec.proto = 0;
1928 }
1929
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001930 /* Reverse the src and dest notion, since the HW views them from
1931 * Tx perspective where as the user expects it from Rx filter view.
1932 */
1933 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1934 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1935 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1936 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001937
1938 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1939 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1940 else
1941 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001942
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04001943 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1944 struct i40e_vsi *vsi;
1945
1946 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1947 if (vsi && vsi->type == I40E_VSI_SRIOV) {
1948 fsp->h_ext.data[1] = htonl(vsi->vf_id);
1949 fsp->m_ext.data[1] = htonl(0x1);
1950 }
1951 }
1952
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001953 return 0;
1954}
1955
1956/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001957 * i40e_get_rxnfc - command to get RX flow classification rules
1958 * @netdev: network interface device structure
1959 * @cmd: ethtool rxnfc command
1960 *
1961 * Returns Success if the command is supported.
1962 **/
1963static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1964 u32 *rule_locs)
1965{
1966 struct i40e_netdev_priv *np = netdev_priv(netdev);
1967 struct i40e_vsi *vsi = np->vsi;
1968 struct i40e_pf *pf = vsi->back;
1969 int ret = -EOPNOTSUPP;
1970
1971 switch (cmd->cmd) {
1972 case ETHTOOL_GRXRINGS:
1973 cmd->data = vsi->alloc_queue_pairs;
1974 ret = 0;
1975 break;
1976 case ETHTOOL_GRXFH:
1977 ret = i40e_get_rss_hash_opts(pf, cmd);
1978 break;
1979 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001980 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001981 /* report total rule count */
1982 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001983 ret = 0;
1984 break;
1985 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001986 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001987 break;
1988 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001989 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1990 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001991 default:
1992 break;
1993 }
1994
1995 return ret;
1996}
1997
1998/**
1999 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2000 * @pf: pointer to the physical function struct
2001 * @cmd: ethtool rxnfc command
2002 *
2003 * Returns Success if the flow input set is supported.
2004 **/
2005static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2006{
2007 struct i40e_hw *hw = &pf->hw;
2008 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2009 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2010
2011 /* RSS does not support anything other than hashing
2012 * to queues on src and dst IPs and ports
2013 */
2014 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2015 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2016 return -EINVAL;
2017
2018 /* We need at least the IP SRC and DEST fields for hashing */
2019 if (!(nfc->data & RXH_IP_SRC) ||
2020 !(nfc->data & RXH_IP_DST))
2021 return -EINVAL;
2022
2023 switch (nfc->flow_type) {
2024 case TCP_V4_FLOW:
2025 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2026 case 0:
2027 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2028 break;
2029 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2030 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2031 break;
2032 default:
2033 return -EINVAL;
2034 }
2035 break;
2036 case TCP_V6_FLOW:
2037 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2038 case 0:
2039 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2040 break;
2041 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2042 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2043 break;
2044 default:
2045 return -EINVAL;
2046 }
2047 break;
2048 case UDP_V4_FLOW:
2049 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2050 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002051 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2052 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002053 break;
2054 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002055 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2056 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002057 break;
2058 default:
2059 return -EINVAL;
2060 }
2061 break;
2062 case UDP_V6_FLOW:
2063 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2064 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002065 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2066 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002067 break;
2068 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002069 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2070 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002071 break;
2072 default:
2073 return -EINVAL;
2074 }
2075 break;
2076 case AH_ESP_V4_FLOW:
2077 case AH_V4_FLOW:
2078 case ESP_V4_FLOW:
2079 case SCTP_V4_FLOW:
2080 if ((nfc->data & RXH_L4_B_0_1) ||
2081 (nfc->data & RXH_L4_B_2_3))
2082 return -EINVAL;
2083 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2084 break;
2085 case AH_ESP_V6_FLOW:
2086 case AH_V6_FLOW:
2087 case ESP_V6_FLOW:
2088 case SCTP_V6_FLOW:
2089 if ((nfc->data & RXH_L4_B_0_1) ||
2090 (nfc->data & RXH_L4_B_2_3))
2091 return -EINVAL;
2092 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2093 break;
2094 case IPV4_FLOW:
2095 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2096 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2097 break;
2098 case IPV6_FLOW:
2099 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2100 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2101 break;
2102 default:
2103 return -EINVAL;
2104 }
2105
2106 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2107 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2108 i40e_flush(hw);
2109
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002110 /* Save setting for future output/update */
2111 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2112
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002113 return 0;
2114}
2115
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002116/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002117 * i40e_match_fdir_input_set - Match a new filter against an existing one
2118 * @rule: The filter already added
2119 * @input: The new filter to comapre against
2120 *
2121 * Returns true if the two input set match
2122 **/
2123static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2124 struct i40e_fdir_filter *input)
2125{
2126 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2127 (rule->src_ip[0] != input->src_ip[0]) ||
2128 (rule->dst_port != input->dst_port) ||
2129 (rule->src_port != input->src_port))
2130 return false;
2131 return true;
2132}
2133
2134/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002135 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2136 * @vsi: Pointer to the targeted VSI
2137 * @input: The filter to update or NULL to indicate deletion
2138 * @sw_idx: Software index to the filter
2139 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002141 * This function updates (or deletes) a Flow Director entry from
2142 * the hlist of the corresponding PF
2143 *
2144 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002145 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002146static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2147 struct i40e_fdir_filter *input,
2148 u16 sw_idx,
2149 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002150{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002151 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002152 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002153 struct hlist_node *node2;
2154 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002155
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002156 parent = NULL;
2157 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002158
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002159 hlist_for_each_entry_safe(rule, node2,
2160 &pf->fdir_filter_list, fdir_node) {
2161 /* hash found, or no matching entry */
2162 if (rule->fd_id >= sw_idx)
2163 break;
2164 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002165 }
2166
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002167 /* if there is an old rule occupying our place remove it */
2168 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002169 if (input && !i40e_match_fdir_input_set(rule, input))
2170 err = i40e_add_del_fdir(vsi, rule, false);
2171 else if (!input)
2172 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002173 hlist_del(&rule->fdir_node);
2174 kfree(rule);
2175 pf->fdir_pf_active_filters--;
2176 }
2177
2178 /* If no input this was a delete, err should be 0 if a rule was
2179 * successfully found and removed from the list else -EINVAL
2180 */
2181 if (!input)
2182 return err;
2183
2184 /* initialize node and set software index */
2185 INIT_HLIST_NODE(&input->fdir_node);
2186
2187 /* add filter to the list */
2188 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002189 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002190 else
2191 hlist_add_head(&input->fdir_node,
2192 &pf->fdir_filter_list);
2193
2194 /* update counts */
2195 pf->fdir_pf_active_filters++;
2196
2197 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002198}
2199
2200/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002201 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2202 * @vsi: Pointer to the targeted VSI
2203 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002205 * The function removes a Flow Director filter entry from the
2206 * hlist of the corresponding PF
2207 *
2208 * Returns 0 on success
2209 */
2210static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2211 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002213 struct ethtool_rx_flow_spec *fsp =
2214 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002215 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002216 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002217
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002218 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2219 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2220 return -EBUSY;
2221
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002222 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2223 return -EBUSY;
2224
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002225 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002226
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002227 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002228 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229}
2230
2231/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002232 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002233 * @vsi: pointer to the targeted VSI
2234 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002235 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002236 * Add Flow Director filters for a specific flow spec based on their
2237 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002238 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002239static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2240 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002241{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002242 struct ethtool_rx_flow_spec *fsp;
2243 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002244 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002245 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002246 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002247
2248 if (!vsi)
2249 return -EINVAL;
2250
2251 pf = vsi->back;
2252
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002253 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2254 return -EOPNOTSUPP;
2255
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002256 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002257 return -ENOSPC;
2258
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002259 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2260 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2261 return -EBUSY;
2262
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002263 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2264 return -EBUSY;
2265
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002266 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2267
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002268 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2269 pf->hw.func_caps.fd_filters_guaranteed)) {
2270 return -EINVAL;
2271 }
2272
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002273 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2274 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275 return -EINVAL;
2276
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002277 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002278
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002279 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002280 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002281
2282 input->fd_id = fsp->location;
2283
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002284 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2285 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2286 else
2287 input->dest_ctl =
2288 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2289
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002290 input->q_index = fsp->ring_cookie;
2291 input->flex_off = 0;
2292 input->pctype = 0;
2293 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002294 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002295 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002296 input->flow_type = fsp->flow_type;
2297 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002298
2299 /* Reverse the src and dest notion, since the HW expects them to be from
2300 * Tx perspective where as the input from user is from Rx filter view.
2301 */
2302 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2303 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2304 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2305 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002306
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002307 if (ntohl(fsp->m_ext.data[1])) {
2308 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2309 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2310 goto free_input;
2311 }
2312 vf_id = ntohl(fsp->h_ext.data[1]);
2313 /* Find vsi id from vf id and override dest vsi */
2314 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2315 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2316 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2317 goto free_input;
2318 }
2319 }
2320
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002321 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002322free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002323 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002324 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002325 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002326 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002327
2328 return ret;
2329}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002330
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002331/**
2332 * i40e_set_rxnfc - command to set RX flow classification rules
2333 * @netdev: network interface device structure
2334 * @cmd: ethtool rxnfc command
2335 *
2336 * Returns Success if the command is supported.
2337 **/
2338static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2339{
2340 struct i40e_netdev_priv *np = netdev_priv(netdev);
2341 struct i40e_vsi *vsi = np->vsi;
2342 struct i40e_pf *pf = vsi->back;
2343 int ret = -EOPNOTSUPP;
2344
2345 switch (cmd->cmd) {
2346 case ETHTOOL_SRXFH:
2347 ret = i40e_set_rss_hash_opt(pf, cmd);
2348 break;
2349 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002350 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002351 break;
2352 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002353 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002354 break;
2355 default:
2356 break;
2357 }
2358
2359 return ret;
2360}
2361
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002362/**
2363 * i40e_max_channels - get Max number of combined channels supported
2364 * @vsi: vsi pointer
2365 **/
2366static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2367{
2368 /* TODO: This code assumes DCB and FD is disabled for now. */
2369 return vsi->alloc_queue_pairs;
2370}
2371
2372/**
2373 * i40e_get_channels - Get the current channels enabled and max supported etc.
2374 * @netdev: network interface device structure
2375 * @ch: ethtool channels structure
2376 *
2377 * We don't support separate tx and rx queues as channels. The other count
2378 * represents how many queues are being used for control. max_combined counts
2379 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2380 * q_vectors since we support a lot more queue pairs than q_vectors.
2381 **/
2382static void i40e_get_channels(struct net_device *dev,
2383 struct ethtool_channels *ch)
2384{
2385 struct i40e_netdev_priv *np = netdev_priv(dev);
2386 struct i40e_vsi *vsi = np->vsi;
2387 struct i40e_pf *pf = vsi->back;
2388
2389 /* report maximum channels */
2390 ch->max_combined = i40e_max_channels(vsi);
2391
2392 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002393 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002394 ch->max_other = ch->other_count;
2395
2396 /* Note: This code assumes DCB is disabled for now. */
2397 ch->combined_count = vsi->num_queue_pairs;
2398}
2399
2400/**
2401 * i40e_set_channels - Set the new channels count.
2402 * @netdev: network interface device structure
2403 * @ch: ethtool channels structure
2404 *
2405 * The new channels count may not be the same as requested by the user
2406 * since it gets rounded down to a power of 2 value.
2407 **/
2408static int i40e_set_channels(struct net_device *dev,
2409 struct ethtool_channels *ch)
2410{
2411 struct i40e_netdev_priv *np = netdev_priv(dev);
2412 unsigned int count = ch->combined_count;
2413 struct i40e_vsi *vsi = np->vsi;
2414 struct i40e_pf *pf = vsi->back;
2415 int new_count;
2416
2417 /* We do not support setting channels for any other VSI at present */
2418 if (vsi->type != I40E_VSI_MAIN)
2419 return -EINVAL;
2420
2421 /* verify they are not requesting separate vectors */
2422 if (!count || ch->rx_count || ch->tx_count)
2423 return -EINVAL;
2424
2425 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002426 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002427 return -EINVAL;
2428
2429 /* verify the number of channels does not exceed hardware limits */
2430 if (count > i40e_max_channels(vsi))
2431 return -EINVAL;
2432
2433 /* update feature limits from largest to smallest supported values */
2434 /* TODO: Flow director limit, DCB etc */
2435
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002436 /* use rss_reconfig to rebuild with new queue count and update traffic
2437 * class queue mapping
2438 */
2439 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002440 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002441 return 0;
2442 else
2443 return -EINVAL;
2444}
2445
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002446#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2447/**
2448 * i40e_get_rxfh_key_size - get the RSS hash key size
2449 * @netdev: network interface device structure
2450 *
2451 * Returns the table size.
2452 **/
2453static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2454{
2455 return I40E_HKEY_ARRAY_SIZE;
2456}
2457
2458/**
2459 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2460 * @netdev: network interface device structure
2461 *
2462 * Returns the table size.
2463 **/
2464static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2465{
2466 return I40E_HLUT_ARRAY_SIZE;
2467}
2468
2469static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2470 u8 *hfunc)
2471{
2472 struct i40e_netdev_priv *np = netdev_priv(netdev);
2473 struct i40e_vsi *vsi = np->vsi;
2474 struct i40e_pf *pf = vsi->back;
2475 struct i40e_hw *hw = &pf->hw;
2476 u32 reg_val;
2477 int i, j;
2478
2479 if (hfunc)
2480 *hfunc = ETH_RSS_HASH_TOP;
2481
2482 if (!indir)
2483 return 0;
2484
2485 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2486 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2487 indir[j++] = reg_val & 0xff;
2488 indir[j++] = (reg_val >> 8) & 0xff;
2489 indir[j++] = (reg_val >> 16) & 0xff;
2490 indir[j++] = (reg_val >> 24) & 0xff;
2491 }
2492
2493 if (key) {
2494 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2495 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2496 key[j++] = (u8)(reg_val & 0xff);
2497 key[j++] = (u8)((reg_val >> 8) & 0xff);
2498 key[j++] = (u8)((reg_val >> 16) & 0xff);
2499 key[j++] = (u8)((reg_val >> 24) & 0xff);
2500 }
2501 }
2502 return 0;
2503}
2504
2505/**
2506 * i40e_set_rxfh - set the rx flow hash indirection table
2507 * @netdev: network interface device structure
2508 * @indir: indirection table
2509 * @key: hash key
2510 *
2511 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
2512 * returns 0 after programming the table.
2513 **/
2514static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2515 const u8 *key, const u8 hfunc)
2516{
2517 struct i40e_netdev_priv *np = netdev_priv(netdev);
2518 struct i40e_vsi *vsi = np->vsi;
2519 struct i40e_pf *pf = vsi->back;
2520 struct i40e_hw *hw = &pf->hw;
2521 u32 reg_val;
2522 int i, j;
2523
2524 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2525 return -EOPNOTSUPP;
2526
2527 if (!indir)
2528 return 0;
2529
2530 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2531 reg_val = indir[j++];
2532 reg_val |= indir[j++] << 8;
2533 reg_val |= indir[j++] << 16;
2534 reg_val |= indir[j++] << 24;
2535 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2536 }
2537
2538 if (key) {
2539 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2540 reg_val = key[j++];
2541 reg_val |= key[j++] << 8;
2542 reg_val |= key[j++] << 16;
2543 reg_val |= key[j++] << 24;
2544 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2545 }
2546 }
2547 return 0;
2548}
2549
Greg Rose7e45ab42015-02-06 08:52:19 +00002550/**
2551 * i40e_get_priv_flags - report device private flags
2552 * @dev: network interface device structure
2553 *
2554 * The get string set count and the string set should be matched for each
2555 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2556 * array.
2557 *
2558 * Returns a u32 bitmap of flags.
2559 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002560static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002561{
2562 struct i40e_netdev_priv *np = netdev_priv(dev);
2563 struct i40e_vsi *vsi = np->vsi;
2564 struct i40e_pf *pf = vsi->back;
2565 u32 ret_flags = 0;
2566
2567 ret_flags |= pf->hw.func_caps.npar_enable ?
2568 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2569
2570 return ret_flags;
2571}
2572
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002573static const struct ethtool_ops i40e_ethtool_ops = {
2574 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002575 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002576 .get_drvinfo = i40e_get_drvinfo,
2577 .get_regs_len = i40e_get_regs_len,
2578 .get_regs = i40e_get_regs,
2579 .nway_reset = i40e_nway_reset,
2580 .get_link = ethtool_op_get_link,
2581 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002582 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002583 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002584 .get_eeprom_len = i40e_get_eeprom_len,
2585 .get_eeprom = i40e_get_eeprom,
2586 .get_ringparam = i40e_get_ringparam,
2587 .set_ringparam = i40e_set_ringparam,
2588 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002589 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002590 .get_msglevel = i40e_get_msglevel,
2591 .set_msglevel = i40e_set_msglevel,
2592 .get_rxnfc = i40e_get_rxnfc,
2593 .set_rxnfc = i40e_set_rxnfc,
2594 .self_test = i40e_diag_test,
2595 .get_strings = i40e_get_strings,
2596 .set_phys_id = i40e_set_phys_id,
2597 .get_sset_count = i40e_get_sset_count,
2598 .get_ethtool_stats = i40e_get_ethtool_stats,
2599 .get_coalesce = i40e_get_coalesce,
2600 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002601 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2602 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2603 .get_rxfh = i40e_get_rxfh,
2604 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002605 .get_channels = i40e_get_channels,
2606 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002607 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002608 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002609};
2610
2611void i40e_set_ethtool_ops(struct net_device *netdev)
2612{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002613 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002614}