blob: b311391276165ee3be911acec603e2fafbaa1976 [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),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Shannon Nelson41a9e552014-04-23 04:50:20 +000091};
92
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000093static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
94 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000095
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096/* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
102 *
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
105 */
106static struct i40e_stats i40e_gstrings_stats[] = {
107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000148 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000149 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000150 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400151 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400152 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000153 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000156 /* LPI stats */
157 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
158 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
159 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
160 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000161};
162
Vasu Dev38e00432014-08-01 13:27:03 -0700163#ifdef I40E_FCOE
164static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
165 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
166 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
167 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
168 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
169 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
170 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
171 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
172 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
173};
174
175#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000177 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
178 * 2 /* Tx and Rx together */ \
179 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000180#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
181#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000182#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700183#ifdef I40E_FCOE
184#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
185#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
186 I40E_FCOE_STATS_LEN + \
187 I40E_MISC_STATS_LEN + \
188 I40E_QUEUE_STATS_LEN((n)))
189#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000191 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700193#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194#define I40E_PFC_STATS_LEN ( \
195 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
200 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400201#define I40E_VEB_TC_STATS_LEN ( \
202 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
206 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000207#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400208#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000209#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
210 I40E_PFC_STATS_LEN + \
211 I40E_VSI_STATS_LEN((n)))
212
213enum i40e_ethtool_test_id {
214 I40E_ETH_TEST_REG = 0,
215 I40E_ETH_TEST_EEPROM,
216 I40E_ETH_TEST_INTR,
217 I40E_ETH_TEST_LOOPBACK,
218 I40E_ETH_TEST_LINK,
219};
220
221static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
222 "Register test (offline)",
223 "Eeprom test (offline)",
224 "Interrupt test (offline)",
225 "Loopback test (offline)",
226 "Link test (on/offline)"
227};
228
229#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
230
Greg Rose7e45ab42015-02-06 08:52:19 +0000231static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
232 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400233 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400234 "flow-director-atr",
Greg Rose7e45ab42015-02-06 08:52:19 +0000235};
236
Shannon Nelson9ac77262015-08-27 11:42:40 -0400237#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000238
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000239/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000240 * i40e_partition_setting_complaint - generic complaint for MFP restriction
241 * @pf: the PF struct
242 **/
243static void i40e_partition_setting_complaint(struct i40e_pf *pf)
244{
245 dev_info(&pf->pdev->dev,
246 "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");
247}
248
249/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000250 * i40e_get_settings_link_up - Get the Link settings for when link is up
251 * @hw: hw structure
252 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000255 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000256static void i40e_get_settings_link_up(struct i40e_hw *hw,
257 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400258 struct net_device *netdev,
259 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000261 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 u32 link_speed = hw_link_info->link_speed;
263
Catherine Sullivane8278452015-02-06 08:52:08 +0000264 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 switch (hw_link_info->phy_type) {
266 case I40E_PHY_TYPE_40GBASE_CR4:
267 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000268 ecmd->supported = SUPPORTED_Autoneg |
269 SUPPORTED_40000baseCR4_Full;
270 ecmd->advertising = ADVERTISED_Autoneg |
271 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000272 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000273 case I40E_PHY_TYPE_XLAUI:
274 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000275 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000276 ecmd->supported = SUPPORTED_40000baseCR4_Full;
277 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000278 case I40E_PHY_TYPE_40GBASE_SR4:
279 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 break;
281 case I40E_PHY_TYPE_40GBASE_LR4:
282 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000284 case I40E_PHY_TYPE_10GBASE_SR:
285 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000286 case I40E_PHY_TYPE_1000BASE_SX:
287 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400288 ecmd->supported = SUPPORTED_10000baseT_Full;
289 if (hw_link_info->module_type[2] &
290 I40E_MODULE_TYPE_1000BASE_SX ||
291 hw_link_info->module_type[2] &
292 I40E_MODULE_TYPE_1000BASE_LX) {
293 ecmd->supported |= SUPPORTED_1000baseT_Full;
294 if (hw_link_info->requested_speeds &
295 I40E_LINK_SPEED_1GB)
296 ecmd->advertising |= ADVERTISED_1000baseT_Full;
297 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000298 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
299 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000300 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000302 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000303 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000304 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400305 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000306 ecmd->advertising = ADVERTISED_Autoneg;
307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
308 ecmd->advertising |= ADVERTISED_10000baseT_Full;
309 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
310 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400311 break;
312 case I40E_PHY_TYPE_100BASE_TX:
313 ecmd->supported = SUPPORTED_Autoneg |
314 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000315 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
316 ecmd->advertising |= ADVERTISED_100baseT_Full;
317 break;
318 case I40E_PHY_TYPE_10GBASE_CR1_CU:
319 case I40E_PHY_TYPE_10GBASE_CR1:
320 ecmd->supported = SUPPORTED_Autoneg |
321 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000322 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000323 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000324 break;
325 case I40E_PHY_TYPE_XAUI:
326 case I40E_PHY_TYPE_XFI:
327 case I40E_PHY_TYPE_SFI:
328 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000329 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000330 ecmd->supported = SUPPORTED_10000baseT_Full;
331 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000332 case I40E_PHY_TYPE_SGMII:
333 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400334 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000335 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
336 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400337 if (pf->hw.mac.type == I40E_MAC_X722) {
338 ecmd->supported |= SUPPORTED_100baseT_Full;
339 if (hw_link_info->requested_speeds &
340 I40E_LINK_SPEED_100MB)
341 ecmd->advertising |= ADVERTISED_100baseT_Full;
342 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000343 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400344 /* Backplane is set based on supported phy types in get_settings
345 * so don't set anything here but don't warn either
346 */
347 case I40E_PHY_TYPE_40GBASE_KR4:
348 case I40E_PHY_TYPE_20GBASE_KR2:
349 case I40E_PHY_TYPE_10GBASE_KR:
350 case I40E_PHY_TYPE_10GBASE_KX4:
351 case I40E_PHY_TYPE_1000BASE_KX:
352 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000353 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000354 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000355 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
356 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000357 }
358
Catherine Sullivane8278452015-02-06 08:52:08 +0000359 /* Set speed and duplex */
360 switch (link_speed) {
361 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400362 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000363 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700364 case I40E_LINK_SPEED_20GB:
365 ethtool_cmd_speed_set(ecmd, SPEED_20000);
366 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000367 case I40E_LINK_SPEED_10GB:
368 ethtool_cmd_speed_set(ecmd, SPEED_10000);
369 break;
370 case I40E_LINK_SPEED_1GB:
371 ethtool_cmd_speed_set(ecmd, SPEED_1000);
372 break;
373 case I40E_LINK_SPEED_100MB:
374 ethtool_cmd_speed_set(ecmd, SPEED_100);
375 break;
376 default:
377 break;
378 }
379 ecmd->duplex = DUPLEX_FULL;
380}
381
382/**
383 * i40e_get_settings_link_down - Get the Link settings for when link is down
384 * @hw: hw structure
385 * @ecmd: ethtool command to fill in
386 *
387 * Reports link settings that can be determined when link is down
388 **/
389static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400390 struct ethtool_cmd *ecmd,
391 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000392{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400393 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000394
395 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400396 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000397 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400398 ecmd->supported = 0x0;
399 ecmd->advertising = 0x0;
400 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
401 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400402 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400403 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400404 ADVERTISED_1000baseT_Full;
405 if (pf->hw.mac.type == I40E_MAC_X722) {
406 ecmd->supported |= SUPPORTED_100baseT_Full;
407 ecmd->advertising |= ADVERTISED_100baseT_Full;
408 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000409 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400410 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
411 phy_types & I40E_CAP_PHY_TYPE_XFI ||
412 phy_types & I40E_CAP_PHY_TYPE_SFI ||
413 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
414 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
415 ecmd->supported |= SUPPORTED_10000baseT_Full;
416 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
417 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
418 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
419 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
420 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
421 ecmd->supported |= SUPPORTED_Autoneg |
422 SUPPORTED_10000baseT_Full;
423 ecmd->advertising |= ADVERTISED_Autoneg |
424 ADVERTISED_10000baseT_Full;
425 }
426 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
427 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
428 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
429 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
430 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
431 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
432 ecmd->supported |= SUPPORTED_Autoneg |
433 SUPPORTED_40000baseCR4_Full;
434 ecmd->advertising |= ADVERTISED_Autoneg |
435 ADVERTISED_40000baseCR4_Full;
436 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400437 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
438 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400439 ecmd->supported |= SUPPORTED_Autoneg |
440 SUPPORTED_100baseT_Full;
441 ecmd->advertising |= ADVERTISED_Autoneg |
442 ADVERTISED_100baseT_Full;
443 }
444 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
445 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
446 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
447 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
448 ecmd->supported |= SUPPORTED_Autoneg |
449 SUPPORTED_1000baseT_Full;
450 ecmd->advertising |= ADVERTISED_Autoneg |
451 ADVERTISED_1000baseT_Full;
452 }
453 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
454 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
455 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
456 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000457
458 /* With no link speed and duplex are unknown */
459 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
460 ecmd->duplex = DUPLEX_UNKNOWN;
461}
462
463/**
464 * i40e_get_settings - Get Link Speed and Duplex settings
465 * @netdev: network interface device structure
466 * @ecmd: ethtool command
467 *
468 * Reports speed/duplex settings based on media_type
469 **/
470static int i40e_get_settings(struct net_device *netdev,
471 struct ethtool_cmd *ecmd)
472{
473 struct i40e_netdev_priv *np = netdev_priv(netdev);
474 struct i40e_pf *pf = np->vsi->back;
475 struct i40e_hw *hw = &pf->hw;
476 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
477 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
478
479 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400480 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000481 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400482 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000483
484 /* Now set the settings that don't rely on link being up/down */
485
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400486 /* For backplane, supported and advertised are only reliant on the
487 * phy types the NVM specifies are supported.
488 */
489 if (hw->device_id == I40E_DEV_ID_KX_B ||
490 hw->device_id == I40E_DEV_ID_KX_C ||
491 hw->device_id == I40E_DEV_ID_20G_KR2 ||
492 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
493 ecmd->supported = SUPPORTED_Autoneg;
494 ecmd->advertising = ADVERTISED_Autoneg;
495 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
496 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
497 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
498 }
499 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
500 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
501 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
502 }
503 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
504 ecmd->supported |= SUPPORTED_10000baseKR_Full;
505 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
506 }
507 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
508 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
509 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
510 }
511 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
512 ecmd->supported |= SUPPORTED_1000baseKX_Full;
513 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
514 }
515 }
516
Catherine Sullivane8278452015-02-06 08:52:08 +0000517 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000518 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
519 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000520
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000521 switch (hw->phy.media_type) {
522 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000523 ecmd->supported |= SUPPORTED_Autoneg |
524 SUPPORTED_Backplane;
525 ecmd->advertising |= ADVERTISED_Autoneg |
526 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000527 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000528 break;
529 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000530 ecmd->supported |= SUPPORTED_TP;
531 ecmd->advertising |= ADVERTISED_TP;
532 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000533 break;
534 case I40E_MEDIA_TYPE_DA:
535 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000536 ecmd->supported |= SUPPORTED_FIBRE;
537 ecmd->advertising |= ADVERTISED_FIBRE;
538 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000539 break;
540 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000541 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000542 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000543 break;
544 case I40E_MEDIA_TYPE_UNKNOWN:
545 default:
546 ecmd->port = PORT_OTHER;
547 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000548 }
549
Catherine Sullivane8278452015-02-06 08:52:08 +0000550 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000551 ecmd->transceiver = XCVR_EXTERNAL;
552
Catherine Sullivane8278452015-02-06 08:52:08 +0000553 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000554 ecmd->supported |= SUPPORTED_Pause;
555
Catherine Sullivane8278452015-02-06 08:52:08 +0000556 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000557 case I40E_FC_FULL:
558 ecmd->advertising |= ADVERTISED_Pause;
559 break;
560 case I40E_FC_TX_PAUSE:
561 ecmd->advertising |= ADVERTISED_Asym_Pause;
562 break;
563 case I40E_FC_RX_PAUSE:
564 ecmd->advertising |= (ADVERTISED_Pause |
565 ADVERTISED_Asym_Pause);
566 break;
567 default:
568 ecmd->advertising &= ~(ADVERTISED_Pause |
569 ADVERTISED_Asym_Pause);
570 break;
571 }
572
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000573 return 0;
574}
575
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000576/**
577 * i40e_set_settings - Set Speed and Duplex
578 * @netdev: network interface device structure
579 * @ecmd: ethtool command
580 *
581 * Set speed/duplex per media_types advertised/forced
582 **/
583static int i40e_set_settings(struct net_device *netdev,
584 struct ethtool_cmd *ecmd)
585{
586 struct i40e_netdev_priv *np = netdev_priv(netdev);
587 struct i40e_aq_get_phy_abilities_resp abilities;
588 struct i40e_aq_set_phy_config config;
589 struct i40e_pf *pf = np->vsi->back;
590 struct i40e_vsi *vsi = np->vsi;
591 struct i40e_hw *hw = &pf->hw;
592 struct ethtool_cmd safe_ecmd;
593 i40e_status status = 0;
594 bool change = false;
595 int err = 0;
596 u8 autoneg;
597 u32 advertise;
598
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000599 /* Changing port settings is not supported if this isn't the
600 * port's controlling PF
601 */
602 if (hw->partition_id != 1) {
603 i40e_partition_setting_complaint(pf);
604 return -EOPNOTSUPP;
605 }
606
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000607 if (vsi != pf->vsi[pf->lan_vsi])
608 return -EOPNOTSUPP;
609
610 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
611 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000612 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
613 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000614 return -EOPNOTSUPP;
615
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400616 if (hw->device_id == I40E_DEV_ID_KX_B ||
617 hw->device_id == I40E_DEV_ID_KX_C ||
618 hw->device_id == I40E_DEV_ID_20G_KR2 ||
619 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
620 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
621 return -EOPNOTSUPP;
622 }
623
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000624 /* get our own copy of the bits to check against */
625 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
626 i40e_get_settings(netdev, &safe_ecmd);
627
628 /* save autoneg and speed out of ecmd */
629 autoneg = ecmd->autoneg;
630 advertise = ecmd->advertising;
631
632 /* set autoneg and speed back to what they currently are */
633 ecmd->autoneg = safe_ecmd.autoneg;
634 ecmd->advertising = safe_ecmd.advertising;
635
636 ecmd->cmd = safe_ecmd.cmd;
637 /* If ecmd and safe_ecmd are not the same now, then they are
638 * trying to set something that we do not support
639 */
640 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
641 return -EOPNOTSUPP;
642
643 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
644 usleep_range(1000, 2000);
645
646 /* Get the current phy config */
647 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
648 NULL);
649 if (status)
650 return -EAGAIN;
651
Catherine Sullivan124ed152014-07-12 07:28:12 +0000652 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000653 * set below
654 */
655 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000656 config.abilities = abilities.abilities;
657
658 /* Check autoneg */
659 if (autoneg == AUTONEG_ENABLE) {
660 /* If autoneg is not supported, return error */
661 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
662 netdev_info(netdev, "Autoneg not supported on this phy\n");
663 return -EINVAL;
664 }
665 /* If autoneg was not already enabled */
666 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
667 config.abilities = abilities.abilities |
668 I40E_AQ_PHY_ENABLE_AN;
669 change = true;
670 }
671 } else {
672 /* If autoneg is supported 10GBASE_T is the only phy that
673 * can disable it, so otherwise return error
674 */
675 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
676 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
677 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
678 return -EINVAL;
679 }
680 /* If autoneg is currently enabled */
681 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000682 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000683 ~I40E_AQ_PHY_ENABLE_AN;
684 change = true;
685 }
686 }
687
688 if (advertise & ~safe_ecmd.supported)
689 return -EINVAL;
690
691 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000692 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000693 if (advertise & ADVERTISED_1000baseT_Full ||
694 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000695 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000696 if (advertise & ADVERTISED_10000baseT_Full ||
697 advertise & ADVERTISED_10000baseKX4_Full ||
698 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000699 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700700 if (advertise & ADVERTISED_20000baseKR2_Full)
701 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000702 if (advertise & ADVERTISED_40000baseKR4_Full ||
703 advertise & ADVERTISED_40000baseCR4_Full ||
704 advertise & ADVERTISED_40000baseSR4_Full ||
705 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000706 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000707
Catherine Sullivan0002e112015-08-26 15:14:16 -0400708 /* If speed didn't get set, set it to what it currently is.
709 * This is needed because if advertise is 0 (as it is when autoneg
710 * is disabled) then speed won't get set.
711 */
712 if (!config.link_speed)
713 config.link_speed = abilities.link_speed;
714
Catherine Sullivan124ed152014-07-12 07:28:12 +0000715 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000716 /* copy over the rest of the abilities */
717 config.phy_type = abilities.phy_type;
718 config.eee_capability = abilities.eee_capability;
719 config.eeer = abilities.eeer_val;
720 config.low_power_ctrl = abilities.d3_lpan;
721
Catherine Sullivane8278452015-02-06 08:52:08 +0000722 /* save the requested speeds */
723 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000724 /* set link and auto negotiation so changes take effect */
725 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
726 /* If link is up put link down */
727 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
728 /* Tell the OS link is going down, the link will go
729 * back up when fw says it is ready asynchronously
730 */
Matt Jaredc156f852015-08-27 11:42:39 -0400731 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000732 netif_carrier_off(netdev);
733 netif_tx_stop_all_queues(netdev);
734 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000735
736 /* make the aq call */
737 status = i40e_aq_set_phy_config(hw, &config, NULL);
738 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400739 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
740 i40e_stat_str(hw, status),
741 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000742 return -EAGAIN;
743 }
744
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400745 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000746 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400747 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
748 i40e_stat_str(hw, status),
749 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750
751 } else {
752 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
753 }
754
755 return err;
756}
757
Jesse Brandeburga6599722014-06-04 08:45:25 +0000758static int i40e_nway_reset(struct net_device *netdev)
759{
760 /* restart autonegotiation */
761 struct i40e_netdev_priv *np = netdev_priv(netdev);
762 struct i40e_pf *pf = np->vsi->back;
763 struct i40e_hw *hw = &pf->hw;
764 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
765 i40e_status ret = 0;
766
767 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
768 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400769 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
770 i40e_stat_str(hw, ret),
771 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000772 return -EIO;
773 }
774
775 return 0;
776}
777
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000778/**
779 * i40e_get_pauseparam - Get Flow Control status
780 * Return tx/rx-pause status
781 **/
782static void i40e_get_pauseparam(struct net_device *netdev,
783 struct ethtool_pauseparam *pause)
784{
785 struct i40e_netdev_priv *np = netdev_priv(netdev);
786 struct i40e_pf *pf = np->vsi->back;
787 struct i40e_hw *hw = &pf->hw;
788 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000789 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000790
791 pause->autoneg =
792 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
793 AUTONEG_ENABLE : AUTONEG_DISABLE);
794
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000795 /* PFC enabled so report LFC as off */
796 if (dcbx_cfg->pfc.pfcenable) {
797 pause->rx_pause = 0;
798 pause->tx_pause = 0;
799 return;
800 }
801
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000802 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000803 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000804 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000805 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000806 } else if (hw->fc.current_mode == I40E_FC_FULL) {
807 pause->rx_pause = 1;
808 pause->tx_pause = 1;
809 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000810}
811
Catherine Sullivan2becc352014-06-04 08:45:27 +0000812/**
813 * i40e_set_pauseparam - Set Flow Control parameter
814 * @netdev: network interface device structure
815 * @pause: return tx/rx flow control status
816 **/
817static int i40e_set_pauseparam(struct net_device *netdev,
818 struct ethtool_pauseparam *pause)
819{
820 struct i40e_netdev_priv *np = netdev_priv(netdev);
821 struct i40e_pf *pf = np->vsi->back;
822 struct i40e_vsi *vsi = np->vsi;
823 struct i40e_hw *hw = &pf->hw;
824 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000825 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000826 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
827 i40e_status status;
828 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000829 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000830
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000831 /* Changing the port's flow control is not supported if this isn't the
832 * port's controlling PF
833 */
834 if (hw->partition_id != 1) {
835 i40e_partition_setting_complaint(pf);
836 return -EOPNOTSUPP;
837 }
838
Catherine Sullivan2becc352014-06-04 08:45:27 +0000839 if (vsi != pf->vsi[pf->lan_vsi])
840 return -EOPNOTSUPP;
841
842 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
843 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
844 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
845 return -EOPNOTSUPP;
846 }
847
848 /* If we have link and don't have autoneg */
849 if (!test_bit(__I40E_DOWN, &pf->state) &&
850 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
851 /* Send message that it might not necessarily work*/
852 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
853 }
854
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000855 if (dcbx_cfg->pfc.pfcenable) {
856 netdev_info(netdev,
857 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000858 return -EOPNOTSUPP;
859 }
860
861 if (pause->rx_pause && pause->tx_pause)
862 hw->fc.requested_mode = I40E_FC_FULL;
863 else if (pause->rx_pause && !pause->tx_pause)
864 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
865 else if (!pause->rx_pause && pause->tx_pause)
866 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
867 else if (!pause->rx_pause && !pause->tx_pause)
868 hw->fc.requested_mode = I40E_FC_NONE;
869 else
870 return -EINVAL;
871
Catherine Sullivan94128512014-07-12 07:28:16 +0000872 /* Tell the OS link is going down, the link will go back up when fw
873 * says it is ready asynchronously
874 */
Matt Jaredc156f852015-08-27 11:42:39 -0400875 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000876 netif_carrier_off(netdev);
877 netif_tx_stop_all_queues(netdev);
878
Catherine Sullivan2becc352014-06-04 08:45:27 +0000879 /* Set the fc mode and only restart an if link is up*/
880 status = i40e_set_fc(hw, &aq_failures, link_up);
881
882 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400883 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
884 i40e_stat_str(hw, status),
885 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000886 err = -EAGAIN;
887 }
888 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400889 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
890 i40e_stat_str(hw, status),
891 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000892 err = -EAGAIN;
893 }
894 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400895 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
896 i40e_stat_str(hw, status),
897 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000898 err = -EAGAIN;
899 }
900
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000901 if (!test_bit(__I40E_DOWN, &pf->state)) {
902 /* Give it a little more time to try to come back */
903 msleep(75);
904 if (!test_bit(__I40E_DOWN, &pf->state))
905 return i40e_nway_reset(netdev);
906 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000907
908 return err;
909}
910
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000911static u32 i40e_get_msglevel(struct net_device *netdev)
912{
913 struct i40e_netdev_priv *np = netdev_priv(netdev);
914 struct i40e_pf *pf = np->vsi->back;
915
916 return pf->msg_enable;
917}
918
919static void i40e_set_msglevel(struct net_device *netdev, u32 data)
920{
921 struct i40e_netdev_priv *np = netdev_priv(netdev);
922 struct i40e_pf *pf = np->vsi->back;
923
924 if (I40E_DEBUG_USER & data)
925 pf->hw.debug_mask = data;
926 pf->msg_enable = data;
927}
928
929static int i40e_get_regs_len(struct net_device *netdev)
930{
931 int reg_count = 0;
932 int i;
933
934 for (i = 0; i40e_reg_list[i].offset != 0; i++)
935 reg_count += i40e_reg_list[i].elements;
936
937 return reg_count * sizeof(u32);
938}
939
940static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
941 void *p)
942{
943 struct i40e_netdev_priv *np = netdev_priv(netdev);
944 struct i40e_pf *pf = np->vsi->back;
945 struct i40e_hw *hw = &pf->hw;
946 u32 *reg_buf = p;
947 int i, j, ri;
948 u32 reg;
949
950 /* Tell ethtool which driver-version-specific regs output we have.
951 *
952 * At some point, if we have ethtool doing special formatting of
953 * this data, it will rely on this version number to know how to
954 * interpret things. Hence, this needs to be updated if/when the
955 * diags register table is changed.
956 */
957 regs->version = 1;
958
959 /* loop through the diags reg table for what to print */
960 ri = 0;
961 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
962 for (j = 0; j < i40e_reg_list[i].elements; j++) {
963 reg = i40e_reg_list[i].offset
964 + (j * i40e_reg_list[i].stride);
965 reg_buf[ri++] = rd32(hw, reg);
966 }
967 }
968
969}
970
971static int i40e_get_eeprom(struct net_device *netdev,
972 struct ethtool_eeprom *eeprom, u8 *bytes)
973{
974 struct i40e_netdev_priv *np = netdev_priv(netdev);
975 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000976 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000977 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000978 u8 *eeprom_buff;
979 u16 i, sectors;
980 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000981 u32 magic;
982
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000983#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000984 if (eeprom->len == 0)
985 return -EINVAL;
986
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000987 /* check for NVMUpdate access method */
988 magic = hw->vendor_id | (hw->device_id << 16);
989 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000990 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000991 int errno;
992
993 /* make sure it is the right magic for NVMUpdate */
994 if ((eeprom->magic >> 16) != hw->device_id)
995 return -EINVAL;
996
Shannon Nelsonc150a502014-11-13 08:23:13 +0000997 cmd = (struct i40e_nvm_access *)eeprom;
998 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000999 if (ret_val &&
1000 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
1001 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001002 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001003 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1004 ret_val, hw->aq.asq_last_status, errno,
1005 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1006 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001007
1008 return errno;
1009 }
1010
1011 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001012 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1013
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001014 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001015 if (!eeprom_buff)
1016 return -ENOMEM;
1017
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001018 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1019 if (ret_val) {
1020 dev_info(&pf->pdev->dev,
1021 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1022 ret_val, hw->aq.asq_last_status);
1023 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001024 }
1025
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001026 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1027 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1028 len = I40E_NVM_SECTOR_SIZE;
1029 last = false;
1030 for (i = 0; i < sectors; i++) {
1031 if (i == (sectors - 1)) {
1032 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1033 last = true;
1034 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001035 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1036 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001037 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001038 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001039 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001040 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001041 "read NVM failed, invalid offset 0x%x\n",
1042 offset);
1043 break;
1044 } else if (ret_val &&
1045 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1046 dev_info(&pf->pdev->dev,
1047 "read NVM failed, access, offset 0x%x\n",
1048 offset);
1049 break;
1050 } else if (ret_val) {
1051 dev_info(&pf->pdev->dev,
1052 "read NVM failed offset %d err=%d status=0x%x\n",
1053 offset, ret_val, hw->aq.asq_last_status);
1054 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001055 }
1056 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001057
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001058 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001059 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001060free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001061 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001062 return ret_val;
1063}
1064
1065static int i40e_get_eeprom_len(struct net_device *netdev)
1066{
1067 struct i40e_netdev_priv *np = netdev_priv(netdev);
1068 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001069 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001070
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001071 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1072 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1073 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1074 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001075 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001076 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001077}
1078
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001079static int i40e_set_eeprom(struct net_device *netdev,
1080 struct ethtool_eeprom *eeprom, u8 *bytes)
1081{
1082 struct i40e_netdev_priv *np = netdev_priv(netdev);
1083 struct i40e_hw *hw = &np->vsi->back->hw;
1084 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001085 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001086 int ret_val = 0;
1087 int errno;
1088 u32 magic;
1089
1090 /* normal ethtool set_eeprom is not supported */
1091 magic = hw->vendor_id | (hw->device_id << 16);
1092 if (eeprom->magic == magic)
1093 return -EOPNOTSUPP;
1094
1095 /* check for NVMUpdate access method */
1096 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1097 return -EINVAL;
1098
1099 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1100 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1101 return -EBUSY;
1102
Shannon Nelsonc150a502014-11-13 08:23:13 +00001103 cmd = (struct i40e_nvm_access *)eeprom;
1104 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001105 if (ret_val &&
1106 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1107 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1108 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001109 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001110 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1111 ret_val, hw->aq.asq_last_status, errno,
1112 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1113 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001114
1115 return errno;
1116}
1117
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001118static void i40e_get_drvinfo(struct net_device *netdev,
1119 struct ethtool_drvinfo *drvinfo)
1120{
1121 struct i40e_netdev_priv *np = netdev_priv(netdev);
1122 struct i40e_vsi *vsi = np->vsi;
1123 struct i40e_pf *pf = vsi->back;
1124
1125 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1126 strlcpy(drvinfo->version, i40e_driver_version_str,
1127 sizeof(drvinfo->version));
1128 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1129 sizeof(drvinfo->fw_version));
1130 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1131 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001132 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001133}
1134
1135static void i40e_get_ringparam(struct net_device *netdev,
1136 struct ethtool_ringparam *ring)
1137{
1138 struct i40e_netdev_priv *np = netdev_priv(netdev);
1139 struct i40e_pf *pf = np->vsi->back;
1140 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1141
1142 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1143 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1144 ring->rx_mini_max_pending = 0;
1145 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001146 ring->rx_pending = vsi->rx_rings[0]->count;
1147 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001148 ring->rx_mini_pending = 0;
1149 ring->rx_jumbo_pending = 0;
1150}
1151
1152static int i40e_set_ringparam(struct net_device *netdev,
1153 struct ethtool_ringparam *ring)
1154{
1155 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1156 struct i40e_netdev_priv *np = netdev_priv(netdev);
1157 struct i40e_vsi *vsi = np->vsi;
1158 struct i40e_pf *pf = vsi->back;
1159 u32 new_rx_count, new_tx_count;
1160 int i, err = 0;
1161
1162 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1163 return -EINVAL;
1164
Shannon Nelson1fa18372013-11-20 10:03:08 +00001165 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1166 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1167 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1168 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1169 netdev_info(netdev,
1170 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1171 ring->tx_pending, ring->rx_pending,
1172 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1173 return -EINVAL;
1174 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001175
Shannon Nelson1fa18372013-11-20 10:03:08 +00001176 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1177 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001178
1179 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001180 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1181 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001182 return 0;
1183
1184 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1185 usleep_range(1000, 2000);
1186
1187 if (!netif_running(vsi->netdev)) {
1188 /* simple case - set for the next time the netdev is started */
1189 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001190 vsi->tx_rings[i]->count = new_tx_count;
1191 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001192 }
1193 goto done;
1194 }
1195
1196 /* We can't just free everything and then setup again,
1197 * because the ISRs in MSI-X mode get passed pointers
1198 * to the Tx and Rx ring structs.
1199 */
1200
1201 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001202 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001203 netdev_info(netdev,
1204 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001205 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001206 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1207 sizeof(struct i40e_ring), GFP_KERNEL);
1208 if (!tx_rings) {
1209 err = -ENOMEM;
1210 goto done;
1211 }
1212
1213 for (i = 0; i < vsi->num_queue_pairs; i++) {
1214 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001215 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001216 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001217 /* the desc and bi pointers will be reallocated in the
1218 * setup call
1219 */
1220 tx_rings[i].desc = NULL;
1221 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001222 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1223 if (err) {
1224 while (i) {
1225 i--;
1226 i40e_free_tx_resources(&tx_rings[i]);
1227 }
1228 kfree(tx_rings);
1229 tx_rings = NULL;
1230
1231 goto done;
1232 }
1233 }
1234 }
1235
1236 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001237 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001238 netdev_info(netdev,
1239 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001240 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001241 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1242 sizeof(struct i40e_ring), GFP_KERNEL);
1243 if (!rx_rings) {
1244 err = -ENOMEM;
1245 goto free_tx;
1246 }
1247
1248 for (i = 0; i < vsi->num_queue_pairs; i++) {
1249 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001250 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001251 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001252 /* the desc and bi pointers will be reallocated in the
1253 * setup call
1254 */
1255 rx_rings[i].desc = NULL;
1256 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001257 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1258 if (err) {
1259 while (i) {
1260 i--;
1261 i40e_free_rx_resources(&rx_rings[i]);
1262 }
1263 kfree(rx_rings);
1264 rx_rings = NULL;
1265
1266 goto free_tx;
1267 }
1268 }
1269 }
1270
1271 /* Bring interface down, copy in the new ring info,
1272 * then restore the interface
1273 */
1274 i40e_down(vsi);
1275
1276 if (tx_rings) {
1277 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001278 i40e_free_tx_resources(vsi->tx_rings[i]);
1279 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001280 }
1281 kfree(tx_rings);
1282 tx_rings = NULL;
1283 }
1284
1285 if (rx_rings) {
1286 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001287 i40e_free_rx_resources(vsi->rx_rings[i]);
1288 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001289 }
1290 kfree(rx_rings);
1291 rx_rings = NULL;
1292 }
1293
1294 i40e_up(vsi);
1295
1296free_tx:
1297 /* error cleanup if the Rx allocations failed after getting Tx */
1298 if (tx_rings) {
1299 for (i = 0; i < vsi->num_queue_pairs; i++)
1300 i40e_free_tx_resources(&tx_rings[i]);
1301 kfree(tx_rings);
1302 tx_rings = NULL;
1303 }
1304
1305done:
1306 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1307
1308 return err;
1309}
1310
1311static int i40e_get_sset_count(struct net_device *netdev, int sset)
1312{
1313 struct i40e_netdev_priv *np = netdev_priv(netdev);
1314 struct i40e_vsi *vsi = np->vsi;
1315 struct i40e_pf *pf = vsi->back;
1316
1317 switch (sset) {
1318 case ETH_SS_TEST:
1319 return I40E_TEST_LEN;
1320 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001321 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001322 int len = I40E_PF_STATS_LEN(netdev);
1323
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001324 if ((pf->lan_veb != I40E_NO_VEB) &&
1325 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001326 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001327 return len;
1328 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001329 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001330 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001331 case ETH_SS_PRIV_FLAGS:
1332 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001333 default:
1334 return -EOPNOTSUPP;
1335 }
1336}
1337
1338static void i40e_get_ethtool_stats(struct net_device *netdev,
1339 struct ethtool_stats *stats, u64 *data)
1340{
1341 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001342 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001343 struct i40e_vsi *vsi = np->vsi;
1344 struct i40e_pf *pf = vsi->back;
1345 int i = 0;
1346 char *p;
1347 int j;
1348 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001349 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350
1351 i40e_update_stats(vsi);
1352
1353 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1354 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1355 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1356 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1357 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001358 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1359 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1360 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1361 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1362 }
Vasu Dev38e00432014-08-01 13:27:03 -07001363#ifdef I40E_FCOE
1364 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1365 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1366 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1367 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1368 }
1369#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001370 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001371 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001372 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001373
1374 if (!tx_ring)
1375 continue;
1376
1377 /* process Tx ring statistics */
1378 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001379 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001380 data[i] = tx_ring->stats.packets;
1381 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001382 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001383 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001384
1385 /* Rx ring is the 2nd half of the queue pair */
1386 rx_ring = &tx_ring[1];
1387 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001388 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001389 data[i] = rx_ring->stats.packets;
1390 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001391 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001392 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001393 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001394 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001395 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001396 return;
1397
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001398 if ((pf->lan_veb != I40E_NO_VEB) &&
1399 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001400 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001401
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001402 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1403 p = (char *)veb;
1404 p += i40e_gstrings_veb_stats[j].stat_offset;
1405 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1406 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001407 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001408 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001409 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1410 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1411 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1412 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1413 }
1414 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1415 data[i++] = pf->stats.priority_xon_tx[j];
1416 data[i++] = pf->stats.priority_xoff_tx[j];
1417 }
1418 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1419 data[i++] = pf->stats.priority_xon_rx[j];
1420 data[i++] = pf->stats.priority_xoff_rx[j];
1421 }
1422 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1423 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001424}
1425
1426static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1427 u8 *data)
1428{
1429 struct i40e_netdev_priv *np = netdev_priv(netdev);
1430 struct i40e_vsi *vsi = np->vsi;
1431 struct i40e_pf *pf = vsi->back;
1432 char *p = (char *)data;
1433 int i;
1434
1435 switch (stringset) {
1436 case ETH_SS_TEST:
1437 for (i = 0; i < I40E_TEST_LEN; i++) {
1438 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1439 data += ETH_GSTRING_LEN;
1440 }
1441 break;
1442 case ETH_SS_STATS:
1443 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1444 snprintf(p, ETH_GSTRING_LEN, "%s",
1445 i40e_gstrings_net_stats[i].stat_string);
1446 p += ETH_GSTRING_LEN;
1447 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001448 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1449 snprintf(p, ETH_GSTRING_LEN, "%s",
1450 i40e_gstrings_misc_stats[i].stat_string);
1451 p += ETH_GSTRING_LEN;
1452 }
Vasu Dev38e00432014-08-01 13:27:03 -07001453#ifdef I40E_FCOE
1454 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1455 snprintf(p, ETH_GSTRING_LEN, "%s",
1456 i40e_gstrings_fcoe_stats[i].stat_string);
1457 p += ETH_GSTRING_LEN;
1458 }
1459#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001460 for (i = 0; i < vsi->num_queue_pairs; i++) {
1461 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1462 p += ETH_GSTRING_LEN;
1463 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1464 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001465 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1466 p += ETH_GSTRING_LEN;
1467 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1468 p += ETH_GSTRING_LEN;
1469 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001470 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001471 return;
1472
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001473 if ((pf->lan_veb != I40E_NO_VEB) &&
1474 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001475 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1476 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1477 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478 p += ETH_GSTRING_LEN;
1479 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001480 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1481 snprintf(p, ETH_GSTRING_LEN,
1482 "veb.tc_%u_tx_packets", i);
1483 p += ETH_GSTRING_LEN;
1484 snprintf(p, ETH_GSTRING_LEN,
1485 "veb.tc_%u_tx_bytes", i);
1486 p += ETH_GSTRING_LEN;
1487 snprintf(p, ETH_GSTRING_LEN,
1488 "veb.tc_%u_rx_packets", i);
1489 p += ETH_GSTRING_LEN;
1490 snprintf(p, ETH_GSTRING_LEN,
1491 "veb.tc_%u_rx_bytes", i);
1492 p += ETH_GSTRING_LEN;
1493 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001494 }
1495 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1496 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1497 i40e_gstrings_stats[i].stat_string);
1498 p += ETH_GSTRING_LEN;
1499 }
1500 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1501 snprintf(p, ETH_GSTRING_LEN,
1502 "port.tx_priority_%u_xon", i);
1503 p += ETH_GSTRING_LEN;
1504 snprintf(p, ETH_GSTRING_LEN,
1505 "port.tx_priority_%u_xoff", i);
1506 p += ETH_GSTRING_LEN;
1507 }
1508 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1509 snprintf(p, ETH_GSTRING_LEN,
1510 "port.rx_priority_%u_xon", i);
1511 p += ETH_GSTRING_LEN;
1512 snprintf(p, ETH_GSTRING_LEN,
1513 "port.rx_priority_%u_xoff", i);
1514 p += ETH_GSTRING_LEN;
1515 }
1516 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1517 snprintf(p, ETH_GSTRING_LEN,
1518 "port.rx_priority_%u_xon_2_xoff", i);
1519 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520 }
1521 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1522 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001523 case ETH_SS_PRIV_FLAGS:
1524 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1525 memcpy(data, i40e_priv_flags_strings[i],
1526 ETH_GSTRING_LEN);
1527 data += ETH_GSTRING_LEN;
1528 }
1529 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001530 default:
1531 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001532 }
1533}
1534
1535static int i40e_get_ts_info(struct net_device *dev,
1536 struct ethtool_ts_info *info)
1537{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001538 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1539
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001540 /* only report HW timestamping if PTP is enabled */
1541 if (!(pf->flags & I40E_FLAG_PTP))
1542 return ethtool_op_get_ts_info(dev, info);
1543
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001544 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1545 SOF_TIMESTAMPING_RX_SOFTWARE |
1546 SOF_TIMESTAMPING_SOFTWARE |
1547 SOF_TIMESTAMPING_TX_HARDWARE |
1548 SOF_TIMESTAMPING_RX_HARDWARE |
1549 SOF_TIMESTAMPING_RAW_HARDWARE;
1550
1551 if (pf->ptp_clock)
1552 info->phc_index = ptp_clock_index(pf->ptp_clock);
1553 else
1554 info->phc_index = -1;
1555
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001556 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001557
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001558 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1559 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1560 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001561
1562 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001563}
1564
Shannon Nelson7b086392013-11-20 10:02:59 +00001565static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566{
Shannon Nelson7b086392013-11-20 10:02:59 +00001567 struct i40e_netdev_priv *np = netdev_priv(netdev);
1568 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001569 i40e_status status;
1570 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001571
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001572 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001573 status = i40e_get_link_status(&pf->hw, &link_up);
1574 if (status) {
1575 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1576 *data = 1;
1577 return *data;
1578 }
1579
1580 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001581 *data = 0;
1582 else
1583 *data = 1;
1584
1585 return *data;
1586}
1587
Shannon Nelson7b086392013-11-20 10:02:59 +00001588static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001589{
Shannon Nelson7b086392013-11-20 10:02:59 +00001590 struct i40e_netdev_priv *np = netdev_priv(netdev);
1591 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001592
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001593 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001594 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595
Shannon Nelson7b086392013-11-20 10:02:59 +00001596 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001597}
1598
Shannon Nelson7b086392013-11-20 10:02:59 +00001599static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600{
Shannon Nelson7b086392013-11-20 10:02:59 +00001601 struct i40e_netdev_priv *np = netdev_priv(netdev);
1602 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001603
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001604 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001605 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001606
Shannon Nelson4443ec92014-11-13 08:23:12 +00001607 /* forcebly clear the NVM Update state machine */
1608 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1609
Shannon Nelson7b086392013-11-20 10:02:59 +00001610 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001611}
1612
Shannon Nelson7b086392013-11-20 10:02:59 +00001613static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614{
Shannon Nelson7b086392013-11-20 10:02:59 +00001615 struct i40e_netdev_priv *np = netdev_priv(netdev);
1616 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001617 u16 swc_old = pf->sw_int_count;
1618
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001619 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001620 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1621 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001622 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1623 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1624 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1625 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001626 usleep_range(1000, 2000);
1627 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001628
1629 return *data;
1630}
1631
Shannon Nelson7b086392013-11-20 10:02:59 +00001632static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001634 struct i40e_netdev_priv *np = netdev_priv(netdev);
1635 struct i40e_pf *pf = np->vsi->back;
1636
1637 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001638 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001639
1640 return *data;
1641}
1642
Greg Rosee17bc412015-04-16 20:05:59 -04001643static inline bool i40e_active_vfs(struct i40e_pf *pf)
1644{
1645 struct i40e_vf *vfs = pf->vf;
1646 int i;
1647
1648 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001649 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001650 return true;
1651 return false;
1652}
1653
Greg Rose510efb22015-07-10 19:36:01 -04001654static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1655{
1656 struct i40e_vsi **vsi = pf->vsi;
1657 int i;
1658
1659 for (i = 0; i < pf->num_alloc_vsi; i++) {
1660 if (!vsi[i])
1661 continue;
1662 if (vsi[i]->type == I40E_VSI_VMDQ2)
1663 return true;
1664 }
1665
1666 return false;
1667}
1668
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001669static void i40e_diag_test(struct net_device *netdev,
1670 struct ethtool_test *eth_test, u64 *data)
1671{
1672 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001673 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001674 struct i40e_pf *pf = np->vsi->back;
1675
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001676 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1677 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001678 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001679
Shannon Nelsonf551b432013-11-26 10:49:12 +00001680 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001681
Greg Rose510efb22015-07-10 19:36:01 -04001682 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001683 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001684 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001685 data[I40E_ETH_TEST_REG] = 1;
1686 data[I40E_ETH_TEST_EEPROM] = 1;
1687 data[I40E_ETH_TEST_INTR] = 1;
1688 data[I40E_ETH_TEST_LOOPBACK] = 1;
1689 data[I40E_ETH_TEST_LINK] = 1;
1690 eth_test->flags |= ETH_TEST_FL_FAILED;
1691 clear_bit(__I40E_TESTING, &pf->state);
1692 goto skip_ol_tests;
1693 }
1694
Greg Rose5b86c5c2015-02-26 16:14:35 +00001695 /* If the device is online then take it offline */
1696 if (if_running)
1697 /* indicate we're in test mode */
1698 dev_close(netdev);
1699 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001700 /* This reset does not affect link - if it is
1701 * changed to a type of reset that does affect
1702 * link then the following link test would have
1703 * to be moved to before the reset
1704 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001705 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001706
Shannon Nelson7b086392013-11-20 10:02:59 +00001707 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001708 eth_test->flags |= ETH_TEST_FL_FAILED;
1709
Shannon Nelson7b086392013-11-20 10:02:59 +00001710 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001711 eth_test->flags |= ETH_TEST_FL_FAILED;
1712
Shannon Nelson7b086392013-11-20 10:02:59 +00001713 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714 eth_test->flags |= ETH_TEST_FL_FAILED;
1715
Shannon Nelson7b086392013-11-20 10:02:59 +00001716 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001717 eth_test->flags |= ETH_TEST_FL_FAILED;
1718
Shannon Nelsonf551b432013-11-26 10:49:12 +00001719 /* run reg test last, a reset is required after it */
1720 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1721 eth_test->flags |= ETH_TEST_FL_FAILED;
1722
1723 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001724 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001725
1726 if (if_running)
1727 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001728 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001729 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001730 netif_info(pf, drv, netdev, "online testing starting\n");
1731
Shannon Nelson7b086392013-11-20 10:02:59 +00001732 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733 eth_test->flags |= ETH_TEST_FL_FAILED;
1734
1735 /* Offline only tests, not run in online; pass by default */
1736 data[I40E_ETH_TEST_REG] = 0;
1737 data[I40E_ETH_TEST_EEPROM] = 0;
1738 data[I40E_ETH_TEST_INTR] = 0;
1739 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001740 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001741
Greg Rosee17bc412015-04-16 20:05:59 -04001742skip_ol_tests:
1743
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001744 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001745}
1746
1747static void i40e_get_wol(struct net_device *netdev,
1748 struct ethtool_wolinfo *wol)
1749{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001750 struct i40e_netdev_priv *np = netdev_priv(netdev);
1751 struct i40e_pf *pf = np->vsi->back;
1752 struct i40e_hw *hw = &pf->hw;
1753 u16 wol_nvm_bits;
1754
1755 /* NVM bit on means WoL disabled for the port */
1756 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001757 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001758 wol->supported = 0;
1759 wol->wolopts = 0;
1760 } else {
1761 wol->supported = WAKE_MAGIC;
1762 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1763 }
1764}
1765
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001766/**
1767 * i40e_set_wol - set the WakeOnLAN configuration
1768 * @netdev: the netdev in question
1769 * @wol: the ethtool WoL setting data
1770 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001771static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1772{
1773 struct i40e_netdev_priv *np = netdev_priv(netdev);
1774 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001775 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001776 struct i40e_hw *hw = &pf->hw;
1777 u16 wol_nvm_bits;
1778
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001779 /* WoL not supported if this isn't the controlling PF on the port */
1780 if (hw->partition_id != 1) {
1781 i40e_partition_setting_complaint(pf);
1782 return -EOPNOTSUPP;
1783 }
1784
1785 if (vsi != pf->vsi[pf->lan_vsi])
1786 return -EOPNOTSUPP;
1787
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001788 /* NVM bit on means WoL disabled for the port */
1789 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001790 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001791 return -EOPNOTSUPP;
1792
1793 /* only magic packet is supported */
1794 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1795 return -EOPNOTSUPP;
1796
1797 /* is this a new value? */
1798 if (pf->wol_en != !!wol->wolopts) {
1799 pf->wol_en = !!wol->wolopts;
1800 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1801 }
1802
1803 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001804}
1805
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001806static int i40e_set_phys_id(struct net_device *netdev,
1807 enum ethtool_phys_id_state state)
1808{
1809 struct i40e_netdev_priv *np = netdev_priv(netdev);
1810 struct i40e_pf *pf = np->vsi->back;
1811 struct i40e_hw *hw = &pf->hw;
1812 int blink_freq = 2;
1813
1814 switch (state) {
1815 case ETHTOOL_ID_ACTIVE:
1816 pf->led_status = i40e_led_get(hw);
1817 return blink_freq;
1818 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001819 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820 break;
1821 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001822 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823 break;
1824 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001825 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001826 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001827 default:
1828 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829 }
1830
1831 return 0;
1832}
1833
1834/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1835 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1836 * 125us (8000 interrupts per second) == ITR(62)
1837 */
1838
1839static int i40e_get_coalesce(struct net_device *netdev,
1840 struct ethtool_coalesce *ec)
1841{
1842 struct i40e_netdev_priv *np = netdev_priv(netdev);
1843 struct i40e_vsi *vsi = np->vsi;
1844
1845 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1846 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1847
1848 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001849 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001850
1851 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001852 ec->use_adaptive_tx_coalesce = 1;
1853
1854 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1855 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001856
1857 return 0;
1858}
1859
1860static int i40e_set_coalesce(struct net_device *netdev,
1861 struct ethtool_coalesce *ec)
1862{
1863 struct i40e_netdev_priv *np = netdev_priv(netdev);
1864 struct i40e_q_vector *q_vector;
1865 struct i40e_vsi *vsi = np->vsi;
1866 struct i40e_pf *pf = vsi->back;
1867 struct i40e_hw *hw = &pf->hw;
1868 u16 vector;
1869 int i;
1870
1871 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1872 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1873
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001874 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001875 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001876 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001877 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001878 } else if (ec->rx_coalesce_usecs == 0) {
1879 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001880 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001881 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 +00001882 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001883 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001884 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001885 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001886
Mitch Williams32f5f542014-04-04 04:43:10 +00001887 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001888 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001889 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001890 } else if (ec->tx_coalesce_usecs == 0) {
1891 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001892 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001893 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 +00001894 } else {
1895 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001896 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001897 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001898 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001899
1900 if (ec->use_adaptive_rx_coalesce)
1901 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1902 else
1903 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1904
1905 if (ec->use_adaptive_tx_coalesce)
1906 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1907 else
1908 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001909
Alexander Duyck493fb302013-09-28 07:01:44 +00001910 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1911 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001912 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1913 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1914 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1915 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1916 i40e_flush(hw);
1917 }
1918
1919 return 0;
1920}
1921
1922/**
1923 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1924 * @pf: pointer to the physical function struct
1925 * @cmd: ethtool rxnfc command
1926 *
1927 * Returns Success if the flow is supported, else Invalid Input.
1928 **/
1929static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1930{
1931 cmd->data = 0;
1932
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001933 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1934 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1935 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1936 return 0;
1937 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001938 /* Report default options for RSS on i40e */
1939 switch (cmd->flow_type) {
1940 case TCP_V4_FLOW:
1941 case UDP_V4_FLOW:
1942 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1943 /* fall through to add IP fields */
1944 case SCTP_V4_FLOW:
1945 case AH_ESP_V4_FLOW:
1946 case AH_V4_FLOW:
1947 case ESP_V4_FLOW:
1948 case IPV4_FLOW:
1949 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1950 break;
1951 case TCP_V6_FLOW:
1952 case UDP_V6_FLOW:
1953 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1954 /* fall through to add IP fields */
1955 case SCTP_V6_FLOW:
1956 case AH_ESP_V6_FLOW:
1957 case AH_V6_FLOW:
1958 case ESP_V6_FLOW:
1959 case IPV6_FLOW:
1960 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1961 break;
1962 default:
1963 return -EINVAL;
1964 }
1965
1966 return 0;
1967}
1968
1969/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001970 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1971 * @pf: Pointer to the physical function struct
1972 * @cmd: The command to get or set Rx flow classification rules
1973 * @rule_locs: Array of used rule locations
1974 *
1975 * This function populates both the total and actual rule count of
1976 * the ethtool flow classification command
1977 *
1978 * Returns 0 on success or -EMSGSIZE if entry not found
1979 **/
1980static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1981 struct ethtool_rxnfc *cmd,
1982 u32 *rule_locs)
1983{
1984 struct i40e_fdir_filter *rule;
1985 struct hlist_node *node2;
1986 int cnt = 0;
1987
1988 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001989 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001990
1991 hlist_for_each_entry_safe(rule, node2,
1992 &pf->fdir_filter_list, fdir_node) {
1993 if (cnt == cmd->rule_cnt)
1994 return -EMSGSIZE;
1995
1996 rule_locs[cnt] = rule->fd_id;
1997 cnt++;
1998 }
1999
2000 cmd->rule_cnt = cnt;
2001
2002 return 0;
2003}
2004
2005/**
2006 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2007 * @pf: Pointer to the physical function struct
2008 * @cmd: The command to get or set Rx flow classification rules
2009 *
2010 * This function looks up a filter based on the Rx flow classification
2011 * command and fills the flow spec info for it if found
2012 *
2013 * Returns 0 on success or -EINVAL if filter not found
2014 **/
2015static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2016 struct ethtool_rxnfc *cmd)
2017{
2018 struct ethtool_rx_flow_spec *fsp =
2019 (struct ethtool_rx_flow_spec *)&cmd->fs;
2020 struct i40e_fdir_filter *rule = NULL;
2021 struct hlist_node *node2;
2022
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002023 hlist_for_each_entry_safe(rule, node2,
2024 &pf->fdir_filter_list, fdir_node) {
2025 if (fsp->location <= rule->fd_id)
2026 break;
2027 }
2028
2029 if (!rule || fsp->location != rule->fd_id)
2030 return -EINVAL;
2031
2032 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002033 if (fsp->flow_type == IP_USER_FLOW) {
2034 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2035 fsp->h_u.usr_ip4_spec.proto = 0;
2036 fsp->m_u.usr_ip4_spec.proto = 0;
2037 }
2038
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002039 /* Reverse the src and dest notion, since the HW views them from
2040 * Tx perspective where as the user expects it from Rx filter view.
2041 */
2042 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2043 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2044 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2045 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002046
2047 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2048 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2049 else
2050 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002051
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002052 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2053 struct i40e_vsi *vsi;
2054
2055 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2056 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2057 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2058 fsp->m_ext.data[1] = htonl(0x1);
2059 }
2060 }
2061
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002062 return 0;
2063}
2064
2065/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002066 * i40e_get_rxnfc - command to get RX flow classification rules
2067 * @netdev: network interface device structure
2068 * @cmd: ethtool rxnfc command
2069 *
2070 * Returns Success if the command is supported.
2071 **/
2072static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2073 u32 *rule_locs)
2074{
2075 struct i40e_netdev_priv *np = netdev_priv(netdev);
2076 struct i40e_vsi *vsi = np->vsi;
2077 struct i40e_pf *pf = vsi->back;
2078 int ret = -EOPNOTSUPP;
2079
2080 switch (cmd->cmd) {
2081 case ETHTOOL_GRXRINGS:
2082 cmd->data = vsi->alloc_queue_pairs;
2083 ret = 0;
2084 break;
2085 case ETHTOOL_GRXFH:
2086 ret = i40e_get_rss_hash_opts(pf, cmd);
2087 break;
2088 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002089 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002090 /* report total rule count */
2091 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002092 ret = 0;
2093 break;
2094 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002095 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002096 break;
2097 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002098 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2099 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002100 default:
2101 break;
2102 }
2103
2104 return ret;
2105}
2106
2107/**
2108 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2109 * @pf: pointer to the physical function struct
2110 * @cmd: ethtool rxnfc command
2111 *
2112 * Returns Success if the flow input set is supported.
2113 **/
2114static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2115{
2116 struct i40e_hw *hw = &pf->hw;
2117 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2118 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2119
2120 /* RSS does not support anything other than hashing
2121 * to queues on src and dst IPs and ports
2122 */
2123 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2124 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2125 return -EINVAL;
2126
2127 /* We need at least the IP SRC and DEST fields for hashing */
2128 if (!(nfc->data & RXH_IP_SRC) ||
2129 !(nfc->data & RXH_IP_DST))
2130 return -EINVAL;
2131
2132 switch (nfc->flow_type) {
2133 case TCP_V4_FLOW:
2134 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2135 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002136 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002137 break;
2138 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002139 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140 break;
2141 default:
2142 return -EINVAL;
2143 }
2144 break;
2145 case TCP_V6_FLOW:
2146 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2147 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002148 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002149 break;
2150 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002151 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002152 break;
2153 default:
2154 return -EINVAL;
2155 }
2156 break;
2157 case UDP_V4_FLOW:
2158 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2159 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002160 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2161 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002162 break;
2163 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002164 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2165 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002166 break;
2167 default:
2168 return -EINVAL;
2169 }
2170 break;
2171 case UDP_V6_FLOW:
2172 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2173 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002174 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2175 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002176 break;
2177 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002178 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2179 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002180 break;
2181 default:
2182 return -EINVAL;
2183 }
2184 break;
2185 case AH_ESP_V4_FLOW:
2186 case AH_V4_FLOW:
2187 case ESP_V4_FLOW:
2188 case SCTP_V4_FLOW:
2189 if ((nfc->data & RXH_L4_B_0_1) ||
2190 (nfc->data & RXH_L4_B_2_3))
2191 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002192 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002193 break;
2194 case AH_ESP_V6_FLOW:
2195 case AH_V6_FLOW:
2196 case ESP_V6_FLOW:
2197 case SCTP_V6_FLOW:
2198 if ((nfc->data & RXH_L4_B_0_1) ||
2199 (nfc->data & RXH_L4_B_2_3))
2200 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002201 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002202 break;
2203 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002204 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2205 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002206 break;
2207 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002208 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2209 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002210 break;
2211 default:
2212 return -EINVAL;
2213 }
2214
2215 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2216 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2217 i40e_flush(hw);
2218
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002219 /* Save setting for future output/update */
2220 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2221
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002222 return 0;
2223}
2224
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002226 * i40e_match_fdir_input_set - Match a new filter against an existing one
2227 * @rule: The filter already added
2228 * @input: The new filter to comapre against
2229 *
2230 * Returns true if the two input set match
2231 **/
2232static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2233 struct i40e_fdir_filter *input)
2234{
2235 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2236 (rule->src_ip[0] != input->src_ip[0]) ||
2237 (rule->dst_port != input->dst_port) ||
2238 (rule->src_port != input->src_port))
2239 return false;
2240 return true;
2241}
2242
2243/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002244 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2245 * @vsi: Pointer to the targeted VSI
2246 * @input: The filter to update or NULL to indicate deletion
2247 * @sw_idx: Software index to the filter
2248 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002249 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002250 * This function updates (or deletes) a Flow Director entry from
2251 * the hlist of the corresponding PF
2252 *
2253 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002254 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002255static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2256 struct i40e_fdir_filter *input,
2257 u16 sw_idx,
2258 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002259{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002260 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002261 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002262 struct hlist_node *node2;
2263 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002264
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002265 parent = NULL;
2266 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002267
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002268 hlist_for_each_entry_safe(rule, node2,
2269 &pf->fdir_filter_list, fdir_node) {
2270 /* hash found, or no matching entry */
2271 if (rule->fd_id >= sw_idx)
2272 break;
2273 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002274 }
2275
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002276 /* if there is an old rule occupying our place remove it */
2277 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002278 if (input && !i40e_match_fdir_input_set(rule, input))
2279 err = i40e_add_del_fdir(vsi, rule, false);
2280 else if (!input)
2281 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002282 hlist_del(&rule->fdir_node);
2283 kfree(rule);
2284 pf->fdir_pf_active_filters--;
2285 }
2286
2287 /* If no input this was a delete, err should be 0 if a rule was
2288 * successfully found and removed from the list else -EINVAL
2289 */
2290 if (!input)
2291 return err;
2292
2293 /* initialize node and set software index */
2294 INIT_HLIST_NODE(&input->fdir_node);
2295
2296 /* add filter to the list */
2297 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002298 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002299 else
2300 hlist_add_head(&input->fdir_node,
2301 &pf->fdir_filter_list);
2302
2303 /* update counts */
2304 pf->fdir_pf_active_filters++;
2305
2306 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002307}
2308
2309/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002310 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2311 * @vsi: Pointer to the targeted VSI
2312 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002313 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002314 * The function removes a Flow Director filter entry from the
2315 * hlist of the corresponding PF
2316 *
2317 * Returns 0 on success
2318 */
2319static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2320 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002321{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002322 struct ethtool_rx_flow_spec *fsp =
2323 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002324 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002325 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002326
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002327 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2328 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2329 return -EBUSY;
2330
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002331 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2332 return -EBUSY;
2333
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002334 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002335
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002336 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002337 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002338}
2339
2340/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002341 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002342 * @vsi: pointer to the targeted VSI
2343 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002344 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002345 * Add Flow Director filters for a specific flow spec based on their
2346 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002347 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002348static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2349 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002350{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002351 struct ethtool_rx_flow_spec *fsp;
2352 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002353 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002354 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002355 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002356
2357 if (!vsi)
2358 return -EINVAL;
2359
2360 pf = vsi->back;
2361
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002362 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2363 return -EOPNOTSUPP;
2364
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002365 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002366 return -ENOSPC;
2367
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002368 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2369 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2370 return -EBUSY;
2371
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002372 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2373 return -EBUSY;
2374
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002375 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2376
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002377 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2378 pf->hw.func_caps.fd_filters_guaranteed)) {
2379 return -EINVAL;
2380 }
2381
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002382 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2383 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002384 return -EINVAL;
2385
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002386 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002387
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002388 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002389 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002390
2391 input->fd_id = fsp->location;
2392
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002393 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2394 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2395 else
2396 input->dest_ctl =
2397 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2398
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002399 input->q_index = fsp->ring_cookie;
2400 input->flex_off = 0;
2401 input->pctype = 0;
2402 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002403 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002404 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002405 input->flow_type = fsp->flow_type;
2406 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002407
2408 /* Reverse the src and dest notion, since the HW expects them to be from
2409 * Tx perspective where as the input from user is from Rx filter view.
2410 */
2411 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2412 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2413 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2414 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002415
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002416 if (ntohl(fsp->m_ext.data[1])) {
2417 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2418 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2419 goto free_input;
2420 }
2421 vf_id = ntohl(fsp->h_ext.data[1]);
2422 /* Find vsi id from vf id and override dest vsi */
2423 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2424 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2425 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2426 goto free_input;
2427 }
2428 }
2429
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002430 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002431free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002432 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002433 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002434 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002435 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002436
2437 return ret;
2438}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002439
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002440/**
2441 * i40e_set_rxnfc - command to set RX flow classification rules
2442 * @netdev: network interface device structure
2443 * @cmd: ethtool rxnfc command
2444 *
2445 * Returns Success if the command is supported.
2446 **/
2447static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2448{
2449 struct i40e_netdev_priv *np = netdev_priv(netdev);
2450 struct i40e_vsi *vsi = np->vsi;
2451 struct i40e_pf *pf = vsi->back;
2452 int ret = -EOPNOTSUPP;
2453
2454 switch (cmd->cmd) {
2455 case ETHTOOL_SRXFH:
2456 ret = i40e_set_rss_hash_opt(pf, cmd);
2457 break;
2458 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002459 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002460 break;
2461 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002462 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002463 break;
2464 default:
2465 break;
2466 }
2467
2468 return ret;
2469}
2470
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002471/**
2472 * i40e_max_channels - get Max number of combined channels supported
2473 * @vsi: vsi pointer
2474 **/
2475static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2476{
2477 /* TODO: This code assumes DCB and FD is disabled for now. */
2478 return vsi->alloc_queue_pairs;
2479}
2480
2481/**
2482 * i40e_get_channels - Get the current channels enabled and max supported etc.
2483 * @netdev: network interface device structure
2484 * @ch: ethtool channels structure
2485 *
2486 * We don't support separate tx and rx queues as channels. The other count
2487 * represents how many queues are being used for control. max_combined counts
2488 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2489 * q_vectors since we support a lot more queue pairs than q_vectors.
2490 **/
2491static void i40e_get_channels(struct net_device *dev,
2492 struct ethtool_channels *ch)
2493{
2494 struct i40e_netdev_priv *np = netdev_priv(dev);
2495 struct i40e_vsi *vsi = np->vsi;
2496 struct i40e_pf *pf = vsi->back;
2497
2498 /* report maximum channels */
2499 ch->max_combined = i40e_max_channels(vsi);
2500
2501 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002502 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002503 ch->max_other = ch->other_count;
2504
2505 /* Note: This code assumes DCB is disabled for now. */
2506 ch->combined_count = vsi->num_queue_pairs;
2507}
2508
2509/**
2510 * i40e_set_channels - Set the new channels count.
2511 * @netdev: network interface device structure
2512 * @ch: ethtool channels structure
2513 *
2514 * The new channels count may not be the same as requested by the user
2515 * since it gets rounded down to a power of 2 value.
2516 **/
2517static int i40e_set_channels(struct net_device *dev,
2518 struct ethtool_channels *ch)
2519{
2520 struct i40e_netdev_priv *np = netdev_priv(dev);
2521 unsigned int count = ch->combined_count;
2522 struct i40e_vsi *vsi = np->vsi;
2523 struct i40e_pf *pf = vsi->back;
2524 int new_count;
2525
2526 /* We do not support setting channels for any other VSI at present */
2527 if (vsi->type != I40E_VSI_MAIN)
2528 return -EINVAL;
2529
2530 /* verify they are not requesting separate vectors */
2531 if (!count || ch->rx_count || ch->tx_count)
2532 return -EINVAL;
2533
2534 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002535 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002536 return -EINVAL;
2537
2538 /* verify the number of channels does not exceed hardware limits */
2539 if (count > i40e_max_channels(vsi))
2540 return -EINVAL;
2541
2542 /* update feature limits from largest to smallest supported values */
2543 /* TODO: Flow director limit, DCB etc */
2544
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002545 /* use rss_reconfig to rebuild with new queue count and update traffic
2546 * class queue mapping
2547 */
2548 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002549 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002550 return 0;
2551 else
2552 return -EINVAL;
2553}
2554
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002555#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2556/**
2557 * i40e_get_rxfh_key_size - get the RSS hash key size
2558 * @netdev: network interface device structure
2559 *
2560 * Returns the table size.
2561 **/
2562static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2563{
2564 return I40E_HKEY_ARRAY_SIZE;
2565}
2566
2567/**
2568 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2569 * @netdev: network interface device structure
2570 *
2571 * Returns the table size.
2572 **/
2573static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2574{
2575 return I40E_HLUT_ARRAY_SIZE;
2576}
2577
2578static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2579 u8 *hfunc)
2580{
2581 struct i40e_netdev_priv *np = netdev_priv(netdev);
2582 struct i40e_vsi *vsi = np->vsi;
2583 struct i40e_pf *pf = vsi->back;
2584 struct i40e_hw *hw = &pf->hw;
2585 u32 reg_val;
2586 int i, j;
2587
2588 if (hfunc)
2589 *hfunc = ETH_RSS_HASH_TOP;
2590
2591 if (!indir)
2592 return 0;
2593
2594 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2595 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2596 indir[j++] = reg_val & 0xff;
2597 indir[j++] = (reg_val >> 8) & 0xff;
2598 indir[j++] = (reg_val >> 16) & 0xff;
2599 indir[j++] = (reg_val >> 24) & 0xff;
2600 }
2601
2602 if (key) {
2603 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2604 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2605 key[j++] = (u8)(reg_val & 0xff);
2606 key[j++] = (u8)((reg_val >> 8) & 0xff);
2607 key[j++] = (u8)((reg_val >> 16) & 0xff);
2608 key[j++] = (u8)((reg_val >> 24) & 0xff);
2609 }
2610 }
2611 return 0;
2612}
2613
2614/**
2615 * i40e_set_rxfh - set the rx flow hash indirection table
2616 * @netdev: network interface device structure
2617 * @indir: indirection table
2618 * @key: hash key
2619 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002620 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002621 * returns 0 after programming the table.
2622 **/
2623static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2624 const u8 *key, const u8 hfunc)
2625{
2626 struct i40e_netdev_priv *np = netdev_priv(netdev);
2627 struct i40e_vsi *vsi = np->vsi;
2628 struct i40e_pf *pf = vsi->back;
2629 struct i40e_hw *hw = &pf->hw;
2630 u32 reg_val;
2631 int i, j;
2632
2633 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2634 return -EOPNOTSUPP;
2635
2636 if (!indir)
2637 return 0;
2638
2639 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2640 reg_val = indir[j++];
2641 reg_val |= indir[j++] << 8;
2642 reg_val |= indir[j++] << 16;
2643 reg_val |= indir[j++] << 24;
2644 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2645 }
2646
2647 if (key) {
2648 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2649 reg_val = key[j++];
2650 reg_val |= key[j++] << 8;
2651 reg_val |= key[j++] << 16;
2652 reg_val |= key[j++] << 24;
2653 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2654 }
2655 }
2656 return 0;
2657}
2658
Greg Rose7e45ab42015-02-06 08:52:19 +00002659/**
2660 * i40e_get_priv_flags - report device private flags
2661 * @dev: network interface device structure
2662 *
2663 * The get string set count and the string set should be matched for each
2664 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2665 * array.
2666 *
2667 * Returns a u32 bitmap of flags.
2668 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002669static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002670{
2671 struct i40e_netdev_priv *np = netdev_priv(dev);
2672 struct i40e_vsi *vsi = np->vsi;
2673 struct i40e_pf *pf = vsi->back;
2674 u32 ret_flags = 0;
2675
2676 ret_flags |= pf->hw.func_caps.npar_enable ?
2677 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002678 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2679 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002680 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2681 I40E_PRIV_FLAGS_FD_ATR : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002682
2683 return ret_flags;
2684}
2685
Shannon Nelson9ac77262015-08-27 11:42:40 -04002686/**
2687 * i40e_set_priv_flags - set private flags
2688 * @dev: network interface device structure
2689 * @flags: bit flags to be set
2690 **/
2691static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2692{
2693 struct i40e_netdev_priv *np = netdev_priv(dev);
2694 struct i40e_vsi *vsi = np->vsi;
2695 struct i40e_pf *pf = vsi->back;
2696
2697 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2698 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2699 else
2700 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2701
Jesse Brandeburgef171782015-09-03 17:18:49 -04002702 /* allow the user to control the state of the Flow
2703 * Director ATR (Application Targeted Routing) feature
2704 * of the driver
2705 */
2706 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2707 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2708 } else {
2709 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2710 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2711 }
2712
Shannon Nelson9ac77262015-08-27 11:42:40 -04002713 return 0;
2714}
2715
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002716static const struct ethtool_ops i40e_ethtool_ops = {
2717 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002718 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002719 .get_drvinfo = i40e_get_drvinfo,
2720 .get_regs_len = i40e_get_regs_len,
2721 .get_regs = i40e_get_regs,
2722 .nway_reset = i40e_nway_reset,
2723 .get_link = ethtool_op_get_link,
2724 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002725 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002726 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002727 .get_eeprom_len = i40e_get_eeprom_len,
2728 .get_eeprom = i40e_get_eeprom,
2729 .get_ringparam = i40e_get_ringparam,
2730 .set_ringparam = i40e_set_ringparam,
2731 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002732 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002733 .get_msglevel = i40e_get_msglevel,
2734 .set_msglevel = i40e_set_msglevel,
2735 .get_rxnfc = i40e_get_rxnfc,
2736 .set_rxnfc = i40e_set_rxnfc,
2737 .self_test = i40e_diag_test,
2738 .get_strings = i40e_get_strings,
2739 .set_phys_id = i40e_set_phys_id,
2740 .get_sset_count = i40e_get_sset_count,
2741 .get_ethtool_stats = i40e_get_ethtool_stats,
2742 .get_coalesce = i40e_get_coalesce,
2743 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002744 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2745 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2746 .get_rxfh = i40e_get_rxfh,
2747 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002748 .get_channels = i40e_get_channels,
2749 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002750 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002751 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002752 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002753};
2754
2755void i40e_set_ethtool_ops(struct net_device *netdev)
2756{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002757 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002758}