blob: 5778f9e2f43cb7335dd883a9394ba5d1b05f415f [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 Nelsonc150a502014-11-13 08:23:13 +00001008 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001009 int errno;
1010
1011 /* make sure it is the right magic for NVMUpdate */
1012 if ((eeprom->magic >> 16) != hw->device_id)
1013 return -EINVAL;
1014
Shannon Nelsonc150a502014-11-13 08:23:13 +00001015 cmd = (struct i40e_nvm_access *)eeprom;
1016 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001017 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001018 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001019 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1020 ret_val, hw->aq.asq_last_status, errno,
1021 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1022 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001023
1024 return errno;
1025 }
1026
1027 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001028 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1029
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001030 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001031 if (!eeprom_buff)
1032 return -ENOMEM;
1033
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001034 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1035 if (ret_val) {
1036 dev_info(&pf->pdev->dev,
1037 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1038 ret_val, hw->aq.asq_last_status);
1039 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001040 }
1041
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001042 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1043 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1044 len = I40E_NVM_SECTOR_SIZE;
1045 last = false;
1046 for (i = 0; i < sectors; i++) {
1047 if (i == (sectors - 1)) {
1048 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1049 last = true;
1050 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001051 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1052 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001053 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001054 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001055 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001056 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001057 "read NVM failed, invalid offset 0x%x\n",
1058 offset);
1059 break;
1060 } else if (ret_val &&
1061 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1062 dev_info(&pf->pdev->dev,
1063 "read NVM failed, access, offset 0x%x\n",
1064 offset);
1065 break;
1066 } else if (ret_val) {
1067 dev_info(&pf->pdev->dev,
1068 "read NVM failed offset %d err=%d status=0x%x\n",
1069 offset, ret_val, hw->aq.asq_last_status);
1070 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001071 }
1072 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001074 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001075 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001076free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001077 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001078 return ret_val;
1079}
1080
1081static int i40e_get_eeprom_len(struct net_device *netdev)
1082{
1083 struct i40e_netdev_priv *np = netdev_priv(netdev);
1084 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001085 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001086
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001087 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1088 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1089 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1090 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001091 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001092 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001093}
1094
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001095static int i40e_set_eeprom(struct net_device *netdev,
1096 struct ethtool_eeprom *eeprom, u8 *bytes)
1097{
1098 struct i40e_netdev_priv *np = netdev_priv(netdev);
1099 struct i40e_hw *hw = &np->vsi->back->hw;
1100 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001101 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001102 int ret_val = 0;
1103 int errno;
1104 u32 magic;
1105
1106 /* normal ethtool set_eeprom is not supported */
1107 magic = hw->vendor_id | (hw->device_id << 16);
1108 if (eeprom->magic == magic)
1109 return -EOPNOTSUPP;
1110
1111 /* check for NVMUpdate access method */
1112 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1113 return -EINVAL;
1114
1115 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1116 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1117 return -EBUSY;
1118
Shannon Nelsonc150a502014-11-13 08:23:13 +00001119 cmd = (struct i40e_nvm_access *)eeprom;
1120 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001121 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001122 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001123 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1124 ret_val, hw->aq.asq_last_status, errno,
1125 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1126 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001127
1128 return errno;
1129}
1130
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001131static void i40e_get_drvinfo(struct net_device *netdev,
1132 struct ethtool_drvinfo *drvinfo)
1133{
1134 struct i40e_netdev_priv *np = netdev_priv(netdev);
1135 struct i40e_vsi *vsi = np->vsi;
1136 struct i40e_pf *pf = vsi->back;
1137
1138 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1139 strlcpy(drvinfo->version, i40e_driver_version_str,
1140 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001141 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001142 sizeof(drvinfo->fw_version));
1143 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1144 sizeof(drvinfo->bus_info));
1145}
1146
1147static void i40e_get_ringparam(struct net_device *netdev,
1148 struct ethtool_ringparam *ring)
1149{
1150 struct i40e_netdev_priv *np = netdev_priv(netdev);
1151 struct i40e_pf *pf = np->vsi->back;
1152 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1153
1154 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1155 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1156 ring->rx_mini_max_pending = 0;
1157 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001158 ring->rx_pending = vsi->rx_rings[0]->count;
1159 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001160 ring->rx_mini_pending = 0;
1161 ring->rx_jumbo_pending = 0;
1162}
1163
1164static int i40e_set_ringparam(struct net_device *netdev,
1165 struct ethtool_ringparam *ring)
1166{
1167 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1168 struct i40e_netdev_priv *np = netdev_priv(netdev);
1169 struct i40e_vsi *vsi = np->vsi;
1170 struct i40e_pf *pf = vsi->back;
1171 u32 new_rx_count, new_tx_count;
1172 int i, err = 0;
1173
1174 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1175 return -EINVAL;
1176
Shannon Nelson1fa18372013-11-20 10:03:08 +00001177 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1178 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1179 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1180 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1181 netdev_info(netdev,
1182 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1183 ring->tx_pending, ring->rx_pending,
1184 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1185 return -EINVAL;
1186 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001187
Shannon Nelson1fa18372013-11-20 10:03:08 +00001188 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1189 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001190
1191 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001192 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1193 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001194 return 0;
1195
1196 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1197 usleep_range(1000, 2000);
1198
1199 if (!netif_running(vsi->netdev)) {
1200 /* simple case - set for the next time the netdev is started */
1201 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001202 vsi->tx_rings[i]->count = new_tx_count;
1203 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001204 }
1205 goto done;
1206 }
1207
1208 /* We can't just free everything and then setup again,
1209 * because the ISRs in MSI-X mode get passed pointers
1210 * to the Tx and Rx ring structs.
1211 */
1212
1213 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001214 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001215 netdev_info(netdev,
1216 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001217 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001218 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1219 sizeof(struct i40e_ring), GFP_KERNEL);
1220 if (!tx_rings) {
1221 err = -ENOMEM;
1222 goto done;
1223 }
1224
1225 for (i = 0; i < vsi->num_queue_pairs; i++) {
1226 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001227 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001228 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001229 /* the desc and bi pointers will be reallocated in the
1230 * setup call
1231 */
1232 tx_rings[i].desc = NULL;
1233 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001234 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1235 if (err) {
1236 while (i) {
1237 i--;
1238 i40e_free_tx_resources(&tx_rings[i]);
1239 }
1240 kfree(tx_rings);
1241 tx_rings = NULL;
1242
1243 goto done;
1244 }
1245 }
1246 }
1247
1248 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001249 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001250 netdev_info(netdev,
1251 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001252 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001253 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1254 sizeof(struct i40e_ring), GFP_KERNEL);
1255 if (!rx_rings) {
1256 err = -ENOMEM;
1257 goto free_tx;
1258 }
1259
1260 for (i = 0; i < vsi->num_queue_pairs; i++) {
1261 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001262 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001263 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001264 /* the desc and bi pointers will be reallocated in the
1265 * setup call
1266 */
1267 rx_rings[i].desc = NULL;
1268 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1270 if (err) {
1271 while (i) {
1272 i--;
1273 i40e_free_rx_resources(&rx_rings[i]);
1274 }
1275 kfree(rx_rings);
1276 rx_rings = NULL;
1277
1278 goto free_tx;
1279 }
1280 }
1281 }
1282
1283 /* Bring interface down, copy in the new ring info,
1284 * then restore the interface
1285 */
1286 i40e_down(vsi);
1287
1288 if (tx_rings) {
1289 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001290 i40e_free_tx_resources(vsi->tx_rings[i]);
1291 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001292 }
1293 kfree(tx_rings);
1294 tx_rings = NULL;
1295 }
1296
1297 if (rx_rings) {
1298 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001299 i40e_free_rx_resources(vsi->rx_rings[i]);
1300 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301 }
1302 kfree(rx_rings);
1303 rx_rings = NULL;
1304 }
1305
1306 i40e_up(vsi);
1307
1308free_tx:
1309 /* error cleanup if the Rx allocations failed after getting Tx */
1310 if (tx_rings) {
1311 for (i = 0; i < vsi->num_queue_pairs; i++)
1312 i40e_free_tx_resources(&tx_rings[i]);
1313 kfree(tx_rings);
1314 tx_rings = NULL;
1315 }
1316
1317done:
1318 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1319
1320 return err;
1321}
1322
1323static int i40e_get_sset_count(struct net_device *netdev, int sset)
1324{
1325 struct i40e_netdev_priv *np = netdev_priv(netdev);
1326 struct i40e_vsi *vsi = np->vsi;
1327 struct i40e_pf *pf = vsi->back;
1328
1329 switch (sset) {
1330 case ETH_SS_TEST:
1331 return I40E_TEST_LEN;
1332 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001333 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001334 int len = I40E_PF_STATS_LEN(netdev);
1335
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001336 if ((pf->lan_veb != I40E_NO_VEB) &&
1337 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001338 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001339 return len;
1340 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001342 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001343 case ETH_SS_PRIV_FLAGS:
1344 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001345 default:
1346 return -EOPNOTSUPP;
1347 }
1348}
1349
1350static void i40e_get_ethtool_stats(struct net_device *netdev,
1351 struct ethtool_stats *stats, u64 *data)
1352{
1353 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001354 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001355 struct i40e_vsi *vsi = np->vsi;
1356 struct i40e_pf *pf = vsi->back;
1357 int i = 0;
1358 char *p;
1359 int j;
1360 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001361 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001362
1363 i40e_update_stats(vsi);
1364
1365 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1366 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1367 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1368 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1369 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001370 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1371 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1372 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1373 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1374 }
Vasu Dev38e00432014-08-01 13:27:03 -07001375#ifdef I40E_FCOE
1376 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1377 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1378 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1379 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1380 }
1381#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001382 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001383 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001384 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001385
1386 if (!tx_ring)
1387 continue;
1388
1389 /* process Tx ring statistics */
1390 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001391 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001392 data[i] = tx_ring->stats.packets;
1393 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001394 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001395 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001396
1397 /* Rx ring is the 2nd half of the queue pair */
1398 rx_ring = &tx_ring[1];
1399 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001400 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001401 data[i] = rx_ring->stats.packets;
1402 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001403 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001404 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001405 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001406 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001407 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001408 return;
1409
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001410 if ((pf->lan_veb != I40E_NO_VEB) &&
1411 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001412 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001413
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001414 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1415 p = (char *)veb;
1416 p += i40e_gstrings_veb_stats[j].stat_offset;
1417 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1418 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001419 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001420 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1421 data[i++] = veb->tc_stats.tc_tx_packets[j];
1422 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1423 data[i++] = veb->tc_stats.tc_rx_packets[j];
1424 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1425 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001426 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001427 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1428 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1429 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1430 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1431 }
1432 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1433 data[i++] = pf->stats.priority_xon_tx[j];
1434 data[i++] = pf->stats.priority_xoff_tx[j];
1435 }
1436 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1437 data[i++] = pf->stats.priority_xon_rx[j];
1438 data[i++] = pf->stats.priority_xoff_rx[j];
1439 }
1440 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1441 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001442}
1443
1444static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1445 u8 *data)
1446{
1447 struct i40e_netdev_priv *np = netdev_priv(netdev);
1448 struct i40e_vsi *vsi = np->vsi;
1449 struct i40e_pf *pf = vsi->back;
1450 char *p = (char *)data;
1451 int i;
1452
1453 switch (stringset) {
1454 case ETH_SS_TEST:
1455 for (i = 0; i < I40E_TEST_LEN; i++) {
1456 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1457 data += ETH_GSTRING_LEN;
1458 }
1459 break;
1460 case ETH_SS_STATS:
1461 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1462 snprintf(p, ETH_GSTRING_LEN, "%s",
1463 i40e_gstrings_net_stats[i].stat_string);
1464 p += ETH_GSTRING_LEN;
1465 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001466 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1467 snprintf(p, ETH_GSTRING_LEN, "%s",
1468 i40e_gstrings_misc_stats[i].stat_string);
1469 p += ETH_GSTRING_LEN;
1470 }
Vasu Dev38e00432014-08-01 13:27:03 -07001471#ifdef I40E_FCOE
1472 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1473 snprintf(p, ETH_GSTRING_LEN, "%s",
1474 i40e_gstrings_fcoe_stats[i].stat_string);
1475 p += ETH_GSTRING_LEN;
1476 }
1477#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001478 for (i = 0; i < vsi->num_queue_pairs; i++) {
1479 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1480 p += ETH_GSTRING_LEN;
1481 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1482 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1484 p += ETH_GSTRING_LEN;
1485 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1486 p += ETH_GSTRING_LEN;
1487 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001488 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001489 return;
1490
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001491 if ((pf->lan_veb != I40E_NO_VEB) &&
1492 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001493 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1494 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1495 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496 p += ETH_GSTRING_LEN;
1497 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001498 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1499 snprintf(p, ETH_GSTRING_LEN,
1500 "veb.tc_%u_tx_packets", i);
1501 p += ETH_GSTRING_LEN;
1502 snprintf(p, ETH_GSTRING_LEN,
1503 "veb.tc_%u_tx_bytes", i);
1504 p += ETH_GSTRING_LEN;
1505 snprintf(p, ETH_GSTRING_LEN,
1506 "veb.tc_%u_rx_packets", i);
1507 p += ETH_GSTRING_LEN;
1508 snprintf(p, ETH_GSTRING_LEN,
1509 "veb.tc_%u_rx_bytes", i);
1510 p += ETH_GSTRING_LEN;
1511 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001512 }
1513 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1514 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1515 i40e_gstrings_stats[i].stat_string);
1516 p += ETH_GSTRING_LEN;
1517 }
1518 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1519 snprintf(p, ETH_GSTRING_LEN,
1520 "port.tx_priority_%u_xon", i);
1521 p += ETH_GSTRING_LEN;
1522 snprintf(p, ETH_GSTRING_LEN,
1523 "port.tx_priority_%u_xoff", i);
1524 p += ETH_GSTRING_LEN;
1525 }
1526 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1527 snprintf(p, ETH_GSTRING_LEN,
1528 "port.rx_priority_%u_xon", i);
1529 p += ETH_GSTRING_LEN;
1530 snprintf(p, ETH_GSTRING_LEN,
1531 "port.rx_priority_%u_xoff", i);
1532 p += ETH_GSTRING_LEN;
1533 }
1534 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1535 snprintf(p, ETH_GSTRING_LEN,
1536 "port.rx_priority_%u_xon_2_xoff", i);
1537 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001538 }
1539 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1540 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001541 case ETH_SS_PRIV_FLAGS:
1542 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1543 memcpy(data, i40e_priv_flags_strings[i],
1544 ETH_GSTRING_LEN);
1545 data += ETH_GSTRING_LEN;
1546 }
1547 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001548 default:
1549 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001550 }
1551}
1552
1553static int i40e_get_ts_info(struct net_device *dev,
1554 struct ethtool_ts_info *info)
1555{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001556 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1557
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001558 /* only report HW timestamping if PTP is enabled */
1559 if (!(pf->flags & I40E_FLAG_PTP))
1560 return ethtool_op_get_ts_info(dev, info);
1561
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001562 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1563 SOF_TIMESTAMPING_RX_SOFTWARE |
1564 SOF_TIMESTAMPING_SOFTWARE |
1565 SOF_TIMESTAMPING_TX_HARDWARE |
1566 SOF_TIMESTAMPING_RX_HARDWARE |
1567 SOF_TIMESTAMPING_RAW_HARDWARE;
1568
1569 if (pf->ptp_clock)
1570 info->phc_index = ptp_clock_index(pf->ptp_clock);
1571 else
1572 info->phc_index = -1;
1573
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001574 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001575
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001576 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1577 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1578 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001579
1580 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001581}
1582
Shannon Nelson7b086392013-11-20 10:02:59 +00001583static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584{
Shannon Nelson7b086392013-11-20 10:02:59 +00001585 struct i40e_netdev_priv *np = netdev_priv(netdev);
1586 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001587 i40e_status status;
1588 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001589
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001590 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001591 status = i40e_get_link_status(&pf->hw, &link_up);
1592 if (status) {
1593 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1594 *data = 1;
1595 return *data;
1596 }
1597
1598 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001599 *data = 0;
1600 else
1601 *data = 1;
1602
1603 return *data;
1604}
1605
Shannon Nelson7b086392013-11-20 10:02:59 +00001606static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001607{
Shannon Nelson7b086392013-11-20 10:02:59 +00001608 struct i40e_netdev_priv *np = netdev_priv(netdev);
1609 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001610
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001611 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001612 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001613
Shannon Nelson7b086392013-11-20 10:02:59 +00001614 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001615}
1616
Shannon Nelson7b086392013-11-20 10:02:59 +00001617static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001618{
Shannon Nelson7b086392013-11-20 10:02:59 +00001619 struct i40e_netdev_priv *np = netdev_priv(netdev);
1620 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001621
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001622 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001623 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624
Shannon Nelson4443ec92014-11-13 08:23:12 +00001625 /* forcebly clear the NVM Update state machine */
1626 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1627
Shannon Nelson7b086392013-11-20 10:02:59 +00001628 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001629}
1630
Shannon Nelson7b086392013-11-20 10:02:59 +00001631static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001632{
Shannon Nelson7b086392013-11-20 10:02:59 +00001633 struct i40e_netdev_priv *np = netdev_priv(netdev);
1634 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001635 u16 swc_old = pf->sw_int_count;
1636
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001637 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001638 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1639 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001640 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1641 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1642 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1643 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001644 usleep_range(1000, 2000);
1645 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001646
1647 return *data;
1648}
1649
Shannon Nelson7b086392013-11-20 10:02:59 +00001650static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001651{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001652 struct i40e_netdev_priv *np = netdev_priv(netdev);
1653 struct i40e_pf *pf = np->vsi->back;
1654
1655 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001656 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001657
1658 return *data;
1659}
1660
Greg Rosee17bc412015-04-16 20:05:59 -04001661static inline bool i40e_active_vfs(struct i40e_pf *pf)
1662{
1663 struct i40e_vf *vfs = pf->vf;
1664 int i;
1665
1666 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001667 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001668 return true;
1669 return false;
1670}
1671
Greg Rose510efb22015-07-10 19:36:01 -04001672static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1673{
1674 struct i40e_vsi **vsi = pf->vsi;
1675 int i;
1676
1677 for (i = 0; i < pf->num_alloc_vsi; i++) {
1678 if (!vsi[i])
1679 continue;
1680 if (vsi[i]->type == I40E_VSI_VMDQ2)
1681 return true;
1682 }
1683
1684 return false;
1685}
1686
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001687static void i40e_diag_test(struct net_device *netdev,
1688 struct ethtool_test *eth_test, u64 *data)
1689{
1690 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001691 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001692 struct i40e_pf *pf = np->vsi->back;
1693
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1695 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001696 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697
Shannon Nelsonf551b432013-11-26 10:49:12 +00001698 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001699
Greg Rose510efb22015-07-10 19:36:01 -04001700 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001701 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001702 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001703 data[I40E_ETH_TEST_REG] = 1;
1704 data[I40E_ETH_TEST_EEPROM] = 1;
1705 data[I40E_ETH_TEST_INTR] = 1;
1706 data[I40E_ETH_TEST_LOOPBACK] = 1;
1707 data[I40E_ETH_TEST_LINK] = 1;
1708 eth_test->flags |= ETH_TEST_FL_FAILED;
1709 clear_bit(__I40E_TESTING, &pf->state);
1710 goto skip_ol_tests;
1711 }
1712
Greg Rose5b86c5c2015-02-26 16:14:35 +00001713 /* If the device is online then take it offline */
1714 if (if_running)
1715 /* indicate we're in test mode */
1716 dev_close(netdev);
1717 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001718 /* This reset does not affect link - if it is
1719 * changed to a type of reset that does affect
1720 * link then the following link test would have
1721 * to be moved to before the reset
1722 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001723 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001724
Shannon Nelson7b086392013-11-20 10:02:59 +00001725 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001726 eth_test->flags |= ETH_TEST_FL_FAILED;
1727
Shannon Nelson7b086392013-11-20 10:02:59 +00001728 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001729 eth_test->flags |= ETH_TEST_FL_FAILED;
1730
Shannon Nelson7b086392013-11-20 10:02:59 +00001731 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001732 eth_test->flags |= ETH_TEST_FL_FAILED;
1733
Shannon Nelson7b086392013-11-20 10:02:59 +00001734 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001735 eth_test->flags |= ETH_TEST_FL_FAILED;
1736
Shannon Nelsonf551b432013-11-26 10:49:12 +00001737 /* run reg test last, a reset is required after it */
1738 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1739 eth_test->flags |= ETH_TEST_FL_FAILED;
1740
1741 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001742 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001743
1744 if (if_running)
1745 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001746 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001747 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001748 netif_info(pf, drv, netdev, "online testing starting\n");
1749
Shannon Nelson7b086392013-11-20 10:02:59 +00001750 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001751 eth_test->flags |= ETH_TEST_FL_FAILED;
1752
1753 /* Offline only tests, not run in online; pass by default */
1754 data[I40E_ETH_TEST_REG] = 0;
1755 data[I40E_ETH_TEST_EEPROM] = 0;
1756 data[I40E_ETH_TEST_INTR] = 0;
1757 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001758 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001759
Greg Rosee17bc412015-04-16 20:05:59 -04001760skip_ol_tests:
1761
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001762 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001763}
1764
1765static void i40e_get_wol(struct net_device *netdev,
1766 struct ethtool_wolinfo *wol)
1767{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001768 struct i40e_netdev_priv *np = netdev_priv(netdev);
1769 struct i40e_pf *pf = np->vsi->back;
1770 struct i40e_hw *hw = &pf->hw;
1771 u16 wol_nvm_bits;
1772
1773 /* NVM bit on means WoL disabled for the port */
1774 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001775 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001776 wol->supported = 0;
1777 wol->wolopts = 0;
1778 } else {
1779 wol->supported = WAKE_MAGIC;
1780 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1781 }
1782}
1783
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001784/**
1785 * i40e_set_wol - set the WakeOnLAN configuration
1786 * @netdev: the netdev in question
1787 * @wol: the ethtool WoL setting data
1788 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001789static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1790{
1791 struct i40e_netdev_priv *np = netdev_priv(netdev);
1792 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001793 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001794 struct i40e_hw *hw = &pf->hw;
1795 u16 wol_nvm_bits;
1796
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001797 /* WoL not supported if this isn't the controlling PF on the port */
1798 if (hw->partition_id != 1) {
1799 i40e_partition_setting_complaint(pf);
1800 return -EOPNOTSUPP;
1801 }
1802
1803 if (vsi != pf->vsi[pf->lan_vsi])
1804 return -EOPNOTSUPP;
1805
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001806 /* NVM bit on means WoL disabled for the port */
1807 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001808 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001809 return -EOPNOTSUPP;
1810
1811 /* only magic packet is supported */
1812 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1813 return -EOPNOTSUPP;
1814
1815 /* is this a new value? */
1816 if (pf->wol_en != !!wol->wolopts) {
1817 pf->wol_en = !!wol->wolopts;
1818 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1819 }
1820
1821 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001822}
1823
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001824static int i40e_set_phys_id(struct net_device *netdev,
1825 enum ethtool_phys_id_state state)
1826{
1827 struct i40e_netdev_priv *np = netdev_priv(netdev);
1828 struct i40e_pf *pf = np->vsi->back;
1829 struct i40e_hw *hw = &pf->hw;
1830 int blink_freq = 2;
1831
1832 switch (state) {
1833 case ETHTOOL_ID_ACTIVE:
1834 pf->led_status = i40e_led_get(hw);
1835 return blink_freq;
1836 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001837 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001838 break;
1839 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001840 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001841 break;
1842 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001843 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001844 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001845 default:
1846 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001847 }
1848
1849 return 0;
1850}
1851
1852/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1853 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1854 * 125us (8000 interrupts per second) == ITR(62)
1855 */
1856
1857static int i40e_get_coalesce(struct net_device *netdev,
1858 struct ethtool_coalesce *ec)
1859{
1860 struct i40e_netdev_priv *np = netdev_priv(netdev);
1861 struct i40e_vsi *vsi = np->vsi;
1862
1863 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1864 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1865
1866 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001867 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001868
1869 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001870 ec->use_adaptive_tx_coalesce = 1;
1871
1872 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1873 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001874 /* we use the _usecs_high to store/set the interrupt rate limit
1875 * that the hardware supports, that almost but not quite
1876 * fits the original intent of the ethtool variable,
1877 * the rx_coalesce_usecs_high limits total interrupts
1878 * per second from both tx/rx sources.
1879 */
1880 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1881 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001882
1883 return 0;
1884}
1885
1886static int i40e_set_coalesce(struct net_device *netdev,
1887 struct ethtool_coalesce *ec)
1888{
1889 struct i40e_netdev_priv *np = netdev_priv(netdev);
1890 struct i40e_q_vector *q_vector;
1891 struct i40e_vsi *vsi = np->vsi;
1892 struct i40e_pf *pf = vsi->back;
1893 struct i40e_hw *hw = &pf->hw;
1894 u16 vector;
1895 int i;
1896
1897 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1898 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1899
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001900 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
1901 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
1902 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
1903 return -EINVAL;
1904 }
1905
1906 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
1907 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
1908 return -EINVAL;
1909 }
1910
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001911 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001912 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001913 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001914 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001915 } else if (ec->rx_coalesce_usecs == 0) {
1916 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001917 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001918 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 +00001919 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001920 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001921 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001922 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001923
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001924 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
1925
Mitch Williams32f5f542014-04-04 04:43:10 +00001926 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001927 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001928 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001929 } else if (ec->tx_coalesce_usecs == 0) {
1930 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001931 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001932 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 +00001933 } else {
1934 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001935 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001936 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001937 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001938
1939 if (ec->use_adaptive_rx_coalesce)
1940 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1941 else
1942 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1943
1944 if (ec->use_adaptive_tx_coalesce)
1945 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1946 else
1947 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948
Alexander Duyck493fb302013-09-28 07:01:44 +00001949 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001950 u16 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1951
Alexander Duyck493fb302013-09-28 07:01:44 +00001952 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1954 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1955 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1956 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001957 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001958 i40e_flush(hw);
1959 }
1960
1961 return 0;
1962}
1963
1964/**
1965 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1966 * @pf: pointer to the physical function struct
1967 * @cmd: ethtool rxnfc command
1968 *
1969 * Returns Success if the flow is supported, else Invalid Input.
1970 **/
1971static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1972{
1973 cmd->data = 0;
1974
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001975 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1976 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1977 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1978 return 0;
1979 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001980 /* Report default options for RSS on i40e */
1981 switch (cmd->flow_type) {
1982 case TCP_V4_FLOW:
1983 case UDP_V4_FLOW:
1984 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1985 /* fall through to add IP fields */
1986 case SCTP_V4_FLOW:
1987 case AH_ESP_V4_FLOW:
1988 case AH_V4_FLOW:
1989 case ESP_V4_FLOW:
1990 case IPV4_FLOW:
1991 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1992 break;
1993 case TCP_V6_FLOW:
1994 case UDP_V6_FLOW:
1995 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1996 /* fall through to add IP fields */
1997 case SCTP_V6_FLOW:
1998 case AH_ESP_V6_FLOW:
1999 case AH_V6_FLOW:
2000 case ESP_V6_FLOW:
2001 case IPV6_FLOW:
2002 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2003 break;
2004 default:
2005 return -EINVAL;
2006 }
2007
2008 return 0;
2009}
2010
2011/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002012 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2013 * @pf: Pointer to the physical function struct
2014 * @cmd: The command to get or set Rx flow classification rules
2015 * @rule_locs: Array of used rule locations
2016 *
2017 * This function populates both the total and actual rule count of
2018 * the ethtool flow classification command
2019 *
2020 * Returns 0 on success or -EMSGSIZE if entry not found
2021 **/
2022static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2023 struct ethtool_rxnfc *cmd,
2024 u32 *rule_locs)
2025{
2026 struct i40e_fdir_filter *rule;
2027 struct hlist_node *node2;
2028 int cnt = 0;
2029
2030 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002031 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002032
2033 hlist_for_each_entry_safe(rule, node2,
2034 &pf->fdir_filter_list, fdir_node) {
2035 if (cnt == cmd->rule_cnt)
2036 return -EMSGSIZE;
2037
2038 rule_locs[cnt] = rule->fd_id;
2039 cnt++;
2040 }
2041
2042 cmd->rule_cnt = cnt;
2043
2044 return 0;
2045}
2046
2047/**
2048 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2049 * @pf: Pointer to the physical function struct
2050 * @cmd: The command to get or set Rx flow classification rules
2051 *
2052 * This function looks up a filter based on the Rx flow classification
2053 * command and fills the flow spec info for it if found
2054 *
2055 * Returns 0 on success or -EINVAL if filter not found
2056 **/
2057static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2058 struct ethtool_rxnfc *cmd)
2059{
2060 struct ethtool_rx_flow_spec *fsp =
2061 (struct ethtool_rx_flow_spec *)&cmd->fs;
2062 struct i40e_fdir_filter *rule = NULL;
2063 struct hlist_node *node2;
2064
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002065 hlist_for_each_entry_safe(rule, node2,
2066 &pf->fdir_filter_list, fdir_node) {
2067 if (fsp->location <= rule->fd_id)
2068 break;
2069 }
2070
2071 if (!rule || fsp->location != rule->fd_id)
2072 return -EINVAL;
2073
2074 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002075 if (fsp->flow_type == IP_USER_FLOW) {
2076 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2077 fsp->h_u.usr_ip4_spec.proto = 0;
2078 fsp->m_u.usr_ip4_spec.proto = 0;
2079 }
2080
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002081 /* Reverse the src and dest notion, since the HW views them from
2082 * Tx perspective where as the user expects it from Rx filter view.
2083 */
2084 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2085 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2086 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2087 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002088
2089 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2090 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2091 else
2092 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002093
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002094 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2095 struct i40e_vsi *vsi;
2096
2097 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2098 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2099 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2100 fsp->m_ext.data[1] = htonl(0x1);
2101 }
2102 }
2103
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002104 return 0;
2105}
2106
2107/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002108 * i40e_get_rxnfc - command to get RX flow classification rules
2109 * @netdev: network interface device structure
2110 * @cmd: ethtool rxnfc command
2111 *
2112 * Returns Success if the command is supported.
2113 **/
2114static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2115 u32 *rule_locs)
2116{
2117 struct i40e_netdev_priv *np = netdev_priv(netdev);
2118 struct i40e_vsi *vsi = np->vsi;
2119 struct i40e_pf *pf = vsi->back;
2120 int ret = -EOPNOTSUPP;
2121
2122 switch (cmd->cmd) {
2123 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002124 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002125 ret = 0;
2126 break;
2127 case ETHTOOL_GRXFH:
2128 ret = i40e_get_rss_hash_opts(pf, cmd);
2129 break;
2130 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002131 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002132 /* report total rule count */
2133 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002134 ret = 0;
2135 break;
2136 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002137 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002138 break;
2139 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002140 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2141 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142 default:
2143 break;
2144 }
2145
2146 return ret;
2147}
2148
2149/**
2150 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2151 * @pf: pointer to the physical function struct
2152 * @cmd: ethtool rxnfc command
2153 *
2154 * Returns Success if the flow input set is supported.
2155 **/
2156static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2157{
2158 struct i40e_hw *hw = &pf->hw;
2159 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2160 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2161
2162 /* RSS does not support anything other than hashing
2163 * to queues on src and dst IPs and ports
2164 */
2165 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2166 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2167 return -EINVAL;
2168
2169 /* We need at least the IP SRC and DEST fields for hashing */
2170 if (!(nfc->data & RXH_IP_SRC) ||
2171 !(nfc->data & RXH_IP_DST))
2172 return -EINVAL;
2173
2174 switch (nfc->flow_type) {
2175 case TCP_V4_FLOW:
2176 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2177 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002178 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002179 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002180 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2181 hena |=
2182 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2183
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002184 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002185 break;
2186 default:
2187 return -EINVAL;
2188 }
2189 break;
2190 case TCP_V6_FLOW:
2191 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2192 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002193 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002194 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002195 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2196 hena |=
2197 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2198
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002199 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002200 break;
2201 default:
2202 return -EINVAL;
2203 }
2204 break;
2205 case UDP_V4_FLOW:
2206 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2207 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002208 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002209 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002210 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2211 hena |=
2212 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2213 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2214
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002215 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2216 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002217 break;
2218 default:
2219 return -EINVAL;
2220 }
2221 break;
2222 case UDP_V6_FLOW:
2223 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2224 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002225 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002226 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002227 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2228 hena |=
2229 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2230 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2231
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002232 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2233 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002234 break;
2235 default:
2236 return -EINVAL;
2237 }
2238 break;
2239 case AH_ESP_V4_FLOW:
2240 case AH_V4_FLOW:
2241 case ESP_V4_FLOW:
2242 case SCTP_V4_FLOW:
2243 if ((nfc->data & RXH_L4_B_0_1) ||
2244 (nfc->data & RXH_L4_B_2_3))
2245 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002246 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002247 break;
2248 case AH_ESP_V6_FLOW:
2249 case AH_V6_FLOW:
2250 case ESP_V6_FLOW:
2251 case SCTP_V6_FLOW:
2252 if ((nfc->data & RXH_L4_B_0_1) ||
2253 (nfc->data & RXH_L4_B_2_3))
2254 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002255 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002256 break;
2257 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002258 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2259 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002260 break;
2261 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002262 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2263 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002264 break;
2265 default:
2266 return -EINVAL;
2267 }
2268
2269 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2270 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2271 i40e_flush(hw);
2272
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002273 /* Save setting for future output/update */
2274 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2275
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002276 return 0;
2277}
2278
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002279/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002280 * i40e_match_fdir_input_set - Match a new filter against an existing one
2281 * @rule: The filter already added
2282 * @input: The new filter to comapre against
2283 *
2284 * Returns true if the two input set match
2285 **/
2286static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2287 struct i40e_fdir_filter *input)
2288{
2289 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2290 (rule->src_ip[0] != input->src_ip[0]) ||
2291 (rule->dst_port != input->dst_port) ||
2292 (rule->src_port != input->src_port))
2293 return false;
2294 return true;
2295}
2296
2297/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002298 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2299 * @vsi: Pointer to the targeted VSI
2300 * @input: The filter to update or NULL to indicate deletion
2301 * @sw_idx: Software index to the filter
2302 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002303 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002304 * This function updates (or deletes) a Flow Director entry from
2305 * the hlist of the corresponding PF
2306 *
2307 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002308 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002309static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2310 struct i40e_fdir_filter *input,
2311 u16 sw_idx,
2312 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002313{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002314 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002315 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002316 struct hlist_node *node2;
2317 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002318
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002319 parent = NULL;
2320 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002321
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002322 hlist_for_each_entry_safe(rule, node2,
2323 &pf->fdir_filter_list, fdir_node) {
2324 /* hash found, or no matching entry */
2325 if (rule->fd_id >= sw_idx)
2326 break;
2327 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002328 }
2329
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002330 /* if there is an old rule occupying our place remove it */
2331 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002332 if (input && !i40e_match_fdir_input_set(rule, input))
2333 err = i40e_add_del_fdir(vsi, rule, false);
2334 else if (!input)
2335 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002336 hlist_del(&rule->fdir_node);
2337 kfree(rule);
2338 pf->fdir_pf_active_filters--;
2339 }
2340
2341 /* If no input this was a delete, err should be 0 if a rule was
2342 * successfully found and removed from the list else -EINVAL
2343 */
2344 if (!input)
2345 return err;
2346
2347 /* initialize node and set software index */
2348 INIT_HLIST_NODE(&input->fdir_node);
2349
2350 /* add filter to the list */
2351 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002352 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002353 else
2354 hlist_add_head(&input->fdir_node,
2355 &pf->fdir_filter_list);
2356
2357 /* update counts */
2358 pf->fdir_pf_active_filters++;
2359
2360 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002361}
2362
2363/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002364 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2365 * @vsi: Pointer to the targeted VSI
2366 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002367 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002368 * The function removes a Flow Director filter entry from the
2369 * hlist of the corresponding PF
2370 *
2371 * Returns 0 on success
2372 */
2373static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2374 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002375{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002376 struct ethtool_rx_flow_spec *fsp =
2377 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002378 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002379 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002380
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002381 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2382 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2383 return -EBUSY;
2384
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002385 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2386 return -EBUSY;
2387
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002388 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002389
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002390 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002391 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002392}
2393
2394/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002395 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002396 * @vsi: pointer to the targeted VSI
2397 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002398 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002399 * Add Flow Director filters for a specific flow spec based on their
2400 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002401 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002402static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2403 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002404{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002405 struct ethtool_rx_flow_spec *fsp;
2406 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002407 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002408 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002409 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002410
2411 if (!vsi)
2412 return -EINVAL;
2413
2414 pf = vsi->back;
2415
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002416 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2417 return -EOPNOTSUPP;
2418
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002419 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002420 return -ENOSPC;
2421
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002422 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2423 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2424 return -EBUSY;
2425
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002426 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2427 return -EBUSY;
2428
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002429 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2430
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002431 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2432 pf->hw.func_caps.fd_filters_guaranteed)) {
2433 return -EINVAL;
2434 }
2435
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002436 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2437 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002438 return -EINVAL;
2439
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002440 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002441
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002442 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002443 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002444
2445 input->fd_id = fsp->location;
2446
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002447 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2448 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2449 else
2450 input->dest_ctl =
2451 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2452
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002453 input->q_index = fsp->ring_cookie;
2454 input->flex_off = 0;
2455 input->pctype = 0;
2456 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002457 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002458 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002459 input->flow_type = fsp->flow_type;
2460 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002461
2462 /* Reverse the src and dest notion, since the HW expects them to be from
2463 * Tx perspective where as the input from user is from Rx filter view.
2464 */
2465 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2466 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2467 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2468 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002469
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002470 if (ntohl(fsp->m_ext.data[1])) {
2471 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2472 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2473 goto free_input;
2474 }
2475 vf_id = ntohl(fsp->h_ext.data[1]);
2476 /* Find vsi id from vf id and override dest vsi */
2477 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2478 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2479 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2480 goto free_input;
2481 }
2482 }
2483
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002484 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002485free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002486 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002487 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002488 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002489 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002490
2491 return ret;
2492}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002493
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002494/**
2495 * i40e_set_rxnfc - command to set RX flow classification rules
2496 * @netdev: network interface device structure
2497 * @cmd: ethtool rxnfc command
2498 *
2499 * Returns Success if the command is supported.
2500 **/
2501static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2502{
2503 struct i40e_netdev_priv *np = netdev_priv(netdev);
2504 struct i40e_vsi *vsi = np->vsi;
2505 struct i40e_pf *pf = vsi->back;
2506 int ret = -EOPNOTSUPP;
2507
2508 switch (cmd->cmd) {
2509 case ETHTOOL_SRXFH:
2510 ret = i40e_set_rss_hash_opt(pf, cmd);
2511 break;
2512 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002513 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002514 break;
2515 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002516 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002517 break;
2518 default:
2519 break;
2520 }
2521
2522 return ret;
2523}
2524
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002525/**
2526 * i40e_max_channels - get Max number of combined channels supported
2527 * @vsi: vsi pointer
2528 **/
2529static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2530{
2531 /* TODO: This code assumes DCB and FD is disabled for now. */
2532 return vsi->alloc_queue_pairs;
2533}
2534
2535/**
2536 * i40e_get_channels - Get the current channels enabled and max supported etc.
2537 * @netdev: network interface device structure
2538 * @ch: ethtool channels structure
2539 *
2540 * We don't support separate tx and rx queues as channels. The other count
2541 * represents how many queues are being used for control. max_combined counts
2542 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2543 * q_vectors since we support a lot more queue pairs than q_vectors.
2544 **/
2545static void i40e_get_channels(struct net_device *dev,
2546 struct ethtool_channels *ch)
2547{
2548 struct i40e_netdev_priv *np = netdev_priv(dev);
2549 struct i40e_vsi *vsi = np->vsi;
2550 struct i40e_pf *pf = vsi->back;
2551
2552 /* report maximum channels */
2553 ch->max_combined = i40e_max_channels(vsi);
2554
2555 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002556 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002557 ch->max_other = ch->other_count;
2558
2559 /* Note: This code assumes DCB is disabled for now. */
2560 ch->combined_count = vsi->num_queue_pairs;
2561}
2562
2563/**
2564 * i40e_set_channels - Set the new channels count.
2565 * @netdev: network interface device structure
2566 * @ch: ethtool channels structure
2567 *
2568 * The new channels count may not be the same as requested by the user
2569 * since it gets rounded down to a power of 2 value.
2570 **/
2571static int i40e_set_channels(struct net_device *dev,
2572 struct ethtool_channels *ch)
2573{
2574 struct i40e_netdev_priv *np = netdev_priv(dev);
2575 unsigned int count = ch->combined_count;
2576 struct i40e_vsi *vsi = np->vsi;
2577 struct i40e_pf *pf = vsi->back;
2578 int new_count;
2579
2580 /* We do not support setting channels for any other VSI at present */
2581 if (vsi->type != I40E_VSI_MAIN)
2582 return -EINVAL;
2583
2584 /* verify they are not requesting separate vectors */
2585 if (!count || ch->rx_count || ch->tx_count)
2586 return -EINVAL;
2587
2588 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002589 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002590 return -EINVAL;
2591
2592 /* verify the number of channels does not exceed hardware limits */
2593 if (count > i40e_max_channels(vsi))
2594 return -EINVAL;
2595
2596 /* update feature limits from largest to smallest supported values */
2597 /* TODO: Flow director limit, DCB etc */
2598
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002599 /* use rss_reconfig to rebuild with new queue count and update traffic
2600 * class queue mapping
2601 */
2602 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002603 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002604 return 0;
2605 else
2606 return -EINVAL;
2607}
2608
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002609/**
2610 * i40e_get_rxfh_key_size - get the RSS hash key size
2611 * @netdev: network interface device structure
2612 *
2613 * Returns the table size.
2614 **/
2615static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2616{
2617 return I40E_HKEY_ARRAY_SIZE;
2618}
2619
2620/**
2621 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2622 * @netdev: network interface device structure
2623 *
2624 * Returns the table size.
2625 **/
2626static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2627{
2628 return I40E_HLUT_ARRAY_SIZE;
2629}
2630
2631static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2632 u8 *hfunc)
2633{
2634 struct i40e_netdev_priv *np = netdev_priv(netdev);
2635 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002636 u8 *lut, *seed = NULL;
2637 int ret;
2638 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002639
2640 if (hfunc)
2641 *hfunc = ETH_RSS_HASH_TOP;
2642
2643 if (!indir)
2644 return 0;
2645
Helin Zhang043dd652015-10-21 19:56:23 -04002646 seed = key;
2647 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2648 if (!lut)
2649 return -ENOMEM;
2650 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2651 if (ret)
2652 goto out;
2653 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2654 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002655
Helin Zhang043dd652015-10-21 19:56:23 -04002656out:
2657 kfree(lut);
2658
2659 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002660}
2661
2662/**
2663 * i40e_set_rxfh - set the rx flow hash indirection table
2664 * @netdev: network interface device structure
2665 * @indir: indirection table
2666 * @key: hash key
2667 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002668 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002669 * returns 0 after programming the table.
2670 **/
2671static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2672 const u8 *key, const u8 hfunc)
2673{
2674 struct i40e_netdev_priv *np = netdev_priv(netdev);
2675 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002676 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002677 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002678
2679 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2680 return -EOPNOTSUPP;
2681
2682 if (!indir)
2683 return 0;
2684
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002685 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002686 if (!vsi->rss_hkey_user) {
2687 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2688 GFP_KERNEL);
2689 if (!vsi->rss_hkey_user)
2690 return -ENOMEM;
2691 }
2692 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2693 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002694 }
Helin Zhang28c58692015-10-26 19:44:27 -04002695 if (!vsi->rss_lut_user) {
2696 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2697 if (!vsi->rss_lut_user)
2698 return -ENOMEM;
2699 }
Helin Zhang043dd652015-10-21 19:56:23 -04002700
Helin Zhang28c58692015-10-26 19:44:27 -04002701 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2702 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2703 vsi->rss_lut_user[i] = (u8)(indir[i]);
2704
2705 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2706 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002707}
2708
Greg Rose7e45ab42015-02-06 08:52:19 +00002709/**
2710 * i40e_get_priv_flags - report device private flags
2711 * @dev: network interface device structure
2712 *
2713 * The get string set count and the string set should be matched for each
2714 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2715 * array.
2716 *
2717 * Returns a u32 bitmap of flags.
2718 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002719static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002720{
2721 struct i40e_netdev_priv *np = netdev_priv(dev);
2722 struct i40e_vsi *vsi = np->vsi;
2723 struct i40e_pf *pf = vsi->back;
2724 u32 ret_flags = 0;
2725
2726 ret_flags |= pf->hw.func_caps.npar_enable ?
2727 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002728 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2729 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002730 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2731 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002732 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2733 I40E_PRIV_FLAGS_VEB_STATS : 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002734 ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
2735 I40E_PRIV_FLAGS_PS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002736 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
2737 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Greg Rose7e45ab42015-02-06 08:52:19 +00002738
2739 return ret_flags;
2740}
2741
Shannon Nelson9ac77262015-08-27 11:42:40 -04002742/**
2743 * i40e_set_priv_flags - set private flags
2744 * @dev: network interface device structure
2745 * @flags: bit flags to be set
2746 **/
2747static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2748{
2749 struct i40e_netdev_priv *np = netdev_priv(dev);
2750 struct i40e_vsi *vsi = np->vsi;
2751 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002752 bool reset_required = false;
2753
2754 /* NOTE: MFP is not settable */
2755
2756 /* allow the user to control the method of receive
2757 * buffer DMA, whether the packet is split at header
2758 * boundaries into two separate buffers. In some cases
2759 * one routine or the other will perform better.
2760 */
2761 if ((flags & I40E_PRIV_FLAGS_PS) &&
2762 !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2763 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
2764 pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
2765 reset_required = true;
2766 } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
2767 (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2768 pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
2769 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
2770 reset_required = true;
2771 }
Shannon Nelson9ac77262015-08-27 11:42:40 -04002772
2773 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2774 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2775 else
2776 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2777
Jesse Brandeburgef171782015-09-03 17:18:49 -04002778 /* allow the user to control the state of the Flow
2779 * Director ATR (Application Targeted Routing) feature
2780 * of the driver
2781 */
2782 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2783 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2784 } else {
2785 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2786 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2787 }
2788
Shannon Nelson66fc3602016-01-13 16:51:42 -08002789 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2790 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002791 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002792 reset_required = true;
2793 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2794 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002795 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002796 reset_required = true;
2797 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002798
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002799 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
2800 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
2801 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2802 else
2803 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2804
Jesse Brandeburg827de392015-11-06 15:26:07 -08002805 /* if needed, issue reset to cause things to take effect */
2806 if (reset_required)
2807 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2808
Shannon Nelson9ac77262015-08-27 11:42:40 -04002809 return 0;
2810}
2811
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002812static const struct ethtool_ops i40e_ethtool_ops = {
2813 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002814 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002815 .get_drvinfo = i40e_get_drvinfo,
2816 .get_regs_len = i40e_get_regs_len,
2817 .get_regs = i40e_get_regs,
2818 .nway_reset = i40e_nway_reset,
2819 .get_link = ethtool_op_get_link,
2820 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002821 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002822 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002823 .get_eeprom_len = i40e_get_eeprom_len,
2824 .get_eeprom = i40e_get_eeprom,
2825 .get_ringparam = i40e_get_ringparam,
2826 .set_ringparam = i40e_set_ringparam,
2827 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002828 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002829 .get_msglevel = i40e_get_msglevel,
2830 .set_msglevel = i40e_set_msglevel,
2831 .get_rxnfc = i40e_get_rxnfc,
2832 .set_rxnfc = i40e_set_rxnfc,
2833 .self_test = i40e_diag_test,
2834 .get_strings = i40e_get_strings,
2835 .set_phys_id = i40e_set_phys_id,
2836 .get_sset_count = i40e_get_sset_count,
2837 .get_ethtool_stats = i40e_get_ethtool_stats,
2838 .get_coalesce = i40e_get_coalesce,
2839 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002840 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2841 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2842 .get_rxfh = i40e_get_rxfh,
2843 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002844 .get_channels = i40e_get_channels,
2845 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002846 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002847 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002848 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002849};
2850
2851void i40e_set_ethtool_ops(struct net_device *netdev)
2852{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002853 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002854}