blob: 185ac91ce78f0e54c10cae4ab99b8f150eea1de0 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Shannon Nelson41a9e552014-04-23 04:50:20 +000091};
92
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +000093static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
94 struct ethtool_rxnfc *cmd);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +000095
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096/* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
102 *
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
105 */
106static struct i40e_stats i40e_gstrings_stats[] = {
107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000148 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000149 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000150 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400151 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400152 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000153 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000156 /* LPI stats */
157 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
158 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
159 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
160 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000161};
162
Vasu Dev38e00432014-08-01 13:27:03 -0700163#ifdef I40E_FCOE
164static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
165 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
166 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
167 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
168 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
169 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
170 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
171 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
172 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
173};
174
175#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000177 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
178 * 2 /* Tx and Rx together */ \
179 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000180#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
181#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000182#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700183#ifdef I40E_FCOE
184#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
185#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
186 I40E_FCOE_STATS_LEN + \
187 I40E_MISC_STATS_LEN + \
188 I40E_QUEUE_STATS_LEN((n)))
189#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000191 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700193#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194#define I40E_PFC_STATS_LEN ( \
195 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
197 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
200 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400201#define I40E_VEB_TC_STATS_LEN ( \
202 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
203 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
204 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
206 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000207#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400208#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000209#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
210 I40E_PFC_STATS_LEN + \
211 I40E_VSI_STATS_LEN((n)))
212
213enum i40e_ethtool_test_id {
214 I40E_ETH_TEST_REG = 0,
215 I40E_ETH_TEST_EEPROM,
216 I40E_ETH_TEST_INTR,
217 I40E_ETH_TEST_LOOPBACK,
218 I40E_ETH_TEST_LINK,
219};
220
221static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
222 "Register test (offline)",
223 "Eeprom test (offline)",
224 "Interrupt test (offline)",
225 "Loopback test (offline)",
226 "Link test (on/offline)"
227};
228
229#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
230
Greg Rose7e45ab42015-02-06 08:52:19 +0000231static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
232 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400233 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400234 "flow-director-atr",
Greg Rose7e45ab42015-02-06 08:52:19 +0000235};
236
Shannon Nelson9ac77262015-08-27 11:42:40 -0400237#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000238
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000239/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000240 * i40e_partition_setting_complaint - generic complaint for MFP restriction
241 * @pf: the PF struct
242 **/
243static void i40e_partition_setting_complaint(struct i40e_pf *pf)
244{
245 dev_info(&pf->pdev->dev,
246 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
247}
248
249/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000250 * i40e_get_settings_link_up - Get the Link settings for when link is up
251 * @hw: hw structure
252 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000253 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000254 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000255 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000256static void i40e_get_settings_link_up(struct i40e_hw *hw,
257 struct ethtool_cmd *ecmd,
258 struct net_device *netdev)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000261 u32 link_speed = hw_link_info->link_speed;
262
Catherine Sullivane8278452015-02-06 08:52:08 +0000263 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000264 switch (hw_link_info->phy_type) {
265 case I40E_PHY_TYPE_40GBASE_CR4:
266 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000267 ecmd->supported = SUPPORTED_Autoneg |
268 SUPPORTED_40000baseCR4_Full;
269 ecmd->advertising = ADVERTISED_Autoneg |
270 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000271 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000272 case I40E_PHY_TYPE_XLAUI:
273 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000274 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000275 ecmd->supported = SUPPORTED_40000baseCR4_Full;
276 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000277 case I40E_PHY_TYPE_40GBASE_SR4:
278 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000279 break;
280 case I40E_PHY_TYPE_40GBASE_LR4:
281 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000282 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000283 case I40E_PHY_TYPE_10GBASE_SR:
284 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000285 case I40E_PHY_TYPE_1000BASE_SX:
286 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400287 ecmd->supported = SUPPORTED_10000baseT_Full;
288 if (hw_link_info->module_type[2] &
289 I40E_MODULE_TYPE_1000BASE_SX ||
290 hw_link_info->module_type[2] &
291 I40E_MODULE_TYPE_1000BASE_LX) {
292 ecmd->supported |= SUPPORTED_1000baseT_Full;
293 if (hw_link_info->requested_speeds &
294 I40E_LINK_SPEED_1GB)
295 ecmd->advertising |= ADVERTISED_1000baseT_Full;
296 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000297 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
298 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000299 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000300 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000301 case I40E_PHY_TYPE_1000BASE_T:
302 case I40E_PHY_TYPE_100BASE_TX:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000303 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000304 SUPPORTED_10000baseT_Full |
305 SUPPORTED_1000baseT_Full |
306 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000307 ecmd->advertising = ADVERTISED_Autoneg;
308 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
309 ecmd->advertising |= ADVERTISED_10000baseT_Full;
310 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
311 ecmd->advertising |= ADVERTISED_1000baseT_Full;
312 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
313 ecmd->advertising |= ADVERTISED_100baseT_Full;
314 break;
315 case I40E_PHY_TYPE_10GBASE_CR1_CU:
316 case I40E_PHY_TYPE_10GBASE_CR1:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000319 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000320 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000321 break;
322 case I40E_PHY_TYPE_XAUI:
323 case I40E_PHY_TYPE_XFI:
324 case I40E_PHY_TYPE_SFI:
325 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000326 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000327 ecmd->supported = SUPPORTED_10000baseT_Full;
328 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000329 case I40E_PHY_TYPE_SGMII:
330 ecmd->supported = SUPPORTED_Autoneg |
331 SUPPORTED_1000baseT_Full |
332 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000333 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
334 ecmd->advertising |= ADVERTISED_1000baseT_Full;
335 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
336 ecmd->advertising |= ADVERTISED_100baseT_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000337 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400338 /* Backplane is set based on supported phy types in get_settings
339 * so don't set anything here but don't warn either
340 */
341 case I40E_PHY_TYPE_40GBASE_KR4:
342 case I40E_PHY_TYPE_20GBASE_KR2:
343 case I40E_PHY_TYPE_10GBASE_KR:
344 case I40E_PHY_TYPE_10GBASE_KX4:
345 case I40E_PHY_TYPE_1000BASE_KX:
346 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000347 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000348 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000349 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
350 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000351 }
352
Catherine Sullivane8278452015-02-06 08:52:08 +0000353 /* Set speed and duplex */
354 switch (link_speed) {
355 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400356 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000357 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700358 case I40E_LINK_SPEED_20GB:
359 ethtool_cmd_speed_set(ecmd, SPEED_20000);
360 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000361 case I40E_LINK_SPEED_10GB:
362 ethtool_cmd_speed_set(ecmd, SPEED_10000);
363 break;
364 case I40E_LINK_SPEED_1GB:
365 ethtool_cmd_speed_set(ecmd, SPEED_1000);
366 break;
367 case I40E_LINK_SPEED_100MB:
368 ethtool_cmd_speed_set(ecmd, SPEED_100);
369 break;
370 default:
371 break;
372 }
373 ecmd->duplex = DUPLEX_FULL;
374}
375
376/**
377 * i40e_get_settings_link_down - Get the Link settings for when link is down
378 * @hw: hw structure
379 * @ecmd: ethtool command to fill in
380 *
381 * Reports link settings that can be determined when link is down
382 **/
383static void i40e_get_settings_link_down(struct i40e_hw *hw,
384 struct ethtool_cmd *ecmd)
385{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400386 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000387
388 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400389 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000390 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400391 ecmd->supported = 0x0;
392 ecmd->advertising = 0x0;
393 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
394 ecmd->supported |= SUPPORTED_Autoneg |
395 SUPPORTED_1000baseT_Full |
396 SUPPORTED_100baseT_Full;
397 ecmd->advertising |= ADVERTISED_Autoneg |
398 ADVERTISED_1000baseT_Full |
399 ADVERTISED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000400 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400401 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
402 phy_types & I40E_CAP_PHY_TYPE_XFI ||
403 phy_types & I40E_CAP_PHY_TYPE_SFI ||
404 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
405 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
406 ecmd->supported |= SUPPORTED_10000baseT_Full;
407 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
408 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
409 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
410 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
411 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
412 ecmd->supported |= SUPPORTED_Autoneg |
413 SUPPORTED_10000baseT_Full;
414 ecmd->advertising |= ADVERTISED_Autoneg |
415 ADVERTISED_10000baseT_Full;
416 }
417 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
418 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
419 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
420 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
421 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
422 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
423 ecmd->supported |= SUPPORTED_Autoneg |
424 SUPPORTED_40000baseCR4_Full;
425 ecmd->advertising |= ADVERTISED_Autoneg |
426 ADVERTISED_40000baseCR4_Full;
427 }
428 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
429 ecmd->supported |= SUPPORTED_Autoneg |
430 SUPPORTED_100baseT_Full;
431 ecmd->advertising |= ADVERTISED_Autoneg |
432 ADVERTISED_100baseT_Full;
433 }
434 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
435 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
436 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
437 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
438 ecmd->supported |= SUPPORTED_Autoneg |
439 SUPPORTED_1000baseT_Full;
440 ecmd->advertising |= ADVERTISED_Autoneg |
441 ADVERTISED_1000baseT_Full;
442 }
443 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
444 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
445 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
446 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000447
448 /* With no link speed and duplex are unknown */
449 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
450 ecmd->duplex = DUPLEX_UNKNOWN;
451}
452
453/**
454 * i40e_get_settings - Get Link Speed and Duplex settings
455 * @netdev: network interface device structure
456 * @ecmd: ethtool command
457 *
458 * Reports speed/duplex settings based on media_type
459 **/
460static int i40e_get_settings(struct net_device *netdev,
461 struct ethtool_cmd *ecmd)
462{
463 struct i40e_netdev_priv *np = netdev_priv(netdev);
464 struct i40e_pf *pf = np->vsi->back;
465 struct i40e_hw *hw = &pf->hw;
466 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
467 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
468
469 if (link_up)
470 i40e_get_settings_link_up(hw, ecmd, netdev);
471 else
472 i40e_get_settings_link_down(hw, ecmd);
473
474 /* Now set the settings that don't rely on link being up/down */
475
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400476 /* For backplane, supported and advertised are only reliant on the
477 * phy types the NVM specifies are supported.
478 */
479 if (hw->device_id == I40E_DEV_ID_KX_B ||
480 hw->device_id == I40E_DEV_ID_KX_C ||
481 hw->device_id == I40E_DEV_ID_20G_KR2 ||
482 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
483 ecmd->supported = SUPPORTED_Autoneg;
484 ecmd->advertising = ADVERTISED_Autoneg;
485 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
486 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
487 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
488 }
489 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
490 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
491 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
492 }
493 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
494 ecmd->supported |= SUPPORTED_10000baseKR_Full;
495 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
496 }
497 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
498 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
499 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
500 }
501 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
502 ecmd->supported |= SUPPORTED_1000baseKX_Full;
503 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
504 }
505 }
506
Catherine Sullivane8278452015-02-06 08:52:08 +0000507 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000508 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
509 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000510
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000511 switch (hw->phy.media_type) {
512 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000513 ecmd->supported |= SUPPORTED_Autoneg |
514 SUPPORTED_Backplane;
515 ecmd->advertising |= ADVERTISED_Autoneg |
516 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000517 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000518 break;
519 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000520 ecmd->supported |= SUPPORTED_TP;
521 ecmd->advertising |= ADVERTISED_TP;
522 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000523 break;
524 case I40E_MEDIA_TYPE_DA:
525 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000526 ecmd->supported |= SUPPORTED_FIBRE;
527 ecmd->advertising |= ADVERTISED_FIBRE;
528 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000529 break;
530 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000531 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000532 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000533 break;
534 case I40E_MEDIA_TYPE_UNKNOWN:
535 default:
536 ecmd->port = PORT_OTHER;
537 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000538 }
539
Catherine Sullivane8278452015-02-06 08:52:08 +0000540 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000541 ecmd->transceiver = XCVR_EXTERNAL;
542
Catherine Sullivane8278452015-02-06 08:52:08 +0000543 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000544 ecmd->supported |= SUPPORTED_Pause;
545
Catherine Sullivane8278452015-02-06 08:52:08 +0000546 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000547 case I40E_FC_FULL:
548 ecmd->advertising |= ADVERTISED_Pause;
549 break;
550 case I40E_FC_TX_PAUSE:
551 ecmd->advertising |= ADVERTISED_Asym_Pause;
552 break;
553 case I40E_FC_RX_PAUSE:
554 ecmd->advertising |= (ADVERTISED_Pause |
555 ADVERTISED_Asym_Pause);
556 break;
557 default:
558 ecmd->advertising &= ~(ADVERTISED_Pause |
559 ADVERTISED_Asym_Pause);
560 break;
561 }
562
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000563 return 0;
564}
565
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000566/**
567 * i40e_set_settings - Set Speed and Duplex
568 * @netdev: network interface device structure
569 * @ecmd: ethtool command
570 *
571 * Set speed/duplex per media_types advertised/forced
572 **/
573static int i40e_set_settings(struct net_device *netdev,
574 struct ethtool_cmd *ecmd)
575{
576 struct i40e_netdev_priv *np = netdev_priv(netdev);
577 struct i40e_aq_get_phy_abilities_resp abilities;
578 struct i40e_aq_set_phy_config config;
579 struct i40e_pf *pf = np->vsi->back;
580 struct i40e_vsi *vsi = np->vsi;
581 struct i40e_hw *hw = &pf->hw;
582 struct ethtool_cmd safe_ecmd;
583 i40e_status status = 0;
584 bool change = false;
585 int err = 0;
586 u8 autoneg;
587 u32 advertise;
588
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000589 /* Changing port settings is not supported if this isn't the
590 * port's controlling PF
591 */
592 if (hw->partition_id != 1) {
593 i40e_partition_setting_complaint(pf);
594 return -EOPNOTSUPP;
595 }
596
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000597 if (vsi != pf->vsi[pf->lan_vsi])
598 return -EOPNOTSUPP;
599
600 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
601 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000602 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
603 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000604 return -EOPNOTSUPP;
605
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400606 if (hw->device_id == I40E_DEV_ID_KX_B ||
607 hw->device_id == I40E_DEV_ID_KX_C ||
608 hw->device_id == I40E_DEV_ID_20G_KR2 ||
609 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
610 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
611 return -EOPNOTSUPP;
612 }
613
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000614 /* get our own copy of the bits to check against */
615 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
616 i40e_get_settings(netdev, &safe_ecmd);
617
618 /* save autoneg and speed out of ecmd */
619 autoneg = ecmd->autoneg;
620 advertise = ecmd->advertising;
621
622 /* set autoneg and speed back to what they currently are */
623 ecmd->autoneg = safe_ecmd.autoneg;
624 ecmd->advertising = safe_ecmd.advertising;
625
626 ecmd->cmd = safe_ecmd.cmd;
627 /* If ecmd and safe_ecmd are not the same now, then they are
628 * trying to set something that we do not support
629 */
630 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
631 return -EOPNOTSUPP;
632
633 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
634 usleep_range(1000, 2000);
635
636 /* Get the current phy config */
637 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
638 NULL);
639 if (status)
640 return -EAGAIN;
641
Catherine Sullivan124ed152014-07-12 07:28:12 +0000642 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000643 * set below
644 */
645 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000646 config.abilities = abilities.abilities;
647
648 /* Check autoneg */
649 if (autoneg == AUTONEG_ENABLE) {
650 /* If autoneg is not supported, return error */
651 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
652 netdev_info(netdev, "Autoneg not supported on this phy\n");
653 return -EINVAL;
654 }
655 /* If autoneg was not already enabled */
656 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
657 config.abilities = abilities.abilities |
658 I40E_AQ_PHY_ENABLE_AN;
659 change = true;
660 }
661 } else {
662 /* If autoneg is supported 10GBASE_T is the only phy that
663 * can disable it, so otherwise return error
664 */
665 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
666 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
667 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
668 return -EINVAL;
669 }
670 /* If autoneg is currently enabled */
671 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000672 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000673 ~I40E_AQ_PHY_ENABLE_AN;
674 change = true;
675 }
676 }
677
678 if (advertise & ~safe_ecmd.supported)
679 return -EINVAL;
680
681 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000682 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000683 if (advertise & ADVERTISED_1000baseT_Full ||
684 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000685 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000686 if (advertise & ADVERTISED_10000baseT_Full ||
687 advertise & ADVERTISED_10000baseKX4_Full ||
688 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000689 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700690 if (advertise & ADVERTISED_20000baseKR2_Full)
691 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000692 if (advertise & ADVERTISED_40000baseKR4_Full ||
693 advertise & ADVERTISED_40000baseCR4_Full ||
694 advertise & ADVERTISED_40000baseSR4_Full ||
695 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000696 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000697
Catherine Sullivan0002e112015-08-26 15:14:16 -0400698 /* If speed didn't get set, set it to what it currently is.
699 * This is needed because if advertise is 0 (as it is when autoneg
700 * is disabled) then speed won't get set.
701 */
702 if (!config.link_speed)
703 config.link_speed = abilities.link_speed;
704
Catherine Sullivan124ed152014-07-12 07:28:12 +0000705 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000706 /* copy over the rest of the abilities */
707 config.phy_type = abilities.phy_type;
708 config.eee_capability = abilities.eee_capability;
709 config.eeer = abilities.eeer_val;
710 config.low_power_ctrl = abilities.d3_lpan;
711
Catherine Sullivane8278452015-02-06 08:52:08 +0000712 /* save the requested speeds */
713 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000714 /* set link and auto negotiation so changes take effect */
715 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
716 /* If link is up put link down */
717 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
718 /* Tell the OS link is going down, the link will go
719 * back up when fw says it is ready asynchronously
720 */
Matt Jaredc156f852015-08-27 11:42:39 -0400721 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000722 netif_carrier_off(netdev);
723 netif_tx_stop_all_queues(netdev);
724 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000725
726 /* make the aq call */
727 status = i40e_aq_set_phy_config(hw, &config, NULL);
728 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400729 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
730 i40e_stat_str(hw, status),
731 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000732 return -EAGAIN;
733 }
734
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400735 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000736 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400737 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
738 i40e_stat_str(hw, status),
739 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000740
741 } else {
742 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
743 }
744
745 return err;
746}
747
Jesse Brandeburga6599722014-06-04 08:45:25 +0000748static int i40e_nway_reset(struct net_device *netdev)
749{
750 /* restart autonegotiation */
751 struct i40e_netdev_priv *np = netdev_priv(netdev);
752 struct i40e_pf *pf = np->vsi->back;
753 struct i40e_hw *hw = &pf->hw;
754 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
755 i40e_status ret = 0;
756
757 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
758 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400759 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
760 i40e_stat_str(hw, ret),
761 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000762 return -EIO;
763 }
764
765 return 0;
766}
767
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000768/**
769 * i40e_get_pauseparam - Get Flow Control status
770 * Return tx/rx-pause status
771 **/
772static void i40e_get_pauseparam(struct net_device *netdev,
773 struct ethtool_pauseparam *pause)
774{
775 struct i40e_netdev_priv *np = netdev_priv(netdev);
776 struct i40e_pf *pf = np->vsi->back;
777 struct i40e_hw *hw = &pf->hw;
778 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000779 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000780
781 pause->autoneg =
782 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
783 AUTONEG_ENABLE : AUTONEG_DISABLE);
784
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000785 /* PFC enabled so report LFC as off */
786 if (dcbx_cfg->pfc.pfcenable) {
787 pause->rx_pause = 0;
788 pause->tx_pause = 0;
789 return;
790 }
791
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000792 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000793 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000794 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000795 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000796 } else if (hw->fc.current_mode == I40E_FC_FULL) {
797 pause->rx_pause = 1;
798 pause->tx_pause = 1;
799 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000800}
801
Catherine Sullivan2becc352014-06-04 08:45:27 +0000802/**
803 * i40e_set_pauseparam - Set Flow Control parameter
804 * @netdev: network interface device structure
805 * @pause: return tx/rx flow control status
806 **/
807static int i40e_set_pauseparam(struct net_device *netdev,
808 struct ethtool_pauseparam *pause)
809{
810 struct i40e_netdev_priv *np = netdev_priv(netdev);
811 struct i40e_pf *pf = np->vsi->back;
812 struct i40e_vsi *vsi = np->vsi;
813 struct i40e_hw *hw = &pf->hw;
814 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000815 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000816 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
817 i40e_status status;
818 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000819 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000820
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000821 /* Changing the port's flow control is not supported if this isn't the
822 * port's controlling PF
823 */
824 if (hw->partition_id != 1) {
825 i40e_partition_setting_complaint(pf);
826 return -EOPNOTSUPP;
827 }
828
Catherine Sullivan2becc352014-06-04 08:45:27 +0000829 if (vsi != pf->vsi[pf->lan_vsi])
830 return -EOPNOTSUPP;
831
832 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
833 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
834 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
835 return -EOPNOTSUPP;
836 }
837
838 /* If we have link and don't have autoneg */
839 if (!test_bit(__I40E_DOWN, &pf->state) &&
840 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
841 /* Send message that it might not necessarily work*/
842 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
843 }
844
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000845 if (dcbx_cfg->pfc.pfcenable) {
846 netdev_info(netdev,
847 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000848 return -EOPNOTSUPP;
849 }
850
851 if (pause->rx_pause && pause->tx_pause)
852 hw->fc.requested_mode = I40E_FC_FULL;
853 else if (pause->rx_pause && !pause->tx_pause)
854 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
855 else if (!pause->rx_pause && pause->tx_pause)
856 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
857 else if (!pause->rx_pause && !pause->tx_pause)
858 hw->fc.requested_mode = I40E_FC_NONE;
859 else
860 return -EINVAL;
861
Catherine Sullivan94128512014-07-12 07:28:16 +0000862 /* Tell the OS link is going down, the link will go back up when fw
863 * says it is ready asynchronously
864 */
Matt Jaredc156f852015-08-27 11:42:39 -0400865 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000866 netif_carrier_off(netdev);
867 netif_tx_stop_all_queues(netdev);
868
Catherine Sullivan2becc352014-06-04 08:45:27 +0000869 /* Set the fc mode and only restart an if link is up*/
870 status = i40e_set_fc(hw, &aq_failures, link_up);
871
872 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400873 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
874 i40e_stat_str(hw, status),
875 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000876 err = -EAGAIN;
877 }
878 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400879 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
880 i40e_stat_str(hw, status),
881 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000882 err = -EAGAIN;
883 }
884 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400885 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
886 i40e_stat_str(hw, status),
887 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000888 err = -EAGAIN;
889 }
890
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000891 if (!test_bit(__I40E_DOWN, &pf->state)) {
892 /* Give it a little more time to try to come back */
893 msleep(75);
894 if (!test_bit(__I40E_DOWN, &pf->state))
895 return i40e_nway_reset(netdev);
896 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000897
898 return err;
899}
900
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000901static u32 i40e_get_msglevel(struct net_device *netdev)
902{
903 struct i40e_netdev_priv *np = netdev_priv(netdev);
904 struct i40e_pf *pf = np->vsi->back;
905
906 return pf->msg_enable;
907}
908
909static void i40e_set_msglevel(struct net_device *netdev, u32 data)
910{
911 struct i40e_netdev_priv *np = netdev_priv(netdev);
912 struct i40e_pf *pf = np->vsi->back;
913
914 if (I40E_DEBUG_USER & data)
915 pf->hw.debug_mask = data;
916 pf->msg_enable = data;
917}
918
919static int i40e_get_regs_len(struct net_device *netdev)
920{
921 int reg_count = 0;
922 int i;
923
924 for (i = 0; i40e_reg_list[i].offset != 0; i++)
925 reg_count += i40e_reg_list[i].elements;
926
927 return reg_count * sizeof(u32);
928}
929
930static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
931 void *p)
932{
933 struct i40e_netdev_priv *np = netdev_priv(netdev);
934 struct i40e_pf *pf = np->vsi->back;
935 struct i40e_hw *hw = &pf->hw;
936 u32 *reg_buf = p;
937 int i, j, ri;
938 u32 reg;
939
940 /* Tell ethtool which driver-version-specific regs output we have.
941 *
942 * At some point, if we have ethtool doing special formatting of
943 * this data, it will rely on this version number to know how to
944 * interpret things. Hence, this needs to be updated if/when the
945 * diags register table is changed.
946 */
947 regs->version = 1;
948
949 /* loop through the diags reg table for what to print */
950 ri = 0;
951 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
952 for (j = 0; j < i40e_reg_list[i].elements; j++) {
953 reg = i40e_reg_list[i].offset
954 + (j * i40e_reg_list[i].stride);
955 reg_buf[ri++] = rd32(hw, reg);
956 }
957 }
958
959}
960
961static int i40e_get_eeprom(struct net_device *netdev,
962 struct ethtool_eeprom *eeprom, u8 *bytes)
963{
964 struct i40e_netdev_priv *np = netdev_priv(netdev);
965 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000966 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000967 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000968 u8 *eeprom_buff;
969 u16 i, sectors;
970 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000971 u32 magic;
972
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000973#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000974 if (eeprom->len == 0)
975 return -EINVAL;
976
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000977 /* check for NVMUpdate access method */
978 magic = hw->vendor_id | (hw->device_id << 16);
979 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000980 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000981 int errno;
982
983 /* make sure it is the right magic for NVMUpdate */
984 if ((eeprom->magic >> 16) != hw->device_id)
985 return -EINVAL;
986
Shannon Nelsonc150a502014-11-13 08:23:13 +0000987 cmd = (struct i40e_nvm_access *)eeprom;
988 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +0000989 if (ret_val &&
990 ((hw->aq.asq_last_status != I40E_AQ_RC_EACCES) ||
991 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000992 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000993 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
994 ret_val, hw->aq.asq_last_status, errno,
995 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
996 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000997
998 return errno;
999 }
1000
1001 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001002 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1003
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001004 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001005 if (!eeprom_buff)
1006 return -ENOMEM;
1007
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001008 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1009 if (ret_val) {
1010 dev_info(&pf->pdev->dev,
1011 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1012 ret_val, hw->aq.asq_last_status);
1013 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001014 }
1015
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001016 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1017 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1018 len = I40E_NVM_SECTOR_SIZE;
1019 last = false;
1020 for (i = 0; i < sectors; i++) {
1021 if (i == (sectors - 1)) {
1022 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1023 last = true;
1024 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001025 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1026 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001027 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001028 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001029 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001030 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001031 "read NVM failed, invalid offset 0x%x\n",
1032 offset);
1033 break;
1034 } else if (ret_val &&
1035 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1036 dev_info(&pf->pdev->dev,
1037 "read NVM failed, access, offset 0x%x\n",
1038 offset);
1039 break;
1040 } else if (ret_val) {
1041 dev_info(&pf->pdev->dev,
1042 "read NVM failed offset %d err=%d status=0x%x\n",
1043 offset, ret_val, hw->aq.asq_last_status);
1044 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001045 }
1046 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001047
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001048 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001049 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001050free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001051 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001052 return ret_val;
1053}
1054
1055static int i40e_get_eeprom_len(struct net_device *netdev)
1056{
1057 struct i40e_netdev_priv *np = netdev_priv(netdev);
1058 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001059 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001060
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001061 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1062 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1063 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1064 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001065 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001066 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001067}
1068
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001069static int i40e_set_eeprom(struct net_device *netdev,
1070 struct ethtool_eeprom *eeprom, u8 *bytes)
1071{
1072 struct i40e_netdev_priv *np = netdev_priv(netdev);
1073 struct i40e_hw *hw = &np->vsi->back->hw;
1074 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001075 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001076 int ret_val = 0;
1077 int errno;
1078 u32 magic;
1079
1080 /* normal ethtool set_eeprom is not supported */
1081 magic = hw->vendor_id | (hw->device_id << 16);
1082 if (eeprom->magic == magic)
1083 return -EOPNOTSUPP;
1084
1085 /* check for NVMUpdate access method */
1086 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1087 return -EINVAL;
1088
1089 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1090 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1091 return -EBUSY;
1092
Shannon Nelsonc150a502014-11-13 08:23:13 +00001093 cmd = (struct i40e_nvm_access *)eeprom;
1094 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson29a06452015-02-27 09:18:33 +00001095 if (ret_val &&
1096 ((hw->aq.asq_last_status != I40E_AQ_RC_EPERM &&
1097 hw->aq.asq_last_status != I40E_AQ_RC_EBUSY) ||
1098 (hw->debug_mask & I40E_DEBUG_NVM)))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001099 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001100 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1101 ret_val, hw->aq.asq_last_status, errno,
1102 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1103 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001104
1105 return errno;
1106}
1107
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001108static void i40e_get_drvinfo(struct net_device *netdev,
1109 struct ethtool_drvinfo *drvinfo)
1110{
1111 struct i40e_netdev_priv *np = netdev_priv(netdev);
1112 struct i40e_vsi *vsi = np->vsi;
1113 struct i40e_pf *pf = vsi->back;
1114
1115 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1116 strlcpy(drvinfo->version, i40e_driver_version_str,
1117 sizeof(drvinfo->version));
1118 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
1119 sizeof(drvinfo->fw_version));
1120 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1121 sizeof(drvinfo->bus_info));
Greg Rose7e45ab42015-02-06 08:52:19 +00001122 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001123}
1124
1125static void i40e_get_ringparam(struct net_device *netdev,
1126 struct ethtool_ringparam *ring)
1127{
1128 struct i40e_netdev_priv *np = netdev_priv(netdev);
1129 struct i40e_pf *pf = np->vsi->back;
1130 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1131
1132 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1133 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1134 ring->rx_mini_max_pending = 0;
1135 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001136 ring->rx_pending = vsi->rx_rings[0]->count;
1137 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001138 ring->rx_mini_pending = 0;
1139 ring->rx_jumbo_pending = 0;
1140}
1141
1142static int i40e_set_ringparam(struct net_device *netdev,
1143 struct ethtool_ringparam *ring)
1144{
1145 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1146 struct i40e_netdev_priv *np = netdev_priv(netdev);
1147 struct i40e_vsi *vsi = np->vsi;
1148 struct i40e_pf *pf = vsi->back;
1149 u32 new_rx_count, new_tx_count;
1150 int i, err = 0;
1151
1152 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1153 return -EINVAL;
1154
Shannon Nelson1fa18372013-11-20 10:03:08 +00001155 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1156 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1157 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1158 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1159 netdev_info(netdev,
1160 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1161 ring->tx_pending, ring->rx_pending,
1162 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1163 return -EINVAL;
1164 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001165
Shannon Nelson1fa18372013-11-20 10:03:08 +00001166 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1167 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001168
1169 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001170 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1171 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001172 return 0;
1173
1174 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1175 usleep_range(1000, 2000);
1176
1177 if (!netif_running(vsi->netdev)) {
1178 /* simple case - set for the next time the netdev is started */
1179 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001180 vsi->tx_rings[i]->count = new_tx_count;
1181 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001182 }
1183 goto done;
1184 }
1185
1186 /* We can't just free everything and then setup again,
1187 * because the ISRs in MSI-X mode get passed pointers
1188 * to the Tx and Rx ring structs.
1189 */
1190
1191 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001192 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001193 netdev_info(netdev,
1194 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001195 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1197 sizeof(struct i40e_ring), GFP_KERNEL);
1198 if (!tx_rings) {
1199 err = -ENOMEM;
1200 goto done;
1201 }
1202
1203 for (i = 0; i < vsi->num_queue_pairs; i++) {
1204 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001205 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001206 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001207 /* the desc and bi pointers will be reallocated in the
1208 * setup call
1209 */
1210 tx_rings[i].desc = NULL;
1211 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001212 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1213 if (err) {
1214 while (i) {
1215 i--;
1216 i40e_free_tx_resources(&tx_rings[i]);
1217 }
1218 kfree(tx_rings);
1219 tx_rings = NULL;
1220
1221 goto done;
1222 }
1223 }
1224 }
1225
1226 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001227 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001228 netdev_info(netdev,
1229 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001230 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001231 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1232 sizeof(struct i40e_ring), GFP_KERNEL);
1233 if (!rx_rings) {
1234 err = -ENOMEM;
1235 goto free_tx;
1236 }
1237
1238 for (i = 0; i < vsi->num_queue_pairs; i++) {
1239 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001240 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001241 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001242 /* the desc and bi pointers will be reallocated in the
1243 * setup call
1244 */
1245 rx_rings[i].desc = NULL;
1246 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001247 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1248 if (err) {
1249 while (i) {
1250 i--;
1251 i40e_free_rx_resources(&rx_rings[i]);
1252 }
1253 kfree(rx_rings);
1254 rx_rings = NULL;
1255
1256 goto free_tx;
1257 }
1258 }
1259 }
1260
1261 /* Bring interface down, copy in the new ring info,
1262 * then restore the interface
1263 */
1264 i40e_down(vsi);
1265
1266 if (tx_rings) {
1267 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001268 i40e_free_tx_resources(vsi->tx_rings[i]);
1269 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001270 }
1271 kfree(tx_rings);
1272 tx_rings = NULL;
1273 }
1274
1275 if (rx_rings) {
1276 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001277 i40e_free_rx_resources(vsi->rx_rings[i]);
1278 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001279 }
1280 kfree(rx_rings);
1281 rx_rings = NULL;
1282 }
1283
1284 i40e_up(vsi);
1285
1286free_tx:
1287 /* error cleanup if the Rx allocations failed after getting Tx */
1288 if (tx_rings) {
1289 for (i = 0; i < vsi->num_queue_pairs; i++)
1290 i40e_free_tx_resources(&tx_rings[i]);
1291 kfree(tx_rings);
1292 tx_rings = NULL;
1293 }
1294
1295done:
1296 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1297
1298 return err;
1299}
1300
1301static int i40e_get_sset_count(struct net_device *netdev, int sset)
1302{
1303 struct i40e_netdev_priv *np = netdev_priv(netdev);
1304 struct i40e_vsi *vsi = np->vsi;
1305 struct i40e_pf *pf = vsi->back;
1306
1307 switch (sset) {
1308 case ETH_SS_TEST:
1309 return I40E_TEST_LEN;
1310 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001311 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001312 int len = I40E_PF_STATS_LEN(netdev);
1313
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001314 if ((pf->lan_veb != I40E_NO_VEB) &&
1315 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001316 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001317 return len;
1318 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001320 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001321 case ETH_SS_PRIV_FLAGS:
1322 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001323 default:
1324 return -EOPNOTSUPP;
1325 }
1326}
1327
1328static void i40e_get_ethtool_stats(struct net_device *netdev,
1329 struct ethtool_stats *stats, u64 *data)
1330{
1331 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001332 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001333 struct i40e_vsi *vsi = np->vsi;
1334 struct i40e_pf *pf = vsi->back;
1335 int i = 0;
1336 char *p;
1337 int j;
1338 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001339 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001340
1341 i40e_update_stats(vsi);
1342
1343 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1344 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1345 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1346 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1347 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001348 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1349 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1350 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1351 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1352 }
Vasu Dev38e00432014-08-01 13:27:03 -07001353#ifdef I40E_FCOE
1354 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1355 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1356 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1357 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1358 }
1359#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001360 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001361 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001362 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001363
1364 if (!tx_ring)
1365 continue;
1366
1367 /* process Tx ring statistics */
1368 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001369 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001370 data[i] = tx_ring->stats.packets;
1371 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001372 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001373 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001374
1375 /* Rx ring is the 2nd half of the queue pair */
1376 rx_ring = &tx_ring[1];
1377 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001378 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001379 data[i] = rx_ring->stats.packets;
1380 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001381 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001382 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001383 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001384 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001385 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001386 return;
1387
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001388 if ((pf->lan_veb != I40E_NO_VEB) &&
1389 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001390 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001391
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001392 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1393 p = (char *)veb;
1394 p += i40e_gstrings_veb_stats[j].stat_offset;
1395 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1396 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001397 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001398 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001399 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1400 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1401 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1402 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1403 }
1404 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1405 data[i++] = pf->stats.priority_xon_tx[j];
1406 data[i++] = pf->stats.priority_xoff_tx[j];
1407 }
1408 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1409 data[i++] = pf->stats.priority_xon_rx[j];
1410 data[i++] = pf->stats.priority_xoff_rx[j];
1411 }
1412 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1413 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001414}
1415
1416static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1417 u8 *data)
1418{
1419 struct i40e_netdev_priv *np = netdev_priv(netdev);
1420 struct i40e_vsi *vsi = np->vsi;
1421 struct i40e_pf *pf = vsi->back;
1422 char *p = (char *)data;
1423 int i;
1424
1425 switch (stringset) {
1426 case ETH_SS_TEST:
1427 for (i = 0; i < I40E_TEST_LEN; i++) {
1428 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1429 data += ETH_GSTRING_LEN;
1430 }
1431 break;
1432 case ETH_SS_STATS:
1433 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1434 snprintf(p, ETH_GSTRING_LEN, "%s",
1435 i40e_gstrings_net_stats[i].stat_string);
1436 p += ETH_GSTRING_LEN;
1437 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001438 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1439 snprintf(p, ETH_GSTRING_LEN, "%s",
1440 i40e_gstrings_misc_stats[i].stat_string);
1441 p += ETH_GSTRING_LEN;
1442 }
Vasu Dev38e00432014-08-01 13:27:03 -07001443#ifdef I40E_FCOE
1444 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1445 snprintf(p, ETH_GSTRING_LEN, "%s",
1446 i40e_gstrings_fcoe_stats[i].stat_string);
1447 p += ETH_GSTRING_LEN;
1448 }
1449#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001450 for (i = 0; i < vsi->num_queue_pairs; i++) {
1451 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1452 p += ETH_GSTRING_LEN;
1453 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1454 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001455 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1456 p += ETH_GSTRING_LEN;
1457 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1458 p += ETH_GSTRING_LEN;
1459 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001460 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001461 return;
1462
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001463 if ((pf->lan_veb != I40E_NO_VEB) &&
1464 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001465 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1466 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1467 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001468 p += ETH_GSTRING_LEN;
1469 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001470 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1471 snprintf(p, ETH_GSTRING_LEN,
1472 "veb.tc_%u_tx_packets", i);
1473 p += ETH_GSTRING_LEN;
1474 snprintf(p, ETH_GSTRING_LEN,
1475 "veb.tc_%u_tx_bytes", i);
1476 p += ETH_GSTRING_LEN;
1477 snprintf(p, ETH_GSTRING_LEN,
1478 "veb.tc_%u_rx_packets", i);
1479 p += ETH_GSTRING_LEN;
1480 snprintf(p, ETH_GSTRING_LEN,
1481 "veb.tc_%u_rx_bytes", i);
1482 p += ETH_GSTRING_LEN;
1483 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001484 }
1485 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1486 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1487 i40e_gstrings_stats[i].stat_string);
1488 p += ETH_GSTRING_LEN;
1489 }
1490 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1491 snprintf(p, ETH_GSTRING_LEN,
1492 "port.tx_priority_%u_xon", i);
1493 p += ETH_GSTRING_LEN;
1494 snprintf(p, ETH_GSTRING_LEN,
1495 "port.tx_priority_%u_xoff", i);
1496 p += ETH_GSTRING_LEN;
1497 }
1498 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1499 snprintf(p, ETH_GSTRING_LEN,
1500 "port.rx_priority_%u_xon", i);
1501 p += ETH_GSTRING_LEN;
1502 snprintf(p, ETH_GSTRING_LEN,
1503 "port.rx_priority_%u_xoff", i);
1504 p += ETH_GSTRING_LEN;
1505 }
1506 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1507 snprintf(p, ETH_GSTRING_LEN,
1508 "port.rx_priority_%u_xon_2_xoff", i);
1509 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001510 }
1511 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1512 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001513 case ETH_SS_PRIV_FLAGS:
1514 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1515 memcpy(data, i40e_priv_flags_strings[i],
1516 ETH_GSTRING_LEN);
1517 data += ETH_GSTRING_LEN;
1518 }
1519 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001520 default:
1521 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522 }
1523}
1524
1525static int i40e_get_ts_info(struct net_device *dev,
1526 struct ethtool_ts_info *info)
1527{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001528 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1529
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001530 /* only report HW timestamping if PTP is enabled */
1531 if (!(pf->flags & I40E_FLAG_PTP))
1532 return ethtool_op_get_ts_info(dev, info);
1533
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001534 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1535 SOF_TIMESTAMPING_RX_SOFTWARE |
1536 SOF_TIMESTAMPING_SOFTWARE |
1537 SOF_TIMESTAMPING_TX_HARDWARE |
1538 SOF_TIMESTAMPING_RX_HARDWARE |
1539 SOF_TIMESTAMPING_RAW_HARDWARE;
1540
1541 if (pf->ptp_clock)
1542 info->phc_index = ptp_clock_index(pf->ptp_clock);
1543 else
1544 info->phc_index = -1;
1545
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001546 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001547
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001548 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1549 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1550 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001551
1552 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001553}
1554
Shannon Nelson7b086392013-11-20 10:02:59 +00001555static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556{
Shannon Nelson7b086392013-11-20 10:02:59 +00001557 struct i40e_netdev_priv *np = netdev_priv(netdev);
1558 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001559 i40e_status status;
1560 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001561
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001562 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001563 status = i40e_get_link_status(&pf->hw, &link_up);
1564 if (status) {
1565 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1566 *data = 1;
1567 return *data;
1568 }
1569
1570 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571 *data = 0;
1572 else
1573 *data = 1;
1574
1575 return *data;
1576}
1577
Shannon Nelson7b086392013-11-20 10:02:59 +00001578static int i40e_reg_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 Brandeburgc7d05ca2013-09-11 08:39:56 +00001582
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001583 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001584 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001585
Shannon Nelson7b086392013-11-20 10:02:59 +00001586 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001587}
1588
Shannon Nelson7b086392013-11-20 10:02:59 +00001589static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001590{
Shannon Nelson7b086392013-11-20 10:02:59 +00001591 struct i40e_netdev_priv *np = netdev_priv(netdev);
1592 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001594 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001595 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596
Shannon Nelson4443ec92014-11-13 08:23:12 +00001597 /* forcebly clear the NVM Update state machine */
1598 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1599
Shannon Nelson7b086392013-11-20 10:02:59 +00001600 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001601}
1602
Shannon Nelson7b086392013-11-20 10:02:59 +00001603static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001604{
Shannon Nelson7b086392013-11-20 10:02:59 +00001605 struct i40e_netdev_priv *np = netdev_priv(netdev);
1606 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001607 u16 swc_old = pf->sw_int_count;
1608
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001609 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001610 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1611 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001612 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1613 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1614 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1615 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001616 usleep_range(1000, 2000);
1617 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001618
1619 return *data;
1620}
1621
Shannon Nelson7b086392013-11-20 10:02:59 +00001622static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001623{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001624 struct i40e_netdev_priv *np = netdev_priv(netdev);
1625 struct i40e_pf *pf = np->vsi->back;
1626
1627 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001628 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001629
1630 return *data;
1631}
1632
Greg Rosee17bc412015-04-16 20:05:59 -04001633static inline bool i40e_active_vfs(struct i40e_pf *pf)
1634{
1635 struct i40e_vf *vfs = pf->vf;
1636 int i;
1637
1638 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001639 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001640 return true;
1641 return false;
1642}
1643
Greg Rose510efb22015-07-10 19:36:01 -04001644static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1645{
1646 struct i40e_vsi **vsi = pf->vsi;
1647 int i;
1648
1649 for (i = 0; i < pf->num_alloc_vsi; i++) {
1650 if (!vsi[i])
1651 continue;
1652 if (vsi[i]->type == I40E_VSI_VMDQ2)
1653 return true;
1654 }
1655
1656 return false;
1657}
1658
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001659static void i40e_diag_test(struct net_device *netdev,
1660 struct ethtool_test *eth_test, u64 *data)
1661{
1662 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001663 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001664 struct i40e_pf *pf = np->vsi->back;
1665
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001666 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1667 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001668 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001669
Shannon Nelsonf551b432013-11-26 10:49:12 +00001670 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001671
Greg Rose510efb22015-07-10 19:36:01 -04001672 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001673 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001674 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001675 data[I40E_ETH_TEST_REG] = 1;
1676 data[I40E_ETH_TEST_EEPROM] = 1;
1677 data[I40E_ETH_TEST_INTR] = 1;
1678 data[I40E_ETH_TEST_LOOPBACK] = 1;
1679 data[I40E_ETH_TEST_LINK] = 1;
1680 eth_test->flags |= ETH_TEST_FL_FAILED;
1681 clear_bit(__I40E_TESTING, &pf->state);
1682 goto skip_ol_tests;
1683 }
1684
Greg Rose5b86c5c2015-02-26 16:14:35 +00001685 /* If the device is online then take it offline */
1686 if (if_running)
1687 /* indicate we're in test mode */
1688 dev_close(netdev);
1689 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001690 /* This reset does not affect link - if it is
1691 * changed to a type of reset that does affect
1692 * link then the following link test would have
1693 * to be moved to before the reset
1694 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001695 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001696
Shannon Nelson7b086392013-11-20 10:02:59 +00001697 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001698 eth_test->flags |= ETH_TEST_FL_FAILED;
1699
Shannon Nelson7b086392013-11-20 10:02:59 +00001700 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001701 eth_test->flags |= ETH_TEST_FL_FAILED;
1702
Shannon Nelson7b086392013-11-20 10:02:59 +00001703 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001704 eth_test->flags |= ETH_TEST_FL_FAILED;
1705
Shannon Nelson7b086392013-11-20 10:02:59 +00001706 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001707 eth_test->flags |= ETH_TEST_FL_FAILED;
1708
Shannon Nelsonf551b432013-11-26 10:49:12 +00001709 /* run reg test last, a reset is required after it */
1710 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1711 eth_test->flags |= ETH_TEST_FL_FAILED;
1712
1713 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001714 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001715
1716 if (if_running)
1717 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001718 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001719 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001720 netif_info(pf, drv, netdev, "online testing starting\n");
1721
Shannon Nelson7b086392013-11-20 10:02:59 +00001722 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001723 eth_test->flags |= ETH_TEST_FL_FAILED;
1724
1725 /* Offline only tests, not run in online; pass by default */
1726 data[I40E_ETH_TEST_REG] = 0;
1727 data[I40E_ETH_TEST_EEPROM] = 0;
1728 data[I40E_ETH_TEST_INTR] = 0;
1729 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001730 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001731
Greg Rosee17bc412015-04-16 20:05:59 -04001732skip_ol_tests:
1733
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001734 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001735}
1736
1737static void i40e_get_wol(struct net_device *netdev,
1738 struct ethtool_wolinfo *wol)
1739{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001740 struct i40e_netdev_priv *np = netdev_priv(netdev);
1741 struct i40e_pf *pf = np->vsi->back;
1742 struct i40e_hw *hw = &pf->hw;
1743 u16 wol_nvm_bits;
1744
1745 /* NVM bit on means WoL disabled for the port */
1746 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001747 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001748 wol->supported = 0;
1749 wol->wolopts = 0;
1750 } else {
1751 wol->supported = WAKE_MAGIC;
1752 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1753 }
1754}
1755
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001756/**
1757 * i40e_set_wol - set the WakeOnLAN configuration
1758 * @netdev: the netdev in question
1759 * @wol: the ethtool WoL setting data
1760 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001761static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1762{
1763 struct i40e_netdev_priv *np = netdev_priv(netdev);
1764 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001765 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001766 struct i40e_hw *hw = &pf->hw;
1767 u16 wol_nvm_bits;
1768
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001769 /* WoL not supported if this isn't the controlling PF on the port */
1770 if (hw->partition_id != 1) {
1771 i40e_partition_setting_complaint(pf);
1772 return -EOPNOTSUPP;
1773 }
1774
1775 if (vsi != pf->vsi[pf->lan_vsi])
1776 return -EOPNOTSUPP;
1777
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001778 /* NVM bit on means WoL disabled for the port */
1779 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001780 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001781 return -EOPNOTSUPP;
1782
1783 /* only magic packet is supported */
1784 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1785 return -EOPNOTSUPP;
1786
1787 /* is this a new value? */
1788 if (pf->wol_en != !!wol->wolopts) {
1789 pf->wol_en = !!wol->wolopts;
1790 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1791 }
1792
1793 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001794}
1795
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001796static int i40e_set_phys_id(struct net_device *netdev,
1797 enum ethtool_phys_id_state state)
1798{
1799 struct i40e_netdev_priv *np = netdev_priv(netdev);
1800 struct i40e_pf *pf = np->vsi->back;
1801 struct i40e_hw *hw = &pf->hw;
1802 int blink_freq = 2;
1803
1804 switch (state) {
1805 case ETHTOOL_ID_ACTIVE:
1806 pf->led_status = i40e_led_get(hw);
1807 return blink_freq;
1808 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001809 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001810 break;
1811 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001812 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001813 break;
1814 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001815 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001816 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001817 default:
1818 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819 }
1820
1821 return 0;
1822}
1823
1824/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1825 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1826 * 125us (8000 interrupts per second) == ITR(62)
1827 */
1828
1829static int i40e_get_coalesce(struct net_device *netdev,
1830 struct ethtool_coalesce *ec)
1831{
1832 struct i40e_netdev_priv *np = netdev_priv(netdev);
1833 struct i40e_vsi *vsi = np->vsi;
1834
1835 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1836 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1837
1838 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001839 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001840
1841 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001842 ec->use_adaptive_tx_coalesce = 1;
1843
1844 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1845 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001846
1847 return 0;
1848}
1849
1850static int i40e_set_coalesce(struct net_device *netdev,
1851 struct ethtool_coalesce *ec)
1852{
1853 struct i40e_netdev_priv *np = netdev_priv(netdev);
1854 struct i40e_q_vector *q_vector;
1855 struct i40e_vsi *vsi = np->vsi;
1856 struct i40e_pf *pf = vsi->back;
1857 struct i40e_hw *hw = &pf->hw;
1858 u16 vector;
1859 int i;
1860
1861 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1862 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1863
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001864 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001865 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001866 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001867 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001868 } else if (ec->rx_coalesce_usecs == 0) {
1869 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001870 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001871 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 +00001872 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001873 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001874 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001875 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001876
Mitch Williams32f5f542014-04-04 04:43:10 +00001877 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001878 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001879 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001880 } else if (ec->tx_coalesce_usecs == 0) {
1881 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001882 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001883 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 +00001884 } else {
1885 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001886 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001887 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001888 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001889
1890 if (ec->use_adaptive_rx_coalesce)
1891 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1892 else
1893 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1894
1895 if (ec->use_adaptive_tx_coalesce)
1896 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1897 else
1898 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001899
Alexander Duyck493fb302013-09-28 07:01:44 +00001900 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1901 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001902 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1903 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1904 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1905 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1906 i40e_flush(hw);
1907 }
1908
1909 return 0;
1910}
1911
1912/**
1913 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1914 * @pf: pointer to the physical function struct
1915 * @cmd: ethtool rxnfc command
1916 *
1917 * Returns Success if the flow is supported, else Invalid Input.
1918 **/
1919static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1920{
1921 cmd->data = 0;
1922
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001923 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1924 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1925 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1926 return 0;
1927 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001928 /* Report default options for RSS on i40e */
1929 switch (cmd->flow_type) {
1930 case TCP_V4_FLOW:
1931 case UDP_V4_FLOW:
1932 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1933 /* fall through to add IP fields */
1934 case SCTP_V4_FLOW:
1935 case AH_ESP_V4_FLOW:
1936 case AH_V4_FLOW:
1937 case ESP_V4_FLOW:
1938 case IPV4_FLOW:
1939 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1940 break;
1941 case TCP_V6_FLOW:
1942 case UDP_V6_FLOW:
1943 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1944 /* fall through to add IP fields */
1945 case SCTP_V6_FLOW:
1946 case AH_ESP_V6_FLOW:
1947 case AH_V6_FLOW:
1948 case ESP_V6_FLOW:
1949 case IPV6_FLOW:
1950 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1951 break;
1952 default:
1953 return -EINVAL;
1954 }
1955
1956 return 0;
1957}
1958
1959/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001960 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1961 * @pf: Pointer to the physical function struct
1962 * @cmd: The command to get or set Rx flow classification rules
1963 * @rule_locs: Array of used rule locations
1964 *
1965 * This function populates both the total and actual rule count of
1966 * the ethtool flow classification command
1967 *
1968 * Returns 0 on success or -EMSGSIZE if entry not found
1969 **/
1970static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1971 struct ethtool_rxnfc *cmd,
1972 u32 *rule_locs)
1973{
1974 struct i40e_fdir_filter *rule;
1975 struct hlist_node *node2;
1976 int cnt = 0;
1977
1978 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001979 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001980
1981 hlist_for_each_entry_safe(rule, node2,
1982 &pf->fdir_filter_list, fdir_node) {
1983 if (cnt == cmd->rule_cnt)
1984 return -EMSGSIZE;
1985
1986 rule_locs[cnt] = rule->fd_id;
1987 cnt++;
1988 }
1989
1990 cmd->rule_cnt = cnt;
1991
1992 return 0;
1993}
1994
1995/**
1996 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1997 * @pf: Pointer to the physical function struct
1998 * @cmd: The command to get or set Rx flow classification rules
1999 *
2000 * This function looks up a filter based on the Rx flow classification
2001 * command and fills the flow spec info for it if found
2002 *
2003 * Returns 0 on success or -EINVAL if filter not found
2004 **/
2005static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2006 struct ethtool_rxnfc *cmd)
2007{
2008 struct ethtool_rx_flow_spec *fsp =
2009 (struct ethtool_rx_flow_spec *)&cmd->fs;
2010 struct i40e_fdir_filter *rule = NULL;
2011 struct hlist_node *node2;
2012
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002013 hlist_for_each_entry_safe(rule, node2,
2014 &pf->fdir_filter_list, fdir_node) {
2015 if (fsp->location <= rule->fd_id)
2016 break;
2017 }
2018
2019 if (!rule || fsp->location != rule->fd_id)
2020 return -EINVAL;
2021
2022 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002023 if (fsp->flow_type == IP_USER_FLOW) {
2024 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2025 fsp->h_u.usr_ip4_spec.proto = 0;
2026 fsp->m_u.usr_ip4_spec.proto = 0;
2027 }
2028
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002029 /* Reverse the src and dest notion, since the HW views them from
2030 * Tx perspective where as the user expects it from Rx filter view.
2031 */
2032 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2033 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2034 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2035 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002036
2037 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2038 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2039 else
2040 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002041
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002042 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2043 struct i40e_vsi *vsi;
2044
2045 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2046 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2047 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2048 fsp->m_ext.data[1] = htonl(0x1);
2049 }
2050 }
2051
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002052 return 0;
2053}
2054
2055/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002056 * i40e_get_rxnfc - command to get RX flow classification rules
2057 * @netdev: network interface device structure
2058 * @cmd: ethtool rxnfc command
2059 *
2060 * Returns Success if the command is supported.
2061 **/
2062static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2063 u32 *rule_locs)
2064{
2065 struct i40e_netdev_priv *np = netdev_priv(netdev);
2066 struct i40e_vsi *vsi = np->vsi;
2067 struct i40e_pf *pf = vsi->back;
2068 int ret = -EOPNOTSUPP;
2069
2070 switch (cmd->cmd) {
2071 case ETHTOOL_GRXRINGS:
2072 cmd->data = vsi->alloc_queue_pairs;
2073 ret = 0;
2074 break;
2075 case ETHTOOL_GRXFH:
2076 ret = i40e_get_rss_hash_opts(pf, cmd);
2077 break;
2078 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002079 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002080 /* report total rule count */
2081 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002082 ret = 0;
2083 break;
2084 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002085 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002086 break;
2087 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002088 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2089 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002090 default:
2091 break;
2092 }
2093
2094 return ret;
2095}
2096
2097/**
2098 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2099 * @pf: pointer to the physical function struct
2100 * @cmd: ethtool rxnfc command
2101 *
2102 * Returns Success if the flow input set is supported.
2103 **/
2104static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2105{
2106 struct i40e_hw *hw = &pf->hw;
2107 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2108 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2109
2110 /* RSS does not support anything other than hashing
2111 * to queues on src and dst IPs and ports
2112 */
2113 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2114 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2115 return -EINVAL;
2116
2117 /* We need at least the IP SRC and DEST fields for hashing */
2118 if (!(nfc->data & RXH_IP_SRC) ||
2119 !(nfc->data & RXH_IP_DST))
2120 return -EINVAL;
2121
2122 switch (nfc->flow_type) {
2123 case TCP_V4_FLOW:
2124 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2125 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002126 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002127 break;
2128 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002129 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002130 break;
2131 default:
2132 return -EINVAL;
2133 }
2134 break;
2135 case TCP_V6_FLOW:
2136 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2137 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002138 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002139 break;
2140 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002141 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142 break;
2143 default:
2144 return -EINVAL;
2145 }
2146 break;
2147 case UDP_V4_FLOW:
2148 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2149 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002150 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2151 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002152 break;
2153 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002154 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2155 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002156 break;
2157 default:
2158 return -EINVAL;
2159 }
2160 break;
2161 case UDP_V6_FLOW:
2162 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2163 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002164 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2165 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002166 break;
2167 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002168 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2169 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002170 break;
2171 default:
2172 return -EINVAL;
2173 }
2174 break;
2175 case AH_ESP_V4_FLOW:
2176 case AH_V4_FLOW:
2177 case ESP_V4_FLOW:
2178 case SCTP_V4_FLOW:
2179 if ((nfc->data & RXH_L4_B_0_1) ||
2180 (nfc->data & RXH_L4_B_2_3))
2181 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002182 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002183 break;
2184 case AH_ESP_V6_FLOW:
2185 case AH_V6_FLOW:
2186 case ESP_V6_FLOW:
2187 case SCTP_V6_FLOW:
2188 if ((nfc->data & RXH_L4_B_0_1) ||
2189 (nfc->data & RXH_L4_B_2_3))
2190 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002191 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002192 break;
2193 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002194 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2195 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002196 break;
2197 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002198 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2199 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200 break;
2201 default:
2202 return -EINVAL;
2203 }
2204
2205 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2206 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2207 i40e_flush(hw);
2208
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002209 /* Save setting for future output/update */
2210 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2211
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212 return 0;
2213}
2214
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002215/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002216 * i40e_match_fdir_input_set - Match a new filter against an existing one
2217 * @rule: The filter already added
2218 * @input: The new filter to comapre against
2219 *
2220 * Returns true if the two input set match
2221 **/
2222static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2223 struct i40e_fdir_filter *input)
2224{
2225 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2226 (rule->src_ip[0] != input->src_ip[0]) ||
2227 (rule->dst_port != input->dst_port) ||
2228 (rule->src_port != input->src_port))
2229 return false;
2230 return true;
2231}
2232
2233/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002234 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2235 * @vsi: Pointer to the targeted VSI
2236 * @input: The filter to update or NULL to indicate deletion
2237 * @sw_idx: Software index to the filter
2238 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002239 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002240 * This function updates (or deletes) a Flow Director entry from
2241 * the hlist of the corresponding PF
2242 *
2243 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002244 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002245static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2246 struct i40e_fdir_filter *input,
2247 u16 sw_idx,
2248 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002249{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002250 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002251 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002252 struct hlist_node *node2;
2253 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002254
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002255 parent = NULL;
2256 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002257
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002258 hlist_for_each_entry_safe(rule, node2,
2259 &pf->fdir_filter_list, fdir_node) {
2260 /* hash found, or no matching entry */
2261 if (rule->fd_id >= sw_idx)
2262 break;
2263 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002264 }
2265
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002266 /* if there is an old rule occupying our place remove it */
2267 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002268 if (input && !i40e_match_fdir_input_set(rule, input))
2269 err = i40e_add_del_fdir(vsi, rule, false);
2270 else if (!input)
2271 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002272 hlist_del(&rule->fdir_node);
2273 kfree(rule);
2274 pf->fdir_pf_active_filters--;
2275 }
2276
2277 /* If no input this was a delete, err should be 0 if a rule was
2278 * successfully found and removed from the list else -EINVAL
2279 */
2280 if (!input)
2281 return err;
2282
2283 /* initialize node and set software index */
2284 INIT_HLIST_NODE(&input->fdir_node);
2285
2286 /* add filter to the list */
2287 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002288 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002289 else
2290 hlist_add_head(&input->fdir_node,
2291 &pf->fdir_filter_list);
2292
2293 /* update counts */
2294 pf->fdir_pf_active_filters++;
2295
2296 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002297}
2298
2299/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002300 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2301 * @vsi: Pointer to the targeted VSI
2302 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002303 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002304 * The function removes a Flow Director filter entry from the
2305 * hlist of the corresponding PF
2306 *
2307 * Returns 0 on success
2308 */
2309static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2310 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002311{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002312 struct ethtool_rx_flow_spec *fsp =
2313 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002314 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002315 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002316
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002317 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2318 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2319 return -EBUSY;
2320
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002321 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2322 return -EBUSY;
2323
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002324 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002325
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002326 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002327 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002328}
2329
2330/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002331 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002332 * @vsi: pointer to the targeted VSI
2333 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002334 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002335 * Add Flow Director filters for a specific flow spec based on their
2336 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002337 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002338static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2339 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002340{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002341 struct ethtool_rx_flow_spec *fsp;
2342 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002343 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002344 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002345 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002346
2347 if (!vsi)
2348 return -EINVAL;
2349
2350 pf = vsi->back;
2351
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002352 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2353 return -EOPNOTSUPP;
2354
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002355 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002356 return -ENOSPC;
2357
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002358 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2359 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2360 return -EBUSY;
2361
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002362 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2363 return -EBUSY;
2364
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002365 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2366
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002367 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2368 pf->hw.func_caps.fd_filters_guaranteed)) {
2369 return -EINVAL;
2370 }
2371
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002372 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2373 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002374 return -EINVAL;
2375
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002376 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002377
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002378 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002379 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002380
2381 input->fd_id = fsp->location;
2382
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002383 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2384 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2385 else
2386 input->dest_ctl =
2387 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2388
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002389 input->q_index = fsp->ring_cookie;
2390 input->flex_off = 0;
2391 input->pctype = 0;
2392 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002393 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002394 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002395 input->flow_type = fsp->flow_type;
2396 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002397
2398 /* Reverse the src and dest notion, since the HW expects them to be from
2399 * Tx perspective where as the input from user is from Rx filter view.
2400 */
2401 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2402 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2403 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2404 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002405
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002406 if (ntohl(fsp->m_ext.data[1])) {
2407 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2408 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2409 goto free_input;
2410 }
2411 vf_id = ntohl(fsp->h_ext.data[1]);
2412 /* Find vsi id from vf id and override dest vsi */
2413 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2414 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2415 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2416 goto free_input;
2417 }
2418 }
2419
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002420 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002421free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002422 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002423 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002424 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002425 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002426
2427 return ret;
2428}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002429
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002430/**
2431 * i40e_set_rxnfc - command to set RX flow classification rules
2432 * @netdev: network interface device structure
2433 * @cmd: ethtool rxnfc command
2434 *
2435 * Returns Success if the command is supported.
2436 **/
2437static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2438{
2439 struct i40e_netdev_priv *np = netdev_priv(netdev);
2440 struct i40e_vsi *vsi = np->vsi;
2441 struct i40e_pf *pf = vsi->back;
2442 int ret = -EOPNOTSUPP;
2443
2444 switch (cmd->cmd) {
2445 case ETHTOOL_SRXFH:
2446 ret = i40e_set_rss_hash_opt(pf, cmd);
2447 break;
2448 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002449 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002450 break;
2451 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002452 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002453 break;
2454 default:
2455 break;
2456 }
2457
2458 return ret;
2459}
2460
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002461/**
2462 * i40e_max_channels - get Max number of combined channels supported
2463 * @vsi: vsi pointer
2464 **/
2465static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2466{
2467 /* TODO: This code assumes DCB and FD is disabled for now. */
2468 return vsi->alloc_queue_pairs;
2469}
2470
2471/**
2472 * i40e_get_channels - Get the current channels enabled and max supported etc.
2473 * @netdev: network interface device structure
2474 * @ch: ethtool channels structure
2475 *
2476 * We don't support separate tx and rx queues as channels. The other count
2477 * represents how many queues are being used for control. max_combined counts
2478 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2479 * q_vectors since we support a lot more queue pairs than q_vectors.
2480 **/
2481static void i40e_get_channels(struct net_device *dev,
2482 struct ethtool_channels *ch)
2483{
2484 struct i40e_netdev_priv *np = netdev_priv(dev);
2485 struct i40e_vsi *vsi = np->vsi;
2486 struct i40e_pf *pf = vsi->back;
2487
2488 /* report maximum channels */
2489 ch->max_combined = i40e_max_channels(vsi);
2490
2491 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002492 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002493 ch->max_other = ch->other_count;
2494
2495 /* Note: This code assumes DCB is disabled for now. */
2496 ch->combined_count = vsi->num_queue_pairs;
2497}
2498
2499/**
2500 * i40e_set_channels - Set the new channels count.
2501 * @netdev: network interface device structure
2502 * @ch: ethtool channels structure
2503 *
2504 * The new channels count may not be the same as requested by the user
2505 * since it gets rounded down to a power of 2 value.
2506 **/
2507static int i40e_set_channels(struct net_device *dev,
2508 struct ethtool_channels *ch)
2509{
2510 struct i40e_netdev_priv *np = netdev_priv(dev);
2511 unsigned int count = ch->combined_count;
2512 struct i40e_vsi *vsi = np->vsi;
2513 struct i40e_pf *pf = vsi->back;
2514 int new_count;
2515
2516 /* We do not support setting channels for any other VSI at present */
2517 if (vsi->type != I40E_VSI_MAIN)
2518 return -EINVAL;
2519
2520 /* verify they are not requesting separate vectors */
2521 if (!count || ch->rx_count || ch->tx_count)
2522 return -EINVAL;
2523
2524 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002525 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002526 return -EINVAL;
2527
2528 /* verify the number of channels does not exceed hardware limits */
2529 if (count > i40e_max_channels(vsi))
2530 return -EINVAL;
2531
2532 /* update feature limits from largest to smallest supported values */
2533 /* TODO: Flow director limit, DCB etc */
2534
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002535 /* use rss_reconfig to rebuild with new queue count and update traffic
2536 * class queue mapping
2537 */
2538 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002539 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002540 return 0;
2541 else
2542 return -EINVAL;
2543}
2544
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002545#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2546/**
2547 * i40e_get_rxfh_key_size - get the RSS hash key size
2548 * @netdev: network interface device structure
2549 *
2550 * Returns the table size.
2551 **/
2552static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2553{
2554 return I40E_HKEY_ARRAY_SIZE;
2555}
2556
2557/**
2558 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2559 * @netdev: network interface device structure
2560 *
2561 * Returns the table size.
2562 **/
2563static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2564{
2565 return I40E_HLUT_ARRAY_SIZE;
2566}
2567
2568static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2569 u8 *hfunc)
2570{
2571 struct i40e_netdev_priv *np = netdev_priv(netdev);
2572 struct i40e_vsi *vsi = np->vsi;
2573 struct i40e_pf *pf = vsi->back;
2574 struct i40e_hw *hw = &pf->hw;
2575 u32 reg_val;
2576 int i, j;
2577
2578 if (hfunc)
2579 *hfunc = ETH_RSS_HASH_TOP;
2580
2581 if (!indir)
2582 return 0;
2583
2584 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2585 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2586 indir[j++] = reg_val & 0xff;
2587 indir[j++] = (reg_val >> 8) & 0xff;
2588 indir[j++] = (reg_val >> 16) & 0xff;
2589 indir[j++] = (reg_val >> 24) & 0xff;
2590 }
2591
2592 if (key) {
2593 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2594 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2595 key[j++] = (u8)(reg_val & 0xff);
2596 key[j++] = (u8)((reg_val >> 8) & 0xff);
2597 key[j++] = (u8)((reg_val >> 16) & 0xff);
2598 key[j++] = (u8)((reg_val >> 24) & 0xff);
2599 }
2600 }
2601 return 0;
2602}
2603
2604/**
2605 * i40e_set_rxfh - set the rx flow hash indirection table
2606 * @netdev: network interface device structure
2607 * @indir: indirection table
2608 * @key: hash key
2609 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002610 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002611 * returns 0 after programming the table.
2612 **/
2613static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2614 const u8 *key, const u8 hfunc)
2615{
2616 struct i40e_netdev_priv *np = netdev_priv(netdev);
2617 struct i40e_vsi *vsi = np->vsi;
2618 struct i40e_pf *pf = vsi->back;
2619 struct i40e_hw *hw = &pf->hw;
2620 u32 reg_val;
2621 int i, j;
2622
2623 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2624 return -EOPNOTSUPP;
2625
2626 if (!indir)
2627 return 0;
2628
2629 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2630 reg_val = indir[j++];
2631 reg_val |= indir[j++] << 8;
2632 reg_val |= indir[j++] << 16;
2633 reg_val |= indir[j++] << 24;
2634 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2635 }
2636
2637 if (key) {
2638 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2639 reg_val = key[j++];
2640 reg_val |= key[j++] << 8;
2641 reg_val |= key[j++] << 16;
2642 reg_val |= key[j++] << 24;
2643 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2644 }
2645 }
2646 return 0;
2647}
2648
Greg Rose7e45ab42015-02-06 08:52:19 +00002649/**
2650 * i40e_get_priv_flags - report device private flags
2651 * @dev: network interface device structure
2652 *
2653 * The get string set count and the string set should be matched for each
2654 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2655 * array.
2656 *
2657 * Returns a u32 bitmap of flags.
2658 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002659static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002660{
2661 struct i40e_netdev_priv *np = netdev_priv(dev);
2662 struct i40e_vsi *vsi = np->vsi;
2663 struct i40e_pf *pf = vsi->back;
2664 u32 ret_flags = 0;
2665
2666 ret_flags |= pf->hw.func_caps.npar_enable ?
2667 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002668 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2669 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002670 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2671 I40E_PRIV_FLAGS_FD_ATR : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002672
2673 return ret_flags;
2674}
2675
Shannon Nelson9ac77262015-08-27 11:42:40 -04002676/**
2677 * i40e_set_priv_flags - set private flags
2678 * @dev: network interface device structure
2679 * @flags: bit flags to be set
2680 **/
2681static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2682{
2683 struct i40e_netdev_priv *np = netdev_priv(dev);
2684 struct i40e_vsi *vsi = np->vsi;
2685 struct i40e_pf *pf = vsi->back;
2686
2687 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2688 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2689 else
2690 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2691
Jesse Brandeburgef171782015-09-03 17:18:49 -04002692 /* allow the user to control the state of the Flow
2693 * Director ATR (Application Targeted Routing) feature
2694 * of the driver
2695 */
2696 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2697 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2698 } else {
2699 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2700 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2701 }
2702
Shannon Nelson9ac77262015-08-27 11:42:40 -04002703 return 0;
2704}
2705
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002706static const struct ethtool_ops i40e_ethtool_ops = {
2707 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002708 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002709 .get_drvinfo = i40e_get_drvinfo,
2710 .get_regs_len = i40e_get_regs_len,
2711 .get_regs = i40e_get_regs,
2712 .nway_reset = i40e_nway_reset,
2713 .get_link = ethtool_op_get_link,
2714 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002715 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002716 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002717 .get_eeprom_len = i40e_get_eeprom_len,
2718 .get_eeprom = i40e_get_eeprom,
2719 .get_ringparam = i40e_get_ringparam,
2720 .set_ringparam = i40e_set_ringparam,
2721 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002722 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002723 .get_msglevel = i40e_get_msglevel,
2724 .set_msglevel = i40e_set_msglevel,
2725 .get_rxnfc = i40e_get_rxnfc,
2726 .set_rxnfc = i40e_set_rxnfc,
2727 .self_test = i40e_diag_test,
2728 .get_strings = i40e_get_strings,
2729 .set_phys_id = i40e_set_phys_id,
2730 .get_sset_count = i40e_get_sset_count,
2731 .get_ethtool_stats = i40e_get_ethtool_stats,
2732 .get_coalesce = i40e_get_coalesce,
2733 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002734 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2735 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2736 .get_rxfh = i40e_get_rxfh,
2737 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002738 .get_channels = i40e_get_channels,
2739 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002740 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002741 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002742 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002743};
2744
2745void i40e_set_ethtool_ops(struct net_device *netdev)
2746{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002747 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002748}