blob: 5ef77dd3763eb66a717b5b612b1b53db6e6b50ac [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
220/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000221 * i40e_partition_setting_complaint - generic complaint for MFP restriction
222 * @pf: the PF struct
223 **/
224static void i40e_partition_setting_complaint(struct i40e_pf *pf)
225{
226 dev_info(&pf->pdev->dev,
227 "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");
228}
229
230/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000231 * i40e_get_settings_link_up - Get the Link settings for when link is up
232 * @hw: hw structure
233 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000234 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000235 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000236 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000237static void i40e_get_settings_link_up(struct i40e_hw *hw,
238 struct ethtool_cmd *ecmd,
239 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000240{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000241 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242 u32 link_speed = hw_link_info->link_speed;
243
Catherine Sullivane8278452015-02-06 08:52:08 +0000244 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000245 switch (hw_link_info->phy_type) {
246 case I40E_PHY_TYPE_40GBASE_CR4:
247 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000248 ecmd->supported = SUPPORTED_Autoneg |
249 SUPPORTED_40000baseCR4_Full;
250 ecmd->advertising = ADVERTISED_Autoneg |
251 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000253 case I40E_PHY_TYPE_XLAUI:
254 case I40E_PHY_TYPE_XLPPI:
255 ecmd->supported = SUPPORTED_40000baseCR4_Full;
256 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000257 case I40E_PHY_TYPE_40GBASE_KR4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000258 ecmd->supported = SUPPORTED_Autoneg |
259 SUPPORTED_40000baseKR4_Full;
260 ecmd->advertising = ADVERTISED_Autoneg |
261 ADVERTISED_40000baseKR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 break;
263 case I40E_PHY_TYPE_40GBASE_SR4:
264 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 break;
266 case I40E_PHY_TYPE_40GBASE_LR4:
267 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000268 break;
269 case I40E_PHY_TYPE_10GBASE_KX4:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000270 ecmd->supported = SUPPORTED_Autoneg |
271 SUPPORTED_10000baseKX4_Full;
272 ecmd->advertising = ADVERTISED_Autoneg |
273 ADVERTISED_10000baseKX4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000274 break;
275 case I40E_PHY_TYPE_10GBASE_KR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000276 ecmd->supported = SUPPORTED_Autoneg |
277 SUPPORTED_10000baseKR_Full;
278 ecmd->advertising = ADVERTISED_Autoneg |
279 ADVERTISED_10000baseKR_Full;
280 break;
281 case I40E_PHY_TYPE_10GBASE_SR:
282 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000283 case I40E_PHY_TYPE_1000BASE_SX:
284 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivane8278452015-02-06 08:52:08 +0000285 ecmd->supported = SUPPORTED_10000baseT_Full |
286 SUPPORTED_1000baseT_Full;
287 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
288 ecmd->advertising |= ADVERTISED_10000baseT_Full;
289 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
290 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000291 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000292 case I40E_PHY_TYPE_1000BASE_KX:
293 ecmd->supported = SUPPORTED_Autoneg |
294 SUPPORTED_1000baseKX_Full;
295 ecmd->advertising = ADVERTISED_Autoneg |
296 ADVERTISED_1000baseKX_Full;
297 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000298 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000299 case I40E_PHY_TYPE_1000BASE_T:
300 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000302 SUPPORTED_10000baseT_Full |
303 SUPPORTED_1000baseT_Full |
304 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000305 ecmd->advertising = ADVERTISED_Autoneg;
306 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
307 ecmd->advertising |= ADVERTISED_10000baseT_Full;
308 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
309 ecmd->advertising |= ADVERTISED_1000baseT_Full;
310 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
311 ecmd->advertising |= ADVERTISED_100baseT_Full;
312 break;
313 case I40E_PHY_TYPE_10GBASE_CR1_CU:
314 case I40E_PHY_TYPE_10GBASE_CR1:
315 ecmd->supported = SUPPORTED_Autoneg |
316 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000317 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000318 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000319 break;
320 case I40E_PHY_TYPE_XAUI:
321 case I40E_PHY_TYPE_XFI:
322 case I40E_PHY_TYPE_SFI:
323 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
324 ecmd->supported = SUPPORTED_10000baseT_Full;
325 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000326 case I40E_PHY_TYPE_SGMII:
327 ecmd->supported = SUPPORTED_Autoneg |
328 SUPPORTED_1000baseT_Full |
329 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000330 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
331 ecmd->advertising |= ADVERTISED_1000baseT_Full;
332 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
333 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000334 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000335 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000337 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
338 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000339 }
340
Catherine Sullivane8278452015-02-06 08:52:08 +0000341 /* Set speed and duplex */
342 switch (link_speed) {
343 case I40E_LINK_SPEED_40GB:
344 /* need a SPEED_40000 in ethtool.h */
345 ethtool_cmd_speed_set(ecmd, 40000);
346 break;
347 case I40E_LINK_SPEED_10GB:
348 ethtool_cmd_speed_set(ecmd, SPEED_10000);
349 break;
350 case I40E_LINK_SPEED_1GB:
351 ethtool_cmd_speed_set(ecmd, SPEED_1000);
352 break;
353 case I40E_LINK_SPEED_100MB:
354 ethtool_cmd_speed_set(ecmd, SPEED_100);
355 break;
356 default:
357 break;
358 }
359 ecmd->duplex = DUPLEX_FULL;
360}
361
362/**
363 * i40e_get_settings_link_down - Get the Link settings for when link is down
364 * @hw: hw structure
365 * @ecmd: ethtool command to fill in
366 *
367 * Reports link settings that can be determined when link is down
368 **/
369static void i40e_get_settings_link_down(struct i40e_hw *hw,
370 struct ethtool_cmd *ecmd)
371{
372 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
373
374 /* link is down and the driver needs to fall back on
375 * device ID to determine what kinds of info to display,
376 * it's mostly a guess that may change when link is up
377 */
378 switch (hw->device_id) {
379 case I40E_DEV_ID_QSFP_A:
380 case I40E_DEV_ID_QSFP_B:
381 case I40E_DEV_ID_QSFP_C:
382 /* pluggable QSFP */
383 ecmd->supported = SUPPORTED_40000baseSR4_Full |
384 SUPPORTED_40000baseCR4_Full |
385 SUPPORTED_40000baseLR4_Full;
386 ecmd->advertising = ADVERTISED_40000baseSR4_Full |
387 ADVERTISED_40000baseCR4_Full |
388 ADVERTISED_40000baseLR4_Full;
389 break;
390 case I40E_DEV_ID_KX_B:
391 /* backplane 40G */
392 ecmd->supported = SUPPORTED_40000baseKR4_Full;
393 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
394 break;
395 case I40E_DEV_ID_KX_C:
396 /* backplane 10G */
397 ecmd->supported = SUPPORTED_10000baseKR_Full;
398 ecmd->advertising = ADVERTISED_10000baseKR_Full;
399 break;
400 case I40E_DEV_ID_10G_BASE_T:
401 ecmd->supported = SUPPORTED_10000baseT_Full |
402 SUPPORTED_1000baseT_Full |
403 SUPPORTED_100baseT_Full;
404 /* Figure out what has been requested */
405 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
406 ecmd->advertising |= ADVERTISED_10000baseT_Full;
407 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
408 ecmd->advertising |= ADVERTISED_1000baseT_Full;
409 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
410 ecmd->advertising |= ADVERTISED_100baseT_Full;
411 break;
412 default:
413 /* all the rest are 10G/1G */
414 ecmd->supported = SUPPORTED_10000baseT_Full |
415 SUPPORTED_1000baseT_Full;
416 /* Figure out what has been requested */
417 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
418 ecmd->advertising |= ADVERTISED_10000baseT_Full;
419 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
420 ecmd->advertising |= ADVERTISED_1000baseT_Full;
421 break;
422 }
423
424 /* With no link speed and duplex are unknown */
425 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
426 ecmd->duplex = DUPLEX_UNKNOWN;
427}
428
429/**
430 * i40e_get_settings - Get Link Speed and Duplex settings
431 * @netdev: network interface device structure
432 * @ecmd: ethtool command
433 *
434 * Reports speed/duplex settings based on media_type
435 **/
436static int i40e_get_settings(struct net_device *netdev,
437 struct ethtool_cmd *ecmd)
438{
439 struct i40e_netdev_priv *np = netdev_priv(netdev);
440 struct i40e_pf *pf = np->vsi->back;
441 struct i40e_hw *hw = &pf->hw;
442 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
443 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
444
445 if (link_up)
446 i40e_get_settings_link_up(hw, ecmd, netdev);
447 else
448 i40e_get_settings_link_down(hw, ecmd);
449
450 /* Now set the settings that don't rely on link being up/down */
451
452 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000453 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
454 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000455
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000456 switch (hw->phy.media_type) {
457 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000458 ecmd->supported |= SUPPORTED_Autoneg |
459 SUPPORTED_Backplane;
460 ecmd->advertising |= ADVERTISED_Autoneg |
461 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000462 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000463 break;
464 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000465 ecmd->supported |= SUPPORTED_TP;
466 ecmd->advertising |= ADVERTISED_TP;
467 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000468 break;
469 case I40E_MEDIA_TYPE_DA:
470 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000471 ecmd->supported |= SUPPORTED_FIBRE;
472 ecmd->advertising |= ADVERTISED_FIBRE;
473 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000474 break;
475 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000476 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000477 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000478 break;
479 case I40E_MEDIA_TYPE_UNKNOWN:
480 default:
481 ecmd->port = PORT_OTHER;
482 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 }
484
Catherine Sullivane8278452015-02-06 08:52:08 +0000485 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000486 ecmd->transceiver = XCVR_EXTERNAL;
487
Catherine Sullivane8278452015-02-06 08:52:08 +0000488 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000489 ecmd->supported |= SUPPORTED_Pause;
490
Catherine Sullivane8278452015-02-06 08:52:08 +0000491 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000492 case I40E_FC_FULL:
493 ecmd->advertising |= ADVERTISED_Pause;
494 break;
495 case I40E_FC_TX_PAUSE:
496 ecmd->advertising |= ADVERTISED_Asym_Pause;
497 break;
498 case I40E_FC_RX_PAUSE:
499 ecmd->advertising |= (ADVERTISED_Pause |
500 ADVERTISED_Asym_Pause);
501 break;
502 default:
503 ecmd->advertising &= ~(ADVERTISED_Pause |
504 ADVERTISED_Asym_Pause);
505 break;
506 }
507
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000508 return 0;
509}
510
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000511/**
512 * i40e_set_settings - Set Speed and Duplex
513 * @netdev: network interface device structure
514 * @ecmd: ethtool command
515 *
516 * Set speed/duplex per media_types advertised/forced
517 **/
518static int i40e_set_settings(struct net_device *netdev,
519 struct ethtool_cmd *ecmd)
520{
521 struct i40e_netdev_priv *np = netdev_priv(netdev);
522 struct i40e_aq_get_phy_abilities_resp abilities;
523 struct i40e_aq_set_phy_config config;
524 struct i40e_pf *pf = np->vsi->back;
525 struct i40e_vsi *vsi = np->vsi;
526 struct i40e_hw *hw = &pf->hw;
527 struct ethtool_cmd safe_ecmd;
528 i40e_status status = 0;
529 bool change = false;
530 int err = 0;
531 u8 autoneg;
532 u32 advertise;
533
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000534 /* Changing port settings is not supported if this isn't the
535 * port's controlling PF
536 */
537 if (hw->partition_id != 1) {
538 i40e_partition_setting_complaint(pf);
539 return -EOPNOTSUPP;
540 }
541
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000542 if (vsi != pf->vsi[pf->lan_vsi])
543 return -EOPNOTSUPP;
544
545 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
546 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000547 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
548 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000549 return -EOPNOTSUPP;
550
551 /* get our own copy of the bits to check against */
552 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
553 i40e_get_settings(netdev, &safe_ecmd);
554
555 /* save autoneg and speed out of ecmd */
556 autoneg = ecmd->autoneg;
557 advertise = ecmd->advertising;
558
559 /* set autoneg and speed back to what they currently are */
560 ecmd->autoneg = safe_ecmd.autoneg;
561 ecmd->advertising = safe_ecmd.advertising;
562
563 ecmd->cmd = safe_ecmd.cmd;
564 /* If ecmd and safe_ecmd are not the same now, then they are
565 * trying to set something that we do not support
566 */
567 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
568 return -EOPNOTSUPP;
569
570 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
571 usleep_range(1000, 2000);
572
573 /* Get the current phy config */
574 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
575 NULL);
576 if (status)
577 return -EAGAIN;
578
Catherine Sullivan124ed152014-07-12 07:28:12 +0000579 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000580 * set below
581 */
582 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000583 config.abilities = abilities.abilities;
584
585 /* Check autoneg */
586 if (autoneg == AUTONEG_ENABLE) {
587 /* If autoneg is not supported, return error */
588 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
589 netdev_info(netdev, "Autoneg not supported on this phy\n");
590 return -EINVAL;
591 }
592 /* If autoneg was not already enabled */
593 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
594 config.abilities = abilities.abilities |
595 I40E_AQ_PHY_ENABLE_AN;
596 change = true;
597 }
598 } else {
599 /* If autoneg is supported 10GBASE_T is the only phy that
600 * can disable it, so otherwise return error
601 */
602 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
603 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
604 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
605 return -EINVAL;
606 }
607 /* If autoneg is currently enabled */
608 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000609 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000610 ~I40E_AQ_PHY_ENABLE_AN;
611 change = true;
612 }
613 }
614
615 if (advertise & ~safe_ecmd.supported)
616 return -EINVAL;
617
618 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000619 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000620 if (advertise & ADVERTISED_1000baseT_Full ||
621 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000622 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000623 if (advertise & ADVERTISED_10000baseT_Full ||
624 advertise & ADVERTISED_10000baseKX4_Full ||
625 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000626 config.link_speed |= I40E_LINK_SPEED_10GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000627 if (advertise & ADVERTISED_40000baseKR4_Full ||
628 advertise & ADVERTISED_40000baseCR4_Full ||
629 advertise & ADVERTISED_40000baseSR4_Full ||
630 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000631 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000632
Catherine Sullivan124ed152014-07-12 07:28:12 +0000633 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000634 /* copy over the rest of the abilities */
635 config.phy_type = abilities.phy_type;
636 config.eee_capability = abilities.eee_capability;
637 config.eeer = abilities.eeer_val;
638 config.low_power_ctrl = abilities.d3_lpan;
639
Catherine Sullivane8278452015-02-06 08:52:08 +0000640 /* save the requested speeds */
641 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000642 /* set link and auto negotiation so changes take effect */
643 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
644 /* If link is up put link down */
645 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
646 /* Tell the OS link is going down, the link will go
647 * back up when fw says it is ready asynchronously
648 */
649 netdev_info(netdev, "PHY settings change requested, NIC Link is going down.\n");
650 netif_carrier_off(netdev);
651 netif_tx_stop_all_queues(netdev);
652 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000653
654 /* make the aq call */
655 status = i40e_aq_set_phy_config(hw, &config, NULL);
656 if (status) {
657 netdev_info(netdev, "Set phy config failed with error %d.\n",
658 status);
659 return -EAGAIN;
660 }
661
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000662 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000663 if (status)
664 netdev_info(netdev, "Updating link info failed with error %d\n",
665 status);
666
667 } else {
668 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
669 }
670
671 return err;
672}
673
Jesse Brandeburga6599722014-06-04 08:45:25 +0000674static int i40e_nway_reset(struct net_device *netdev)
675{
676 /* restart autonegotiation */
677 struct i40e_netdev_priv *np = netdev_priv(netdev);
678 struct i40e_pf *pf = np->vsi->back;
679 struct i40e_hw *hw = &pf->hw;
680 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
681 i40e_status ret = 0;
682
683 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
684 if (ret) {
685 netdev_info(netdev, "link restart failed, aq_err=%d\n",
686 pf->hw.aq.asq_last_status);
687 return -EIO;
688 }
689
690 return 0;
691}
692
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000693/**
694 * i40e_get_pauseparam - Get Flow Control status
695 * Return tx/rx-pause status
696 **/
697static void i40e_get_pauseparam(struct net_device *netdev,
698 struct ethtool_pauseparam *pause)
699{
700 struct i40e_netdev_priv *np = netdev_priv(netdev);
701 struct i40e_pf *pf = np->vsi->back;
702 struct i40e_hw *hw = &pf->hw;
703 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000704 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000705
706 pause->autoneg =
707 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
708 AUTONEG_ENABLE : AUTONEG_DISABLE);
709
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000710 /* PFC enabled so report LFC as off */
711 if (dcbx_cfg->pfc.pfcenable) {
712 pause->rx_pause = 0;
713 pause->tx_pause = 0;
714 return;
715 }
716
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000717 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000718 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000719 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000720 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000721 } else if (hw->fc.current_mode == I40E_FC_FULL) {
722 pause->rx_pause = 1;
723 pause->tx_pause = 1;
724 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000725}
726
Catherine Sullivan2becc352014-06-04 08:45:27 +0000727/**
728 * i40e_set_pauseparam - Set Flow Control parameter
729 * @netdev: network interface device structure
730 * @pause: return tx/rx flow control status
731 **/
732static int i40e_set_pauseparam(struct net_device *netdev,
733 struct ethtool_pauseparam *pause)
734{
735 struct i40e_netdev_priv *np = netdev_priv(netdev);
736 struct i40e_pf *pf = np->vsi->back;
737 struct i40e_vsi *vsi = np->vsi;
738 struct i40e_hw *hw = &pf->hw;
739 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000740 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000741 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
742 i40e_status status;
743 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000744 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000745
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000746 /* Changing the port's flow control is not supported if this isn't the
747 * port's controlling PF
748 */
749 if (hw->partition_id != 1) {
750 i40e_partition_setting_complaint(pf);
751 return -EOPNOTSUPP;
752 }
753
Catherine Sullivan2becc352014-06-04 08:45:27 +0000754 if (vsi != pf->vsi[pf->lan_vsi])
755 return -EOPNOTSUPP;
756
757 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
758 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
759 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
760 return -EOPNOTSUPP;
761 }
762
763 /* If we have link and don't have autoneg */
764 if (!test_bit(__I40E_DOWN, &pf->state) &&
765 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
766 /* Send message that it might not necessarily work*/
767 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
768 }
769
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000770 if (dcbx_cfg->pfc.pfcenable) {
771 netdev_info(netdev,
772 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000773 return -EOPNOTSUPP;
774 }
775
776 if (pause->rx_pause && pause->tx_pause)
777 hw->fc.requested_mode = I40E_FC_FULL;
778 else if (pause->rx_pause && !pause->tx_pause)
779 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
780 else if (!pause->rx_pause && pause->tx_pause)
781 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
782 else if (!pause->rx_pause && !pause->tx_pause)
783 hw->fc.requested_mode = I40E_FC_NONE;
784 else
785 return -EINVAL;
786
Catherine Sullivan94128512014-07-12 07:28:16 +0000787 /* Tell the OS link is going down, the link will go back up when fw
788 * says it is ready asynchronously
789 */
790 netdev_info(netdev, "Flow control settings change requested, NIC Link is going down.\n");
791 netif_carrier_off(netdev);
792 netif_tx_stop_all_queues(netdev);
793
Catherine Sullivan2becc352014-06-04 08:45:27 +0000794 /* Set the fc mode and only restart an if link is up*/
795 status = i40e_set_fc(hw, &aq_failures, link_up);
796
797 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
798 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n",
799 status, hw->aq.asq_last_status);
800 err = -EAGAIN;
801 }
802 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
803 netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n",
804 status, hw->aq.asq_last_status);
805 err = -EAGAIN;
806 }
807 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Catherine Sullivan21af70f2015-01-24 09:58:41 +0000808 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 +0000809 status, hw->aq.asq_last_status);
810 err = -EAGAIN;
811 }
812
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000813 if (!test_bit(__I40E_DOWN, &pf->state)) {
814 /* Give it a little more time to try to come back */
815 msleep(75);
816 if (!test_bit(__I40E_DOWN, &pf->state))
817 return i40e_nway_reset(netdev);
818 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000819
820 return err;
821}
822
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000823static u32 i40e_get_msglevel(struct net_device *netdev)
824{
825 struct i40e_netdev_priv *np = netdev_priv(netdev);
826 struct i40e_pf *pf = np->vsi->back;
827
828 return pf->msg_enable;
829}
830
831static void i40e_set_msglevel(struct net_device *netdev, u32 data)
832{
833 struct i40e_netdev_priv *np = netdev_priv(netdev);
834 struct i40e_pf *pf = np->vsi->back;
835
836 if (I40E_DEBUG_USER & data)
837 pf->hw.debug_mask = data;
838 pf->msg_enable = data;
839}
840
841static int i40e_get_regs_len(struct net_device *netdev)
842{
843 int reg_count = 0;
844 int i;
845
846 for (i = 0; i40e_reg_list[i].offset != 0; i++)
847 reg_count += i40e_reg_list[i].elements;
848
849 return reg_count * sizeof(u32);
850}
851
852static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
853 void *p)
854{
855 struct i40e_netdev_priv *np = netdev_priv(netdev);
856 struct i40e_pf *pf = np->vsi->back;
857 struct i40e_hw *hw = &pf->hw;
858 u32 *reg_buf = p;
859 int i, j, ri;
860 u32 reg;
861
862 /* Tell ethtool which driver-version-specific regs output we have.
863 *
864 * At some point, if we have ethtool doing special formatting of
865 * this data, it will rely on this version number to know how to
866 * interpret things. Hence, this needs to be updated if/when the
867 * diags register table is changed.
868 */
869 regs->version = 1;
870
871 /* loop through the diags reg table for what to print */
872 ri = 0;
873 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
874 for (j = 0; j < i40e_reg_list[i].elements; j++) {
875 reg = i40e_reg_list[i].offset
876 + (j * i40e_reg_list[i].stride);
877 reg_buf[ri++] = rd32(hw, reg);
878 }
879 }
880
881}
882
883static int i40e_get_eeprom(struct net_device *netdev,
884 struct ethtool_eeprom *eeprom, u8 *bytes)
885{
886 struct i40e_netdev_priv *np = netdev_priv(netdev);
887 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000888 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000889 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000890 u8 *eeprom_buff;
891 u16 i, sectors;
892 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000893 u32 magic;
894
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000895#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000896 if (eeprom->len == 0)
897 return -EINVAL;
898
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000899 /* check for NVMUpdate access method */
900 magic = hw->vendor_id | (hw->device_id << 16);
901 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000902 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000903 int errno;
904
905 /* make sure it is the right magic for NVMUpdate */
906 if ((eeprom->magic >> 16) != hw->device_id)
907 return -EINVAL;
908
Shannon Nelsonc150a502014-11-13 08:23:13 +0000909 cmd = (struct i40e_nvm_access *)eeprom;
910 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000911 if (ret_val)
912 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000913 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
914 ret_val, hw->aq.asq_last_status, errno,
915 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
916 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000917
918 return errno;
919 }
920
921 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000922 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
923
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000924 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000925 if (!eeprom_buff)
926 return -ENOMEM;
927
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000928 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
929 if (ret_val) {
930 dev_info(&pf->pdev->dev,
931 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
932 ret_val, hw->aq.asq_last_status);
933 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000934 }
935
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000936 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
937 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
938 len = I40E_NVM_SECTOR_SIZE;
939 last = false;
940 for (i = 0; i < sectors; i++) {
941 if (i == (sectors - 1)) {
942 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
943 last = true;
944 }
Shannon Nelsonc150a502014-11-13 08:23:13 +0000945 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
946 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000947 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000948 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +0000949 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000950 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000951 "read NVM failed, invalid offset 0x%x\n",
952 offset);
953 break;
954 } else if (ret_val &&
955 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
956 dev_info(&pf->pdev->dev,
957 "read NVM failed, access, offset 0x%x\n",
958 offset);
959 break;
960 } else if (ret_val) {
961 dev_info(&pf->pdev->dev,
962 "read NVM failed offset %d err=%d status=0x%x\n",
963 offset, ret_val, hw->aq.asq_last_status);
964 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000965 }
966 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000967
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000968 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000969 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000970free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000971 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000972 return ret_val;
973}
974
975static int i40e_get_eeprom_len(struct net_device *netdev)
976{
977 struct i40e_netdev_priv *np = netdev_priv(netdev);
978 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000979 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000980
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000981 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
982 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
983 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
984 /* register returns value in power of 2, 64Kbyte chunks. */
985 val = (64 * 1024) * (1 << val);
986 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000987}
988
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000989static int i40e_set_eeprom(struct net_device *netdev,
990 struct ethtool_eeprom *eeprom, u8 *bytes)
991{
992 struct i40e_netdev_priv *np = netdev_priv(netdev);
993 struct i40e_hw *hw = &np->vsi->back->hw;
994 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000995 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000996 int ret_val = 0;
997 int errno;
998 u32 magic;
999
1000 /* normal ethtool set_eeprom is not supported */
1001 magic = hw->vendor_id | (hw->device_id << 16);
1002 if (eeprom->magic == magic)
1003 return -EOPNOTSUPP;
1004
1005 /* check for NVMUpdate access method */
1006 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1007 return -EINVAL;
1008
1009 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1010 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1011 return -EBUSY;
1012
Shannon Nelsonc150a502014-11-13 08:23:13 +00001013 cmd = (struct i40e_nvm_access *)eeprom;
1014 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
1015 if (ret_val && hw->aq.asq_last_status != I40E_AQ_RC_EBUSY)
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001016 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001017 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1018 ret_val, hw->aq.asq_last_status, errno,
1019 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1020 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001021
1022 return errno;
1023}
1024
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001025static void i40e_get_drvinfo(struct net_device *netdev,
1026 struct ethtool_drvinfo *drvinfo)
1027{
1028 struct i40e_netdev_priv *np = netdev_priv(netdev);
1029 struct i40e_vsi *vsi = np->vsi;
1030 struct i40e_pf *pf = vsi->back;
1031
1032 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1033 strlcpy(drvinfo->version, i40e_driver_version_str,
1034 sizeof(drvinfo->version));
1035 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1036 sizeof(drvinfo->fw_version));
1037 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1038 sizeof(drvinfo->bus_info));
1039}
1040
1041static void i40e_get_ringparam(struct net_device *netdev,
1042 struct ethtool_ringparam *ring)
1043{
1044 struct i40e_netdev_priv *np = netdev_priv(netdev);
1045 struct i40e_pf *pf = np->vsi->back;
1046 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1047
1048 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1049 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1050 ring->rx_mini_max_pending = 0;
1051 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001052 ring->rx_pending = vsi->rx_rings[0]->count;
1053 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001054 ring->rx_mini_pending = 0;
1055 ring->rx_jumbo_pending = 0;
1056}
1057
1058static int i40e_set_ringparam(struct net_device *netdev,
1059 struct ethtool_ringparam *ring)
1060{
1061 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1062 struct i40e_netdev_priv *np = netdev_priv(netdev);
1063 struct i40e_vsi *vsi = np->vsi;
1064 struct i40e_pf *pf = vsi->back;
1065 u32 new_rx_count, new_tx_count;
1066 int i, err = 0;
1067
1068 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1069 return -EINVAL;
1070
Shannon Nelson1fa18372013-11-20 10:03:08 +00001071 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1072 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1073 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1074 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1075 netdev_info(netdev,
1076 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1077 ring->tx_pending, ring->rx_pending,
1078 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1079 return -EINVAL;
1080 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001081
Shannon Nelson1fa18372013-11-20 10:03:08 +00001082 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1083 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001084
1085 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001086 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1087 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001088 return 0;
1089
1090 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1091 usleep_range(1000, 2000);
1092
1093 if (!netif_running(vsi->netdev)) {
1094 /* simple case - set for the next time the netdev is started */
1095 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001096 vsi->tx_rings[i]->count = new_tx_count;
1097 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001098 }
1099 goto done;
1100 }
1101
1102 /* We can't just free everything and then setup again,
1103 * because the ISRs in MSI-X mode get passed pointers
1104 * to the Tx and Rx ring structs.
1105 */
1106
1107 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001108 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001109 netdev_info(netdev,
1110 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001111 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001112 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1113 sizeof(struct i40e_ring), GFP_KERNEL);
1114 if (!tx_rings) {
1115 err = -ENOMEM;
1116 goto done;
1117 }
1118
1119 for (i = 0; i < vsi->num_queue_pairs; i++) {
1120 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001121 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001122 tx_rings[i].count = new_tx_count;
1123 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1124 if (err) {
1125 while (i) {
1126 i--;
1127 i40e_free_tx_resources(&tx_rings[i]);
1128 }
1129 kfree(tx_rings);
1130 tx_rings = NULL;
1131
1132 goto done;
1133 }
1134 }
1135 }
1136
1137 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001138 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001139 netdev_info(netdev,
1140 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001141 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001142 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1143 sizeof(struct i40e_ring), GFP_KERNEL);
1144 if (!rx_rings) {
1145 err = -ENOMEM;
1146 goto free_tx;
1147 }
1148
1149 for (i = 0; i < vsi->num_queue_pairs; i++) {
1150 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001151 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001152 rx_rings[i].count = new_rx_count;
1153 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1154 if (err) {
1155 while (i) {
1156 i--;
1157 i40e_free_rx_resources(&rx_rings[i]);
1158 }
1159 kfree(rx_rings);
1160 rx_rings = NULL;
1161
1162 goto free_tx;
1163 }
1164 }
1165 }
1166
1167 /* Bring interface down, copy in the new ring info,
1168 * then restore the interface
1169 */
1170 i40e_down(vsi);
1171
1172 if (tx_rings) {
1173 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001174 i40e_free_tx_resources(vsi->tx_rings[i]);
1175 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001176 }
1177 kfree(tx_rings);
1178 tx_rings = NULL;
1179 }
1180
1181 if (rx_rings) {
1182 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001183 i40e_free_rx_resources(vsi->rx_rings[i]);
1184 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001185 }
1186 kfree(rx_rings);
1187 rx_rings = NULL;
1188 }
1189
1190 i40e_up(vsi);
1191
1192free_tx:
1193 /* error cleanup if the Rx allocations failed after getting Tx */
1194 if (tx_rings) {
1195 for (i = 0; i < vsi->num_queue_pairs; i++)
1196 i40e_free_tx_resources(&tx_rings[i]);
1197 kfree(tx_rings);
1198 tx_rings = NULL;
1199 }
1200
1201done:
1202 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1203
1204 return err;
1205}
1206
1207static int i40e_get_sset_count(struct net_device *netdev, int sset)
1208{
1209 struct i40e_netdev_priv *np = netdev_priv(netdev);
1210 struct i40e_vsi *vsi = np->vsi;
1211 struct i40e_pf *pf = vsi->back;
1212
1213 switch (sset) {
1214 case ETH_SS_TEST:
1215 return I40E_TEST_LEN;
1216 case ETH_SS_STATS:
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001217 if (vsi == pf->vsi[pf->lan_vsi]) {
1218 int len = I40E_PF_STATS_LEN(netdev);
1219
1220 if (pf->lan_veb != I40E_NO_VEB)
1221 len += I40E_VEB_STATS_LEN;
1222 return len;
1223 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001224 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001225 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001226 default:
1227 return -EOPNOTSUPP;
1228 }
1229}
1230
1231static void i40e_get_ethtool_stats(struct net_device *netdev,
1232 struct ethtool_stats *stats, u64 *data)
1233{
1234 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001235 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001236 struct i40e_vsi *vsi = np->vsi;
1237 struct i40e_pf *pf = vsi->back;
1238 int i = 0;
1239 char *p;
1240 int j;
1241 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001242 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001243
1244 i40e_update_stats(vsi);
1245
1246 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1247 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1248 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1249 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1250 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001251 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1252 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1253 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1254 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1255 }
Vasu Dev38e00432014-08-01 13:27:03 -07001256#ifdef I40E_FCOE
1257 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1258 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1259 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1260 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1261 }
1262#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001263 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001264 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001265 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001266
1267 if (!tx_ring)
1268 continue;
1269
1270 /* process Tx ring statistics */
1271 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001272 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001273 data[i] = tx_ring->stats.packets;
1274 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001275 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001276 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001277
1278 /* Rx ring is the 2nd half of the queue pair */
1279 rx_ring = &tx_ring[1];
1280 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001281 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001282 data[i] = rx_ring->stats.packets;
1283 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001284 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001285 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001286 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001287 rcu_read_unlock();
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001288 if (vsi != pf->vsi[pf->lan_vsi])
1289 return;
1290
1291 if (pf->lan_veb != I40E_NO_VEB) {
1292 struct i40e_veb *veb = pf->veb[pf->lan_veb];
1293 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1294 p = (char *)veb;
1295 p += i40e_gstrings_veb_stats[j].stat_offset;
1296 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1297 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001298 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001299 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001300 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1301 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1302 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1303 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1304 }
1305 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1306 data[i++] = pf->stats.priority_xon_tx[j];
1307 data[i++] = pf->stats.priority_xoff_tx[j];
1308 }
1309 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1310 data[i++] = pf->stats.priority_xon_rx[j];
1311 data[i++] = pf->stats.priority_xoff_rx[j];
1312 }
1313 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1314 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001315}
1316
1317static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1318 u8 *data)
1319{
1320 struct i40e_netdev_priv *np = netdev_priv(netdev);
1321 struct i40e_vsi *vsi = np->vsi;
1322 struct i40e_pf *pf = vsi->back;
1323 char *p = (char *)data;
1324 int i;
1325
1326 switch (stringset) {
1327 case ETH_SS_TEST:
1328 for (i = 0; i < I40E_TEST_LEN; i++) {
1329 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1330 data += ETH_GSTRING_LEN;
1331 }
1332 break;
1333 case ETH_SS_STATS:
1334 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1335 snprintf(p, ETH_GSTRING_LEN, "%s",
1336 i40e_gstrings_net_stats[i].stat_string);
1337 p += ETH_GSTRING_LEN;
1338 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001339 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1340 snprintf(p, ETH_GSTRING_LEN, "%s",
1341 i40e_gstrings_misc_stats[i].stat_string);
1342 p += ETH_GSTRING_LEN;
1343 }
Vasu Dev38e00432014-08-01 13:27:03 -07001344#ifdef I40E_FCOE
1345 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1346 snprintf(p, ETH_GSTRING_LEN, "%s",
1347 i40e_gstrings_fcoe_stats[i].stat_string);
1348 p += ETH_GSTRING_LEN;
1349 }
1350#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001351 for (i = 0; i < vsi->num_queue_pairs; i++) {
1352 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1353 p += ETH_GSTRING_LEN;
1354 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1355 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001356 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1357 p += ETH_GSTRING_LEN;
1358 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1359 p += ETH_GSTRING_LEN;
1360 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001361 if (vsi != pf->vsi[pf->lan_vsi])
1362 return;
1363
1364 if (pf->lan_veb != I40E_NO_VEB) {
1365 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1366 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1367 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001368 p += ETH_GSTRING_LEN;
1369 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001370 }
1371 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1372 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1373 i40e_gstrings_stats[i].stat_string);
1374 p += ETH_GSTRING_LEN;
1375 }
1376 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1377 snprintf(p, ETH_GSTRING_LEN,
1378 "port.tx_priority_%u_xon", i);
1379 p += ETH_GSTRING_LEN;
1380 snprintf(p, ETH_GSTRING_LEN,
1381 "port.tx_priority_%u_xoff", i);
1382 p += ETH_GSTRING_LEN;
1383 }
1384 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1385 snprintf(p, ETH_GSTRING_LEN,
1386 "port.rx_priority_%u_xon", i);
1387 p += ETH_GSTRING_LEN;
1388 snprintf(p, ETH_GSTRING_LEN,
1389 "port.rx_priority_%u_xoff", i);
1390 p += ETH_GSTRING_LEN;
1391 }
1392 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1393 snprintf(p, ETH_GSTRING_LEN,
1394 "port.rx_priority_%u_xon_2_xoff", i);
1395 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001396 }
1397 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1398 break;
1399 }
1400}
1401
1402static int i40e_get_ts_info(struct net_device *dev,
1403 struct ethtool_ts_info *info)
1404{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001405 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1406
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001407 /* only report HW timestamping if PTP is enabled */
1408 if (!(pf->flags & I40E_FLAG_PTP))
1409 return ethtool_op_get_ts_info(dev, info);
1410
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001411 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1412 SOF_TIMESTAMPING_RX_SOFTWARE |
1413 SOF_TIMESTAMPING_SOFTWARE |
1414 SOF_TIMESTAMPING_TX_HARDWARE |
1415 SOF_TIMESTAMPING_RX_HARDWARE |
1416 SOF_TIMESTAMPING_RAW_HARDWARE;
1417
1418 if (pf->ptp_clock)
1419 info->phc_index = ptp_clock_index(pf->ptp_clock);
1420 else
1421 info->phc_index = -1;
1422
1423 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1424
1425 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1426 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1427 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1428 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1429 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1430 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1431 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1432 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1433 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1434 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1435 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
1436 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1437
1438 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001439}
1440
Shannon Nelson7b086392013-11-20 10:02:59 +00001441static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001442{
Shannon Nelson7b086392013-11-20 10:02:59 +00001443 struct i40e_netdev_priv *np = netdev_priv(netdev);
1444 struct i40e_pf *pf = np->vsi->back;
1445
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001446 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001447 if (i40e_get_link_status(&pf->hw))
1448 *data = 0;
1449 else
1450 *data = 1;
1451
1452 return *data;
1453}
1454
Shannon Nelson7b086392013-11-20 10:02:59 +00001455static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456{
Shannon Nelson7b086392013-11-20 10:02:59 +00001457 struct i40e_netdev_priv *np = netdev_priv(netdev);
1458 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001459
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001460 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001461 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001462
Shannon Nelson7b086392013-11-20 10:02:59 +00001463 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001464}
1465
Shannon Nelson7b086392013-11-20 10:02:59 +00001466static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001467{
Shannon Nelson7b086392013-11-20 10:02:59 +00001468 struct i40e_netdev_priv *np = netdev_priv(netdev);
1469 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001470
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001471 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001472 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001473
Shannon Nelson4443ec92014-11-13 08:23:12 +00001474 /* forcebly clear the NVM Update state machine */
1475 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1476
Shannon Nelson7b086392013-11-20 10:02:59 +00001477 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478}
1479
Shannon Nelson7b086392013-11-20 10:02:59 +00001480static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001481{
Shannon Nelson7b086392013-11-20 10:02:59 +00001482 struct i40e_netdev_priv *np = netdev_priv(netdev);
1483 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001484 u16 swc_old = pf->sw_int_count;
1485
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001486 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001487 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1488 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001489 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1490 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1491 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1492 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001493 usleep_range(1000, 2000);
1494 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495
1496 return *data;
1497}
1498
Shannon Nelson7b086392013-11-20 10:02:59 +00001499static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001501 struct i40e_netdev_priv *np = netdev_priv(netdev);
1502 struct i40e_pf *pf = np->vsi->back;
1503
1504 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001505 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506
1507 return *data;
1508}
1509
1510static void i40e_diag_test(struct net_device *netdev,
1511 struct ethtool_test *eth_test, u64 *data)
1512{
1513 struct i40e_netdev_priv *np = netdev_priv(netdev);
1514 struct i40e_pf *pf = np->vsi->back;
1515
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1517 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001518 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001519
Shannon Nelsonf551b432013-11-26 10:49:12 +00001520 set_bit(__I40E_TESTING, &pf->state);
1521
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522 /* Link test performed before hardware reset
1523 * so autoneg doesn't interfere with test result
1524 */
Shannon Nelson7b086392013-11-20 10:02:59 +00001525 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001526 eth_test->flags |= ETH_TEST_FL_FAILED;
1527
Shannon Nelson7b086392013-11-20 10:02:59 +00001528 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001529 eth_test->flags |= ETH_TEST_FL_FAILED;
1530
Shannon Nelson7b086392013-11-20 10:02:59 +00001531 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001532 eth_test->flags |= ETH_TEST_FL_FAILED;
1533
Shannon Nelson7b086392013-11-20 10:02:59 +00001534 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001535 eth_test->flags |= ETH_TEST_FL_FAILED;
1536
Shannon Nelsonf551b432013-11-26 10:49:12 +00001537 /* run reg test last, a reset is required after it */
1538 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1539 eth_test->flags |= ETH_TEST_FL_FAILED;
1540
1541 clear_bit(__I40E_TESTING, &pf->state);
1542 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001544 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001545 netif_info(pf, drv, netdev, "online testing starting\n");
1546
Shannon Nelson7b086392013-11-20 10:02:59 +00001547 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 eth_test->flags |= ETH_TEST_FL_FAILED;
1549
1550 /* Offline only tests, not run in online; pass by default */
1551 data[I40E_ETH_TEST_REG] = 0;
1552 data[I40E_ETH_TEST_EEPROM] = 0;
1553 data[I40E_ETH_TEST_INTR] = 0;
1554 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001556
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001557 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558}
1559
1560static void i40e_get_wol(struct net_device *netdev,
1561 struct ethtool_wolinfo *wol)
1562{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001563 struct i40e_netdev_priv *np = netdev_priv(netdev);
1564 struct i40e_pf *pf = np->vsi->back;
1565 struct i40e_hw *hw = &pf->hw;
1566 u16 wol_nvm_bits;
1567
1568 /* NVM bit on means WoL disabled for the port */
1569 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001570 if ((1 << hw->port) & wol_nvm_bits || hw->partition_id != 1) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001571 wol->supported = 0;
1572 wol->wolopts = 0;
1573 } else {
1574 wol->supported = WAKE_MAGIC;
1575 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1576 }
1577}
1578
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001579/**
1580 * i40e_set_wol - set the WakeOnLAN configuration
1581 * @netdev: the netdev in question
1582 * @wol: the ethtool WoL setting data
1583 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001584static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1585{
1586 struct i40e_netdev_priv *np = netdev_priv(netdev);
1587 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001588 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001589 struct i40e_hw *hw = &pf->hw;
1590 u16 wol_nvm_bits;
1591
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001592 /* WoL not supported if this isn't the controlling PF on the port */
1593 if (hw->partition_id != 1) {
1594 i40e_partition_setting_complaint(pf);
1595 return -EOPNOTSUPP;
1596 }
1597
1598 if (vsi != pf->vsi[pf->lan_vsi])
1599 return -EOPNOTSUPP;
1600
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001601 /* NVM bit on means WoL disabled for the port */
1602 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
1603 if (((1 << hw->port) & wol_nvm_bits))
1604 return -EOPNOTSUPP;
1605
1606 /* only magic packet is supported */
1607 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1608 return -EOPNOTSUPP;
1609
1610 /* is this a new value? */
1611 if (pf->wol_en != !!wol->wolopts) {
1612 pf->wol_en = !!wol->wolopts;
1613 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1614 }
1615
1616 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001617}
1618
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619static int i40e_set_phys_id(struct net_device *netdev,
1620 enum ethtool_phys_id_state state)
1621{
1622 struct i40e_netdev_priv *np = netdev_priv(netdev);
1623 struct i40e_pf *pf = np->vsi->back;
1624 struct i40e_hw *hw = &pf->hw;
1625 int blink_freq = 2;
1626
1627 switch (state) {
1628 case ETHTOOL_ID_ACTIVE:
1629 pf->led_status = i40e_led_get(hw);
1630 return blink_freq;
1631 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001632 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633 break;
1634 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001635 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001636 break;
1637 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001638 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001639 break;
1640 }
1641
1642 return 0;
1643}
1644
1645/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1646 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1647 * 125us (8000 interrupts per second) == ITR(62)
1648 */
1649
1650static int i40e_get_coalesce(struct net_device *netdev,
1651 struct ethtool_coalesce *ec)
1652{
1653 struct i40e_netdev_priv *np = netdev_priv(netdev);
1654 struct i40e_vsi *vsi = np->vsi;
1655
1656 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1657 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1658
1659 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001660 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001661
1662 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001663 ec->use_adaptive_tx_coalesce = 1;
1664
1665 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1666 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667
1668 return 0;
1669}
1670
1671static int i40e_set_coalesce(struct net_device *netdev,
1672 struct ethtool_coalesce *ec)
1673{
1674 struct i40e_netdev_priv *np = netdev_priv(netdev);
1675 struct i40e_q_vector *q_vector;
1676 struct i40e_vsi *vsi = np->vsi;
1677 struct i40e_pf *pf = vsi->back;
1678 struct i40e_hw *hw = &pf->hw;
1679 u16 vector;
1680 int i;
1681
1682 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1683 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1684
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001685 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001686 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001687 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001688 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001689 } else if (ec->rx_coalesce_usecs == 0) {
1690 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001691 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001692 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 +00001693 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001694 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001695 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001696 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697
Mitch Williams32f5f542014-04-04 04:43:10 +00001698 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001699 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001700 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001701 } else if (ec->tx_coalesce_usecs == 0) {
1702 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001703 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001704 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 +00001705 } else {
1706 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001707 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001708 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001709 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001710
1711 if (ec->use_adaptive_rx_coalesce)
1712 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1713 else
1714 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1715
1716 if (ec->use_adaptive_tx_coalesce)
1717 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1718 else
1719 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001720
Alexander Duyck493fb302013-09-28 07:01:44 +00001721 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1722 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001723 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1724 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1725 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1726 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1727 i40e_flush(hw);
1728 }
1729
1730 return 0;
1731}
1732
1733/**
1734 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1735 * @pf: pointer to the physical function struct
1736 * @cmd: ethtool rxnfc command
1737 *
1738 * Returns Success if the flow is supported, else Invalid Input.
1739 **/
1740static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1741{
1742 cmd->data = 0;
1743
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001744 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1745 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1746 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1747 return 0;
1748 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001749 /* Report default options for RSS on i40e */
1750 switch (cmd->flow_type) {
1751 case TCP_V4_FLOW:
1752 case UDP_V4_FLOW:
1753 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1754 /* fall through to add IP fields */
1755 case SCTP_V4_FLOW:
1756 case AH_ESP_V4_FLOW:
1757 case AH_V4_FLOW:
1758 case ESP_V4_FLOW:
1759 case IPV4_FLOW:
1760 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1761 break;
1762 case TCP_V6_FLOW:
1763 case UDP_V6_FLOW:
1764 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1765 /* fall through to add IP fields */
1766 case SCTP_V6_FLOW:
1767 case AH_ESP_V6_FLOW:
1768 case AH_V6_FLOW:
1769 case ESP_V6_FLOW:
1770 case IPV6_FLOW:
1771 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1772 break;
1773 default:
1774 return -EINVAL;
1775 }
1776
1777 return 0;
1778}
1779
1780/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001781 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1782 * @pf: Pointer to the physical function struct
1783 * @cmd: The command to get or set Rx flow classification rules
1784 * @rule_locs: Array of used rule locations
1785 *
1786 * This function populates both the total and actual rule count of
1787 * the ethtool flow classification command
1788 *
1789 * Returns 0 on success or -EMSGSIZE if entry not found
1790 **/
1791static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1792 struct ethtool_rxnfc *cmd,
1793 u32 *rule_locs)
1794{
1795 struct i40e_fdir_filter *rule;
1796 struct hlist_node *node2;
1797 int cnt = 0;
1798
1799 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001800 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001801
1802 hlist_for_each_entry_safe(rule, node2,
1803 &pf->fdir_filter_list, fdir_node) {
1804 if (cnt == cmd->rule_cnt)
1805 return -EMSGSIZE;
1806
1807 rule_locs[cnt] = rule->fd_id;
1808 cnt++;
1809 }
1810
1811 cmd->rule_cnt = cnt;
1812
1813 return 0;
1814}
1815
1816/**
1817 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1818 * @pf: Pointer to the physical function struct
1819 * @cmd: The command to get or set Rx flow classification rules
1820 *
1821 * This function looks up a filter based on the Rx flow classification
1822 * command and fills the flow spec info for it if found
1823 *
1824 * Returns 0 on success or -EINVAL if filter not found
1825 **/
1826static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1827 struct ethtool_rxnfc *cmd)
1828{
1829 struct ethtool_rx_flow_spec *fsp =
1830 (struct ethtool_rx_flow_spec *)&cmd->fs;
1831 struct i40e_fdir_filter *rule = NULL;
1832 struct hlist_node *node2;
1833
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001834 hlist_for_each_entry_safe(rule, node2,
1835 &pf->fdir_filter_list, fdir_node) {
1836 if (fsp->location <= rule->fd_id)
1837 break;
1838 }
1839
1840 if (!rule || fsp->location != rule->fd_id)
1841 return -EINVAL;
1842
1843 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00001844 if (fsp->flow_type == IP_USER_FLOW) {
1845 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1846 fsp->h_u.usr_ip4_spec.proto = 0;
1847 fsp->m_u.usr_ip4_spec.proto = 0;
1848 }
1849
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00001850 /* Reverse the src and dest notion, since the HW views them from
1851 * Tx perspective where as the user expects it from Rx filter view.
1852 */
1853 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
1854 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
1855 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
1856 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00001857
1858 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
1859 fsp->ring_cookie = RX_CLS_FLOW_DISC;
1860 else
1861 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001862
1863 return 0;
1864}
1865
1866/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001867 * i40e_get_rxnfc - command to get RX flow classification rules
1868 * @netdev: network interface device structure
1869 * @cmd: ethtool rxnfc command
1870 *
1871 * Returns Success if the command is supported.
1872 **/
1873static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1874 u32 *rule_locs)
1875{
1876 struct i40e_netdev_priv *np = netdev_priv(netdev);
1877 struct i40e_vsi *vsi = np->vsi;
1878 struct i40e_pf *pf = vsi->back;
1879 int ret = -EOPNOTSUPP;
1880
1881 switch (cmd->cmd) {
1882 case ETHTOOL_GRXRINGS:
1883 cmd->data = vsi->alloc_queue_pairs;
1884 ret = 0;
1885 break;
1886 case ETHTOOL_GRXFH:
1887 ret = i40e_get_rss_hash_opts(pf, cmd);
1888 break;
1889 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001890 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001891 /* report total rule count */
1892 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001893 ret = 0;
1894 break;
1895 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001896 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001897 break;
1898 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001899 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1900 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001901 default:
1902 break;
1903 }
1904
1905 return ret;
1906}
1907
1908/**
1909 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1910 * @pf: pointer to the physical function struct
1911 * @cmd: ethtool rxnfc command
1912 *
1913 * Returns Success if the flow input set is supported.
1914 **/
1915static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1916{
1917 struct i40e_hw *hw = &pf->hw;
1918 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1919 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1920
1921 /* RSS does not support anything other than hashing
1922 * to queues on src and dst IPs and ports
1923 */
1924 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1925 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1926 return -EINVAL;
1927
1928 /* We need at least the IP SRC and DEST fields for hashing */
1929 if (!(nfc->data & RXH_IP_SRC) ||
1930 !(nfc->data & RXH_IP_DST))
1931 return -EINVAL;
1932
1933 switch (nfc->flow_type) {
1934 case TCP_V4_FLOW:
1935 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1936 case 0:
1937 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1938 break;
1939 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1940 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1941 break;
1942 default:
1943 return -EINVAL;
1944 }
1945 break;
1946 case TCP_V6_FLOW:
1947 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1948 case 0:
1949 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1950 break;
1951 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1952 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1953 break;
1954 default:
1955 return -EINVAL;
1956 }
1957 break;
1958 case UDP_V4_FLOW:
1959 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1960 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001961 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1962 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001963 break;
1964 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001965 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1966 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001967 break;
1968 default:
1969 return -EINVAL;
1970 }
1971 break;
1972 case UDP_V6_FLOW:
1973 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1974 case 0:
Kevin Scottb2d36c02014-04-09 05:58:59 +00001975 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1976 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001977 break;
1978 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Kevin Scottb2d36c02014-04-09 05:58:59 +00001979 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1980 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001981 break;
1982 default:
1983 return -EINVAL;
1984 }
1985 break;
1986 case AH_ESP_V4_FLOW:
1987 case AH_V4_FLOW:
1988 case ESP_V4_FLOW:
1989 case SCTP_V4_FLOW:
1990 if ((nfc->data & RXH_L4_B_0_1) ||
1991 (nfc->data & RXH_L4_B_2_3))
1992 return -EINVAL;
1993 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1994 break;
1995 case AH_ESP_V6_FLOW:
1996 case AH_V6_FLOW:
1997 case ESP_V6_FLOW:
1998 case SCTP_V6_FLOW:
1999 if ((nfc->data & RXH_L4_B_0_1) ||
2000 (nfc->data & RXH_L4_B_2_3))
2001 return -EINVAL;
2002 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
2003 break;
2004 case IPV4_FLOW:
2005 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2006 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
2007 break;
2008 case IPV6_FLOW:
2009 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2010 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
2011 break;
2012 default:
2013 return -EINVAL;
2014 }
2015
2016 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2017 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2018 i40e_flush(hw);
2019
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002020 /* Save setting for future output/update */
2021 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2022
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002023 return 0;
2024}
2025
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002026/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002027 * i40e_match_fdir_input_set - Match a new filter against an existing one
2028 * @rule: The filter already added
2029 * @input: The new filter to comapre against
2030 *
2031 * Returns true if the two input set match
2032 **/
2033static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2034 struct i40e_fdir_filter *input)
2035{
2036 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2037 (rule->src_ip[0] != input->src_ip[0]) ||
2038 (rule->dst_port != input->dst_port) ||
2039 (rule->src_port != input->src_port))
2040 return false;
2041 return true;
2042}
2043
2044/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002045 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2046 * @vsi: Pointer to the targeted VSI
2047 * @input: The filter to update or NULL to indicate deletion
2048 * @sw_idx: Software index to the filter
2049 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002050 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002051 * This function updates (or deletes) a Flow Director entry from
2052 * the hlist of the corresponding PF
2053 *
2054 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002055 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002056static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2057 struct i40e_fdir_filter *input,
2058 u16 sw_idx,
2059 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002060{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002061 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002063 struct hlist_node *node2;
2064 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002065
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002066 parent = NULL;
2067 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002068
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002069 hlist_for_each_entry_safe(rule, node2,
2070 &pf->fdir_filter_list, fdir_node) {
2071 /* hash found, or no matching entry */
2072 if (rule->fd_id >= sw_idx)
2073 break;
2074 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002075 }
2076
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002077 /* if there is an old rule occupying our place remove it */
2078 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002079 if (input && !i40e_match_fdir_input_set(rule, input))
2080 err = i40e_add_del_fdir(vsi, rule, false);
2081 else if (!input)
2082 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002083 hlist_del(&rule->fdir_node);
2084 kfree(rule);
2085 pf->fdir_pf_active_filters--;
2086 }
2087
2088 /* If no input this was a delete, err should be 0 if a rule was
2089 * successfully found and removed from the list else -EINVAL
2090 */
2091 if (!input)
2092 return err;
2093
2094 /* initialize node and set software index */
2095 INIT_HLIST_NODE(&input->fdir_node);
2096
2097 /* add filter to the list */
2098 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002099 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002100 else
2101 hlist_add_head(&input->fdir_node,
2102 &pf->fdir_filter_list);
2103
2104 /* update counts */
2105 pf->fdir_pf_active_filters++;
2106
2107 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002108}
2109
2110/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002111 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2112 * @vsi: Pointer to the targeted VSI
2113 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002114 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002115 * The function removes a Flow Director filter entry from the
2116 * hlist of the corresponding PF
2117 *
2118 * Returns 0 on success
2119 */
2120static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2121 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002122{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002123 struct ethtool_rx_flow_spec *fsp =
2124 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002125 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002126 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002127
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002128 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2129 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2130 return -EBUSY;
2131
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002132 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2133 return -EBUSY;
2134
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002135 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002136
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002137 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002138 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002139}
2140
2141/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002142 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002143 * @vsi: pointer to the targeted VSI
2144 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002145 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002146 * Add Flow Director filters for a specific flow spec based on their
2147 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002148 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002149static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2150 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002151{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002152 struct ethtool_rx_flow_spec *fsp;
2153 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002154 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002155 int ret = -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002156
2157 if (!vsi)
2158 return -EINVAL;
2159
2160 pf = vsi->back;
2161
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002162 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2163 return -EOPNOTSUPP;
2164
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002165 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002166 return -ENOSPC;
2167
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002168 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2169 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2170 return -EBUSY;
2171
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002172 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2173 return -EBUSY;
2174
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002175 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2176
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002177 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2178 pf->hw.func_caps.fd_filters_guaranteed)) {
2179 return -EINVAL;
2180 }
2181
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002182 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2183 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 return -EINVAL;
2185
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002186 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002188 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002189 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002190
2191 input->fd_id = fsp->location;
2192
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002193 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2194 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2195 else
2196 input->dest_ctl =
2197 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2198
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002199 input->q_index = fsp->ring_cookie;
2200 input->flex_off = 0;
2201 input->pctype = 0;
2202 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002203 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +00002204 input->cnt_index = pf->fd_sb_cnt_idx;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002205 input->flow_type = fsp->flow_type;
2206 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002207
2208 /* Reverse the src and dest notion, since the HW expects them to be from
2209 * Tx perspective where as the input from user is from Rx filter view.
2210 */
2211 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2212 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2213 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2214 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002215
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002216 ret = i40e_add_del_fdir(vsi, input, true);
2217 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002218 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002219 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002220 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002221
2222 return ret;
2223}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002224
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225/**
2226 * i40e_set_rxnfc - command to set RX flow classification rules
2227 * @netdev: network interface device structure
2228 * @cmd: ethtool rxnfc command
2229 *
2230 * Returns Success if the command is supported.
2231 **/
2232static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2233{
2234 struct i40e_netdev_priv *np = netdev_priv(netdev);
2235 struct i40e_vsi *vsi = np->vsi;
2236 struct i40e_pf *pf = vsi->back;
2237 int ret = -EOPNOTSUPP;
2238
2239 switch (cmd->cmd) {
2240 case ETHTOOL_SRXFH:
2241 ret = i40e_set_rss_hash_opt(pf, cmd);
2242 break;
2243 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002244 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002245 break;
2246 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002247 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002248 break;
2249 default:
2250 break;
2251 }
2252
2253 return ret;
2254}
2255
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002256/**
2257 * i40e_max_channels - get Max number of combined channels supported
2258 * @vsi: vsi pointer
2259 **/
2260static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2261{
2262 /* TODO: This code assumes DCB and FD is disabled for now. */
2263 return vsi->alloc_queue_pairs;
2264}
2265
2266/**
2267 * i40e_get_channels - Get the current channels enabled and max supported etc.
2268 * @netdev: network interface device structure
2269 * @ch: ethtool channels structure
2270 *
2271 * We don't support separate tx and rx queues as channels. The other count
2272 * represents how many queues are being used for control. max_combined counts
2273 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2274 * q_vectors since we support a lot more queue pairs than q_vectors.
2275 **/
2276static void i40e_get_channels(struct net_device *dev,
2277 struct ethtool_channels *ch)
2278{
2279 struct i40e_netdev_priv *np = netdev_priv(dev);
2280 struct i40e_vsi *vsi = np->vsi;
2281 struct i40e_pf *pf = vsi->back;
2282
2283 /* report maximum channels */
2284 ch->max_combined = i40e_max_channels(vsi);
2285
2286 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002287 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002288 ch->max_other = ch->other_count;
2289
2290 /* Note: This code assumes DCB is disabled for now. */
2291 ch->combined_count = vsi->num_queue_pairs;
2292}
2293
2294/**
2295 * i40e_set_channels - Set the new channels count.
2296 * @netdev: network interface device structure
2297 * @ch: ethtool channels structure
2298 *
2299 * The new channels count may not be the same as requested by the user
2300 * since it gets rounded down to a power of 2 value.
2301 **/
2302static int i40e_set_channels(struct net_device *dev,
2303 struct ethtool_channels *ch)
2304{
2305 struct i40e_netdev_priv *np = netdev_priv(dev);
2306 unsigned int count = ch->combined_count;
2307 struct i40e_vsi *vsi = np->vsi;
2308 struct i40e_pf *pf = vsi->back;
2309 int new_count;
2310
2311 /* We do not support setting channels for any other VSI at present */
2312 if (vsi->type != I40E_VSI_MAIN)
2313 return -EINVAL;
2314
2315 /* verify they are not requesting separate vectors */
2316 if (!count || ch->rx_count || ch->tx_count)
2317 return -EINVAL;
2318
2319 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002320 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002321 return -EINVAL;
2322
2323 /* verify the number of channels does not exceed hardware limits */
2324 if (count > i40e_max_channels(vsi))
2325 return -EINVAL;
2326
2327 /* update feature limits from largest to smallest supported values */
2328 /* TODO: Flow director limit, DCB etc */
2329
2330 /* cap RSS limit */
2331 if (count > pf->rss_size_max)
2332 count = pf->rss_size_max;
2333
2334 /* use rss_reconfig to rebuild with new queue count and update traffic
2335 * class queue mapping
2336 */
2337 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002338 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002339 return 0;
2340 else
2341 return -EINVAL;
2342}
2343
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002344static const struct ethtool_ops i40e_ethtool_ops = {
2345 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002346 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002347 .get_drvinfo = i40e_get_drvinfo,
2348 .get_regs_len = i40e_get_regs_len,
2349 .get_regs = i40e_get_regs,
2350 .nway_reset = i40e_nway_reset,
2351 .get_link = ethtool_op_get_link,
2352 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002353 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002354 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002355 .get_eeprom_len = i40e_get_eeprom_len,
2356 .get_eeprom = i40e_get_eeprom,
2357 .get_ringparam = i40e_get_ringparam,
2358 .set_ringparam = i40e_set_ringparam,
2359 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002360 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002361 .get_msglevel = i40e_get_msglevel,
2362 .set_msglevel = i40e_set_msglevel,
2363 .get_rxnfc = i40e_get_rxnfc,
2364 .set_rxnfc = i40e_set_rxnfc,
2365 .self_test = i40e_diag_test,
2366 .get_strings = i40e_get_strings,
2367 .set_phys_id = i40e_set_phys_id,
2368 .get_sset_count = i40e_get_sset_count,
2369 .get_ethtool_stats = i40e_get_ethtool_stats,
2370 .get_coalesce = i40e_get_coalesce,
2371 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002372 .get_channels = i40e_get_channels,
2373 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002374 .get_ts_info = i40e_get_ts_info,
2375};
2376
2377void i40e_set_ethtool_ops(struct net_device *netdev)
2378{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002379 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002380}