blob: 8a83d45148124d12db9ada6bf0164300d338dd2e [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;
Avinash Dayanand16badc32016-03-18 12:18:13 -0700316 /* adding 100baseT support for 10GBASET_PHY */
317 if (pf->flags & I40E_FLAG_HAVE_10GBASET_PHY) {
318 ecmd->supported |= SUPPORTED_100baseT_Full;
319 ecmd->advertising |= ADVERTISED_100baseT_Full |
320 ADVERTISED_1000baseT_Full |
321 ADVERTISED_10000baseT_Full;
322 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400323 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400324 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
325 ecmd->supported = SUPPORTED_Autoneg |
326 SUPPORTED_1000baseT_Full;
327 ecmd->advertising = ADVERTISED_Autoneg |
328 ADVERTISED_1000baseT_Full;
329 break;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400330 case I40E_PHY_TYPE_100BASE_TX:
331 ecmd->supported = SUPPORTED_Autoneg |
332 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000333 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
334 ecmd->advertising |= ADVERTISED_100baseT_Full;
Avinash Dayanand16badc32016-03-18 12:18:13 -0700335 /* firmware detects 10G phy as 100M phy at 100M speed */
336 if (pf->flags & I40E_FLAG_HAVE_10GBASET_PHY) {
337 ecmd->supported |= SUPPORTED_10000baseT_Full |
338 SUPPORTED_1000baseT_Full;
339 ecmd->advertising |= ADVERTISED_Autoneg |
340 ADVERTISED_100baseT_Full |
341 ADVERTISED_1000baseT_Full |
342 ADVERTISED_10000baseT_Full;
343 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000344 break;
345 case I40E_PHY_TYPE_10GBASE_CR1_CU:
346 case I40E_PHY_TYPE_10GBASE_CR1:
347 ecmd->supported = SUPPORTED_Autoneg |
348 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000349 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000350 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000351 break;
352 case I40E_PHY_TYPE_XAUI:
353 case I40E_PHY_TYPE_XFI:
354 case I40E_PHY_TYPE_SFI:
355 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000356 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000357 ecmd->supported = SUPPORTED_10000baseT_Full;
358 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000359 case I40E_PHY_TYPE_SGMII:
360 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400361 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000362 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
363 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800364 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400365 ecmd->supported |= SUPPORTED_100baseT_Full;
366 if (hw_link_info->requested_speeds &
367 I40E_LINK_SPEED_100MB)
368 ecmd->advertising |= ADVERTISED_100baseT_Full;
369 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000370 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400371 /* Backplane is set based on supported phy types in get_settings
372 * so don't set anything here but don't warn either
373 */
374 case I40E_PHY_TYPE_40GBASE_KR4:
375 case I40E_PHY_TYPE_20GBASE_KR2:
376 case I40E_PHY_TYPE_10GBASE_KR:
377 case I40E_PHY_TYPE_10GBASE_KX4:
378 case I40E_PHY_TYPE_1000BASE_KX:
379 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000381 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000382 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
383 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000384 }
385
Catherine Sullivane8278452015-02-06 08:52:08 +0000386 /* Set speed and duplex */
387 switch (link_speed) {
388 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400389 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000390 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700391 case I40E_LINK_SPEED_20GB:
392 ethtool_cmd_speed_set(ecmd, SPEED_20000);
393 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000394 case I40E_LINK_SPEED_10GB:
395 ethtool_cmd_speed_set(ecmd, SPEED_10000);
396 break;
397 case I40E_LINK_SPEED_1GB:
398 ethtool_cmd_speed_set(ecmd, SPEED_1000);
399 break;
400 case I40E_LINK_SPEED_100MB:
401 ethtool_cmd_speed_set(ecmd, SPEED_100);
402 break;
403 default:
404 break;
405 }
406 ecmd->duplex = DUPLEX_FULL;
407}
408
409/**
410 * i40e_get_settings_link_down - Get the Link settings for when link is down
411 * @hw: hw structure
412 * @ecmd: ethtool command to fill in
413 *
414 * Reports link settings that can be determined when link is down
415 **/
416static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400417 struct ethtool_cmd *ecmd,
418 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000419{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400420 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000421
422 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400423 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000424 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400425 ecmd->supported = 0x0;
426 ecmd->advertising = 0x0;
427 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
428 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400429 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400430 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400431 ADVERTISED_1000baseT_Full;
432 if (pf->hw.mac.type == I40E_MAC_X722) {
433 ecmd->supported |= SUPPORTED_100baseT_Full;
434 ecmd->advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivanf8db54cc2015-12-22 14:25:14 -0800435 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
436 ecmd->supported |= SUPPORTED_100baseT_Full;
437 ecmd->advertising |= ADVERTISED_100baseT_Full;
438 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400439 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000440 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400441 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
442 phy_types & I40E_CAP_PHY_TYPE_XFI ||
443 phy_types & I40E_CAP_PHY_TYPE_SFI ||
444 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
445 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
446 ecmd->supported |= SUPPORTED_10000baseT_Full;
447 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
448 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
449 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
450 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
451 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
452 ecmd->supported |= SUPPORTED_Autoneg |
453 SUPPORTED_10000baseT_Full;
454 ecmd->advertising |= ADVERTISED_Autoneg |
455 ADVERTISED_10000baseT_Full;
456 }
457 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
458 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
459 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
460 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
461 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
462 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
463 ecmd->supported |= SUPPORTED_Autoneg |
464 SUPPORTED_40000baseCR4_Full;
465 ecmd->advertising |= ADVERTISED_Autoneg |
466 ADVERTISED_40000baseCR4_Full;
467 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400468 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
469 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400470 ecmd->supported |= SUPPORTED_Autoneg |
471 SUPPORTED_100baseT_Full;
472 ecmd->advertising |= ADVERTISED_Autoneg |
473 ADVERTISED_100baseT_Full;
474 }
475 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
476 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
477 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
478 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
479 ecmd->supported |= SUPPORTED_Autoneg |
480 SUPPORTED_1000baseT_Full;
481 ecmd->advertising |= ADVERTISED_Autoneg |
482 ADVERTISED_1000baseT_Full;
483 }
484 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
485 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
486 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
487 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000488
489 /* With no link speed and duplex are unknown */
490 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
491 ecmd->duplex = DUPLEX_UNKNOWN;
492}
493
494/**
495 * i40e_get_settings - Get Link Speed and Duplex settings
496 * @netdev: network interface device structure
497 * @ecmd: ethtool command
498 *
499 * Reports speed/duplex settings based on media_type
500 **/
501static int i40e_get_settings(struct net_device *netdev,
502 struct ethtool_cmd *ecmd)
503{
504 struct i40e_netdev_priv *np = netdev_priv(netdev);
505 struct i40e_pf *pf = np->vsi->back;
506 struct i40e_hw *hw = &pf->hw;
507 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
508 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
509
510 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400511 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000512 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400513 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000514
515 /* Now set the settings that don't rely on link being up/down */
516
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400517 /* For backplane, supported and advertised are only reliant on the
518 * phy types the NVM specifies are supported.
519 */
520 if (hw->device_id == I40E_DEV_ID_KX_B ||
521 hw->device_id == I40E_DEV_ID_KX_C ||
522 hw->device_id == I40E_DEV_ID_20G_KR2 ||
523 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
524 ecmd->supported = SUPPORTED_Autoneg;
525 ecmd->advertising = ADVERTISED_Autoneg;
526 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
527 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
528 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
529 }
530 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
531 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
532 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
533 }
534 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
535 ecmd->supported |= SUPPORTED_10000baseKR_Full;
536 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
537 }
538 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
539 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
540 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
541 }
542 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
543 ecmd->supported |= SUPPORTED_1000baseKX_Full;
544 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
545 }
546 }
547
Catherine Sullivane8278452015-02-06 08:52:08 +0000548 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000549 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
550 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000551
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000552 switch (hw->phy.media_type) {
553 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000554 ecmd->supported |= SUPPORTED_Autoneg |
555 SUPPORTED_Backplane;
556 ecmd->advertising |= ADVERTISED_Autoneg |
557 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000558 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000559 break;
560 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000561 ecmd->supported |= SUPPORTED_TP;
562 ecmd->advertising |= ADVERTISED_TP;
563 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000564 break;
565 case I40E_MEDIA_TYPE_DA:
566 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000567 ecmd->supported |= SUPPORTED_FIBRE;
568 ecmd->advertising |= ADVERTISED_FIBRE;
569 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000570 break;
571 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000572 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000573 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000574 break;
575 case I40E_MEDIA_TYPE_UNKNOWN:
576 default:
577 ecmd->port = PORT_OTHER;
578 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000579 }
580
Catherine Sullivane8278452015-02-06 08:52:08 +0000581 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000582 ecmd->transceiver = XCVR_EXTERNAL;
583
Catherine Sullivane8278452015-02-06 08:52:08 +0000584 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000585 ecmd->supported |= SUPPORTED_Pause;
586
Catherine Sullivane8278452015-02-06 08:52:08 +0000587 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000588 case I40E_FC_FULL:
589 ecmd->advertising |= ADVERTISED_Pause;
590 break;
591 case I40E_FC_TX_PAUSE:
592 ecmd->advertising |= ADVERTISED_Asym_Pause;
593 break;
594 case I40E_FC_RX_PAUSE:
595 ecmd->advertising |= (ADVERTISED_Pause |
596 ADVERTISED_Asym_Pause);
597 break;
598 default:
599 ecmd->advertising &= ~(ADVERTISED_Pause |
600 ADVERTISED_Asym_Pause);
601 break;
602 }
603
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000604 return 0;
605}
606
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000607/**
608 * i40e_set_settings - Set Speed and Duplex
609 * @netdev: network interface device structure
610 * @ecmd: ethtool command
611 *
612 * Set speed/duplex per media_types advertised/forced
613 **/
614static int i40e_set_settings(struct net_device *netdev,
615 struct ethtool_cmd *ecmd)
616{
617 struct i40e_netdev_priv *np = netdev_priv(netdev);
618 struct i40e_aq_get_phy_abilities_resp abilities;
619 struct i40e_aq_set_phy_config config;
620 struct i40e_pf *pf = np->vsi->back;
621 struct i40e_vsi *vsi = np->vsi;
622 struct i40e_hw *hw = &pf->hw;
623 struct ethtool_cmd safe_ecmd;
624 i40e_status status = 0;
625 bool change = false;
626 int err = 0;
627 u8 autoneg;
628 u32 advertise;
629
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000630 /* Changing port settings is not supported if this isn't the
631 * port's controlling PF
632 */
633 if (hw->partition_id != 1) {
634 i40e_partition_setting_complaint(pf);
635 return -EOPNOTSUPP;
636 }
637
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000638 if (vsi != pf->vsi[pf->lan_vsi])
639 return -EOPNOTSUPP;
640
641 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
642 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000643 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
644 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000645 return -EOPNOTSUPP;
646
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400647 if (hw->device_id == I40E_DEV_ID_KX_B ||
648 hw->device_id == I40E_DEV_ID_KX_C ||
649 hw->device_id == I40E_DEV_ID_20G_KR2 ||
650 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
651 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
652 return -EOPNOTSUPP;
653 }
654
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000655 /* get our own copy of the bits to check against */
656 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
657 i40e_get_settings(netdev, &safe_ecmd);
658
659 /* save autoneg and speed out of ecmd */
660 autoneg = ecmd->autoneg;
661 advertise = ecmd->advertising;
662
663 /* set autoneg and speed back to what they currently are */
664 ecmd->autoneg = safe_ecmd.autoneg;
665 ecmd->advertising = safe_ecmd.advertising;
666
667 ecmd->cmd = safe_ecmd.cmd;
668 /* If ecmd and safe_ecmd are not the same now, then they are
669 * trying to set something that we do not support
670 */
671 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
672 return -EOPNOTSUPP;
673
674 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
675 usleep_range(1000, 2000);
676
677 /* Get the current phy config */
678 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
679 NULL);
680 if (status)
681 return -EAGAIN;
682
Catherine Sullivan124ed152014-07-12 07:28:12 +0000683 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000684 * set below
685 */
686 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000687 config.abilities = abilities.abilities;
688
689 /* Check autoneg */
690 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000691 /* If autoneg was not already enabled */
692 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400693 /* If autoneg is not supported, return error */
694 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
695 netdev_info(netdev, "Autoneg not supported on this phy\n");
696 return -EINVAL;
697 }
698 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000699 config.abilities = abilities.abilities |
700 I40E_AQ_PHY_ENABLE_AN;
701 change = true;
702 }
703 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000704 /* If autoneg is currently enabled */
705 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400706 /* If autoneg is supported 10GBASE_T is the only PHY
707 * that can disable it, so otherwise return error
708 */
709 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
710 hw->phy.link_info.phy_type !=
711 I40E_PHY_TYPE_10GBASE_T) {
712 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
713 return -EINVAL;
714 }
715 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000716 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000717 ~I40E_AQ_PHY_ENABLE_AN;
718 change = true;
719 }
720 }
721
722 if (advertise & ~safe_ecmd.supported)
723 return -EINVAL;
724
725 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000726 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000727 if (advertise & ADVERTISED_1000baseT_Full ||
728 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000729 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000730 if (advertise & ADVERTISED_10000baseT_Full ||
731 advertise & ADVERTISED_10000baseKX4_Full ||
732 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000733 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700734 if (advertise & ADVERTISED_20000baseKR2_Full)
735 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000736 if (advertise & ADVERTISED_40000baseKR4_Full ||
737 advertise & ADVERTISED_40000baseCR4_Full ||
738 advertise & ADVERTISED_40000baseSR4_Full ||
739 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000740 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000741
Catherine Sullivan0002e112015-08-26 15:14:16 -0400742 /* If speed didn't get set, set it to what it currently is.
743 * This is needed because if advertise is 0 (as it is when autoneg
744 * is disabled) then speed won't get set.
745 */
746 if (!config.link_speed)
747 config.link_speed = abilities.link_speed;
748
Catherine Sullivan124ed152014-07-12 07:28:12 +0000749 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750 /* copy over the rest of the abilities */
751 config.phy_type = abilities.phy_type;
752 config.eee_capability = abilities.eee_capability;
753 config.eeer = abilities.eeer_val;
754 config.low_power_ctrl = abilities.d3_lpan;
755
Catherine Sullivane8278452015-02-06 08:52:08 +0000756 /* save the requested speeds */
757 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000758 /* set link and auto negotiation so changes take effect */
759 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
760 /* If link is up put link down */
761 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
762 /* Tell the OS link is going down, the link will go
763 * back up when fw says it is ready asynchronously
764 */
Matt Jaredc156f852015-08-27 11:42:39 -0400765 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000766 netif_carrier_off(netdev);
767 netif_tx_stop_all_queues(netdev);
768 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000769
770 /* make the aq call */
771 status = i40e_aq_set_phy_config(hw, &config, NULL);
772 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400773 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
774 i40e_stat_str(hw, status),
775 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000776 return -EAGAIN;
777 }
778
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400779 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000780 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400781 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
782 i40e_stat_str(hw, status),
783 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000784
785 } else {
786 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
787 }
788
789 return err;
790}
791
Jesse Brandeburga6599722014-06-04 08:45:25 +0000792static int i40e_nway_reset(struct net_device *netdev)
793{
794 /* restart autonegotiation */
795 struct i40e_netdev_priv *np = netdev_priv(netdev);
796 struct i40e_pf *pf = np->vsi->back;
797 struct i40e_hw *hw = &pf->hw;
798 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
799 i40e_status ret = 0;
800
801 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
802 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400803 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
804 i40e_stat_str(hw, ret),
805 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000806 return -EIO;
807 }
808
809 return 0;
810}
811
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000812/**
813 * i40e_get_pauseparam - Get Flow Control status
814 * Return tx/rx-pause status
815 **/
816static void i40e_get_pauseparam(struct net_device *netdev,
817 struct ethtool_pauseparam *pause)
818{
819 struct i40e_netdev_priv *np = netdev_priv(netdev);
820 struct i40e_pf *pf = np->vsi->back;
821 struct i40e_hw *hw = &pf->hw;
822 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000823 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000824
825 pause->autoneg =
826 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
827 AUTONEG_ENABLE : AUTONEG_DISABLE);
828
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000829 /* PFC enabled so report LFC as off */
830 if (dcbx_cfg->pfc.pfcenable) {
831 pause->rx_pause = 0;
832 pause->tx_pause = 0;
833 return;
834 }
835
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000836 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000837 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000838 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000839 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000840 } else if (hw->fc.current_mode == I40E_FC_FULL) {
841 pause->rx_pause = 1;
842 pause->tx_pause = 1;
843 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000844}
845
Catherine Sullivan2becc352014-06-04 08:45:27 +0000846/**
847 * i40e_set_pauseparam - Set Flow Control parameter
848 * @netdev: network interface device structure
849 * @pause: return tx/rx flow control status
850 **/
851static int i40e_set_pauseparam(struct net_device *netdev,
852 struct ethtool_pauseparam *pause)
853{
854 struct i40e_netdev_priv *np = netdev_priv(netdev);
855 struct i40e_pf *pf = np->vsi->back;
856 struct i40e_vsi *vsi = np->vsi;
857 struct i40e_hw *hw = &pf->hw;
858 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000859 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000860 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
861 i40e_status status;
862 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000863 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000864
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000865 /* Changing the port's flow control is not supported if this isn't the
866 * port's controlling PF
867 */
868 if (hw->partition_id != 1) {
869 i40e_partition_setting_complaint(pf);
870 return -EOPNOTSUPP;
871 }
872
Catherine Sullivan2becc352014-06-04 08:45:27 +0000873 if (vsi != pf->vsi[pf->lan_vsi])
874 return -EOPNOTSUPP;
875
876 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
877 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
878 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
879 return -EOPNOTSUPP;
880 }
881
882 /* If we have link and don't have autoneg */
883 if (!test_bit(__I40E_DOWN, &pf->state) &&
884 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
885 /* Send message that it might not necessarily work*/
886 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
887 }
888
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000889 if (dcbx_cfg->pfc.pfcenable) {
890 netdev_info(netdev,
891 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000892 return -EOPNOTSUPP;
893 }
894
895 if (pause->rx_pause && pause->tx_pause)
896 hw->fc.requested_mode = I40E_FC_FULL;
897 else if (pause->rx_pause && !pause->tx_pause)
898 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
899 else if (!pause->rx_pause && pause->tx_pause)
900 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
901 else if (!pause->rx_pause && !pause->tx_pause)
902 hw->fc.requested_mode = I40E_FC_NONE;
903 else
904 return -EINVAL;
905
Catherine Sullivan94128512014-07-12 07:28:16 +0000906 /* Tell the OS link is going down, the link will go back up when fw
907 * says it is ready asynchronously
908 */
Matt Jaredc156f852015-08-27 11:42:39 -0400909 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000910 netif_carrier_off(netdev);
911 netif_tx_stop_all_queues(netdev);
912
Catherine Sullivan2becc352014-06-04 08:45:27 +0000913 /* Set the fc mode and only restart an if link is up*/
914 status = i40e_set_fc(hw, &aq_failures, link_up);
915
916 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400917 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
918 i40e_stat_str(hw, status),
919 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000920 err = -EAGAIN;
921 }
922 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400923 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
924 i40e_stat_str(hw, status),
925 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000926 err = -EAGAIN;
927 }
928 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400929 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
930 i40e_stat_str(hw, status),
931 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000932 err = -EAGAIN;
933 }
934
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000935 if (!test_bit(__I40E_DOWN, &pf->state)) {
936 /* Give it a little more time to try to come back */
937 msleep(75);
938 if (!test_bit(__I40E_DOWN, &pf->state))
939 return i40e_nway_reset(netdev);
940 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000941
942 return err;
943}
944
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000945static u32 i40e_get_msglevel(struct net_device *netdev)
946{
947 struct i40e_netdev_priv *np = netdev_priv(netdev);
948 struct i40e_pf *pf = np->vsi->back;
949
950 return pf->msg_enable;
951}
952
953static void i40e_set_msglevel(struct net_device *netdev, u32 data)
954{
955 struct i40e_netdev_priv *np = netdev_priv(netdev);
956 struct i40e_pf *pf = np->vsi->back;
957
958 if (I40E_DEBUG_USER & data)
959 pf->hw.debug_mask = data;
960 pf->msg_enable = data;
961}
962
963static int i40e_get_regs_len(struct net_device *netdev)
964{
965 int reg_count = 0;
966 int i;
967
968 for (i = 0; i40e_reg_list[i].offset != 0; i++)
969 reg_count += i40e_reg_list[i].elements;
970
971 return reg_count * sizeof(u32);
972}
973
974static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
975 void *p)
976{
977 struct i40e_netdev_priv *np = netdev_priv(netdev);
978 struct i40e_pf *pf = np->vsi->back;
979 struct i40e_hw *hw = &pf->hw;
980 u32 *reg_buf = p;
981 int i, j, ri;
982 u32 reg;
983
984 /* Tell ethtool which driver-version-specific regs output we have.
985 *
986 * At some point, if we have ethtool doing special formatting of
987 * this data, it will rely on this version number to know how to
988 * interpret things. Hence, this needs to be updated if/when the
989 * diags register table is changed.
990 */
991 regs->version = 1;
992
993 /* loop through the diags reg table for what to print */
994 ri = 0;
995 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
996 for (j = 0; j < i40e_reg_list[i].elements; j++) {
997 reg = i40e_reg_list[i].offset
998 + (j * i40e_reg_list[i].stride);
999 reg_buf[ri++] = rd32(hw, reg);
1000 }
1001 }
1002
1003}
1004
1005static int i40e_get_eeprom(struct net_device *netdev,
1006 struct ethtool_eeprom *eeprom, u8 *bytes)
1007{
1008 struct i40e_netdev_priv *np = netdev_priv(netdev);
1009 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001010 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001011 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001012 u8 *eeprom_buff;
1013 u16 i, sectors;
1014 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001015 u32 magic;
1016
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001017#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001018 if (eeprom->len == 0)
1019 return -EINVAL;
1020
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001021 /* check for NVMUpdate access method */
1022 magic = hw->vendor_id | (hw->device_id << 16);
1023 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001024 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1025 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001026
1027 /* make sure it is the right magic for NVMUpdate */
1028 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001029 errno = -EINVAL;
1030 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1031 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1032 errno = -EBUSY;
1033 else
1034 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001035
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001036 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001037 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001038 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1039 ret_val, hw->aq.asq_last_status, errno,
1040 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1041 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001042
1043 return errno;
1044 }
1045
1046 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001047 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1048
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001049 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001050 if (!eeprom_buff)
1051 return -ENOMEM;
1052
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001053 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1054 if (ret_val) {
1055 dev_info(&pf->pdev->dev,
1056 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1057 ret_val, hw->aq.asq_last_status);
1058 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001059 }
1060
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001061 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1062 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1063 len = I40E_NVM_SECTOR_SIZE;
1064 last = false;
1065 for (i = 0; i < sectors; i++) {
1066 if (i == (sectors - 1)) {
1067 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1068 last = true;
1069 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001070 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1071 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001072 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001073 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001074 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001075 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001076 "read NVM failed, invalid offset 0x%x\n",
1077 offset);
1078 break;
1079 } else if (ret_val &&
1080 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1081 dev_info(&pf->pdev->dev,
1082 "read NVM failed, access, offset 0x%x\n",
1083 offset);
1084 break;
1085 } else if (ret_val) {
1086 dev_info(&pf->pdev->dev,
1087 "read NVM failed offset %d err=%d status=0x%x\n",
1088 offset, ret_val, hw->aq.asq_last_status);
1089 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001090 }
1091 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001092
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001093 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001094 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001095free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001096 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001097 return ret_val;
1098}
1099
1100static int i40e_get_eeprom_len(struct net_device *netdev)
1101{
1102 struct i40e_netdev_priv *np = netdev_priv(netdev);
1103 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001104 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001105
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001106 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1107 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1108 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1109 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001110 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001111 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001112}
1113
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001114static int i40e_set_eeprom(struct net_device *netdev,
1115 struct ethtool_eeprom *eeprom, u8 *bytes)
1116{
1117 struct i40e_netdev_priv *np = netdev_priv(netdev);
1118 struct i40e_hw *hw = &np->vsi->back->hw;
1119 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001120 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001121 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001122 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001123 u32 magic;
1124
1125 /* normal ethtool set_eeprom is not supported */
1126 magic = hw->vendor_id | (hw->device_id << 16);
1127 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001128 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001129 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001130 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1131 errno = -EINVAL;
1132 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1133 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1134 errno = -EBUSY;
1135 else
1136 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001137
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001138 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001139 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001140 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1141 ret_val, hw->aq.asq_last_status, errno,
1142 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1143 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001144
1145 return errno;
1146}
1147
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001148static void i40e_get_drvinfo(struct net_device *netdev,
1149 struct ethtool_drvinfo *drvinfo)
1150{
1151 struct i40e_netdev_priv *np = netdev_priv(netdev);
1152 struct i40e_vsi *vsi = np->vsi;
1153 struct i40e_pf *pf = vsi->back;
1154
1155 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1156 strlcpy(drvinfo->version, i40e_driver_version_str,
1157 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001158 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001159 sizeof(drvinfo->fw_version));
1160 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1161 sizeof(drvinfo->bus_info));
1162}
1163
1164static void i40e_get_ringparam(struct net_device *netdev,
1165 struct ethtool_ringparam *ring)
1166{
1167 struct i40e_netdev_priv *np = netdev_priv(netdev);
1168 struct i40e_pf *pf = np->vsi->back;
1169 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1170
1171 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1172 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1173 ring->rx_mini_max_pending = 0;
1174 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001175 ring->rx_pending = vsi->rx_rings[0]->count;
1176 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001177 ring->rx_mini_pending = 0;
1178 ring->rx_jumbo_pending = 0;
1179}
1180
1181static int i40e_set_ringparam(struct net_device *netdev,
1182 struct ethtool_ringparam *ring)
1183{
1184 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1185 struct i40e_netdev_priv *np = netdev_priv(netdev);
1186 struct i40e_vsi *vsi = np->vsi;
1187 struct i40e_pf *pf = vsi->back;
1188 u32 new_rx_count, new_tx_count;
1189 int i, err = 0;
1190
1191 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1192 return -EINVAL;
1193
Shannon Nelson1fa18372013-11-20 10:03:08 +00001194 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1195 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1196 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1197 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1198 netdev_info(netdev,
1199 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1200 ring->tx_pending, ring->rx_pending,
1201 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1202 return -EINVAL;
1203 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001204
Shannon Nelson1fa18372013-11-20 10:03:08 +00001205 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1206 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001207
1208 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001209 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1210 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001211 return 0;
1212
1213 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1214 usleep_range(1000, 2000);
1215
1216 if (!netif_running(vsi->netdev)) {
1217 /* simple case - set for the next time the netdev is started */
1218 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001219 vsi->tx_rings[i]->count = new_tx_count;
1220 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001221 }
1222 goto done;
1223 }
1224
1225 /* We can't just free everything and then setup again,
1226 * because the ISRs in MSI-X mode get passed pointers
1227 * to the Tx and Rx ring structs.
1228 */
1229
1230 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001231 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 netdev_info(netdev,
1233 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001234 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001235 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1236 sizeof(struct i40e_ring), GFP_KERNEL);
1237 if (!tx_rings) {
1238 err = -ENOMEM;
1239 goto done;
1240 }
1241
1242 for (i = 0; i < vsi->num_queue_pairs; i++) {
1243 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001244 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001245 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001246 /* the desc and bi pointers will be reallocated in the
1247 * setup call
1248 */
1249 tx_rings[i].desc = NULL;
1250 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001251 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1252 if (err) {
1253 while (i) {
1254 i--;
1255 i40e_free_tx_resources(&tx_rings[i]);
1256 }
1257 kfree(tx_rings);
1258 tx_rings = NULL;
1259
1260 goto done;
1261 }
1262 }
1263 }
1264
1265 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001266 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001267 netdev_info(netdev,
1268 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001269 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001270 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1271 sizeof(struct i40e_ring), GFP_KERNEL);
1272 if (!rx_rings) {
1273 err = -ENOMEM;
1274 goto free_tx;
1275 }
1276
1277 for (i = 0; i < vsi->num_queue_pairs; i++) {
1278 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001279 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001280 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001281 /* the desc and bi pointers will be reallocated in the
1282 * setup call
1283 */
1284 rx_rings[i].desc = NULL;
1285 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001286 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1287 if (err) {
1288 while (i) {
1289 i--;
1290 i40e_free_rx_resources(&rx_rings[i]);
1291 }
1292 kfree(rx_rings);
1293 rx_rings = NULL;
1294
1295 goto free_tx;
1296 }
1297 }
1298 }
1299
1300 /* Bring interface down, copy in the new ring info,
1301 * then restore the interface
1302 */
1303 i40e_down(vsi);
1304
1305 if (tx_rings) {
1306 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001307 i40e_free_tx_resources(vsi->tx_rings[i]);
1308 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001309 }
1310 kfree(tx_rings);
1311 tx_rings = NULL;
1312 }
1313
1314 if (rx_rings) {
1315 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001316 i40e_free_rx_resources(vsi->rx_rings[i]);
1317 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001318 }
1319 kfree(rx_rings);
1320 rx_rings = NULL;
1321 }
1322
1323 i40e_up(vsi);
1324
1325free_tx:
1326 /* error cleanup if the Rx allocations failed after getting Tx */
1327 if (tx_rings) {
1328 for (i = 0; i < vsi->num_queue_pairs; i++)
1329 i40e_free_tx_resources(&tx_rings[i]);
1330 kfree(tx_rings);
1331 tx_rings = NULL;
1332 }
1333
1334done:
1335 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1336
1337 return err;
1338}
1339
1340static int i40e_get_sset_count(struct net_device *netdev, int sset)
1341{
1342 struct i40e_netdev_priv *np = netdev_priv(netdev);
1343 struct i40e_vsi *vsi = np->vsi;
1344 struct i40e_pf *pf = vsi->back;
1345
1346 switch (sset) {
1347 case ETH_SS_TEST:
1348 return I40E_TEST_LEN;
1349 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001350 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001351 int len = I40E_PF_STATS_LEN(netdev);
1352
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001353 if ((pf->lan_veb != I40E_NO_VEB) &&
1354 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001355 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001356 return len;
1357 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001358 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001359 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001360 case ETH_SS_PRIV_FLAGS:
1361 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001362 default:
1363 return -EOPNOTSUPP;
1364 }
1365}
1366
1367static void i40e_get_ethtool_stats(struct net_device *netdev,
1368 struct ethtool_stats *stats, u64 *data)
1369{
1370 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001371 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001372 struct i40e_vsi *vsi = np->vsi;
1373 struct i40e_pf *pf = vsi->back;
1374 int i = 0;
1375 char *p;
1376 int j;
1377 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001378 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379
1380 i40e_update_stats(vsi);
1381
1382 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1383 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1384 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1385 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1386 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001387 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1388 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1389 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1390 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1391 }
Vasu Dev38e00432014-08-01 13:27:03 -07001392#ifdef I40E_FCOE
1393 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1394 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1395 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1396 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1397 }
1398#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001399 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001400 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001401 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001402
1403 if (!tx_ring)
1404 continue;
1405
1406 /* process Tx ring statistics */
1407 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001408 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001409 data[i] = tx_ring->stats.packets;
1410 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001411 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001412 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001413
1414 /* Rx ring is the 2nd half of the queue pair */
1415 rx_ring = &tx_ring[1];
1416 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001417 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001418 data[i] = rx_ring->stats.packets;
1419 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001420 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001421 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001422 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001423 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001424 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001425 return;
1426
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001427 if ((pf->lan_veb != I40E_NO_VEB) &&
1428 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001429 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001430
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001431 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1432 p = (char *)veb;
1433 p += i40e_gstrings_veb_stats[j].stat_offset;
1434 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1435 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001436 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001437 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1438 data[i++] = veb->tc_stats.tc_tx_packets[j];
1439 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1440 data[i++] = veb->tc_stats.tc_rx_packets[j];
1441 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1442 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001443 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001444 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1445 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1446 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1447 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1448 }
1449 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1450 data[i++] = pf->stats.priority_xon_tx[j];
1451 data[i++] = pf->stats.priority_xoff_tx[j];
1452 }
1453 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1454 data[i++] = pf->stats.priority_xon_rx[j];
1455 data[i++] = pf->stats.priority_xoff_rx[j];
1456 }
1457 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1458 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001459}
1460
1461static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1462 u8 *data)
1463{
1464 struct i40e_netdev_priv *np = netdev_priv(netdev);
1465 struct i40e_vsi *vsi = np->vsi;
1466 struct i40e_pf *pf = vsi->back;
1467 char *p = (char *)data;
1468 int i;
1469
1470 switch (stringset) {
1471 case ETH_SS_TEST:
1472 for (i = 0; i < I40E_TEST_LEN; i++) {
1473 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1474 data += ETH_GSTRING_LEN;
1475 }
1476 break;
1477 case ETH_SS_STATS:
1478 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1479 snprintf(p, ETH_GSTRING_LEN, "%s",
1480 i40e_gstrings_net_stats[i].stat_string);
1481 p += ETH_GSTRING_LEN;
1482 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001483 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1484 snprintf(p, ETH_GSTRING_LEN, "%s",
1485 i40e_gstrings_misc_stats[i].stat_string);
1486 p += ETH_GSTRING_LEN;
1487 }
Vasu Dev38e00432014-08-01 13:27:03 -07001488#ifdef I40E_FCOE
1489 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1490 snprintf(p, ETH_GSTRING_LEN, "%s",
1491 i40e_gstrings_fcoe_stats[i].stat_string);
1492 p += ETH_GSTRING_LEN;
1493 }
1494#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495 for (i = 0; i < vsi->num_queue_pairs; i++) {
1496 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1497 p += ETH_GSTRING_LEN;
1498 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1499 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1501 p += ETH_GSTRING_LEN;
1502 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1503 p += ETH_GSTRING_LEN;
1504 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001505 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001506 return;
1507
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001508 if ((pf->lan_veb != I40E_NO_VEB) &&
1509 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001510 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1511 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1512 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513 p += ETH_GSTRING_LEN;
1514 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001515 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1516 snprintf(p, ETH_GSTRING_LEN,
1517 "veb.tc_%u_tx_packets", i);
1518 p += ETH_GSTRING_LEN;
1519 snprintf(p, ETH_GSTRING_LEN,
1520 "veb.tc_%u_tx_bytes", i);
1521 p += ETH_GSTRING_LEN;
1522 snprintf(p, ETH_GSTRING_LEN,
1523 "veb.tc_%u_rx_packets", i);
1524 p += ETH_GSTRING_LEN;
1525 snprintf(p, ETH_GSTRING_LEN,
1526 "veb.tc_%u_rx_bytes", i);
1527 p += ETH_GSTRING_LEN;
1528 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001529 }
1530 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1531 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1532 i40e_gstrings_stats[i].stat_string);
1533 p += ETH_GSTRING_LEN;
1534 }
1535 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1536 snprintf(p, ETH_GSTRING_LEN,
1537 "port.tx_priority_%u_xon", i);
1538 p += ETH_GSTRING_LEN;
1539 snprintf(p, ETH_GSTRING_LEN,
1540 "port.tx_priority_%u_xoff", i);
1541 p += ETH_GSTRING_LEN;
1542 }
1543 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1544 snprintf(p, ETH_GSTRING_LEN,
1545 "port.rx_priority_%u_xon", i);
1546 p += ETH_GSTRING_LEN;
1547 snprintf(p, ETH_GSTRING_LEN,
1548 "port.rx_priority_%u_xoff", i);
1549 p += ETH_GSTRING_LEN;
1550 }
1551 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1552 snprintf(p, ETH_GSTRING_LEN,
1553 "port.rx_priority_%u_xon_2_xoff", i);
1554 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555 }
1556 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1557 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001558 case ETH_SS_PRIV_FLAGS:
1559 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1560 memcpy(data, i40e_priv_flags_strings[i],
1561 ETH_GSTRING_LEN);
1562 data += ETH_GSTRING_LEN;
1563 }
1564 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001565 default:
1566 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001567 }
1568}
1569
1570static int i40e_get_ts_info(struct net_device *dev,
1571 struct ethtool_ts_info *info)
1572{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001573 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1574
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001575 /* only report HW timestamping if PTP is enabled */
1576 if (!(pf->flags & I40E_FLAG_PTP))
1577 return ethtool_op_get_ts_info(dev, info);
1578
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001579 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1580 SOF_TIMESTAMPING_RX_SOFTWARE |
1581 SOF_TIMESTAMPING_SOFTWARE |
1582 SOF_TIMESTAMPING_TX_HARDWARE |
1583 SOF_TIMESTAMPING_RX_HARDWARE |
1584 SOF_TIMESTAMPING_RAW_HARDWARE;
1585
1586 if (pf->ptp_clock)
1587 info->phc_index = ptp_clock_index(pf->ptp_clock);
1588 else
1589 info->phc_index = -1;
1590
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001591 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001592
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001593 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1594 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1595 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001596
1597 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001598}
1599
Shannon Nelson7b086392013-11-20 10:02:59 +00001600static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001601{
Shannon Nelson7b086392013-11-20 10:02:59 +00001602 struct i40e_netdev_priv *np = netdev_priv(netdev);
1603 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001604 i40e_status status;
1605 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001606
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001607 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001608 status = i40e_get_link_status(&pf->hw, &link_up);
1609 if (status) {
1610 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1611 *data = 1;
1612 return *data;
1613 }
1614
1615 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001616 *data = 0;
1617 else
1618 *data = 1;
1619
1620 return *data;
1621}
1622
Shannon Nelson7b086392013-11-20 10:02:59 +00001623static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624{
Shannon Nelson7b086392013-11-20 10:02:59 +00001625 struct i40e_netdev_priv *np = netdev_priv(netdev);
1626 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001628 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001629 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001630
Shannon Nelson7b086392013-11-20 10:02:59 +00001631 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001632}
1633
Shannon Nelson7b086392013-11-20 10:02:59 +00001634static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001635{
Shannon Nelson7b086392013-11-20 10:02:59 +00001636 struct i40e_netdev_priv *np = netdev_priv(netdev);
1637 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001638
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001639 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001640 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001641
Shannon Nelson4443ec92014-11-13 08:23:12 +00001642 /* forcebly clear the NVM Update state machine */
1643 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1644
Shannon Nelson7b086392013-11-20 10:02:59 +00001645 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001646}
1647
Shannon Nelson7b086392013-11-20 10:02:59 +00001648static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001649{
Shannon Nelson7b086392013-11-20 10:02:59 +00001650 struct i40e_netdev_priv *np = netdev_priv(netdev);
1651 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001652 u16 swc_old = pf->sw_int_count;
1653
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001654 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001655 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1656 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001657 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1658 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1659 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1660 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001661 usleep_range(1000, 2000);
1662 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001663
1664 return *data;
1665}
1666
Shannon Nelson7b086392013-11-20 10:02:59 +00001667static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001669 struct i40e_netdev_priv *np = netdev_priv(netdev);
1670 struct i40e_pf *pf = np->vsi->back;
1671
1672 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001673 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001674
1675 return *data;
1676}
1677
Greg Rosee17bc412015-04-16 20:05:59 -04001678static inline bool i40e_active_vfs(struct i40e_pf *pf)
1679{
1680 struct i40e_vf *vfs = pf->vf;
1681 int i;
1682
1683 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001684 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001685 return true;
1686 return false;
1687}
1688
Greg Rose510efb22015-07-10 19:36:01 -04001689static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1690{
1691 struct i40e_vsi **vsi = pf->vsi;
1692 int i;
1693
1694 for (i = 0; i < pf->num_alloc_vsi; i++) {
1695 if (!vsi[i])
1696 continue;
1697 if (vsi[i]->type == I40E_VSI_VMDQ2)
1698 return true;
1699 }
1700
1701 return false;
1702}
1703
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001704static void i40e_diag_test(struct net_device *netdev,
1705 struct ethtool_test *eth_test, u64 *data)
1706{
1707 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001708 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001709 struct i40e_pf *pf = np->vsi->back;
1710
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001711 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1712 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001713 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001714
Shannon Nelsonf551b432013-11-26 10:49:12 +00001715 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001716
Greg Rose510efb22015-07-10 19:36:01 -04001717 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001718 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001719 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001720 data[I40E_ETH_TEST_REG] = 1;
1721 data[I40E_ETH_TEST_EEPROM] = 1;
1722 data[I40E_ETH_TEST_INTR] = 1;
1723 data[I40E_ETH_TEST_LOOPBACK] = 1;
1724 data[I40E_ETH_TEST_LINK] = 1;
1725 eth_test->flags |= ETH_TEST_FL_FAILED;
1726 clear_bit(__I40E_TESTING, &pf->state);
1727 goto skip_ol_tests;
1728 }
1729
Greg Rose5b86c5c2015-02-26 16:14:35 +00001730 /* If the device is online then take it offline */
1731 if (if_running)
1732 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001733 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001734 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001735 /* This reset does not affect link - if it is
1736 * changed to a type of reset that does affect
1737 * link then the following link test would have
1738 * to be moved to before the reset
1739 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001740 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001741
Shannon Nelson7b086392013-11-20 10:02:59 +00001742 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001743 eth_test->flags |= ETH_TEST_FL_FAILED;
1744
Shannon Nelson7b086392013-11-20 10:02:59 +00001745 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001746 eth_test->flags |= ETH_TEST_FL_FAILED;
1747
Shannon Nelson7b086392013-11-20 10:02:59 +00001748 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001749 eth_test->flags |= ETH_TEST_FL_FAILED;
1750
Shannon Nelson7b086392013-11-20 10:02:59 +00001751 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001752 eth_test->flags |= ETH_TEST_FL_FAILED;
1753
Shannon Nelsonf551b432013-11-26 10:49:12 +00001754 /* run reg test last, a reset is required after it */
1755 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1756 eth_test->flags |= ETH_TEST_FL_FAILED;
1757
1758 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001759 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001760
1761 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001762 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001763 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001764 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001765 netif_info(pf, drv, netdev, "online testing starting\n");
1766
Shannon Nelson7b086392013-11-20 10:02:59 +00001767 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001768 eth_test->flags |= ETH_TEST_FL_FAILED;
1769
1770 /* Offline only tests, not run in online; pass by default */
1771 data[I40E_ETH_TEST_REG] = 0;
1772 data[I40E_ETH_TEST_EEPROM] = 0;
1773 data[I40E_ETH_TEST_INTR] = 0;
1774 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001775 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001776
Greg Rosee17bc412015-04-16 20:05:59 -04001777skip_ol_tests:
1778
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001779 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001780}
1781
1782static void i40e_get_wol(struct net_device *netdev,
1783 struct ethtool_wolinfo *wol)
1784{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001785 struct i40e_netdev_priv *np = netdev_priv(netdev);
1786 struct i40e_pf *pf = np->vsi->back;
1787 struct i40e_hw *hw = &pf->hw;
1788 u16 wol_nvm_bits;
1789
1790 /* NVM bit on means WoL disabled for the port */
1791 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001792 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001793 wol->supported = 0;
1794 wol->wolopts = 0;
1795 } else {
1796 wol->supported = WAKE_MAGIC;
1797 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1798 }
1799}
1800
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001801/**
1802 * i40e_set_wol - set the WakeOnLAN configuration
1803 * @netdev: the netdev in question
1804 * @wol: the ethtool WoL setting data
1805 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001806static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1807{
1808 struct i40e_netdev_priv *np = netdev_priv(netdev);
1809 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001810 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001811 struct i40e_hw *hw = &pf->hw;
1812 u16 wol_nvm_bits;
1813
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001814 /* WoL not supported if this isn't the controlling PF on the port */
1815 if (hw->partition_id != 1) {
1816 i40e_partition_setting_complaint(pf);
1817 return -EOPNOTSUPP;
1818 }
1819
1820 if (vsi != pf->vsi[pf->lan_vsi])
1821 return -EOPNOTSUPP;
1822
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001823 /* NVM bit on means WoL disabled for the port */
1824 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001825 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001826 return -EOPNOTSUPP;
1827
1828 /* only magic packet is supported */
1829 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1830 return -EOPNOTSUPP;
1831
1832 /* is this a new value? */
1833 if (pf->wol_en != !!wol->wolopts) {
1834 pf->wol_en = !!wol->wolopts;
1835 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1836 }
1837
1838 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001839}
1840
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001841static int i40e_set_phys_id(struct net_device *netdev,
1842 enum ethtool_phys_id_state state)
1843{
1844 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001845 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001846 struct i40e_pf *pf = np->vsi->back;
1847 struct i40e_hw *hw = &pf->hw;
1848 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001849 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001850
1851 switch (state) {
1852 case ETHTOOL_ID_ACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001853 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1854 pf->led_status = i40e_led_get(hw);
1855 } else {
1856 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_PORT, NULL);
1857 ret = i40e_led_get_phy(hw, &temp_status,
1858 &pf->phy_led_val);
1859 pf->led_status = temp_status;
1860 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001861 return blink_freq;
1862 case ETHTOOL_ID_ON:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001863 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1864 i40e_led_set(hw, 0xf, false);
1865 else
1866 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001867 break;
1868 case ETHTOOL_ID_OFF:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001869 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY))
1870 i40e_led_set(hw, 0x0, false);
1871 else
1872 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001873 break;
1874 case ETHTOOL_ID_INACTIVE:
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001875 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) {
1876 i40e_led_set(hw, false, pf->led_status);
1877 } else {
1878 ret = i40e_led_set_phy(hw, false, pf->led_status,
1879 (pf->phy_led_val |
1880 I40E_PHY_LED_MODE_ORIG));
1881 i40e_aq_set_phy_debug(hw, 0, NULL);
1882 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001883 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001884 default:
1885 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001886 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001887 if (ret)
1888 return -ENOENT;
1889 else
1890 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001891}
1892
1893/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1894 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1895 * 125us (8000 interrupts per second) == ITR(62)
1896 */
1897
Kan Lianga75e8002016-02-19 09:24:04 -05001898static int __i40e_get_coalesce(struct net_device *netdev,
1899 struct ethtool_coalesce *ec,
1900 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001901{
1902 struct i40e_netdev_priv *np = netdev_priv(netdev);
1903 struct i40e_vsi *vsi = np->vsi;
1904
1905 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1906 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1907
Kan Lianga75e8002016-02-19 09:24:04 -05001908 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
1909 * return queue 0's value to represent.
1910 */
1911 if (queue < 0) {
1912 queue = 0;
1913 } else if (queue >= vsi->num_queue_pairs) {
1914 return -EINVAL;
1915 }
1916
1917 if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001918 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001919
Kan Lianga75e8002016-02-19 09:24:04 -05001920 if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001921 ec->use_adaptive_tx_coalesce = 1;
1922
Kan Lianga75e8002016-02-19 09:24:04 -05001923 ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1924 ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1925
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04001926 /* we use the _usecs_high to store/set the interrupt rate limit
1927 * that the hardware supports, that almost but not quite
1928 * fits the original intent of the ethtool variable,
1929 * the rx_coalesce_usecs_high limits total interrupts
1930 * per second from both tx/rx sources.
1931 */
1932 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
1933 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001934
1935 return 0;
1936}
1937
Kan Lianga75e8002016-02-19 09:24:04 -05001938static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939 struct ethtool_coalesce *ec)
1940{
Kan Lianga75e8002016-02-19 09:24:04 -05001941 return __i40e_get_coalesce(netdev, ec, -1);
1942}
1943
Kan Liangbe280ba2016-02-19 09:24:05 -05001944static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
1945 struct ethtool_coalesce *ec)
1946{
1947 return __i40e_get_coalesce(netdev, ec, queue);
1948}
1949
Kan Lianga75e8002016-02-19 09:24:04 -05001950static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
1951 struct ethtool_coalesce *ec,
1952 int queue)
1953{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001954 struct i40e_pf *pf = vsi->back;
1955 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05001956 struct i40e_q_vector *q_vector;
1957 u16 vector, intrl;
1958
1959 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit);
1960
1961 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
1962 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
1963
1964 if (ec->use_adaptive_rx_coalesce)
1965 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
1966 else
1967 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1968
1969 if (ec->use_adaptive_tx_coalesce)
1970 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
1971 else
1972 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1973
1974 q_vector = vsi->rx_rings[queue]->q_vector;
1975 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
1976 vector = vsi->base_vector + q_vector->v_idx;
1977 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
1978
1979 q_vector = vsi->tx_rings[queue]->q_vector;
1980 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
1981 vector = vsi->base_vector + q_vector->v_idx;
1982 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
1983
1984 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
1985 i40e_flush(hw);
1986}
1987
1988static int __i40e_set_coalesce(struct net_device *netdev,
1989 struct ethtool_coalesce *ec,
1990 int queue)
1991{
1992 struct i40e_netdev_priv *np = netdev_priv(netdev);
1993 struct i40e_vsi *vsi = np->vsi;
1994 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001995 int i;
1996
1997 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1998 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1999
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002000 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2001 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2002 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2003 return -EINVAL;
2004 }
2005
2006 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2007 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n");
2008 return -EINVAL;
2009 }
2010
Kan Lianga75e8002016-02-19 09:24:04 -05002011 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002012 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002013 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
Kan Lianga75e8002016-02-19 09:24:04 -05002014 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2015 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2016 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2017 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002018 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002019
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002020 vsi->int_rate_limit = ec->rx_coalesce_usecs_high;
2021
Kan Lianga75e8002016-02-19 09:24:04 -05002022 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002023 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002024 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
Kan Lianga75e8002016-02-19 09:24:04 -05002025 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2026 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2027 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2028 return -EINVAL;
2029 }
2030
2031 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2032 * apply to all queues.
2033 */
2034 if (queue < 0) {
2035 for (i = 0; i < vsi->num_queue_pairs; i++)
2036 i40e_set_itr_per_queue(vsi, ec, i);
2037 } else if (queue < vsi->num_queue_pairs) {
2038 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002039 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002040 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2041 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002042 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002043 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002044
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002045 return 0;
2046}
2047
Kan Lianga75e8002016-02-19 09:24:04 -05002048static int i40e_set_coalesce(struct net_device *netdev,
2049 struct ethtool_coalesce *ec)
2050{
2051 return __i40e_set_coalesce(netdev, ec, -1);
2052}
2053
Kan Liangf3757a42016-02-19 09:24:06 -05002054static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2055 struct ethtool_coalesce *ec)
2056{
2057 return __i40e_set_coalesce(netdev, ec, queue);
2058}
2059
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002060/**
2061 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2062 * @pf: pointer to the physical function struct
2063 * @cmd: ethtool rxnfc command
2064 *
2065 * Returns Success if the flow is supported, else Invalid Input.
2066 **/
2067static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2068{
2069 cmd->data = 0;
2070
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002071 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
2072 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
2073 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
2074 return 0;
2075 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002076 /* Report default options for RSS on i40e */
2077 switch (cmd->flow_type) {
2078 case TCP_V4_FLOW:
2079 case UDP_V4_FLOW:
2080 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2081 /* fall through to add IP fields */
2082 case SCTP_V4_FLOW:
2083 case AH_ESP_V4_FLOW:
2084 case AH_V4_FLOW:
2085 case ESP_V4_FLOW:
2086 case IPV4_FLOW:
2087 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2088 break;
2089 case TCP_V6_FLOW:
2090 case UDP_V6_FLOW:
2091 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
2092 /* fall through to add IP fields */
2093 case SCTP_V6_FLOW:
2094 case AH_ESP_V6_FLOW:
2095 case AH_V6_FLOW:
2096 case ESP_V6_FLOW:
2097 case IPV6_FLOW:
2098 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2099 break;
2100 default:
2101 return -EINVAL;
2102 }
2103
2104 return 0;
2105}
2106
2107/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002108 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2109 * @pf: Pointer to the physical function struct
2110 * @cmd: The command to get or set Rx flow classification rules
2111 * @rule_locs: Array of used rule locations
2112 *
2113 * This function populates both the total and actual rule count of
2114 * the ethtool flow classification command
2115 *
2116 * Returns 0 on success or -EMSGSIZE if entry not found
2117 **/
2118static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2119 struct ethtool_rxnfc *cmd,
2120 u32 *rule_locs)
2121{
2122 struct i40e_fdir_filter *rule;
2123 struct hlist_node *node2;
2124 int cnt = 0;
2125
2126 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002127 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002128
2129 hlist_for_each_entry_safe(rule, node2,
2130 &pf->fdir_filter_list, fdir_node) {
2131 if (cnt == cmd->rule_cnt)
2132 return -EMSGSIZE;
2133
2134 rule_locs[cnt] = rule->fd_id;
2135 cnt++;
2136 }
2137
2138 cmd->rule_cnt = cnt;
2139
2140 return 0;
2141}
2142
2143/**
2144 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2145 * @pf: Pointer to the physical function struct
2146 * @cmd: The command to get or set Rx flow classification rules
2147 *
2148 * This function looks up a filter based on the Rx flow classification
2149 * command and fills the flow spec info for it if found
2150 *
2151 * Returns 0 on success or -EINVAL if filter not found
2152 **/
2153static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2154 struct ethtool_rxnfc *cmd)
2155{
2156 struct ethtool_rx_flow_spec *fsp =
2157 (struct ethtool_rx_flow_spec *)&cmd->fs;
2158 struct i40e_fdir_filter *rule = NULL;
2159 struct hlist_node *node2;
2160
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002161 hlist_for_each_entry_safe(rule, node2,
2162 &pf->fdir_filter_list, fdir_node) {
2163 if (fsp->location <= rule->fd_id)
2164 break;
2165 }
2166
2167 if (!rule || fsp->location != rule->fd_id)
2168 return -EINVAL;
2169
2170 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002171 if (fsp->flow_type == IP_USER_FLOW) {
2172 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2173 fsp->h_u.usr_ip4_spec.proto = 0;
2174 fsp->m_u.usr_ip4_spec.proto = 0;
2175 }
2176
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002177 /* Reverse the src and dest notion, since the HW views them from
2178 * Tx perspective where as the user expects it from Rx filter view.
2179 */
2180 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2181 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2182 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2183 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002184
2185 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2186 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2187 else
2188 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002189
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002190 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2191 struct i40e_vsi *vsi;
2192
2193 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2194 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2195 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2196 fsp->m_ext.data[1] = htonl(0x1);
2197 }
2198 }
2199
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002200 return 0;
2201}
2202
2203/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002204 * i40e_get_rxnfc - command to get RX flow classification rules
2205 * @netdev: network interface device structure
2206 * @cmd: ethtool rxnfc command
2207 *
2208 * Returns Success if the command is supported.
2209 **/
2210static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2211 u32 *rule_locs)
2212{
2213 struct i40e_netdev_priv *np = netdev_priv(netdev);
2214 struct i40e_vsi *vsi = np->vsi;
2215 struct i40e_pf *pf = vsi->back;
2216 int ret = -EOPNOTSUPP;
2217
2218 switch (cmd->cmd) {
2219 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002220 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002221 ret = 0;
2222 break;
2223 case ETHTOOL_GRXFH:
2224 ret = i40e_get_rss_hash_opts(pf, cmd);
2225 break;
2226 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002227 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002228 /* report total rule count */
2229 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002230 ret = 0;
2231 break;
2232 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002233 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002234 break;
2235 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002236 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2237 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002238 default:
2239 break;
2240 }
2241
2242 return ret;
2243}
2244
2245/**
2246 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2247 * @pf: pointer to the physical function struct
2248 * @cmd: ethtool rxnfc command
2249 *
2250 * Returns Success if the flow input set is supported.
2251 **/
2252static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2253{
2254 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002255 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2256 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002257
2258 /* RSS does not support anything other than hashing
2259 * to queues on src and dst IPs and ports
2260 */
2261 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2262 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2263 return -EINVAL;
2264
2265 /* We need at least the IP SRC and DEST fields for hashing */
2266 if (!(nfc->data & RXH_IP_SRC) ||
2267 !(nfc->data & RXH_IP_DST))
2268 return -EINVAL;
2269
2270 switch (nfc->flow_type) {
2271 case TCP_V4_FLOW:
2272 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2273 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002274 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002276 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2277 hena |=
2278 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2279
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002280 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 break;
2282 default:
2283 return -EINVAL;
2284 }
2285 break;
2286 case TCP_V6_FLOW:
2287 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2288 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002289 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002290 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002291 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2292 hena |=
2293 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
2294
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002295 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002296 break;
2297 default:
2298 return -EINVAL;
2299 }
2300 break;
2301 case UDP_V4_FLOW:
2302 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2303 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002304 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002305 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002306 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2307 hena |=
2308 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2309 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
2310
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002311 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2312 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002313 break;
2314 default:
2315 return -EINVAL;
2316 }
2317 break;
2318 case UDP_V6_FLOW:
2319 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2320 case 0:
Anjali Singhai Jain6e35c042015-12-09 15:50:24 -08002321 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002322 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002323 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2324 hena |=
2325 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2326 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
2327
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002328 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2329 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002330 break;
2331 default:
2332 return -EINVAL;
2333 }
2334 break;
2335 case AH_ESP_V4_FLOW:
2336 case AH_V4_FLOW:
2337 case ESP_V4_FLOW:
2338 case SCTP_V4_FLOW:
2339 if ((nfc->data & RXH_L4_B_0_1) ||
2340 (nfc->data & RXH_L4_B_2_3))
2341 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002342 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002343 break;
2344 case AH_ESP_V6_FLOW:
2345 case AH_V6_FLOW:
2346 case ESP_V6_FLOW:
2347 case SCTP_V6_FLOW:
2348 if ((nfc->data & RXH_L4_B_0_1) ||
2349 (nfc->data & RXH_L4_B_2_3))
2350 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002351 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002352 break;
2353 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002354 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2355 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002356 break;
2357 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002358 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2359 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002360 break;
2361 default:
2362 return -EINVAL;
2363 }
2364
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002365 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2366 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002367 i40e_flush(hw);
2368
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002369 /* Save setting for future output/update */
2370 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2371
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002372 return 0;
2373}
2374
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002375/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002376 * i40e_match_fdir_input_set - Match a new filter against an existing one
2377 * @rule: The filter already added
2378 * @input: The new filter to comapre against
2379 *
2380 * Returns true if the two input set match
2381 **/
2382static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2383 struct i40e_fdir_filter *input)
2384{
2385 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2386 (rule->src_ip[0] != input->src_ip[0]) ||
2387 (rule->dst_port != input->dst_port) ||
2388 (rule->src_port != input->src_port))
2389 return false;
2390 return true;
2391}
2392
2393/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002394 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2395 * @vsi: Pointer to the targeted VSI
2396 * @input: The filter to update or NULL to indicate deletion
2397 * @sw_idx: Software index to the filter
2398 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002399 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002400 * This function updates (or deletes) a Flow Director entry from
2401 * the hlist of the corresponding PF
2402 *
2403 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002404 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002405static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2406 struct i40e_fdir_filter *input,
2407 u16 sw_idx,
2408 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002409{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002410 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002411 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002412 struct hlist_node *node2;
2413 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002414
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002415 parent = NULL;
2416 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002417
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002418 hlist_for_each_entry_safe(rule, node2,
2419 &pf->fdir_filter_list, fdir_node) {
2420 /* hash found, or no matching entry */
2421 if (rule->fd_id >= sw_idx)
2422 break;
2423 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002424 }
2425
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002426 /* if there is an old rule occupying our place remove it */
2427 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002428 if (input && !i40e_match_fdir_input_set(rule, input))
2429 err = i40e_add_del_fdir(vsi, rule, false);
2430 else if (!input)
2431 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002432 hlist_del(&rule->fdir_node);
2433 kfree(rule);
2434 pf->fdir_pf_active_filters--;
2435 }
2436
2437 /* If no input this was a delete, err should be 0 if a rule was
2438 * successfully found and removed from the list else -EINVAL
2439 */
2440 if (!input)
2441 return err;
2442
2443 /* initialize node and set software index */
2444 INIT_HLIST_NODE(&input->fdir_node);
2445
2446 /* add filter to the list */
2447 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002448 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002449 else
2450 hlist_add_head(&input->fdir_node,
2451 &pf->fdir_filter_list);
2452
2453 /* update counts */
2454 pf->fdir_pf_active_filters++;
2455
2456 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002457}
2458
2459/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002460 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2461 * @vsi: Pointer to the targeted VSI
2462 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002463 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002464 * The function removes a Flow Director filter entry from the
2465 * hlist of the corresponding PF
2466 *
2467 * Returns 0 on success
2468 */
2469static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2470 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002471{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002472 struct ethtool_rx_flow_spec *fsp =
2473 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002474 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002475 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002476
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002477 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2478 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2479 return -EBUSY;
2480
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002481 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2482 return -EBUSY;
2483
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002484 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002485
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002486 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002487 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002488}
2489
2490/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002491 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002492 * @vsi: pointer to the targeted VSI
2493 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002494 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002495 * Add Flow Director filters for a specific flow spec based on their
2496 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002497 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002498static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2499 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002500{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002501 struct ethtool_rx_flow_spec *fsp;
2502 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002503 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002504 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002505 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002506
2507 if (!vsi)
2508 return -EINVAL;
2509
2510 pf = vsi->back;
2511
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002512 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2513 return -EOPNOTSUPP;
2514
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002515 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002516 return -ENOSPC;
2517
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002518 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2519 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2520 return -EBUSY;
2521
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002522 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2523 return -EBUSY;
2524
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002525 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2526
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002527 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2528 pf->hw.func_caps.fd_filters_guaranteed)) {
2529 return -EINVAL;
2530 }
2531
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002532 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2533 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002534 return -EINVAL;
2535
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002536 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002537
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002538 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002539 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002540
2541 input->fd_id = fsp->location;
2542
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002543 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2544 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2545 else
2546 input->dest_ctl =
2547 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2548
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002549 input->q_index = fsp->ring_cookie;
2550 input->flex_off = 0;
2551 input->pctype = 0;
2552 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002553 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002554 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002555 input->flow_type = fsp->flow_type;
2556 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002557
2558 /* Reverse the src and dest notion, since the HW expects them to be from
2559 * Tx perspective where as the input from user is from Rx filter view.
2560 */
2561 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2562 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2563 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2564 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002565
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002566 if (ntohl(fsp->m_ext.data[1])) {
2567 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2568 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2569 goto free_input;
2570 }
2571 vf_id = ntohl(fsp->h_ext.data[1]);
2572 /* Find vsi id from vf id and override dest vsi */
2573 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2574 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2575 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2576 goto free_input;
2577 }
2578 }
2579
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002580 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002581free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002582 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002583 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002584 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002585 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002586
2587 return ret;
2588}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002589
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002590/**
2591 * i40e_set_rxnfc - command to set RX flow classification rules
2592 * @netdev: network interface device structure
2593 * @cmd: ethtool rxnfc command
2594 *
2595 * Returns Success if the command is supported.
2596 **/
2597static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2598{
2599 struct i40e_netdev_priv *np = netdev_priv(netdev);
2600 struct i40e_vsi *vsi = np->vsi;
2601 struct i40e_pf *pf = vsi->back;
2602 int ret = -EOPNOTSUPP;
2603
2604 switch (cmd->cmd) {
2605 case ETHTOOL_SRXFH:
2606 ret = i40e_set_rss_hash_opt(pf, cmd);
2607 break;
2608 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002609 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002610 break;
2611 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002612 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002613 break;
2614 default:
2615 break;
2616 }
2617
2618 return ret;
2619}
2620
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002621/**
2622 * i40e_max_channels - get Max number of combined channels supported
2623 * @vsi: vsi pointer
2624 **/
2625static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2626{
2627 /* TODO: This code assumes DCB and FD is disabled for now. */
2628 return vsi->alloc_queue_pairs;
2629}
2630
2631/**
2632 * i40e_get_channels - Get the current channels enabled and max supported etc.
2633 * @netdev: network interface device structure
2634 * @ch: ethtool channels structure
2635 *
2636 * We don't support separate tx and rx queues as channels. The other count
2637 * represents how many queues are being used for control. max_combined counts
2638 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2639 * q_vectors since we support a lot more queue pairs than q_vectors.
2640 **/
2641static void i40e_get_channels(struct net_device *dev,
2642 struct ethtool_channels *ch)
2643{
2644 struct i40e_netdev_priv *np = netdev_priv(dev);
2645 struct i40e_vsi *vsi = np->vsi;
2646 struct i40e_pf *pf = vsi->back;
2647
2648 /* report maximum channels */
2649 ch->max_combined = i40e_max_channels(vsi);
2650
2651 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002652 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002653 ch->max_other = ch->other_count;
2654
2655 /* Note: This code assumes DCB is disabled for now. */
2656 ch->combined_count = vsi->num_queue_pairs;
2657}
2658
2659/**
2660 * i40e_set_channels - Set the new channels count.
2661 * @netdev: network interface device structure
2662 * @ch: ethtool channels structure
2663 *
2664 * The new channels count may not be the same as requested by the user
2665 * since it gets rounded down to a power of 2 value.
2666 **/
2667static int i40e_set_channels(struct net_device *dev,
2668 struct ethtool_channels *ch)
2669{
2670 struct i40e_netdev_priv *np = netdev_priv(dev);
2671 unsigned int count = ch->combined_count;
2672 struct i40e_vsi *vsi = np->vsi;
2673 struct i40e_pf *pf = vsi->back;
2674 int new_count;
2675
2676 /* We do not support setting channels for any other VSI at present */
2677 if (vsi->type != I40E_VSI_MAIN)
2678 return -EINVAL;
2679
2680 /* verify they are not requesting separate vectors */
2681 if (!count || ch->rx_count || ch->tx_count)
2682 return -EINVAL;
2683
2684 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002685 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002686 return -EINVAL;
2687
2688 /* verify the number of channels does not exceed hardware limits */
2689 if (count > i40e_max_channels(vsi))
2690 return -EINVAL;
2691
2692 /* update feature limits from largest to smallest supported values */
2693 /* TODO: Flow director limit, DCB etc */
2694
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002695 /* use rss_reconfig to rebuild with new queue count and update traffic
2696 * class queue mapping
2697 */
2698 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002699 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002700 return 0;
2701 else
2702 return -EINVAL;
2703}
2704
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002705/**
2706 * i40e_get_rxfh_key_size - get the RSS hash key size
2707 * @netdev: network interface device structure
2708 *
2709 * Returns the table size.
2710 **/
2711static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2712{
2713 return I40E_HKEY_ARRAY_SIZE;
2714}
2715
2716/**
2717 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2718 * @netdev: network interface device structure
2719 *
2720 * Returns the table size.
2721 **/
2722static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2723{
2724 return I40E_HLUT_ARRAY_SIZE;
2725}
2726
2727static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2728 u8 *hfunc)
2729{
2730 struct i40e_netdev_priv *np = netdev_priv(netdev);
2731 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04002732 u8 *lut, *seed = NULL;
2733 int ret;
2734 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002735
2736 if (hfunc)
2737 *hfunc = ETH_RSS_HASH_TOP;
2738
2739 if (!indir)
2740 return 0;
2741
Helin Zhang043dd652015-10-21 19:56:23 -04002742 seed = key;
2743 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2744 if (!lut)
2745 return -ENOMEM;
2746 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
2747 if (ret)
2748 goto out;
2749 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2750 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002751
Helin Zhang043dd652015-10-21 19:56:23 -04002752out:
2753 kfree(lut);
2754
2755 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002756}
2757
2758/**
2759 * i40e_set_rxfh - set the rx flow hash indirection table
2760 * @netdev: network interface device structure
2761 * @indir: indirection table
2762 * @key: hash key
2763 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002764 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002765 * returns 0 after programming the table.
2766 **/
2767static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2768 const u8 *key, const u8 hfunc)
2769{
2770 struct i40e_netdev_priv *np = netdev_priv(netdev);
2771 struct i40e_vsi *vsi = np->vsi;
Helin Zhang28c58692015-10-26 19:44:27 -04002772 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04002773 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002774
2775 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2776 return -EOPNOTSUPP;
2777
2778 if (!indir)
2779 return 0;
2780
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002781 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04002782 if (!vsi->rss_hkey_user) {
2783 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
2784 GFP_KERNEL);
2785 if (!vsi->rss_hkey_user)
2786 return -ENOMEM;
2787 }
2788 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
2789 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002790 }
Helin Zhang28c58692015-10-26 19:44:27 -04002791 if (!vsi->rss_lut_user) {
2792 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
2793 if (!vsi->rss_lut_user)
2794 return -ENOMEM;
2795 }
Helin Zhang043dd652015-10-21 19:56:23 -04002796
Helin Zhang28c58692015-10-26 19:44:27 -04002797 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
2798 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
2799 vsi->rss_lut_user[i] = (u8)(indir[i]);
2800
2801 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
2802 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002803}
2804
Greg Rose7e45ab42015-02-06 08:52:19 +00002805/**
2806 * i40e_get_priv_flags - report device private flags
2807 * @dev: network interface device structure
2808 *
2809 * The get string set count and the string set should be matched for each
2810 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2811 * array.
2812 *
2813 * Returns a u32 bitmap of flags.
2814 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002815static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002816{
2817 struct i40e_netdev_priv *np = netdev_priv(dev);
2818 struct i40e_vsi *vsi = np->vsi;
2819 struct i40e_pf *pf = vsi->back;
2820 u32 ret_flags = 0;
2821
2822 ret_flags |= pf->hw.func_caps.npar_enable ?
2823 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002824 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2825 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002826 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2827 I40E_PRIV_FLAGS_FD_ATR : 0;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002828 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ?
2829 I40E_PRIV_FLAGS_VEB_STATS : 0;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002830 ret_flags |= pf->flags & I40E_FLAG_RX_PS_ENABLED ?
2831 I40E_PRIV_FLAGS_PS : 0;
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002832 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ?
2833 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT;
Greg Rose7e45ab42015-02-06 08:52:19 +00002834
2835 return ret_flags;
2836}
2837
Shannon Nelson9ac77262015-08-27 11:42:40 -04002838/**
2839 * i40e_set_priv_flags - set private flags
2840 * @dev: network interface device structure
2841 * @flags: bit flags to be set
2842 **/
2843static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2844{
2845 struct i40e_netdev_priv *np = netdev_priv(dev);
2846 struct i40e_vsi *vsi = np->vsi;
2847 struct i40e_pf *pf = vsi->back;
Jesse Brandeburg827de392015-11-06 15:26:07 -08002848 bool reset_required = false;
2849
2850 /* NOTE: MFP is not settable */
2851
2852 /* allow the user to control the method of receive
2853 * buffer DMA, whether the packet is split at header
2854 * boundaries into two separate buffers. In some cases
2855 * one routine or the other will perform better.
2856 */
2857 if ((flags & I40E_PRIV_FLAGS_PS) &&
2858 !(pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2859 pf->flags |= I40E_FLAG_RX_PS_ENABLED;
2860 pf->flags &= ~I40E_FLAG_RX_1BUF_ENABLED;
2861 reset_required = true;
2862 } else if (!(flags & I40E_PRIV_FLAGS_PS) &&
2863 (pf->flags & I40E_FLAG_RX_PS_ENABLED)) {
2864 pf->flags &= ~I40E_FLAG_RX_PS_ENABLED;
2865 pf->flags |= I40E_FLAG_RX_1BUF_ENABLED;
2866 reset_required = true;
2867 }
Shannon Nelson9ac77262015-08-27 11:42:40 -04002868
2869 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2870 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2871 else
2872 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2873
Jesse Brandeburgef171782015-09-03 17:18:49 -04002874 /* allow the user to control the state of the Flow
2875 * Director ATR (Application Targeted Routing) feature
2876 * of the driver
2877 */
2878 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2879 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2880 } else {
2881 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2882 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2883 }
2884
Shannon Nelson66fc3602016-01-13 16:51:42 -08002885 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2886 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002887 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002888 reset_required = true;
2889 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) &&
2890 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002891 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
Shannon Nelson66fc3602016-01-13 16:51:42 -08002892 reset_required = true;
2893 }
Shannon Nelson1cdfd882015-09-28 14:12:34 -04002894
Anjali Singhai Jain72b74862016-01-08 17:50:21 -08002895 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) &&
2896 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE))
2897 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2898 else
2899 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE;
2900
Jesse Brandeburg827de392015-11-06 15:26:07 -08002901 /* if needed, issue reset to cause things to take effect */
2902 if (reset_required)
2903 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
2904
Shannon Nelson9ac77262015-08-27 11:42:40 -04002905 return 0;
2906}
2907
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002908static const struct ethtool_ops i40e_ethtool_ops = {
2909 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002910 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002911 .get_drvinfo = i40e_get_drvinfo,
2912 .get_regs_len = i40e_get_regs_len,
2913 .get_regs = i40e_get_regs,
2914 .nway_reset = i40e_nway_reset,
2915 .get_link = ethtool_op_get_link,
2916 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002917 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002918 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002919 .get_eeprom_len = i40e_get_eeprom_len,
2920 .get_eeprom = i40e_get_eeprom,
2921 .get_ringparam = i40e_get_ringparam,
2922 .set_ringparam = i40e_set_ringparam,
2923 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002924 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002925 .get_msglevel = i40e_get_msglevel,
2926 .set_msglevel = i40e_set_msglevel,
2927 .get_rxnfc = i40e_get_rxnfc,
2928 .set_rxnfc = i40e_set_rxnfc,
2929 .self_test = i40e_diag_test,
2930 .get_strings = i40e_get_strings,
2931 .set_phys_id = i40e_set_phys_id,
2932 .get_sset_count = i40e_get_sset_count,
2933 .get_ethtool_stats = i40e_get_ethtool_stats,
2934 .get_coalesce = i40e_get_coalesce,
2935 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002936 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2937 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2938 .get_rxfh = i40e_get_rxfh,
2939 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002940 .get_channels = i40e_get_channels,
2941 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002942 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002943 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002944 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05002945 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05002946 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002947};
2948
2949void i40e_set_ethtool_ops(struct net_device *netdev)
2950{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002951 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002952}