blob: c568c901453e04b385500ae357889ac4aa2019a6 [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),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400150 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000151 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
152
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000153 /* LPI stats */
154 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
155 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
156 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
157 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000158};
159
Vasu Dev38e00432014-08-01 13:27:03 -0700160#ifdef I40E_FCOE
161static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
162 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
163 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
164 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
165 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
166 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
167 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
168 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
169 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
170};
171
172#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000173#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000174 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
175 * 2 /* Tx and Rx together */ \
176 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000177#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
178#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000179#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700180#ifdef I40E_FCOE
181#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
182#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
183 I40E_FCOE_STATS_LEN + \
184 I40E_MISC_STATS_LEN + \
185 I40E_QUEUE_STATS_LEN((n)))
186#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000188 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700190#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191#define I40E_PFC_STATS_LEN ( \
192 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
197 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000198#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000199#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
200 I40E_PFC_STATS_LEN + \
201 I40E_VSI_STATS_LEN((n)))
202
203enum i40e_ethtool_test_id {
204 I40E_ETH_TEST_REG = 0,
205 I40E_ETH_TEST_EEPROM,
206 I40E_ETH_TEST_INTR,
207 I40E_ETH_TEST_LOOPBACK,
208 I40E_ETH_TEST_LINK,
209};
210
211static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
212 "Register test (offline)",
213 "Eeprom test (offline)",
214 "Interrupt test (offline)",
215 "Loopback test (offline)",
216 "Link test (on/offline)"
217};
218
219#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
220
Greg Rose7e45ab42015-02-06 08:52:19 +0000221static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
222 "NPAR",
223};
224
225#define I40E_PRIV_FLAGS_STR_LEN \
226 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
227
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000228/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000229 * i40e_partition_setting_complaint - generic complaint for MFP restriction
230 * @pf: the PF struct
231 **/
232static void i40e_partition_setting_complaint(struct i40e_pf *pf)
233{
234 dev_info(&pf->pdev->dev,
235 "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");
236}
237
238/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000239 * i40e_get_settings_link_up - Get the Link settings for when link is up
240 * @hw: hw structure
241 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000243 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000244 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000245static void i40e_get_settings_link_up(struct i40e_hw *hw,
246 struct ethtool_cmd *ecmd,
247 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000248{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000249 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000250 u32 link_speed = hw_link_info->link_speed;
251
Catherine Sullivane8278452015-02-06 08:52:08 +0000252 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 switch (hw_link_info->phy_type) {
254 case I40E_PHY_TYPE_40GBASE_CR4:
255 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000256 ecmd->supported = SUPPORTED_Autoneg |
257 SUPPORTED_40000baseCR4_Full;
258 ecmd->advertising = ADVERTISED_Autoneg |
259 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000261 case I40E_PHY_TYPE_XLAUI:
262 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000263 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000264 ecmd->supported = SUPPORTED_40000baseCR4_Full;
265 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000266 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000267 ecmd->supported = SUPPORTED_Autoneg |
268 SUPPORTED_40000baseKR4_Full;
269 ecmd->advertising = ADVERTISED_Autoneg |
270 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000271 break;
272 case I40E_PHY_TYPE_40GBASE_SR4:
273 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000274 break;
275 case I40E_PHY_TYPE_40GBASE_LR4:
276 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000277 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700278 case I40E_PHY_TYPE_20GBASE_KR2:
279 ecmd->supported = SUPPORTED_Autoneg |
280 SUPPORTED_20000baseKR2_Full;
281 ecmd->advertising = ADVERTISED_Autoneg |
282 ADVERTISED_20000baseKR2_Full;
283 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000284 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000285 ecmd->supported = SUPPORTED_Autoneg |
286 SUPPORTED_10000baseKX4_Full;
287 ecmd->advertising = ADVERTISED_Autoneg |
288 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000289 break;
290 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000291 ecmd->supported = SUPPORTED_Autoneg |
292 SUPPORTED_10000baseKR_Full;
293 ecmd->advertising = ADVERTISED_Autoneg |
294 ADVERTISED_10000baseKR_Full;
295 break;
296 case I40E_PHY_TYPE_10GBASE_SR:
297 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000298 case I40E_PHY_TYPE_1000BASE_SX:
299 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000300 ecmd->supported = SUPPORTED_10000baseT_Full |
301 SUPPORTED_1000baseT_Full;
302 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
303 ecmd->advertising |= ADVERTISED_10000baseT_Full;
304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
305 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000306 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000307 case I40E_PHY_TYPE_1000BASE_KX:
308 ecmd->supported = SUPPORTED_Autoneg |
309 SUPPORTED_1000baseKX_Full;
310 ecmd->advertising = ADVERTISED_Autoneg |
311 ADVERTISED_1000baseKX_Full;
312 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000313 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000314 case I40E_PHY_TYPE_1000BASE_T:
315 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000316 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000317 SUPPORTED_10000baseT_Full |
318 SUPPORTED_1000baseT_Full |
319 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000320 ecmd->advertising = ADVERTISED_Autoneg;
321 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
322 ecmd->advertising |= ADVERTISED_10000baseT_Full;
323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
324 ecmd->advertising |= ADVERTISED_1000baseT_Full;
325 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
326 ecmd->advertising |= ADVERTISED_100baseT_Full;
327 break;
328 case I40E_PHY_TYPE_10GBASE_CR1_CU:
329 case I40E_PHY_TYPE_10GBASE_CR1:
330 ecmd->supported = SUPPORTED_Autoneg |
331 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000332 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000333 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000334 break;
335 case I40E_PHY_TYPE_XAUI:
336 case I40E_PHY_TYPE_XFI:
337 case I40E_PHY_TYPE_SFI:
338 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000339 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000340 ecmd->supported = SUPPORTED_10000baseT_Full;
341 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000342 case I40E_PHY_TYPE_SGMII:
343 ecmd->supported = SUPPORTED_Autoneg |
344 SUPPORTED_1000baseT_Full |
345 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000346 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
347 ecmd->advertising |= ADVERTISED_1000baseT_Full;
348 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
349 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000350 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000351 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000352 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000353 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
354 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000355 }
356
Catherine Sullivane8278452015-02-06 08:52:08 +0000357 /* Set speed and duplex */
358 switch (link_speed) {
359 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400360 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000361 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700362 case I40E_LINK_SPEED_20GB:
363 ethtool_cmd_speed_set(ecmd, SPEED_20000);
364 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000365 case I40E_LINK_SPEED_10GB:
366 ethtool_cmd_speed_set(ecmd, SPEED_10000);
367 break;
368 case I40E_LINK_SPEED_1GB:
369 ethtool_cmd_speed_set(ecmd, SPEED_1000);
370 break;
371 case I40E_LINK_SPEED_100MB:
372 ethtool_cmd_speed_set(ecmd, SPEED_100);
373 break;
374 default:
375 break;
376 }
377 ecmd->duplex = DUPLEX_FULL;
378}
379
380/**
381 * i40e_get_settings_link_down - Get the Link settings for when link is down
382 * @hw: hw structure
383 * @ecmd: ethtool command to fill in
384 *
385 * Reports link settings that can be determined when link is down
386 **/
387static void i40e_get_settings_link_down(struct i40e_hw *hw,
388 struct ethtool_cmd *ecmd)
389{
390 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
391
392 /* link is down and the driver needs to fall back on
393 * device ID to determine what kinds of info to display,
394 * it's mostly a guess that may change when link is up
395 */
396 switch (hw->device_id) {
397 case I40E_DEV_ID_QSFP_A:
398 case I40E_DEV_ID_QSFP_B:
399 case I40E_DEV_ID_QSFP_C:
400 /* pluggable QSFP */
401 ecmd->supported = SUPPORTED_40000baseSR4_Full |
402 SUPPORTED_40000baseCR4_Full |
403 SUPPORTED_40000baseLR4_Full;
404 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
405 ADVERTISED_40000baseCR4_Full |
406 ADVERTISED_40000baseLR4_Full;
407 break;
408 case I40E_DEV_ID_KX_B:
409 /* backplane 40G */
410 ecmd->supported = SUPPORTED_40000baseKR4_Full;
411 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
412 break;
413 case I40E_DEV_ID_KX_C:
414 /* backplane 10G */
415 ecmd->supported = SUPPORTED_10000baseKR_Full;
416 ecmd->advertising = ADVERTISED_10000baseKR_Full;
417 break;
418 case I40E_DEV_ID_10G_BASE_T:
419 ecmd->supported = SUPPORTED_10000baseT_Full |
420 SUPPORTED_1000baseT_Full |
421 SUPPORTED_100baseT_Full;
422 /* Figure out what has been requested */
423 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
424 ecmd->advertising |= ADVERTISED_10000baseT_Full;
425 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
426 ecmd->advertising |= ADVERTISED_1000baseT_Full;
427 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
428 ecmd->advertising |= ADVERTISED_100baseT_Full;
429 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700430 case I40E_DEV_ID_20G_KR2:
431 /* backplane 20G */
432 ecmd->supported = SUPPORTED_20000baseKR2_Full;
433 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
434 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000435 default:
436 /* all the rest are 10G/1G */
437 ecmd->supported = SUPPORTED_10000baseT_Full |
438 SUPPORTED_1000baseT_Full;
439 /* Figure out what has been requested */
440 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
441 ecmd->advertising |= ADVERTISED_10000baseT_Full;
442 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
443 ecmd->advertising |= ADVERTISED_1000baseT_Full;
444 break;
445 }
446
447 /* With no link speed and duplex are unknown */
448 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
449 ecmd->duplex = DUPLEX_UNKNOWN;
450}
451
452/**
453 * i40e_get_settings - Get Link Speed and Duplex settings
454 * @netdev: network interface device structure
455 * @ecmd: ethtool command
456 *
457 * Reports speed/duplex settings based on media_type
458 **/
459static int i40e_get_settings(struct net_device *netdev,
460 struct ethtool_cmd *ecmd)
461{
462 struct i40e_netdev_priv *np = netdev_priv(netdev);
463 struct i40e_pf *pf = np->vsi->back;
464 struct i40e_hw *hw = &pf->hw;
465 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
466 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
467
468 if (link_up)
469 i40e_get_settings_link_up(hw, ecmd, netdev);
470 else
471 i40e_get_settings_link_down(hw, ecmd);
472
473 /* Now set the settings that don't rely on link being up/down */
474
475 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000476 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
477 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000478
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000479 switch (hw->phy.media_type) {
480 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000481 ecmd->supported |= SUPPORTED_Autoneg |
482 SUPPORTED_Backplane;
483 ecmd->advertising |= ADVERTISED_Autoneg |
484 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000486 break;
487 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000488 ecmd->supported |= SUPPORTED_TP;
489 ecmd->advertising |= ADVERTISED_TP;
490 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000491 break;
492 case I40E_MEDIA_TYPE_DA:
493 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000494 ecmd->supported |= SUPPORTED_FIBRE;
495 ecmd->advertising |= ADVERTISED_FIBRE;
496 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000497 break;
498 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000499 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000500 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000501 break;
502 case I40E_MEDIA_TYPE_UNKNOWN:
503 default:
504 ecmd->port = PORT_OTHER;
505 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000506 }
507
Catherine Sullivane8278452015-02-06 08:52:08 +0000508 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000509 ecmd->transceiver = XCVR_EXTERNAL;
510
Catherine Sullivane8278452015-02-06 08:52:08 +0000511 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000512 ecmd->supported |= SUPPORTED_Pause;
513
Catherine Sullivane8278452015-02-06 08:52:08 +0000514 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000515 case I40E_FC_FULL:
516 ecmd->advertising |= ADVERTISED_Pause;
517 break;
518 case I40E_FC_TX_PAUSE:
519 ecmd->advertising |= ADVERTISED_Asym_Pause;
520 break;
521 case I40E_FC_RX_PAUSE:
522 ecmd->advertising |= (ADVERTISED_Pause |
523 ADVERTISED_Asym_Pause);
524 break;
525 default:
526 ecmd->advertising &= ~(ADVERTISED_Pause |
527 ADVERTISED_Asym_Pause);
528 break;
529 }
530
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000531 return 0;
532}
533
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000534/**
535 * i40e_set_settings - Set Speed and Duplex
536 * @netdev: network interface device structure
537 * @ecmd: ethtool command
538 *
539 * Set speed/duplex per media_types advertised/forced
540 **/
541static int i40e_set_settings(struct net_device *netdev,
542 struct ethtool_cmd *ecmd)
543{
544 struct i40e_netdev_priv *np = netdev_priv(netdev);
545 struct i40e_aq_get_phy_abilities_resp abilities;
546 struct i40e_aq_set_phy_config config;
547 struct i40e_pf *pf = np->vsi->back;
548 struct i40e_vsi *vsi = np->vsi;
549 struct i40e_hw *hw = &pf->hw;
550 struct ethtool_cmd safe_ecmd;
551 i40e_status status = 0;
552 bool change = false;
553 int err = 0;
554 u8 autoneg;
555 u32 advertise;
556
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000557 /* Changing port settings is not supported if this isn't the
558 * port's controlling PF
559 */
560 if (hw->partition_id != 1) {
561 i40e_partition_setting_complaint(pf);
562 return -EOPNOTSUPP;
563 }
564
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000565 if (vsi != pf->vsi[pf->lan_vsi])
566 return -EOPNOTSUPP;
567
568 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
569 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000570 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
571 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000572 return -EOPNOTSUPP;
573
574 /* get our own copy of the bits to check against */
575 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
576 i40e_get_settings(netdev, &safe_ecmd);
577
578 /* save autoneg and speed out of ecmd */
579 autoneg = ecmd->autoneg;
580 advertise = ecmd->advertising;
581
582 /* set autoneg and speed back to what they currently are */
583 ecmd->autoneg = safe_ecmd.autoneg;
584 ecmd->advertising = safe_ecmd.advertising;
585
586 ecmd->cmd = safe_ecmd.cmd;
587 /* If ecmd and safe_ecmd are not the same now, then they are
588 * trying to set something that we do not support
589 */
590 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
591 return -EOPNOTSUPP;
592
593 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
594 usleep_range(1000, 2000);
595
596 /* Get the current phy config */
597 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
598 NULL);
599 if (status)
600 return -EAGAIN;
601
Catherine Sullivan124ed152014-07-12 07:28:12 +0000602 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000603 * set below
604 */
605 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000606 config.abilities = abilities.abilities;
607
608 /* Check autoneg */
609 if (autoneg == AUTONEG_ENABLE) {
610 /* If autoneg is not supported, return error */
611 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
612 netdev_info(netdev, "Autoneg not supported on this phy\n");
613 return -EINVAL;
614 }
615 /* If autoneg was not already enabled */
616 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
617 config.abilities = abilities.abilities |
618 I40E_AQ_PHY_ENABLE_AN;
619 change = true;
620 }
621 } else {
622 /* If autoneg is supported 10GBASE_T is the only phy that
623 * can disable it, so otherwise return error
624 */
625 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
626 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
627 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
628 return -EINVAL;
629 }
630 /* If autoneg is currently enabled */
631 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000632 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000633 ~I40E_AQ_PHY_ENABLE_AN;
634 change = true;
635 }
636 }
637
638 if (advertise & ~safe_ecmd.supported)
639 return -EINVAL;
640
641 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000642 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000643 if (advertise & ADVERTISED_1000baseT_Full ||
644 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000645 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000646 if (advertise & ADVERTISED_10000baseT_Full ||
647 advertise & ADVERTISED_10000baseKX4_Full ||
648 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000649 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700650 if (advertise & ADVERTISED_20000baseKR2_Full)
651 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000652 if (advertise & ADVERTISED_40000baseKR4_Full ||
653 advertise & ADVERTISED_40000baseCR4_Full ||
654 advertise & ADVERTISED_40000baseSR4_Full ||
655 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000656 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000657
Catherine Sullivan124ed152014-07-12 07:28:12 +0000658 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000659 /* copy over the rest of the abilities */
660 config.phy_type = abilities.phy_type;
661 config.eee_capability = abilities.eee_capability;
662 config.eeer = abilities.eeer_val;
663 config.low_power_ctrl = abilities.d3_lpan;
664
Catherine Sullivane8278452015-02-06 08:52:08 +0000665 /* save the requested speeds */
666 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000667 /* set link and auto negotiation so changes take effect */
668 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
669 /* If link is up put link down */
670 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
671 /* Tell the OS link is going down, the link will go
672 * back up when fw says it is ready asynchronously
673 */
674 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
675 netif_carrier_off(netdev);
676 netif_tx_stop_all_queues(netdev);
677 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000678
679 /* make the aq call */
680 status = i40e_aq_set_phy_config(hw, &config, NULL);
681 if (status) {
682 netdev_info(netdev, "Set phy config failed with error %d.\n",
683 status);
684 return -EAGAIN;
685 }
686
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000687 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000688 if (status)
689 netdev_info(netdev, "Updating link info failed with error %d\n",
690 status);
691
692 } else {
693 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
694 }
695
696 return err;
697}
698
Jesse Brandeburga6599722014-06-04 08:45:25 +0000699static int i40e_nway_reset(struct net_device *netdev)
700{
701 /* restart autonegotiation */
702 struct i40e_netdev_priv *np = netdev_priv(netdev);
703 struct i40e_pf *pf = np->vsi->back;
704 struct i40e_hw *hw = &pf->hw;
705 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
706 i40e_status ret = 0;
707
708 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
709 if (ret) {
710 netdev_info(netdev, "link restart failed, aq_err=%d\n",
711 pf->hw.aq.asq_last_status);
712 return -EIO;
713 }
714
715 return 0;
716}
717
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000718/**
719 * i40e_get_pauseparam - Get Flow Control status
720 * Return tx/rx-pause status
721 **/
722static void i40e_get_pauseparam(struct net_device *netdev,
723 struct ethtool_pauseparam *pause)
724{
725 struct i40e_netdev_priv *np = netdev_priv(netdev);
726 struct i40e_pf *pf = np->vsi->back;
727 struct i40e_hw *hw = &pf->hw;
728 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000729 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000730
731 pause->autoneg =
732 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
733 AUTONEG_ENABLE : AUTONEG_DISABLE);
734
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000735 /* PFC enabled so report LFC as off */
736 if (dcbx_cfg->pfc.pfcenable) {
737 pause->rx_pause = 0;
738 pause->tx_pause = 0;
739 return;
740 }
741
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000742 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000743 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000744 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000745 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000746 } else if (hw->fc.current_mode == I40E_FC_FULL) {
747 pause->rx_pause = 1;
748 pause->tx_pause = 1;
749 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000750}
751
Catherine Sullivan2becc352014-06-04 08:45:27 +0000752/**
753 * i40e_set_pauseparam - Set Flow Control parameter
754 * @netdev: network interface device structure
755 * @pause: return tx/rx flow control status
756 **/
757static int i40e_set_pauseparam(struct net_device *netdev,
758 struct ethtool_pauseparam *pause)
759{
760 struct i40e_netdev_priv *np = netdev_priv(netdev);
761 struct i40e_pf *pf = np->vsi->back;
762 struct i40e_vsi *vsi = np->vsi;
763 struct i40e_hw *hw = &pf->hw;
764 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000765 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000766 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
767 i40e_status status;
768 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000769 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000770
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000771 /* Changing the port's flow control is not supported if this isn't the
772 * port's controlling PF
773 */
774 if (hw->partition_id != 1) {
775 i40e_partition_setting_complaint(pf);
776 return -EOPNOTSUPP;
777 }
778
Catherine Sullivan2becc352014-06-04 08:45:27 +0000779 if (vsi != pf->vsi[pf->lan_vsi])
780 return -EOPNOTSUPP;
781
782 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
783 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
784 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
785 return -EOPNOTSUPP;
786 }
787
788 /* If we have link and don't have autoneg */
789 if (!test_bit(__I40E_DOWN, &pf->state) &&
790 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
791 /* Send message that it might not necessarily work*/
792 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
793 }
794
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000795 if (dcbx_cfg->pfc.pfcenable) {
796 netdev_info(netdev,
797 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000798 return -EOPNOTSUPP;
799 }
800
801 if (pause->rx_pause && pause->tx_pause)
802 hw->fc.requested_mode = I40E_FC_FULL;
803 else if (pause->rx_pause && !pause->tx_pause)
804 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
805 else if (!pause->rx_pause && pause->tx_pause)
806 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
807 else if (!pause->rx_pause && !pause->tx_pause)
808 hw->fc.requested_mode = I40E_FC_NONE;
809 else
810 return -EINVAL;
811
Catherine Sullivan94128512014-07-12 07:28:16 +0000812 /* Tell the OS link is going down, the link will go back up when fw
813 * says it is ready asynchronously
814 */
815 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
816 netif_carrier_off(netdev);
817 netif_tx_stop_all_queues(netdev);
818
Catherine Sullivan2becc352014-06-04 08:45:27 +0000819 /* Set the fc mode and only restart an if link is up*/
820 status = i40e_set_fc(hw, &aq_failures, link_up);
821
822 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
823 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
824 status, hw->aq.asq_last_status);
825 err = -EAGAIN;
826 }
827 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
828 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
829 status, hw->aq.asq_last_status);
830 err = -EAGAIN;
831 }
832 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000833 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 +0000834 status, hw->aq.asq_last_status);
835 err = -EAGAIN;
836 }
837
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000838 if (!test_bit(__I40E_DOWN, &pf->state)) {
839 /* Give it a little more time to try to come back */
840 msleep(75);
841 if (!test_bit(__I40E_DOWN, &pf->state))
842 return i40e_nway_reset(netdev);
843 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000844
845 return err;
846}
847
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000848static u32 i40e_get_msglevel(struct net_device *netdev)
849{
850 struct i40e_netdev_priv *np = netdev_priv(netdev);
851 struct i40e_pf *pf = np->vsi->back;
852
853 return pf->msg_enable;
854}
855
856static void i40e_set_msglevel(struct net_device *netdev, u32 data)
857{
858 struct i40e_netdev_priv *np = netdev_priv(netdev);
859 struct i40e_pf *pf = np->vsi->back;
860
861 if (I40E_DEBUG_USER & data)
862 pf->hw.debug_mask = data;
863 pf->msg_enable = data;
864}
865
866static int i40e_get_regs_len(struct net_device *netdev)
867{
868 int reg_count = 0;
869 int i;
870
871 for (i = 0; i40e_reg_list[i].offset != 0; i++)
872 reg_count += i40e_reg_list[i].elements;
873
874 return reg_count * sizeof(u32);
875}
876
877static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
878 void *p)
879{
880 struct i40e_netdev_priv *np = netdev_priv(netdev);
881 struct i40e_pf *pf = np->vsi->back;
882 struct i40e_hw *hw = &pf->hw;
883 u32 *reg_buf = p;
884 int i, j, ri;
885 u32 reg;
886
887 /* Tell ethtool which driver-version-specific regs output we have.
888 *
889 * At some point, if we have ethtool doing special formatting of
890 * this data, it will rely on this version number to know how to
891 * interpret things. Hence, this needs to be updated if/when the
892 * diags register table is changed.
893 */
894 regs->version = 1;
895
896 /* loop through the diags reg table for what to print */
897 ri = 0;
898 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
899 for (j = 0; j < i40e_reg_list[i].elements; j++) {
900 reg = i40e_reg_list[i].offset
901 + (j * i40e_reg_list[i].stride);
902 reg_buf[ri++] = rd32(hw, reg);
903 }
904 }
905
906}
907
908static int i40e_get_eeprom(struct net_device *netdev,
909 struct ethtool_eeprom *eeprom, u8 *bytes)
910{
911 struct i40e_netdev_priv *np = netdev_priv(netdev);
912 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000913 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000914 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000915 u8 *eeprom_buff;
916 u16 i, sectors;
917 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000918 u32 magic;
919
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000920#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000921 if (eeprom->len == 0)
922 return -EINVAL;
923
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000924 /* check for NVMUpdate access method */
925 magic = hw->vendor_id | (hw->device_id << 16);
926 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000927 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000928 int errno;
929
930 /* make sure it is the right magic for NVMUpdate */
931 if ((eeprom->magic >> 16) != hw->device_id)
932 return -EINVAL;
933
Shannon Nelsonc150a502014-11-13 08:23:13 +0000934 cmd = (struct i40e_nvm_access *)eeprom;
935 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000936 if (ret_val &&
937 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
938 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000939 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000940 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
941 ret_val, hw->aq.asq_last_status, errno,
942 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
943 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000944
945 return errno;
946 }
947
948 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000949 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
950
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000951 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000952 if (!eeprom_buff)
953 return -ENOMEM;
954
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000955 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
956 if (ret_val) {
957 dev_info(&pf->pdev->dev,
958 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
959 ret_val, hw->aq.asq_last_status);
960 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000961 }
962
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000963 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
964 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
965 len = I40E_NVM_SECTOR_SIZE;
966 last = false;
967 for (i = 0; i < sectors; i++) {
968 if (i == (sectors - 1)) {
969 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
970 last = true;
971 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000972 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
973 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000974 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000975 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000976 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000977 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000978 "read NVM failed, invalid offset 0x%x\n",
979 offset);
980 break;
981 } else if (ret_val &&
982 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
983 dev_info(&pf->pdev->dev,
984 "read NVM failed, access, offset 0x%x\n",
985 offset);
986 break;
987 } else if (ret_val) {
988 dev_info(&pf->pdev->dev,
989 "read NVM failed offset %d err=%d status=0x%x\n",
990 offset, ret_val, hw->aq.asq_last_status);
991 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000992 }
993 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000994
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000995 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000996 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000997free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000998 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000999 return ret_val;
1000}
1001
1002static int i40e_get_eeprom_len(struct net_device *netdev)
1003{
1004 struct i40e_netdev_priv *np = netdev_priv(netdev);
1005 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001006 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001007
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001008 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1009 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1010 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1011 /* register returns value in power of 2, 64Kbyte chunks. */
1012 val = (64 * 1024) * (1 << val);
1013 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001014}
1015
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001016static int i40e_set_eeprom(struct net_device *netdev,
1017 struct ethtool_eeprom *eeprom, u8 *bytes)
1018{
1019 struct i40e_netdev_priv *np = netdev_priv(netdev);
1020 struct i40e_hw *hw = &np->vsi->back->hw;
1021 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001022 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001023 int ret_val = 0;
1024 int errno;
1025 u32 magic;
1026
1027 /* normal ethtool set_eeprom is not supported */
1028 magic = hw->vendor_id | (hw->device_id << 16);
1029 if (eeprom->magic == magic)
1030 return -EOPNOTSUPP;
1031
1032 /* check for NVMUpdate access method */
1033 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1034 return -EINVAL;
1035
1036 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1037 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1038 return -EBUSY;
1039
Shannon Nelsonc150a502014-11-13 08:23:13 +00001040 cmd = (struct i40e_nvm_access *)eeprom;
1041 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001042 if (ret_val &&
1043 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1044 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1045 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001046 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001047 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1048 ret_val, hw->aq.asq_last_status, errno,
1049 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1050 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001051
1052 return errno;
1053}
1054
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001055static void i40e_get_drvinfo(struct net_device *netdev,
1056 struct ethtool_drvinfo *drvinfo)
1057{
1058 struct i40e_netdev_priv *np = netdev_priv(netdev);
1059 struct i40e_vsi *vsi = np->vsi;
1060 struct i40e_pf *pf = vsi->back;
1061
1062 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1063 strlcpy(drvinfo->version, i40e_driver_version_str,
1064 sizeof(drvinfo->version));
1065 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1066 sizeof(drvinfo->fw_version));
1067 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1068 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001069 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001070}
1071
1072static void i40e_get_ringparam(struct net_device *netdev,
1073 struct ethtool_ringparam *ring)
1074{
1075 struct i40e_netdev_priv *np = netdev_priv(netdev);
1076 struct i40e_pf *pf = np->vsi->back;
1077 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1078
1079 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1080 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1081 ring->rx_mini_max_pending = 0;
1082 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001083 ring->rx_pending = vsi->rx_rings[0]->count;
1084 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085 ring->rx_mini_pending = 0;
1086 ring->rx_jumbo_pending = 0;
1087}
1088
1089static int i40e_set_ringparam(struct net_device *netdev,
1090 struct ethtool_ringparam *ring)
1091{
1092 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1093 struct i40e_netdev_priv *np = netdev_priv(netdev);
1094 struct i40e_vsi *vsi = np->vsi;
1095 struct i40e_pf *pf = vsi->back;
1096 u32 new_rx_count, new_tx_count;
1097 int i, err = 0;
1098
1099 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1100 return -EINVAL;
1101
Shannon Nelson1fa18372013-11-20 10:03:08 +00001102 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1103 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1104 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1105 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1106 netdev_info(netdev,
1107 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1108 ring->tx_pending, ring->rx_pending,
1109 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1110 return -EINVAL;
1111 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001112
Shannon Nelson1fa18372013-11-20 10:03:08 +00001113 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1114 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001115
1116 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001117 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1118 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001119 return 0;
1120
1121 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1122 usleep_range(1000, 2000);
1123
1124 if (!netif_running(vsi->netdev)) {
1125 /* simple case - set for the next time the netdev is started */
1126 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001127 vsi->tx_rings[i]->count = new_tx_count;
1128 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001129 }
1130 goto done;
1131 }
1132
1133 /* We can't just free everything and then setup again,
1134 * because the ISRs in MSI-X mode get passed pointers
1135 * to the Tx and Rx ring structs.
1136 */
1137
1138 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001139 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001140 netdev_info(netdev,
1141 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001142 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001143 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1144 sizeof(struct i40e_ring), GFP_KERNEL);
1145 if (!tx_rings) {
1146 err = -ENOMEM;
1147 goto done;
1148 }
1149
1150 for (i = 0; i < vsi->num_queue_pairs; i++) {
1151 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001152 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001153 tx_rings[i].count = new_tx_count;
1154 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1155 if (err) {
1156 while (i) {
1157 i--;
1158 i40e_free_tx_resources(&tx_rings[i]);
1159 }
1160 kfree(tx_rings);
1161 tx_rings = NULL;
1162
1163 goto done;
1164 }
1165 }
1166 }
1167
1168 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001169 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001170 netdev_info(netdev,
1171 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001172 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001173 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1174 sizeof(struct i40e_ring), GFP_KERNEL);
1175 if (!rx_rings) {
1176 err = -ENOMEM;
1177 goto free_tx;
1178 }
1179
1180 for (i = 0; i < vsi->num_queue_pairs; i++) {
1181 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001182 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001183 rx_rings[i].count = new_rx_count;
1184 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1185 if (err) {
1186 while (i) {
1187 i--;
1188 i40e_free_rx_resources(&rx_rings[i]);
1189 }
1190 kfree(rx_rings);
1191 rx_rings = NULL;
1192
1193 goto free_tx;
1194 }
1195 }
1196 }
1197
1198 /* Bring interface down, copy in the new ring info,
1199 * then restore the interface
1200 */
1201 i40e_down(vsi);
1202
1203 if (tx_rings) {
1204 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001205 i40e_free_tx_resources(vsi->tx_rings[i]);
1206 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001207 }
1208 kfree(tx_rings);
1209 tx_rings = NULL;
1210 }
1211
1212 if (rx_rings) {
1213 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001214 i40e_free_rx_resources(vsi->rx_rings[i]);
1215 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001216 }
1217 kfree(rx_rings);
1218 rx_rings = NULL;
1219 }
1220
1221 i40e_up(vsi);
1222
1223free_tx:
1224 /* error cleanup if the Rx allocations failed after getting Tx */
1225 if (tx_rings) {
1226 for (i = 0; i < vsi->num_queue_pairs; i++)
1227 i40e_free_tx_resources(&tx_rings[i]);
1228 kfree(tx_rings);
1229 tx_rings = NULL;
1230 }
1231
1232done:
1233 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1234
1235 return err;
1236}
1237
1238static int i40e_get_sset_count(struct net_device *netdev, int sset)
1239{
1240 struct i40e_netdev_priv *np = netdev_priv(netdev);
1241 struct i40e_vsi *vsi = np->vsi;
1242 struct i40e_pf *pf = vsi->back;
1243
1244 switch (sset) {
1245 case ETH_SS_TEST:
1246 return I40E_TEST_LEN;
1247 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001248 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001249 int len = I40E_PF_STATS_LEN(netdev);
1250
1251 if (pf->lan_veb != I40E_NO_VEB)
1252 len += I40E_VEB_STATS_LEN;
1253 return len;
1254 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001255 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001256 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001257 case ETH_SS_PRIV_FLAGS:
1258 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001259 default:
1260 return -EOPNOTSUPP;
1261 }
1262}
1263
1264static void i40e_get_ethtool_stats(struct net_device *netdev,
1265 struct ethtool_stats *stats, u64 *data)
1266{
1267 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001268 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 struct i40e_vsi *vsi = np->vsi;
1270 struct i40e_pf *pf = vsi->back;
1271 int i = 0;
1272 char *p;
1273 int j;
1274 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001275 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001276
1277 i40e_update_stats(vsi);
1278
1279 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1280 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1281 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1282 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1283 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001284 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1285 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1286 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1287 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1288 }
Vasu Dev38e00432014-08-01 13:27:03 -07001289#ifdef I40E_FCOE
1290 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1291 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1292 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1293 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1294 }
1295#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001296 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001297 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001298 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001299
1300 if (!tx_ring)
1301 continue;
1302
1303 /* process Tx ring statistics */
1304 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001305 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001306 data[i] = tx_ring->stats.packets;
1307 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001308 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001309 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001310
1311 /* Rx ring is the 2nd half of the queue pair */
1312 rx_ring = &tx_ring[1];
1313 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001314 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001315 data[i] = rx_ring->stats.packets;
1316 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001317 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001318 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001320 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001321 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001322 return;
1323
1324 if (pf->lan_veb != I40E_NO_VEB) {
1325 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1326 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1327 p = (char *)veb;
1328 p += i40e_gstrings_veb_stats[j].stat_offset;
1329 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1330 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001332 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001333 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1334 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1335 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1336 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1337 }
1338 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1339 data[i++] = pf->stats.priority_xon_tx[j];
1340 data[i++] = pf->stats.priority_xoff_tx[j];
1341 }
1342 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1343 data[i++] = pf->stats.priority_xon_rx[j];
1344 data[i++] = pf->stats.priority_xoff_rx[j];
1345 }
1346 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1347 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348}
1349
1350static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1351 u8 *data)
1352{
1353 struct i40e_netdev_priv *np = netdev_priv(netdev);
1354 struct i40e_vsi *vsi = np->vsi;
1355 struct i40e_pf *pf = vsi->back;
1356 char *p = (char *)data;
1357 int i;
1358
1359 switch (stringset) {
1360 case ETH_SS_TEST:
1361 for (i = 0; i < I40E_TEST_LEN; i++) {
1362 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1363 data += ETH_GSTRING_LEN;
1364 }
1365 break;
1366 case ETH_SS_STATS:
1367 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1368 snprintf(p, ETH_GSTRING_LEN, "%s",
1369 i40e_gstrings_net_stats[i].stat_string);
1370 p += ETH_GSTRING_LEN;
1371 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001372 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1373 snprintf(p, ETH_GSTRING_LEN, "%s",
1374 i40e_gstrings_misc_stats[i].stat_string);
1375 p += ETH_GSTRING_LEN;
1376 }
Vasu Dev38e00432014-08-01 13:27:03 -07001377#ifdef I40E_FCOE
1378 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1379 snprintf(p, ETH_GSTRING_LEN, "%s",
1380 i40e_gstrings_fcoe_stats[i].stat_string);
1381 p += ETH_GSTRING_LEN;
1382 }
1383#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001384 for (i = 0; i < vsi->num_queue_pairs; i++) {
1385 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1386 p += ETH_GSTRING_LEN;
1387 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1388 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001389 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1390 p += ETH_GSTRING_LEN;
1391 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1392 p += ETH_GSTRING_LEN;
1393 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001394 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001395 return;
1396
1397 if (pf->lan_veb != I40E_NO_VEB) {
1398 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1399 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1400 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001401 p += ETH_GSTRING_LEN;
1402 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001403 }
1404 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1405 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1406 i40e_gstrings_stats[i].stat_string);
1407 p += ETH_GSTRING_LEN;
1408 }
1409 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1410 snprintf(p, ETH_GSTRING_LEN,
1411 "port.tx_priority_%u_xon", i);
1412 p += ETH_GSTRING_LEN;
1413 snprintf(p, ETH_GSTRING_LEN,
1414 "port.tx_priority_%u_xoff", i);
1415 p += ETH_GSTRING_LEN;
1416 }
1417 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1418 snprintf(p, ETH_GSTRING_LEN,
1419 "port.rx_priority_%u_xon", i);
1420 p += ETH_GSTRING_LEN;
1421 snprintf(p, ETH_GSTRING_LEN,
1422 "port.rx_priority_%u_xoff", i);
1423 p += ETH_GSTRING_LEN;
1424 }
1425 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1426 snprintf(p, ETH_GSTRING_LEN,
1427 "port.rx_priority_%u_xon_2_xoff", i);
1428 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001429 }
1430 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1431 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001432 case ETH_SS_PRIV_FLAGS:
1433 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1434 memcpy(data, i40e_priv_flags_strings[i],
1435 ETH_GSTRING_LEN);
1436 data += ETH_GSTRING_LEN;
1437 }
1438 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001439 default:
1440 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441 }
1442}
1443
1444static int i40e_get_ts_info(struct net_device *dev,
1445 struct ethtool_ts_info *info)
1446{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001447 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1448
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001449 /* only report HW timestamping if PTP is enabled */
1450 if (!(pf->flags & I40E_FLAG_PTP))
1451 return ethtool_op_get_ts_info(dev, info);
1452
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001453 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1454 SOF_TIMESTAMPING_RX_SOFTWARE |
1455 SOF_TIMESTAMPING_SOFTWARE |
1456 SOF_TIMESTAMPING_TX_HARDWARE |
1457 SOF_TIMESTAMPING_RX_HARDWARE |
1458 SOF_TIMESTAMPING_RAW_HARDWARE;
1459
1460 if (pf->ptp_clock)
1461 info->phc_index = ptp_clock_index(pf->ptp_clock);
1462 else
1463 info->phc_index = -1;
1464
1465 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1466
1467 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1468 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1469 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1470 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1471 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1472 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1473 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1474 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1475 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1476 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1477 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1478 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1479
1480 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481}
1482
Shannon Nelson7b086392013-11-20 10:02:59 +00001483static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001484{
Shannon Nelson7b086392013-11-20 10:02:59 +00001485 struct i40e_netdev_priv *np = netdev_priv(netdev);
1486 struct i40e_pf *pf = np->vsi->back;
1487
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001488 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489 if (i40e_get_link_status(&pf->hw))
1490 *data = 0;
1491 else
1492 *data = 1;
1493
1494 return *data;
1495}
1496
Shannon Nelson7b086392013-11-20 10:02:59 +00001497static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001498{
Shannon Nelson7b086392013-11-20 10:02:59 +00001499 struct i40e_netdev_priv *np = netdev_priv(netdev);
1500 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001501
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001502 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001503 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001504
Shannon Nelson7b086392013-11-20 10:02:59 +00001505 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506}
1507
Shannon Nelson7b086392013-11-20 10:02:59 +00001508static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001509{
Shannon Nelson7b086392013-11-20 10:02:59 +00001510 struct i40e_netdev_priv *np = netdev_priv(netdev);
1511 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001512
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001513 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001514 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001515
Shannon Nelson4443ec92014-11-13 08:23:12 +00001516 /* forcebly clear the NVM Update state machine */
1517 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1518
Shannon Nelson7b086392013-11-20 10:02:59 +00001519 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520}
1521
Shannon Nelson7b086392013-11-20 10:02:59 +00001522static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523{
Shannon Nelson7b086392013-11-20 10:02:59 +00001524 struct i40e_netdev_priv *np = netdev_priv(netdev);
1525 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001526 u16 swc_old = pf->sw_int_count;
1527
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001528 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001529 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1530 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001531 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1532 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1533 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1534 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001535 usleep_range(1000, 2000);
1536 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537
1538 return *data;
1539}
1540
Shannon Nelson7b086392013-11-20 10:02:59 +00001541static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001542{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001543 struct i40e_netdev_priv *np = netdev_priv(netdev);
1544 struct i40e_pf *pf = np->vsi->back;
1545
1546 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001547 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548
1549 return *data;
1550}
1551
Greg Rosee17bc412015-04-16 20:05:59 -04001552static inline bool i40e_active_vfs(struct i40e_pf *pf)
1553{
1554 struct i40e_vf *vfs = pf->vf;
1555 int i;
1556
1557 for (i = 0; i < pf->num_alloc_vfs; i++)
1558 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1559 return true;
1560 return false;
1561}
1562
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563static void i40e_diag_test(struct net_device *netdev,
1564 struct ethtool_test *eth_test, u64 *data)
1565{
1566 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001567 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568 struct i40e_pf *pf = np->vsi->back;
1569
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001570 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1571 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001572 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573
Shannon Nelsonf551b432013-11-26 10:49:12 +00001574 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001575
1576 if (i40e_active_vfs(pf)) {
1577 dev_warn(&pf->pdev->dev,
1578 "Please take active VFS offline and restart the adapter before running NIC diagnostics\n");
1579 data[I40E_ETH_TEST_REG] = 1;
1580 data[I40E_ETH_TEST_EEPROM] = 1;
1581 data[I40E_ETH_TEST_INTR] = 1;
1582 data[I40E_ETH_TEST_LOOPBACK] = 1;
1583 data[I40E_ETH_TEST_LINK] = 1;
1584 eth_test->flags |= ETH_TEST_FL_FAILED;
1585 clear_bit(__I40E_TESTING, &pf->state);
1586 goto skip_ol_tests;
1587 }
1588
Greg Rose5b86c5c2015-02-26 16:14:35 +00001589 /* If the device is online then take it offline */
1590 if (if_running)
1591 /* indicate we're in test mode */
1592 dev_close(netdev);
1593 else
1594 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001595
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 /* Link test performed before hardware reset
1597 * so autoneg doesn't interfere with test result
1598 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001599 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 eth_test->flags |= ETH_TEST_FL_FAILED;
1601
Shannon Nelson7b086392013-11-20 10:02:59 +00001602 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001603 eth_test->flags |= ETH_TEST_FL_FAILED;
1604
Shannon Nelson7b086392013-11-20 10:02:59 +00001605 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001606 eth_test->flags |= ETH_TEST_FL_FAILED;
1607
Shannon Nelson7b086392013-11-20 10:02:59 +00001608 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609 eth_test->flags |= ETH_TEST_FL_FAILED;
1610
Shannon Nelsonf551b432013-11-26 10:49:12 +00001611 /* run reg test last, a reset is required after it */
1612 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1613 eth_test->flags |= ETH_TEST_FL_FAILED;
1614
1615 clear_bit(__I40E_TESTING, &pf->state);
1616 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001617
1618 if (if_running)
1619 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001620 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001621 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001622 netif_info(pf, drv, netdev, "online testing starting\n");
1623
Shannon Nelson7b086392013-11-20 10:02:59 +00001624 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001625 eth_test->flags |= ETH_TEST_FL_FAILED;
1626
1627 /* Offline only tests, not run in online; pass by default */
1628 data[I40E_ETH_TEST_REG] = 0;
1629 data[I40E_ETH_TEST_EEPROM] = 0;
1630 data[I40E_ETH_TEST_INTR] = 0;
1631 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001632 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001633
Greg Rosee17bc412015-04-16 20:05:59 -04001634skip_ol_tests:
1635
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001636 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001637}
1638
1639static void i40e_get_wol(struct net_device *netdev,
1640 struct ethtool_wolinfo *wol)
1641{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001642 struct i40e_netdev_priv *np = netdev_priv(netdev);
1643 struct i40e_pf *pf = np->vsi->back;
1644 struct i40e_hw *hw = &pf->hw;
1645 u16 wol_nvm_bits;
1646
1647 /* NVM bit on means WoL disabled for the port */
1648 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001649 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001650 wol->supported = 0;
1651 wol->wolopts = 0;
1652 } else {
1653 wol->supported = WAKE_MAGIC;
1654 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1655 }
1656}
1657
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001658/**
1659 * i40e_set_wol - set the WakeOnLAN configuration
1660 * @netdev: the netdev in question
1661 * @wol: the ethtool WoL setting data
1662 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001663static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1664{
1665 struct i40e_netdev_priv *np = netdev_priv(netdev);
1666 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001667 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001668 struct i40e_hw *hw = &pf->hw;
1669 u16 wol_nvm_bits;
1670
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001671 /* WoL not supported if this isn't the controlling PF on the port */
1672 if (hw->partition_id != 1) {
1673 i40e_partition_setting_complaint(pf);
1674 return -EOPNOTSUPP;
1675 }
1676
1677 if (vsi != pf->vsi[pf->lan_vsi])
1678 return -EOPNOTSUPP;
1679
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001680 /* NVM bit on means WoL disabled for the port */
1681 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1682 if (((1 << hw->port) & wol_nvm_bits))
1683 return -EOPNOTSUPP;
1684
1685 /* only magic packet is supported */
1686 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1687 return -EOPNOTSUPP;
1688
1689 /* is this a new value? */
1690 if (pf->wol_en != !!wol->wolopts) {
1691 pf->wol_en = !!wol->wolopts;
1692 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1693 }
1694
1695 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001696}
1697
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001698static int i40e_set_phys_id(struct net_device *netdev,
1699 enum ethtool_phys_id_state state)
1700{
1701 struct i40e_netdev_priv *np = netdev_priv(netdev);
1702 struct i40e_pf *pf = np->vsi->back;
1703 struct i40e_hw *hw = &pf->hw;
1704 int blink_freq = 2;
1705
1706 switch (state) {
1707 case ETHTOOL_ID_ACTIVE:
1708 pf->led_status = i40e_led_get(hw);
1709 return blink_freq;
1710 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001711 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712 break;
1713 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001714 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001715 break;
1716 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001717 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001718 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001719 default:
1720 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721 }
1722
1723 return 0;
1724}
1725
1726/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1727 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1728 * 125us (8000 interrupts per second) == ITR(62)
1729 */
1730
1731static int i40e_get_coalesce(struct net_device *netdev,
1732 struct ethtool_coalesce *ec)
1733{
1734 struct i40e_netdev_priv *np = netdev_priv(netdev);
1735 struct i40e_vsi *vsi = np->vsi;
1736
1737 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1738 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1739
1740 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001741 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001742
1743 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001744 ec->use_adaptive_tx_coalesce = 1;
1745
1746 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1747 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001748
1749 return 0;
1750}
1751
1752static int i40e_set_coalesce(struct net_device *netdev,
1753 struct ethtool_coalesce *ec)
1754{
1755 struct i40e_netdev_priv *np = netdev_priv(netdev);
1756 struct i40e_q_vector *q_vector;
1757 struct i40e_vsi *vsi = np->vsi;
1758 struct i40e_pf *pf = vsi->back;
1759 struct i40e_hw *hw = &pf->hw;
1760 u16 vector;
1761 int i;
1762
1763 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1764 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1765
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001766 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001767 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001768 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001769 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001770 } else if (ec->rx_coalesce_usecs == 0) {
1771 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001772 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001773 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 +00001774 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001775 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001776 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001777 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001778
Mitch Williams32f5f542014-04-04 04:43:10 +00001779 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001780 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001781 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001782 } else if (ec->tx_coalesce_usecs == 0) {
1783 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001784 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001785 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 +00001786 } else {
1787 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001788 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001789 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001790 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001791
1792 if (ec->use_adaptive_rx_coalesce)
1793 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1794 else
1795 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1796
1797 if (ec->use_adaptive_tx_coalesce)
1798 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1799 else
1800 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001801
Alexander Duyck493fb302013-09-28 07:01:44 +00001802 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1803 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001804 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1805 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1806 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1807 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1808 i40e_flush(hw);
1809 }
1810
1811 return 0;
1812}
1813
1814/**
1815 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1816 * @pf: pointer to the physical function struct
1817 * @cmd: ethtool rxnfc command
1818 *
1819 * Returns Success if the flow is supported, else Invalid Input.
1820 **/
1821static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1822{
1823 cmd->data = 0;
1824
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001825 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1826 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1827 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1828 return 0;
1829 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001830 /* Report default options for RSS on i40e */
1831 switch (cmd->flow_type) {
1832 case TCP_V4_FLOW:
1833 case UDP_V4_FLOW:
1834 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1835 /* fall through to add IP fields */
1836 case SCTP_V4_FLOW:
1837 case AH_ESP_V4_FLOW:
1838 case AH_V4_FLOW:
1839 case ESP_V4_FLOW:
1840 case IPV4_FLOW:
1841 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1842 break;
1843 case TCP_V6_FLOW:
1844 case UDP_V6_FLOW:
1845 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1846 /* fall through to add IP fields */
1847 case SCTP_V6_FLOW:
1848 case AH_ESP_V6_FLOW:
1849 case AH_V6_FLOW:
1850 case ESP_V6_FLOW:
1851 case IPV6_FLOW:
1852 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1853 break;
1854 default:
1855 return -EINVAL;
1856 }
1857
1858 return 0;
1859}
1860
1861/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001862 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1863 * @pf: Pointer to the physical function struct
1864 * @cmd: The command to get or set Rx flow classification rules
1865 * @rule_locs: Array of used rule locations
1866 *
1867 * This function populates both the total and actual rule count of
1868 * the ethtool flow classification command
1869 *
1870 * Returns 0 on success or -EMSGSIZE if entry not found
1871 **/
1872static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1873 struct ethtool_rxnfc *cmd,
1874 u32 *rule_locs)
1875{
1876 struct i40e_fdir_filter *rule;
1877 struct hlist_node *node2;
1878 int cnt = 0;
1879
1880 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001881 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001882
1883 hlist_for_each_entry_safe(rule, node2,
1884 &pf->fdir_filter_list, fdir_node) {
1885 if (cnt == cmd->rule_cnt)
1886 return -EMSGSIZE;
1887
1888 rule_locs[cnt] = rule->fd_id;
1889 cnt++;
1890 }
1891
1892 cmd->rule_cnt = cnt;
1893
1894 return 0;
1895}
1896
1897/**
1898 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1899 * @pf: Pointer to the physical function struct
1900 * @cmd: The command to get or set Rx flow classification rules
1901 *
1902 * This function looks up a filter based on the Rx flow classification
1903 * command and fills the flow spec info for it if found
1904 *
1905 * Returns 0 on success or -EINVAL if filter not found
1906 **/
1907static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1908 struct ethtool_rxnfc *cmd)
1909{
1910 struct ethtool_rx_flow_spec *fsp =
1911 (struct ethtool_rx_flow_spec *)&cmd->fs;
1912 struct i40e_fdir_filter *rule = NULL;
1913 struct hlist_node *node2;
1914
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001915 hlist_for_each_entry_safe(rule, node2,
1916 &pf->fdir_filter_list, fdir_node) {
1917 if (fsp->location <= rule->fd_id)
1918 break;
1919 }
1920
1921 if (!rule || fsp->location != rule->fd_id)
1922 return -EINVAL;
1923
1924 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001925 if (fsp->flow_type == IP_USER_FLOW) {
1926 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1927 fsp->h_u.usr_ip4_spec.proto = 0;
1928 fsp->m_u.usr_ip4_spec.proto = 0;
1929 }
1930
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001931 /* Reverse the src and dest notion, since the HW views them from
1932 * Tx perspective where as the user expects it from Rx filter view.
1933 */
1934 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1935 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1936 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1937 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001938
1939 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1940 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1941 else
1942 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001943
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04001944 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1945 struct i40e_vsi *vsi;
1946
1947 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1948 if (vsi && vsi->type == I40E_VSI_SRIOV) {
1949 fsp->h_ext.data[1] = htonl(vsi->vf_id);
1950 fsp->m_ext.data[1] = htonl(0x1);
1951 }
1952 }
1953
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001954 return 0;
1955}
1956
1957/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958 * i40e_get_rxnfc - command to get RX flow classification rules
1959 * @netdev: network interface device structure
1960 * @cmd: ethtool rxnfc command
1961 *
1962 * Returns Success if the command is supported.
1963 **/
1964static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1965 u32 *rule_locs)
1966{
1967 struct i40e_netdev_priv *np = netdev_priv(netdev);
1968 struct i40e_vsi *vsi = np->vsi;
1969 struct i40e_pf *pf = vsi->back;
1970 int ret = -EOPNOTSUPP;
1971
1972 switch (cmd->cmd) {
1973 case ETHTOOL_GRXRINGS:
1974 cmd->data = vsi->alloc_queue_pairs;
1975 ret = 0;
1976 break;
1977 case ETHTOOL_GRXFH:
1978 ret = i40e_get_rss_hash_opts(pf, cmd);
1979 break;
1980 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001981 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001982 /* report total rule count */
1983 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001984 ret = 0;
1985 break;
1986 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001987 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001988 break;
1989 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001990 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1991 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992 default:
1993 break;
1994 }
1995
1996 return ret;
1997}
1998
1999/**
2000 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2001 * @pf: pointer to the physical function struct
2002 * @cmd: ethtool rxnfc command
2003 *
2004 * Returns Success if the flow input set is supported.
2005 **/
2006static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2007{
2008 struct i40e_hw *hw = &pf->hw;
2009 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2010 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2011
2012 /* RSS does not support anything other than hashing
2013 * to queues on src and dst IPs and ports
2014 */
2015 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2016 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2017 return -EINVAL;
2018
2019 /* We need at least the IP SRC and DEST fields for hashing */
2020 if (!(nfc->data & RXH_IP_SRC) ||
2021 !(nfc->data & RXH_IP_DST))
2022 return -EINVAL;
2023
2024 switch (nfc->flow_type) {
2025 case TCP_V4_FLOW:
2026 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2027 case 0:
2028 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2029 break;
2030 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2031 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
2032 break;
2033 default:
2034 return -EINVAL;
2035 }
2036 break;
2037 case TCP_V6_FLOW:
2038 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2039 case 0:
2040 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2041 break;
2042 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
2043 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
2044 break;
2045 default:
2046 return -EINVAL;
2047 }
2048 break;
2049 case UDP_V4_FLOW:
2050 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2051 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002052 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2053 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002054 break;
2055 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002056 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2057 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002058 break;
2059 default:
2060 return -EINVAL;
2061 }
2062 break;
2063 case UDP_V6_FLOW:
2064 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2065 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00002066 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2067 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002068 break;
2069 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002070 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2071 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002072 break;
2073 default:
2074 return -EINVAL;
2075 }
2076 break;
2077 case AH_ESP_V4_FLOW:
2078 case AH_V4_FLOW:
2079 case ESP_V4_FLOW:
2080 case SCTP_V4_FLOW:
2081 if ((nfc->data & RXH_L4_B_0_1) ||
2082 (nfc->data & RXH_L4_B_2_3))
2083 return -EINVAL;
2084 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2085 break;
2086 case AH_ESP_V6_FLOW:
2087 case AH_V6_FLOW:
2088 case ESP_V6_FLOW:
2089 case SCTP_V6_FLOW:
2090 if ((nfc->data & RXH_L4_B_0_1) ||
2091 (nfc->data & RXH_L4_B_2_3))
2092 return -EINVAL;
2093 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2094 break;
2095 case IPV4_FLOW:
2096 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2097 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2098 break;
2099 case IPV6_FLOW:
2100 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2101 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2102 break;
2103 default:
2104 return -EINVAL;
2105 }
2106
2107 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2108 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2109 i40e_flush(hw);
2110
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002111 /* Save setting for future output/update */
2112 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2113
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002114 return 0;
2115}
2116
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002117/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002118 * i40e_match_fdir_input_set - Match a new filter against an existing one
2119 * @rule: The filter already added
2120 * @input: The new filter to comapre against
2121 *
2122 * Returns true if the two input set match
2123 **/
2124static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2125 struct i40e_fdir_filter *input)
2126{
2127 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2128 (rule->src_ip[0] != input->src_ip[0]) ||
2129 (rule->dst_port != input->dst_port) ||
2130 (rule->src_port != input->src_port))
2131 return false;
2132 return true;
2133}
2134
2135/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002136 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2137 * @vsi: Pointer to the targeted VSI
2138 * @input: The filter to update or NULL to indicate deletion
2139 * @sw_idx: Software index to the filter
2140 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002141 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002142 * This function updates (or deletes) a Flow Director entry from
2143 * the hlist of the corresponding PF
2144 *
2145 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002146 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002147static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2148 struct i40e_fdir_filter *input,
2149 u16 sw_idx,
2150 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002151{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002152 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002153 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002154 struct hlist_node *node2;
2155 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002156
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002157 parent = NULL;
2158 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002159
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002160 hlist_for_each_entry_safe(rule, node2,
2161 &pf->fdir_filter_list, fdir_node) {
2162 /* hash found, or no matching entry */
2163 if (rule->fd_id >= sw_idx)
2164 break;
2165 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002166 }
2167
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002168 /* if there is an old rule occupying our place remove it */
2169 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002170 if (input && !i40e_match_fdir_input_set(rule, input))
2171 err = i40e_add_del_fdir(vsi, rule, false);
2172 else if (!input)
2173 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002174 hlist_del(&rule->fdir_node);
2175 kfree(rule);
2176 pf->fdir_pf_active_filters--;
2177 }
2178
2179 /* If no input this was a delete, err should be 0 if a rule was
2180 * successfully found and removed from the list else -EINVAL
2181 */
2182 if (!input)
2183 return err;
2184
2185 /* initialize node and set software index */
2186 INIT_HLIST_NODE(&input->fdir_node);
2187
2188 /* add filter to the list */
2189 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002190 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002191 else
2192 hlist_add_head(&input->fdir_node,
2193 &pf->fdir_filter_list);
2194
2195 /* update counts */
2196 pf->fdir_pf_active_filters++;
2197
2198 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002199}
2200
2201/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002202 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2203 * @vsi: Pointer to the targeted VSI
2204 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002206 * The function removes a Flow Director filter entry from the
2207 * hlist of the corresponding PF
2208 *
2209 * Returns 0 on success
2210 */
2211static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2212 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002213{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002214 struct ethtool_rx_flow_spec *fsp =
2215 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002216 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002217 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002218
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002219 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2220 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2221 return -EBUSY;
2222
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002223 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2224 return -EBUSY;
2225
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002226 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002227
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002228 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002229 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002230}
2231
2232/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002233 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002234 * @vsi: pointer to the targeted VSI
2235 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002236 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002237 * Add Flow Director filters for a specific flow spec based on their
2238 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002239 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002240static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2241 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002243 struct ethtool_rx_flow_spec *fsp;
2244 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002245 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002246 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002247 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002248
2249 if (!vsi)
2250 return -EINVAL;
2251
2252 pf = vsi->back;
2253
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002254 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2255 return -EOPNOTSUPP;
2256
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002257 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002258 return -ENOSPC;
2259
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002260 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2261 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2262 return -EBUSY;
2263
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002264 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2265 return -EBUSY;
2266
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002267 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2268
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002269 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2270 pf->hw.func_caps.fd_filters_guaranteed)) {
2271 return -EINVAL;
2272 }
2273
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002274 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2275 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002276 return -EINVAL;
2277
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002278 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002279
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002280 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002282
2283 input->fd_id = fsp->location;
2284
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002285 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2286 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2287 else
2288 input->dest_ctl =
2289 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2290
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002291 input->q_index = fsp->ring_cookie;
2292 input->flex_off = 0;
2293 input->pctype = 0;
2294 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002295 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002296 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002297 input->flow_type = fsp->flow_type;
2298 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002299
2300 /* Reverse the src and dest notion, since the HW expects them to be from
2301 * Tx perspective where as the input from user is from Rx filter view.
2302 */
2303 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2304 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2305 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2306 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002307
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002308 if (ntohl(fsp->m_ext.data[1])) {
2309 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2310 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2311 goto free_input;
2312 }
2313 vf_id = ntohl(fsp->h_ext.data[1]);
2314 /* Find vsi id from vf id and override dest vsi */
2315 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2316 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2317 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2318 goto free_input;
2319 }
2320 }
2321
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002322 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002323free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002324 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002325 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002326 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002327 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002328
2329 return ret;
2330}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002331
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002332/**
2333 * i40e_set_rxnfc - command to set RX flow classification rules
2334 * @netdev: network interface device structure
2335 * @cmd: ethtool rxnfc command
2336 *
2337 * Returns Success if the command is supported.
2338 **/
2339static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2340{
2341 struct i40e_netdev_priv *np = netdev_priv(netdev);
2342 struct i40e_vsi *vsi = np->vsi;
2343 struct i40e_pf *pf = vsi->back;
2344 int ret = -EOPNOTSUPP;
2345
2346 switch (cmd->cmd) {
2347 case ETHTOOL_SRXFH:
2348 ret = i40e_set_rss_hash_opt(pf, cmd);
2349 break;
2350 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002351 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002352 break;
2353 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002354 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002355 break;
2356 default:
2357 break;
2358 }
2359
2360 return ret;
2361}
2362
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002363/**
2364 * i40e_max_channels - get Max number of combined channels supported
2365 * @vsi: vsi pointer
2366 **/
2367static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2368{
2369 /* TODO: This code assumes DCB and FD is disabled for now. */
2370 return vsi->alloc_queue_pairs;
2371}
2372
2373/**
2374 * i40e_get_channels - Get the current channels enabled and max supported etc.
2375 * @netdev: network interface device structure
2376 * @ch: ethtool channels structure
2377 *
2378 * We don't support separate tx and rx queues as channels. The other count
2379 * represents how many queues are being used for control. max_combined counts
2380 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2381 * q_vectors since we support a lot more queue pairs than q_vectors.
2382 **/
2383static void i40e_get_channels(struct net_device *dev,
2384 struct ethtool_channels *ch)
2385{
2386 struct i40e_netdev_priv *np = netdev_priv(dev);
2387 struct i40e_vsi *vsi = np->vsi;
2388 struct i40e_pf *pf = vsi->back;
2389
2390 /* report maximum channels */
2391 ch->max_combined = i40e_max_channels(vsi);
2392
2393 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002394 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002395 ch->max_other = ch->other_count;
2396
2397 /* Note: This code assumes DCB is disabled for now. */
2398 ch->combined_count = vsi->num_queue_pairs;
2399}
2400
2401/**
2402 * i40e_set_channels - Set the new channels count.
2403 * @netdev: network interface device structure
2404 * @ch: ethtool channels structure
2405 *
2406 * The new channels count may not be the same as requested by the user
2407 * since it gets rounded down to a power of 2 value.
2408 **/
2409static int i40e_set_channels(struct net_device *dev,
2410 struct ethtool_channels *ch)
2411{
2412 struct i40e_netdev_priv *np = netdev_priv(dev);
2413 unsigned int count = ch->combined_count;
2414 struct i40e_vsi *vsi = np->vsi;
2415 struct i40e_pf *pf = vsi->back;
2416 int new_count;
2417
2418 /* We do not support setting channels for any other VSI at present */
2419 if (vsi->type != I40E_VSI_MAIN)
2420 return -EINVAL;
2421
2422 /* verify they are not requesting separate vectors */
2423 if (!count || ch->rx_count || ch->tx_count)
2424 return -EINVAL;
2425
2426 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002427 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002428 return -EINVAL;
2429
2430 /* verify the number of channels does not exceed hardware limits */
2431 if (count > i40e_max_channels(vsi))
2432 return -EINVAL;
2433
2434 /* update feature limits from largest to smallest supported values */
2435 /* TODO: Flow director limit, DCB etc */
2436
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002437 /* use rss_reconfig to rebuild with new queue count and update traffic
2438 * class queue mapping
2439 */
2440 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002441 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002442 return 0;
2443 else
2444 return -EINVAL;
2445}
2446
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002447#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2448/**
2449 * i40e_get_rxfh_key_size - get the RSS hash key size
2450 * @netdev: network interface device structure
2451 *
2452 * Returns the table size.
2453 **/
2454static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2455{
2456 return I40E_HKEY_ARRAY_SIZE;
2457}
2458
2459/**
2460 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2461 * @netdev: network interface device structure
2462 *
2463 * Returns the table size.
2464 **/
2465static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2466{
2467 return I40E_HLUT_ARRAY_SIZE;
2468}
2469
2470static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2471 u8 *hfunc)
2472{
2473 struct i40e_netdev_priv *np = netdev_priv(netdev);
2474 struct i40e_vsi *vsi = np->vsi;
2475 struct i40e_pf *pf = vsi->back;
2476 struct i40e_hw *hw = &pf->hw;
2477 u32 reg_val;
2478 int i, j;
2479
2480 if (hfunc)
2481 *hfunc = ETH_RSS_HASH_TOP;
2482
2483 if (!indir)
2484 return 0;
2485
2486 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2487 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2488 indir[j++] = reg_val & 0xff;
2489 indir[j++] = (reg_val >> 8) & 0xff;
2490 indir[j++] = (reg_val >> 16) & 0xff;
2491 indir[j++] = (reg_val >> 24) & 0xff;
2492 }
2493
2494 if (key) {
2495 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2496 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2497 key[j++] = (u8)(reg_val & 0xff);
2498 key[j++] = (u8)((reg_val >> 8) & 0xff);
2499 key[j++] = (u8)((reg_val >> 16) & 0xff);
2500 key[j++] = (u8)((reg_val >> 24) & 0xff);
2501 }
2502 }
2503 return 0;
2504}
2505
2506/**
2507 * i40e_set_rxfh - set the rx flow hash indirection table
2508 * @netdev: network interface device structure
2509 * @indir: indirection table
2510 * @key: hash key
2511 *
2512 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
2513 * returns 0 after programming the table.
2514 **/
2515static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2516 const u8 *key, const u8 hfunc)
2517{
2518 struct i40e_netdev_priv *np = netdev_priv(netdev);
2519 struct i40e_vsi *vsi = np->vsi;
2520 struct i40e_pf *pf = vsi->back;
2521 struct i40e_hw *hw = &pf->hw;
2522 u32 reg_val;
2523 int i, j;
2524
2525 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2526 return -EOPNOTSUPP;
2527
2528 if (!indir)
2529 return 0;
2530
2531 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2532 reg_val = indir[j++];
2533 reg_val |= indir[j++] << 8;
2534 reg_val |= indir[j++] << 16;
2535 reg_val |= indir[j++] << 24;
2536 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2537 }
2538
2539 if (key) {
2540 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2541 reg_val = key[j++];
2542 reg_val |= key[j++] << 8;
2543 reg_val |= key[j++] << 16;
2544 reg_val |= key[j++] << 24;
2545 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2546 }
2547 }
2548 return 0;
2549}
2550
Greg Rose7e45ab42015-02-06 08:52:19 +00002551/**
2552 * i40e_get_priv_flags - report device private flags
2553 * @dev: network interface device structure
2554 *
2555 * The get string set count and the string set should be matched for each
2556 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2557 * array.
2558 *
2559 * Returns a u32 bitmap of flags.
2560 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002561static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002562{
2563 struct i40e_netdev_priv *np = netdev_priv(dev);
2564 struct i40e_vsi *vsi = np->vsi;
2565 struct i40e_pf *pf = vsi->back;
2566 u32 ret_flags = 0;
2567
2568 ret_flags |= pf->hw.func_caps.npar_enable ?
2569 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2570
2571 return ret_flags;
2572}
2573
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002574static const struct ethtool_ops i40e_ethtool_ops = {
2575 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002576 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002577 .get_drvinfo = i40e_get_drvinfo,
2578 .get_regs_len = i40e_get_regs_len,
2579 .get_regs = i40e_get_regs,
2580 .nway_reset = i40e_nway_reset,
2581 .get_link = ethtool_op_get_link,
2582 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002583 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002584 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002585 .get_eeprom_len = i40e_get_eeprom_len,
2586 .get_eeprom = i40e_get_eeprom,
2587 .get_ringparam = i40e_get_ringparam,
2588 .set_ringparam = i40e_set_ringparam,
2589 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002590 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002591 .get_msglevel = i40e_get_msglevel,
2592 .set_msglevel = i40e_set_msglevel,
2593 .get_rxnfc = i40e_get_rxnfc,
2594 .set_rxnfc = i40e_set_rxnfc,
2595 .self_test = i40e_diag_test,
2596 .get_strings = i40e_get_strings,
2597 .set_phys_id = i40e_set_phys_id,
2598 .get_sset_count = i40e_get_sset_count,
2599 .get_ethtool_stats = i40e_get_ethtool_stats,
2600 .get_coalesce = i40e_get_coalesce,
2601 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002602 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2603 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2604 .get_rxfh = i40e_get_rxfh,
2605 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002606 .get_channels = i40e_get_channels,
2607 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002608 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002609 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002610};
2611
2612void i40e_set_ethtool_ops(struct net_device *netdev)
2613{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002614 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002615}