blob: 45495911c5a4f5f221bac91ced1f284371880c4c [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),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000146 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000147 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000148 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400149 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400150 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000151 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400152 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000153
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000154 /* LPI stats */
155 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
156 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
157 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
158 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000159};
160
Vasu Dev38e00432014-08-01 13:27:03 -0700161#ifdef I40E_FCOE
162static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
163 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
164 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
165 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
166 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
167 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
168 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
169 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
170 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
171};
172
173#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000174#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000175 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
176 * 2 /* Tx and Rx together */ \
177 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000178#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
179#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000180#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700181#ifdef I40E_FCOE
182#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
183#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
184 I40E_FCOE_STATS_LEN + \
185 I40E_MISC_STATS_LEN + \
186 I40E_QUEUE_STATS_LEN((n)))
187#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000189 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700191#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192#define I40E_PFC_STATS_LEN ( \
193 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
198 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400199#define I40E_VEB_TC_STATS_LEN ( \
200 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
201 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
204 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000205#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400206#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000207#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
208 I40E_PFC_STATS_LEN + \
209 I40E_VSI_STATS_LEN((n)))
210
211enum i40e_ethtool_test_id {
212 I40E_ETH_TEST_REG = 0,
213 I40E_ETH_TEST_EEPROM,
214 I40E_ETH_TEST_INTR,
215 I40E_ETH_TEST_LOOPBACK,
216 I40E_ETH_TEST_LINK,
217};
218
219static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
220 "Register test (offline)",
221 "Eeprom test (offline)",
222 "Interrupt test (offline)",
223 "Loopback test (offline)",
224 "Link test (on/offline)"
225};
226
227#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
228
Greg Rose7e45ab42015-02-06 08:52:19 +0000229static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
230 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400231 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400232 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400233 "veb-stats",
Jesse Brandeburg827de392015-11-06 15:26:07 -0800234 "packet-split",
Greg Rose7e45ab42015-02-06 08:52:19 +0000235};
236
Shannon Nelson9ac77262015-08-27 11:42:40 -0400237#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000238
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000239/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000240 * i40e_partition_setting_complaint - generic complaint for MFP restriction
241 * @pf: the PF struct
242 **/
243static void i40e_partition_setting_complaint(struct i40e_pf *pf)
244{
245 dev_info(&pf->pdev->dev,
246 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
247}
248
249/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000250 * i40e_get_settings_link_up - Get the Link settings for when link is up
251 * @hw: hw structure
252 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000255 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000256static void i40e_get_settings_link_up(struct i40e_hw *hw,
257 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400258 struct net_device *netdev,
259 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000261 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 u32 link_speed = hw_link_info->link_speed;
263
Catherine Sullivane8278452015-02-06 08:52:08 +0000264 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265 switch (hw_link_info->phy_type) {
266 case I40E_PHY_TYPE_40GBASE_CR4:
267 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000268 ecmd->supported = SUPPORTED_Autoneg |
269 SUPPORTED_40000baseCR4_Full;
270 ecmd->advertising = ADVERTISED_Autoneg |
271 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000272 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000273 case I40E_PHY_TYPE_XLAUI:
274 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000275 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000276 ecmd->supported = SUPPORTED_40000baseCR4_Full;
277 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000278 case I40E_PHY_TYPE_40GBASE_SR4:
279 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 break;
281 case I40E_PHY_TYPE_40GBASE_LR4:
282 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000284 case I40E_PHY_TYPE_10GBASE_SR:
285 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000286 case I40E_PHY_TYPE_1000BASE_SX:
287 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400288 ecmd->supported = SUPPORTED_10000baseT_Full;
289 if (hw_link_info->module_type[2] &
290 I40E_MODULE_TYPE_1000BASE_SX ||
291 hw_link_info->module_type[2] &
292 I40E_MODULE_TYPE_1000BASE_LX) {
293 ecmd->supported |= SUPPORTED_1000baseT_Full;
294 if (hw_link_info->requested_speeds &
295 I40E_LINK_SPEED_1GB)
296 ecmd->advertising |= ADVERTISED_1000baseT_Full;
297 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000298 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
299 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000300 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000301 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000302 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000303 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000304 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400305 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000306 ecmd->advertising = ADVERTISED_Autoneg;
307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
308 ecmd->advertising |= ADVERTISED_10000baseT_Full;
309 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
310 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400311 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400312 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
313 ecmd->supported = SUPPORTED_Autoneg |
314 SUPPORTED_1000baseT_Full;
315 ecmd->advertising = ADVERTISED_Autoneg |
316 ADVERTISED_1000baseT_Full;
317 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400318 case I40E_PHY_TYPE_100BASE_TX:
319 ecmd->supported = SUPPORTED_Autoneg |
320 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000321 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
322 ecmd->advertising |= ADVERTISED_100baseT_Full;
323 break;
324 case I40E_PHY_TYPE_10GBASE_CR1_CU:
325 case I40E_PHY_TYPE_10GBASE_CR1:
326 ecmd->supported = SUPPORTED_Autoneg |
327 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000328 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000329 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000330 break;
331 case I40E_PHY_TYPE_XAUI:
332 case I40E_PHY_TYPE_XFI:
333 case I40E_PHY_TYPE_SFI:
334 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000335 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000336 ecmd->supported = SUPPORTED_10000baseT_Full;
337 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000338 case I40E_PHY_TYPE_SGMII:
339 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400340 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000341 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
342 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800343 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400344 ecmd->supported |= SUPPORTED_100baseT_Full;
345 if (hw_link_info->requested_speeds &
346 I40E_LINK_SPEED_100MB)
347 ecmd->advertising |= ADVERTISED_100baseT_Full;
348 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000349 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400350 /* Backplane is set based on supported phy types in get_settings
351 * so don't set anything here but don't warn either
352 */
353 case I40E_PHY_TYPE_40GBASE_KR4:
354 case I40E_PHY_TYPE_20GBASE_KR2:
355 case I40E_PHY_TYPE_10GBASE_KR:
356 case I40E_PHY_TYPE_10GBASE_KX4:
357 case I40E_PHY_TYPE_1000BASE_KX:
358 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000359 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000360 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000361 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
362 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000363 }
364
Catherine Sullivane8278452015-02-06 08:52:08 +0000365 /* Set speed and duplex */
366 switch (link_speed) {
367 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400368 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000369 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700370 case I40E_LINK_SPEED_20GB:
371 ethtool_cmd_speed_set(ecmd, SPEED_20000);
372 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000373 case I40E_LINK_SPEED_10GB:
374 ethtool_cmd_speed_set(ecmd, SPEED_10000);
375 break;
376 case I40E_LINK_SPEED_1GB:
377 ethtool_cmd_speed_set(ecmd, SPEED_1000);
378 break;
379 case I40E_LINK_SPEED_100MB:
380 ethtool_cmd_speed_set(ecmd, SPEED_100);
381 break;
382 default:
383 break;
384 }
385 ecmd->duplex = DUPLEX_FULL;
386}
387
388/**
389 * i40e_get_settings_link_down - Get the Link settings for when link is down
390 * @hw: hw structure
391 * @ecmd: ethtool command to fill in
392 *
393 * Reports link settings that can be determined when link is down
394 **/
395static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400396 struct ethtool_cmd *ecmd,
397 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000398{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400399 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000400
401 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400402 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000403 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400404 ecmd->supported = 0x0;
405 ecmd->advertising = 0x0;
406 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
407 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400408 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400409 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400410 ADVERTISED_1000baseT_Full;
411 if (pf->hw.mac.type == I40E_MAC_X722) {
412 ecmd->supported |= SUPPORTED_100baseT_Full;
413 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivanf8db54cc2015-12-22 14:25:14 -0800414 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
415 ecmd->supported |= SUPPORTED_100baseT_Full;
416 ecmd->advertising |= ADVERTISED_100baseT_Full;
417 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400418 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000419 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400420 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
421 phy_types & I40E_CAP_PHY_TYPE_XFI ||
422 phy_types & I40E_CAP_PHY_TYPE_SFI ||
423 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
424 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
425 ecmd->supported |= SUPPORTED_10000baseT_Full;
426 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
427 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
430 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
431 ecmd->supported |= SUPPORTED_Autoneg |
432 SUPPORTED_10000baseT_Full;
433 ecmd->advertising |= ADVERTISED_Autoneg |
434 ADVERTISED_10000baseT_Full;
435 }
436 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
437 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
438 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
439 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
440 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
441 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
442 ecmd->supported |= SUPPORTED_Autoneg |
443 SUPPORTED_40000baseCR4_Full;
444 ecmd->advertising |= ADVERTISED_Autoneg |
445 ADVERTISED_40000baseCR4_Full;
446 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400447 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
448 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400449 ecmd->supported |= SUPPORTED_Autoneg |
450 SUPPORTED_100baseT_Full;
451 ecmd->advertising |= ADVERTISED_Autoneg |
452 ADVERTISED_100baseT_Full;
453 }
454 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
455 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
456 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
457 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
458 ecmd->supported |= SUPPORTED_Autoneg |
459 SUPPORTED_1000baseT_Full;
460 ecmd->advertising |= ADVERTISED_Autoneg |
461 ADVERTISED_1000baseT_Full;
462 }
463 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
464 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
465 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
466 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000467
468 /* With no link speed and duplex are unknown */
469 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
470 ecmd->duplex = DUPLEX_UNKNOWN;
471}
472
473/**
474 * i40e_get_settings - Get Link Speed and Duplex settings
475 * @netdev: network interface device structure
476 * @ecmd: ethtool command
477 *
478 * Reports speed/duplex settings based on media_type
479 **/
480static int i40e_get_settings(struct net_device *netdev,
481 struct ethtool_cmd *ecmd)
482{
483 struct i40e_netdev_priv *np = netdev_priv(netdev);
484 struct i40e_pf *pf = np->vsi->back;
485 struct i40e_hw *hw = &pf->hw;
486 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
487 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
488
489 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400490 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000491 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400492 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000493
494 /* Now set the settings that don't rely on link being up/down */
495
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400496 /* For backplane, supported and advertised are only reliant on the
497 * phy types the NVM specifies are supported.
498 */
499 if (hw->device_id == I40E_DEV_ID_KX_B ||
500 hw->device_id == I40E_DEV_ID_KX_C ||
501 hw->device_id == I40E_DEV_ID_20G_KR2 ||
502 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
503 ecmd->supported = SUPPORTED_Autoneg;
504 ecmd->advertising = ADVERTISED_Autoneg;
505 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
506 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
507 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
508 }
509 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
510 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
511 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
512 }
513 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
514 ecmd->supported |= SUPPORTED_10000baseKR_Full;
515 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
516 }
517 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
518 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
519 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
520 }
521 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
522 ecmd->supported |= SUPPORTED_1000baseKX_Full;
523 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
524 }
525 }
526
Catherine Sullivane8278452015-02-06 08:52:08 +0000527 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000528 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
529 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000530
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000531 switch (hw->phy.media_type) {
532 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000533 ecmd->supported |= SUPPORTED_Autoneg |
534 SUPPORTED_Backplane;
535 ecmd->advertising |= ADVERTISED_Autoneg |
536 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000537 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000538 break;
539 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000540 ecmd->supported |= SUPPORTED_TP;
541 ecmd->advertising |= ADVERTISED_TP;
542 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000543 break;
544 case I40E_MEDIA_TYPE_DA:
545 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000546 ecmd->supported |= SUPPORTED_FIBRE;
547 ecmd->advertising |= ADVERTISED_FIBRE;
548 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000549 break;
550 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000551 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000552 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000553 break;
554 case I40E_MEDIA_TYPE_UNKNOWN:
555 default:
556 ecmd->port = PORT_OTHER;
557 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000558 }
559
Catherine Sullivane8278452015-02-06 08:52:08 +0000560 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000561 ecmd->transceiver = XCVR_EXTERNAL;
562
Catherine Sullivane8278452015-02-06 08:52:08 +0000563 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000564 ecmd->supported |= SUPPORTED_Pause;
565
Catherine Sullivane8278452015-02-06 08:52:08 +0000566 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000567 case I40E_FC_FULL:
568 ecmd->advertising |= ADVERTISED_Pause;
569 break;
570 case I40E_FC_TX_PAUSE:
571 ecmd->advertising |= ADVERTISED_Asym_Pause;
572 break;
573 case I40E_FC_RX_PAUSE:
574 ecmd->advertising |= (ADVERTISED_Pause |
575 ADVERTISED_Asym_Pause);
576 break;
577 default:
578 ecmd->advertising &= ~(ADVERTISED_Pause |
579 ADVERTISED_Asym_Pause);
580 break;
581 }
582
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000583 return 0;
584}
585
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000586/**
587 * i40e_set_settings - Set Speed and Duplex
588 * @netdev: network interface device structure
589 * @ecmd: ethtool command
590 *
591 * Set speed/duplex per media_types advertised/forced
592 **/
593static int i40e_set_settings(struct net_device *netdev,
594 struct ethtool_cmd *ecmd)
595{
596 struct i40e_netdev_priv *np = netdev_priv(netdev);
597 struct i40e_aq_get_phy_abilities_resp abilities;
598 struct i40e_aq_set_phy_config config;
599 struct i40e_pf *pf = np->vsi->back;
600 struct i40e_vsi *vsi = np->vsi;
601 struct i40e_hw *hw = &pf->hw;
602 struct ethtool_cmd safe_ecmd;
603 i40e_status status = 0;
604 bool change = false;
605 int err = 0;
606 u8 autoneg;
607 u32 advertise;
608
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000609 /* Changing port settings is not supported if this isn't the
610 * port's controlling PF
611 */
612 if (hw->partition_id != 1) {
613 i40e_partition_setting_complaint(pf);
614 return -EOPNOTSUPP;
615 }
616
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000617 if (vsi != pf->vsi[pf->lan_vsi])
618 return -EOPNOTSUPP;
619
620 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
621 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000622 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
623 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000624 return -EOPNOTSUPP;
625
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400626 if (hw->device_id == I40E_DEV_ID_KX_B ||
627 hw->device_id == I40E_DEV_ID_KX_C ||
628 hw->device_id == I40E_DEV_ID_20G_KR2 ||
629 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
630 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
631 return -EOPNOTSUPP;
632 }
633
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000634 /* get our own copy of the bits to check against */
635 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
636 i40e_get_settings(netdev, &safe_ecmd);
637
638 /* save autoneg and speed out of ecmd */
639 autoneg = ecmd->autoneg;
640 advertise = ecmd->advertising;
641
642 /* set autoneg and speed back to what they currently are */
643 ecmd->autoneg = safe_ecmd.autoneg;
644 ecmd->advertising = safe_ecmd.advertising;
645
646 ecmd->cmd = safe_ecmd.cmd;
647 /* If ecmd and safe_ecmd are not the same now, then they are
648 * trying to set something that we do not support
649 */
650 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
651 return -EOPNOTSUPP;
652
653 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
654 usleep_range(1000, 2000);
655
656 /* Get the current phy config */
657 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
658 NULL);
659 if (status)
660 return -EAGAIN;
661
Catherine Sullivan124ed152014-07-12 07:28:12 +0000662 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000663 * set below
664 */
665 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000666 config.abilities = abilities.abilities;
667
668 /* Check autoneg */
669 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000670 /* If autoneg was not already enabled */
671 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400672 /* If autoneg is not supported, return error */
673 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
674 netdev_info(netdev, "Autoneg not supported on this phy\n");
675 return -EINVAL;
676 }
677 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000678 config.abilities = abilities.abilities |
679 I40E_AQ_PHY_ENABLE_AN;
680 change = true;
681 }
682 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000683 /* If autoneg is currently enabled */
684 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400685 /* If autoneg is supported 10GBASE_T is the only PHY
686 * that can disable it, so otherwise return error
687 */
688 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
689 hw->phy.link_info.phy_type !=
690 I40E_PHY_TYPE_10GBASE_T) {
691 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
692 return -EINVAL;
693 }
694 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000695 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000696 ~I40E_AQ_PHY_ENABLE_AN;
697 change = true;
698 }
699 }
700
701 if (advertise & ~safe_ecmd.supported)
702 return -EINVAL;
703
704 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000705 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000706 if (advertise & ADVERTISED_1000baseT_Full ||
707 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000708 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000709 if (advertise & ADVERTISED_10000baseT_Full ||
710 advertise & ADVERTISED_10000baseKX4_Full ||
711 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000712 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700713 if (advertise & ADVERTISED_20000baseKR2_Full)
714 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000715 if (advertise & ADVERTISED_40000baseKR4_Full ||
716 advertise & ADVERTISED_40000baseCR4_Full ||
717 advertise & ADVERTISED_40000baseSR4_Full ||
718 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000719 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000720
Catherine Sullivan0002e112015-08-26 15:14:16 -0400721 /* If speed didn't get set, set it to what it currently is.
722 * This is needed because if advertise is 0 (as it is when autoneg
723 * is disabled) then speed won't get set.
724 */
725 if (!config.link_speed)
726 config.link_speed = abilities.link_speed;
727
Catherine Sullivan124ed152014-07-12 07:28:12 +0000728 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000729 /* copy over the rest of the abilities */
730 config.phy_type = abilities.phy_type;
731 config.eee_capability = abilities.eee_capability;
732 config.eeer = abilities.eeer_val;
733 config.low_power_ctrl = abilities.d3_lpan;
734
Catherine Sullivane8278452015-02-06 08:52:08 +0000735 /* save the requested speeds */
736 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000737 /* set link and auto negotiation so changes take effect */
738 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
739 /* If link is up put link down */
740 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
741 /* Tell the OS link is going down, the link will go
742 * back up when fw says it is ready asynchronously
743 */
Matt Jaredc156f852015-08-27 11:42:39 -0400744 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000745 netif_carrier_off(netdev);
746 netif_tx_stop_all_queues(netdev);
747 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000748
749 /* make the aq call */
750 status = i40e_aq_set_phy_config(hw, &config, NULL);
751 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400752 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
753 i40e_stat_str(hw, status),
754 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000755 return -EAGAIN;
756 }
757
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400758 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000759 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400760 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
761 i40e_stat_str(hw, status),
762 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000763
764 } else {
765 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
766 }
767
768 return err;
769}
770
Jesse Brandeburga6599722014-06-04 08:45:25 +0000771static int i40e_nway_reset(struct net_device *netdev)
772{
773 /* restart autonegotiation */
774 struct i40e_netdev_priv *np = netdev_priv(netdev);
775 struct i40e_pf *pf = np->vsi->back;
776 struct i40e_hw *hw = &pf->hw;
777 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
778 i40e_status ret = 0;
779
780 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
781 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400782 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
783 i40e_stat_str(hw, ret),
784 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000785 return -EIO;
786 }
787
788 return 0;
789}
790
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000791/**
792 * i40e_get_pauseparam - Get Flow Control status
793 * Return tx/rx-pause status
794 **/
795static void i40e_get_pauseparam(struct net_device *netdev,
796 struct ethtool_pauseparam *pause)
797{
798 struct i40e_netdev_priv *np = netdev_priv(netdev);
799 struct i40e_pf *pf = np->vsi->back;
800 struct i40e_hw *hw = &pf->hw;
801 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000802 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000803
804 pause->autoneg =
805 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
806 AUTONEG_ENABLE : AUTONEG_DISABLE);
807
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000808 /* PFC enabled so report LFC as off */
809 if (dcbx_cfg->pfc.pfcenable) {
810 pause->rx_pause = 0;
811 pause->tx_pause = 0;
812 return;
813 }
814
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000815 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000816 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000817 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000818 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000819 } else if (hw->fc.current_mode == I40E_FC_FULL) {
820 pause->rx_pause = 1;
821 pause->tx_pause = 1;
822 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000823}
824
Catherine Sullivan2becc352014-06-04 08:45:27 +0000825/**
826 * i40e_set_pauseparam - Set Flow Control parameter
827 * @netdev: network interface device structure
828 * @pause: return tx/rx flow control status
829 **/
830static int i40e_set_pauseparam(struct net_device *netdev,
831 struct ethtool_pauseparam *pause)
832{
833 struct i40e_netdev_priv *np = netdev_priv(netdev);
834 struct i40e_pf *pf = np->vsi->back;
835 struct i40e_vsi *vsi = np->vsi;
836 struct i40e_hw *hw = &pf->hw;
837 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000838 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000839 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
840 i40e_status status;
841 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000842 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000843
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000844 /* Changing the port's flow control is not supported if this isn't the
845 * port's controlling PF
846 */
847 if (hw->partition_id != 1) {
848 i40e_partition_setting_complaint(pf);
849 return -EOPNOTSUPP;
850 }
851
Catherine Sullivan2becc352014-06-04 08:45:27 +0000852 if (vsi != pf->vsi[pf->lan_vsi])
853 return -EOPNOTSUPP;
854
855 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
856 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
857 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
858 return -EOPNOTSUPP;
859 }
860
861 /* If we have link and don't have autoneg */
862 if (!test_bit(__I40E_DOWN, &pf->state) &&
863 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
864 /* Send message that it might not necessarily work*/
865 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
866 }
867
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000868 if (dcbx_cfg->pfc.pfcenable) {
869 netdev_info(netdev,
870 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000871 return -EOPNOTSUPP;
872 }
873
874 if (pause->rx_pause && pause->tx_pause)
875 hw->fc.requested_mode = I40E_FC_FULL;
876 else if (pause->rx_pause && !pause->tx_pause)
877 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
878 else if (!pause->rx_pause && pause->tx_pause)
879 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
880 else if (!pause->rx_pause && !pause->tx_pause)
881 hw->fc.requested_mode = I40E_FC_NONE;
882 else
883 return -EINVAL;
884
Catherine Sullivan94128512014-07-12 07:28:16 +0000885 /* Tell the OS link is going down, the link will go back up when fw
886 * says it is ready asynchronously
887 */
Matt Jaredc156f852015-08-27 11:42:39 -0400888 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000889 netif_carrier_off(netdev);
890 netif_tx_stop_all_queues(netdev);
891
Catherine Sullivan2becc352014-06-04 08:45:27 +0000892 /* Set the fc mode and only restart an if link is up*/
893 status = i40e_set_fc(hw, &aq_failures, link_up);
894
895 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400896 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
897 i40e_stat_str(hw, status),
898 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000899 err = -EAGAIN;
900 }
901 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400902 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
903 i40e_stat_str(hw, status),
904 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000905 err = -EAGAIN;
906 }
907 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400908 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
909 i40e_stat_str(hw, status),
910 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000911 err = -EAGAIN;
912 }
913
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000914 if (!test_bit(__I40E_DOWN, &pf->state)) {
915 /* Give it a little more time to try to come back */
916 msleep(75);
917 if (!test_bit(__I40E_DOWN, &pf->state))
918 return i40e_nway_reset(netdev);
919 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000920
921 return err;
922}
923
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000924static u32 i40e_get_msglevel(struct net_device *netdev)
925{
926 struct i40e_netdev_priv *np = netdev_priv(netdev);
927 struct i40e_pf *pf = np->vsi->back;
928
929 return pf->msg_enable;
930}
931
932static void i40e_set_msglevel(struct net_device *netdev, u32 data)
933{
934 struct i40e_netdev_priv *np = netdev_priv(netdev);
935 struct i40e_pf *pf = np->vsi->back;
936
937 if (I40E_DEBUG_USER & data)
938 pf->hw.debug_mask = data;
939 pf->msg_enable = data;
940}
941
942static int i40e_get_regs_len(struct net_device *netdev)
943{
944 int reg_count = 0;
945 int i;
946
947 for (i = 0; i40e_reg_list[i].offset != 0; i++)
948 reg_count += i40e_reg_list[i].elements;
949
950 return reg_count * sizeof(u32);
951}
952
953static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
954 void *p)
955{
956 struct i40e_netdev_priv *np = netdev_priv(netdev);
957 struct i40e_pf *pf = np->vsi->back;
958 struct i40e_hw *hw = &pf->hw;
959 u32 *reg_buf = p;
960 int i, j, ri;
961 u32 reg;
962
963 /* Tell ethtool which driver-version-specific regs output we have.
964 *
965 * At some point, if we have ethtool doing special formatting of
966 * this data, it will rely on this version number to know how to
967 * interpret things. Hence, this needs to be updated if/when the
968 * diags register table is changed.
969 */
970 regs->version = 1;
971
972 /* loop through the diags reg table for what to print */
973 ri = 0;
974 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
975 for (j = 0; j < i40e_reg_list[i].elements; j++) {
976 reg = i40e_reg_list[i].offset
977 + (j * i40e_reg_list[i].stride);
978 reg_buf[ri++] = rd32(hw, reg);
979 }
980 }
981
982}
983
984static int i40e_get_eeprom(struct net_device *netdev,
985 struct ethtool_eeprom *eeprom, u8 *bytes)
986{
987 struct i40e_netdev_priv *np = netdev_priv(netdev);
988 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000989 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000990 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000991 u8 *eeprom_buff;
992 u16 i, sectors;
993 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000994 u32 magic;
995
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000996#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000997 if (eeprom->len == 0)
998 return -EINVAL;
999
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001000 /* check for NVMUpdate access method */
1001 magic = hw->vendor_id | (hw->device_id << 16);
1002 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +00001003 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001004 int errno;
1005
1006 /* make sure it is the right magic for NVMUpdate */
1007 if ((eeprom->magic >> 16) != hw->device_id)
1008 return -EINVAL;
1009
Shannon Nelsonc150a502014-11-13 08:23:13 +00001010 cmd = (struct i40e_nvm_access *)eeprom;
1011 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001012 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001013 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001014 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1015 ret_val, hw->aq.asq_last_status, errno,
1016 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1017 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001018
1019 return errno;
1020 }
1021
1022 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001023 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1024
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001025 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001026 if (!eeprom_buff)
1027 return -ENOMEM;
1028
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001029 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1030 if (ret_val) {
1031 dev_info(&pf->pdev->dev,
1032 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1033 ret_val, hw->aq.asq_last_status);
1034 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001035 }
1036
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001037 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1038 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1039 len = I40E_NVM_SECTOR_SIZE;
1040 last = false;
1041 for (i = 0; i < sectors; i++) {
1042 if (i == (sectors - 1)) {
1043 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1044 last = true;
1045 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001046 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1047 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001048 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001049 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001050 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001051 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001052 "read NVM failed, invalid offset 0x%x\n",
1053 offset);
1054 break;
1055 } else if (ret_val &&
1056 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1057 dev_info(&pf->pdev->dev,
1058 "read NVM failed, access, offset 0x%x\n",
1059 offset);
1060 break;
1061 } else if (ret_val) {
1062 dev_info(&pf->pdev->dev,
1063 "read NVM failed offset %d err=%d status=0x%x\n",
1064 offset, ret_val, hw->aq.asq_last_status);
1065 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001066 }
1067 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001068
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001069 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001070 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001071free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073 return ret_val;
1074}
1075
1076static int i40e_get_eeprom_len(struct net_device *netdev)
1077{
1078 struct i40e_netdev_priv *np = netdev_priv(netdev);
1079 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001080 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001081
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001082 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1083 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1084 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1085 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001086 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001087 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001088}
1089
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001090static int i40e_set_eeprom(struct net_device *netdev,
1091 struct ethtool_eeprom *eeprom, u8 *bytes)
1092{
1093 struct i40e_netdev_priv *np = netdev_priv(netdev);
1094 struct i40e_hw *hw = &np->vsi->back->hw;
1095 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001096 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001097 int ret_val = 0;
1098 int errno;
1099 u32 magic;
1100
1101 /* normal ethtool set_eeprom is not supported */
1102 magic = hw->vendor_id | (hw->device_id << 16);
1103 if (eeprom->magic == magic)
1104 return -EOPNOTSUPP;
1105
1106 /* check for NVMUpdate access method */
1107 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1108 return -EINVAL;
1109
1110 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1111 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1112 return -EBUSY;
1113
Shannon Nelsonc150a502014-11-13 08:23:13 +00001114 cmd = (struct i40e_nvm_access *)eeprom;
1115 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001116 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001117 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001118 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1119 ret_val, hw->aq.asq_last_status, errno,
1120 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1121 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001122
1123 return errno;
1124}
1125
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001126static void i40e_get_drvinfo(struct net_device *netdev,
1127 struct ethtool_drvinfo *drvinfo)
1128{
1129 struct i40e_netdev_priv *np = netdev_priv(netdev);
1130 struct i40e_vsi *vsi = np->vsi;
1131 struct i40e_pf *pf = vsi->back;
1132
1133 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1134 strlcpy(drvinfo->version, i40e_driver_version_str,
1135 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001136 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001137 sizeof(drvinfo->fw_version));
1138 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1139 sizeof(drvinfo->bus_info));
1140}
1141
1142static void i40e_get_ringparam(struct net_device *netdev,
1143 struct ethtool_ringparam *ring)
1144{
1145 struct i40e_netdev_priv *np = netdev_priv(netdev);
1146 struct i40e_pf *pf = np->vsi->back;
1147 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1148
1149 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1150 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1151 ring->rx_mini_max_pending = 0;
1152 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001153 ring->rx_pending = vsi->rx_rings[0]->count;
1154 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001155 ring->rx_mini_pending = 0;
1156 ring->rx_jumbo_pending = 0;
1157}
1158
1159static int i40e_set_ringparam(struct net_device *netdev,
1160 struct ethtool_ringparam *ring)
1161{
1162 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1163 struct i40e_netdev_priv *np = netdev_priv(netdev);
1164 struct i40e_vsi *vsi = np->vsi;
1165 struct i40e_pf *pf = vsi->back;
1166 u32 new_rx_count, new_tx_count;
1167 int i, err = 0;
1168
1169 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1170 return -EINVAL;
1171
Shannon Nelson1fa18372013-11-20 10:03:08 +00001172 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1173 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1174 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1175 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1176 netdev_info(netdev,
1177 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1178 ring->tx_pending, ring->rx_pending,
1179 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1180 return -EINVAL;
1181 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001182
Shannon Nelson1fa18372013-11-20 10:03:08 +00001183 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1184 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001185
1186 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001187 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1188 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001189 return 0;
1190
1191 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1192 usleep_range(1000, 2000);
1193
1194 if (!netif_running(vsi->netdev)) {
1195 /* simple case - set for the next time the netdev is started */
1196 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001197 vsi->tx_rings[i]->count = new_tx_count;
1198 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001199 }
1200 goto done;
1201 }
1202
1203 /* We can't just free everything and then setup again,
1204 * because the ISRs in MSI-X mode get passed pointers
1205 * to the Tx and Rx ring structs.
1206 */
1207
1208 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001209 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001210 netdev_info(netdev,
1211 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001212 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001213 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1214 sizeof(struct i40e_ring), GFP_KERNEL);
1215 if (!tx_rings) {
1216 err = -ENOMEM;
1217 goto done;
1218 }
1219
1220 for (i = 0; i < vsi->num_queue_pairs; i++) {
1221 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001222 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001223 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001224 /* the desc and bi pointers will be reallocated in the
1225 * setup call
1226 */
1227 tx_rings[i].desc = NULL;
1228 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001229 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1230 if (err) {
1231 while (i) {
1232 i--;
1233 i40e_free_tx_resources(&tx_rings[i]);
1234 }
1235 kfree(tx_rings);
1236 tx_rings = NULL;
1237
1238 goto done;
1239 }
1240 }
1241 }
1242
1243 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001244 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001245 netdev_info(netdev,
1246 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001247 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1249 sizeof(struct i40e_ring), GFP_KERNEL);
1250 if (!rx_rings) {
1251 err = -ENOMEM;
1252 goto free_tx;
1253 }
1254
1255 for (i = 0; i < vsi->num_queue_pairs; i++) {
1256 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001257 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001258 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001259 /* the desc and bi pointers will be reallocated in the
1260 * setup call
1261 */
1262 rx_rings[i].desc = NULL;
1263 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001264 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1265 if (err) {
1266 while (i) {
1267 i--;
1268 i40e_free_rx_resources(&rx_rings[i]);
1269 }
1270 kfree(rx_rings);
1271 rx_rings = NULL;
1272
1273 goto free_tx;
1274 }
1275 }
1276 }
1277
1278 /* Bring interface down, copy in the new ring info,
1279 * then restore the interface
1280 */
1281 i40e_down(vsi);
1282
1283 if (tx_rings) {
1284 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001285 i40e_free_tx_resources(vsi->tx_rings[i]);
1286 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001287 }
1288 kfree(tx_rings);
1289 tx_rings = NULL;
1290 }
1291
1292 if (rx_rings) {
1293 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001294 i40e_free_rx_resources(vsi->rx_rings[i]);
1295 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001296 }
1297 kfree(rx_rings);
1298 rx_rings = NULL;
1299 }
1300
1301 i40e_up(vsi);
1302
1303free_tx:
1304 /* error cleanup if the Rx allocations failed after getting Tx */
1305 if (tx_rings) {
1306 for (i = 0; i < vsi->num_queue_pairs; i++)
1307 i40e_free_tx_resources(&tx_rings[i]);
1308 kfree(tx_rings);
1309 tx_rings = NULL;
1310 }
1311
1312done:
1313 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1314
1315 return err;
1316}
1317
1318static int i40e_get_sset_count(struct net_device *netdev, int sset)
1319{
1320 struct i40e_netdev_priv *np = netdev_priv(netdev);
1321 struct i40e_vsi *vsi = np->vsi;
1322 struct i40e_pf *pf = vsi->back;
1323
1324 switch (sset) {
1325 case ETH_SS_TEST:
1326 return I40E_TEST_LEN;
1327 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001328 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001329 int len = I40E_PF_STATS_LEN(netdev);
1330
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001331 if ((pf->lan_veb != I40E_NO_VEB) &&
1332 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001333 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001334 return len;
1335 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001336 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001337 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001338 case ETH_SS_PRIV_FLAGS:
1339 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001340 default:
1341 return -EOPNOTSUPP;
1342 }
1343}
1344
1345static void i40e_get_ethtool_stats(struct net_device *netdev,
1346 struct ethtool_stats *stats, u64 *data)
1347{
1348 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001349 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350 struct i40e_vsi *vsi = np->vsi;
1351 struct i40e_pf *pf = vsi->back;
1352 int i = 0;
1353 char *p;
1354 int j;
1355 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001356 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001357
1358 i40e_update_stats(vsi);
1359
1360 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1361 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1362 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1363 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1364 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001365 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1366 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1367 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1368 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1369 }
Vasu Dev38e00432014-08-01 13:27:03 -07001370#ifdef I40E_FCOE
1371 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1372 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1373 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1374 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1375 }
1376#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001377 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001378 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001379 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001380
1381 if (!tx_ring)
1382 continue;
1383
1384 /* process Tx ring statistics */
1385 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001386 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001387 data[i] = tx_ring->stats.packets;
1388 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001389 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001390 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001391
1392 /* Rx ring is the 2nd half of the queue pair */
1393 rx_ring = &tx_ring[1];
1394 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001395 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001396 data[i] = rx_ring->stats.packets;
1397 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001398 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001399 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001400 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001401 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001402 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001403 return;
1404
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001405 if ((pf->lan_veb != I40E_NO_VEB) &&
1406 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001407 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001408
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001409 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1410 p = (char *)veb;
1411 p += i40e_gstrings_veb_stats[j].stat_offset;
1412 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1413 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001414 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001415 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1416 data[i++] = veb->tc_stats.tc_tx_packets[j];
1417 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1418 data[i++] = veb->tc_stats.tc_rx_packets[j];
1419 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1420 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001422 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1423 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1424 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1425 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1426 }
1427 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1428 data[i++] = pf->stats.priority_xon_tx[j];
1429 data[i++] = pf->stats.priority_xoff_tx[j];
1430 }
1431 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1432 data[i++] = pf->stats.priority_xon_rx[j];
1433 data[i++] = pf->stats.priority_xoff_rx[j];
1434 }
1435 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1436 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001437}
1438
1439static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1440 u8 *data)
1441{
1442 struct i40e_netdev_priv *np = netdev_priv(netdev);
1443 struct i40e_vsi *vsi = np->vsi;
1444 struct i40e_pf *pf = vsi->back;
1445 char *p = (char *)data;
1446 int i;
1447
1448 switch (stringset) {
1449 case ETH_SS_TEST:
1450 for (i = 0; i < I40E_TEST_LEN; i++) {
1451 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1452 data += ETH_GSTRING_LEN;
1453 }
1454 break;
1455 case ETH_SS_STATS:
1456 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1457 snprintf(p, ETH_GSTRING_LEN, "%s",
1458 i40e_gstrings_net_stats[i].stat_string);
1459 p += ETH_GSTRING_LEN;
1460 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001461 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1462 snprintf(p, ETH_GSTRING_LEN, "%s",
1463 i40e_gstrings_misc_stats[i].stat_string);
1464 p += ETH_GSTRING_LEN;
1465 }
Vasu Dev38e00432014-08-01 13:27:03 -07001466#ifdef I40E_FCOE
1467 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1468 snprintf(p, ETH_GSTRING_LEN, "%s",
1469 i40e_gstrings_fcoe_stats[i].stat_string);
1470 p += ETH_GSTRING_LEN;
1471 }
1472#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001473 for (i = 0; i < vsi->num_queue_pairs; i++) {
1474 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1475 p += ETH_GSTRING_LEN;
1476 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1477 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1479 p += ETH_GSTRING_LEN;
1480 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1481 p += ETH_GSTRING_LEN;
1482 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001483 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001484 return;
1485
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001486 if ((pf->lan_veb != I40E_NO_VEB) &&
1487 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001488 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1489 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1490 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001491 p += ETH_GSTRING_LEN;
1492 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001493 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1494 snprintf(p, ETH_GSTRING_LEN,
1495 "veb.tc_%u_tx_packets", i);
1496 p += ETH_GSTRING_LEN;
1497 snprintf(p, ETH_GSTRING_LEN,
1498 "veb.tc_%u_tx_bytes", i);
1499 p += ETH_GSTRING_LEN;
1500 snprintf(p, ETH_GSTRING_LEN,
1501 "veb.tc_%u_rx_packets", i);
1502 p += ETH_GSTRING_LEN;
1503 snprintf(p, ETH_GSTRING_LEN,
1504 "veb.tc_%u_rx_bytes", i);
1505 p += ETH_GSTRING_LEN;
1506 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001507 }
1508 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1509 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1510 i40e_gstrings_stats[i].stat_string);
1511 p += ETH_GSTRING_LEN;
1512 }
1513 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1514 snprintf(p, ETH_GSTRING_LEN,
1515 "port.tx_priority_%u_xon", i);
1516 p += ETH_GSTRING_LEN;
1517 snprintf(p, ETH_GSTRING_LEN,
1518 "port.tx_priority_%u_xoff", i);
1519 p += ETH_GSTRING_LEN;
1520 }
1521 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1522 snprintf(p, ETH_GSTRING_LEN,
1523 "port.rx_priority_%u_xon", i);
1524 p += ETH_GSTRING_LEN;
1525 snprintf(p, ETH_GSTRING_LEN,
1526 "port.rx_priority_%u_xoff", i);
1527 p += ETH_GSTRING_LEN;
1528 }
1529 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1530 snprintf(p, ETH_GSTRING_LEN,
1531 "port.rx_priority_%u_xon_2_xoff", i);
1532 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001533 }
1534 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1535 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001536 case ETH_SS_PRIV_FLAGS:
1537 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1538 memcpy(data, i40e_priv_flags_strings[i],
1539 ETH_GSTRING_LEN);
1540 data += ETH_GSTRING_LEN;
1541 }
1542 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001543 default:
1544 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545 }
1546}
1547
1548static int i40e_get_ts_info(struct net_device *dev,
1549 struct ethtool_ts_info *info)
1550{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001551 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1552
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001553 /* only report HW timestamping if PTP is enabled */
1554 if (!(pf->flags & I40E_FLAG_PTP))
1555 return ethtool_op_get_ts_info(dev, info);
1556
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001557 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1558 SOF_TIMESTAMPING_RX_SOFTWARE |
1559 SOF_TIMESTAMPING_SOFTWARE |
1560 SOF_TIMESTAMPING_TX_HARDWARE |
1561 SOF_TIMESTAMPING_RX_HARDWARE |
1562 SOF_TIMESTAMPING_RAW_HARDWARE;
1563
1564 if (pf->ptp_clock)
1565 info->phc_index = ptp_clock_index(pf->ptp_clock);
1566 else
1567 info->phc_index = -1;
1568
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001569 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001570
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001571 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1572 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1573 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001574
1575 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001576}
1577
Shannon Nelson7b086392013-11-20 10:02:59 +00001578static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001579{
Shannon Nelson7b086392013-11-20 10:02:59 +00001580 struct i40e_netdev_priv *np = netdev_priv(netdev);
1581 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001582 i40e_status status;
1583 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001584
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001585 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001586 status = i40e_get_link_status(&pf->hw, &link_up);
1587 if (status) {
1588 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1589 *data = 1;
1590 return *data;
1591 }
1592
1593 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594 *data = 0;
1595 else
1596 *data = 1;
1597
1598 return *data;
1599}
1600
Shannon Nelson7b086392013-11-20 10:02:59 +00001601static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001602{
Shannon Nelson7b086392013-11-20 10:02:59 +00001603 struct i40e_netdev_priv *np = netdev_priv(netdev);
1604 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001605
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001606 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001607 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608
Shannon Nelson7b086392013-11-20 10:02:59 +00001609 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001610}
1611
Shannon Nelson7b086392013-11-20 10:02:59 +00001612static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001613{
Shannon Nelson7b086392013-11-20 10:02:59 +00001614 struct i40e_netdev_priv *np = netdev_priv(netdev);
1615 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001616
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001617 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001618 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619
Shannon Nelson4443ec92014-11-13 08:23:12 +00001620 /* forcebly clear the NVM Update state machine */
1621 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1622
Shannon Nelson7b086392013-11-20 10:02:59 +00001623 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624}
1625
Shannon Nelson7b086392013-11-20 10:02:59 +00001626static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627{
Shannon Nelson7b086392013-11-20 10:02:59 +00001628 struct i40e_netdev_priv *np = netdev_priv(netdev);
1629 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001630 u16 swc_old = pf->sw_int_count;
1631
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001632 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001633 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1634 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001635 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1636 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1637 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1638 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001639 usleep_range(1000, 2000);
1640 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001641
1642 return *data;
1643}
1644
Shannon Nelson7b086392013-11-20 10:02:59 +00001645static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001646{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001647 struct i40e_netdev_priv *np = netdev_priv(netdev);
1648 struct i40e_pf *pf = np->vsi->back;
1649
1650 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001651 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652
1653 return *data;
1654}
1655
Greg Rosee17bc412015-04-16 20:05:59 -04001656static inline bool i40e_active_vfs(struct i40e_pf *pf)
1657{
1658 struct i40e_vf *vfs = pf->vf;
1659 int i;
1660
1661 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001662 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001663 return true;
1664 return false;
1665}
1666
Greg Rose510efb22015-07-10 19:36:01 -04001667static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1668{
1669 struct i40e_vsi **vsi = pf->vsi;
1670 int i;
1671
1672 for (i = 0; i < pf->num_alloc_vsi; i++) {
1673 if (!vsi[i])
1674 continue;
1675 if (vsi[i]->type == I40E_VSI_VMDQ2)
1676 return true;
1677 }
1678
1679 return false;
1680}
1681
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001682static void i40e_diag_test(struct net_device *netdev,
1683 struct ethtool_test *eth_test, u64 *data)
1684{
1685 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001686 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001687 struct i40e_pf *pf = np->vsi->back;
1688
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001689 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1690 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001691 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001692
Shannon Nelsonf551b432013-11-26 10:49:12 +00001693 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001694
Greg Rose510efb22015-07-10 19:36:01 -04001695 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001696 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001697 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001698 data[I40E_ETH_TEST_REG] = 1;
1699 data[I40E_ETH_TEST_EEPROM] = 1;
1700 data[I40E_ETH_TEST_INTR] = 1;
1701 data[I40E_ETH_TEST_LOOPBACK] = 1;
1702 data[I40E_ETH_TEST_LINK] = 1;
1703 eth_test->flags |= ETH_TEST_FL_FAILED;
1704 clear_bit(__I40E_TESTING, &pf->state);
1705 goto skip_ol_tests;
1706 }
1707
Greg Rose5b86c5c2015-02-26 16:14:35 +00001708 /* If the device is online then take it offline */
1709 if (if_running)
1710 /* indicate we're in test mode */
1711 dev_close(netdev);
1712 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001713 /* This reset does not affect link - if it is
1714 * changed to a type of reset that does affect
1715 * link then the following link test would have
1716 * to be moved to before the reset
1717 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001718 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001719
Shannon Nelson7b086392013-11-20 10:02:59 +00001720 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001721 eth_test->flags |= ETH_TEST_FL_FAILED;
1722
Shannon Nelson7b086392013-11-20 10:02:59 +00001723 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001724 eth_test->flags |= ETH_TEST_FL_FAILED;
1725
Shannon Nelson7b086392013-11-20 10:02:59 +00001726 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001727 eth_test->flags |= ETH_TEST_FL_FAILED;
1728
Shannon Nelson7b086392013-11-20 10:02:59 +00001729 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001730 eth_test->flags |= ETH_TEST_FL_FAILED;
1731
Shannon Nelsonf551b432013-11-26 10:49:12 +00001732 /* run reg test last, a reset is required after it */
1733 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1734 eth_test->flags |= ETH_TEST_FL_FAILED;
1735
1736 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001737 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001738
1739 if (if_running)
1740 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001741 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001742 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001743 netif_info(pf, drv, netdev, "online testing starting\n");
1744
Shannon Nelson7b086392013-11-20 10:02:59 +00001745 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001746 eth_test->flags |= ETH_TEST_FL_FAILED;
1747
1748 /* Offline only tests, not run in online; pass by default */
1749 data[I40E_ETH_TEST_REG] = 0;
1750 data[I40E_ETH_TEST_EEPROM] = 0;
1751 data[I40E_ETH_TEST_INTR] = 0;
1752 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001753 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001754
Greg Rosee17bc412015-04-16 20:05:59 -04001755skip_ol_tests:
1756
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001757 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001758}
1759
1760static void i40e_get_wol(struct net_device *netdev,
1761 struct ethtool_wolinfo *wol)
1762{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001763 struct i40e_netdev_priv *np = netdev_priv(netdev);
1764 struct i40e_pf *pf = np->vsi->back;
1765 struct i40e_hw *hw = &pf->hw;
1766 u16 wol_nvm_bits;
1767
1768 /* NVM bit on means WoL disabled for the port */
1769 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001770 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001771 wol->supported = 0;
1772 wol->wolopts = 0;
1773 } else {
1774 wol->supported = WAKE_MAGIC;
1775 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1776 }
1777}
1778
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001779/**
1780 * i40e_set_wol - set the WakeOnLAN configuration
1781 * @netdev: the netdev in question
1782 * @wol: the ethtool WoL setting data
1783 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001784static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1785{
1786 struct i40e_netdev_priv *np = netdev_priv(netdev);
1787 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001788 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001789 struct i40e_hw *hw = &pf->hw;
1790 u16 wol_nvm_bits;
1791
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001792 /* WoL not supported if this isn't the controlling PF on the port */
1793 if (hw->partition_id != 1) {
1794 i40e_partition_setting_complaint(pf);
1795 return -EOPNOTSUPP;
1796 }
1797
1798 if (vsi != pf->vsi[pf->lan_vsi])
1799 return -EOPNOTSUPP;
1800
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001801 /* NVM bit on means WoL disabled for the port */
1802 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001803 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001804 return -EOPNOTSUPP;
1805
1806 /* only magic packet is supported */
1807 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1808 return -EOPNOTSUPP;
1809
1810 /* is this a new value? */
1811 if (pf->wol_en != !!wol->wolopts) {
1812 pf->wol_en = !!wol->wolopts;
1813 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1814 }
1815
1816 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001817}
1818
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819static int i40e_set_phys_id(struct net_device *netdev,
1820 enum ethtool_phys_id_state state)
1821{
1822 struct i40e_netdev_priv *np = netdev_priv(netdev);
1823 struct i40e_pf *pf = np->vsi->back;
1824 struct i40e_hw *hw = &pf->hw;
1825 int blink_freq = 2;
1826
1827 switch (state) {
1828 case ETHTOOL_ID_ACTIVE:
1829 pf->led_status = i40e_led_get(hw);
1830 return blink_freq;
1831 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001832 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001833 break;
1834 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001835 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001836 break;
1837 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001838 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001839 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001840 default:
1841 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001842 }
1843
1844 return 0;
1845}
1846
1847/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1848 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1849 * 125us (8000 interrupts per second) == ITR(62)
1850 */
1851
1852static int i40e_get_coalesce(struct net_device *netdev,
1853 struct ethtool_coalesce *ec)
1854{
1855 struct i40e_netdev_priv *np = netdev_priv(netdev);
1856 struct i40e_vsi *vsi = np->vsi;
1857
1858 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1859 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1860
1861 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001862 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001863
1864 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001865 ec->use_adaptive_tx_coalesce = 1;
1866
1867 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1868 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001869 /* we use the _usecs_high to store/set the interrupt rate limit
1870 * that the hardware supports, that almost but not quite
1871 * fits the original intent of the ethtool variable,
1872 * the rx_coalesce_usecs_high limits total interrupts
1873 * per second from both tx/rx sources.
1874 */
1875 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1876 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001877
1878 return 0;
1879}
1880
1881static int i40e_set_coalesce(struct net_device *netdev,
1882 struct ethtool_coalesce *ec)
1883{
1884 struct i40e_netdev_priv *np = netdev_priv(netdev);
1885 struct i40e_q_vector *q_vector;
1886 struct i40e_vsi *vsi = np->vsi;
1887 struct i40e_pf *pf = vsi->back;
1888 struct i40e_hw *hw = &pf->hw;
1889 u16 vector;
1890 int i;
1891
1892 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1893 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1894
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001895 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1896 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1897 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1898 return -EINVAL;
1899 }
1900
1901 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1902 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1903 return -EINVAL;
1904 }
1905
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001906 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001907 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001908 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001909 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001910 } else if (ec->rx_coalesce_usecs == 0) {
1911 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001912 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001913 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 +00001914 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001915 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001916 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001917 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001918
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001919 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1920
Mitch Williams32f5f542014-04-04 04:43:10 +00001921 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001922 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001923 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001924 } else if (ec->tx_coalesce_usecs == 0) {
1925 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001926 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001927 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 +00001928 } else {
1929 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001930 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001931 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001932 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001933
1934 if (ec->use_adaptive_rx_coalesce)
1935 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1936 else
1937 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1938
1939 if (ec->use_adaptive_tx_coalesce)
1940 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1941 else
1942 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001943
Alexander Duyck493fb302013-09-28 07:01:44 +00001944 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001945 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1946
Alexander Duyck493fb302013-09-28 07:01:44 +00001947 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1949 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1950 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1951 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001952 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953 i40e_flush(hw);
1954 }
1955
1956 return 0;
1957}
1958
1959/**
1960 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1961 * @pf: pointer to the physical function struct
1962 * @cmd: ethtool rxnfc command
1963 *
1964 * Returns Success if the flow is supported, else Invalid Input.
1965 **/
1966static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1967{
1968 cmd->data = 0;
1969
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001970 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1971 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1972 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1973 return 0;
1974 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001975 /* Report default options for RSS on i40e */
1976 switch (cmd->flow_type) {
1977 case TCP_V4_FLOW:
1978 case UDP_V4_FLOW:
1979 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1980 /* fall through to add IP fields */
1981 case SCTP_V4_FLOW:
1982 case AH_ESP_V4_FLOW:
1983 case AH_V4_FLOW:
1984 case ESP_V4_FLOW:
1985 case IPV4_FLOW:
1986 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1987 break;
1988 case TCP_V6_FLOW:
1989 case UDP_V6_FLOW:
1990 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1991 /* fall through to add IP fields */
1992 case SCTP_V6_FLOW:
1993 case AH_ESP_V6_FLOW:
1994 case AH_V6_FLOW:
1995 case ESP_V6_FLOW:
1996 case IPV6_FLOW:
1997 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1998 break;
1999 default:
2000 return -EINVAL;
2001 }
2002
2003 return 0;
2004}
2005
2006/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002007 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2008 * @pf: Pointer to the physical function struct
2009 * @cmd: The command to get or set Rx flow classification rules
2010 * @rule_locs: Array of used rule locations
2011 *
2012 * This function populates both the total and actual rule count of
2013 * the ethtool flow classification command
2014 *
2015 * Returns 0 on success or -EMSGSIZE if entry not found
2016 **/
2017static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2018 struct ethtool_rxnfc *cmd,
2019 u32 *rule_locs)
2020{
2021 struct i40e_fdir_filter *rule;
2022 struct hlist_node *node2;
2023 int cnt = 0;
2024
2025 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002026 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002027
2028 hlist_for_each_entry_safe(rule, node2,
2029 &pf->fdir_filter_list, fdir_node) {
2030 if (cnt == cmd->rule_cnt)
2031 return -EMSGSIZE;
2032
2033 rule_locs[cnt] = rule->fd_id;
2034 cnt++;
2035 }
2036
2037 cmd->rule_cnt = cnt;
2038
2039 return 0;
2040}
2041
2042/**
2043 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2044 * @pf: Pointer to the physical function struct
2045 * @cmd: The command to get or set Rx flow classification rules
2046 *
2047 * This function looks up a filter based on the Rx flow classification
2048 * command and fills the flow spec info for it if found
2049 *
2050 * Returns 0 on success or -EINVAL if filter not found
2051 **/
2052static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2053 struct ethtool_rxnfc *cmd)
2054{
2055 struct ethtool_rx_flow_spec *fsp =
2056 (struct ethtool_rx_flow_spec *)&cmd->fs;
2057 struct i40e_fdir_filter *rule = NULL;
2058 struct hlist_node *node2;
2059
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002060 hlist_for_each_entry_safe(rule, node2,
2061 &pf->fdir_filter_list, fdir_node) {
2062 if (fsp->location <= rule->fd_id)
2063 break;
2064 }
2065
2066 if (!rule || fsp->location != rule->fd_id)
2067 return -EINVAL;
2068
2069 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002070 if (fsp->flow_type == IP_USER_FLOW) {
2071 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2072 fsp->h_u.usr_ip4_spec.proto = 0;
2073 fsp->m_u.usr_ip4_spec.proto = 0;
2074 }
2075
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002076 /* Reverse the src and dest notion, since the HW views them from
2077 * Tx perspective where as the user expects it from Rx filter view.
2078 */
2079 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2080 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2081 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2082 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002083
2084 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2085 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2086 else
2087 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002088
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002089 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2090 struct i40e_vsi *vsi;
2091
2092 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2093 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2094 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2095 fsp->m_ext.data[1] = htonl(0x1);
2096 }
2097 }
2098
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002099 return 0;
2100}
2101
2102/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002103 * i40e_get_rxnfc - command to get RX flow classification rules
2104 * @netdev: network interface device structure
2105 * @cmd: ethtool rxnfc command
2106 *
2107 * Returns Success if the command is supported.
2108 **/
2109static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2110 u32 *rule_locs)
2111{
2112 struct i40e_netdev_priv *np = netdev_priv(netdev);
2113 struct i40e_vsi *vsi = np->vsi;
2114 struct i40e_pf *pf = vsi->back;
2115 int ret = -EOPNOTSUPP;
2116
2117 switch (cmd->cmd) {
2118 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002119 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002120 ret = 0;
2121 break;
2122 case ETHTOOL_GRXFH:
2123 ret = i40e_get_rss_hash_opts(pf, cmd);
2124 break;
2125 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002126 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002127 /* report total rule count */
2128 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002129 ret = 0;
2130 break;
2131 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002132 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002133 break;
2134 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002135 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2136 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002137 default:
2138 break;
2139 }
2140
2141 return ret;
2142}
2143
2144/**
2145 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2146 * @pf: pointer to the physical function struct
2147 * @cmd: ethtool rxnfc command
2148 *
2149 * Returns Success if the flow input set is supported.
2150 **/
2151static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2152{
2153 struct i40e_hw *hw = &pf->hw;
2154 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2155 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2156
2157 /* RSS does not support anything other than hashing
2158 * to queues on src and dst IPs and ports
2159 */
2160 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2161 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2162 return -EINVAL;
2163
2164 /* We need at least the IP SRC and DEST fields for hashing */
2165 if (!(nfc->data & RXH_IP_SRC) ||
2166 !(nfc->data & RXH_IP_DST))
2167 return -EINVAL;
2168
2169 switch (nfc->flow_type) {
2170 case TCP_V4_FLOW:
2171 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2172 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002173 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002174 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002175 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2176 hena |=
2177 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2178
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002179 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002180 break;
2181 default:
2182 return -EINVAL;
2183 }
2184 break;
2185 case TCP_V6_FLOW:
2186 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2187 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002188 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002189 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002190 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2191 hena |=
2192 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2193
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002194 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002195 break;
2196 default:
2197 return -EINVAL;
2198 }
2199 break;
2200 case UDP_V4_FLOW:
2201 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2202 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002203 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002205 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2206 hena |=
2207 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2208 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2209
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002210 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2211 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212 break;
2213 default:
2214 return -EINVAL;
2215 }
2216 break;
2217 case UDP_V6_FLOW:
2218 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2219 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002220 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002221 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002222 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2223 hena |=
2224 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2225 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2226
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002227 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2228 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229 break;
2230 default:
2231 return -EINVAL;
2232 }
2233 break;
2234 case AH_ESP_V4_FLOW:
2235 case AH_V4_FLOW:
2236 case ESP_V4_FLOW:
2237 case SCTP_V4_FLOW:
2238 if ((nfc->data & RXH_L4_B_0_1) ||
2239 (nfc->data & RXH_L4_B_2_3))
2240 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002241 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242 break;
2243 case AH_ESP_V6_FLOW:
2244 case AH_V6_FLOW:
2245 case ESP_V6_FLOW:
2246 case SCTP_V6_FLOW:
2247 if ((nfc->data & RXH_L4_B_0_1) ||
2248 (nfc->data & RXH_L4_B_2_3))
2249 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002250 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002251 break;
2252 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002253 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2254 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002255 break;
2256 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002257 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2258 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002259 break;
2260 default:
2261 return -EINVAL;
2262 }
2263
2264 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2265 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2266 i40e_flush(hw);
2267
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002268 /* Save setting for future output/update */
2269 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2270
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002271 return 0;
2272}
2273
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002274/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002275 * i40e_match_fdir_input_set - Match a new filter against an existing one
2276 * @rule: The filter already added
2277 * @input: The new filter to comapre against
2278 *
2279 * Returns true if the two input set match
2280 **/
2281static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2282 struct i40e_fdir_filter *input)
2283{
2284 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2285 (rule->src_ip[0] != input->src_ip[0]) ||
2286 (rule->dst_port != input->dst_port) ||
2287 (rule->src_port != input->src_port))
2288 return false;
2289 return true;
2290}
2291
2292/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002293 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2294 * @vsi: Pointer to the targeted VSI
2295 * @input: The filter to update or NULL to indicate deletion
2296 * @sw_idx: Software index to the filter
2297 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002298 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002299 * This function updates (or deletes) a Flow Director entry from
2300 * the hlist of the corresponding PF
2301 *
2302 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002303 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002304static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2305 struct i40e_fdir_filter *input,
2306 u16 sw_idx,
2307 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002308{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002309 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002310 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002311 struct hlist_node *node2;
2312 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002313
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002314 parent = NULL;
2315 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002316
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002317 hlist_for_each_entry_safe(rule, node2,
2318 &pf->fdir_filter_list, fdir_node) {
2319 /* hash found, or no matching entry */
2320 if (rule->fd_id >= sw_idx)
2321 break;
2322 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002323 }
2324
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002325 /* if there is an old rule occupying our place remove it */
2326 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002327 if (input && !i40e_match_fdir_input_set(rule, input))
2328 err = i40e_add_del_fdir(vsi, rule, false);
2329 else if (!input)
2330 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002331 hlist_del(&rule->fdir_node);
2332 kfree(rule);
2333 pf->fdir_pf_active_filters--;
2334 }
2335
2336 /* If no input this was a delete, err should be 0 if a rule was
2337 * successfully found and removed from the list else -EINVAL
2338 */
2339 if (!input)
2340 return err;
2341
2342 /* initialize node and set software index */
2343 INIT_HLIST_NODE(&input->fdir_node);
2344
2345 /* add filter to the list */
2346 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002347 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002348 else
2349 hlist_add_head(&input->fdir_node,
2350 &pf->fdir_filter_list);
2351
2352 /* update counts */
2353 pf->fdir_pf_active_filters++;
2354
2355 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002356}
2357
2358/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002359 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2360 * @vsi: Pointer to the targeted VSI
2361 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002362 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002363 * The function removes a Flow Director filter entry from the
2364 * hlist of the corresponding PF
2365 *
2366 * Returns 0 on success
2367 */
2368static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2369 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002370{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002371 struct ethtool_rx_flow_spec *fsp =
2372 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002373 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002374 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002375
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002376 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2377 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2378 return -EBUSY;
2379
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002380 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2381 return -EBUSY;
2382
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002383 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002384
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002385 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002386 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002387}
2388
2389/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002390 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002391 * @vsi: pointer to the targeted VSI
2392 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002393 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002394 * Add Flow Director filters for a specific flow spec based on their
2395 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002396 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002397static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2398 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002399{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002400 struct ethtool_rx_flow_spec *fsp;
2401 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002402 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002403 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002404 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002405
2406 if (!vsi)
2407 return -EINVAL;
2408
2409 pf = vsi->back;
2410
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002411 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2412 return -EOPNOTSUPP;
2413
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002414 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002415 return -ENOSPC;
2416
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002417 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2418 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2419 return -EBUSY;
2420
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002421 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2422 return -EBUSY;
2423
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002424 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2425
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002426 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2427 pf->hw.func_caps.fd_filters_guaranteed)) {
2428 return -EINVAL;
2429 }
2430
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002431 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2432 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002433 return -EINVAL;
2434
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002435 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002436
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002437 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002438 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002439
2440 input->fd_id = fsp->location;
2441
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002442 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2443 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2444 else
2445 input->dest_ctl =
2446 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2447
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002448 input->q_index = fsp->ring_cookie;
2449 input->flex_off = 0;
2450 input->pctype = 0;
2451 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002452 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002453 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002454 input->flow_type = fsp->flow_type;
2455 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002456
2457 /* Reverse the src and dest notion, since the HW expects them to be from
2458 * Tx perspective where as the input from user is from Rx filter view.
2459 */
2460 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2461 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2462 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2463 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002464
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002465 if (ntohl(fsp->m_ext.data[1])) {
2466 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2467 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2468 goto free_input;
2469 }
2470 vf_id = ntohl(fsp->h_ext.data[1]);
2471 /* Find vsi id from vf id and override dest vsi */
2472 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2473 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2474 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2475 goto free_input;
2476 }
2477 }
2478
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002479 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002480free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002481 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002482 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002483 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002484 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002485
2486 return ret;
2487}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002488
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002489/**
2490 * i40e_set_rxnfc - command to set RX flow classification rules
2491 * @netdev: network interface device structure
2492 * @cmd: ethtool rxnfc command
2493 *
2494 * Returns Success if the command is supported.
2495 **/
2496static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2497{
2498 struct i40e_netdev_priv *np = netdev_priv(netdev);
2499 struct i40e_vsi *vsi = np->vsi;
2500 struct i40e_pf *pf = vsi->back;
2501 int ret = -EOPNOTSUPP;
2502
2503 switch (cmd->cmd) {
2504 case ETHTOOL_SRXFH:
2505 ret = i40e_set_rss_hash_opt(pf, cmd);
2506 break;
2507 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002508 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002509 break;
2510 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002511 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002512 break;
2513 default:
2514 break;
2515 }
2516
2517 return ret;
2518}
2519
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002520/**
2521 * i40e_max_channels - get Max number of combined channels supported
2522 * @vsi: vsi pointer
2523 **/
2524static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2525{
2526 /* TODO: This code assumes DCB and FD is disabled for now. */
2527 return vsi->alloc_queue_pairs;
2528}
2529
2530/**
2531 * i40e_get_channels - Get the current channels enabled and max supported etc.
2532 * @netdev: network interface device structure
2533 * @ch: ethtool channels structure
2534 *
2535 * We don't support separate tx and rx queues as channels. The other count
2536 * represents how many queues are being used for control. max_combined counts
2537 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2538 * q_vectors since we support a lot more queue pairs than q_vectors.
2539 **/
2540static void i40e_get_channels(struct net_device *dev,
2541 struct ethtool_channels *ch)
2542{
2543 struct i40e_netdev_priv *np = netdev_priv(dev);
2544 struct i40e_vsi *vsi = np->vsi;
2545 struct i40e_pf *pf = vsi->back;
2546
2547 /* report maximum channels */
2548 ch->max_combined = i40e_max_channels(vsi);
2549
2550 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002551 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002552 ch->max_other = ch->other_count;
2553
2554 /* Note: This code assumes DCB is disabled for now. */
2555 ch->combined_count = vsi->num_queue_pairs;
2556}
2557
2558/**
2559 * i40e_set_channels - Set the new channels count.
2560 * @netdev: network interface device structure
2561 * @ch: ethtool channels structure
2562 *
2563 * The new channels count may not be the same as requested by the user
2564 * since it gets rounded down to a power of 2 value.
2565 **/
2566static int i40e_set_channels(struct net_device *dev,
2567 struct ethtool_channels *ch)
2568{
2569 struct i40e_netdev_priv *np = netdev_priv(dev);
2570 unsigned int count = ch->combined_count;
2571 struct i40e_vsi *vsi = np->vsi;
2572 struct i40e_pf *pf = vsi->back;
2573 int new_count;
2574
2575 /* We do not support setting channels for any other VSI at present */
2576 if (vsi->type != I40E_VSI_MAIN)
2577 return -EINVAL;
2578
2579 /* verify they are not requesting separate vectors */
2580 if (!count || ch->rx_count || ch->tx_count)
2581 return -EINVAL;
2582
2583 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002584 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002585 return -EINVAL;
2586
2587 /* verify the number of channels does not exceed hardware limits */
2588 if (count > i40e_max_channels(vsi))
2589 return -EINVAL;
2590
2591 /* update feature limits from largest to smallest supported values */
2592 /* TODO: Flow director limit, DCB etc */
2593
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002594 /* use rss_reconfig to rebuild with new queue count and update traffic
2595 * class queue mapping
2596 */
2597 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002598 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002599 return 0;
2600 else
2601 return -EINVAL;
2602}
2603
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002604/**
2605 * i40e_get_rxfh_key_size - get the RSS hash key size
2606 * @netdev: network interface device structure
2607 *
2608 * Returns the table size.
2609 **/
2610static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2611{
2612 return I40E_HKEY_ARRAY_SIZE;
2613}
2614
2615/**
2616 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2617 * @netdev: network interface device structure
2618 *
2619 * Returns the table size.
2620 **/
2621static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2622{
2623 return I40E_HLUT_ARRAY_SIZE;
2624}
2625
2626static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2627 u8 *hfunc)
2628{
2629 struct i40e_netdev_priv *np = netdev_priv(netdev);
2630 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002631 u8 *lut, *seed = NULL;
2632 int ret;
2633 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002634
2635 if (hfunc)
2636 *hfunc = ETH_RSS_HASH_TOP;
2637
2638 if (!indir)
2639 return 0;
2640
Helin Zhang043dd652015-10-21 19:56:23 -04002641 seed = key;
2642 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2643 if (!lut)
2644 return -ENOMEM;
2645 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2646 if (ret)
2647 goto out;
2648 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2649 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002650
Helin Zhang043dd652015-10-21 19:56:23 -04002651out:
2652 kfree(lut);
2653
2654 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002655}
2656
2657/**
2658 * i40e_set_rxfh - set the rx flow hash indirection table
2659 * @netdev: network interface device structure
2660 * @indir: indirection table
2661 * @key: hash key
2662 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002663 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002664 * returns 0 after programming the table.
2665 **/
2666static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2667 const u8 *key, const u8 hfunc)
2668{
2669 struct i40e_netdev_priv *np = netdev_priv(netdev);
2670 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002671 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002672 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002673
2674 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2675 return -EOPNOTSUPP;
2676
2677 if (!indir)
2678 return 0;
2679
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002680 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002681 if (!vsi->rss_hkey_user) {
2682 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2683 GFP_KERNEL);
2684 if (!vsi->rss_hkey_user)
2685 return -ENOMEM;
2686 }
2687 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2688 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002689 }
Helin Zhang28c58692015-10-26 19:44:27 -04002690 if (!vsi->rss_lut_user) {
2691 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2692 if (!vsi->rss_lut_user)
2693 return -ENOMEM;
2694 }
Helin Zhang043dd652015-10-21 19:56:23 -04002695
Helin Zhang28c58692015-10-26 19:44:27 -04002696 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2697 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2698 vsi->rss_lut_user[i] = (u8)(indir[i]);
2699
2700 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2701 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002702}
2703
Greg Rose7e45ab42015-02-06 08:52:19 +00002704/**
2705 * i40e_get_priv_flags - report device private flags
2706 * @dev: network interface device structure
2707 *
2708 * The get string set count and the string set should be matched for each
2709 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2710 * array.
2711 *
2712 * Returns a u32 bitmap of flags.
2713 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002714static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002715{
2716 struct i40e_netdev_priv *np = netdev_priv(dev);
2717 struct i40e_vsi *vsi = np->vsi;
2718 struct i40e_pf *pf = vsi->back;
2719 u32 ret_flags = 0;
2720
2721 ret_flags |= pf->hw.func_caps.npar_enable ?
2722 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002723 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2724 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002725 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2726 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002727 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2728 I40E_PRIV_FLAGS_VEB_STATS : 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002729 ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
2730 I40E_PRIV_FLAGS_PS : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002731
2732 return ret_flags;
2733}
2734
Shannon Nelson9ac77262015-08-27 11:42:40 -04002735/**
2736 * i40e_set_priv_flags - set private flags
2737 * @dev: network interface device structure
2738 * @flags: bit flags to be set
2739 **/
2740static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2741{
2742 struct i40e_netdev_priv *np = netdev_priv(dev);
2743 struct i40e_vsi *vsi = np->vsi;
2744 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002745 bool reset_required = false;
2746
2747 /* NOTE: MFP is not settable */
2748
2749 /* allow the user to control the method of receive
2750 * buffer DMA, whether the packet is split at header
2751 * boundaries into two separate buffers. In some cases
2752 * one routine or the other will perform better.
2753 */
2754 if ((flags & I40E_PRIV_FLAGS_PS) &&
2755 !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2756 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
2757 pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
2758 reset_required = true;
2759 } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
2760 (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2761 pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
2762 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
2763 reset_required = true;
2764 }
Shannon Nelson9ac77262015-08-27 11:42:40 -04002765
2766 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2767 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2768 else
2769 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2770
Jesse Brandeburgef171782015-09-03 17:18:49 -04002771 /* allow the user to control the state of the Flow
2772 * Director ATR (Application Targeted Routing) feature
2773 * of the driver
2774 */
2775 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2776 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2777 } else {
2778 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2779 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2780 }
2781
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002782 if (flags & I40E_PRIV_FLAGS_VEB_STATS)
2783 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
2784 else
2785 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
2786
Jesse Brandeburg827de392015-11-06 15:26:07 -08002787 /* if needed, issue reset to cause things to take effect */
2788 if (reset_required)
2789 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2790
Shannon Nelson9ac77262015-08-27 11:42:40 -04002791 return 0;
2792}
2793
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002794static const struct ethtool_ops i40e_ethtool_ops = {
2795 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002796 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002797 .get_drvinfo = i40e_get_drvinfo,
2798 .get_regs_len = i40e_get_regs_len,
2799 .get_regs = i40e_get_regs,
2800 .nway_reset = i40e_nway_reset,
2801 .get_link = ethtool_op_get_link,
2802 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002803 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002804 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002805 .get_eeprom_len = i40e_get_eeprom_len,
2806 .get_eeprom = i40e_get_eeprom,
2807 .get_ringparam = i40e_get_ringparam,
2808 .set_ringparam = i40e_set_ringparam,
2809 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002810 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002811 .get_msglevel = i40e_get_msglevel,
2812 .set_msglevel = i40e_set_msglevel,
2813 .get_rxnfc = i40e_get_rxnfc,
2814 .set_rxnfc = i40e_set_rxnfc,
2815 .self_test = i40e_diag_test,
2816 .get_strings = i40e_get_strings,
2817 .set_phys_id = i40e_set_phys_id,
2818 .get_sset_count = i40e_get_sset_count,
2819 .get_ethtool_stats = i40e_get_ethtool_stats,
2820 .get_coalesce = i40e_get_coalesce,
2821 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002822 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2823 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2824 .get_rxfh = i40e_get_rxfh,
2825 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002826 .get_channels = i40e_get_channels,
2827 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002828 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002829 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002830 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002831};
2832
2833void i40e_set_ethtool_ops(struct net_device *netdev)
2834{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002835 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002836}