blob: 812c954934134b54ef17e02bd1ee91e71d28f088 [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),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040091 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Shannon Nelson41a9e552014-04-23 04:50:20 +000092};
93
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000094/* These PF_STATs might look like duplicates of some NETDEV_STATs,
95 * but they are separate. This device supports Virtualization, and
96 * as such might have several netdevs supporting VMDq and FCoE going
97 * through a single port. The NETDEV_STATs are for individual netdevs
98 * seen at the top of the stack, and the PF_STATs are for the physical
99 * function at the bottom of the stack hosting those netdevs.
100 *
101 * The PF_STATs are appended to the netdev stats only when ethtool -S
102 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
103 */
104static struct i40e_stats i40e_gstrings_stats[] = {
105 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
106 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000107 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
108 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
109 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
110 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
111 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
112 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000113 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
114 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400116 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
118 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
119 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000120 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000121 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000122 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
123 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
124 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
125 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
126 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
127 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
128 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
129 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
130 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
131 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
132 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
133 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
134 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
135 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
136 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
137 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
138 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
139 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
140 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
141 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
142 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
143 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
144 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
145 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800146 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000147 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f42014-07-09 07:46:23 +0000148 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000149 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400150 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400151 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400153 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000154
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000155 /* LPI stats */
156 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
157 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
158 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
159 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000160};
161
Vasu Dev38e00432014-08-01 13:27:03 -0700162#ifdef I40E_FCOE
163static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
164 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
165 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
166 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
167 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
168 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
169 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
170 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
171 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
172};
173
174#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000175#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000176 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
177 * 2 /* Tx and Rx together */ \
178 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000179#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
180#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000181#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700182#ifdef I40E_FCOE
183#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
184#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
185 I40E_FCOE_STATS_LEN + \
186 I40E_MISC_STATS_LEN + \
187 I40E_QUEUE_STATS_LEN((n)))
188#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000190 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700192#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000193#define I40E_PFC_STATS_LEN ( \
194 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
199 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400200#define I40E_VEB_TC_STATS_LEN ( \
201 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
205 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000206#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400207#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000208#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
209 I40E_PFC_STATS_LEN + \
210 I40E_VSI_STATS_LEN((n)))
211
212enum i40e_ethtool_test_id {
213 I40E_ETH_TEST_REG = 0,
214 I40E_ETH_TEST_EEPROM,
215 I40E_ETH_TEST_INTR,
216 I40E_ETH_TEST_LOOPBACK,
217 I40E_ETH_TEST_LINK,
218};
219
220static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
221 "Register test (offline)",
222 "Eeprom test (offline)",
223 "Interrupt test (offline)",
224 "Loopback test (offline)",
225 "Link test (on/offline)"
226};
227
228#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
229
Greg Rose7e45ab42015-02-06 08:52:19 +0000230static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
231 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400232 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400233 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400234 "veb-stats",
Jesse Brandeburg827de392015-11-06 15:26:07 -0800235 "packet-split",
Greg Rose7e45ab42015-02-06 08:52:19 +0000236};
237
Shannon Nelson9ac77262015-08-27 11:42:40 -0400238#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000239
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000240/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000241 * i40e_partition_setting_complaint - generic complaint for MFP restriction
242 * @pf: the PF struct
243 **/
244static void i40e_partition_setting_complaint(struct i40e_pf *pf)
245{
246 dev_info(&pf->pdev->dev,
247 "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");
248}
249
250/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000251 * i40e_get_settings_link_up - Get the Link settings for when link is up
252 * @hw: hw structure
253 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000255 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000256 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000257static void i40e_get_settings_link_up(struct i40e_hw *hw,
258 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400259 struct net_device *netdev,
260 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000261{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000263 u32 link_speed = hw_link_info->link_speed;
264
Catherine Sullivane8278452015-02-06 08:52:08 +0000265 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000266 switch (hw_link_info->phy_type) {
267 case I40E_PHY_TYPE_40GBASE_CR4:
268 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000269 ecmd->supported = SUPPORTED_Autoneg |
270 SUPPORTED_40000baseCR4_Full;
271 ecmd->advertising = ADVERTISED_Autoneg |
272 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000273 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000274 case I40E_PHY_TYPE_XLAUI:
275 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000276 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000277 ecmd->supported = SUPPORTED_40000baseCR4_Full;
278 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000279 case I40E_PHY_TYPE_40GBASE_SR4:
280 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000281 break;
282 case I40E_PHY_TYPE_40GBASE_LR4:
283 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000284 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000285 case I40E_PHY_TYPE_10GBASE_SR:
286 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000287 case I40E_PHY_TYPE_1000BASE_SX:
288 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400289 ecmd->supported = SUPPORTED_10000baseT_Full;
290 if (hw_link_info->module_type[2] &
291 I40E_MODULE_TYPE_1000BASE_SX ||
292 hw_link_info->module_type[2] &
293 I40E_MODULE_TYPE_1000BASE_LX) {
294 ecmd->supported |= SUPPORTED_1000baseT_Full;
295 if (hw_link_info->requested_speeds &
296 I40E_LINK_SPEED_1GB)
297 ecmd->advertising |= ADVERTISED_1000baseT_Full;
298 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000299 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
300 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000302 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000303 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000304 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000305 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400306 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000307 ecmd->advertising = ADVERTISED_Autoneg;
308 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
309 ecmd->advertising |= ADVERTISED_10000baseT_Full;
310 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
311 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400312 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400313 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
314 ecmd->supported = SUPPORTED_Autoneg |
315 SUPPORTED_1000baseT_Full;
316 ecmd->advertising = ADVERTISED_Autoneg |
317 ADVERTISED_1000baseT_Full;
318 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400319 case I40E_PHY_TYPE_100BASE_TX:
320 ecmd->supported = SUPPORTED_Autoneg |
321 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000322 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
323 ecmd->advertising |= ADVERTISED_100baseT_Full;
324 break;
325 case I40E_PHY_TYPE_10GBASE_CR1_CU:
326 case I40E_PHY_TYPE_10GBASE_CR1:
327 ecmd->supported = SUPPORTED_Autoneg |
328 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000329 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000330 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000331 break;
332 case I40E_PHY_TYPE_XAUI:
333 case I40E_PHY_TYPE_XFI:
334 case I40E_PHY_TYPE_SFI:
335 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000336 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000337 ecmd->supported = SUPPORTED_10000baseT_Full;
338 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000339 case I40E_PHY_TYPE_SGMII:
340 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400341 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000342 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
343 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800344 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400345 ecmd->supported |= SUPPORTED_100baseT_Full;
346 if (hw_link_info->requested_speeds &
347 I40E_LINK_SPEED_100MB)
348 ecmd->advertising |= ADVERTISED_100baseT_Full;
349 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000350 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400351 /* Backplane is set based on supported phy types in get_settings
352 * so don't set anything here but don't warn either
353 */
354 case I40E_PHY_TYPE_40GBASE_KR4:
355 case I40E_PHY_TYPE_20GBASE_KR2:
356 case I40E_PHY_TYPE_10GBASE_KR:
357 case I40E_PHY_TYPE_10GBASE_KX4:
358 case I40E_PHY_TYPE_1000BASE_KX:
359 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000360 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000361 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000362 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
363 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000364 }
365
Catherine Sullivane8278452015-02-06 08:52:08 +0000366 /* Set speed and duplex */
367 switch (link_speed) {
368 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400369 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000370 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700371 case I40E_LINK_SPEED_20GB:
372 ethtool_cmd_speed_set(ecmd, SPEED_20000);
373 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000374 case I40E_LINK_SPEED_10GB:
375 ethtool_cmd_speed_set(ecmd, SPEED_10000);
376 break;
377 case I40E_LINK_SPEED_1GB:
378 ethtool_cmd_speed_set(ecmd, SPEED_1000);
379 break;
380 case I40E_LINK_SPEED_100MB:
381 ethtool_cmd_speed_set(ecmd, SPEED_100);
382 break;
383 default:
384 break;
385 }
386 ecmd->duplex = DUPLEX_FULL;
387}
388
389/**
390 * i40e_get_settings_link_down - Get the Link settings for when link is down
391 * @hw: hw structure
392 * @ecmd: ethtool command to fill in
393 *
394 * Reports link settings that can be determined when link is down
395 **/
396static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400397 struct ethtool_cmd *ecmd,
398 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000399{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400400 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000401
402 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400403 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000404 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400405 ecmd->supported = 0x0;
406 ecmd->advertising = 0x0;
407 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
408 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400409 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400410 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400411 ADVERTISED_1000baseT_Full;
412 if (pf->hw.mac.type == I40E_MAC_X722) {
413 ecmd->supported |= SUPPORTED_100baseT_Full;
414 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivanf8db54cc2015-12-22 14:25:14 -0800415 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
416 ecmd->supported |= SUPPORTED_100baseT_Full;
417 ecmd->advertising |= ADVERTISED_100baseT_Full;
418 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400419 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000420 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400421 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
422 phy_types & I40E_CAP_PHY_TYPE_XFI ||
423 phy_types & I40E_CAP_PHY_TYPE_SFI ||
424 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
425 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
426 ecmd->supported |= SUPPORTED_10000baseT_Full;
427 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
430 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
431 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
432 ecmd->supported |= SUPPORTED_Autoneg |
433 SUPPORTED_10000baseT_Full;
434 ecmd->advertising |= ADVERTISED_Autoneg |
435 ADVERTISED_10000baseT_Full;
436 }
437 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
438 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
439 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
440 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
441 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
442 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
443 ecmd->supported |= SUPPORTED_Autoneg |
444 SUPPORTED_40000baseCR4_Full;
445 ecmd->advertising |= ADVERTISED_Autoneg |
446 ADVERTISED_40000baseCR4_Full;
447 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400448 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
449 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400450 ecmd->supported |= SUPPORTED_Autoneg |
451 SUPPORTED_100baseT_Full;
452 ecmd->advertising |= ADVERTISED_Autoneg |
453 ADVERTISED_100baseT_Full;
454 }
455 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
456 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
457 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
458 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
459 ecmd->supported |= SUPPORTED_Autoneg |
460 SUPPORTED_1000baseT_Full;
461 ecmd->advertising |= ADVERTISED_Autoneg |
462 ADVERTISED_1000baseT_Full;
463 }
464 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
465 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
466 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
467 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000468
469 /* With no link speed and duplex are unknown */
470 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
471 ecmd->duplex = DUPLEX_UNKNOWN;
472}
473
474/**
475 * i40e_get_settings - Get Link Speed and Duplex settings
476 * @netdev: network interface device structure
477 * @ecmd: ethtool command
478 *
479 * Reports speed/duplex settings based on media_type
480 **/
481static int i40e_get_settings(struct net_device *netdev,
482 struct ethtool_cmd *ecmd)
483{
484 struct i40e_netdev_priv *np = netdev_priv(netdev);
485 struct i40e_pf *pf = np->vsi->back;
486 struct i40e_hw *hw = &pf->hw;
487 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
488 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
489
490 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400491 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000492 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400493 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000494
495 /* Now set the settings that don't rely on link being up/down */
496
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400497 /* For backplane, supported and advertised are only reliant on the
498 * phy types the NVM specifies are supported.
499 */
500 if (hw->device_id == I40E_DEV_ID_KX_B ||
501 hw->device_id == I40E_DEV_ID_KX_C ||
502 hw->device_id == I40E_DEV_ID_20G_KR2 ||
503 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
504 ecmd->supported = SUPPORTED_Autoneg;
505 ecmd->advertising = ADVERTISED_Autoneg;
506 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
507 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
508 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
509 }
510 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
511 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
512 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
513 }
514 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
515 ecmd->supported |= SUPPORTED_10000baseKR_Full;
516 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
517 }
518 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
519 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
520 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
521 }
522 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
523 ecmd->supported |= SUPPORTED_1000baseKX_Full;
524 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
525 }
526 }
527
Catherine Sullivane8278452015-02-06 08:52:08 +0000528 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000529 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
530 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000531
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000532 switch (hw->phy.media_type) {
533 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000534 ecmd->supported |= SUPPORTED_Autoneg |
535 SUPPORTED_Backplane;
536 ecmd->advertising |= ADVERTISED_Autoneg |
537 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000538 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000539 break;
540 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000541 ecmd->supported |= SUPPORTED_TP;
542 ecmd->advertising |= ADVERTISED_TP;
543 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000544 break;
545 case I40E_MEDIA_TYPE_DA:
546 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000547 ecmd->supported |= SUPPORTED_FIBRE;
548 ecmd->advertising |= ADVERTISED_FIBRE;
549 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000550 break;
551 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000552 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000553 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000554 break;
555 case I40E_MEDIA_TYPE_UNKNOWN:
556 default:
557 ecmd->port = PORT_OTHER;
558 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000559 }
560
Catherine Sullivane8278452015-02-06 08:52:08 +0000561 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000562 ecmd->transceiver = XCVR_EXTERNAL;
563
Catherine Sullivane8278452015-02-06 08:52:08 +0000564 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000565 ecmd->supported |= SUPPORTED_Pause;
566
Catherine Sullivane8278452015-02-06 08:52:08 +0000567 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000568 case I40E_FC_FULL:
569 ecmd->advertising |= ADVERTISED_Pause;
570 break;
571 case I40E_FC_TX_PAUSE:
572 ecmd->advertising |= ADVERTISED_Asym_Pause;
573 break;
574 case I40E_FC_RX_PAUSE:
575 ecmd->advertising |= (ADVERTISED_Pause |
576 ADVERTISED_Asym_Pause);
577 break;
578 default:
579 ecmd->advertising &= ~(ADVERTISED_Pause |
580 ADVERTISED_Asym_Pause);
581 break;
582 }
583
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000584 return 0;
585}
586
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000587/**
588 * i40e_set_settings - Set Speed and Duplex
589 * @netdev: network interface device structure
590 * @ecmd: ethtool command
591 *
592 * Set speed/duplex per media_types advertised/forced
593 **/
594static int i40e_set_settings(struct net_device *netdev,
595 struct ethtool_cmd *ecmd)
596{
597 struct i40e_netdev_priv *np = netdev_priv(netdev);
598 struct i40e_aq_get_phy_abilities_resp abilities;
599 struct i40e_aq_set_phy_config config;
600 struct i40e_pf *pf = np->vsi->back;
601 struct i40e_vsi *vsi = np->vsi;
602 struct i40e_hw *hw = &pf->hw;
603 struct ethtool_cmd safe_ecmd;
604 i40e_status status = 0;
605 bool change = false;
606 int err = 0;
607 u8 autoneg;
608 u32 advertise;
609
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000610 /* Changing port settings is not supported if this isn't the
611 * port's controlling PF
612 */
613 if (hw->partition_id != 1) {
614 i40e_partition_setting_complaint(pf);
615 return -EOPNOTSUPP;
616 }
617
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000618 if (vsi != pf->vsi[pf->lan_vsi])
619 return -EOPNOTSUPP;
620
621 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
622 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000623 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
624 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000625 return -EOPNOTSUPP;
626
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400627 if (hw->device_id == I40E_DEV_ID_KX_B ||
628 hw->device_id == I40E_DEV_ID_KX_C ||
629 hw->device_id == I40E_DEV_ID_20G_KR2 ||
630 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
631 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
632 return -EOPNOTSUPP;
633 }
634
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000635 /* get our own copy of the bits to check against */
636 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
637 i40e_get_settings(netdev, &safe_ecmd);
638
639 /* save autoneg and speed out of ecmd */
640 autoneg = ecmd->autoneg;
641 advertise = ecmd->advertising;
642
643 /* set autoneg and speed back to what they currently are */
644 ecmd->autoneg = safe_ecmd.autoneg;
645 ecmd->advertising = safe_ecmd.advertising;
646
647 ecmd->cmd = safe_ecmd.cmd;
648 /* If ecmd and safe_ecmd are not the same now, then they are
649 * trying to set something that we do not support
650 */
651 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
652 return -EOPNOTSUPP;
653
654 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
655 usleep_range(1000, 2000);
656
657 /* Get the current phy config */
658 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
659 NULL);
660 if (status)
661 return -EAGAIN;
662
Catherine Sullivan124ed152014-07-12 07:28:12 +0000663 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000664 * set below
665 */
666 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000667 config.abilities = abilities.abilities;
668
669 /* Check autoneg */
670 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000671 /* If autoneg was not already enabled */
672 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400673 /* If autoneg is not supported, return error */
674 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
675 netdev_info(netdev, "Autoneg not supported on this phy\n");
676 return -EINVAL;
677 }
678 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000679 config.abilities = abilities.abilities |
680 I40E_AQ_PHY_ENABLE_AN;
681 change = true;
682 }
683 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000684 /* If autoneg is currently enabled */
685 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400686 /* If autoneg is supported 10GBASE_T is the only PHY
687 * that can disable it, so otherwise return error
688 */
689 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
690 hw->phy.link_info.phy_type !=
691 I40E_PHY_TYPE_10GBASE_T) {
692 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
693 return -EINVAL;
694 }
695 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000696 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000697 ~I40E_AQ_PHY_ENABLE_AN;
698 change = true;
699 }
700 }
701
702 if (advertise & ~safe_ecmd.supported)
703 return -EINVAL;
704
705 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000706 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000707 if (advertise & ADVERTISED_1000baseT_Full ||
708 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000709 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000710 if (advertise & ADVERTISED_10000baseT_Full ||
711 advertise & ADVERTISED_10000baseKX4_Full ||
712 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000713 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700714 if (advertise & ADVERTISED_20000baseKR2_Full)
715 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000716 if (advertise & ADVERTISED_40000baseKR4_Full ||
717 advertise & ADVERTISED_40000baseCR4_Full ||
718 advertise & ADVERTISED_40000baseSR4_Full ||
719 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000720 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000721
Catherine Sullivan0002e112015-08-26 15:14:16 -0400722 /* If speed didn't get set, set it to what it currently is.
723 * This is needed because if advertise is 0 (as it is when autoneg
724 * is disabled) then speed won't get set.
725 */
726 if (!config.link_speed)
727 config.link_speed = abilities.link_speed;
728
Catherine Sullivan124ed152014-07-12 07:28:12 +0000729 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000730 /* copy over the rest of the abilities */
731 config.phy_type = abilities.phy_type;
732 config.eee_capability = abilities.eee_capability;
733 config.eeer = abilities.eeer_val;
734 config.low_power_ctrl = abilities.d3_lpan;
735
Catherine Sullivane8278452015-02-06 08:52:08 +0000736 /* save the requested speeds */
737 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000738 /* set link and auto negotiation so changes take effect */
739 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
740 /* If link is up put link down */
741 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
742 /* Tell the OS link is going down, the link will go
743 * back up when fw says it is ready asynchronously
744 */
Matt Jaredc156f852015-08-27 11:42:39 -0400745 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000746 netif_carrier_off(netdev);
747 netif_tx_stop_all_queues(netdev);
748 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000749
750 /* make the aq call */
751 status = i40e_aq_set_phy_config(hw, &config, NULL);
752 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400753 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
754 i40e_stat_str(hw, status),
755 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000756 return -EAGAIN;
757 }
758
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400759 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000760 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400761 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
762 i40e_stat_str(hw, status),
763 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000764
765 } else {
766 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
767 }
768
769 return err;
770}
771
Jesse Brandeburga6599722014-06-04 08:45:25 +0000772static int i40e_nway_reset(struct net_device *netdev)
773{
774 /* restart autonegotiation */
775 struct i40e_netdev_priv *np = netdev_priv(netdev);
776 struct i40e_pf *pf = np->vsi->back;
777 struct i40e_hw *hw = &pf->hw;
778 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
779 i40e_status ret = 0;
780
781 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
782 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400783 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
784 i40e_stat_str(hw, ret),
785 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000786 return -EIO;
787 }
788
789 return 0;
790}
791
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000792/**
793 * i40e_get_pauseparam - Get Flow Control status
794 * Return tx/rx-pause status
795 **/
796static void i40e_get_pauseparam(struct net_device *netdev,
797 struct ethtool_pauseparam *pause)
798{
799 struct i40e_netdev_priv *np = netdev_priv(netdev);
800 struct i40e_pf *pf = np->vsi->back;
801 struct i40e_hw *hw = &pf->hw;
802 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000803 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000804
805 pause->autoneg =
806 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
807 AUTONEG_ENABLE : AUTONEG_DISABLE);
808
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000809 /* PFC enabled so report LFC as off */
810 if (dcbx_cfg->pfc.pfcenable) {
811 pause->rx_pause = 0;
812 pause->tx_pause = 0;
813 return;
814 }
815
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000816 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000817 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000818 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000819 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000820 } else if (hw->fc.current_mode == I40E_FC_FULL) {
821 pause->rx_pause = 1;
822 pause->tx_pause = 1;
823 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000824}
825
Catherine Sullivan2becc352014-06-04 08:45:27 +0000826/**
827 * i40e_set_pauseparam - Set Flow Control parameter
828 * @netdev: network interface device structure
829 * @pause: return tx/rx flow control status
830 **/
831static int i40e_set_pauseparam(struct net_device *netdev,
832 struct ethtool_pauseparam *pause)
833{
834 struct i40e_netdev_priv *np = netdev_priv(netdev);
835 struct i40e_pf *pf = np->vsi->back;
836 struct i40e_vsi *vsi = np->vsi;
837 struct i40e_hw *hw = &pf->hw;
838 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000839 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000840 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
841 i40e_status status;
842 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000843 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000844
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000845 /* Changing the port's flow control is not supported if this isn't the
846 * port's controlling PF
847 */
848 if (hw->partition_id != 1) {
849 i40e_partition_setting_complaint(pf);
850 return -EOPNOTSUPP;
851 }
852
Catherine Sullivan2becc352014-06-04 08:45:27 +0000853 if (vsi != pf->vsi[pf->lan_vsi])
854 return -EOPNOTSUPP;
855
856 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
857 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
858 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
859 return -EOPNOTSUPP;
860 }
861
862 /* If we have link and don't have autoneg */
863 if (!test_bit(__I40E_DOWN, &pf->state) &&
864 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
865 /* Send message that it might not necessarily work*/
866 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
867 }
868
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000869 if (dcbx_cfg->pfc.pfcenable) {
870 netdev_info(netdev,
871 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000872 return -EOPNOTSUPP;
873 }
874
875 if (pause->rx_pause && pause->tx_pause)
876 hw->fc.requested_mode = I40E_FC_FULL;
877 else if (pause->rx_pause && !pause->tx_pause)
878 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
879 else if (!pause->rx_pause && pause->tx_pause)
880 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
881 else if (!pause->rx_pause && !pause->tx_pause)
882 hw->fc.requested_mode = I40E_FC_NONE;
883 else
884 return -EINVAL;
885
Catherine Sullivan94128512014-07-12 07:28:16 +0000886 /* Tell the OS link is going down, the link will go back up when fw
887 * says it is ready asynchronously
888 */
Matt Jaredc156f852015-08-27 11:42:39 -0400889 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000890 netif_carrier_off(netdev);
891 netif_tx_stop_all_queues(netdev);
892
Catherine Sullivan2becc352014-06-04 08:45:27 +0000893 /* Set the fc mode and only restart an if link is up*/
894 status = i40e_set_fc(hw, &aq_failures, link_up);
895
896 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400897 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
898 i40e_stat_str(hw, status),
899 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000900 err = -EAGAIN;
901 }
902 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400903 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
904 i40e_stat_str(hw, status),
905 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000906 err = -EAGAIN;
907 }
908 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400909 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
910 i40e_stat_str(hw, status),
911 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000912 err = -EAGAIN;
913 }
914
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000915 if (!test_bit(__I40E_DOWN, &pf->state)) {
916 /* Give it a little more time to try to come back */
917 msleep(75);
918 if (!test_bit(__I40E_DOWN, &pf->state))
919 return i40e_nway_reset(netdev);
920 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000921
922 return err;
923}
924
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000925static u32 i40e_get_msglevel(struct net_device *netdev)
926{
927 struct i40e_netdev_priv *np = netdev_priv(netdev);
928 struct i40e_pf *pf = np->vsi->back;
929
930 return pf->msg_enable;
931}
932
933static void i40e_set_msglevel(struct net_device *netdev, u32 data)
934{
935 struct i40e_netdev_priv *np = netdev_priv(netdev);
936 struct i40e_pf *pf = np->vsi->back;
937
938 if (I40E_DEBUG_USER & data)
939 pf->hw.debug_mask = data;
940 pf->msg_enable = data;
941}
942
943static int i40e_get_regs_len(struct net_device *netdev)
944{
945 int reg_count = 0;
946 int i;
947
948 for (i = 0; i40e_reg_list[i].offset != 0; i++)
949 reg_count += i40e_reg_list[i].elements;
950
951 return reg_count * sizeof(u32);
952}
953
954static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
955 void *p)
956{
957 struct i40e_netdev_priv *np = netdev_priv(netdev);
958 struct i40e_pf *pf = np->vsi->back;
959 struct i40e_hw *hw = &pf->hw;
960 u32 *reg_buf = p;
961 int i, j, ri;
962 u32 reg;
963
964 /* Tell ethtool which driver-version-specific regs output we have.
965 *
966 * At some point, if we have ethtool doing special formatting of
967 * this data, it will rely on this version number to know how to
968 * interpret things. Hence, this needs to be updated if/when the
969 * diags register table is changed.
970 */
971 regs->version = 1;
972
973 /* loop through the diags reg table for what to print */
974 ri = 0;
975 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
976 for (j = 0; j < i40e_reg_list[i].elements; j++) {
977 reg = i40e_reg_list[i].offset
978 + (j * i40e_reg_list[i].stride);
979 reg_buf[ri++] = rd32(hw, reg);
980 }
981 }
982
983}
984
985static int i40e_get_eeprom(struct net_device *netdev,
986 struct ethtool_eeprom *eeprom, u8 *bytes)
987{
988 struct i40e_netdev_priv *np = netdev_priv(netdev);
989 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000990 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000991 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000992 u8 *eeprom_buff;
993 u16 i, sectors;
994 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000995 u32 magic;
996
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000997#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000998 if (eeprom->len == 0)
999 return -EINVAL;
1000
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001001 /* check for NVMUpdate access method */
1002 magic = hw->vendor_id | (hw->device_id << 16);
1003 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +00001004 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001005 int errno;
1006
1007 /* make sure it is the right magic for NVMUpdate */
1008 if ((eeprom->magic >> 16) != hw->device_id)
1009 return -EINVAL;
1010
Shannon Nelsonc150a502014-11-13 08:23:13 +00001011 cmd = (struct i40e_nvm_access *)eeprom;
1012 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001013 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001014 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001015 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1016 ret_val, hw->aq.asq_last_status, errno,
1017 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1018 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001019
1020 return errno;
1021 }
1022
1023 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001024 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1025
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001026 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001027 if (!eeprom_buff)
1028 return -ENOMEM;
1029
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001030 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1031 if (ret_val) {
1032 dev_info(&pf->pdev->dev,
1033 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1034 ret_val, hw->aq.asq_last_status);
1035 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001036 }
1037
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001038 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1039 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1040 len = I40E_NVM_SECTOR_SIZE;
1041 last = false;
1042 for (i = 0; i < sectors; i++) {
1043 if (i == (sectors - 1)) {
1044 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1045 last = true;
1046 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001047 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1048 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001049 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001050 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001051 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001052 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001053 "read NVM failed, invalid offset 0x%x\n",
1054 offset);
1055 break;
1056 } else if (ret_val &&
1057 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1058 dev_info(&pf->pdev->dev,
1059 "read NVM failed, access, offset 0x%x\n",
1060 offset);
1061 break;
1062 } else if (ret_val) {
1063 dev_info(&pf->pdev->dev,
1064 "read NVM failed offset %d err=%d status=0x%x\n",
1065 offset, ret_val, hw->aq.asq_last_status);
1066 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001067 }
1068 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001069
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001070 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001071 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001072free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001074 return ret_val;
1075}
1076
1077static int i40e_get_eeprom_len(struct net_device *netdev)
1078{
1079 struct i40e_netdev_priv *np = netdev_priv(netdev);
1080 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001081 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001082
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001083 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1084 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1085 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1086 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001087 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001088 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001089}
1090
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001091static int i40e_set_eeprom(struct net_device *netdev,
1092 struct ethtool_eeprom *eeprom, u8 *bytes)
1093{
1094 struct i40e_netdev_priv *np = netdev_priv(netdev);
1095 struct i40e_hw *hw = &np->vsi->back->hw;
1096 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001097 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001098 int ret_val = 0;
1099 int errno;
1100 u32 magic;
1101
1102 /* normal ethtool set_eeprom is not supported */
1103 magic = hw->vendor_id | (hw->device_id << 16);
1104 if (eeprom->magic == magic)
1105 return -EOPNOTSUPP;
1106
1107 /* check for NVMUpdate access method */
1108 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1109 return -EINVAL;
1110
1111 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1112 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1113 return -EBUSY;
1114
Shannon Nelsonc150a502014-11-13 08:23:13 +00001115 cmd = (struct i40e_nvm_access *)eeprom;
1116 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001117 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001118 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001119 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1120 ret_val, hw->aq.asq_last_status, errno,
1121 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1122 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001123
1124 return errno;
1125}
1126
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001127static void i40e_get_drvinfo(struct net_device *netdev,
1128 struct ethtool_drvinfo *drvinfo)
1129{
1130 struct i40e_netdev_priv *np = netdev_priv(netdev);
1131 struct i40e_vsi *vsi = np->vsi;
1132 struct i40e_pf *pf = vsi->back;
1133
1134 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1135 strlcpy(drvinfo->version, i40e_driver_version_str,
1136 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001137 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001138 sizeof(drvinfo->fw_version));
1139 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1140 sizeof(drvinfo->bus_info));
1141}
1142
1143static void i40e_get_ringparam(struct net_device *netdev,
1144 struct ethtool_ringparam *ring)
1145{
1146 struct i40e_netdev_priv *np = netdev_priv(netdev);
1147 struct i40e_pf *pf = np->vsi->back;
1148 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1149
1150 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1151 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1152 ring->rx_mini_max_pending = 0;
1153 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001154 ring->rx_pending = vsi->rx_rings[0]->count;
1155 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001156 ring->rx_mini_pending = 0;
1157 ring->rx_jumbo_pending = 0;
1158}
1159
1160static int i40e_set_ringparam(struct net_device *netdev,
1161 struct ethtool_ringparam *ring)
1162{
1163 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1164 struct i40e_netdev_priv *np = netdev_priv(netdev);
1165 struct i40e_vsi *vsi = np->vsi;
1166 struct i40e_pf *pf = vsi->back;
1167 u32 new_rx_count, new_tx_count;
1168 int i, err = 0;
1169
1170 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1171 return -EINVAL;
1172
Shannon Nelson1fa18372013-11-20 10:03:08 +00001173 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1174 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1175 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1176 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1177 netdev_info(netdev,
1178 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1179 ring->tx_pending, ring->rx_pending,
1180 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1181 return -EINVAL;
1182 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001183
Shannon Nelson1fa18372013-11-20 10:03:08 +00001184 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1185 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001186
1187 /* if nothing to do return success */
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001188 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1189 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001190 return 0;
1191
1192 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1193 usleep_range(1000, 2000);
1194
1195 if (!netif_running(vsi->netdev)) {
1196 /* simple case - set for the next time the netdev is started */
1197 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001198 vsi->tx_rings[i]->count = new_tx_count;
1199 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001200 }
1201 goto done;
1202 }
1203
1204 /* We can't just free everything and then setup again,
1205 * because the ISRs in MSI-X mode get passed pointers
1206 * to the Tx and Rx ring structs.
1207 */
1208
1209 /* alloc updated Tx resources */
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001210 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001211 netdev_info(netdev,
1212 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001213 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001214 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1215 sizeof(struct i40e_ring), GFP_KERNEL);
1216 if (!tx_rings) {
1217 err = -ENOMEM;
1218 goto done;
1219 }
1220
1221 for (i = 0; i < vsi->num_queue_pairs; i++) {
1222 /* clone ring and setup updated count */
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001223 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001224 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001225 /* the desc and bi pointers will be reallocated in the
1226 * setup call
1227 */
1228 tx_rings[i].desc = NULL;
1229 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001230 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1231 if (err) {
1232 while (i) {
1233 i--;
1234 i40e_free_tx_resources(&tx_rings[i]);
1235 }
1236 kfree(tx_rings);
1237 tx_rings = NULL;
1238
1239 goto done;
1240 }
1241 }
1242 }
1243
1244 /* alloc updated Rx resources */
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001245 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001246 netdev_info(netdev,
1247 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001248 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001249 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1250 sizeof(struct i40e_ring), GFP_KERNEL);
1251 if (!rx_rings) {
1252 err = -ENOMEM;
1253 goto free_tx;
1254 }
1255
1256 for (i = 0; i < vsi->num_queue_pairs; i++) {
1257 /* clone ring and setup updated count */
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001258 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001259 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001260 /* the desc and bi pointers will be reallocated in the
1261 * setup call
1262 */
1263 rx_rings[i].desc = NULL;
1264 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001265 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1266 if (err) {
1267 while (i) {
1268 i--;
1269 i40e_free_rx_resources(&rx_rings[i]);
1270 }
1271 kfree(rx_rings);
1272 rx_rings = NULL;
1273
1274 goto free_tx;
1275 }
1276 }
1277 }
1278
1279 /* Bring interface down, copy in the new ring info,
1280 * then restore the interface
1281 */
1282 i40e_down(vsi);
1283
1284 if (tx_rings) {
1285 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001286 i40e_free_tx_resources(vsi->tx_rings[i]);
1287 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001288 }
1289 kfree(tx_rings);
1290 tx_rings = NULL;
1291 }
1292
1293 if (rx_rings) {
1294 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e15b2013-09-28 06:00:58 +00001295 i40e_free_rx_resources(vsi->rx_rings[i]);
1296 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001297 }
1298 kfree(rx_rings);
1299 rx_rings = NULL;
1300 }
1301
1302 i40e_up(vsi);
1303
1304free_tx:
1305 /* error cleanup if the Rx allocations failed after getting Tx */
1306 if (tx_rings) {
1307 for (i = 0; i < vsi->num_queue_pairs; i++)
1308 i40e_free_tx_resources(&tx_rings[i]);
1309 kfree(tx_rings);
1310 tx_rings = NULL;
1311 }
1312
1313done:
1314 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1315
1316 return err;
1317}
1318
1319static int i40e_get_sset_count(struct net_device *netdev, int sset)
1320{
1321 struct i40e_netdev_priv *np = netdev_priv(netdev);
1322 struct i40e_vsi *vsi = np->vsi;
1323 struct i40e_pf *pf = vsi->back;
1324
1325 switch (sset) {
1326 case ETH_SS_TEST:
1327 return I40E_TEST_LEN;
1328 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001329 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001330 int len = I40E_PF_STATS_LEN(netdev);
1331
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001332 if ((pf->lan_veb != I40E_NO_VEB) &&
1333 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001334 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001335 return len;
1336 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001337 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001338 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001339 case ETH_SS_PRIV_FLAGS:
1340 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341 default:
1342 return -EOPNOTSUPP;
1343 }
1344}
1345
1346static void i40e_get_ethtool_stats(struct net_device *netdev,
1347 struct ethtool_stats *stats, u64 *data)
1348{
1349 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001350 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001351 struct i40e_vsi *vsi = np->vsi;
1352 struct i40e_pf *pf = vsi->back;
1353 int i = 0;
1354 char *p;
1355 int j;
1356 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001357 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001358
1359 i40e_update_stats(vsi);
1360
1361 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1362 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1363 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1364 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1365 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001366 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1367 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1368 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1369 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1370 }
Vasu Dev38e00432014-08-01 13:27:03 -07001371#ifdef I40E_FCOE
1372 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1373 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1374 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1375 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1376 }
1377#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001378 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001379 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001380 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001381
1382 if (!tx_ring)
1383 continue;
1384
1385 /* process Tx ring statistics */
1386 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001387 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001388 data[i] = tx_ring->stats.packets;
1389 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001390 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001391 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001392
1393 /* Rx ring is the 2nd half of the queue pair */
1394 rx_ring = &tx_ring[1];
1395 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001396 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001397 data[i] = rx_ring->stats.packets;
1398 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001399 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001400 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001401 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001402 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001403 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001404 return;
1405
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001406 if ((pf->lan_veb != I40E_NO_VEB) &&
1407 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001408 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001409
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001410 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1411 p = (char *)veb;
1412 p += i40e_gstrings_veb_stats[j].stat_offset;
1413 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1414 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001415 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001416 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1417 data[i++] = veb->tc_stats.tc_tx_packets[j];
1418 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1419 data[i++] = veb->tc_stats.tc_rx_packets[j];
1420 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1421 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001422 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001423 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1424 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1425 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1426 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1427 }
1428 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1429 data[i++] = pf->stats.priority_xon_tx[j];
1430 data[i++] = pf->stats.priority_xoff_tx[j];
1431 }
1432 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1433 data[i++] = pf->stats.priority_xon_rx[j];
1434 data[i++] = pf->stats.priority_xoff_rx[j];
1435 }
1436 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1437 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001438}
1439
1440static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1441 u8 *data)
1442{
1443 struct i40e_netdev_priv *np = netdev_priv(netdev);
1444 struct i40e_vsi *vsi = np->vsi;
1445 struct i40e_pf *pf = vsi->back;
1446 char *p = (char *)data;
1447 int i;
1448
1449 switch (stringset) {
1450 case ETH_SS_TEST:
1451 for (i = 0; i < I40E_TEST_LEN; i++) {
1452 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1453 data += ETH_GSTRING_LEN;
1454 }
1455 break;
1456 case ETH_SS_STATS:
1457 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1458 snprintf(p, ETH_GSTRING_LEN, "%s",
1459 i40e_gstrings_net_stats[i].stat_string);
1460 p += ETH_GSTRING_LEN;
1461 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001462 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1463 snprintf(p, ETH_GSTRING_LEN, "%s",
1464 i40e_gstrings_misc_stats[i].stat_string);
1465 p += ETH_GSTRING_LEN;
1466 }
Vasu Dev38e00432014-08-01 13:27:03 -07001467#ifdef I40E_FCOE
1468 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1469 snprintf(p, ETH_GSTRING_LEN, "%s",
1470 i40e_gstrings_fcoe_stats[i].stat_string);
1471 p += ETH_GSTRING_LEN;
1472 }
1473#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001474 for (i = 0; i < vsi->num_queue_pairs; i++) {
1475 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1476 p += ETH_GSTRING_LEN;
1477 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1478 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001479 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1480 p += ETH_GSTRING_LEN;
1481 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1482 p += ETH_GSTRING_LEN;
1483 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001484 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001485 return;
1486
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001487 if ((pf->lan_veb != I40E_NO_VEB) &&
1488 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001489 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1490 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1491 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001492 p += ETH_GSTRING_LEN;
1493 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001494 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1495 snprintf(p, ETH_GSTRING_LEN,
1496 "veb.tc_%u_tx_packets", i);
1497 p += ETH_GSTRING_LEN;
1498 snprintf(p, ETH_GSTRING_LEN,
1499 "veb.tc_%u_tx_bytes", i);
1500 p += ETH_GSTRING_LEN;
1501 snprintf(p, ETH_GSTRING_LEN,
1502 "veb.tc_%u_rx_packets", i);
1503 p += ETH_GSTRING_LEN;
1504 snprintf(p, ETH_GSTRING_LEN,
1505 "veb.tc_%u_rx_bytes", i);
1506 p += ETH_GSTRING_LEN;
1507 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001508 }
1509 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1510 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1511 i40e_gstrings_stats[i].stat_string);
1512 p += ETH_GSTRING_LEN;
1513 }
1514 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1515 snprintf(p, ETH_GSTRING_LEN,
1516 "port.tx_priority_%u_xon", i);
1517 p += ETH_GSTRING_LEN;
1518 snprintf(p, ETH_GSTRING_LEN,
1519 "port.tx_priority_%u_xoff", i);
1520 p += ETH_GSTRING_LEN;
1521 }
1522 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1523 snprintf(p, ETH_GSTRING_LEN,
1524 "port.rx_priority_%u_xon", i);
1525 p += ETH_GSTRING_LEN;
1526 snprintf(p, ETH_GSTRING_LEN,
1527 "port.rx_priority_%u_xoff", i);
1528 p += ETH_GSTRING_LEN;
1529 }
1530 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1531 snprintf(p, ETH_GSTRING_LEN,
1532 "port.rx_priority_%u_xon_2_xoff", i);
1533 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534 }
1535 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1536 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001537 case ETH_SS_PRIV_FLAGS:
1538 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1539 memcpy(data, i40e_priv_flags_strings[i],
1540 ETH_GSTRING_LEN);
1541 data += ETH_GSTRING_LEN;
1542 }
1543 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001544 default:
1545 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001546 }
1547}
1548
1549static int i40e_get_ts_info(struct net_device *dev,
1550 struct ethtool_ts_info *info)
1551{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001552 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1553
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001554 /* only report HW timestamping if PTP is enabled */
1555 if (!(pf->flags & I40E_FLAG_PTP))
1556 return ethtool_op_get_ts_info(dev, info);
1557
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001558 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1559 SOF_TIMESTAMPING_RX_SOFTWARE |
1560 SOF_TIMESTAMPING_SOFTWARE |
1561 SOF_TIMESTAMPING_TX_HARDWARE |
1562 SOF_TIMESTAMPING_RX_HARDWARE |
1563 SOF_TIMESTAMPING_RAW_HARDWARE;
1564
1565 if (pf->ptp_clock)
1566 info->phc_index = ptp_clock_index(pf->ptp_clock);
1567 else
1568 info->phc_index = -1;
1569
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001570 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001571
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001572 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1573 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1574 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001575
1576 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001577}
1578
Shannon Nelson7b086392013-11-20 10:02:59 +00001579static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580{
Shannon Nelson7b086392013-11-20 10:02:59 +00001581 struct i40e_netdev_priv *np = netdev_priv(netdev);
1582 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001583 i40e_status status;
1584 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001585
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001586 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001587 status = i40e_get_link_status(&pf->hw, &link_up);
1588 if (status) {
1589 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1590 *data = 1;
1591 return *data;
1592 }
1593
1594 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595 *data = 0;
1596 else
1597 *data = 1;
1598
1599 return *data;
1600}
1601
Shannon Nelson7b086392013-11-20 10:02:59 +00001602static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001603{
Shannon Nelson7b086392013-11-20 10:02:59 +00001604 struct i40e_netdev_priv *np = netdev_priv(netdev);
1605 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001606
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001607 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001608 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609
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_eeprom_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;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001617
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001618 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001619 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001620
Shannon Nelson4443ec92014-11-13 08:23:12 +00001621 /* forcebly clear the NVM Update state machine */
1622 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1623
Shannon Nelson7b086392013-11-20 10:02:59 +00001624 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001625}
1626
Shannon Nelson7b086392013-11-20 10:02:59 +00001627static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001628{
Shannon Nelson7b086392013-11-20 10:02:59 +00001629 struct i40e_netdev_priv *np = netdev_priv(netdev);
1630 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001631 u16 swc_old = pf->sw_int_count;
1632
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001633 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001634 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1635 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001636 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1637 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1638 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1639 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001640 usleep_range(1000, 2000);
1641 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001642
1643 return *data;
1644}
1645
Shannon Nelson7b086392013-11-20 10:02:59 +00001646static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001647{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001648 struct i40e_netdev_priv *np = netdev_priv(netdev);
1649 struct i40e_pf *pf = np->vsi->back;
1650
1651 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001652 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001653
1654 return *data;
1655}
1656
Greg Rosee17bc412015-04-16 20:05:59 -04001657static inline bool i40e_active_vfs(struct i40e_pf *pf)
1658{
1659 struct i40e_vf *vfs = pf->vf;
1660 int i;
1661
1662 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001663 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001664 return true;
1665 return false;
1666}
1667
Greg Rose510efb22015-07-10 19:36:01 -04001668static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1669{
1670 struct i40e_vsi **vsi = pf->vsi;
1671 int i;
1672
1673 for (i = 0; i < pf->num_alloc_vsi; i++) {
1674 if (!vsi[i])
1675 continue;
1676 if (vsi[i]->type == I40E_VSI_VMDQ2)
1677 return true;
1678 }
1679
1680 return false;
1681}
1682
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001683static void i40e_diag_test(struct net_device *netdev,
1684 struct ethtool_test *eth_test, u64 *data)
1685{
1686 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001687 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001688 struct i40e_pf *pf = np->vsi->back;
1689
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001690 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1691 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001692 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001693
Shannon Nelsonf551b432013-11-26 10:49:12 +00001694 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001695
Greg Rose510efb22015-07-10 19:36:01 -04001696 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001697 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001698 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001699 data[I40E_ETH_TEST_REG] = 1;
1700 data[I40E_ETH_TEST_EEPROM] = 1;
1701 data[I40E_ETH_TEST_INTR] = 1;
1702 data[I40E_ETH_TEST_LOOPBACK] = 1;
1703 data[I40E_ETH_TEST_LINK] = 1;
1704 eth_test->flags |= ETH_TEST_FL_FAILED;
1705 clear_bit(__I40E_TESTING, &pf->state);
1706 goto skip_ol_tests;
1707 }
1708
Greg Rose5b86c5c2015-02-26 16:14:35 +00001709 /* If the device is online then take it offline */
1710 if (if_running)
1711 /* indicate we're in test mode */
1712 dev_close(netdev);
1713 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001714 /* This reset does not affect link - if it is
1715 * changed to a type of reset that does affect
1716 * link then the following link test would have
1717 * to be moved to before the reset
1718 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001719 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001720
Shannon Nelson7b086392013-11-20 10:02:59 +00001721 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001722 eth_test->flags |= ETH_TEST_FL_FAILED;
1723
Shannon Nelson7b086392013-11-20 10:02:59 +00001724 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001725 eth_test->flags |= ETH_TEST_FL_FAILED;
1726
Shannon Nelson7b086392013-11-20 10:02:59 +00001727 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001728 eth_test->flags |= ETH_TEST_FL_FAILED;
1729
Shannon Nelson7b086392013-11-20 10:02:59 +00001730 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001731 eth_test->flags |= ETH_TEST_FL_FAILED;
1732
Shannon Nelsonf551b432013-11-26 10:49:12 +00001733 /* run reg test last, a reset is required after it */
1734 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1735 eth_test->flags |= ETH_TEST_FL_FAILED;
1736
1737 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001738 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001739
1740 if (if_running)
1741 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001742 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001743 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001744 netif_info(pf, drv, netdev, "online testing starting\n");
1745
Shannon Nelson7b086392013-11-20 10:02:59 +00001746 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001747 eth_test->flags |= ETH_TEST_FL_FAILED;
1748
1749 /* Offline only tests, not run in online; pass by default */
1750 data[I40E_ETH_TEST_REG] = 0;
1751 data[I40E_ETH_TEST_EEPROM] = 0;
1752 data[I40E_ETH_TEST_INTR] = 0;
1753 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001754 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001755
Greg Rosee17bc412015-04-16 20:05:59 -04001756skip_ol_tests:
1757
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001758 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001759}
1760
1761static void i40e_get_wol(struct net_device *netdev,
1762 struct ethtool_wolinfo *wol)
1763{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001764 struct i40e_netdev_priv *np = netdev_priv(netdev);
1765 struct i40e_pf *pf = np->vsi->back;
1766 struct i40e_hw *hw = &pf->hw;
1767 u16 wol_nvm_bits;
1768
1769 /* NVM bit on means WoL disabled for the port */
1770 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001771 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001772 wol->supported = 0;
1773 wol->wolopts = 0;
1774 } else {
1775 wol->supported = WAKE_MAGIC;
1776 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1777 }
1778}
1779
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001780/**
1781 * i40e_set_wol - set the WakeOnLAN configuration
1782 * @netdev: the netdev in question
1783 * @wol: the ethtool WoL setting data
1784 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001785static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1786{
1787 struct i40e_netdev_priv *np = netdev_priv(netdev);
1788 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001789 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001790 struct i40e_hw *hw = &pf->hw;
1791 u16 wol_nvm_bits;
1792
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001793 /* WoL not supported if this isn't the controlling PF on the port */
1794 if (hw->partition_id != 1) {
1795 i40e_partition_setting_complaint(pf);
1796 return -EOPNOTSUPP;
1797 }
1798
1799 if (vsi != pf->vsi[pf->lan_vsi])
1800 return -EOPNOTSUPP;
1801
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001802 /* NVM bit on means WoL disabled for the port */
1803 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001804 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001805 return -EOPNOTSUPP;
1806
1807 /* only magic packet is supported */
1808 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1809 return -EOPNOTSUPP;
1810
1811 /* is this a new value? */
1812 if (pf->wol_en != !!wol->wolopts) {
1813 pf->wol_en = !!wol->wolopts;
1814 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1815 }
1816
1817 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818}
1819
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820static int i40e_set_phys_id(struct net_device *netdev,
1821 enum ethtool_phys_id_state state)
1822{
1823 struct i40e_netdev_priv *np = netdev_priv(netdev);
1824 struct i40e_pf *pf = np->vsi->back;
1825 struct i40e_hw *hw = &pf->hw;
1826 int blink_freq = 2;
1827
1828 switch (state) {
1829 case ETHTOOL_ID_ACTIVE:
1830 pf->led_status = i40e_led_get(hw);
1831 return blink_freq;
1832 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001833 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001834 break;
1835 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001836 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001837 break;
1838 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001839 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001840 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001841 default:
1842 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001843 }
1844
1845 return 0;
1846}
1847
1848/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1849 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1850 * 125us (8000 interrupts per second) == ITR(62)
1851 */
1852
1853static int i40e_get_coalesce(struct net_device *netdev,
1854 struct ethtool_coalesce *ec)
1855{
1856 struct i40e_netdev_priv *np = netdev_priv(netdev);
1857 struct i40e_vsi *vsi = np->vsi;
1858
1859 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1860 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1861
1862 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001863 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001864
1865 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001866 ec->use_adaptive_tx_coalesce = 1;
1867
1868 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1869 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001870 /* we use the _usecs_high to store/set the interrupt rate limit
1871 * that the hardware supports, that almost but not quite
1872 * fits the original intent of the ethtool variable,
1873 * the rx_coalesce_usecs_high limits total interrupts
1874 * per second from both tx/rx sources.
1875 */
1876 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1877 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001878
1879 return 0;
1880}
1881
1882static int i40e_set_coalesce(struct net_device *netdev,
1883 struct ethtool_coalesce *ec)
1884{
1885 struct i40e_netdev_priv *np = netdev_priv(netdev);
1886 struct i40e_q_vector *q_vector;
1887 struct i40e_vsi *vsi = np->vsi;
1888 struct i40e_pf *pf = vsi->back;
1889 struct i40e_hw *hw = &pf->hw;
1890 u16 vector;
1891 int i;
1892
1893 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1894 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1895
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001896 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1897 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1898 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1899 return -EINVAL;
1900 }
1901
1902 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1903 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1904 return -EINVAL;
1905 }
1906
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001907 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001908 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001909 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001910 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001911 } else if (ec->rx_coalesce_usecs == 0) {
1912 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001913 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001914 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 +00001915 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001916 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001917 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001918 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001919
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001920 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1921
Mitch Williams32f5f542014-04-04 04:43:10 +00001922 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001923 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001924 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001925 } else if (ec->tx_coalesce_usecs == 0) {
1926 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001927 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001928 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 +00001929 } else {
1930 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001931 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001932 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001933 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001934
1935 if (ec->use_adaptive_rx_coalesce)
1936 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1937 else
1938 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1939
1940 if (ec->use_adaptive_tx_coalesce)
1941 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1942 else
1943 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001944
Alexander Duyck493fb302013-09-28 07:01:44 +00001945 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001946 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1947
Alexander Duyck493fb302013-09-28 07:01:44 +00001948 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001949 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1950 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1951 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1952 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001953 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001954 i40e_flush(hw);
1955 }
1956
1957 return 0;
1958}
1959
1960/**
1961 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1962 * @pf: pointer to the physical function struct
1963 * @cmd: ethtool rxnfc command
1964 *
1965 * Returns Success if the flow is supported, else Invalid Input.
1966 **/
1967static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1968{
1969 cmd->data = 0;
1970
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001971 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1972 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1973 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1974 return 0;
1975 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001976 /* Report default options for RSS on i40e */
1977 switch (cmd->flow_type) {
1978 case TCP_V4_FLOW:
1979 case UDP_V4_FLOW:
1980 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1981 /* fall through to add IP fields */
1982 case SCTP_V4_FLOW:
1983 case AH_ESP_V4_FLOW:
1984 case AH_V4_FLOW:
1985 case ESP_V4_FLOW:
1986 case IPV4_FLOW:
1987 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1988 break;
1989 case TCP_V6_FLOW:
1990 case UDP_V6_FLOW:
1991 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1992 /* fall through to add IP fields */
1993 case SCTP_V6_FLOW:
1994 case AH_ESP_V6_FLOW:
1995 case AH_V6_FLOW:
1996 case ESP_V6_FLOW:
1997 case IPV6_FLOW:
1998 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1999 break;
2000 default:
2001 return -EINVAL;
2002 }
2003
2004 return 0;
2005}
2006
2007/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002008 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2009 * @pf: Pointer to the physical function struct
2010 * @cmd: The command to get or set Rx flow classification rules
2011 * @rule_locs: Array of used rule locations
2012 *
2013 * This function populates both the total and actual rule count of
2014 * the ethtool flow classification command
2015 *
2016 * Returns 0 on success or -EMSGSIZE if entry not found
2017 **/
2018static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2019 struct ethtool_rxnfc *cmd,
2020 u32 *rule_locs)
2021{
2022 struct i40e_fdir_filter *rule;
2023 struct hlist_node *node2;
2024 int cnt = 0;
2025
2026 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002027 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002028
2029 hlist_for_each_entry_safe(rule, node2,
2030 &pf->fdir_filter_list, fdir_node) {
2031 if (cnt == cmd->rule_cnt)
2032 return -EMSGSIZE;
2033
2034 rule_locs[cnt] = rule->fd_id;
2035 cnt++;
2036 }
2037
2038 cmd->rule_cnt = cnt;
2039
2040 return 0;
2041}
2042
2043/**
2044 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2045 * @pf: Pointer to the physical function struct
2046 * @cmd: The command to get or set Rx flow classification rules
2047 *
2048 * This function looks up a filter based on the Rx flow classification
2049 * command and fills the flow spec info for it if found
2050 *
2051 * Returns 0 on success or -EINVAL if filter not found
2052 **/
2053static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2054 struct ethtool_rxnfc *cmd)
2055{
2056 struct ethtool_rx_flow_spec *fsp =
2057 (struct ethtool_rx_flow_spec *)&cmd->fs;
2058 struct i40e_fdir_filter *rule = NULL;
2059 struct hlist_node *node2;
2060
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002061 hlist_for_each_entry_safe(rule, node2,
2062 &pf->fdir_filter_list, fdir_node) {
2063 if (fsp->location <= rule->fd_id)
2064 break;
2065 }
2066
2067 if (!rule || fsp->location != rule->fd_id)
2068 return -EINVAL;
2069
2070 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002071 if (fsp->flow_type == IP_USER_FLOW) {
2072 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2073 fsp->h_u.usr_ip4_spec.proto = 0;
2074 fsp->m_u.usr_ip4_spec.proto = 0;
2075 }
2076
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002077 /* Reverse the src and dest notion, since the HW views them from
2078 * Tx perspective where as the user expects it from Rx filter view.
2079 */
2080 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2081 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2082 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2083 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002084
2085 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2086 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2087 else
2088 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002089
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002090 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2091 struct i40e_vsi *vsi;
2092
2093 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2094 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2095 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2096 fsp->m_ext.data[1] = htonl(0x1);
2097 }
2098 }
2099
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002100 return 0;
2101}
2102
2103/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002104 * i40e_get_rxnfc - command to get RX flow classification rules
2105 * @netdev: network interface device structure
2106 * @cmd: ethtool rxnfc command
2107 *
2108 * Returns Success if the command is supported.
2109 **/
2110static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2111 u32 *rule_locs)
2112{
2113 struct i40e_netdev_priv *np = netdev_priv(netdev);
2114 struct i40e_vsi *vsi = np->vsi;
2115 struct i40e_pf *pf = vsi->back;
2116 int ret = -EOPNOTSUPP;
2117
2118 switch (cmd->cmd) {
2119 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002120 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002121 ret = 0;
2122 break;
2123 case ETHTOOL_GRXFH:
2124 ret = i40e_get_rss_hash_opts(pf, cmd);
2125 break;
2126 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002127 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002128 /* report total rule count */
2129 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002130 ret = 0;
2131 break;
2132 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002133 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002134 break;
2135 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002136 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2137 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002138 default:
2139 break;
2140 }
2141
2142 return ret;
2143}
2144
2145/**
2146 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2147 * @pf: pointer to the physical function struct
2148 * @cmd: ethtool rxnfc command
2149 *
2150 * Returns Success if the flow input set is supported.
2151 **/
2152static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2153{
2154 struct i40e_hw *hw = &pf->hw;
2155 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2156 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2157
2158 /* RSS does not support anything other than hashing
2159 * to queues on src and dst IPs and ports
2160 */
2161 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2162 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2163 return -EINVAL;
2164
2165 /* We need at least the IP SRC and DEST fields for hashing */
2166 if (!(nfc->data & RXH_IP_SRC) ||
2167 !(nfc->data & RXH_IP_DST))
2168 return -EINVAL;
2169
2170 switch (nfc->flow_type) {
2171 case TCP_V4_FLOW:
2172 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2173 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002174 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002175 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002176 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2177 hena |=
2178 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2179
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002180 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002181 break;
2182 default:
2183 return -EINVAL;
2184 }
2185 break;
2186 case TCP_V6_FLOW:
2187 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2188 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002189 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002190 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002191 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2192 hena |=
2193 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2194
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002195 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002196 break;
2197 default:
2198 return -EINVAL;
2199 }
2200 break;
2201 case UDP_V4_FLOW:
2202 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2203 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002204 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002206 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2207 hena |=
2208 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2209 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2210
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002211 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2212 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002213 break;
2214 default:
2215 return -EINVAL;
2216 }
2217 break;
2218 case UDP_V6_FLOW:
2219 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2220 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002221 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002222 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002223 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2224 hena |=
2225 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2226 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2227
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002228 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2229 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002230 break;
2231 default:
2232 return -EINVAL;
2233 }
2234 break;
2235 case AH_ESP_V4_FLOW:
2236 case AH_V4_FLOW:
2237 case ESP_V4_FLOW:
2238 case SCTP_V4_FLOW:
2239 if ((nfc->data & RXH_L4_B_0_1) ||
2240 (nfc->data & RXH_L4_B_2_3))
2241 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002242 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002243 break;
2244 case AH_ESP_V6_FLOW:
2245 case AH_V6_FLOW:
2246 case ESP_V6_FLOW:
2247 case SCTP_V6_FLOW:
2248 if ((nfc->data & RXH_L4_B_0_1) ||
2249 (nfc->data & RXH_L4_B_2_3))
2250 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002251 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002252 break;
2253 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002254 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2255 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002256 break;
2257 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002258 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2259 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002260 break;
2261 default:
2262 return -EINVAL;
2263 }
2264
2265 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2266 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2267 i40e_flush(hw);
2268
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002269 /* Save setting for future output/update */
2270 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2271
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002272 return 0;
2273}
2274
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002276 * i40e_match_fdir_input_set - Match a new filter against an existing one
2277 * @rule: The filter already added
2278 * @input: The new filter to comapre against
2279 *
2280 * Returns true if the two input set match
2281 **/
2282static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2283 struct i40e_fdir_filter *input)
2284{
2285 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2286 (rule->src_ip[0] != input->src_ip[0]) ||
2287 (rule->dst_port != input->dst_port) ||
2288 (rule->src_port != input->src_port))
2289 return false;
2290 return true;
2291}
2292
2293/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002294 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2295 * @vsi: Pointer to the targeted VSI
2296 * @input: The filter to update or NULL to indicate deletion
2297 * @sw_idx: Software index to the filter
2298 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002299 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002300 * This function updates (or deletes) a Flow Director entry from
2301 * the hlist of the corresponding PF
2302 *
2303 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002304 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002305static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2306 struct i40e_fdir_filter *input,
2307 u16 sw_idx,
2308 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002309{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002310 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002311 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002312 struct hlist_node *node2;
2313 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002314
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002315 parent = NULL;
2316 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002317
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002318 hlist_for_each_entry_safe(rule, node2,
2319 &pf->fdir_filter_list, fdir_node) {
2320 /* hash found, or no matching entry */
2321 if (rule->fd_id >= sw_idx)
2322 break;
2323 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002324 }
2325
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002326 /* if there is an old rule occupying our place remove it */
2327 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002328 if (input && !i40e_match_fdir_input_set(rule, input))
2329 err = i40e_add_del_fdir(vsi, rule, false);
2330 else if (!input)
2331 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002332 hlist_del(&rule->fdir_node);
2333 kfree(rule);
2334 pf->fdir_pf_active_filters--;
2335 }
2336
2337 /* If no input this was a delete, err should be 0 if a rule was
2338 * successfully found and removed from the list else -EINVAL
2339 */
2340 if (!input)
2341 return err;
2342
2343 /* initialize node and set software index */
2344 INIT_HLIST_NODE(&input->fdir_node);
2345
2346 /* add filter to the list */
2347 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002348 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002349 else
2350 hlist_add_head(&input->fdir_node,
2351 &pf->fdir_filter_list);
2352
2353 /* update counts */
2354 pf->fdir_pf_active_filters++;
2355
2356 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002357}
2358
2359/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002360 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2361 * @vsi: Pointer to the targeted VSI
2362 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002363 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002364 * The function removes a Flow Director filter entry from the
2365 * hlist of the corresponding PF
2366 *
2367 * Returns 0 on success
2368 */
2369static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2370 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002371{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002372 struct ethtool_rx_flow_spec *fsp =
2373 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002374 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002375 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002376
Anjali Singhai Jain60793f42014-07-09 07:46:23 +00002377 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2378 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2379 return -EBUSY;
2380
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002381 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2382 return -EBUSY;
2383
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002384 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002385
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002386 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002387 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002388}
2389
2390/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002391 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002392 * @vsi: pointer to the targeted VSI
2393 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002394 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002395 * Add Flow Director filters for a specific flow spec based on their
2396 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002397 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002398static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2399 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002400{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002401 struct ethtool_rx_flow_spec *fsp;
2402 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002403 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002404 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002405 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002406
2407 if (!vsi)
2408 return -EINVAL;
2409
2410 pf = vsi->back;
2411
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002412 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2413 return -EOPNOTSUPP;
2414
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002415 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002416 return -ENOSPC;
2417
Anjali Singhai Jain60793f42014-07-09 07:46:23 +00002418 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2419 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2420 return -EBUSY;
2421
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002422 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2423 return -EBUSY;
2424
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002425 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2426
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002427 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2428 pf->hw.func_caps.fd_filters_guaranteed)) {
2429 return -EINVAL;
2430 }
2431
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002432 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2433 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002434 return -EINVAL;
2435
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002436 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002437
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002438 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002439 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002440
2441 input->fd_id = fsp->location;
2442
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002443 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2444 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2445 else
2446 input->dest_ctl =
2447 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2448
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002449 input->q_index = fsp->ring_cookie;
2450 input->flex_off = 0;
2451 input->pctype = 0;
2452 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002453 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002454 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002455 input->flow_type = fsp->flow_type;
2456 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002457
2458 /* Reverse the src and dest notion, since the HW expects them to be from
2459 * Tx perspective where as the input from user is from Rx filter view.
2460 */
2461 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2462 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2463 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2464 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002465
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002466 if (ntohl(fsp->m_ext.data[1])) {
2467 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2468 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2469 goto free_input;
2470 }
2471 vf_id = ntohl(fsp->h_ext.data[1]);
2472 /* Find vsi id from vf id and override dest vsi */
2473 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2474 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2475 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2476 goto free_input;
2477 }
2478 }
2479
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002480 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002481free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002482 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002483 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002484 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002485 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002486
2487 return ret;
2488}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002489
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002490/**
2491 * i40e_set_rxnfc - command to set RX flow classification rules
2492 * @netdev: network interface device structure
2493 * @cmd: ethtool rxnfc command
2494 *
2495 * Returns Success if the command is supported.
2496 **/
2497static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2498{
2499 struct i40e_netdev_priv *np = netdev_priv(netdev);
2500 struct i40e_vsi *vsi = np->vsi;
2501 struct i40e_pf *pf = vsi->back;
2502 int ret = -EOPNOTSUPP;
2503
2504 switch (cmd->cmd) {
2505 case ETHTOOL_SRXFH:
2506 ret = i40e_set_rss_hash_opt(pf, cmd);
2507 break;
2508 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002509 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002510 break;
2511 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002512 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002513 break;
2514 default:
2515 break;
2516 }
2517
2518 return ret;
2519}
2520
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002521/**
2522 * i40e_max_channels - get Max number of combined channels supported
2523 * @vsi: vsi pointer
2524 **/
2525static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2526{
2527 /* TODO: This code assumes DCB and FD is disabled for now. */
2528 return vsi->alloc_queue_pairs;
2529}
2530
2531/**
2532 * i40e_get_channels - Get the current channels enabled and max supported etc.
2533 * @netdev: network interface device structure
2534 * @ch: ethtool channels structure
2535 *
2536 * We don't support separate tx and rx queues as channels. The other count
2537 * represents how many queues are being used for control. max_combined counts
2538 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2539 * q_vectors since we support a lot more queue pairs than q_vectors.
2540 **/
2541static void i40e_get_channels(struct net_device *dev,
2542 struct ethtool_channels *ch)
2543{
2544 struct i40e_netdev_priv *np = netdev_priv(dev);
2545 struct i40e_vsi *vsi = np->vsi;
2546 struct i40e_pf *pf = vsi->back;
2547
2548 /* report maximum channels */
2549 ch->max_combined = i40e_max_channels(vsi);
2550
2551 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002552 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002553 ch->max_other = ch->other_count;
2554
2555 /* Note: This code assumes DCB is disabled for now. */
2556 ch->combined_count = vsi->num_queue_pairs;
2557}
2558
2559/**
2560 * i40e_set_channels - Set the new channels count.
2561 * @netdev: network interface device structure
2562 * @ch: ethtool channels structure
2563 *
2564 * The new channels count may not be the same as requested by the user
2565 * since it gets rounded down to a power of 2 value.
2566 **/
2567static int i40e_set_channels(struct net_device *dev,
2568 struct ethtool_channels *ch)
2569{
2570 struct i40e_netdev_priv *np = netdev_priv(dev);
2571 unsigned int count = ch->combined_count;
2572 struct i40e_vsi *vsi = np->vsi;
2573 struct i40e_pf *pf = vsi->back;
2574 int new_count;
2575
2576 /* We do not support setting channels for any other VSI at present */
2577 if (vsi->type != I40E_VSI_MAIN)
2578 return -EINVAL;
2579
2580 /* verify they are not requesting separate vectors */
2581 if (!count || ch->rx_count || ch->tx_count)
2582 return -EINVAL;
2583
2584 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002585 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002586 return -EINVAL;
2587
2588 /* verify the number of channels does not exceed hardware limits */
2589 if (count > i40e_max_channels(vsi))
2590 return -EINVAL;
2591
2592 /* update feature limits from largest to smallest supported values */
2593 /* TODO: Flow director limit, DCB etc */
2594
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002595 /* use rss_reconfig to rebuild with new queue count and update traffic
2596 * class queue mapping
2597 */
2598 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002599 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002600 return 0;
2601 else
2602 return -EINVAL;
2603}
2604
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002605/**
2606 * i40e_get_rxfh_key_size - get the RSS hash key size
2607 * @netdev: network interface device structure
2608 *
2609 * Returns the table size.
2610 **/
2611static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2612{
2613 return I40E_HKEY_ARRAY_SIZE;
2614}
2615
2616/**
2617 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2618 * @netdev: network interface device structure
2619 *
2620 * Returns the table size.
2621 **/
2622static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2623{
2624 return I40E_HLUT_ARRAY_SIZE;
2625}
2626
2627static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2628 u8 *hfunc)
2629{
2630 struct i40e_netdev_priv *np = netdev_priv(netdev);
2631 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002632 u8 *lut, *seed = NULL;
2633 int ret;
2634 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002635
2636 if (hfunc)
2637 *hfunc = ETH_RSS_HASH_TOP;
2638
2639 if (!indir)
2640 return 0;
2641
Helin Zhang043dd652015-10-21 19:56:23 -04002642 seed = key;
2643 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2644 if (!lut)
2645 return -ENOMEM;
2646 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2647 if (ret)
2648 goto out;
2649 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2650 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002651
Helin Zhang043dd652015-10-21 19:56:23 -04002652out:
2653 kfree(lut);
2654
2655 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002656}
2657
2658/**
2659 * i40e_set_rxfh - set the rx flow hash indirection table
2660 * @netdev: network interface device structure
2661 * @indir: indirection table
2662 * @key: hash key
2663 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002664 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002665 * returns 0 after programming the table.
2666 **/
2667static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2668 const u8 *key, const u8 hfunc)
2669{
2670 struct i40e_netdev_priv *np = netdev_priv(netdev);
2671 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002672 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002673 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002674
2675 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2676 return -EOPNOTSUPP;
2677
2678 if (!indir)
2679 return 0;
2680
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002681 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002682 if (!vsi->rss_hkey_user) {
2683 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2684 GFP_KERNEL);
2685 if (!vsi->rss_hkey_user)
2686 return -ENOMEM;
2687 }
2688 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2689 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002690 }
Helin Zhang28c58692015-10-26 19:44:27 -04002691 if (!vsi->rss_lut_user) {
2692 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2693 if (!vsi->rss_lut_user)
2694 return -ENOMEM;
2695 }
Helin Zhang043dd652015-10-21 19:56:23 -04002696
Helin Zhang28c58692015-10-26 19:44:27 -04002697 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2698 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2699 vsi->rss_lut_user[i] = (u8)(indir[i]);
2700
2701 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2702 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002703}
2704
Greg Rose7e45ab42015-02-06 08:52:19 +00002705/**
2706 * i40e_get_priv_flags - report device private flags
2707 * @dev: network interface device structure
2708 *
2709 * The get string set count and the string set should be matched for each
2710 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2711 * array.
2712 *
2713 * Returns a u32 bitmap of flags.
2714 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002715static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002716{
2717 struct i40e_netdev_priv *np = netdev_priv(dev);
2718 struct i40e_vsi *vsi = np->vsi;
2719 struct i40e_pf *pf = vsi->back;
2720 u32 ret_flags = 0;
2721
2722 ret_flags |= pf->hw.func_caps.npar_enable ?
2723 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002724 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2725 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002726 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2727 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002728 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2729 I40E_PRIV_FLAGS_VEB_STATS : 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002730 ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
2731 I40E_PRIV_FLAGS_PS : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002732
2733 return ret_flags;
2734}
2735
Shannon Nelson9ac77262015-08-27 11:42:40 -04002736/**
2737 * i40e_set_priv_flags - set private flags
2738 * @dev: network interface device structure
2739 * @flags: bit flags to be set
2740 **/
2741static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2742{
2743 struct i40e_netdev_priv *np = netdev_priv(dev);
2744 struct i40e_vsi *vsi = np->vsi;
2745 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002746 bool reset_required = false;
2747
2748 /* NOTE: MFP is not settable */
2749
2750 /* allow the user to control the method of receive
2751 * buffer DMA, whether the packet is split at header
2752 * boundaries into two separate buffers. In some cases
2753 * one routine or the other will perform better.
2754 */
2755 if ((flags & I40E_PRIV_FLAGS_PS) &&
2756 !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2757 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
2758 pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
2759 reset_required = true;
2760 } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
2761 (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2762 pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
2763 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
2764 reset_required = true;
2765 }
Shannon Nelson9ac77262015-08-27 11:42:40 -04002766
2767 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2768 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2769 else
2770 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2771
Jesse Brandeburgef171782015-09-03 17:18:49 -04002772 /* allow the user to control the state of the Flow
2773 * Director ATR (Application Targeted Routing) feature
2774 * of the driver
2775 */
2776 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2777 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2778 } else {
2779 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2780 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2781 }
2782
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002783 if (flags & I40E_PRIV_FLAGS_VEB_STATS)
2784 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2785 else
2786 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2787
Jesse Brandeburg827de392015-11-06 15:26:07 -08002788 /* if needed, issue reset to cause things to take effect */
2789 if (reset_required)
2790 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2791
Shannon Nelson9ac77262015-08-27 11:42:40 -04002792 return 0;
2793}
2794
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002795static const struct ethtool_ops i40e_ethtool_ops = {
2796 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002797 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002798 .get_drvinfo = i40e_get_drvinfo,
2799 .get_regs_len = i40e_get_regs_len,
2800 .get_regs = i40e_get_regs,
2801 .nway_reset = i40e_nway_reset,
2802 .get_link = ethtool_op_get_link,
2803 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002804 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002805 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002806 .get_eeprom_len = i40e_get_eeprom_len,
2807 .get_eeprom = i40e_get_eeprom,
2808 .get_ringparam = i40e_get_ringparam,
2809 .set_ringparam = i40e_set_ringparam,
2810 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002811 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002812 .get_msglevel = i40e_get_msglevel,
2813 .set_msglevel = i40e_set_msglevel,
2814 .get_rxnfc = i40e_get_rxnfc,
2815 .set_rxnfc = i40e_set_rxnfc,
2816 .self_test = i40e_diag_test,
2817 .get_strings = i40e_get_strings,
2818 .set_phys_id = i40e_set_phys_id,
2819 .get_sset_count = i40e_get_sset_count,
2820 .get_ethtool_stats = i40e_get_ethtool_stats,
2821 .get_coalesce = i40e_get_coalesce,
2822 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002823 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2824 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2825 .get_rxfh = i40e_get_rxfh,
2826 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002827 .get_channels = i40e_get_channels,
2828 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002829 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002830 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002831 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002832};
2833
2834void i40e_set_ethtool_ops(struct net_device *netdev)
2835{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002836 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002837}