blob: f1ad10161792d89548ffe7182139aa2e06907307 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Shannon Nelson66fc3602016-01-13 16:51:42 -08004 * Copyright(c) 2013 - 2016 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040091 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Anjali Singhai Jaindd353102016-01-15 14:33:12 -080092 I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080093 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
94 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000095};
96
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000097/* These PF_STATs might look like duplicates of some NETDEV_STATs,
98 * but they are separate. This device supports Virtualization, and
99 * as such might have several netdevs supporting VMDq and FCoE going
100 * through a single port. The NETDEV_STATs are for individual netdevs
101 * seen at the top of the stack, and the PF_STATs are for the physical
102 * function at the bottom of the stack hosting those netdevs.
103 *
104 * The PF_STATs are appended to the netdev stats only when ethtool -S
105 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
106 */
107static struct i40e_stats i40e_gstrings_stats[] = {
108 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
109 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000110 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
111 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
112 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
113 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
114 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
115 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
117 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000118 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400119 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000120 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
121 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
122 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000123 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000124 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000125 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
126 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
127 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
128 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
129 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
130 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
131 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
132 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
133 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
134 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
135 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
136 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
137 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
138 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
139 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
140 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
141 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
142 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
143 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
144 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
145 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
146 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
147 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
148 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800149 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000150 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400153 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400156 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000157
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000158 /* LPI stats */
159 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
160 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
161 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
162 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000163};
164
Vasu Dev38e00432014-08-01 13:27:03 -0700165#ifdef I40E_FCOE
166static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
167 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
168 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
169 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
170 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
171 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
172 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
173 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
174 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
175};
176
177#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000178#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000179 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
180 * 2 /* Tx and Rx together */ \
181 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000182#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
183#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000184#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700185#ifdef I40E_FCOE
186#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
188 I40E_FCOE_STATS_LEN + \
189 I40E_MISC_STATS_LEN + \
190 I40E_QUEUE_STATS_LEN((n)))
191#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000192#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000193 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000194 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700195#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000196#define I40E_PFC_STATS_LEN ( \
197 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
201 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
202 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400203#define I40E_VEB_TC_STATS_LEN ( \
204 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
207 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
208 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000209#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400210#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000211#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
212 I40E_PFC_STATS_LEN + \
213 I40E_VSI_STATS_LEN((n)))
214
215enum i40e_ethtool_test_id {
216 I40E_ETH_TEST_REG = 0,
217 I40E_ETH_TEST_EEPROM,
218 I40E_ETH_TEST_INTR,
219 I40E_ETH_TEST_LOOPBACK,
220 I40E_ETH_TEST_LINK,
221};
222
223static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
224 "Register test (offline)",
225 "Eeprom test (offline)",
226 "Interrupt test (offline)",
227 "Loopback test (offline)",
228 "Link test (on/offline)"
229};
230
231#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
232
Greg Rose7e45ab42015-02-06 08:52:19 +0000233static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
234 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400235 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400236 "flow-director-atr",
Shannon Nelson1cdfd882015-09-28 14:12:34 -0400237 "veb-stats",
Jesse Brandeburg827de392015-11-06 15:26:07 -0800238 "packet-split",
Anjali Singhai Jain72b74862016-01-08 17:50:21 -0800239 "hw-atr-eviction",
Greg Rose7e45ab42015-02-06 08:52:19 +0000240};
241
Shannon Nelson9ac77262015-08-27 11:42:40 -0400242#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000243
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000244/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000245 * i40e_partition_setting_complaint - generic complaint for MFP restriction
246 * @pf: the PF struct
247 **/
248static void i40e_partition_setting_complaint(struct i40e_pf *pf)
249{
250 dev_info(&pf->pdev->dev,
251 "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");
252}
253
254/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000255 * i40e_get_settings_link_up - Get the Link settings for when link is up
256 * @hw: hw structure
257 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000260 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000261static void i40e_get_settings_link_up(struct i40e_hw *hw,
262 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400263 struct net_device *netdev,
264 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000265{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000266 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000267 u32 link_speed = hw_link_info->link_speed;
268
Catherine Sullivane8278452015-02-06 08:52:08 +0000269 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000270 switch (hw_link_info->phy_type) {
271 case I40E_PHY_TYPE_40GBASE_CR4:
272 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000273 ecmd->supported = SUPPORTED_Autoneg |
274 SUPPORTED_40000baseCR4_Full;
275 ecmd->advertising = ADVERTISED_Autoneg |
276 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000277 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000278 case I40E_PHY_TYPE_XLAUI:
279 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000280 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000281 ecmd->supported = SUPPORTED_40000baseCR4_Full;
282 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000283 case I40E_PHY_TYPE_40GBASE_SR4:
284 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000285 break;
286 case I40E_PHY_TYPE_40GBASE_LR4:
287 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000288 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000289 case I40E_PHY_TYPE_10GBASE_SR:
290 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000291 case I40E_PHY_TYPE_1000BASE_SX:
292 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400293 ecmd->supported = SUPPORTED_10000baseT_Full;
294 if (hw_link_info->module_type[2] &
295 I40E_MODULE_TYPE_1000BASE_SX ||
296 hw_link_info->module_type[2] &
297 I40E_MODULE_TYPE_1000BASE_LX) {
298 ecmd->supported |= SUPPORTED_1000baseT_Full;
299 if (hw_link_info->requested_speeds &
300 I40E_LINK_SPEED_1GB)
301 ecmd->advertising |= ADVERTISED_1000baseT_Full;
302 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000303 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
304 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000305 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000306 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000307 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000308 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000309 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400310 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000311 ecmd->advertising = ADVERTISED_Autoneg;
312 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
313 ecmd->advertising |= ADVERTISED_10000baseT_Full;
314 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
315 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400316 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400317 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
318 ecmd->supported = SUPPORTED_Autoneg |
319 SUPPORTED_1000baseT_Full;
320 ecmd->advertising = ADVERTISED_Autoneg |
321 ADVERTISED_1000baseT_Full;
322 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400323 case I40E_PHY_TYPE_100BASE_TX:
324 ecmd->supported = SUPPORTED_Autoneg |
325 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000326 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
327 ecmd->advertising |= ADVERTISED_100baseT_Full;
328 break;
329 case I40E_PHY_TYPE_10GBASE_CR1_CU:
330 case I40E_PHY_TYPE_10GBASE_CR1:
331 ecmd->supported = SUPPORTED_Autoneg |
332 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000333 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000334 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000335 break;
336 case I40E_PHY_TYPE_XAUI:
337 case I40E_PHY_TYPE_XFI:
338 case I40E_PHY_TYPE_SFI:
339 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000340 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000341 ecmd->supported = SUPPORTED_10000baseT_Full;
342 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000343 case I40E_PHY_TYPE_SGMII:
344 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400345 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000346 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
347 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800348 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400349 ecmd->supported |= SUPPORTED_100baseT_Full;
350 if (hw_link_info->requested_speeds &
351 I40E_LINK_SPEED_100MB)
352 ecmd->advertising |= ADVERTISED_100baseT_Full;
353 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000354 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400355 /* Backplane is set based on supported phy types in get_settings
356 * so don't set anything here but don't warn either
357 */
358 case I40E_PHY_TYPE_40GBASE_KR4:
359 case I40E_PHY_TYPE_20GBASE_KR2:
360 case I40E_PHY_TYPE_10GBASE_KR:
361 case I40E_PHY_TYPE_10GBASE_KX4:
362 case I40E_PHY_TYPE_1000BASE_KX:
363 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000364 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000365 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000366 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
367 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000368 }
369
Catherine Sullivane8278452015-02-06 08:52:08 +0000370 /* Set speed and duplex */
371 switch (link_speed) {
372 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400373 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000374 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700375 case I40E_LINK_SPEED_20GB:
376 ethtool_cmd_speed_set(ecmd, SPEED_20000);
377 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000378 case I40E_LINK_SPEED_10GB:
379 ethtool_cmd_speed_set(ecmd, SPEED_10000);
380 break;
381 case I40E_LINK_SPEED_1GB:
382 ethtool_cmd_speed_set(ecmd, SPEED_1000);
383 break;
384 case I40E_LINK_SPEED_100MB:
385 ethtool_cmd_speed_set(ecmd, SPEED_100);
386 break;
387 default:
388 break;
389 }
390 ecmd->duplex = DUPLEX_FULL;
391}
392
393/**
394 * i40e_get_settings_link_down - Get the Link settings for when link is down
395 * @hw: hw structure
396 * @ecmd: ethtool command to fill in
397 *
398 * Reports link settings that can be determined when link is down
399 **/
400static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400401 struct ethtool_cmd *ecmd,
402 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000403{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400404 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000405
406 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400407 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000408 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400409 ecmd->supported = 0x0;
410 ecmd->advertising = 0x0;
411 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
412 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400413 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400414 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400415 ADVERTISED_1000baseT_Full;
416 if (pf->hw.mac.type == I40E_MAC_X722) {
417 ecmd->supported |= SUPPORTED_100baseT_Full;
418 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivanf8db54cc2015-12-22 14:25:14 -0800419 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
420 ecmd->supported |= SUPPORTED_100baseT_Full;
421 ecmd->advertising |= ADVERTISED_100baseT_Full;
422 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400423 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000424 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400425 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
426 phy_types & I40E_CAP_PHY_TYPE_XFI ||
427 phy_types & I40E_CAP_PHY_TYPE_SFI ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
430 ecmd->supported |= SUPPORTED_10000baseT_Full;
431 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
432 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
433 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
434 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
435 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
436 ecmd->supported |= SUPPORTED_Autoneg |
437 SUPPORTED_10000baseT_Full;
438 ecmd->advertising |= ADVERTISED_Autoneg |
439 ADVERTISED_10000baseT_Full;
440 }
441 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
442 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
443 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
444 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
445 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
446 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
447 ecmd->supported |= SUPPORTED_Autoneg |
448 SUPPORTED_40000baseCR4_Full;
449 ecmd->advertising |= ADVERTISED_Autoneg |
450 ADVERTISED_40000baseCR4_Full;
451 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400452 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
453 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400454 ecmd->supported |= SUPPORTED_Autoneg |
455 SUPPORTED_100baseT_Full;
456 ecmd->advertising |= ADVERTISED_Autoneg |
457 ADVERTISED_100baseT_Full;
458 }
459 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
460 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
461 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
462 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
463 ecmd->supported |= SUPPORTED_Autoneg |
464 SUPPORTED_1000baseT_Full;
465 ecmd->advertising |= ADVERTISED_Autoneg |
466 ADVERTISED_1000baseT_Full;
467 }
468 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
469 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
470 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
471 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000472
473 /* With no link speed and duplex are unknown */
474 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
475 ecmd->duplex = DUPLEX_UNKNOWN;
476}
477
478/**
479 * i40e_get_settings - Get Link Speed and Duplex settings
480 * @netdev: network interface device structure
481 * @ecmd: ethtool command
482 *
483 * Reports speed/duplex settings based on media_type
484 **/
485static int i40e_get_settings(struct net_device *netdev,
486 struct ethtool_cmd *ecmd)
487{
488 struct i40e_netdev_priv *np = netdev_priv(netdev);
489 struct i40e_pf *pf = np->vsi->back;
490 struct i40e_hw *hw = &pf->hw;
491 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
492 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
493
494 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400495 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000496 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400497 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000498
499 /* Now set the settings that don't rely on link being up/down */
500
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400501 /* For backplane, supported and advertised are only reliant on the
502 * phy types the NVM specifies are supported.
503 */
504 if (hw->device_id == I40E_DEV_ID_KX_B ||
505 hw->device_id == I40E_DEV_ID_KX_C ||
506 hw->device_id == I40E_DEV_ID_20G_KR2 ||
507 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
508 ecmd->supported = SUPPORTED_Autoneg;
509 ecmd->advertising = ADVERTISED_Autoneg;
510 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
511 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
512 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
513 }
514 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
515 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
516 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
517 }
518 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
519 ecmd->supported |= SUPPORTED_10000baseKR_Full;
520 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
521 }
522 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
523 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
524 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
525 }
526 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
527 ecmd->supported |= SUPPORTED_1000baseKX_Full;
528 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
529 }
530 }
531
Catherine Sullivane8278452015-02-06 08:52:08 +0000532 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000533 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
534 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000535
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000536 switch (hw->phy.media_type) {
537 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000538 ecmd->supported |= SUPPORTED_Autoneg |
539 SUPPORTED_Backplane;
540 ecmd->advertising |= ADVERTISED_Autoneg |
541 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000542 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000543 break;
544 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000545 ecmd->supported |= SUPPORTED_TP;
546 ecmd->advertising |= ADVERTISED_TP;
547 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000548 break;
549 case I40E_MEDIA_TYPE_DA:
550 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000551 ecmd->supported |= SUPPORTED_FIBRE;
552 ecmd->advertising |= ADVERTISED_FIBRE;
553 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000554 break;
555 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000556 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000557 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000558 break;
559 case I40E_MEDIA_TYPE_UNKNOWN:
560 default:
561 ecmd->port = PORT_OTHER;
562 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000563 }
564
Catherine Sullivane8278452015-02-06 08:52:08 +0000565 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000566 ecmd->transceiver = XCVR_EXTERNAL;
567
Catherine Sullivane8278452015-02-06 08:52:08 +0000568 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000569 ecmd->supported |= SUPPORTED_Pause;
570
Catherine Sullivane8278452015-02-06 08:52:08 +0000571 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000572 case I40E_FC_FULL:
573 ecmd->advertising |= ADVERTISED_Pause;
574 break;
575 case I40E_FC_TX_PAUSE:
576 ecmd->advertising |= ADVERTISED_Asym_Pause;
577 break;
578 case I40E_FC_RX_PAUSE:
579 ecmd->advertising |= (ADVERTISED_Pause |
580 ADVERTISED_Asym_Pause);
581 break;
582 default:
583 ecmd->advertising &= ~(ADVERTISED_Pause |
584 ADVERTISED_Asym_Pause);
585 break;
586 }
587
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000588 return 0;
589}
590
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000591/**
592 * i40e_set_settings - Set Speed and Duplex
593 * @netdev: network interface device structure
594 * @ecmd: ethtool command
595 *
596 * Set speed/duplex per media_types advertised/forced
597 **/
598static int i40e_set_settings(struct net_device *netdev,
599 struct ethtool_cmd *ecmd)
600{
601 struct i40e_netdev_priv *np = netdev_priv(netdev);
602 struct i40e_aq_get_phy_abilities_resp abilities;
603 struct i40e_aq_set_phy_config config;
604 struct i40e_pf *pf = np->vsi->back;
605 struct i40e_vsi *vsi = np->vsi;
606 struct i40e_hw *hw = &pf->hw;
607 struct ethtool_cmd safe_ecmd;
608 i40e_status status = 0;
609 bool change = false;
610 int err = 0;
611 u8 autoneg;
612 u32 advertise;
613
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000614 /* Changing port settings is not supported if this isn't the
615 * port's controlling PF
616 */
617 if (hw->partition_id != 1) {
618 i40e_partition_setting_complaint(pf);
619 return -EOPNOTSUPP;
620 }
621
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000622 if (vsi != pf->vsi[pf->lan_vsi])
623 return -EOPNOTSUPP;
624
625 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
626 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000627 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
628 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000629 return -EOPNOTSUPP;
630
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400631 if (hw->device_id == I40E_DEV_ID_KX_B ||
632 hw->device_id == I40E_DEV_ID_KX_C ||
633 hw->device_id == I40E_DEV_ID_20G_KR2 ||
634 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
635 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
636 return -EOPNOTSUPP;
637 }
638
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000639 /* get our own copy of the bits to check against */
640 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
641 i40e_get_settings(netdev, &safe_ecmd);
642
643 /* save autoneg and speed out of ecmd */
644 autoneg = ecmd->autoneg;
645 advertise = ecmd->advertising;
646
647 /* set autoneg and speed back to what they currently are */
648 ecmd->autoneg = safe_ecmd.autoneg;
649 ecmd->advertising = safe_ecmd.advertising;
650
651 ecmd->cmd = safe_ecmd.cmd;
652 /* If ecmd and safe_ecmd are not the same now, then they are
653 * trying to set something that we do not support
654 */
655 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
656 return -EOPNOTSUPP;
657
658 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
659 usleep_range(1000, 2000);
660
661 /* Get the current phy config */
662 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
663 NULL);
664 if (status)
665 return -EAGAIN;
666
Catherine Sullivan124ed152014-07-12 07:28:12 +0000667 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000668 * set below
669 */
670 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000671 config.abilities = abilities.abilities;
672
673 /* Check autoneg */
674 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000675 /* If autoneg was not already enabled */
676 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400677 /* If autoneg is not supported, return error */
678 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
679 netdev_info(netdev, "Autoneg not supported on this phy\n");
680 return -EINVAL;
681 }
682 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000683 config.abilities = abilities.abilities |
684 I40E_AQ_PHY_ENABLE_AN;
685 change = true;
686 }
687 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000688 /* If autoneg is currently enabled */
689 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400690 /* If autoneg is supported 10GBASE_T is the only PHY
691 * that can disable it, so otherwise return error
692 */
693 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
694 hw->phy.link_info.phy_type !=
695 I40E_PHY_TYPE_10GBASE_T) {
696 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
697 return -EINVAL;
698 }
699 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000700 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000701 ~I40E_AQ_PHY_ENABLE_AN;
702 change = true;
703 }
704 }
705
706 if (advertise & ~safe_ecmd.supported)
707 return -EINVAL;
708
709 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000710 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000711 if (advertise & ADVERTISED_1000baseT_Full ||
712 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000713 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000714 if (advertise & ADVERTISED_10000baseT_Full ||
715 advertise & ADVERTISED_10000baseKX4_Full ||
716 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000717 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700718 if (advertise & ADVERTISED_20000baseKR2_Full)
719 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000720 if (advertise & ADVERTISED_40000baseKR4_Full ||
721 advertise & ADVERTISED_40000baseCR4_Full ||
722 advertise & ADVERTISED_40000baseSR4_Full ||
723 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000724 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000725
Catherine Sullivan0002e112015-08-26 15:14:16 -0400726 /* If speed didn't get set, set it to what it currently is.
727 * This is needed because if advertise is 0 (as it is when autoneg
728 * is disabled) then speed won't get set.
729 */
730 if (!config.link_speed)
731 config.link_speed = abilities.link_speed;
732
Catherine Sullivan124ed152014-07-12 07:28:12 +0000733 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000734 /* copy over the rest of the abilities */
735 config.phy_type = abilities.phy_type;
736 config.eee_capability = abilities.eee_capability;
737 config.eeer = abilities.eeer_val;
738 config.low_power_ctrl = abilities.d3_lpan;
739
Catherine Sullivane8278452015-02-06 08:52:08 +0000740 /* save the requested speeds */
741 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000742 /* set link and auto negotiation so changes take effect */
743 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
744 /* If link is up put link down */
745 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
746 /* Tell the OS link is going down, the link will go
747 * back up when fw says it is ready asynchronously
748 */
Matt Jaredc156f852015-08-27 11:42:39 -0400749 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000750 netif_carrier_off(netdev);
751 netif_tx_stop_all_queues(netdev);
752 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000753
754 /* make the aq call */
755 status = i40e_aq_set_phy_config(hw, &config, NULL);
756 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400757 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
758 i40e_stat_str(hw, status),
759 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000760 return -EAGAIN;
761 }
762
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400763 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000764 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400765 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
766 i40e_stat_str(hw, status),
767 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000768
769 } else {
770 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
771 }
772
773 return err;
774}
775
Jesse Brandeburga6599722014-06-04 08:45:25 +0000776static int i40e_nway_reset(struct net_device *netdev)
777{
778 /* restart autonegotiation */
779 struct i40e_netdev_priv *np = netdev_priv(netdev);
780 struct i40e_pf *pf = np->vsi->back;
781 struct i40e_hw *hw = &pf->hw;
782 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
783 i40e_status ret = 0;
784
785 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
786 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400787 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
788 i40e_stat_str(hw, ret),
789 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000790 return -EIO;
791 }
792
793 return 0;
794}
795
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000796/**
797 * i40e_get_pauseparam - Get Flow Control status
798 * Return tx/rx-pause status
799 **/
800static void i40e_get_pauseparam(struct net_device *netdev,
801 struct ethtool_pauseparam *pause)
802{
803 struct i40e_netdev_priv *np = netdev_priv(netdev);
804 struct i40e_pf *pf = np->vsi->back;
805 struct i40e_hw *hw = &pf->hw;
806 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000807 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000808
809 pause->autoneg =
810 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
811 AUTONEG_ENABLE : AUTONEG_DISABLE);
812
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000813 /* PFC enabled so report LFC as off */
814 if (dcbx_cfg->pfc.pfcenable) {
815 pause->rx_pause = 0;
816 pause->tx_pause = 0;
817 return;
818 }
819
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000820 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000821 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000822 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000823 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000824 } else if (hw->fc.current_mode == I40E_FC_FULL) {
825 pause->rx_pause = 1;
826 pause->tx_pause = 1;
827 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000828}
829
Catherine Sullivan2becc352014-06-04 08:45:27 +0000830/**
831 * i40e_set_pauseparam - Set Flow Control parameter
832 * @netdev: network interface device structure
833 * @pause: return tx/rx flow control status
834 **/
835static int i40e_set_pauseparam(struct net_device *netdev,
836 struct ethtool_pauseparam *pause)
837{
838 struct i40e_netdev_priv *np = netdev_priv(netdev);
839 struct i40e_pf *pf = np->vsi->back;
840 struct i40e_vsi *vsi = np->vsi;
841 struct i40e_hw *hw = &pf->hw;
842 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000843 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000844 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
845 i40e_status status;
846 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000847 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000848
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000849 /* Changing the port's flow control is not supported if this isn't the
850 * port's controlling PF
851 */
852 if (hw->partition_id != 1) {
853 i40e_partition_setting_complaint(pf);
854 return -EOPNOTSUPP;
855 }
856
Catherine Sullivan2becc352014-06-04 08:45:27 +0000857 if (vsi != pf->vsi[pf->lan_vsi])
858 return -EOPNOTSUPP;
859
860 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
861 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
862 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
863 return -EOPNOTSUPP;
864 }
865
866 /* If we have link and don't have autoneg */
867 if (!test_bit(__I40E_DOWN, &pf->state) &&
868 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
869 /* Send message that it might not necessarily work*/
870 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
871 }
872
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000873 if (dcbx_cfg->pfc.pfcenable) {
874 netdev_info(netdev,
875 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000876 return -EOPNOTSUPP;
877 }
878
879 if (pause->rx_pause && pause->tx_pause)
880 hw->fc.requested_mode = I40E_FC_FULL;
881 else if (pause->rx_pause && !pause->tx_pause)
882 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
883 else if (!pause->rx_pause && pause->tx_pause)
884 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
885 else if (!pause->rx_pause && !pause->tx_pause)
886 hw->fc.requested_mode = I40E_FC_NONE;
887 else
888 return -EINVAL;
889
Catherine Sullivan94128512014-07-12 07:28:16 +0000890 /* Tell the OS link is going down, the link will go back up when fw
891 * says it is ready asynchronously
892 */
Matt Jaredc156f852015-08-27 11:42:39 -0400893 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000894 netif_carrier_off(netdev);
895 netif_tx_stop_all_queues(netdev);
896
Catherine Sullivan2becc352014-06-04 08:45:27 +0000897 /* Set the fc mode and only restart an if link is up*/
898 status = i40e_set_fc(hw, &aq_failures, link_up);
899
900 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400901 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
902 i40e_stat_str(hw, status),
903 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000904 err = -EAGAIN;
905 }
906 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400907 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
908 i40e_stat_str(hw, status),
909 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000910 err = -EAGAIN;
911 }
912 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400913 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
914 i40e_stat_str(hw, status),
915 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000916 err = -EAGAIN;
917 }
918
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000919 if (!test_bit(__I40E_DOWN, &pf->state)) {
920 /* Give it a little more time to try to come back */
921 msleep(75);
922 if (!test_bit(__I40E_DOWN, &pf->state))
923 return i40e_nway_reset(netdev);
924 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000925
926 return err;
927}
928
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000929static u32 i40e_get_msglevel(struct net_device *netdev)
930{
931 struct i40e_netdev_priv *np = netdev_priv(netdev);
932 struct i40e_pf *pf = np->vsi->back;
933
934 return pf->msg_enable;
935}
936
937static void i40e_set_msglevel(struct net_device *netdev, u32 data)
938{
939 struct i40e_netdev_priv *np = netdev_priv(netdev);
940 struct i40e_pf *pf = np->vsi->back;
941
942 if (I40E_DEBUG_USER & data)
943 pf->hw.debug_mask = data;
944 pf->msg_enable = data;
945}
946
947static int i40e_get_regs_len(struct net_device *netdev)
948{
949 int reg_count = 0;
950 int i;
951
952 for (i = 0; i40e_reg_list[i].offset != 0; i++)
953 reg_count += i40e_reg_list[i].elements;
954
955 return reg_count * sizeof(u32);
956}
957
958static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
959 void *p)
960{
961 struct i40e_netdev_priv *np = netdev_priv(netdev);
962 struct i40e_pf *pf = np->vsi->back;
963 struct i40e_hw *hw = &pf->hw;
964 u32 *reg_buf = p;
965 int i, j, ri;
966 u32 reg;
967
968 /* Tell ethtool which driver-version-specific regs output we have.
969 *
970 * At some point, if we have ethtool doing special formatting of
971 * this data, it will rely on this version number to know how to
972 * interpret things. Hence, this needs to be updated if/when the
973 * diags register table is changed.
974 */
975 regs->version = 1;
976
977 /* loop through the diags reg table for what to print */
978 ri = 0;
979 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
980 for (j = 0; j < i40e_reg_list[i].elements; j++) {
981 reg = i40e_reg_list[i].offset
982 + (j * i40e_reg_list[i].stride);
983 reg_buf[ri++] = rd32(hw, reg);
984 }
985 }
986
987}
988
989static int i40e_get_eeprom(struct net_device *netdev,
990 struct ethtool_eeprom *eeprom, u8 *bytes)
991{
992 struct i40e_netdev_priv *np = netdev_priv(netdev);
993 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000994 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000995 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000996 u8 *eeprom_buff;
997 u16 i, sectors;
998 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000999 u32 magic;
1000
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001001#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001002 if (eeprom->len == 0)
1003 return -EINVAL;
1004
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001005 /* check for NVMUpdate access method */
1006 magic = hw->vendor_id | (hw->device_id << 16);
1007 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001008 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1009 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001010
1011 /* make sure it is the right magic for NVMUpdate */
1012 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001013 errno = -EINVAL;
1014 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1015 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1016 errno = -EBUSY;
1017 else
1018 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001019
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001020 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001021 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001022 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1023 ret_val, hw->aq.asq_last_status, errno,
1024 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1025 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001026
1027 return errno;
1028 }
1029
1030 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001031 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1032
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001033 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001034 if (!eeprom_buff)
1035 return -ENOMEM;
1036
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001037 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1038 if (ret_val) {
1039 dev_info(&pf->pdev->dev,
1040 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1041 ret_val, hw->aq.asq_last_status);
1042 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001043 }
1044
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001045 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1046 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1047 len = I40E_NVM_SECTOR_SIZE;
1048 last = false;
1049 for (i = 0; i < sectors; i++) {
1050 if (i == (sectors - 1)) {
1051 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1052 last = true;
1053 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001054 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1055 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001056 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001057 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001058 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001059 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001060 "read NVM failed, invalid offset 0x%x\n",
1061 offset);
1062 break;
1063 } else if (ret_val &&
1064 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1065 dev_info(&pf->pdev->dev,
1066 "read NVM failed, access, offset 0x%x\n",
1067 offset);
1068 break;
1069 } else if (ret_val) {
1070 dev_info(&pf->pdev->dev,
1071 "read NVM failed offset %d err=%d status=0x%x\n",
1072 offset, ret_val, hw->aq.asq_last_status);
1073 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001074 }
1075 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001076
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001077 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001078 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001079free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001080 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001081 return ret_val;
1082}
1083
1084static int i40e_get_eeprom_len(struct net_device *netdev)
1085{
1086 struct i40e_netdev_priv *np = netdev_priv(netdev);
1087 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001088 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001089
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001090 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1091 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1092 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1093 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001094 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001095 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001096}
1097
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001098static int i40e_set_eeprom(struct net_device *netdev,
1099 struct ethtool_eeprom *eeprom, u8 *bytes)
1100{
1101 struct i40e_netdev_priv *np = netdev_priv(netdev);
1102 struct i40e_hw *hw = &np->vsi->back->hw;
1103 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001104 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001105 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001106 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001107 u32 magic;
1108
1109 /* normal ethtool set_eeprom is not supported */
1110 magic = hw->vendor_id | (hw->device_id << 16);
1111 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001112 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001113 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001114 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1115 errno = -EINVAL;
1116 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1117 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1118 errno = -EBUSY;
1119 else
1120 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001121
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001122 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001123 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001124 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1125 ret_val, hw->aq.asq_last_status, errno,
1126 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1127 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001128
1129 return errno;
1130}
1131
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001132static void i40e_get_drvinfo(struct net_device *netdev,
1133 struct ethtool_drvinfo *drvinfo)
1134{
1135 struct i40e_netdev_priv *np = netdev_priv(netdev);
1136 struct i40e_vsi *vsi = np->vsi;
1137 struct i40e_pf *pf = vsi->back;
1138
1139 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1140 strlcpy(drvinfo->version, i40e_driver_version_str,
1141 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001142 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001143 sizeof(drvinfo->fw_version));
1144 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1145 sizeof(drvinfo->bus_info));
1146}
1147
1148static void i40e_get_ringparam(struct net_device *netdev,
1149 struct ethtool_ringparam *ring)
1150{
1151 struct i40e_netdev_priv *np = netdev_priv(netdev);
1152 struct i40e_pf *pf = np->vsi->back;
1153 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1154
1155 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1156 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1157 ring->rx_mini_max_pending = 0;
1158 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001159 ring->rx_pending = vsi->rx_rings[0]->count;
1160 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001161 ring->rx_mini_pending = 0;
1162 ring->rx_jumbo_pending = 0;
1163}
1164
1165static int i40e_set_ringparam(struct net_device *netdev,
1166 struct ethtool_ringparam *ring)
1167{
1168 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1169 struct i40e_netdev_priv *np = netdev_priv(netdev);
1170 struct i40e_vsi *vsi = np->vsi;
1171 struct i40e_pf *pf = vsi->back;
1172 u32 new_rx_count, new_tx_count;
1173 int i, err = 0;
1174
1175 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1176 return -EINVAL;
1177
Shannon Nelson1fa18372013-11-20 10:03:08 +00001178 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1179 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1180 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1181 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1182 netdev_info(netdev,
1183 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1184 ring->tx_pending, ring->rx_pending,
1185 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1186 return -EINVAL;
1187 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001188
Shannon Nelson1fa18372013-11-20 10:03:08 +00001189 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1190 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001191
1192 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001193 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1194 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001195 return 0;
1196
1197 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1198 usleep_range(1000, 2000);
1199
1200 if (!netif_running(vsi->netdev)) {
1201 /* simple case - set for the next time the netdev is started */
1202 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001203 vsi->tx_rings[i]->count = new_tx_count;
1204 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001205 }
1206 goto done;
1207 }
1208
1209 /* We can't just free everything and then setup again,
1210 * because the ISRs in MSI-X mode get passed pointers
1211 * to the Tx and Rx ring structs.
1212 */
1213
1214 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001215 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001216 netdev_info(netdev,
1217 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001218 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001219 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1220 sizeof(struct i40e_ring), GFP_KERNEL);
1221 if (!tx_rings) {
1222 err = -ENOMEM;
1223 goto done;
1224 }
1225
1226 for (i = 0; i < vsi->num_queue_pairs; i++) {
1227 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001228 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001229 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001230 /* the desc and bi pointers will be reallocated in the
1231 * setup call
1232 */
1233 tx_rings[i].desc = NULL;
1234 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001235 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1236 if (err) {
1237 while (i) {
1238 i--;
1239 i40e_free_tx_resources(&tx_rings[i]);
1240 }
1241 kfree(tx_rings);
1242 tx_rings = NULL;
1243
1244 goto done;
1245 }
1246 }
1247 }
1248
1249 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001250 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001251 netdev_info(netdev,
1252 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001253 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001254 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1255 sizeof(struct i40e_ring), GFP_KERNEL);
1256 if (!rx_rings) {
1257 err = -ENOMEM;
1258 goto free_tx;
1259 }
1260
1261 for (i = 0; i < vsi->num_queue_pairs; i++) {
1262 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001263 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001264 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001265 /* the desc and bi pointers will be reallocated in the
1266 * setup call
1267 */
1268 rx_rings[i].desc = NULL;
1269 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001270 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1271 if (err) {
1272 while (i) {
1273 i--;
1274 i40e_free_rx_resources(&rx_rings[i]);
1275 }
1276 kfree(rx_rings);
1277 rx_rings = NULL;
1278
1279 goto free_tx;
1280 }
1281 }
1282 }
1283
1284 /* Bring interface down, copy in the new ring info,
1285 * then restore the interface
1286 */
1287 i40e_down(vsi);
1288
1289 if (tx_rings) {
1290 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001291 i40e_free_tx_resources(vsi->tx_rings[i]);
1292 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001293 }
1294 kfree(tx_rings);
1295 tx_rings = NULL;
1296 }
1297
1298 if (rx_rings) {
1299 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001300 i40e_free_rx_resources(vsi->rx_rings[i]);
1301 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001302 }
1303 kfree(rx_rings);
1304 rx_rings = NULL;
1305 }
1306
1307 i40e_up(vsi);
1308
1309free_tx:
1310 /* error cleanup if the Rx allocations failed after getting Tx */
1311 if (tx_rings) {
1312 for (i = 0; i < vsi->num_queue_pairs; i++)
1313 i40e_free_tx_resources(&tx_rings[i]);
1314 kfree(tx_rings);
1315 tx_rings = NULL;
1316 }
1317
1318done:
1319 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1320
1321 return err;
1322}
1323
1324static int i40e_get_sset_count(struct net_device *netdev, int sset)
1325{
1326 struct i40e_netdev_priv *np = netdev_priv(netdev);
1327 struct i40e_vsi *vsi = np->vsi;
1328 struct i40e_pf *pf = vsi->back;
1329
1330 switch (sset) {
1331 case ETH_SS_TEST:
1332 return I40E_TEST_LEN;
1333 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001334 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001335 int len = I40E_PF_STATS_LEN(netdev);
1336
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001337 if ((pf->lan_veb != I40E_NO_VEB) &&
1338 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001339 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001340 return len;
1341 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001342 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001343 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001344 case ETH_SS_PRIV_FLAGS:
1345 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001346 default:
1347 return -EOPNOTSUPP;
1348 }
1349}
1350
1351static void i40e_get_ethtool_stats(struct net_device *netdev,
1352 struct ethtool_stats *stats, u64 *data)
1353{
1354 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001355 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001356 struct i40e_vsi *vsi = np->vsi;
1357 struct i40e_pf *pf = vsi->back;
1358 int i = 0;
1359 char *p;
1360 int j;
1361 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001362 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001363
1364 i40e_update_stats(vsi);
1365
1366 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1367 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1368 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1369 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1370 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001371 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1372 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1373 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1374 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1375 }
Vasu Dev38e00432014-08-01 13:27:03 -07001376#ifdef I40E_FCOE
1377 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1378 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1379 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1380 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1381 }
1382#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001383 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001384 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001385 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001386
1387 if (!tx_ring)
1388 continue;
1389
1390 /* process Tx ring statistics */
1391 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001392 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001393 data[i] = tx_ring->stats.packets;
1394 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001395 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001396 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001397
1398 /* Rx ring is the 2nd half of the queue pair */
1399 rx_ring = &tx_ring[1];
1400 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001401 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001402 data[i] = rx_ring->stats.packets;
1403 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001404 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001405 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001407 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001408 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001409 return;
1410
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001411 if ((pf->lan_veb != I40E_NO_VEB) &&
1412 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001413 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001414
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001415 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1416 p = (char *)veb;
1417 p += i40e_gstrings_veb_stats[j].stat_offset;
1418 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1419 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001421 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1422 data[i++] = veb->tc_stats.tc_tx_packets[j];
1423 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1424 data[i++] = veb->tc_stats.tc_rx_packets[j];
1425 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1426 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001427 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001428 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1429 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1430 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1431 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1432 }
1433 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1434 data[i++] = pf->stats.priority_xon_tx[j];
1435 data[i++] = pf->stats.priority_xoff_tx[j];
1436 }
1437 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1438 data[i++] = pf->stats.priority_xon_rx[j];
1439 data[i++] = pf->stats.priority_xoff_rx[j];
1440 }
1441 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1442 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001443}
1444
1445static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1446 u8 *data)
1447{
1448 struct i40e_netdev_priv *np = netdev_priv(netdev);
1449 struct i40e_vsi *vsi = np->vsi;
1450 struct i40e_pf *pf = vsi->back;
1451 char *p = (char *)data;
1452 int i;
1453
1454 switch (stringset) {
1455 case ETH_SS_TEST:
1456 for (i = 0; i < I40E_TEST_LEN; i++) {
1457 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1458 data += ETH_GSTRING_LEN;
1459 }
1460 break;
1461 case ETH_SS_STATS:
1462 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1463 snprintf(p, ETH_GSTRING_LEN, "%s",
1464 i40e_gstrings_net_stats[i].stat_string);
1465 p += ETH_GSTRING_LEN;
1466 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001467 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1468 snprintf(p, ETH_GSTRING_LEN, "%s",
1469 i40e_gstrings_misc_stats[i].stat_string);
1470 p += ETH_GSTRING_LEN;
1471 }
Vasu Dev38e00432014-08-01 13:27:03 -07001472#ifdef I40E_FCOE
1473 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1474 snprintf(p, ETH_GSTRING_LEN, "%s",
1475 i40e_gstrings_fcoe_stats[i].stat_string);
1476 p += ETH_GSTRING_LEN;
1477 }
1478#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001479 for (i = 0; i < vsi->num_queue_pairs; i++) {
1480 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1481 p += ETH_GSTRING_LEN;
1482 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1483 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001484 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1485 p += ETH_GSTRING_LEN;
1486 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1487 p += ETH_GSTRING_LEN;
1488 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001489 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001490 return;
1491
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001492 if ((pf->lan_veb != I40E_NO_VEB) &&
1493 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001494 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1495 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1496 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497 p += ETH_GSTRING_LEN;
1498 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001499 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1500 snprintf(p, ETH_GSTRING_LEN,
1501 "veb.tc_%u_tx_packets", i);
1502 p += ETH_GSTRING_LEN;
1503 snprintf(p, ETH_GSTRING_LEN,
1504 "veb.tc_%u_tx_bytes", i);
1505 p += ETH_GSTRING_LEN;
1506 snprintf(p, ETH_GSTRING_LEN,
1507 "veb.tc_%u_rx_packets", i);
1508 p += ETH_GSTRING_LEN;
1509 snprintf(p, ETH_GSTRING_LEN,
1510 "veb.tc_%u_rx_bytes", i);
1511 p += ETH_GSTRING_LEN;
1512 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001513 }
1514 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1515 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1516 i40e_gstrings_stats[i].stat_string);
1517 p += ETH_GSTRING_LEN;
1518 }
1519 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1520 snprintf(p, ETH_GSTRING_LEN,
1521 "port.tx_priority_%u_xon", i);
1522 p += ETH_GSTRING_LEN;
1523 snprintf(p, ETH_GSTRING_LEN,
1524 "port.tx_priority_%u_xoff", i);
1525 p += ETH_GSTRING_LEN;
1526 }
1527 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1528 snprintf(p, ETH_GSTRING_LEN,
1529 "port.rx_priority_%u_xon", i);
1530 p += ETH_GSTRING_LEN;
1531 snprintf(p, ETH_GSTRING_LEN,
1532 "port.rx_priority_%u_xoff", i);
1533 p += ETH_GSTRING_LEN;
1534 }
1535 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1536 snprintf(p, ETH_GSTRING_LEN,
1537 "port.rx_priority_%u_xon_2_xoff", i);
1538 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001539 }
1540 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1541 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001542 case ETH_SS_PRIV_FLAGS:
1543 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1544 memcpy(data, i40e_priv_flags_strings[i],
1545 ETH_GSTRING_LEN);
1546 data += ETH_GSTRING_LEN;
1547 }
1548 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001549 default:
1550 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001551 }
1552}
1553
1554static int i40e_get_ts_info(struct net_device *dev,
1555 struct ethtool_ts_info *info)
1556{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001557 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1558
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001559 /* only report HW timestamping if PTP is enabled */
1560 if (!(pf->flags & I40E_FLAG_PTP))
1561 return ethtool_op_get_ts_info(dev, info);
1562
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001563 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1564 SOF_TIMESTAMPING_RX_SOFTWARE |
1565 SOF_TIMESTAMPING_SOFTWARE |
1566 SOF_TIMESTAMPING_TX_HARDWARE |
1567 SOF_TIMESTAMPING_RX_HARDWARE |
1568 SOF_TIMESTAMPING_RAW_HARDWARE;
1569
1570 if (pf->ptp_clock)
1571 info->phc_index = ptp_clock_index(pf->ptp_clock);
1572 else
1573 info->phc_index = -1;
1574
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001575 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001576
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001577 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1578 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1579 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001580
1581 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001582}
1583
Shannon Nelson7b086392013-11-20 10:02:59 +00001584static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001585{
Shannon Nelson7b086392013-11-20 10:02:59 +00001586 struct i40e_netdev_priv *np = netdev_priv(netdev);
1587 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001588 i40e_status status;
1589 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001590
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001591 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001592 status = i40e_get_link_status(&pf->hw, &link_up);
1593 if (status) {
1594 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1595 *data = 1;
1596 return *data;
1597 }
1598
1599 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 *data = 0;
1601 else
1602 *data = 1;
1603
1604 return *data;
1605}
1606
Shannon Nelson7b086392013-11-20 10:02:59 +00001607static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608{
Shannon Nelson7b086392013-11-20 10:02:59 +00001609 struct i40e_netdev_priv *np = netdev_priv(netdev);
1610 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001611
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001612 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001613 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614
Shannon Nelson7b086392013-11-20 10:02:59 +00001615 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001616}
1617
Shannon Nelson7b086392013-11-20 10:02:59 +00001618static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619{
Shannon Nelson7b086392013-11-20 10:02:59 +00001620 struct i40e_netdev_priv *np = netdev_priv(netdev);
1621 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001622
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001623 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001624 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001625
Shannon Nelson4443ec92014-11-13 08:23:12 +00001626 /* forcebly clear the NVM Update state machine */
1627 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1628
Shannon Nelson7b086392013-11-20 10:02:59 +00001629 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001630}
1631
Shannon Nelson7b086392013-11-20 10:02:59 +00001632static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633{
Shannon Nelson7b086392013-11-20 10:02:59 +00001634 struct i40e_netdev_priv *np = netdev_priv(netdev);
1635 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001636 u16 swc_old = pf->sw_int_count;
1637
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001638 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001639 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1640 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001641 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1642 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1643 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1644 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001645 usleep_range(1000, 2000);
1646 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001647
1648 return *data;
1649}
1650
Shannon Nelson7b086392013-11-20 10:02:59 +00001651static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001653 struct i40e_netdev_priv *np = netdev_priv(netdev);
1654 struct i40e_pf *pf = np->vsi->back;
1655
1656 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001657 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658
1659 return *data;
1660}
1661
Greg Rosee17bc412015-04-16 20:05:59 -04001662static inline bool i40e_active_vfs(struct i40e_pf *pf)
1663{
1664 struct i40e_vf *vfs = pf->vf;
1665 int i;
1666
1667 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001668 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001669 return true;
1670 return false;
1671}
1672
Greg Rose510efb22015-07-10 19:36:01 -04001673static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1674{
1675 struct i40e_vsi **vsi = pf->vsi;
1676 int i;
1677
1678 for (i = 0; i < pf->num_alloc_vsi; i++) {
1679 if (!vsi[i])
1680 continue;
1681 if (vsi[i]->type == I40E_VSI_VMDQ2)
1682 return true;
1683 }
1684
1685 return false;
1686}
1687
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001688static void i40e_diag_test(struct net_device *netdev,
1689 struct ethtool_test *eth_test, u64 *data)
1690{
1691 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001692 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001693 struct i40e_pf *pf = np->vsi->back;
1694
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001695 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1696 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001697 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001698
Shannon Nelsonf551b432013-11-26 10:49:12 +00001699 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001700
Greg Rose510efb22015-07-10 19:36:01 -04001701 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001702 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001703 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001704 data[I40E_ETH_TEST_REG] = 1;
1705 data[I40E_ETH_TEST_EEPROM] = 1;
1706 data[I40E_ETH_TEST_INTR] = 1;
1707 data[I40E_ETH_TEST_LOOPBACK] = 1;
1708 data[I40E_ETH_TEST_LINK] = 1;
1709 eth_test->flags |= ETH_TEST_FL_FAILED;
1710 clear_bit(__I40E_TESTING, &pf->state);
1711 goto skip_ol_tests;
1712 }
1713
Greg Rose5b86c5c2015-02-26 16:14:35 +00001714 /* If the device is online then take it offline */
1715 if (if_running)
1716 /* indicate we're in test mode */
1717 dev_close(netdev);
1718 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001719 /* This reset does not affect link - if it is
1720 * changed to a type of reset that does affect
1721 * link then the following link test would have
1722 * to be moved to before the reset
1723 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001724 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001725
Shannon Nelson7b086392013-11-20 10:02:59 +00001726 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001727 eth_test->flags |= ETH_TEST_FL_FAILED;
1728
Shannon Nelson7b086392013-11-20 10:02:59 +00001729 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001730 eth_test->flags |= ETH_TEST_FL_FAILED;
1731
Shannon Nelson7b086392013-11-20 10:02:59 +00001732 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733 eth_test->flags |= ETH_TEST_FL_FAILED;
1734
Shannon Nelson7b086392013-11-20 10:02:59 +00001735 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001736 eth_test->flags |= ETH_TEST_FL_FAILED;
1737
Shannon Nelsonf551b432013-11-26 10:49:12 +00001738 /* run reg test last, a reset is required after it */
1739 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1740 eth_test->flags |= ETH_TEST_FL_FAILED;
1741
1742 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001743 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001744
1745 if (if_running)
1746 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001747 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001748 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001749 netif_info(pf, drv, netdev, "online testing starting\n");
1750
Shannon Nelson7b086392013-11-20 10:02:59 +00001751 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001752 eth_test->flags |= ETH_TEST_FL_FAILED;
1753
1754 /* Offline only tests, not run in online; pass by default */
1755 data[I40E_ETH_TEST_REG] = 0;
1756 data[I40E_ETH_TEST_EEPROM] = 0;
1757 data[I40E_ETH_TEST_INTR] = 0;
1758 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001759 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001760
Greg Rosee17bc412015-04-16 20:05:59 -04001761skip_ol_tests:
1762
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001763 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001764}
1765
1766static void i40e_get_wol(struct net_device *netdev,
1767 struct ethtool_wolinfo *wol)
1768{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001769 struct i40e_netdev_priv *np = netdev_priv(netdev);
1770 struct i40e_pf *pf = np->vsi->back;
1771 struct i40e_hw *hw = &pf->hw;
1772 u16 wol_nvm_bits;
1773
1774 /* NVM bit on means WoL disabled for the port */
1775 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001776 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001777 wol->supported = 0;
1778 wol->wolopts = 0;
1779 } else {
1780 wol->supported = WAKE_MAGIC;
1781 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1782 }
1783}
1784
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001785/**
1786 * i40e_set_wol - set the WakeOnLAN configuration
1787 * @netdev: the netdev in question
1788 * @wol: the ethtool WoL setting data
1789 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001790static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1791{
1792 struct i40e_netdev_priv *np = netdev_priv(netdev);
1793 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001794 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001795 struct i40e_hw *hw = &pf->hw;
1796 u16 wol_nvm_bits;
1797
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001798 /* WoL not supported if this isn't the controlling PF on the port */
1799 if (hw->partition_id != 1) {
1800 i40e_partition_setting_complaint(pf);
1801 return -EOPNOTSUPP;
1802 }
1803
1804 if (vsi != pf->vsi[pf->lan_vsi])
1805 return -EOPNOTSUPP;
1806
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001807 /* NVM bit on means WoL disabled for the port */
1808 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001809 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001810 return -EOPNOTSUPP;
1811
1812 /* only magic packet is supported */
1813 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1814 return -EOPNOTSUPP;
1815
1816 /* is this a new value? */
1817 if (pf->wol_en != !!wol->wolopts) {
1818 pf->wol_en = !!wol->wolopts;
1819 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1820 }
1821
1822 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001823}
1824
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001825static int i40e_set_phys_id(struct net_device *netdev,
1826 enum ethtool_phys_id_state state)
1827{
1828 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001829 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001830 struct i40e_pf *pf = np->vsi->back;
1831 struct i40e_hw *hw = &pf->hw;
1832 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001833 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001834
1835 switch (state) {
1836 case ETHTOOL_ID_ACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001837 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1838 pf->led_status = i40e_led_get(hw);
1839 } else {
1840 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_PORT, NULL);
1841 ret = i40e_led_get_phy(hw, &temp_status,
1842 &pf->phy_led_val);
1843 pf->led_status = temp_status;
1844 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001845 return blink_freq;
1846 case ETHTOOL_ID_ON:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001847 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1848 i40e_led_set(hw, 0xf, false);
1849 else
1850 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001851 break;
1852 case ETHTOOL_ID_OFF:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001853 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1854 i40e_led_set(hw, 0x0, false);
1855 else
1856 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001857 break;
1858 case ETHTOOL_ID_INACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001859 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1860 i40e_led_set(hw, false, pf->led_status);
1861 } else {
1862 ret = i40e_led_set_phy(hw, false, pf->led_status,
1863 (pf->phy_led_val |
1864 I40E_PHY_LED_MODE_ORIG));
1865 i40e_aq_set_phy_debug(hw, 0, NULL);
1866 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001867 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001868 default:
1869 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001870 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001871 if (ret)
1872 return -ENOENT;
1873 else
1874 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001875}
1876
1877/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1878 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1879 * 125us (8000 interrupts per second) == ITR(62)
1880 */
1881
1882static int i40e_get_coalesce(struct net_device *netdev,
1883 struct ethtool_coalesce *ec)
1884{
1885 struct i40e_netdev_priv *np = netdev_priv(netdev);
1886 struct i40e_vsi *vsi = np->vsi;
1887
1888 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1889 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1890
1891 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001892 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001893
1894 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001895 ec->use_adaptive_tx_coalesce = 1;
1896
1897 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1898 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001899 /* we use the _usecs_high to store/set the interrupt rate limit
1900 * that the hardware supports, that almost but not quite
1901 * fits the original intent of the ethtool variable,
1902 * the rx_coalesce_usecs_high limits total interrupts
1903 * per second from both tx/rx sources.
1904 */
1905 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1906 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001907
1908 return 0;
1909}
1910
1911static int i40e_set_coalesce(struct net_device *netdev,
1912 struct ethtool_coalesce *ec)
1913{
1914 struct i40e_netdev_priv *np = netdev_priv(netdev);
1915 struct i40e_q_vector *q_vector;
1916 struct i40e_vsi *vsi = np->vsi;
1917 struct i40e_pf *pf = vsi->back;
1918 struct i40e_hw *hw = &pf->hw;
1919 u16 vector;
1920 int i;
1921
1922 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1923 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1924
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001925 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1926 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1927 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1928 return -EINVAL;
1929 }
1930
1931 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1932 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1933 return -EINVAL;
1934 }
1935
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001936 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001937 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001938 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001940 } else if (ec->rx_coalesce_usecs == 0) {
1941 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001942 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001943 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 +00001944 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001945 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001946 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001947 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001949 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1950
Mitch Williams32f5f542014-04-04 04:43:10 +00001951 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001952 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001954 } else if (ec->tx_coalesce_usecs == 0) {
1955 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001956 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001957 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 +00001958 } else {
1959 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001960 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001961 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001962 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001963
1964 if (ec->use_adaptive_rx_coalesce)
1965 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1966 else
1967 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1968
1969 if (ec->use_adaptive_tx_coalesce)
1970 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1971 else
1972 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001973
Alexander Duyck493fb302013-09-28 07:01:44 +00001974 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001975 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1976
Alexander Duyck493fb302013-09-28 07:01:44 +00001977 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001978 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1979 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1980 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1981 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001982 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001983 i40e_flush(hw);
1984 }
1985
1986 return 0;
1987}
1988
1989/**
1990 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1991 * @pf: pointer to the physical function struct
1992 * @cmd: ethtool rxnfc command
1993 *
1994 * Returns Success if the flow is supported, else Invalid Input.
1995 **/
1996static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1997{
1998 cmd->data = 0;
1999
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002000 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
2001 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
2002 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
2003 return 0;
2004 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002005 /* Report default options for RSS on i40e */
2006 switch (cmd->flow_type) {
2007 case TCP_V4_FLOW:
2008 case UDP_V4_FLOW:
2009 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2010 /* fall through to add IP fields */
2011 case SCTP_V4_FLOW:
2012 case AH_ESP_V4_FLOW:
2013 case AH_V4_FLOW:
2014 case ESP_V4_FLOW:
2015 case IPV4_FLOW:
2016 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2017 break;
2018 case TCP_V6_FLOW:
2019 case UDP_V6_FLOW:
2020 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2021 /* fall through to add IP fields */
2022 case SCTP_V6_FLOW:
2023 case AH_ESP_V6_FLOW:
2024 case AH_V6_FLOW:
2025 case ESP_V6_FLOW:
2026 case IPV6_FLOW:
2027 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2028 break;
2029 default:
2030 return -EINVAL;
2031 }
2032
2033 return 0;
2034}
2035
2036/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002037 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2038 * @pf: Pointer to the physical function struct
2039 * @cmd: The command to get or set Rx flow classification rules
2040 * @rule_locs: Array of used rule locations
2041 *
2042 * This function populates both the total and actual rule count of
2043 * the ethtool flow classification command
2044 *
2045 * Returns 0 on success or -EMSGSIZE if entry not found
2046 **/
2047static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2048 struct ethtool_rxnfc *cmd,
2049 u32 *rule_locs)
2050{
2051 struct i40e_fdir_filter *rule;
2052 struct hlist_node *node2;
2053 int cnt = 0;
2054
2055 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002056 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002057
2058 hlist_for_each_entry_safe(rule, node2,
2059 &pf->fdir_filter_list, fdir_node) {
2060 if (cnt == cmd->rule_cnt)
2061 return -EMSGSIZE;
2062
2063 rule_locs[cnt] = rule->fd_id;
2064 cnt++;
2065 }
2066
2067 cmd->rule_cnt = cnt;
2068
2069 return 0;
2070}
2071
2072/**
2073 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2074 * @pf: Pointer to the physical function struct
2075 * @cmd: The command to get or set Rx flow classification rules
2076 *
2077 * This function looks up a filter based on the Rx flow classification
2078 * command and fills the flow spec info for it if found
2079 *
2080 * Returns 0 on success or -EINVAL if filter not found
2081 **/
2082static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2083 struct ethtool_rxnfc *cmd)
2084{
2085 struct ethtool_rx_flow_spec *fsp =
2086 (struct ethtool_rx_flow_spec *)&cmd->fs;
2087 struct i40e_fdir_filter *rule = NULL;
2088 struct hlist_node *node2;
2089
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002090 hlist_for_each_entry_safe(rule, node2,
2091 &pf->fdir_filter_list, fdir_node) {
2092 if (fsp->location <= rule->fd_id)
2093 break;
2094 }
2095
2096 if (!rule || fsp->location != rule->fd_id)
2097 return -EINVAL;
2098
2099 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002100 if (fsp->flow_type == IP_USER_FLOW) {
2101 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2102 fsp->h_u.usr_ip4_spec.proto = 0;
2103 fsp->m_u.usr_ip4_spec.proto = 0;
2104 }
2105
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002106 /* Reverse the src and dest notion, since the HW views them from
2107 * Tx perspective where as the user expects it from Rx filter view.
2108 */
2109 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2110 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2111 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2112 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002113
2114 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2115 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2116 else
2117 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002118
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002119 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2120 struct i40e_vsi *vsi;
2121
2122 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2123 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2124 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2125 fsp->m_ext.data[1] = htonl(0x1);
2126 }
2127 }
2128
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002129 return 0;
2130}
2131
2132/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002133 * i40e_get_rxnfc - command to get RX flow classification rules
2134 * @netdev: network interface device structure
2135 * @cmd: ethtool rxnfc command
2136 *
2137 * Returns Success if the command is supported.
2138 **/
2139static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2140 u32 *rule_locs)
2141{
2142 struct i40e_netdev_priv *np = netdev_priv(netdev);
2143 struct i40e_vsi *vsi = np->vsi;
2144 struct i40e_pf *pf = vsi->back;
2145 int ret = -EOPNOTSUPP;
2146
2147 switch (cmd->cmd) {
2148 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002149 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002150 ret = 0;
2151 break;
2152 case ETHTOOL_GRXFH:
2153 ret = i40e_get_rss_hash_opts(pf, cmd);
2154 break;
2155 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002156 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002157 /* report total rule count */
2158 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002159 ret = 0;
2160 break;
2161 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002162 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002163 break;
2164 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002165 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2166 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002167 default:
2168 break;
2169 }
2170
2171 return ret;
2172}
2173
2174/**
2175 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2176 * @pf: pointer to the physical function struct
2177 * @cmd: ethtool rxnfc command
2178 *
2179 * Returns Success if the flow input set is supported.
2180 **/
2181static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2182{
2183 struct i40e_hw *hw = &pf->hw;
2184 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2185 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2186
2187 /* RSS does not support anything other than hashing
2188 * to queues on src and dst IPs and ports
2189 */
2190 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2191 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2192 return -EINVAL;
2193
2194 /* We need at least the IP SRC and DEST fields for hashing */
2195 if (!(nfc->data & RXH_IP_SRC) ||
2196 !(nfc->data & RXH_IP_DST))
2197 return -EINVAL;
2198
2199 switch (nfc->flow_type) {
2200 case TCP_V4_FLOW:
2201 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2202 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002203 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002205 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2206 hena |=
2207 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2208
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002209 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002210 break;
2211 default:
2212 return -EINVAL;
2213 }
2214 break;
2215 case TCP_V6_FLOW:
2216 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2217 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002218 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002219 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002220 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2221 hena |=
2222 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2223
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002224 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002225 break;
2226 default:
2227 return -EINVAL;
2228 }
2229 break;
2230 case UDP_V4_FLOW:
2231 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2232 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002233 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002234 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002235 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2236 hena |=
2237 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2238 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2239
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002240 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2241 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242 break;
2243 default:
2244 return -EINVAL;
2245 }
2246 break;
2247 case UDP_V6_FLOW:
2248 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2249 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002250 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002251 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002252 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2253 hena |=
2254 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2255 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2256
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002257 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2258 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002259 break;
2260 default:
2261 return -EINVAL;
2262 }
2263 break;
2264 case AH_ESP_V4_FLOW:
2265 case AH_V4_FLOW:
2266 case ESP_V4_FLOW:
2267 case SCTP_V4_FLOW:
2268 if ((nfc->data & RXH_L4_B_0_1) ||
2269 (nfc->data & RXH_L4_B_2_3))
2270 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002271 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002272 break;
2273 case AH_ESP_V6_FLOW:
2274 case AH_V6_FLOW:
2275 case ESP_V6_FLOW:
2276 case SCTP_V6_FLOW:
2277 if ((nfc->data & RXH_L4_B_0_1) ||
2278 (nfc->data & RXH_L4_B_2_3))
2279 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002280 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 break;
2282 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002283 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2284 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002285 break;
2286 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002287 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2288 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002289 break;
2290 default:
2291 return -EINVAL;
2292 }
2293
2294 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2295 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2296 i40e_flush(hw);
2297
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002298 /* Save setting for future output/update */
2299 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2300
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002301 return 0;
2302}
2303
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002304/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002305 * i40e_match_fdir_input_set - Match a new filter against an existing one
2306 * @rule: The filter already added
2307 * @input: The new filter to comapre against
2308 *
2309 * Returns true if the two input set match
2310 **/
2311static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2312 struct i40e_fdir_filter *input)
2313{
2314 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2315 (rule->src_ip[0] != input->src_ip[0]) ||
2316 (rule->dst_port != input->dst_port) ||
2317 (rule->src_port != input->src_port))
2318 return false;
2319 return true;
2320}
2321
2322/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002323 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2324 * @vsi: Pointer to the targeted VSI
2325 * @input: The filter to update or NULL to indicate deletion
2326 * @sw_idx: Software index to the filter
2327 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002328 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002329 * This function updates (or deletes) a Flow Director entry from
2330 * the hlist of the corresponding PF
2331 *
2332 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002333 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002334static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2335 struct i40e_fdir_filter *input,
2336 u16 sw_idx,
2337 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002338{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002339 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002340 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002341 struct hlist_node *node2;
2342 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002343
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002344 parent = NULL;
2345 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002346
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002347 hlist_for_each_entry_safe(rule, node2,
2348 &pf->fdir_filter_list, fdir_node) {
2349 /* hash found, or no matching entry */
2350 if (rule->fd_id >= sw_idx)
2351 break;
2352 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002353 }
2354
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002355 /* if there is an old rule occupying our place remove it */
2356 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002357 if (input && !i40e_match_fdir_input_set(rule, input))
2358 err = i40e_add_del_fdir(vsi, rule, false);
2359 else if (!input)
2360 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002361 hlist_del(&rule->fdir_node);
2362 kfree(rule);
2363 pf->fdir_pf_active_filters--;
2364 }
2365
2366 /* If no input this was a delete, err should be 0 if a rule was
2367 * successfully found and removed from the list else -EINVAL
2368 */
2369 if (!input)
2370 return err;
2371
2372 /* initialize node and set software index */
2373 INIT_HLIST_NODE(&input->fdir_node);
2374
2375 /* add filter to the list */
2376 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002377 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002378 else
2379 hlist_add_head(&input->fdir_node,
2380 &pf->fdir_filter_list);
2381
2382 /* update counts */
2383 pf->fdir_pf_active_filters++;
2384
2385 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002386}
2387
2388/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002389 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2390 * @vsi: Pointer to the targeted VSI
2391 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002392 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002393 * The function removes a Flow Director filter entry from the
2394 * hlist of the corresponding PF
2395 *
2396 * Returns 0 on success
2397 */
2398static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2399 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002400{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002401 struct ethtool_rx_flow_spec *fsp =
2402 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002403 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002404 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002405
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002406 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2407 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2408 return -EBUSY;
2409
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002410 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2411 return -EBUSY;
2412
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002413 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002414
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002415 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002416 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002417}
2418
2419/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002420 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002421 * @vsi: pointer to the targeted VSI
2422 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002423 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002424 * Add Flow Director filters for a specific flow spec based on their
2425 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002426 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002427static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2428 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002429{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002430 struct ethtool_rx_flow_spec *fsp;
2431 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002432 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002433 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002434 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002435
2436 if (!vsi)
2437 return -EINVAL;
2438
2439 pf = vsi->back;
2440
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002441 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2442 return -EOPNOTSUPP;
2443
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002444 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002445 return -ENOSPC;
2446
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002447 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2448 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2449 return -EBUSY;
2450
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002451 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2452 return -EBUSY;
2453
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002454 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2455
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002456 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2457 pf->hw.func_caps.fd_filters_guaranteed)) {
2458 return -EINVAL;
2459 }
2460
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002461 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2462 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002463 return -EINVAL;
2464
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002465 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002466
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002467 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002468 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002469
2470 input->fd_id = fsp->location;
2471
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002472 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2473 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2474 else
2475 input->dest_ctl =
2476 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2477
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002478 input->q_index = fsp->ring_cookie;
2479 input->flex_off = 0;
2480 input->pctype = 0;
2481 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002482 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002483 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002484 input->flow_type = fsp->flow_type;
2485 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002486
2487 /* Reverse the src and dest notion, since the HW expects them to be from
2488 * Tx perspective where as the input from user is from Rx filter view.
2489 */
2490 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2491 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2492 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2493 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002494
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002495 if (ntohl(fsp->m_ext.data[1])) {
2496 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2497 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2498 goto free_input;
2499 }
2500 vf_id = ntohl(fsp->h_ext.data[1]);
2501 /* Find vsi id from vf id and override dest vsi */
2502 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2503 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2504 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2505 goto free_input;
2506 }
2507 }
2508
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002509 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002510free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002511 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002512 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002513 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002514 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002515
2516 return ret;
2517}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002518
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002519/**
2520 * i40e_set_rxnfc - command to set RX flow classification rules
2521 * @netdev: network interface device structure
2522 * @cmd: ethtool rxnfc command
2523 *
2524 * Returns Success if the command is supported.
2525 **/
2526static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2527{
2528 struct i40e_netdev_priv *np = netdev_priv(netdev);
2529 struct i40e_vsi *vsi = np->vsi;
2530 struct i40e_pf *pf = vsi->back;
2531 int ret = -EOPNOTSUPP;
2532
2533 switch (cmd->cmd) {
2534 case ETHTOOL_SRXFH:
2535 ret = i40e_set_rss_hash_opt(pf, cmd);
2536 break;
2537 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002538 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002539 break;
2540 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002541 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002542 break;
2543 default:
2544 break;
2545 }
2546
2547 return ret;
2548}
2549
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002550/**
2551 * i40e_max_channels - get Max number of combined channels supported
2552 * @vsi: vsi pointer
2553 **/
2554static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2555{
2556 /* TODO: This code assumes DCB and FD is disabled for now. */
2557 return vsi->alloc_queue_pairs;
2558}
2559
2560/**
2561 * i40e_get_channels - Get the current channels enabled and max supported etc.
2562 * @netdev: network interface device structure
2563 * @ch: ethtool channels structure
2564 *
2565 * We don't support separate tx and rx queues as channels. The other count
2566 * represents how many queues are being used for control. max_combined counts
2567 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2568 * q_vectors since we support a lot more queue pairs than q_vectors.
2569 **/
2570static void i40e_get_channels(struct net_device *dev,
2571 struct ethtool_channels *ch)
2572{
2573 struct i40e_netdev_priv *np = netdev_priv(dev);
2574 struct i40e_vsi *vsi = np->vsi;
2575 struct i40e_pf *pf = vsi->back;
2576
2577 /* report maximum channels */
2578 ch->max_combined = i40e_max_channels(vsi);
2579
2580 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002581 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002582 ch->max_other = ch->other_count;
2583
2584 /* Note: This code assumes DCB is disabled for now. */
2585 ch->combined_count = vsi->num_queue_pairs;
2586}
2587
2588/**
2589 * i40e_set_channels - Set the new channels count.
2590 * @netdev: network interface device structure
2591 * @ch: ethtool channels structure
2592 *
2593 * The new channels count may not be the same as requested by the user
2594 * since it gets rounded down to a power of 2 value.
2595 **/
2596static int i40e_set_channels(struct net_device *dev,
2597 struct ethtool_channels *ch)
2598{
2599 struct i40e_netdev_priv *np = netdev_priv(dev);
2600 unsigned int count = ch->combined_count;
2601 struct i40e_vsi *vsi = np->vsi;
2602 struct i40e_pf *pf = vsi->back;
2603 int new_count;
2604
2605 /* We do not support setting channels for any other VSI at present */
2606 if (vsi->type != I40E_VSI_MAIN)
2607 return -EINVAL;
2608
2609 /* verify they are not requesting separate vectors */
2610 if (!count || ch->rx_count || ch->tx_count)
2611 return -EINVAL;
2612
2613 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002614 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002615 return -EINVAL;
2616
2617 /* verify the number of channels does not exceed hardware limits */
2618 if (count > i40e_max_channels(vsi))
2619 return -EINVAL;
2620
2621 /* update feature limits from largest to smallest supported values */
2622 /* TODO: Flow director limit, DCB etc */
2623
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002624 /* use rss_reconfig to rebuild with new queue count and update traffic
2625 * class queue mapping
2626 */
2627 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002628 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002629 return 0;
2630 else
2631 return -EINVAL;
2632}
2633
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002634/**
2635 * i40e_get_rxfh_key_size - get the RSS hash key size
2636 * @netdev: network interface device structure
2637 *
2638 * Returns the table size.
2639 **/
2640static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2641{
2642 return I40E_HKEY_ARRAY_SIZE;
2643}
2644
2645/**
2646 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2647 * @netdev: network interface device structure
2648 *
2649 * Returns the table size.
2650 **/
2651static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2652{
2653 return I40E_HLUT_ARRAY_SIZE;
2654}
2655
2656static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2657 u8 *hfunc)
2658{
2659 struct i40e_netdev_priv *np = netdev_priv(netdev);
2660 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002661 u8 *lut, *seed = NULL;
2662 int ret;
2663 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002664
2665 if (hfunc)
2666 *hfunc = ETH_RSS_HASH_TOP;
2667
2668 if (!indir)
2669 return 0;
2670
Helin Zhang043dd652015-10-21 19:56:23 -04002671 seed = key;
2672 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2673 if (!lut)
2674 return -ENOMEM;
2675 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2676 if (ret)
2677 goto out;
2678 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2679 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002680
Helin Zhang043dd652015-10-21 19:56:23 -04002681out:
2682 kfree(lut);
2683
2684 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002685}
2686
2687/**
2688 * i40e_set_rxfh - set the rx flow hash indirection table
2689 * @netdev: network interface device structure
2690 * @indir: indirection table
2691 * @key: hash key
2692 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002693 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002694 * returns 0 after programming the table.
2695 **/
2696static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2697 const u8 *key, const u8 hfunc)
2698{
2699 struct i40e_netdev_priv *np = netdev_priv(netdev);
2700 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002701 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002702 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002703
2704 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2705 return -EOPNOTSUPP;
2706
2707 if (!indir)
2708 return 0;
2709
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002710 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002711 if (!vsi->rss_hkey_user) {
2712 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2713 GFP_KERNEL);
2714 if (!vsi->rss_hkey_user)
2715 return -ENOMEM;
2716 }
2717 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2718 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002719 }
Helin Zhang28c58692015-10-26 19:44:27 -04002720 if (!vsi->rss_lut_user) {
2721 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2722 if (!vsi->rss_lut_user)
2723 return -ENOMEM;
2724 }
Helin Zhang043dd652015-10-21 19:56:23 -04002725
Helin Zhang28c58692015-10-26 19:44:27 -04002726 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2727 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2728 vsi->rss_lut_user[i] = (u8)(indir[i]);
2729
2730 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2731 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002732}
2733
Greg Rose7e45ab42015-02-06 08:52:19 +00002734/**
2735 * i40e_get_priv_flags - report device private flags
2736 * @dev: network interface device structure
2737 *
2738 * The get string set count and the string set should be matched for each
2739 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2740 * array.
2741 *
2742 * Returns a u32 bitmap of flags.
2743 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002744static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002745{
2746 struct i40e_netdev_priv *np = netdev_priv(dev);
2747 struct i40e_vsi *vsi = np->vsi;
2748 struct i40e_pf *pf = vsi->back;
2749 u32 ret_flags = 0;
2750
2751 ret_flags |= pf->hw.func_caps.npar_enable ?
2752 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002753 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2754 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002755 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2756 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002757 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2758 I40E_PRIV_FLAGS_VEB_STATS : 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002759 ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
2760 I40E_PRIV_FLAGS_PS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002761 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
2762 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Greg Rose7e45ab42015-02-06 08:52:19 +00002763
2764 return ret_flags;
2765}
2766
Shannon Nelson9ac77262015-08-27 11:42:40 -04002767/**
2768 * i40e_set_priv_flags - set private flags
2769 * @dev: network interface device structure
2770 * @flags: bit flags to be set
2771 **/
2772static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2773{
2774 struct i40e_netdev_priv *np = netdev_priv(dev);
2775 struct i40e_vsi *vsi = np->vsi;
2776 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002777 bool reset_required = false;
2778
2779 /* NOTE: MFP is not settable */
2780
2781 /* allow the user to control the method of receive
2782 * buffer DMA, whether the packet is split at header
2783 * boundaries into two separate buffers. In some cases
2784 * one routine or the other will perform better.
2785 */
2786 if ((flags & I40E_PRIV_FLAGS_PS) &&
2787 !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2788 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
2789 pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
2790 reset_required = true;
2791 } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
2792 (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2793 pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
2794 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
2795 reset_required = true;
2796 }
Shannon Nelson9ac77262015-08-27 11:42:40 -04002797
2798 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2799 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2800 else
2801 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2802
Jesse Brandeburgef171782015-09-03 17:18:49 -04002803 /* allow the user to control the state of the Flow
2804 * Director ATR (Application Targeted Routing) feature
2805 * of the driver
2806 */
2807 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2808 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2809 } else {
2810 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2811 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2812 }
2813
Shannon Nelson66fc3602016-01-13 16:51:42 -08002814 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2815 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002816 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002817 reset_required = true;
2818 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2819 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002820 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002821 reset_required = true;
2822 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002823
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002824 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
2825 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
2826 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2827 else
2828 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2829
Jesse Brandeburg827de392015-11-06 15:26:07 -08002830 /* if needed, issue reset to cause things to take effect */
2831 if (reset_required)
2832 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2833
Shannon Nelson9ac77262015-08-27 11:42:40 -04002834 return 0;
2835}
2836
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002837static const struct ethtool_ops i40e_ethtool_ops = {
2838 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002839 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002840 .get_drvinfo = i40e_get_drvinfo,
2841 .get_regs_len = i40e_get_regs_len,
2842 .get_regs = i40e_get_regs,
2843 .nway_reset = i40e_nway_reset,
2844 .get_link = ethtool_op_get_link,
2845 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002846 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002847 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002848 .get_eeprom_len = i40e_get_eeprom_len,
2849 .get_eeprom = i40e_get_eeprom,
2850 .get_ringparam = i40e_get_ringparam,
2851 .set_ringparam = i40e_set_ringparam,
2852 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002853 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002854 .get_msglevel = i40e_get_msglevel,
2855 .set_msglevel = i40e_set_msglevel,
2856 .get_rxnfc = i40e_get_rxnfc,
2857 .set_rxnfc = i40e_set_rxnfc,
2858 .self_test = i40e_diag_test,
2859 .get_strings = i40e_get_strings,
2860 .set_phys_id = i40e_set_phys_id,
2861 .get_sset_count = i40e_get_sset_count,
2862 .get_ethtool_stats = i40e_get_ethtool_stats,
2863 .get_coalesce = i40e_get_coalesce,
2864 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002865 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2866 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2867 .get_rxfh = i40e_get_rxfh,
2868 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002869 .get_channels = i40e_get_channels,
2870 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002871 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002872 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002873 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002874};
2875
2876void i40e_set_ethtool_ops(struct net_device *netdev)
2877{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002878 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002879}