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