blob: 230d1270bfaaee0a9d77a200dccc74acbc886d31 [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),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400117 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000118 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 Jaind0389e52015-04-22 19:34:05 -0400151 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400153 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000154
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000155 /* LPI stats */
156 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
157 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
158 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
159 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000160};
161
Vasu Dev38e00432014-08-01 13:27:03 -0700162#ifdef I40E_FCOE
163static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
164 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
165 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
166 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
167 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
168 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
169 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
170 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
171 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
172};
173
174#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000175#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000176 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
177 * 2 /* Tx and Rx together */ \
178 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000179#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
180#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000181#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700182#ifdef I40E_FCOE
183#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
184#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
185 I40E_FCOE_STATS_LEN + \
186 I40E_MISC_STATS_LEN + \
187 I40E_QUEUE_STATS_LEN((n)))
188#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000190 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700192#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000193#define I40E_PFC_STATS_LEN ( \
194 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
199 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000200#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000201#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
202 I40E_PFC_STATS_LEN + \
203 I40E_VSI_STATS_LEN((n)))
204
205enum i40e_ethtool_test_id {
206 I40E_ETH_TEST_REG = 0,
207 I40E_ETH_TEST_EEPROM,
208 I40E_ETH_TEST_INTR,
209 I40E_ETH_TEST_LOOPBACK,
210 I40E_ETH_TEST_LINK,
211};
212
213static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
214 "Register test (offline)",
215 "Eeprom test (offline)",
216 "Interrupt test (offline)",
217 "Loopback test (offline)",
218 "Link test (on/offline)"
219};
220
221#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
222
Greg Rose7e45ab42015-02-06 08:52:19 +0000223static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
224 "NPAR",
225};
226
227#define I40E_PRIV_FLAGS_STR_LEN \
228 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
229
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000230/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000231 * i40e_partition_setting_complaint - generic complaint for MFP restriction
232 * @pf: the PF struct
233 **/
234static void i40e_partition_setting_complaint(struct i40e_pf *pf)
235{
236 dev_info(&pf->pdev->dev,
237 "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");
238}
239
240/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000241 * i40e_get_settings_link_up - Get the Link settings for when link is up
242 * @hw: hw structure
243 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000244 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000245 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000246 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000247static void i40e_get_settings_link_up(struct i40e_hw *hw,
248 struct ethtool_cmd *ecmd,
249 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000250{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 u32 link_speed = hw_link_info->link_speed;
253
Catherine Sullivane8278452015-02-06 08:52:08 +0000254 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000255 switch (hw_link_info->phy_type) {
256 case I40E_PHY_TYPE_40GBASE_CR4:
257 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000258 ecmd->supported = SUPPORTED_Autoneg |
259 SUPPORTED_40000baseCR4_Full;
260 ecmd->advertising = ADVERTISED_Autoneg |
261 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000263 case I40E_PHY_TYPE_XLAUI:
264 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000265 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000266 ecmd->supported = SUPPORTED_40000baseCR4_Full;
267 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000268 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000269 ecmd->supported = SUPPORTED_Autoneg |
270 SUPPORTED_40000baseKR4_Full;
271 ecmd->advertising = ADVERTISED_Autoneg |
272 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000273 break;
274 case I40E_PHY_TYPE_40GBASE_SR4:
275 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000276 break;
277 case I40E_PHY_TYPE_40GBASE_LR4:
278 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000279 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700280 case I40E_PHY_TYPE_20GBASE_KR2:
281 ecmd->supported = SUPPORTED_Autoneg |
282 SUPPORTED_20000baseKR2_Full;
283 ecmd->advertising = ADVERTISED_Autoneg |
284 ADVERTISED_20000baseKR2_Full;
285 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000286 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000287 ecmd->supported = SUPPORTED_Autoneg |
288 SUPPORTED_10000baseKX4_Full;
289 ecmd->advertising = ADVERTISED_Autoneg |
290 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000291 break;
292 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000293 ecmd->supported = SUPPORTED_Autoneg |
294 SUPPORTED_10000baseKR_Full;
295 ecmd->advertising = ADVERTISED_Autoneg |
296 ADVERTISED_10000baseKR_Full;
297 break;
298 case I40E_PHY_TYPE_10GBASE_SR:
299 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000300 case I40E_PHY_TYPE_1000BASE_SX:
301 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000302 ecmd->supported = SUPPORTED_10000baseT_Full |
303 SUPPORTED_1000baseT_Full;
304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
305 ecmd->advertising |= ADVERTISED_10000baseT_Full;
306 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
307 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000308 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000309 case I40E_PHY_TYPE_1000BASE_KX:
310 ecmd->supported = SUPPORTED_Autoneg |
311 SUPPORTED_1000baseKX_Full;
312 ecmd->advertising = ADVERTISED_Autoneg |
313 ADVERTISED_1000baseKX_Full;
314 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000315 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000316 case I40E_PHY_TYPE_1000BASE_T:
317 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000318 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000319 SUPPORTED_10000baseT_Full |
320 SUPPORTED_1000baseT_Full |
321 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000322 ecmd->advertising = ADVERTISED_Autoneg;
323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
324 ecmd->advertising |= ADVERTISED_10000baseT_Full;
325 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
326 ecmd->advertising |= ADVERTISED_1000baseT_Full;
327 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
328 ecmd->advertising |= ADVERTISED_100baseT_Full;
329 break;
330 case I40E_PHY_TYPE_10GBASE_CR1_CU:
331 case I40E_PHY_TYPE_10GBASE_CR1:
332 ecmd->supported = SUPPORTED_Autoneg |
333 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000334 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000335 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336 break;
337 case I40E_PHY_TYPE_XAUI:
338 case I40E_PHY_TYPE_XFI:
339 case I40E_PHY_TYPE_SFI:
340 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000341 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000342 ecmd->supported = SUPPORTED_10000baseT_Full;
343 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000344 case I40E_PHY_TYPE_SGMII:
345 ecmd->supported = SUPPORTED_Autoneg |
346 SUPPORTED_1000baseT_Full |
347 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000348 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
349 ecmd->advertising |= ADVERTISED_1000baseT_Full;
350 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
351 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000352 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000353 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000354 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000355 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
356 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000357 }
358
Catherine Sullivane8278452015-02-06 08:52:08 +0000359 /* Set speed and duplex */
360 switch (link_speed) {
361 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400362 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000363 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700364 case I40E_LINK_SPEED_20GB:
365 ethtool_cmd_speed_set(ecmd, SPEED_20000);
366 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000367 case I40E_LINK_SPEED_10GB:
368 ethtool_cmd_speed_set(ecmd, SPEED_10000);
369 break;
370 case I40E_LINK_SPEED_1GB:
371 ethtool_cmd_speed_set(ecmd, SPEED_1000);
372 break;
373 case I40E_LINK_SPEED_100MB:
374 ethtool_cmd_speed_set(ecmd, SPEED_100);
375 break;
376 default:
377 break;
378 }
379 ecmd->duplex = DUPLEX_FULL;
380}
381
382/**
383 * i40e_get_settings_link_down - Get the Link settings for when link is down
384 * @hw: hw structure
385 * @ecmd: ethtool command to fill in
386 *
387 * Reports link settings that can be determined when link is down
388 **/
389static void i40e_get_settings_link_down(struct i40e_hw *hw,
390 struct ethtool_cmd *ecmd)
391{
392 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
393
394 /* link is down and the driver needs to fall back on
395 * device ID to determine what kinds of info to display,
396 * it's mostly a guess that may change when link is up
397 */
398 switch (hw->device_id) {
399 case I40E_DEV_ID_QSFP_A:
400 case I40E_DEV_ID_QSFP_B:
401 case I40E_DEV_ID_QSFP_C:
402 /* pluggable QSFP */
403 ecmd->supported = SUPPORTED_40000baseSR4_Full |
404 SUPPORTED_40000baseCR4_Full |
405 SUPPORTED_40000baseLR4_Full;
406 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
407 ADVERTISED_40000baseCR4_Full |
408 ADVERTISED_40000baseLR4_Full;
409 break;
410 case I40E_DEV_ID_KX_B:
411 /* backplane 40G */
412 ecmd->supported = SUPPORTED_40000baseKR4_Full;
413 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
414 break;
415 case I40E_DEV_ID_KX_C:
416 /* backplane 10G */
417 ecmd->supported = SUPPORTED_10000baseKR_Full;
418 ecmd->advertising = ADVERTISED_10000baseKR_Full;
419 break;
420 case I40E_DEV_ID_10G_BASE_T:
421 ecmd->supported = SUPPORTED_10000baseT_Full |
422 SUPPORTED_1000baseT_Full |
423 SUPPORTED_100baseT_Full;
424 /* Figure out what has been requested */
425 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
426 ecmd->advertising |= ADVERTISED_10000baseT_Full;
427 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
428 ecmd->advertising |= ADVERTISED_1000baseT_Full;
429 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
430 ecmd->advertising |= ADVERTISED_100baseT_Full;
431 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700432 case I40E_DEV_ID_20G_KR2:
433 /* backplane 20G */
434 ecmd->supported = SUPPORTED_20000baseKR2_Full;
435 ecmd->advertising = ADVERTISED_20000baseKR2_Full;
436 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000437 default:
438 /* all the rest are 10G/1G */
439 ecmd->supported = SUPPORTED_10000baseT_Full |
440 SUPPORTED_1000baseT_Full;
441 /* Figure out what has been requested */
442 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
443 ecmd->advertising |= ADVERTISED_10000baseT_Full;
444 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
445 ecmd->advertising |= ADVERTISED_1000baseT_Full;
446 break;
447 }
448
449 /* With no link speed and duplex are unknown */
450 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
451 ecmd->duplex = DUPLEX_UNKNOWN;
452}
453
454/**
455 * i40e_get_settings - Get Link Speed and Duplex settings
456 * @netdev: network interface device structure
457 * @ecmd: ethtool command
458 *
459 * Reports speed/duplex settings based on media_type
460 **/
461static int i40e_get_settings(struct net_device *netdev,
462 struct ethtool_cmd *ecmd)
463{
464 struct i40e_netdev_priv *np = netdev_priv(netdev);
465 struct i40e_pf *pf = np->vsi->back;
466 struct i40e_hw *hw = &pf->hw;
467 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
468 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
469
470 if (link_up)
471 i40e_get_settings_link_up(hw, ecmd, netdev);
472 else
473 i40e_get_settings_link_down(hw, ecmd);
474
475 /* Now set the settings that don't rely on link being up/down */
476
477 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000478 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
479 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000480
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000481 switch (hw->phy.media_type) {
482 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000483 ecmd->supported |= SUPPORTED_Autoneg |
484 SUPPORTED_Backplane;
485 ecmd->advertising |= ADVERTISED_Autoneg |
486 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000487 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000488 break;
489 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490 ecmd->supported |= SUPPORTED_TP;
491 ecmd->advertising |= ADVERTISED_TP;
492 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000493 break;
494 case I40E_MEDIA_TYPE_DA:
495 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000496 ecmd->supported |= SUPPORTED_FIBRE;
497 ecmd->advertising |= ADVERTISED_FIBRE;
498 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000499 break;
500 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000501 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000502 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000503 break;
504 case I40E_MEDIA_TYPE_UNKNOWN:
505 default:
506 ecmd->port = PORT_OTHER;
507 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000508 }
509
Catherine Sullivane8278452015-02-06 08:52:08 +0000510 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000511 ecmd->transceiver = XCVR_EXTERNAL;
512
Catherine Sullivane8278452015-02-06 08:52:08 +0000513 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000514 ecmd->supported |= SUPPORTED_Pause;
515
Catherine Sullivane8278452015-02-06 08:52:08 +0000516 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000517 case I40E_FC_FULL:
518 ecmd->advertising |= ADVERTISED_Pause;
519 break;
520 case I40E_FC_TX_PAUSE:
521 ecmd->advertising |= ADVERTISED_Asym_Pause;
522 break;
523 case I40E_FC_RX_PAUSE:
524 ecmd->advertising |= (ADVERTISED_Pause |
525 ADVERTISED_Asym_Pause);
526 break;
527 default:
528 ecmd->advertising &= ~(ADVERTISED_Pause |
529 ADVERTISED_Asym_Pause);
530 break;
531 }
532
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000533 return 0;
534}
535
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000536/**
537 * i40e_set_settings - Set Speed and Duplex
538 * @netdev: network interface device structure
539 * @ecmd: ethtool command
540 *
541 * Set speed/duplex per media_types advertised/forced
542 **/
543static int i40e_set_settings(struct net_device *netdev,
544 struct ethtool_cmd *ecmd)
545{
546 struct i40e_netdev_priv *np = netdev_priv(netdev);
547 struct i40e_aq_get_phy_abilities_resp abilities;
548 struct i40e_aq_set_phy_config config;
549 struct i40e_pf *pf = np->vsi->back;
550 struct i40e_vsi *vsi = np->vsi;
551 struct i40e_hw *hw = &pf->hw;
552 struct ethtool_cmd safe_ecmd;
553 i40e_status status = 0;
554 bool change = false;
555 int err = 0;
556 u8 autoneg;
557 u32 advertise;
558
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000559 /* Changing port settings is not supported if this isn't the
560 * port's controlling PF
561 */
562 if (hw->partition_id != 1) {
563 i40e_partition_setting_complaint(pf);
564 return -EOPNOTSUPP;
565 }
566
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000567 if (vsi != pf->vsi[pf->lan_vsi])
568 return -EOPNOTSUPP;
569
570 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
571 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000572 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
573 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000574 return -EOPNOTSUPP;
575
576 /* get our own copy of the bits to check against */
577 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
578 i40e_get_settings(netdev, &safe_ecmd);
579
580 /* save autoneg and speed out of ecmd */
581 autoneg = ecmd->autoneg;
582 advertise = ecmd->advertising;
583
584 /* set autoneg and speed back to what they currently are */
585 ecmd->autoneg = safe_ecmd.autoneg;
586 ecmd->advertising = safe_ecmd.advertising;
587
588 ecmd->cmd = safe_ecmd.cmd;
589 /* If ecmd and safe_ecmd are not the same now, then they are
590 * trying to set something that we do not support
591 */
592 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
593 return -EOPNOTSUPP;
594
595 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
596 usleep_range(1000, 2000);
597
598 /* Get the current phy config */
599 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
600 NULL);
601 if (status)
602 return -EAGAIN;
603
Catherine Sullivan124ed152014-07-12 07:28:12 +0000604 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000605 * set below
606 */
607 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000608 config.abilities = abilities.abilities;
609
610 /* Check autoneg */
611 if (autoneg == AUTONEG_ENABLE) {
612 /* If autoneg is not supported, return error */
613 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
614 netdev_info(netdev, "Autoneg not supported on this phy\n");
615 return -EINVAL;
616 }
617 /* If autoneg was not already enabled */
618 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
619 config.abilities = abilities.abilities |
620 I40E_AQ_PHY_ENABLE_AN;
621 change = true;
622 }
623 } else {
624 /* If autoneg is supported 10GBASE_T is the only phy that
625 * can disable it, so otherwise return error
626 */
627 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
628 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
629 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
630 return -EINVAL;
631 }
632 /* If autoneg is currently enabled */
633 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000634 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000635 ~I40E_AQ_PHY_ENABLE_AN;
636 change = true;
637 }
638 }
639
640 if (advertise & ~safe_ecmd.supported)
641 return -EINVAL;
642
643 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000644 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000645 if (advertise & ADVERTISED_1000baseT_Full ||
646 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000647 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000648 if (advertise & ADVERTISED_10000baseT_Full ||
649 advertise & ADVERTISED_10000baseKX4_Full ||
650 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000651 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700652 if (advertise & ADVERTISED_20000baseKR2_Full)
653 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000654 if (advertise & ADVERTISED_40000baseKR4_Full ||
655 advertise & ADVERTISED_40000baseCR4_Full ||
656 advertise & ADVERTISED_40000baseSR4_Full ||
657 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000658 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000659
Catherine Sullivan124ed152014-07-12 07:28:12 +0000660 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000661 /* copy over the rest of the abilities */
662 config.phy_type = abilities.phy_type;
663 config.eee_capability = abilities.eee_capability;
664 config.eeer = abilities.eeer_val;
665 config.low_power_ctrl = abilities.d3_lpan;
666
Catherine Sullivane8278452015-02-06 08:52:08 +0000667 /* save the requested speeds */
668 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000669 /* set link and auto negotiation so changes take effect */
670 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
671 /* If link is up put link down */
672 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
673 /* Tell the OS link is going down, the link will go
674 * back up when fw says it is ready asynchronously
675 */
676 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
677 netif_carrier_off(netdev);
678 netif_tx_stop_all_queues(netdev);
679 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000680
681 /* make the aq call */
682 status = i40e_aq_set_phy_config(hw, &config, NULL);
683 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400684 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
685 i40e_stat_str(hw, status),
686 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000687 return -EAGAIN;
688 }
689
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000690 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000691 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400692 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
693 i40e_stat_str(hw, status),
694 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000695
696 } else {
697 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
698 }
699
700 return err;
701}
702
Jesse Brandeburga6599722014-06-04 08:45:25 +0000703static int i40e_nway_reset(struct net_device *netdev)
704{
705 /* restart autonegotiation */
706 struct i40e_netdev_priv *np = netdev_priv(netdev);
707 struct i40e_pf *pf = np->vsi->back;
708 struct i40e_hw *hw = &pf->hw;
709 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
710 i40e_status ret = 0;
711
712 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
713 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400714 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
715 i40e_stat_str(hw, ret),
716 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000717 return -EIO;
718 }
719
720 return 0;
721}
722
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000723/**
724 * i40e_get_pauseparam - Get Flow Control status
725 * Return tx/rx-pause status
726 **/
727static void i40e_get_pauseparam(struct net_device *netdev,
728 struct ethtool_pauseparam *pause)
729{
730 struct i40e_netdev_priv *np = netdev_priv(netdev);
731 struct i40e_pf *pf = np->vsi->back;
732 struct i40e_hw *hw = &pf->hw;
733 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000734 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000735
736 pause->autoneg =
737 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
738 AUTONEG_ENABLE : AUTONEG_DISABLE);
739
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000740 /* PFC enabled so report LFC as off */
741 if (dcbx_cfg->pfc.pfcenable) {
742 pause->rx_pause = 0;
743 pause->tx_pause = 0;
744 return;
745 }
746
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000747 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000748 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000749 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000750 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000751 } else if (hw->fc.current_mode == I40E_FC_FULL) {
752 pause->rx_pause = 1;
753 pause->tx_pause = 1;
754 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000755}
756
Catherine Sullivan2becc352014-06-04 08:45:27 +0000757/**
758 * i40e_set_pauseparam - Set Flow Control parameter
759 * @netdev: network interface device structure
760 * @pause: return tx/rx flow control status
761 **/
762static int i40e_set_pauseparam(struct net_device *netdev,
763 struct ethtool_pauseparam *pause)
764{
765 struct i40e_netdev_priv *np = netdev_priv(netdev);
766 struct i40e_pf *pf = np->vsi->back;
767 struct i40e_vsi *vsi = np->vsi;
768 struct i40e_hw *hw = &pf->hw;
769 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000770 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000771 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
772 i40e_status status;
773 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000774 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000775
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000776 /* Changing the port's flow control is not supported if this isn't the
777 * port's controlling PF
778 */
779 if (hw->partition_id != 1) {
780 i40e_partition_setting_complaint(pf);
781 return -EOPNOTSUPP;
782 }
783
Catherine Sullivan2becc352014-06-04 08:45:27 +0000784 if (vsi != pf->vsi[pf->lan_vsi])
785 return -EOPNOTSUPP;
786
787 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
788 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
789 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
790 return -EOPNOTSUPP;
791 }
792
793 /* If we have link and don't have autoneg */
794 if (!test_bit(__I40E_DOWN, &pf->state) &&
795 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
796 /* Send message that it might not necessarily work*/
797 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
798 }
799
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000800 if (dcbx_cfg->pfc.pfcenable) {
801 netdev_info(netdev,
802 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000803 return -EOPNOTSUPP;
804 }
805
806 if (pause->rx_pause && pause->tx_pause)
807 hw->fc.requested_mode = I40E_FC_FULL;
808 else if (pause->rx_pause && !pause->tx_pause)
809 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
810 else if (!pause->rx_pause && pause->tx_pause)
811 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
812 else if (!pause->rx_pause && !pause->tx_pause)
813 hw->fc.requested_mode = I40E_FC_NONE;
814 else
815 return -EINVAL;
816
Catherine Sullivan94128512014-07-12 07:28:16 +0000817 /* Tell the OS link is going down, the link will go back up when fw
818 * says it is ready asynchronously
819 */
820 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
821 netif_carrier_off(netdev);
822 netif_tx_stop_all_queues(netdev);
823
Catherine Sullivan2becc352014-06-04 08:45:27 +0000824 /* Set the fc mode and only restart an if link is up*/
825 status = i40e_set_fc(hw, &aq_failures, link_up);
826
827 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400828 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
829 i40e_stat_str(hw, status),
830 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000831 err = -EAGAIN;
832 }
833 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400834 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
835 i40e_stat_str(hw, status),
836 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000837 err = -EAGAIN;
838 }
839 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400840 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
841 i40e_stat_str(hw, status),
842 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000843 err = -EAGAIN;
844 }
845
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000846 if (!test_bit(__I40E_DOWN, &pf->state)) {
847 /* Give it a little more time to try to come back */
848 msleep(75);
849 if (!test_bit(__I40E_DOWN, &pf->state))
850 return i40e_nway_reset(netdev);
851 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000852
853 return err;
854}
855
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000856static u32 i40e_get_msglevel(struct net_device *netdev)
857{
858 struct i40e_netdev_priv *np = netdev_priv(netdev);
859 struct i40e_pf *pf = np->vsi->back;
860
861 return pf->msg_enable;
862}
863
864static void i40e_set_msglevel(struct net_device *netdev, u32 data)
865{
866 struct i40e_netdev_priv *np = netdev_priv(netdev);
867 struct i40e_pf *pf = np->vsi->back;
868
869 if (I40E_DEBUG_USER & data)
870 pf->hw.debug_mask = data;
871 pf->msg_enable = data;
872}
873
874static int i40e_get_regs_len(struct net_device *netdev)
875{
876 int reg_count = 0;
877 int i;
878
879 for (i = 0; i40e_reg_list[i].offset != 0; i++)
880 reg_count += i40e_reg_list[i].elements;
881
882 return reg_count * sizeof(u32);
883}
884
885static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
886 void *p)
887{
888 struct i40e_netdev_priv *np = netdev_priv(netdev);
889 struct i40e_pf *pf = np->vsi->back;
890 struct i40e_hw *hw = &pf->hw;
891 u32 *reg_buf = p;
892 int i, j, ri;
893 u32 reg;
894
895 /* Tell ethtool which driver-version-specific regs output we have.
896 *
897 * At some point, if we have ethtool doing special formatting of
898 * this data, it will rely on this version number to know how to
899 * interpret things. Hence, this needs to be updated if/when the
900 * diags register table is changed.
901 */
902 regs->version = 1;
903
904 /* loop through the diags reg table for what to print */
905 ri = 0;
906 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
907 for (j = 0; j < i40e_reg_list[i].elements; j++) {
908 reg = i40e_reg_list[i].offset
909 + (j * i40e_reg_list[i].stride);
910 reg_buf[ri++] = rd32(hw, reg);
911 }
912 }
913
914}
915
916static int i40e_get_eeprom(struct net_device *netdev,
917 struct ethtool_eeprom *eeprom, u8 *bytes)
918{
919 struct i40e_netdev_priv *np = netdev_priv(netdev);
920 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000921 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000922 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000923 u8 *eeprom_buff;
924 u16 i, sectors;
925 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000926 u32 magic;
927
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000928#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000929 if (eeprom->len == 0)
930 return -EINVAL;
931
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000932 /* check for NVMUpdate access method */
933 magic = hw->vendor_id | (hw->device_id << 16);
934 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000935 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000936 int errno;
937
938 /* make sure it is the right magic for NVMUpdate */
939 if ((eeprom->magic >> 16) != hw->device_id)
940 return -EINVAL;
941
Shannon Nelsonc150a502014-11-13 08:23:13 +0000942 cmd = (struct i40e_nvm_access *)eeprom;
943 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000944 if (ret_val &&
945 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
946 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000947 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000948 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
949 ret_val, hw->aq.asq_last_status, errno,
950 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
951 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000952
953 return errno;
954 }
955
956 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000957 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
958
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000959 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000960 if (!eeprom_buff)
961 return -ENOMEM;
962
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000963 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
964 if (ret_val) {
965 dev_info(&pf->pdev->dev,
966 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
967 ret_val, hw->aq.asq_last_status);
968 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000969 }
970
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000971 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
972 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
973 len = I40E_NVM_SECTOR_SIZE;
974 last = false;
975 for (i = 0; i < sectors; i++) {
976 if (i == (sectors - 1)) {
977 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
978 last = true;
979 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000980 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
981 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000982 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000983 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000984 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000985 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000986 "read NVM failed, invalid offset 0x%x\n",
987 offset);
988 break;
989 } else if (ret_val &&
990 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
991 dev_info(&pf->pdev->dev,
992 "read NVM failed, access, offset 0x%x\n",
993 offset);
994 break;
995 } else if (ret_val) {
996 dev_info(&pf->pdev->dev,
997 "read NVM failed offset %d err=%d status=0x%x\n",
998 offset, ret_val, hw->aq.asq_last_status);
999 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001000 }
1001 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001002
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001003 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001004 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001005free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001006 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001007 return ret_val;
1008}
1009
1010static int i40e_get_eeprom_len(struct net_device *netdev)
1011{
1012 struct i40e_netdev_priv *np = netdev_priv(netdev);
1013 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001014 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001015
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001016 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1017 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1018 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1019 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001020 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001021 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001022}
1023
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001024static int i40e_set_eeprom(struct net_device *netdev,
1025 struct ethtool_eeprom *eeprom, u8 *bytes)
1026{
1027 struct i40e_netdev_priv *np = netdev_priv(netdev);
1028 struct i40e_hw *hw = &np->vsi->back->hw;
1029 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001030 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001031 int ret_val = 0;
1032 int errno;
1033 u32 magic;
1034
1035 /* normal ethtool set_eeprom is not supported */
1036 magic = hw->vendor_id | (hw->device_id << 16);
1037 if (eeprom->magic == magic)
1038 return -EOPNOTSUPP;
1039
1040 /* check for NVMUpdate access method */
1041 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1042 return -EINVAL;
1043
1044 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1045 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1046 return -EBUSY;
1047
Shannon Nelsonc150a502014-11-13 08:23:13 +00001048 cmd = (struct i40e_nvm_access *)eeprom;
1049 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001050 if (ret_val &&
1051 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1052 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1053 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001054 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001055 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1056 ret_val, hw->aq.asq_last_status, errno,
1057 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1058 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001059
1060 return errno;
1061}
1062
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063static void i40e_get_drvinfo(struct net_device *netdev,
1064 struct ethtool_drvinfo *drvinfo)
1065{
1066 struct i40e_netdev_priv *np = netdev_priv(netdev);
1067 struct i40e_vsi *vsi = np->vsi;
1068 struct i40e_pf *pf = vsi->back;
1069
1070 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1071 strlcpy(drvinfo->version, i40e_driver_version_str,
1072 sizeof(drvinfo->version));
1073 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1074 sizeof(drvinfo->fw_version));
1075 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1076 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001077 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001078}
1079
1080static void i40e_get_ringparam(struct net_device *netdev,
1081 struct ethtool_ringparam *ring)
1082{
1083 struct i40e_netdev_priv *np = netdev_priv(netdev);
1084 struct i40e_pf *pf = np->vsi->back;
1085 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1086
1087 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1088 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1089 ring->rx_mini_max_pending = 0;
1090 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001091 ring->rx_pending = vsi->rx_rings[0]->count;
1092 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001093 ring->rx_mini_pending = 0;
1094 ring->rx_jumbo_pending = 0;
1095}
1096
1097static int i40e_set_ringparam(struct net_device *netdev,
1098 struct ethtool_ringparam *ring)
1099{
1100 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1101 struct i40e_netdev_priv *np = netdev_priv(netdev);
1102 struct i40e_vsi *vsi = np->vsi;
1103 struct i40e_pf *pf = vsi->back;
1104 u32 new_rx_count, new_tx_count;
1105 int i, err = 0;
1106
1107 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1108 return -EINVAL;
1109
Shannon Nelson1fa18372013-11-20 10:03:08 +00001110 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1111 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1112 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1113 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1114 netdev_info(netdev,
1115 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1116 ring->tx_pending, ring->rx_pending,
1117 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1118 return -EINVAL;
1119 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001120
Shannon Nelson1fa18372013-11-20 10:03:08 +00001121 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1122 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001123
1124 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001125 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1126 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001127 return 0;
1128
1129 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1130 usleep_range(1000, 2000);
1131
1132 if (!netif_running(vsi->netdev)) {
1133 /* simple case - set for the next time the netdev is started */
1134 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001135 vsi->tx_rings[i]->count = new_tx_count;
1136 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001137 }
1138 goto done;
1139 }
1140
1141 /* We can't just free everything and then setup again,
1142 * because the ISRs in MSI-X mode get passed pointers
1143 * to the Tx and Rx ring structs.
1144 */
1145
1146 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001147 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001148 netdev_info(netdev,
1149 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001150 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001151 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1152 sizeof(struct i40e_ring), GFP_KERNEL);
1153 if (!tx_rings) {
1154 err = -ENOMEM;
1155 goto done;
1156 }
1157
1158 for (i = 0; i < vsi->num_queue_pairs; i++) {
1159 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001160 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001161 tx_rings[i].count = new_tx_count;
1162 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1163 if (err) {
1164 while (i) {
1165 i--;
1166 i40e_free_tx_resources(&tx_rings[i]);
1167 }
1168 kfree(tx_rings);
1169 tx_rings = NULL;
1170
1171 goto done;
1172 }
1173 }
1174 }
1175
1176 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001177 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001178 netdev_info(netdev,
1179 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001180 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001181 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1182 sizeof(struct i40e_ring), GFP_KERNEL);
1183 if (!rx_rings) {
1184 err = -ENOMEM;
1185 goto free_tx;
1186 }
1187
1188 for (i = 0; i < vsi->num_queue_pairs; i++) {
1189 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001190 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001191 rx_rings[i].count = new_rx_count;
1192 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1193 if (err) {
1194 while (i) {
1195 i--;
1196 i40e_free_rx_resources(&rx_rings[i]);
1197 }
1198 kfree(rx_rings);
1199 rx_rings = NULL;
1200
1201 goto free_tx;
1202 }
1203 }
1204 }
1205
1206 /* Bring interface down, copy in the new ring info,
1207 * then restore the interface
1208 */
1209 i40e_down(vsi);
1210
1211 if (tx_rings) {
1212 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001213 i40e_free_tx_resources(vsi->tx_rings[i]);
1214 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001215 }
1216 kfree(tx_rings);
1217 tx_rings = NULL;
1218 }
1219
1220 if (rx_rings) {
1221 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001222 i40e_free_rx_resources(vsi->rx_rings[i]);
1223 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001224 }
1225 kfree(rx_rings);
1226 rx_rings = NULL;
1227 }
1228
1229 i40e_up(vsi);
1230
1231free_tx:
1232 /* error cleanup if the Rx allocations failed after getting Tx */
1233 if (tx_rings) {
1234 for (i = 0; i < vsi->num_queue_pairs; i++)
1235 i40e_free_tx_resources(&tx_rings[i]);
1236 kfree(tx_rings);
1237 tx_rings = NULL;
1238 }
1239
1240done:
1241 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1242
1243 return err;
1244}
1245
1246static int i40e_get_sset_count(struct net_device *netdev, int sset)
1247{
1248 struct i40e_netdev_priv *np = netdev_priv(netdev);
1249 struct i40e_vsi *vsi = np->vsi;
1250 struct i40e_pf *pf = vsi->back;
1251
1252 switch (sset) {
1253 case ETH_SS_TEST:
1254 return I40E_TEST_LEN;
1255 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001256 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001257 int len = I40E_PF_STATS_LEN(netdev);
1258
1259 if (pf->lan_veb != I40E_NO_VEB)
1260 len += I40E_VEB_STATS_LEN;
1261 return len;
1262 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001263 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001264 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001265 case ETH_SS_PRIV_FLAGS:
1266 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001267 default:
1268 return -EOPNOTSUPP;
1269 }
1270}
1271
1272static void i40e_get_ethtool_stats(struct net_device *netdev,
1273 struct ethtool_stats *stats, u64 *data)
1274{
1275 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001276 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 struct i40e_vsi *vsi = np->vsi;
1278 struct i40e_pf *pf = vsi->back;
1279 int i = 0;
1280 char *p;
1281 int j;
1282 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001283 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001284
1285 i40e_update_stats(vsi);
1286
1287 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1288 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1289 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1290 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1291 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001292 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1293 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1294 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1295 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1296 }
Vasu Dev38e00432014-08-01 13:27:03 -07001297#ifdef I40E_FCOE
1298 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1299 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1300 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1301 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1302 }
1303#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001304 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001305 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001306 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001307
1308 if (!tx_ring)
1309 continue;
1310
1311 /* process Tx ring statistics */
1312 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001313 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001314 data[i] = tx_ring->stats.packets;
1315 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001316 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001317 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001318
1319 /* Rx ring is the 2nd half of the queue pair */
1320 rx_ring = &tx_ring[1];
1321 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001322 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001323 data[i] = rx_ring->stats.packets;
1324 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001325 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001326 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001327 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001328 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001329 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001330 return;
1331
1332 if (pf->lan_veb != I40E_NO_VEB) {
1333 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1334 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1335 p = (char *)veb;
1336 p += i40e_gstrings_veb_stats[j].stat_offset;
1337 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1338 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001339 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001340 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001341 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1342 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1343 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1344 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1345 }
1346 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1347 data[i++] = pf->stats.priority_xon_tx[j];
1348 data[i++] = pf->stats.priority_xoff_tx[j];
1349 }
1350 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1351 data[i++] = pf->stats.priority_xon_rx[j];
1352 data[i++] = pf->stats.priority_xoff_rx[j];
1353 }
1354 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1355 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001356}
1357
1358static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1359 u8 *data)
1360{
1361 struct i40e_netdev_priv *np = netdev_priv(netdev);
1362 struct i40e_vsi *vsi = np->vsi;
1363 struct i40e_pf *pf = vsi->back;
1364 char *p = (char *)data;
1365 int i;
1366
1367 switch (stringset) {
1368 case ETH_SS_TEST:
1369 for (i = 0; i < I40E_TEST_LEN; i++) {
1370 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1371 data += ETH_GSTRING_LEN;
1372 }
1373 break;
1374 case ETH_SS_STATS:
1375 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1376 snprintf(p, ETH_GSTRING_LEN, "%s",
1377 i40e_gstrings_net_stats[i].stat_string);
1378 p += ETH_GSTRING_LEN;
1379 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001380 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1381 snprintf(p, ETH_GSTRING_LEN, "%s",
1382 i40e_gstrings_misc_stats[i].stat_string);
1383 p += ETH_GSTRING_LEN;
1384 }
Vasu Dev38e00432014-08-01 13:27:03 -07001385#ifdef I40E_FCOE
1386 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1387 snprintf(p, ETH_GSTRING_LEN, "%s",
1388 i40e_gstrings_fcoe_stats[i].stat_string);
1389 p += ETH_GSTRING_LEN;
1390 }
1391#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392 for (i = 0; i < vsi->num_queue_pairs; i++) {
1393 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1394 p += ETH_GSTRING_LEN;
1395 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1396 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001397 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1398 p += ETH_GSTRING_LEN;
1399 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1400 p += ETH_GSTRING_LEN;
1401 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001402 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001403 return;
1404
1405 if (pf->lan_veb != I40E_NO_VEB) {
1406 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1407 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1408 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001409 p += ETH_GSTRING_LEN;
1410 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001411 }
1412 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1413 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1414 i40e_gstrings_stats[i].stat_string);
1415 p += ETH_GSTRING_LEN;
1416 }
1417 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1418 snprintf(p, ETH_GSTRING_LEN,
1419 "port.tx_priority_%u_xon", i);
1420 p += ETH_GSTRING_LEN;
1421 snprintf(p, ETH_GSTRING_LEN,
1422 "port.tx_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", i);
1428 p += ETH_GSTRING_LEN;
1429 snprintf(p, ETH_GSTRING_LEN,
1430 "port.rx_priority_%u_xoff", i);
1431 p += ETH_GSTRING_LEN;
1432 }
1433 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1434 snprintf(p, ETH_GSTRING_LEN,
1435 "port.rx_priority_%u_xon_2_xoff", i);
1436 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001437 }
1438 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1439 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001440 case ETH_SS_PRIV_FLAGS:
1441 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1442 memcpy(data, i40e_priv_flags_strings[i],
1443 ETH_GSTRING_LEN);
1444 data += ETH_GSTRING_LEN;
1445 }
1446 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001447 default:
1448 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001449 }
1450}
1451
1452static int i40e_get_ts_info(struct net_device *dev,
1453 struct ethtool_ts_info *info)
1454{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001455 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1456
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001457 /* only report HW timestamping if PTP is enabled */
1458 if (!(pf->flags & I40E_FLAG_PTP))
1459 return ethtool_op_get_ts_info(dev, info);
1460
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001461 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1462 SOF_TIMESTAMPING_RX_SOFTWARE |
1463 SOF_TIMESTAMPING_SOFTWARE |
1464 SOF_TIMESTAMPING_TX_HARDWARE |
1465 SOF_TIMESTAMPING_RX_HARDWARE |
1466 SOF_TIMESTAMPING_RAW_HARDWARE;
1467
1468 if (pf->ptp_clock)
1469 info->phc_index = ptp_clock_index(pf->ptp_clock);
1470 else
1471 info->phc_index = -1;
1472
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001473 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001474
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001475 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1476 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1477 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001478
1479 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480}
1481
Shannon Nelson7b086392013-11-20 10:02:59 +00001482static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483{
Shannon Nelson7b086392013-11-20 10:02:59 +00001484 struct i40e_netdev_priv *np = netdev_priv(netdev);
1485 struct i40e_pf *pf = np->vsi->back;
1486
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001487 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001488 if (i40e_get_link_status(&pf->hw))
1489 *data = 0;
1490 else
1491 *data = 1;
1492
1493 return *data;
1494}
1495
Shannon Nelson7b086392013-11-20 10:02:59 +00001496static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497{
Shannon Nelson7b086392013-11-20 10:02:59 +00001498 struct i40e_netdev_priv *np = netdev_priv(netdev);
1499 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001501 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001502 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001503
Shannon Nelson7b086392013-11-20 10:02:59 +00001504 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505}
1506
Shannon Nelson7b086392013-11-20 10:02:59 +00001507static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001508{
Shannon Nelson7b086392013-11-20 10:02:59 +00001509 struct i40e_netdev_priv *np = netdev_priv(netdev);
1510 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001511
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001512 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001513 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514
Shannon Nelson4443ec92014-11-13 08:23:12 +00001515 /* forcebly clear the NVM Update state machine */
1516 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1517
Shannon Nelson7b086392013-11-20 10:02:59 +00001518 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519}
1520
Shannon Nelson7b086392013-11-20 10:02:59 +00001521static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522{
Shannon Nelson7b086392013-11-20 10:02:59 +00001523 struct i40e_netdev_priv *np = netdev_priv(netdev);
1524 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001525 u16 swc_old = pf->sw_int_count;
1526
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001527 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001528 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1529 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001530 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1531 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1532 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1533 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001534 usleep_range(1000, 2000);
1535 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536
1537 return *data;
1538}
1539
Shannon Nelson7b086392013-11-20 10:02:59 +00001540static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001541{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001542 struct i40e_netdev_priv *np = netdev_priv(netdev);
1543 struct i40e_pf *pf = np->vsi->back;
1544
1545 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001546 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001547
1548 return *data;
1549}
1550
Greg Rosee17bc412015-04-16 20:05:59 -04001551static inline bool i40e_active_vfs(struct i40e_pf *pf)
1552{
1553 struct i40e_vf *vfs = pf->vf;
1554 int i;
1555
1556 for (i = 0; i < pf->num_alloc_vfs; i++)
1557 if (vfs[i].vf_states & I40E_VF_STAT_ACTIVE)
1558 return true;
1559 return false;
1560}
1561
Greg Rose510efb22015-07-10 19:36:01 -04001562static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1563{
1564 struct i40e_vsi **vsi = pf->vsi;
1565 int i;
1566
1567 for (i = 0; i < pf->num_alloc_vsi; i++) {
1568 if (!vsi[i])
1569 continue;
1570 if (vsi[i]->type == I40E_VSI_VMDQ2)
1571 return true;
1572 }
1573
1574 return false;
1575}
1576
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001577static void i40e_diag_test(struct net_device *netdev,
1578 struct ethtool_test *eth_test, u64 *data)
1579{
1580 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001581 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001582 struct i40e_pf *pf = np->vsi->back;
1583
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1585 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001586 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001587
Shannon Nelsonf551b432013-11-26 10:49:12 +00001588 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001589
Greg Rose510efb22015-07-10 19:36:01 -04001590 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001591 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001592 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001593 data[I40E_ETH_TEST_REG] = 1;
1594 data[I40E_ETH_TEST_EEPROM] = 1;
1595 data[I40E_ETH_TEST_INTR] = 1;
1596 data[I40E_ETH_TEST_LOOPBACK] = 1;
1597 data[I40E_ETH_TEST_LINK] = 1;
1598 eth_test->flags |= ETH_TEST_FL_FAILED;
1599 clear_bit(__I40E_TESTING, &pf->state);
1600 goto skip_ol_tests;
1601 }
1602
Greg Rose5b86c5c2015-02-26 16:14:35 +00001603 /* If the device is online then take it offline */
1604 if (if_running)
1605 /* indicate we're in test mode */
1606 dev_close(netdev);
1607 else
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001608 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001609
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001610 /* Link test performed before hardware reset
1611 * so autoneg doesn't interfere with test result
1612 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001613 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614 eth_test->flags |= ETH_TEST_FL_FAILED;
1615
Shannon Nelson7b086392013-11-20 10:02:59 +00001616 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001617 eth_test->flags |= ETH_TEST_FL_FAILED;
1618
Shannon Nelson7b086392013-11-20 10:02:59 +00001619 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001620 eth_test->flags |= ETH_TEST_FL_FAILED;
1621
Shannon Nelson7b086392013-11-20 10:02:59 +00001622 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001623 eth_test->flags |= ETH_TEST_FL_FAILED;
1624
Shannon Nelsonf551b432013-11-26 10:49:12 +00001625 /* run reg test last, a reset is required after it */
1626 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1627 eth_test->flags |= ETH_TEST_FL_FAILED;
1628
1629 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001630 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001631
1632 if (if_running)
1633 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001634 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001635 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001636 netif_info(pf, drv, netdev, "online testing starting\n");
1637
Shannon Nelson7b086392013-11-20 10:02:59 +00001638 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001639 eth_test->flags |= ETH_TEST_FL_FAILED;
1640
1641 /* Offline only tests, not run in online; pass by default */
1642 data[I40E_ETH_TEST_REG] = 0;
1643 data[I40E_ETH_TEST_EEPROM] = 0;
1644 data[I40E_ETH_TEST_INTR] = 0;
1645 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001646 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001647
Greg Rosee17bc412015-04-16 20:05:59 -04001648skip_ol_tests:
1649
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001650 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001651}
1652
1653static void i40e_get_wol(struct net_device *netdev,
1654 struct ethtool_wolinfo *wol)
1655{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001656 struct i40e_netdev_priv *np = netdev_priv(netdev);
1657 struct i40e_pf *pf = np->vsi->back;
1658 struct i40e_hw *hw = &pf->hw;
1659 u16 wol_nvm_bits;
1660
1661 /* NVM bit on means WoL disabled for the port */
1662 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001663 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001664 wol->supported = 0;
1665 wol->wolopts = 0;
1666 } else {
1667 wol->supported = WAKE_MAGIC;
1668 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1669 }
1670}
1671
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001672/**
1673 * i40e_set_wol - set the WakeOnLAN configuration
1674 * @netdev: the netdev in question
1675 * @wol: the ethtool WoL setting data
1676 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001677static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1678{
1679 struct i40e_netdev_priv *np = netdev_priv(netdev);
1680 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001681 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001682 struct i40e_hw *hw = &pf->hw;
1683 u16 wol_nvm_bits;
1684
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001685 /* WoL not supported if this isn't the controlling PF on the port */
1686 if (hw->partition_id != 1) {
1687 i40e_partition_setting_complaint(pf);
1688 return -EOPNOTSUPP;
1689 }
1690
1691 if (vsi != pf->vsi[pf->lan_vsi])
1692 return -EOPNOTSUPP;
1693
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001694 /* NVM bit on means WoL disabled for the port */
1695 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001696 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001697 return -EOPNOTSUPP;
1698
1699 /* only magic packet is supported */
1700 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1701 return -EOPNOTSUPP;
1702
1703 /* is this a new value? */
1704 if (pf->wol_en != !!wol->wolopts) {
1705 pf->wol_en = !!wol->wolopts;
1706 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1707 }
1708
1709 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001710}
1711
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001712static int i40e_set_phys_id(struct net_device *netdev,
1713 enum ethtool_phys_id_state state)
1714{
1715 struct i40e_netdev_priv *np = netdev_priv(netdev);
1716 struct i40e_pf *pf = np->vsi->back;
1717 struct i40e_hw *hw = &pf->hw;
1718 int blink_freq = 2;
1719
1720 switch (state) {
1721 case ETHTOOL_ID_ACTIVE:
1722 pf->led_status = i40e_led_get(hw);
1723 return blink_freq;
1724 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001725 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001726 break;
1727 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001728 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001729 break;
1730 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001731 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001732 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001733 default:
1734 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001735 }
1736
1737 return 0;
1738}
1739
1740/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1741 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1742 * 125us (8000 interrupts per second) == ITR(62)
1743 */
1744
1745static int i40e_get_coalesce(struct net_device *netdev,
1746 struct ethtool_coalesce *ec)
1747{
1748 struct i40e_netdev_priv *np = netdev_priv(netdev);
1749 struct i40e_vsi *vsi = np->vsi;
1750
1751 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1752 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1753
1754 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001755 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001756
1757 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001758 ec->use_adaptive_tx_coalesce = 1;
1759
1760 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1761 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001762
1763 return 0;
1764}
1765
1766static int i40e_set_coalesce(struct net_device *netdev,
1767 struct ethtool_coalesce *ec)
1768{
1769 struct i40e_netdev_priv *np = netdev_priv(netdev);
1770 struct i40e_q_vector *q_vector;
1771 struct i40e_vsi *vsi = np->vsi;
1772 struct i40e_pf *pf = vsi->back;
1773 struct i40e_hw *hw = &pf->hw;
1774 u16 vector;
1775 int i;
1776
1777 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1778 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1779
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001780 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001781 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001782 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001783 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001784 } else if (ec->rx_coalesce_usecs == 0) {
1785 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001786 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001787 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 +00001788 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001789 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001790 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001791 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001792
Mitch Williams32f5f542014-04-04 04:43:10 +00001793 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001794 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001795 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001796 } else if (ec->tx_coalesce_usecs == 0) {
1797 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001798 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001799 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 +00001800 } else {
1801 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001802 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001803 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001804 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001805
1806 if (ec->use_adaptive_rx_coalesce)
1807 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1808 else
1809 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1810
1811 if (ec->use_adaptive_tx_coalesce)
1812 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1813 else
1814 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001815
Alexander Duyck493fb302013-09-28 07:01:44 +00001816 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1817 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1819 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1820 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1821 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1822 i40e_flush(hw);
1823 }
1824
1825 return 0;
1826}
1827
1828/**
1829 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1830 * @pf: pointer to the physical function struct
1831 * @cmd: ethtool rxnfc command
1832 *
1833 * Returns Success if the flow is supported, else Invalid Input.
1834 **/
1835static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1836{
1837 cmd->data = 0;
1838
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001839 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1840 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1841 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1842 return 0;
1843 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001844 /* Report default options for RSS on i40e */
1845 switch (cmd->flow_type) {
1846 case TCP_V4_FLOW:
1847 case UDP_V4_FLOW:
1848 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1849 /* fall through to add IP fields */
1850 case SCTP_V4_FLOW:
1851 case AH_ESP_V4_FLOW:
1852 case AH_V4_FLOW:
1853 case ESP_V4_FLOW:
1854 case IPV4_FLOW:
1855 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1856 break;
1857 case TCP_V6_FLOW:
1858 case UDP_V6_FLOW:
1859 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1860 /* fall through to add IP fields */
1861 case SCTP_V6_FLOW:
1862 case AH_ESP_V6_FLOW:
1863 case AH_V6_FLOW:
1864 case ESP_V6_FLOW:
1865 case IPV6_FLOW:
1866 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1867 break;
1868 default:
1869 return -EINVAL;
1870 }
1871
1872 return 0;
1873}
1874
1875/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001876 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1877 * @pf: Pointer to the physical function struct
1878 * @cmd: The command to get or set Rx flow classification rules
1879 * @rule_locs: Array of used rule locations
1880 *
1881 * This function populates both the total and actual rule count of
1882 * the ethtool flow classification command
1883 *
1884 * Returns 0 on success or -EMSGSIZE if entry not found
1885 **/
1886static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1887 struct ethtool_rxnfc *cmd,
1888 u32 *rule_locs)
1889{
1890 struct i40e_fdir_filter *rule;
1891 struct hlist_node *node2;
1892 int cnt = 0;
1893
1894 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001895 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001896
1897 hlist_for_each_entry_safe(rule, node2,
1898 &pf->fdir_filter_list, fdir_node) {
1899 if (cnt == cmd->rule_cnt)
1900 return -EMSGSIZE;
1901
1902 rule_locs[cnt] = rule->fd_id;
1903 cnt++;
1904 }
1905
1906 cmd->rule_cnt = cnt;
1907
1908 return 0;
1909}
1910
1911/**
1912 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1913 * @pf: Pointer to the physical function struct
1914 * @cmd: The command to get or set Rx flow classification rules
1915 *
1916 * This function looks up a filter based on the Rx flow classification
1917 * command and fills the flow spec info for it if found
1918 *
1919 * Returns 0 on success or -EINVAL if filter not found
1920 **/
1921static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1922 struct ethtool_rxnfc *cmd)
1923{
1924 struct ethtool_rx_flow_spec *fsp =
1925 (struct ethtool_rx_flow_spec *)&cmd->fs;
1926 struct i40e_fdir_filter *rule = NULL;
1927 struct hlist_node *node2;
1928
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001929 hlist_for_each_entry_safe(rule, node2,
1930 &pf->fdir_filter_list, fdir_node) {
1931 if (fsp->location <= rule->fd_id)
1932 break;
1933 }
1934
1935 if (!rule || fsp->location != rule->fd_id)
1936 return -EINVAL;
1937
1938 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001939 if (fsp->flow_type == IP_USER_FLOW) {
1940 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1941 fsp->h_u.usr_ip4_spec.proto = 0;
1942 fsp->m_u.usr_ip4_spec.proto = 0;
1943 }
1944
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001945 /* Reverse the src and dest notion, since the HW views them from
1946 * Tx perspective where as the user expects it from Rx filter view.
1947 */
1948 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1949 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1950 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1951 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001952
1953 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1954 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1955 else
1956 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001957
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04001958 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
1959 struct i40e_vsi *vsi;
1960
1961 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
1962 if (vsi && vsi->type == I40E_VSI_SRIOV) {
1963 fsp->h_ext.data[1] = htonl(vsi->vf_id);
1964 fsp->m_ext.data[1] = htonl(0x1);
1965 }
1966 }
1967
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001968 return 0;
1969}
1970
1971/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001972 * i40e_get_rxnfc - command to get RX flow classification rules
1973 * @netdev: network interface device structure
1974 * @cmd: ethtool rxnfc command
1975 *
1976 * Returns Success if the command is supported.
1977 **/
1978static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1979 u32 *rule_locs)
1980{
1981 struct i40e_netdev_priv *np = netdev_priv(netdev);
1982 struct i40e_vsi *vsi = np->vsi;
1983 struct i40e_pf *pf = vsi->back;
1984 int ret = -EOPNOTSUPP;
1985
1986 switch (cmd->cmd) {
1987 case ETHTOOL_GRXRINGS:
1988 cmd->data = vsi->alloc_queue_pairs;
1989 ret = 0;
1990 break;
1991 case ETHTOOL_GRXFH:
1992 ret = i40e_get_rss_hash_opts(pf, cmd);
1993 break;
1994 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001995 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001996 /* report total rule count */
1997 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998 ret = 0;
1999 break;
2000 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002001 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002002 break;
2003 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002004 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2005 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002006 default:
2007 break;
2008 }
2009
2010 return ret;
2011}
2012
2013/**
2014 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2015 * @pf: pointer to the physical function struct
2016 * @cmd: ethtool rxnfc command
2017 *
2018 * Returns Success if the flow input set is supported.
2019 **/
2020static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2021{
2022 struct i40e_hw *hw = &pf->hw;
2023 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2024 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2025
2026 /* RSS does not support anything other than hashing
2027 * to queues on src and dst IPs and ports
2028 */
2029 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2030 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2031 return -EINVAL;
2032
2033 /* We need at least the IP SRC and DEST fields for hashing */
2034 if (!(nfc->data & RXH_IP_SRC) ||
2035 !(nfc->data & RXH_IP_DST))
2036 return -EINVAL;
2037
2038 switch (nfc->flow_type) {
2039 case TCP_V4_FLOW:
2040 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2041 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002042 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002043 break;
2044 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002045 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002046 break;
2047 default:
2048 return -EINVAL;
2049 }
2050 break;
2051 case TCP_V6_FLOW:
2052 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2053 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002054 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002055 break;
2056 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002057 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002058 break;
2059 default:
2060 return -EINVAL;
2061 }
2062 break;
2063 case UDP_V4_FLOW:
2064 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2065 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002066 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2067 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002068 break;
2069 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002070 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2071 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002072 break;
2073 default:
2074 return -EINVAL;
2075 }
2076 break;
2077 case UDP_V6_FLOW:
2078 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2079 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002080 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2081 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002082 break;
2083 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002084 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2085 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002086 break;
2087 default:
2088 return -EINVAL;
2089 }
2090 break;
2091 case AH_ESP_V4_FLOW:
2092 case AH_V4_FLOW:
2093 case ESP_V4_FLOW:
2094 case SCTP_V4_FLOW:
2095 if ((nfc->data & RXH_L4_B_0_1) ||
2096 (nfc->data & RXH_L4_B_2_3))
2097 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002098 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002099 break;
2100 case AH_ESP_V6_FLOW:
2101 case AH_V6_FLOW:
2102 case ESP_V6_FLOW:
2103 case SCTP_V6_FLOW:
2104 if ((nfc->data & RXH_L4_B_0_1) ||
2105 (nfc->data & RXH_L4_B_2_3))
2106 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002107 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002108 break;
2109 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002110 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2111 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002112 break;
2113 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002114 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2115 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002116 break;
2117 default:
2118 return -EINVAL;
2119 }
2120
2121 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2122 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2123 i40e_flush(hw);
2124
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002125 /* Save setting for future output/update */
2126 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2127
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002128 return 0;
2129}
2130
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002131/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002132 * i40e_match_fdir_input_set - Match a new filter against an existing one
2133 * @rule: The filter already added
2134 * @input: The new filter to comapre against
2135 *
2136 * Returns true if the two input set match
2137 **/
2138static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2139 struct i40e_fdir_filter *input)
2140{
2141 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2142 (rule->src_ip[0] != input->src_ip[0]) ||
2143 (rule->dst_port != input->dst_port) ||
2144 (rule->src_port != input->src_port))
2145 return false;
2146 return true;
2147}
2148
2149/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002150 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2151 * @vsi: Pointer to the targeted VSI
2152 * @input: The filter to update or NULL to indicate deletion
2153 * @sw_idx: Software index to the filter
2154 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002156 * This function updates (or deletes) a Flow Director entry from
2157 * the hlist of the corresponding PF
2158 *
2159 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002160 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002161static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2162 struct i40e_fdir_filter *input,
2163 u16 sw_idx,
2164 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002165{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002166 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002167 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002168 struct hlist_node *node2;
2169 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002170
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002171 parent = NULL;
2172 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002173
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002174 hlist_for_each_entry_safe(rule, node2,
2175 &pf->fdir_filter_list, fdir_node) {
2176 /* hash found, or no matching entry */
2177 if (rule->fd_id >= sw_idx)
2178 break;
2179 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002180 }
2181
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002182 /* if there is an old rule occupying our place remove it */
2183 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002184 if (input && !i40e_match_fdir_input_set(rule, input))
2185 err = i40e_add_del_fdir(vsi, rule, false);
2186 else if (!input)
2187 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002188 hlist_del(&rule->fdir_node);
2189 kfree(rule);
2190 pf->fdir_pf_active_filters--;
2191 }
2192
2193 /* If no input this was a delete, err should be 0 if a rule was
2194 * successfully found and removed from the list else -EINVAL
2195 */
2196 if (!input)
2197 return err;
2198
2199 /* initialize node and set software index */
2200 INIT_HLIST_NODE(&input->fdir_node);
2201
2202 /* add filter to the list */
2203 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002204 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002205 else
2206 hlist_add_head(&input->fdir_node,
2207 &pf->fdir_filter_list);
2208
2209 /* update counts */
2210 pf->fdir_pf_active_filters++;
2211
2212 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002213}
2214
2215/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002216 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2217 * @vsi: Pointer to the targeted VSI
2218 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002219 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002220 * The function removes a Flow Director filter entry from the
2221 * hlist of the corresponding PF
2222 *
2223 * Returns 0 on success
2224 */
2225static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2226 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002227{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002228 struct ethtool_rx_flow_spec *fsp =
2229 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002230 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002231 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002232
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002233 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2234 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2235 return -EBUSY;
2236
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002237 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2238 return -EBUSY;
2239
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002240 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002241
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002242 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002243 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002244}
2245
2246/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002247 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002248 * @vsi: pointer to the targeted VSI
2249 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002250 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002251 * Add Flow Director filters for a specific flow spec based on their
2252 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002253 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002254static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2255 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002256{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002257 struct ethtool_rx_flow_spec *fsp;
2258 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002259 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002260 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002261 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002262
2263 if (!vsi)
2264 return -EINVAL;
2265
2266 pf = vsi->back;
2267
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002268 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2269 return -EOPNOTSUPP;
2270
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002271 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002272 return -ENOSPC;
2273
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002274 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2275 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2276 return -EBUSY;
2277
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002278 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2279 return -EBUSY;
2280
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002281 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2282
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002283 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2284 pf->hw.func_caps.fd_filters_guaranteed)) {
2285 return -EINVAL;
2286 }
2287
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002288 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2289 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002290 return -EINVAL;
2291
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002292 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002293
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002294 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002295 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002296
2297 input->fd_id = fsp->location;
2298
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002299 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2300 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2301 else
2302 input->dest_ctl =
2303 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2304
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002305 input->q_index = fsp->ring_cookie;
2306 input->flex_off = 0;
2307 input->pctype = 0;
2308 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002309 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002310 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002311 input->flow_type = fsp->flow_type;
2312 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002313
2314 /* Reverse the src and dest notion, since the HW expects them to be from
2315 * Tx perspective where as the input from user is from Rx filter view.
2316 */
2317 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2318 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2319 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2320 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002321
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002322 if (ntohl(fsp->m_ext.data[1])) {
2323 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2324 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2325 goto free_input;
2326 }
2327 vf_id = ntohl(fsp->h_ext.data[1]);
2328 /* Find vsi id from vf id and override dest vsi */
2329 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2330 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2331 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2332 goto free_input;
2333 }
2334 }
2335
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002336 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002337free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002338 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002339 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002340 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002341 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002342
2343 return ret;
2344}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002345
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002346/**
2347 * i40e_set_rxnfc - command to set RX flow classification rules
2348 * @netdev: network interface device structure
2349 * @cmd: ethtool rxnfc command
2350 *
2351 * Returns Success if the command is supported.
2352 **/
2353static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2354{
2355 struct i40e_netdev_priv *np = netdev_priv(netdev);
2356 struct i40e_vsi *vsi = np->vsi;
2357 struct i40e_pf *pf = vsi->back;
2358 int ret = -EOPNOTSUPP;
2359
2360 switch (cmd->cmd) {
2361 case ETHTOOL_SRXFH:
2362 ret = i40e_set_rss_hash_opt(pf, cmd);
2363 break;
2364 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002365 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002366 break;
2367 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002368 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002369 break;
2370 default:
2371 break;
2372 }
2373
2374 return ret;
2375}
2376
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002377/**
2378 * i40e_max_channels - get Max number of combined channels supported
2379 * @vsi: vsi pointer
2380 **/
2381static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2382{
2383 /* TODO: This code assumes DCB and FD is disabled for now. */
2384 return vsi->alloc_queue_pairs;
2385}
2386
2387/**
2388 * i40e_get_channels - Get the current channels enabled and max supported etc.
2389 * @netdev: network interface device structure
2390 * @ch: ethtool channels structure
2391 *
2392 * We don't support separate tx and rx queues as channels. The other count
2393 * represents how many queues are being used for control. max_combined counts
2394 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2395 * q_vectors since we support a lot more queue pairs than q_vectors.
2396 **/
2397static void i40e_get_channels(struct net_device *dev,
2398 struct ethtool_channels *ch)
2399{
2400 struct i40e_netdev_priv *np = netdev_priv(dev);
2401 struct i40e_vsi *vsi = np->vsi;
2402 struct i40e_pf *pf = vsi->back;
2403
2404 /* report maximum channels */
2405 ch->max_combined = i40e_max_channels(vsi);
2406
2407 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002408 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002409 ch->max_other = ch->other_count;
2410
2411 /* Note: This code assumes DCB is disabled for now. */
2412 ch->combined_count = vsi->num_queue_pairs;
2413}
2414
2415/**
2416 * i40e_set_channels - Set the new channels count.
2417 * @netdev: network interface device structure
2418 * @ch: ethtool channels structure
2419 *
2420 * The new channels count may not be the same as requested by the user
2421 * since it gets rounded down to a power of 2 value.
2422 **/
2423static int i40e_set_channels(struct net_device *dev,
2424 struct ethtool_channels *ch)
2425{
2426 struct i40e_netdev_priv *np = netdev_priv(dev);
2427 unsigned int count = ch->combined_count;
2428 struct i40e_vsi *vsi = np->vsi;
2429 struct i40e_pf *pf = vsi->back;
2430 int new_count;
2431
2432 /* We do not support setting channels for any other VSI at present */
2433 if (vsi->type != I40E_VSI_MAIN)
2434 return -EINVAL;
2435
2436 /* verify they are not requesting separate vectors */
2437 if (!count || ch->rx_count || ch->tx_count)
2438 return -EINVAL;
2439
2440 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002441 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002442 return -EINVAL;
2443
2444 /* verify the number of channels does not exceed hardware limits */
2445 if (count > i40e_max_channels(vsi))
2446 return -EINVAL;
2447
2448 /* update feature limits from largest to smallest supported values */
2449 /* TODO: Flow director limit, DCB etc */
2450
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002451 /* use rss_reconfig to rebuild with new queue count and update traffic
2452 * class queue mapping
2453 */
2454 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002455 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002456 return 0;
2457 else
2458 return -EINVAL;
2459}
2460
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002461#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2462/**
2463 * i40e_get_rxfh_key_size - get the RSS hash key size
2464 * @netdev: network interface device structure
2465 *
2466 * Returns the table size.
2467 **/
2468static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2469{
2470 return I40E_HKEY_ARRAY_SIZE;
2471}
2472
2473/**
2474 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2475 * @netdev: network interface device structure
2476 *
2477 * Returns the table size.
2478 **/
2479static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2480{
2481 return I40E_HLUT_ARRAY_SIZE;
2482}
2483
2484static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2485 u8 *hfunc)
2486{
2487 struct i40e_netdev_priv *np = netdev_priv(netdev);
2488 struct i40e_vsi *vsi = np->vsi;
2489 struct i40e_pf *pf = vsi->back;
2490 struct i40e_hw *hw = &pf->hw;
2491 u32 reg_val;
2492 int i, j;
2493
2494 if (hfunc)
2495 *hfunc = ETH_RSS_HASH_TOP;
2496
2497 if (!indir)
2498 return 0;
2499
2500 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2501 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2502 indir[j++] = reg_val & 0xff;
2503 indir[j++] = (reg_val >> 8) & 0xff;
2504 indir[j++] = (reg_val >> 16) & 0xff;
2505 indir[j++] = (reg_val >> 24) & 0xff;
2506 }
2507
2508 if (key) {
2509 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2510 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2511 key[j++] = (u8)(reg_val & 0xff);
2512 key[j++] = (u8)((reg_val >> 8) & 0xff);
2513 key[j++] = (u8)((reg_val >> 16) & 0xff);
2514 key[j++] = (u8)((reg_val >> 24) & 0xff);
2515 }
2516 }
2517 return 0;
2518}
2519
2520/**
2521 * i40e_set_rxfh - set the rx flow hash indirection table
2522 * @netdev: network interface device structure
2523 * @indir: indirection table
2524 * @key: hash key
2525 *
2526 * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
2527 * returns 0 after programming the table.
2528 **/
2529static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2530 const u8 *key, const u8 hfunc)
2531{
2532 struct i40e_netdev_priv *np = netdev_priv(netdev);
2533 struct i40e_vsi *vsi = np->vsi;
2534 struct i40e_pf *pf = vsi->back;
2535 struct i40e_hw *hw = &pf->hw;
2536 u32 reg_val;
2537 int i, j;
2538
2539 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2540 return -EOPNOTSUPP;
2541
2542 if (!indir)
2543 return 0;
2544
2545 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2546 reg_val = indir[j++];
2547 reg_val |= indir[j++] << 8;
2548 reg_val |= indir[j++] << 16;
2549 reg_val |= indir[j++] << 24;
2550 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2551 }
2552
2553 if (key) {
2554 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2555 reg_val = key[j++];
2556 reg_val |= key[j++] << 8;
2557 reg_val |= key[j++] << 16;
2558 reg_val |= key[j++] << 24;
2559 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2560 }
2561 }
2562 return 0;
2563}
2564
Greg Rose7e45ab42015-02-06 08:52:19 +00002565/**
2566 * i40e_get_priv_flags - report device private flags
2567 * @dev: network interface device structure
2568 *
2569 * The get string set count and the string set should be matched for each
2570 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2571 * array.
2572 *
2573 * Returns a u32 bitmap of flags.
2574 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002575static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002576{
2577 struct i40e_netdev_priv *np = netdev_priv(dev);
2578 struct i40e_vsi *vsi = np->vsi;
2579 struct i40e_pf *pf = vsi->back;
2580 u32 ret_flags = 0;
2581
2582 ret_flags |= pf->hw.func_caps.npar_enable ?
2583 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2584
2585 return ret_flags;
2586}
2587
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002588static const struct ethtool_ops i40e_ethtool_ops = {
2589 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002590 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002591 .get_drvinfo = i40e_get_drvinfo,
2592 .get_regs_len = i40e_get_regs_len,
2593 .get_regs = i40e_get_regs,
2594 .nway_reset = i40e_nway_reset,
2595 .get_link = ethtool_op_get_link,
2596 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002597 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002598 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002599 .get_eeprom_len = i40e_get_eeprom_len,
2600 .get_eeprom = i40e_get_eeprom,
2601 .get_ringparam = i40e_get_ringparam,
2602 .set_ringparam = i40e_set_ringparam,
2603 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002604 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002605 .get_msglevel = i40e_get_msglevel,
2606 .set_msglevel = i40e_set_msglevel,
2607 .get_rxnfc = i40e_get_rxnfc,
2608 .set_rxnfc = i40e_set_rxnfc,
2609 .self_test = i40e_diag_test,
2610 .get_strings = i40e_get_strings,
2611 .set_phys_id = i40e_set_phys_id,
2612 .get_sset_count = i40e_get_sset_count,
2613 .get_ethtool_stats = i40e_get_ethtool_stats,
2614 .get_coalesce = i40e_get_coalesce,
2615 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002616 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2617 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2618 .get_rxfh = i40e_get_rxfh,
2619 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002620 .get_channels = i40e_get_channels,
2621 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002622 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002623 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002624};
2625
2626void i40e_set_ethtool_ops(struct net_device *netdev)
2627{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002628 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002629}