blob: 7413b0e429c82b500c5a0dd2464c6e464949efbc [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Shannon Nelson41a9e552014-04-23 04:50:20 +000090};
91
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000092static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
93 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000094
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000095/* These PF_STATs might look like duplicates of some NETDEV_STATs,
96 * but they are separate. This device supports Virtualization, and
97 * as such might have several netdevs supporting VMDq and FCoE going
98 * through a single port. The NETDEV_STATs are for individual netdevs
99 * seen at the top of the stack, and the PF_STATs are for the physical
100 * function at the bottom of the stack hosting those netdevs.
101 *
102 * The PF_STATs are appended to the netdev stats only when ethtool -S
103 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
104 */
105static struct i40e_stats i40e_gstrings_stats[] = {
106 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
107 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000108 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
109 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
110 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
111 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
112 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
113 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000114 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
115 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
117 I40E_PF_STAT("crc_errors", stats.crc_errors),
118 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
119 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
120 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000121 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000122 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000123 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
124 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
125 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
126 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
127 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
128 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
129 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
130 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
131 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
132 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
133 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
134 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
135 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
136 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
137 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
138 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
139 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
140 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
141 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
142 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
143 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
144 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
145 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
146 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
151
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000152 /* LPI stats */
153 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
154 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
155 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
156 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000157};
158
Vasu Dev38e00432014-08-01 13:27:03 -0700159#ifdef I40E_FCOE
160static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
161 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
162 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
163 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
164 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
165 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
166 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
167 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
168 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
169};
170
171#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000173 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
174 * 2 /* Tx and Rx together */ \
175 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
177#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000178#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700179#ifdef I40E_FCOE
180#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
181#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
182 I40E_FCOE_STATS_LEN + \
183 I40E_MISC_STATS_LEN + \
184 I40E_QUEUE_STATS_LEN((n)))
185#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000186#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000187 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700189#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PFC_STATS_LEN ( \
191 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
192 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
196 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000197#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
199 I40E_PFC_STATS_LEN + \
200 I40E_VSI_STATS_LEN((n)))
201
202enum i40e_ethtool_test_id {
203 I40E_ETH_TEST_REG = 0,
204 I40E_ETH_TEST_EEPROM,
205 I40E_ETH_TEST_INTR,
206 I40E_ETH_TEST_LOOPBACK,
207 I40E_ETH_TEST_LINK,
208};
209
210static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
211 "Register test (offline)",
212 "Eeprom test (offline)",
213 "Interrupt test (offline)",
214 "Loopback test (offline)",
215 "Link test (on/offline)"
216};
217
218#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
219
Greg Rose7e45ab42015-02-06 08:52:19 +0000220static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
221 "NPAR",
222};
223
224#define I40E_PRIV_FLAGS_STR_LEN \
225 (sizeof(i40e_priv_flags_strings) / ETH_GSTRING_LEN)
226
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000227/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000228 * i40e_partition_setting_complaint - generic complaint for MFP restriction
229 * @pf: the PF struct
230 **/
231static void i40e_partition_setting_complaint(struct i40e_pf *pf)
232{
233 dev_info(&pf->pdev->dev,
234 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
235}
236
237/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000238 * i40e_get_settings_link_up - Get the Link settings for when link is up
239 * @hw: hw structure
240 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000241 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000243 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000244static void i40e_get_settings_link_up(struct i40e_hw *hw,
245 struct ethtool_cmd *ecmd,
246 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000247{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000248 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000249 u32 link_speed = hw_link_info->link_speed;
250
Catherine Sullivane8278452015-02-06 08:52:08 +0000251 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 switch (hw_link_info->phy_type) {
253 case I40E_PHY_TYPE_40GBASE_CR4:
254 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000255 ecmd->supported = SUPPORTED_Autoneg |
256 SUPPORTED_40000baseCR4_Full;
257 ecmd->advertising = ADVERTISED_Autoneg |
258 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000260 case I40E_PHY_TYPE_XLAUI:
261 case I40E_PHY_TYPE_XLPPI:
262 ecmd->supported = SUPPORTED_40000baseCR4_Full;
263 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000264 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000265 ecmd->supported = SUPPORTED_Autoneg |
266 SUPPORTED_40000baseKR4_Full;
267 ecmd->advertising = ADVERTISED_Autoneg |
268 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000269 break;
270 case I40E_PHY_TYPE_40GBASE_SR4:
271 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000272 break;
273 case I40E_PHY_TYPE_40GBASE_LR4:
274 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000275 break;
276 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000277 ecmd->supported = SUPPORTED_Autoneg |
278 SUPPORTED_10000baseKX4_Full;
279 ecmd->advertising = ADVERTISED_Autoneg |
280 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000281 break;
282 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000283 ecmd->supported = SUPPORTED_Autoneg |
284 SUPPORTED_10000baseKR_Full;
285 ecmd->advertising = ADVERTISED_Autoneg |
286 ADVERTISED_10000baseKR_Full;
287 break;
288 case I40E_PHY_TYPE_10GBASE_SR:
289 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000290 case I40E_PHY_TYPE_1000BASE_SX:
291 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000292 ecmd->supported = SUPPORTED_10000baseT_Full |
293 SUPPORTED_1000baseT_Full;
294 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
295 ecmd->advertising |= ADVERTISED_10000baseT_Full;
296 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
297 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000298 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000299 case I40E_PHY_TYPE_1000BASE_KX:
300 ecmd->supported = SUPPORTED_Autoneg |
301 SUPPORTED_1000baseKX_Full;
302 ecmd->advertising = ADVERTISED_Autoneg |
303 ADVERTISED_1000baseKX_Full;
304 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000305 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000306 case I40E_PHY_TYPE_1000BASE_T:
307 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000308 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000309 SUPPORTED_10000baseT_Full |
310 SUPPORTED_1000baseT_Full |
311 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000312 ecmd->advertising = ADVERTISED_Autoneg;
313 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
314 ecmd->advertising |= ADVERTISED_10000baseT_Full;
315 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
316 ecmd->advertising |= ADVERTISED_1000baseT_Full;
317 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
318 ecmd->advertising |= ADVERTISED_100baseT_Full;
319 break;
320 case I40E_PHY_TYPE_10GBASE_CR1_CU:
321 case I40E_PHY_TYPE_10GBASE_CR1:
322 ecmd->supported = SUPPORTED_Autoneg |
323 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000324 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000325 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000326 break;
327 case I40E_PHY_TYPE_XAUI:
328 case I40E_PHY_TYPE_XFI:
329 case I40E_PHY_TYPE_SFI:
330 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
331 ecmd->supported = SUPPORTED_10000baseT_Full;
332 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000333 case I40E_PHY_TYPE_SGMII:
334 ecmd->supported = SUPPORTED_Autoneg |
335 SUPPORTED_1000baseT_Full |
336 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000337 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
338 ecmd->advertising |= ADVERTISED_1000baseT_Full;
339 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
340 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000341 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000342 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000343 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000344 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
345 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000346 }
347
Catherine Sullivane8278452015-02-06 08:52:08 +0000348 /* Set speed and duplex */
349 switch (link_speed) {
350 case I40E_LINK_SPEED_40GB:
351 /* need a SPEED_40000 in ethtool.h */
352 ethtool_cmd_speed_set(ecmd, 40000);
353 break;
354 case I40E_LINK_SPEED_10GB:
355 ethtool_cmd_speed_set(ecmd, SPEED_10000);
356 break;
357 case I40E_LINK_SPEED_1GB:
358 ethtool_cmd_speed_set(ecmd, SPEED_1000);
359 break;
360 case I40E_LINK_SPEED_100MB:
361 ethtool_cmd_speed_set(ecmd, SPEED_100);
362 break;
363 default:
364 break;
365 }
366 ecmd->duplex = DUPLEX_FULL;
367}
368
369/**
370 * i40e_get_settings_link_down - Get the Link settings for when link is down
371 * @hw: hw structure
372 * @ecmd: ethtool command to fill in
373 *
374 * Reports link settings that can be determined when link is down
375 **/
376static void i40e_get_settings_link_down(struct i40e_hw *hw,
377 struct ethtool_cmd *ecmd)
378{
379 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
380
381 /* link is down and the driver needs to fall back on
382 * device ID to determine what kinds of info to display,
383 * it's mostly a guess that may change when link is up
384 */
385 switch (hw->device_id) {
386 case I40E_DEV_ID_QSFP_A:
387 case I40E_DEV_ID_QSFP_B:
388 case I40E_DEV_ID_QSFP_C:
389 /* pluggable QSFP */
390 ecmd->supported = SUPPORTED_40000baseSR4_Full |
391 SUPPORTED_40000baseCR4_Full |
392 SUPPORTED_40000baseLR4_Full;
393 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
394 ADVERTISED_40000baseCR4_Full |
395 ADVERTISED_40000baseLR4_Full;
396 break;
397 case I40E_DEV_ID_KX_B:
398 /* backplane 40G */
399 ecmd->supported = SUPPORTED_40000baseKR4_Full;
400 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
401 break;
402 case I40E_DEV_ID_KX_C:
403 /* backplane 10G */
404 ecmd->supported = SUPPORTED_10000baseKR_Full;
405 ecmd->advertising = ADVERTISED_10000baseKR_Full;
406 break;
407 case I40E_DEV_ID_10G_BASE_T:
408 ecmd->supported = SUPPORTED_10000baseT_Full |
409 SUPPORTED_1000baseT_Full |
410 SUPPORTED_100baseT_Full;
411 /* Figure out what has been requested */
412 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
413 ecmd->advertising |= ADVERTISED_10000baseT_Full;
414 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
415 ecmd->advertising |= ADVERTISED_1000baseT_Full;
416 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
417 ecmd->advertising |= ADVERTISED_100baseT_Full;
418 break;
419 default:
420 /* all the rest are 10G/1G */
421 ecmd->supported = SUPPORTED_10000baseT_Full |
422 SUPPORTED_1000baseT_Full;
423 /* Figure out what has been requested */
424 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
425 ecmd->advertising |= ADVERTISED_10000baseT_Full;
426 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
427 ecmd->advertising |= ADVERTISED_1000baseT_Full;
428 break;
429 }
430
431 /* With no link speed and duplex are unknown */
432 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
433 ecmd->duplex = DUPLEX_UNKNOWN;
434}
435
436/**
437 * i40e_get_settings - Get Link Speed and Duplex settings
438 * @netdev: network interface device structure
439 * @ecmd: ethtool command
440 *
441 * Reports speed/duplex settings based on media_type
442 **/
443static int i40e_get_settings(struct net_device *netdev,
444 struct ethtool_cmd *ecmd)
445{
446 struct i40e_netdev_priv *np = netdev_priv(netdev);
447 struct i40e_pf *pf = np->vsi->back;
448 struct i40e_hw *hw = &pf->hw;
449 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
450 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
451
452 if (link_up)
453 i40e_get_settings_link_up(hw, ecmd, netdev);
454 else
455 i40e_get_settings_link_down(hw, ecmd);
456
457 /* Now set the settings that don't rely on link being up/down */
458
459 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000460 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
461 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000462
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000463 switch (hw->phy.media_type) {
464 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000465 ecmd->supported |= SUPPORTED_Autoneg |
466 SUPPORTED_Backplane;
467 ecmd->advertising |= ADVERTISED_Autoneg |
468 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000469 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000470 break;
471 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000472 ecmd->supported |= SUPPORTED_TP;
473 ecmd->advertising |= ADVERTISED_TP;
474 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000475 break;
476 case I40E_MEDIA_TYPE_DA:
477 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000478 ecmd->supported |= SUPPORTED_FIBRE;
479 ecmd->advertising |= ADVERTISED_FIBRE;
480 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000481 break;
482 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000484 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000485 break;
486 case I40E_MEDIA_TYPE_UNKNOWN:
487 default:
488 ecmd->port = PORT_OTHER;
489 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000490 }
491
Catherine Sullivane8278452015-02-06 08:52:08 +0000492 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000493 ecmd->transceiver = XCVR_EXTERNAL;
494
Catherine Sullivane8278452015-02-06 08:52:08 +0000495 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000496 ecmd->supported |= SUPPORTED_Pause;
497
Catherine Sullivane8278452015-02-06 08:52:08 +0000498 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000499 case I40E_FC_FULL:
500 ecmd->advertising |= ADVERTISED_Pause;
501 break;
502 case I40E_FC_TX_PAUSE:
503 ecmd->advertising |= ADVERTISED_Asym_Pause;
504 break;
505 case I40E_FC_RX_PAUSE:
506 ecmd->advertising |= (ADVERTISED_Pause |
507 ADVERTISED_Asym_Pause);
508 break;
509 default:
510 ecmd->advertising &= ~(ADVERTISED_Pause |
511 ADVERTISED_Asym_Pause);
512 break;
513 }
514
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000515 return 0;
516}
517
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000518/**
519 * i40e_set_settings - Set Speed and Duplex
520 * @netdev: network interface device structure
521 * @ecmd: ethtool command
522 *
523 * Set speed/duplex per media_types advertised/forced
524 **/
525static int i40e_set_settings(struct net_device *netdev,
526 struct ethtool_cmd *ecmd)
527{
528 struct i40e_netdev_priv *np = netdev_priv(netdev);
529 struct i40e_aq_get_phy_abilities_resp abilities;
530 struct i40e_aq_set_phy_config config;
531 struct i40e_pf *pf = np->vsi->back;
532 struct i40e_vsi *vsi = np->vsi;
533 struct i40e_hw *hw = &pf->hw;
534 struct ethtool_cmd safe_ecmd;
535 i40e_status status = 0;
536 bool change = false;
537 int err = 0;
538 u8 autoneg;
539 u32 advertise;
540
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000541 /* Changing port settings is not supported if this isn't the
542 * port's controlling PF
543 */
544 if (hw->partition_id != 1) {
545 i40e_partition_setting_complaint(pf);
546 return -EOPNOTSUPP;
547 }
548
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000549 if (vsi != pf->vsi[pf->lan_vsi])
550 return -EOPNOTSUPP;
551
552 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
553 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000554 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
555 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000556 return -EOPNOTSUPP;
557
558 /* get our own copy of the bits to check against */
559 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
560 i40e_get_settings(netdev, &safe_ecmd);
561
562 /* save autoneg and speed out of ecmd */
563 autoneg = ecmd->autoneg;
564 advertise = ecmd->advertising;
565
566 /* set autoneg and speed back to what they currently are */
567 ecmd->autoneg = safe_ecmd.autoneg;
568 ecmd->advertising = safe_ecmd.advertising;
569
570 ecmd->cmd = safe_ecmd.cmd;
571 /* If ecmd and safe_ecmd are not the same now, then they are
572 * trying to set something that we do not support
573 */
574 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
575 return -EOPNOTSUPP;
576
577 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
578 usleep_range(1000, 2000);
579
580 /* Get the current phy config */
581 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
582 NULL);
583 if (status)
584 return -EAGAIN;
585
Catherine Sullivan124ed152014-07-12 07:28:12 +0000586 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000587 * set below
588 */
589 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000590 config.abilities = abilities.abilities;
591
592 /* Check autoneg */
593 if (autoneg == AUTONEG_ENABLE) {
594 /* If autoneg is not supported, return error */
595 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
596 netdev_info(netdev, "Autoneg not supported on this phy\n");
597 return -EINVAL;
598 }
599 /* If autoneg was not already enabled */
600 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
601 config.abilities = abilities.abilities |
602 I40E_AQ_PHY_ENABLE_AN;
603 change = true;
604 }
605 } else {
606 /* If autoneg is supported 10GBASE_T is the only phy that
607 * can disable it, so otherwise return error
608 */
609 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
610 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
611 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
612 return -EINVAL;
613 }
614 /* If autoneg is currently enabled */
615 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000616 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000617 ~I40E_AQ_PHY_ENABLE_AN;
618 change = true;
619 }
620 }
621
622 if (advertise & ~safe_ecmd.supported)
623 return -EINVAL;
624
625 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000626 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000627 if (advertise & ADVERTISED_1000baseT_Full ||
628 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000629 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000630 if (advertise & ADVERTISED_10000baseT_Full ||
631 advertise & ADVERTISED_10000baseKX4_Full ||
632 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000633 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000634 if (advertise & ADVERTISED_40000baseKR4_Full ||
635 advertise & ADVERTISED_40000baseCR4_Full ||
636 advertise & ADVERTISED_40000baseSR4_Full ||
637 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000638 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000639
Catherine Sullivan124ed152014-07-12 07:28:12 +0000640 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000641 /* copy over the rest of the abilities */
642 config.phy_type = abilities.phy_type;
643 config.eee_capability = abilities.eee_capability;
644 config.eeer = abilities.eeer_val;
645 config.low_power_ctrl = abilities.d3_lpan;
646
Catherine Sullivane8278452015-02-06 08:52:08 +0000647 /* save the requested speeds */
648 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000649 /* set link and auto negotiation so changes take effect */
650 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
651 /* If link is up put link down */
652 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
653 /* Tell the OS link is going down, the link will go
654 * back up when fw says it is ready asynchronously
655 */
656 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
657 netif_carrier_off(netdev);
658 netif_tx_stop_all_queues(netdev);
659 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000660
661 /* make the aq call */
662 status = i40e_aq_set_phy_config(hw, &config, NULL);
663 if (status) {
664 netdev_info(netdev, "Set phy config failed with error %d.\n",
665 status);
666 return -EAGAIN;
667 }
668
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000669 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000670 if (status)
671 netdev_info(netdev, "Updating link info failed with error %d\n",
672 status);
673
674 } else {
675 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
676 }
677
678 return err;
679}
680
Jesse Brandeburga6599722014-06-04 08:45:25 +0000681static int i40e_nway_reset(struct net_device *netdev)
682{
683 /* restart autonegotiation */
684 struct i40e_netdev_priv *np = netdev_priv(netdev);
685 struct i40e_pf *pf = np->vsi->back;
686 struct i40e_hw *hw = &pf->hw;
687 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
688 i40e_status ret = 0;
689
690 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
691 if (ret) {
692 netdev_info(netdev, "link restart failed, aq_err=%d\n",
693 pf->hw.aq.asq_last_status);
694 return -EIO;
695 }
696
697 return 0;
698}
699
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000700/**
701 * i40e_get_pauseparam - Get Flow Control status
702 * Return tx/rx-pause status
703 **/
704static void i40e_get_pauseparam(struct net_device *netdev,
705 struct ethtool_pauseparam *pause)
706{
707 struct i40e_netdev_priv *np = netdev_priv(netdev);
708 struct i40e_pf *pf = np->vsi->back;
709 struct i40e_hw *hw = &pf->hw;
710 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000711 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000712
713 pause->autoneg =
714 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
715 AUTONEG_ENABLE : AUTONEG_DISABLE);
716
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000717 /* PFC enabled so report LFC as off */
718 if (dcbx_cfg->pfc.pfcenable) {
719 pause->rx_pause = 0;
720 pause->tx_pause = 0;
721 return;
722 }
723
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000724 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000725 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000726 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000727 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000728 } else if (hw->fc.current_mode == I40E_FC_FULL) {
729 pause->rx_pause = 1;
730 pause->tx_pause = 1;
731 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000732}
733
Catherine Sullivan2becc352014-06-04 08:45:27 +0000734/**
735 * i40e_set_pauseparam - Set Flow Control parameter
736 * @netdev: network interface device structure
737 * @pause: return tx/rx flow control status
738 **/
739static int i40e_set_pauseparam(struct net_device *netdev,
740 struct ethtool_pauseparam *pause)
741{
742 struct i40e_netdev_priv *np = netdev_priv(netdev);
743 struct i40e_pf *pf = np->vsi->back;
744 struct i40e_vsi *vsi = np->vsi;
745 struct i40e_hw *hw = &pf->hw;
746 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000747 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000748 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
749 i40e_status status;
750 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000751 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000752
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000753 /* Changing the port's flow control is not supported if this isn't the
754 * port's controlling PF
755 */
756 if (hw->partition_id != 1) {
757 i40e_partition_setting_complaint(pf);
758 return -EOPNOTSUPP;
759 }
760
Catherine Sullivan2becc352014-06-04 08:45:27 +0000761 if (vsi != pf->vsi[pf->lan_vsi])
762 return -EOPNOTSUPP;
763
764 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
765 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
766 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
767 return -EOPNOTSUPP;
768 }
769
770 /* If we have link and don't have autoneg */
771 if (!test_bit(__I40E_DOWN, &pf->state) &&
772 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
773 /* Send message that it might not necessarily work*/
774 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
775 }
776
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000777 if (dcbx_cfg->pfc.pfcenable) {
778 netdev_info(netdev,
779 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000780 return -EOPNOTSUPP;
781 }
782
783 if (pause->rx_pause && pause->tx_pause)
784 hw->fc.requested_mode = I40E_FC_FULL;
785 else if (pause->rx_pause && !pause->tx_pause)
786 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
787 else if (!pause->rx_pause && pause->tx_pause)
788 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
789 else if (!pause->rx_pause && !pause->tx_pause)
790 hw->fc.requested_mode = I40E_FC_NONE;
791 else
792 return -EINVAL;
793
Catherine Sullivan94128512014-07-12 07:28:16 +0000794 /* Tell the OS link is going down, the link will go back up when fw
795 * says it is ready asynchronously
796 */
797 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
798 netif_carrier_off(netdev);
799 netif_tx_stop_all_queues(netdev);
800
Catherine Sullivan2becc352014-06-04 08:45:27 +0000801 /* Set the fc mode and only restart an if link is up*/
802 status = i40e_set_fc(hw, &aq_failures, link_up);
803
804 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
805 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
806 status, hw->aq.asq_last_status);
807 err = -EAGAIN;
808 }
809 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
810 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
811 status, hw->aq.asq_last_status);
812 err = -EAGAIN;
813 }
814 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000815 netdev_info(netdev, "Set fc failed on the get_link_info call with error %d and status %d\n",
Catherine Sullivan2becc352014-06-04 08:45:27 +0000816 status, hw->aq.asq_last_status);
817 err = -EAGAIN;
818 }
819
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000820 if (!test_bit(__I40E_DOWN, &pf->state)) {
821 /* Give it a little more time to try to come back */
822 msleep(75);
823 if (!test_bit(__I40E_DOWN, &pf->state))
824 return i40e_nway_reset(netdev);
825 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000826
827 return err;
828}
829
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000830static u32 i40e_get_msglevel(struct net_device *netdev)
831{
832 struct i40e_netdev_priv *np = netdev_priv(netdev);
833 struct i40e_pf *pf = np->vsi->back;
834
835 return pf->msg_enable;
836}
837
838static void i40e_set_msglevel(struct net_device *netdev, u32 data)
839{
840 struct i40e_netdev_priv *np = netdev_priv(netdev);
841 struct i40e_pf *pf = np->vsi->back;
842
843 if (I40E_DEBUG_USER & data)
844 pf->hw.debug_mask = data;
845 pf->msg_enable = data;
846}
847
848static int i40e_get_regs_len(struct net_device *netdev)
849{
850 int reg_count = 0;
851 int i;
852
853 for (i = 0; i40e_reg_list[i].offset != 0; i++)
854 reg_count += i40e_reg_list[i].elements;
855
856 return reg_count * sizeof(u32);
857}
858
859static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
860 void *p)
861{
862 struct i40e_netdev_priv *np = netdev_priv(netdev);
863 struct i40e_pf *pf = np->vsi->back;
864 struct i40e_hw *hw = &pf->hw;
865 u32 *reg_buf = p;
866 int i, j, ri;
867 u32 reg;
868
869 /* Tell ethtool which driver-version-specific regs output we have.
870 *
871 * At some point, if we have ethtool doing special formatting of
872 * this data, it will rely on this version number to know how to
873 * interpret things. Hence, this needs to be updated if/when the
874 * diags register table is changed.
875 */
876 regs->version = 1;
877
878 /* loop through the diags reg table for what to print */
879 ri = 0;
880 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
881 for (j = 0; j < i40e_reg_list[i].elements; j++) {
882 reg = i40e_reg_list[i].offset
883 + (j * i40e_reg_list[i].stride);
884 reg_buf[ri++] = rd32(hw, reg);
885 }
886 }
887
888}
889
890static int i40e_get_eeprom(struct net_device *netdev,
891 struct ethtool_eeprom *eeprom, u8 *bytes)
892{
893 struct i40e_netdev_priv *np = netdev_priv(netdev);
894 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000895 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000896 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000897 u8 *eeprom_buff;
898 u16 i, sectors;
899 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000900 u32 magic;
901
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000902#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000903 if (eeprom->len == 0)
904 return -EINVAL;
905
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000906 /* check for NVMUpdate access method */
907 magic = hw->vendor_id | (hw->device_id << 16);
908 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000909 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000910 int errno;
911
912 /* make sure it is the right magic for NVMUpdate */
913 if ((eeprom->magic >> 16) != hw->device_id)
914 return -EINVAL;
915
Shannon Nelsonc150a502014-11-13 08:23:13 +0000916 cmd = (struct i40e_nvm_access *)eeprom;
917 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000918 if (ret_val)
919 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000920 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
921 ret_val, hw->aq.asq_last_status, errno,
922 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
923 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000924
925 return errno;
926 }
927
928 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000929 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
930
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000931 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000932 if (!eeprom_buff)
933 return -ENOMEM;
934
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000935 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
936 if (ret_val) {
937 dev_info(&pf->pdev->dev,
938 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
939 ret_val, hw->aq.asq_last_status);
940 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000941 }
942
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000943 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
944 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
945 len = I40E_NVM_SECTOR_SIZE;
946 last = false;
947 for (i = 0; i < sectors; i++) {
948 if (i == (sectors - 1)) {
949 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
950 last = true;
951 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000952 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
953 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000954 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000955 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000956 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000957 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000958 "read NVM failed, invalid offset 0x%x\n",
959 offset);
960 break;
961 } else if (ret_val &&
962 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
963 dev_info(&pf->pdev->dev,
964 "read NVM failed, access, offset 0x%x\n",
965 offset);
966 break;
967 } else if (ret_val) {
968 dev_info(&pf->pdev->dev,
969 "read NVM failed offset %d err=%d status=0x%x\n",
970 offset, ret_val, hw->aq.asq_last_status);
971 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000972 }
973 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000974
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000975 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000976 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000977free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000978 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000979 return ret_val;
980}
981
982static int i40e_get_eeprom_len(struct net_device *netdev)
983{
984 struct i40e_netdev_priv *np = netdev_priv(netdev);
985 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000986 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000987
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000988 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
989 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
990 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
991 /* register returns value in power of 2, 64Kbyte chunks. */
992 val = (64 * 1024) * (1 << val);
993 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000994}
995
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000996static int i40e_set_eeprom(struct net_device *netdev,
997 struct ethtool_eeprom *eeprom, u8 *bytes)
998{
999 struct i40e_netdev_priv *np = netdev_priv(netdev);
1000 struct i40e_hw *hw = &np->vsi->back->hw;
1001 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001002 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001003 int ret_val = 0;
1004 int errno;
1005 u32 magic;
1006
1007 /* normal ethtool set_eeprom is not supported */
1008 magic = hw->vendor_id | (hw->device_id << 16);
1009 if (eeprom->magic == magic)
1010 return -EOPNOTSUPP;
1011
1012 /* check for NVMUpdate access method */
1013 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1014 return -EINVAL;
1015
1016 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1017 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1018 return -EBUSY;
1019
Shannon Nelsonc150a502014-11-13 08:23:13 +00001020 cmd = (struct i40e_nvm_access *)eeprom;
1021 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1022 if (ret_val && hw->aq.asq_last_status != I40E_AQ_RC_EBUSY)
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001023 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001024 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1025 ret_val, hw->aq.asq_last_status, errno,
1026 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1027 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001028
1029 return errno;
1030}
1031
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001032static void i40e_get_drvinfo(struct net_device *netdev,
1033 struct ethtool_drvinfo *drvinfo)
1034{
1035 struct i40e_netdev_priv *np = netdev_priv(netdev);
1036 struct i40e_vsi *vsi = np->vsi;
1037 struct i40e_pf *pf = vsi->back;
1038
1039 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1040 strlcpy(drvinfo->version, i40e_driver_version_str,
1041 sizeof(drvinfo->version));
1042 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1043 sizeof(drvinfo->fw_version));
1044 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1045 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001046 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001047}
1048
1049static void i40e_get_ringparam(struct net_device *netdev,
1050 struct ethtool_ringparam *ring)
1051{
1052 struct i40e_netdev_priv *np = netdev_priv(netdev);
1053 struct i40e_pf *pf = np->vsi->back;
1054 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1055
1056 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1057 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1058 ring->rx_mini_max_pending = 0;
1059 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001060 ring->rx_pending = vsi->rx_rings[0]->count;
1061 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001062 ring->rx_mini_pending = 0;
1063 ring->rx_jumbo_pending = 0;
1064}
1065
1066static int i40e_set_ringparam(struct net_device *netdev,
1067 struct ethtool_ringparam *ring)
1068{
1069 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1070 struct i40e_netdev_priv *np = netdev_priv(netdev);
1071 struct i40e_vsi *vsi = np->vsi;
1072 struct i40e_pf *pf = vsi->back;
1073 u32 new_rx_count, new_tx_count;
1074 int i, err = 0;
1075
1076 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1077 return -EINVAL;
1078
Shannon Nelson1fa18372013-11-20 10:03:08 +00001079 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1080 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1081 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1082 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1083 netdev_info(netdev,
1084 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1085 ring->tx_pending, ring->rx_pending,
1086 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1087 return -EINVAL;
1088 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001089
Shannon Nelson1fa18372013-11-20 10:03:08 +00001090 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1091 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001092
1093 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001094 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1095 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001096 return 0;
1097
1098 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1099 usleep_range(1000, 2000);
1100
1101 if (!netif_running(vsi->netdev)) {
1102 /* simple case - set for the next time the netdev is started */
1103 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001104 vsi->tx_rings[i]->count = new_tx_count;
1105 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001106 }
1107 goto done;
1108 }
1109
1110 /* We can't just free everything and then setup again,
1111 * because the ISRs in MSI-X mode get passed pointers
1112 * to the Tx and Rx ring structs.
1113 */
1114
1115 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001116 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001117 netdev_info(netdev,
1118 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001119 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001120 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1121 sizeof(struct i40e_ring), GFP_KERNEL);
1122 if (!tx_rings) {
1123 err = -ENOMEM;
1124 goto done;
1125 }
1126
1127 for (i = 0; i < vsi->num_queue_pairs; i++) {
1128 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001129 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001130 tx_rings[i].count = new_tx_count;
1131 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1132 if (err) {
1133 while (i) {
1134 i--;
1135 i40e_free_tx_resources(&tx_rings[i]);
1136 }
1137 kfree(tx_rings);
1138 tx_rings = NULL;
1139
1140 goto done;
1141 }
1142 }
1143 }
1144
1145 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001146 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001147 netdev_info(netdev,
1148 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001149 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001150 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1151 sizeof(struct i40e_ring), GFP_KERNEL);
1152 if (!rx_rings) {
1153 err = -ENOMEM;
1154 goto free_tx;
1155 }
1156
1157 for (i = 0; i < vsi->num_queue_pairs; i++) {
1158 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001159 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001160 rx_rings[i].count = new_rx_count;
1161 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1162 if (err) {
1163 while (i) {
1164 i--;
1165 i40e_free_rx_resources(&rx_rings[i]);
1166 }
1167 kfree(rx_rings);
1168 rx_rings = NULL;
1169
1170 goto free_tx;
1171 }
1172 }
1173 }
1174
1175 /* Bring interface down, copy in the new ring info,
1176 * then restore the interface
1177 */
1178 i40e_down(vsi);
1179
1180 if (tx_rings) {
1181 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001182 i40e_free_tx_resources(vsi->tx_rings[i]);
1183 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001184 }
1185 kfree(tx_rings);
1186 tx_rings = NULL;
1187 }
1188
1189 if (rx_rings) {
1190 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001191 i40e_free_rx_resources(vsi->rx_rings[i]);
1192 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001193 }
1194 kfree(rx_rings);
1195 rx_rings = NULL;
1196 }
1197
1198 i40e_up(vsi);
1199
1200free_tx:
1201 /* error cleanup if the Rx allocations failed after getting Tx */
1202 if (tx_rings) {
1203 for (i = 0; i < vsi->num_queue_pairs; i++)
1204 i40e_free_tx_resources(&tx_rings[i]);
1205 kfree(tx_rings);
1206 tx_rings = NULL;
1207 }
1208
1209done:
1210 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1211
1212 return err;
1213}
1214
1215static int i40e_get_sset_count(struct net_device *netdev, int sset)
1216{
1217 struct i40e_netdev_priv *np = netdev_priv(netdev);
1218 struct i40e_vsi *vsi = np->vsi;
1219 struct i40e_pf *pf = vsi->back;
1220
1221 switch (sset) {
1222 case ETH_SS_TEST:
1223 return I40E_TEST_LEN;
1224 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001225 if (vsi == pf->vsi[pf->lan_vsi]) {
1226 int len = I40E_PF_STATS_LEN(netdev);
1227
1228 if (pf->lan_veb != I40E_NO_VEB)
1229 len += I40E_VEB_STATS_LEN;
1230 return len;
1231 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001233 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001234 case ETH_SS_PRIV_FLAGS:
1235 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001236 default:
1237 return -EOPNOTSUPP;
1238 }
1239}
1240
1241static void i40e_get_ethtool_stats(struct net_device *netdev,
1242 struct ethtool_stats *stats, u64 *data)
1243{
1244 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001245 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001246 struct i40e_vsi *vsi = np->vsi;
1247 struct i40e_pf *pf = vsi->back;
1248 int i = 0;
1249 char *p;
1250 int j;
1251 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001252 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001253
1254 i40e_update_stats(vsi);
1255
1256 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1257 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1258 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1259 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1260 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001261 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1262 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1263 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1264 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1265 }
Vasu Dev38e00432014-08-01 13:27:03 -07001266#ifdef I40E_FCOE
1267 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1268 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1269 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1270 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1271 }
1272#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001273 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001274 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001275 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001276
1277 if (!tx_ring)
1278 continue;
1279
1280 /* process Tx ring statistics */
1281 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001282 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001283 data[i] = tx_ring->stats.packets;
1284 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001285 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001286 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001287
1288 /* Rx ring is the 2nd half of the queue pair */
1289 rx_ring = &tx_ring[1];
1290 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001291 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001292 data[i] = rx_ring->stats.packets;
1293 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001294 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001295 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001296 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001297 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001298 if (vsi != pf->vsi[pf->lan_vsi])
1299 return;
1300
1301 if (pf->lan_veb != I40E_NO_VEB) {
1302 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1303 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1304 p = (char *)veb;
1305 p += i40e_gstrings_veb_stats[j].stat_offset;
1306 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1307 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001308 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001309 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001310 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1311 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1312 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1313 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1314 }
1315 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1316 data[i++] = pf->stats.priority_xon_tx[j];
1317 data[i++] = pf->stats.priority_xoff_tx[j];
1318 }
1319 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1320 data[i++] = pf->stats.priority_xon_rx[j];
1321 data[i++] = pf->stats.priority_xoff_rx[j];
1322 }
1323 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1324 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001325}
1326
1327static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1328 u8 *data)
1329{
1330 struct i40e_netdev_priv *np = netdev_priv(netdev);
1331 struct i40e_vsi *vsi = np->vsi;
1332 struct i40e_pf *pf = vsi->back;
1333 char *p = (char *)data;
1334 int i;
1335
1336 switch (stringset) {
1337 case ETH_SS_TEST:
1338 for (i = 0; i < I40E_TEST_LEN; i++) {
1339 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1340 data += ETH_GSTRING_LEN;
1341 }
1342 break;
1343 case ETH_SS_STATS:
1344 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1345 snprintf(p, ETH_GSTRING_LEN, "%s",
1346 i40e_gstrings_net_stats[i].stat_string);
1347 p += ETH_GSTRING_LEN;
1348 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001349 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1350 snprintf(p, ETH_GSTRING_LEN, "%s",
1351 i40e_gstrings_misc_stats[i].stat_string);
1352 p += ETH_GSTRING_LEN;
1353 }
Vasu Dev38e00432014-08-01 13:27:03 -07001354#ifdef I40E_FCOE
1355 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1356 snprintf(p, ETH_GSTRING_LEN, "%s",
1357 i40e_gstrings_fcoe_stats[i].stat_string);
1358 p += ETH_GSTRING_LEN;
1359 }
1360#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361 for (i = 0; i < vsi->num_queue_pairs; i++) {
1362 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1363 p += ETH_GSTRING_LEN;
1364 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1365 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001366 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1367 p += ETH_GSTRING_LEN;
1368 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1369 p += ETH_GSTRING_LEN;
1370 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001371 if (vsi != pf->vsi[pf->lan_vsi])
1372 return;
1373
1374 if (pf->lan_veb != I40E_NO_VEB) {
1375 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1376 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1377 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001378 p += ETH_GSTRING_LEN;
1379 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001380 }
1381 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1382 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1383 i40e_gstrings_stats[i].stat_string);
1384 p += ETH_GSTRING_LEN;
1385 }
1386 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1387 snprintf(p, ETH_GSTRING_LEN,
1388 "port.tx_priority_%u_xon", i);
1389 p += ETH_GSTRING_LEN;
1390 snprintf(p, ETH_GSTRING_LEN,
1391 "port.tx_priority_%u_xoff", i);
1392 p += ETH_GSTRING_LEN;
1393 }
1394 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1395 snprintf(p, ETH_GSTRING_LEN,
1396 "port.rx_priority_%u_xon", i);
1397 p += ETH_GSTRING_LEN;
1398 snprintf(p, ETH_GSTRING_LEN,
1399 "port.rx_priority_%u_xoff", i);
1400 p += ETH_GSTRING_LEN;
1401 }
1402 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1403 snprintf(p, ETH_GSTRING_LEN,
1404 "port.rx_priority_%u_xon_2_xoff", i);
1405 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 }
1407 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1408 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001409 case ETH_SS_PRIV_FLAGS:
1410 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1411 memcpy(data, i40e_priv_flags_strings[i],
1412 ETH_GSTRING_LEN);
1413 data += ETH_GSTRING_LEN;
1414 }
1415 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001416 default:
1417 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001418 }
1419}
1420
1421static int i40e_get_ts_info(struct net_device *dev,
1422 struct ethtool_ts_info *info)
1423{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001424 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1425
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001426 /* only report HW timestamping if PTP is enabled */
1427 if (!(pf->flags & I40E_FLAG_PTP))
1428 return ethtool_op_get_ts_info(dev, info);
1429
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001430 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1431 SOF_TIMESTAMPING_RX_SOFTWARE |
1432 SOF_TIMESTAMPING_SOFTWARE |
1433 SOF_TIMESTAMPING_TX_HARDWARE |
1434 SOF_TIMESTAMPING_RX_HARDWARE |
1435 SOF_TIMESTAMPING_RAW_HARDWARE;
1436
1437 if (pf->ptp_clock)
1438 info->phc_index = ptp_clock_index(pf->ptp_clock);
1439 else
1440 info->phc_index = -1;
1441
1442 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1443
1444 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1445 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1446 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1447 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1448 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1449 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1450 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1451 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1452 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1453 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1454 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1455 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1456
1457 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001458}
1459
Shannon Nelson7b086392013-11-20 10:02:59 +00001460static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001461{
Shannon Nelson7b086392013-11-20 10:02:59 +00001462 struct i40e_netdev_priv *np = netdev_priv(netdev);
1463 struct i40e_pf *pf = np->vsi->back;
1464
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001465 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001466 if (i40e_get_link_status(&pf->hw))
1467 *data = 0;
1468 else
1469 *data = 1;
1470
1471 return *data;
1472}
1473
Shannon Nelson7b086392013-11-20 10:02:59 +00001474static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001475{
Shannon Nelson7b086392013-11-20 10:02:59 +00001476 struct i40e_netdev_priv *np = netdev_priv(netdev);
1477 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001479 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001480 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481
Shannon Nelson7b086392013-11-20 10:02:59 +00001482 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483}
1484
Shannon Nelson7b086392013-11-20 10:02:59 +00001485static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001486{
Shannon Nelson7b086392013-11-20 10:02:59 +00001487 struct i40e_netdev_priv *np = netdev_priv(netdev);
1488 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001490 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001491 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001492
Shannon Nelson4443ec92014-11-13 08:23:12 +00001493 /* forcebly clear the NVM Update state machine */
1494 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1495
Shannon Nelson7b086392013-11-20 10:02:59 +00001496 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497}
1498
Shannon Nelson7b086392013-11-20 10:02:59 +00001499static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500{
Shannon Nelson7b086392013-11-20 10:02:59 +00001501 struct i40e_netdev_priv *np = netdev_priv(netdev);
1502 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001503 u16 swc_old = pf->sw_int_count;
1504
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001505 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001506 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1507 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001508 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1509 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1510 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1511 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001512 usleep_range(1000, 2000);
1513 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514
1515 return *data;
1516}
1517
Shannon Nelson7b086392013-11-20 10:02:59 +00001518static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001520 struct i40e_netdev_priv *np = netdev_priv(netdev);
1521 struct i40e_pf *pf = np->vsi->back;
1522
1523 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001524 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001525
1526 return *data;
1527}
1528
1529static void i40e_diag_test(struct net_device *netdev,
1530 struct ethtool_test *eth_test, u64 *data)
1531{
1532 struct i40e_netdev_priv *np = netdev_priv(netdev);
1533 struct i40e_pf *pf = np->vsi->back;
1534
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001535 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1536 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001537 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001538
Shannon Nelsonf551b432013-11-26 10:49:12 +00001539 set_bit(__I40E_TESTING, &pf->state);
1540
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001541 /* Link test performed before hardware reset
1542 * so autoneg doesn't interfere with test result
1543 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001544 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545 eth_test->flags |= ETH_TEST_FL_FAILED;
1546
Shannon Nelson7b086392013-11-20 10:02:59 +00001547 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 eth_test->flags |= ETH_TEST_FL_FAILED;
1549
Shannon Nelson7b086392013-11-20 10:02:59 +00001550 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001551 eth_test->flags |= ETH_TEST_FL_FAILED;
1552
Shannon Nelson7b086392013-11-20 10:02:59 +00001553 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554 eth_test->flags |= ETH_TEST_FL_FAILED;
1555
Shannon Nelsonf551b432013-11-26 10:49:12 +00001556 /* run reg test last, a reset is required after it */
1557 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1558 eth_test->flags |= ETH_TEST_FL_FAILED;
1559
1560 clear_bit(__I40E_TESTING, &pf->state);
1561 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001562 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001564 netif_info(pf, drv, netdev, "online testing starting\n");
1565
Shannon Nelson7b086392013-11-20 10:02:59 +00001566 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001567 eth_test->flags |= ETH_TEST_FL_FAILED;
1568
1569 /* Offline only tests, not run in online; pass by default */
1570 data[I40E_ETH_TEST_REG] = 0;
1571 data[I40E_ETH_TEST_EEPROM] = 0;
1572 data[I40E_ETH_TEST_INTR] = 0;
1573 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001574 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001575
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001576 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001577}
1578
1579static void i40e_get_wol(struct net_device *netdev,
1580 struct ethtool_wolinfo *wol)
1581{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001582 struct i40e_netdev_priv *np = netdev_priv(netdev);
1583 struct i40e_pf *pf = np->vsi->back;
1584 struct i40e_hw *hw = &pf->hw;
1585 u16 wol_nvm_bits;
1586
1587 /* NVM bit on means WoL disabled for the port */
1588 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001589 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001590 wol->supported = 0;
1591 wol->wolopts = 0;
1592 } else {
1593 wol->supported = WAKE_MAGIC;
1594 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1595 }
1596}
1597
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001598/**
1599 * i40e_set_wol - set the WakeOnLAN configuration
1600 * @netdev: the netdev in question
1601 * @wol: the ethtool WoL setting data
1602 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001603static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1604{
1605 struct i40e_netdev_priv *np = netdev_priv(netdev);
1606 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001607 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001608 struct i40e_hw *hw = &pf->hw;
1609 u16 wol_nvm_bits;
1610
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001611 /* WoL not supported if this isn't the controlling PF on the port */
1612 if (hw->partition_id != 1) {
1613 i40e_partition_setting_complaint(pf);
1614 return -EOPNOTSUPP;
1615 }
1616
1617 if (vsi != pf->vsi[pf->lan_vsi])
1618 return -EOPNOTSUPP;
1619
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001620 /* NVM bit on means WoL disabled for the port */
1621 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1622 if (((1 << hw->port) & wol_nvm_bits))
1623 return -EOPNOTSUPP;
1624
1625 /* only magic packet is supported */
1626 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1627 return -EOPNOTSUPP;
1628
1629 /* is this a new value? */
1630 if (pf->wol_en != !!wol->wolopts) {
1631 pf->wol_en = !!wol->wolopts;
1632 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1633 }
1634
1635 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001636}
1637
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001638static int i40e_set_phys_id(struct net_device *netdev,
1639 enum ethtool_phys_id_state state)
1640{
1641 struct i40e_netdev_priv *np = netdev_priv(netdev);
1642 struct i40e_pf *pf = np->vsi->back;
1643 struct i40e_hw *hw = &pf->hw;
1644 int blink_freq = 2;
1645
1646 switch (state) {
1647 case ETHTOOL_ID_ACTIVE:
1648 pf->led_status = i40e_led_get(hw);
1649 return blink_freq;
1650 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001651 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652 break;
1653 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001654 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001655 break;
1656 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001657 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001659 default:
1660 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661 }
1662
1663 return 0;
1664}
1665
1666/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1667 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1668 * 125us (8000 interrupts per second) == ITR(62)
1669 */
1670
1671static int i40e_get_coalesce(struct net_device *netdev,
1672 struct ethtool_coalesce *ec)
1673{
1674 struct i40e_netdev_priv *np = netdev_priv(netdev);
1675 struct i40e_vsi *vsi = np->vsi;
1676
1677 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1678 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1679
1680 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001681 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001682
1683 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001684 ec->use_adaptive_tx_coalesce = 1;
1685
1686 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1687 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001688
1689 return 0;
1690}
1691
1692static int i40e_set_coalesce(struct net_device *netdev,
1693 struct ethtool_coalesce *ec)
1694{
1695 struct i40e_netdev_priv *np = netdev_priv(netdev);
1696 struct i40e_q_vector *q_vector;
1697 struct i40e_vsi *vsi = np->vsi;
1698 struct i40e_pf *pf = vsi->back;
1699 struct i40e_hw *hw = &pf->hw;
1700 u16 vector;
1701 int i;
1702
1703 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1704 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1705
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001706 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001707 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001708 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001709 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001710 } else if (ec->rx_coalesce_usecs == 0) {
1711 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001712 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001713 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 +00001714 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001715 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001716 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001717 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001718
Mitch Williams32f5f542014-04-04 04:43:10 +00001719 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001720 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001722 } else if (ec->tx_coalesce_usecs == 0) {
1723 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001724 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001725 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 +00001726 } else {
1727 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001728 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001729 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001730 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001731
1732 if (ec->use_adaptive_rx_coalesce)
1733 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1734 else
1735 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1736
1737 if (ec->use_adaptive_tx_coalesce)
1738 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1739 else
1740 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741
Alexander Duyck493fb302013-09-28 07:01:44 +00001742 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1743 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001744 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1745 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1746 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1747 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1748 i40e_flush(hw);
1749 }
1750
1751 return 0;
1752}
1753
1754/**
1755 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1756 * @pf: pointer to the physical function struct
1757 * @cmd: ethtool rxnfc command
1758 *
1759 * Returns Success if the flow is supported, else Invalid Input.
1760 **/
1761static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1762{
1763 cmd->data = 0;
1764
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001765 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1766 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1767 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1768 return 0;
1769 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001770 /* Report default options for RSS on i40e */
1771 switch (cmd->flow_type) {
1772 case TCP_V4_FLOW:
1773 case UDP_V4_FLOW:
1774 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1775 /* fall through to add IP fields */
1776 case SCTP_V4_FLOW:
1777 case AH_ESP_V4_FLOW:
1778 case AH_V4_FLOW:
1779 case ESP_V4_FLOW:
1780 case IPV4_FLOW:
1781 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1782 break;
1783 case TCP_V6_FLOW:
1784 case UDP_V6_FLOW:
1785 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1786 /* fall through to add IP fields */
1787 case SCTP_V6_FLOW:
1788 case AH_ESP_V6_FLOW:
1789 case AH_V6_FLOW:
1790 case ESP_V6_FLOW:
1791 case IPV6_FLOW:
1792 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1793 break;
1794 default:
1795 return -EINVAL;
1796 }
1797
1798 return 0;
1799}
1800
1801/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001802 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1803 * @pf: Pointer to the physical function struct
1804 * @cmd: The command to get or set Rx flow classification rules
1805 * @rule_locs: Array of used rule locations
1806 *
1807 * This function populates both the total and actual rule count of
1808 * the ethtool flow classification command
1809 *
1810 * Returns 0 on success or -EMSGSIZE if entry not found
1811 **/
1812static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1813 struct ethtool_rxnfc *cmd,
1814 u32 *rule_locs)
1815{
1816 struct i40e_fdir_filter *rule;
1817 struct hlist_node *node2;
1818 int cnt = 0;
1819
1820 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001821 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001822
1823 hlist_for_each_entry_safe(rule, node2,
1824 &pf->fdir_filter_list, fdir_node) {
1825 if (cnt == cmd->rule_cnt)
1826 return -EMSGSIZE;
1827
1828 rule_locs[cnt] = rule->fd_id;
1829 cnt++;
1830 }
1831
1832 cmd->rule_cnt = cnt;
1833
1834 return 0;
1835}
1836
1837/**
1838 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1839 * @pf: Pointer to the physical function struct
1840 * @cmd: The command to get or set Rx flow classification rules
1841 *
1842 * This function looks up a filter based on the Rx flow classification
1843 * command and fills the flow spec info for it if found
1844 *
1845 * Returns 0 on success or -EINVAL if filter not found
1846 **/
1847static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1848 struct ethtool_rxnfc *cmd)
1849{
1850 struct ethtool_rx_flow_spec *fsp =
1851 (struct ethtool_rx_flow_spec *)&cmd->fs;
1852 struct i40e_fdir_filter *rule = NULL;
1853 struct hlist_node *node2;
1854
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001855 hlist_for_each_entry_safe(rule, node2,
1856 &pf->fdir_filter_list, fdir_node) {
1857 if (fsp->location <= rule->fd_id)
1858 break;
1859 }
1860
1861 if (!rule || fsp->location != rule->fd_id)
1862 return -EINVAL;
1863
1864 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001865 if (fsp->flow_type == IP_USER_FLOW) {
1866 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1867 fsp->h_u.usr_ip4_spec.proto = 0;
1868 fsp->m_u.usr_ip4_spec.proto = 0;
1869 }
1870
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001871 /* Reverse the src and dest notion, since the HW views them from
1872 * Tx perspective where as the user expects it from Rx filter view.
1873 */
1874 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1875 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1876 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1877 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001878
1879 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1880 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1881 else
1882 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001883
1884 return 0;
1885}
1886
1887/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001888 * i40e_get_rxnfc - command to get RX flow classification rules
1889 * @netdev: network interface device structure
1890 * @cmd: ethtool rxnfc command
1891 *
1892 * Returns Success if the command is supported.
1893 **/
1894static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1895 u32 *rule_locs)
1896{
1897 struct i40e_netdev_priv *np = netdev_priv(netdev);
1898 struct i40e_vsi *vsi = np->vsi;
1899 struct i40e_pf *pf = vsi->back;
1900 int ret = -EOPNOTSUPP;
1901
1902 switch (cmd->cmd) {
1903 case ETHTOOL_GRXRINGS:
1904 cmd->data = vsi->alloc_queue_pairs;
1905 ret = 0;
1906 break;
1907 case ETHTOOL_GRXFH:
1908 ret = i40e_get_rss_hash_opts(pf, cmd);
1909 break;
1910 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001911 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001912 /* report total rule count */
1913 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001914 ret = 0;
1915 break;
1916 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001917 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001918 break;
1919 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001920 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1921 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001922 default:
1923 break;
1924 }
1925
1926 return ret;
1927}
1928
1929/**
1930 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1931 * @pf: pointer to the physical function struct
1932 * @cmd: ethtool rxnfc command
1933 *
1934 * Returns Success if the flow input set is supported.
1935 **/
1936static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1937{
1938 struct i40e_hw *hw = &pf->hw;
1939 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1940 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1941
1942 /* RSS does not support anything other than hashing
1943 * to queues on src and dst IPs and ports
1944 */
1945 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1946 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1947 return -EINVAL;
1948
1949 /* We need at least the IP SRC and DEST fields for hashing */
1950 if (!(nfc->data & RXH_IP_SRC) ||
1951 !(nfc->data & RXH_IP_DST))
1952 return -EINVAL;
1953
1954 switch (nfc->flow_type) {
1955 case TCP_V4_FLOW:
1956 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1957 case 0:
1958 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1959 break;
1960 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1961 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1962 break;
1963 default:
1964 return -EINVAL;
1965 }
1966 break;
1967 case TCP_V6_FLOW:
1968 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1969 case 0:
1970 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1971 break;
1972 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1973 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1974 break;
1975 default:
1976 return -EINVAL;
1977 }
1978 break;
1979 case UDP_V4_FLOW:
1980 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1981 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001982 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1983 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001984 break;
1985 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001986 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1987 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001988 break;
1989 default:
1990 return -EINVAL;
1991 }
1992 break;
1993 case UDP_V6_FLOW:
1994 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1995 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001996 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1997 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998 break;
1999 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00002000 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2001 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002002 break;
2003 default:
2004 return -EINVAL;
2005 }
2006 break;
2007 case AH_ESP_V4_FLOW:
2008 case AH_V4_FLOW:
2009 case ESP_V4_FLOW:
2010 case SCTP_V4_FLOW:
2011 if ((nfc->data & RXH_L4_B_0_1) ||
2012 (nfc->data & RXH_L4_B_2_3))
2013 return -EINVAL;
2014 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
2015 break;
2016 case AH_ESP_V6_FLOW:
2017 case AH_V6_FLOW:
2018 case ESP_V6_FLOW:
2019 case SCTP_V6_FLOW:
2020 if ((nfc->data & RXH_L4_B_0_1) ||
2021 (nfc->data & RXH_L4_B_2_3))
2022 return -EINVAL;
2023 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2024 break;
2025 case IPV4_FLOW:
2026 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2027 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2028 break;
2029 case IPV6_FLOW:
2030 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2031 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2032 break;
2033 default:
2034 return -EINVAL;
2035 }
2036
2037 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2038 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2039 i40e_flush(hw);
2040
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002041 /* Save setting for future output/update */
2042 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002044 return 0;
2045}
2046
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002047/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002048 * i40e_match_fdir_input_set - Match a new filter against an existing one
2049 * @rule: The filter already added
2050 * @input: The new filter to comapre against
2051 *
2052 * Returns true if the two input set match
2053 **/
2054static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2055 struct i40e_fdir_filter *input)
2056{
2057 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2058 (rule->src_ip[0] != input->src_ip[0]) ||
2059 (rule->dst_port != input->dst_port) ||
2060 (rule->src_port != input->src_port))
2061 return false;
2062 return true;
2063}
2064
2065/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002066 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2067 * @vsi: Pointer to the targeted VSI
2068 * @input: The filter to update or NULL to indicate deletion
2069 * @sw_idx: Software index to the filter
2070 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002071 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002072 * This function updates (or deletes) a Flow Director entry from
2073 * the hlist of the corresponding PF
2074 *
2075 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002076 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002077static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2078 struct i40e_fdir_filter *input,
2079 u16 sw_idx,
2080 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002081{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002082 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002083 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002084 struct hlist_node *node2;
2085 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002086
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002087 parent = NULL;
2088 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002089
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002090 hlist_for_each_entry_safe(rule, node2,
2091 &pf->fdir_filter_list, fdir_node) {
2092 /* hash found, or no matching entry */
2093 if (rule->fd_id >= sw_idx)
2094 break;
2095 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002096 }
2097
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002098 /* if there is an old rule occupying our place remove it */
2099 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002100 if (input && !i40e_match_fdir_input_set(rule, input))
2101 err = i40e_add_del_fdir(vsi, rule, false);
2102 else if (!input)
2103 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002104 hlist_del(&rule->fdir_node);
2105 kfree(rule);
2106 pf->fdir_pf_active_filters--;
2107 }
2108
2109 /* If no input this was a delete, err should be 0 if a rule was
2110 * successfully found and removed from the list else -EINVAL
2111 */
2112 if (!input)
2113 return err;
2114
2115 /* initialize node and set software index */
2116 INIT_HLIST_NODE(&input->fdir_node);
2117
2118 /* add filter to the list */
2119 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002120 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002121 else
2122 hlist_add_head(&input->fdir_node,
2123 &pf->fdir_filter_list);
2124
2125 /* update counts */
2126 pf->fdir_pf_active_filters++;
2127
2128 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002129}
2130
2131/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002132 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2133 * @vsi: Pointer to the targeted VSI
2134 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002135 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002136 * The function removes a Flow Director filter entry from the
2137 * hlist of the corresponding PF
2138 *
2139 * Returns 0 on success
2140 */
2141static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2142 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002143{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002144 struct ethtool_rx_flow_spec *fsp =
2145 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002146 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002147 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002148
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002149 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2150 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2151 return -EBUSY;
2152
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002153 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2154 return -EBUSY;
2155
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002156 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002157
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002158 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002159 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002160}
2161
2162/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002163 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002164 * @vsi: pointer to the targeted VSI
2165 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002166 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002167 * Add Flow Director filters for a specific flow spec based on their
2168 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002169 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002170static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2171 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002173 struct ethtool_rx_flow_spec *fsp;
2174 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002175 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002176 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002177
2178 if (!vsi)
2179 return -EINVAL;
2180
2181 pf = vsi->back;
2182
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002183 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2184 return -EOPNOTSUPP;
2185
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002186 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002187 return -ENOSPC;
2188
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002189 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2190 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2191 return -EBUSY;
2192
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002193 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2194 return -EBUSY;
2195
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002196 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2197
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002198 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2199 pf->hw.func_caps.fd_filters_guaranteed)) {
2200 return -EINVAL;
2201 }
2202
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002203 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2204 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205 return -EINVAL;
2206
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002207 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002208
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002209 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002210 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002211
2212 input->fd_id = fsp->location;
2213
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002214 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2215 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2216 else
2217 input->dest_ctl =
2218 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2219
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002220 input->q_index = fsp->ring_cookie;
2221 input->flex_off = 0;
2222 input->pctype = 0;
2223 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002224 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002225 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002226 input->flow_type = fsp->flow_type;
2227 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002228
2229 /* Reverse the src and dest notion, since the HW expects them to be from
2230 * Tx perspective where as the input from user is from Rx filter view.
2231 */
2232 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2233 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2234 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2235 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002236
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002237 ret = i40e_add_del_fdir(vsi, input, true);
2238 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002239 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002240 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002241 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242
2243 return ret;
2244}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002245
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002246/**
2247 * i40e_set_rxnfc - command to set RX flow classification rules
2248 * @netdev: network interface device structure
2249 * @cmd: ethtool rxnfc command
2250 *
2251 * Returns Success if the command is supported.
2252 **/
2253static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2254{
2255 struct i40e_netdev_priv *np = netdev_priv(netdev);
2256 struct i40e_vsi *vsi = np->vsi;
2257 struct i40e_pf *pf = vsi->back;
2258 int ret = -EOPNOTSUPP;
2259
2260 switch (cmd->cmd) {
2261 case ETHTOOL_SRXFH:
2262 ret = i40e_set_rss_hash_opt(pf, cmd);
2263 break;
2264 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002265 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002266 break;
2267 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002268 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002269 break;
2270 default:
2271 break;
2272 }
2273
2274 return ret;
2275}
2276
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002277/**
2278 * i40e_max_channels - get Max number of combined channels supported
2279 * @vsi: vsi pointer
2280 **/
2281static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2282{
2283 /* TODO: This code assumes DCB and FD is disabled for now. */
2284 return vsi->alloc_queue_pairs;
2285}
2286
2287/**
2288 * i40e_get_channels - Get the current channels enabled and max supported etc.
2289 * @netdev: network interface device structure
2290 * @ch: ethtool channels structure
2291 *
2292 * We don't support separate tx and rx queues as channels. The other count
2293 * represents how many queues are being used for control. max_combined counts
2294 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2295 * q_vectors since we support a lot more queue pairs than q_vectors.
2296 **/
2297static void i40e_get_channels(struct net_device *dev,
2298 struct ethtool_channels *ch)
2299{
2300 struct i40e_netdev_priv *np = netdev_priv(dev);
2301 struct i40e_vsi *vsi = np->vsi;
2302 struct i40e_pf *pf = vsi->back;
2303
2304 /* report maximum channels */
2305 ch->max_combined = i40e_max_channels(vsi);
2306
2307 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002308 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002309 ch->max_other = ch->other_count;
2310
2311 /* Note: This code assumes DCB is disabled for now. */
2312 ch->combined_count = vsi->num_queue_pairs;
2313}
2314
2315/**
2316 * i40e_set_channels - Set the new channels count.
2317 * @netdev: network interface device structure
2318 * @ch: ethtool channels structure
2319 *
2320 * The new channels count may not be the same as requested by the user
2321 * since it gets rounded down to a power of 2 value.
2322 **/
2323static int i40e_set_channels(struct net_device *dev,
2324 struct ethtool_channels *ch)
2325{
2326 struct i40e_netdev_priv *np = netdev_priv(dev);
2327 unsigned int count = ch->combined_count;
2328 struct i40e_vsi *vsi = np->vsi;
2329 struct i40e_pf *pf = vsi->back;
2330 int new_count;
2331
2332 /* We do not support setting channels for any other VSI at present */
2333 if (vsi->type != I40E_VSI_MAIN)
2334 return -EINVAL;
2335
2336 /* verify they are not requesting separate vectors */
2337 if (!count || ch->rx_count || ch->tx_count)
2338 return -EINVAL;
2339
2340 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002341 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002342 return -EINVAL;
2343
2344 /* verify the number of channels does not exceed hardware limits */
2345 if (count > i40e_max_channels(vsi))
2346 return -EINVAL;
2347
2348 /* update feature limits from largest to smallest supported values */
2349 /* TODO: Flow director limit, DCB etc */
2350
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002351 /* use rss_reconfig to rebuild with new queue count and update traffic
2352 * class queue mapping
2353 */
2354 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002355 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002356 return 0;
2357 else
2358 return -EINVAL;
2359}
2360
Greg Rose7e45ab42015-02-06 08:52:19 +00002361/**
2362 * i40e_get_priv_flags - report device private flags
2363 * @dev: network interface device structure
2364 *
2365 * The get string set count and the string set should be matched for each
2366 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2367 * array.
2368 *
2369 * Returns a u32 bitmap of flags.
2370 **/
2371u32 i40e_get_priv_flags(struct net_device *dev)
2372{
2373 struct i40e_netdev_priv *np = netdev_priv(dev);
2374 struct i40e_vsi *vsi = np->vsi;
2375 struct i40e_pf *pf = vsi->back;
2376 u32 ret_flags = 0;
2377
2378 ret_flags |= pf->hw.func_caps.npar_enable ?
2379 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
2380
2381 return ret_flags;
2382}
2383
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002384static const struct ethtool_ops i40e_ethtool_ops = {
2385 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002386 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002387 .get_drvinfo = i40e_get_drvinfo,
2388 .get_regs_len = i40e_get_regs_len,
2389 .get_regs = i40e_get_regs,
2390 .nway_reset = i40e_nway_reset,
2391 .get_link = ethtool_op_get_link,
2392 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002393 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002394 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002395 .get_eeprom_len = i40e_get_eeprom_len,
2396 .get_eeprom = i40e_get_eeprom,
2397 .get_ringparam = i40e_get_ringparam,
2398 .set_ringparam = i40e_set_ringparam,
2399 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002400 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002401 .get_msglevel = i40e_get_msglevel,
2402 .set_msglevel = i40e_set_msglevel,
2403 .get_rxnfc = i40e_get_rxnfc,
2404 .set_rxnfc = i40e_set_rxnfc,
2405 .self_test = i40e_diag_test,
2406 .get_strings = i40e_get_strings,
2407 .set_phys_id = i40e_set_phys_id,
2408 .get_sset_count = i40e_get_sset_count,
2409 .get_ethtool_stats = i40e_get_ethtool_stats,
2410 .get_coalesce = i40e_get_coalesce,
2411 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002412 .get_channels = i40e_get_channels,
2413 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002414 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002415 .get_priv_flags = i40e_get_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002416};
2417
2418void i40e_set_ethtool_ops(struct net_device *netdev)
2419{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002420 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002421}