blob: de0dfe3404946f7bf76bf8df7d56bccc56e9ff7a [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),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080092 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
93 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000094};
95
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096/* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
102 *
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
105 */
Joe Perchesfe180a52016-09-26 20:17:01 -0700106static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800148 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000149 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jacob Keller2955fac2017-05-03 10:28:58 -0700150 I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
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
165#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000166 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
167 * 2 /* Tx and Rx together */ \
168 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000169#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
170#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000171#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000173 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000174 I40E_QUEUE_STATS_LEN((n)))
175#define I40E_PFC_STATS_LEN ( \
176 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
177 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
178 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
179 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
180 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
181 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400182#define I40E_VEB_TC_STATS_LEN ( \
183 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
184 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
185 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
186 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
187 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000188#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400189#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
191 I40E_PFC_STATS_LEN + \
192 I40E_VSI_STATS_LEN((n)))
193
194enum i40e_ethtool_test_id {
195 I40E_ETH_TEST_REG = 0,
196 I40E_ETH_TEST_EEPROM,
197 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198 I40E_ETH_TEST_LINK,
199};
200
201static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
202 "Register test (offline)",
203 "Eeprom test (offline)",
204 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000205 "Link test (on/offline)"
206};
207
208#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
209
Alexander Duyckaca955d2017-03-10 12:22:01 -0800210struct i40e_priv_flags {
211 char flag_string[ETH_GSTRING_LEN];
212 u64 flag;
213 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000214};
215
Alexander Duyckaca955d2017-03-10 12:22:01 -0800216#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
217 .flag_string = _name, \
218 .flag = _flag, \
219 .read_only = _read_only, \
220}
221
222static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
223 /* NOTE: MFP setting cannot be changed */
224 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
225 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
226 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
227 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700228 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700229 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400230 I40E_PRIV_FLAG("disable-source-pruning",
231 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800232};
233
234#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000235
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700236/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800237static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
238 I40E_PRIV_FLAG("vf-true-promisc-support",
239 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700240};
241
Alexander Duyckaca955d2017-03-10 12:22:01 -0800242#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700243
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 Sullivan06566e52016-05-03 15:13:14 -0700255 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
256 * @phy_types: PHY types to convert
257 * @supported: pointer to the ethtool supported variable to fill in
258 * @advertising: pointer to the ethtool advertising variable to fill in
259 *
260 **/
261static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
262 u32 *advertising)
263{
Avinash Dayanand28537042016-06-20 09:10:33 -0700264 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800265 u64 phy_types = pf->hw.phy.phy_types;
266
Catherine Sullivan06566e52016-05-03 15:13:14 -0700267 *supported = 0x0;
268 *advertising = 0x0;
269
270 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
271 *supported |= SUPPORTED_Autoneg |
272 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700273 *advertising |= ADVERTISED_Autoneg;
274 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
275 *advertising |= ADVERTISED_1000baseT_Full;
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400276 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700277 *supported |= SUPPORTED_100baseT_Full;
278 *advertising |= ADVERTISED_100baseT_Full;
279 }
280 }
281 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
282 phy_types & I40E_CAP_PHY_TYPE_XFI ||
283 phy_types & I40E_CAP_PHY_TYPE_SFI ||
284 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
285 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
286 *supported |= SUPPORTED_10000baseT_Full;
287 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
288 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
289 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
290 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
291 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
292 *supported |= SUPPORTED_Autoneg |
293 SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700294 *advertising |= ADVERTISED_Autoneg;
295 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
296 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700297 }
298 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
299 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
300 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
301 *supported |= SUPPORTED_40000baseCR4_Full;
302 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
303 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
304 *supported |= SUPPORTED_Autoneg |
305 SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700306 *advertising |= ADVERTISED_Autoneg;
307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
308 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700309 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700310 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700311 *supported |= SUPPORTED_Autoneg |
312 SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700313 *advertising |= ADVERTISED_Autoneg;
314 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
315 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700316 }
317 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
318 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
319 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
320 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
321 *supported |= SUPPORTED_Autoneg |
322 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700323 *advertising |= ADVERTISED_Autoneg;
324 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
325 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700326 }
327 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
328 *supported |= SUPPORTED_40000baseSR4_Full;
329 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
330 *supported |= SUPPORTED_40000baseLR4_Full;
331 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
332 *supported |= SUPPORTED_40000baseKR4_Full |
333 SUPPORTED_Autoneg;
334 *advertising |= ADVERTISED_40000baseKR4_Full |
335 ADVERTISED_Autoneg;
336 }
337 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
338 *supported |= SUPPORTED_20000baseKR2_Full |
339 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700340 *advertising |= ADVERTISED_Autoneg;
341 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
342 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700343 }
344 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400345 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800346 *supported |= SUPPORTED_10000baseKR_Full |
347 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700348 *advertising |= ADVERTISED_Autoneg;
349 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400350 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800351 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700352 }
353 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
354 *supported |= SUPPORTED_10000baseKX4_Full |
355 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700356 *advertising |= ADVERTISED_Autoneg;
357 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
358 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700359 }
360 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400361 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800362 *supported |= SUPPORTED_1000baseKX_Full |
363 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700364 *advertising |= ADVERTISED_Autoneg;
365 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400366 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800367 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700368 }
Carolyn Wyborny31232372016-11-21 13:03:48 -0800369 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
370 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
371 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
372 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
373 *supported |= SUPPORTED_Autoneg;
374 *advertising |= ADVERTISED_Autoneg;
375 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700376}
377
378/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000379 * i40e_get_settings_link_up - Get the Link settings for when link is up
380 * @hw: hw structure
381 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000382 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000383 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000384 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000385static void i40e_get_settings_link_up(struct i40e_hw *hw,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100386 struct ethtool_link_ksettings *cmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400387 struct net_device *netdev,
388 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000389{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000390 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000391 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700392 u32 e_advertising = 0x0;
393 u32 e_supported = 0x0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100394 u32 supported, advertising;
395
396 ethtool_convert_link_mode_to_legacy_u32(&supported,
397 cmd->link_modes.supported);
398 ethtool_convert_link_mode_to_legacy_u32(&advertising,
399 cmd->link_modes.advertising);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000400
Catherine Sullivane8278452015-02-06 08:52:08 +0000401 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000402 switch (hw_link_info->phy_type) {
403 case I40E_PHY_TYPE_40GBASE_CR4:
404 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100405 supported = SUPPORTED_Autoneg |
406 SUPPORTED_40000baseCR4_Full;
407 advertising = ADVERTISED_Autoneg |
408 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000409 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000410 case I40E_PHY_TYPE_XLAUI:
411 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000412 case I40E_PHY_TYPE_40GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100413 supported = SUPPORTED_40000baseCR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000414 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000415 case I40E_PHY_TYPE_40GBASE_SR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100416 supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000417 break;
418 case I40E_PHY_TYPE_40GBASE_LR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100419 supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000420 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000421 case I40E_PHY_TYPE_10GBASE_SR:
422 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000423 case I40E_PHY_TYPE_1000BASE_SX:
424 case I40E_PHY_TYPE_1000BASE_LX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100425 supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400426 if (hw_link_info->module_type[2] &
427 I40E_MODULE_TYPE_1000BASE_SX ||
428 hw_link_info->module_type[2] &
429 I40E_MODULE_TYPE_1000BASE_LX) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100430 supported |= SUPPORTED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400431 if (hw_link_info->requested_speeds &
432 I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100433 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400434 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000435 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100436 advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000437 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000438 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000439 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700440 case I40E_PHY_TYPE_100BASE_TX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100441 supported = SUPPORTED_Autoneg |
442 SUPPORTED_10000baseT_Full |
443 SUPPORTED_1000baseT_Full |
444 SUPPORTED_100baseT_Full;
445 advertising = ADVERTISED_Autoneg;
Catherine Sullivane8278452015-02-06 08:52:08 +0000446 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100447 advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000448 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100449 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700450 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100451 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400452 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400453 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100454 supported = SUPPORTED_Autoneg |
455 SUPPORTED_1000baseT_Full;
456 advertising = ADVERTISED_Autoneg |
457 ADVERTISED_1000baseT_Full;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400458 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000459 case I40E_PHY_TYPE_10GBASE_CR1_CU:
460 case I40E_PHY_TYPE_10GBASE_CR1:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100461 supported = SUPPORTED_Autoneg |
462 SUPPORTED_10000baseT_Full;
463 advertising = ADVERTISED_Autoneg |
464 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000465 break;
466 case I40E_PHY_TYPE_XAUI:
467 case I40E_PHY_TYPE_XFI:
468 case I40E_PHY_TYPE_SFI:
469 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000470 case I40E_PHY_TYPE_10GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100471 supported = SUPPORTED_10000baseT_Full;
472 advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000473 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000474 case I40E_PHY_TYPE_SGMII:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100475 supported = SUPPORTED_Autoneg |
476 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000477 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100478 advertising |= ADVERTISED_1000baseT_Full;
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400479 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100480 supported |= SUPPORTED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400481 if (hw_link_info->requested_speeds &
482 I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100483 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400484 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400486 case I40E_PHY_TYPE_40GBASE_KR4:
487 case I40E_PHY_TYPE_20GBASE_KR2:
488 case I40E_PHY_TYPE_10GBASE_KR:
489 case I40E_PHY_TYPE_10GBASE_KX4:
490 case I40E_PHY_TYPE_1000BASE_KX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100491 supported |= SUPPORTED_40000baseKR4_Full |
492 SUPPORTED_20000baseKR2_Full |
493 SUPPORTED_10000baseKR_Full |
494 SUPPORTED_10000baseKX4_Full |
495 SUPPORTED_1000baseKX_Full |
496 SUPPORTED_Autoneg;
497 advertising |= ADVERTISED_40000baseKR4_Full |
498 ADVERTISED_20000baseKR2_Full |
499 ADVERTISED_10000baseKR_Full |
500 ADVERTISED_10000baseKX4_Full |
501 ADVERTISED_1000baseKX_Full |
502 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400503 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800504 case I40E_PHY_TYPE_25GBASE_KR:
505 case I40E_PHY_TYPE_25GBASE_CR:
506 case I40E_PHY_TYPE_25GBASE_SR:
507 case I40E_PHY_TYPE_25GBASE_LR:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100508 supported = SUPPORTED_Autoneg;
509 advertising = ADVERTISED_Autoneg;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800510 /* TODO: add speeds when ethtool is ready to support*/
511 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000512 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000513 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000514 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
515 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000516 }
517
Catherine Sullivan06566e52016-05-03 15:13:14 -0700518 /* Now that we've worked out everything that could be supported by the
519 * current PHY type, get what is supported by the NVM and them to
520 * get what is truly supported
521 */
522 i40e_phy_type_to_ethtool(pf, &e_supported,
523 &e_advertising);
524
Philippe Reynesa7f90942017-02-04 22:05:06 +0100525 supported = supported & e_supported;
526 advertising = advertising & e_advertising;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700527
Catherine Sullivane8278452015-02-06 08:52:08 +0000528 /* Set speed and duplex */
529 switch (link_speed) {
530 case I40E_LINK_SPEED_40GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100531 cmd->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000532 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800533 case I40E_LINK_SPEED_25GB:
534#ifdef SPEED_25000
Philippe Reynesa7f90942017-02-04 22:05:06 +0100535 cmd->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800536#else
537 netdev_info(netdev,
538 "Speed is 25G, display not supported by this version of ethtool.\n");
539#endif
540 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700541 case I40E_LINK_SPEED_20GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100542 cmd->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700543 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000544 case I40E_LINK_SPEED_10GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100545 cmd->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000546 break;
547 case I40E_LINK_SPEED_1GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100548 cmd->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000549 break;
550 case I40E_LINK_SPEED_100MB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100551 cmd->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000552 break;
553 default:
554 break;
555 }
Philippe Reynesa7f90942017-02-04 22:05:06 +0100556 cmd->base.duplex = DUPLEX_FULL;
557
558 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
559 supported);
560 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
561 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000562}
563
564/**
565 * i40e_get_settings_link_down - Get the Link settings for when link is down
566 * @hw: hw structure
567 * @ecmd: ethtool command to fill in
568 *
569 * Reports link settings that can be determined when link is down
570 **/
571static void i40e_get_settings_link_down(struct i40e_hw *hw,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100572 struct ethtool_link_ksettings *cmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400573 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000574{
Philippe Reynesa7f90942017-02-04 22:05:06 +0100575 u32 supported, advertising;
576
Catherine Sullivane8278452015-02-06 08:52:08 +0000577 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400578 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000579 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100580 i40e_phy_type_to_ethtool(pf, &supported, &advertising);
581
582 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
583 supported);
584 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
585 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000586
587 /* With no link speed and duplex are unknown */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100588 cmd->base.speed = SPEED_UNKNOWN;
589 cmd->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000590}
591
592/**
593 * i40e_get_settings - Get Link Speed and Duplex settings
594 * @netdev: network interface device structure
595 * @ecmd: ethtool command
596 *
597 * Reports speed/duplex settings based on media_type
598 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100599static int i40e_get_link_ksettings(struct net_device *netdev,
600 struct ethtool_link_ksettings *cmd)
Catherine Sullivane8278452015-02-06 08:52:08 +0000601{
602 struct i40e_netdev_priv *np = netdev_priv(netdev);
603 struct i40e_pf *pf = np->vsi->back;
604 struct i40e_hw *hw = &pf->hw;
605 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
606 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100607 u32 advertising;
Catherine Sullivane8278452015-02-06 08:52:08 +0000608
609 if (link_up)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100610 i40e_get_settings_link_up(hw, cmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000611 else
Philippe Reynesa7f90942017-02-04 22:05:06 +0100612 i40e_get_settings_link_down(hw, cmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000613
614 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000615 /* Set autoneg settings */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100616 cmd->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000617 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000618
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000619 switch (hw->phy.media_type) {
620 case I40E_MEDIA_TYPE_BACKPLANE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100621 ethtool_link_ksettings_add_link_mode(cmd, supported,
622 Autoneg);
623 ethtool_link_ksettings_add_link_mode(cmd, supported,
624 Backplane);
625 ethtool_link_ksettings_add_link_mode(cmd, advertising,
626 Autoneg);
627 ethtool_link_ksettings_add_link_mode(cmd, advertising,
628 Backplane);
629 cmd->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000630 break;
631 case I40E_MEDIA_TYPE_BASET:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100632 ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
633 ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
634 cmd->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000635 break;
636 case I40E_MEDIA_TYPE_DA:
637 case I40E_MEDIA_TYPE_CX4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100638 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
639 ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
640 cmd->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000641 break;
642 case I40E_MEDIA_TYPE_FIBER:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100643 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
644 cmd->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000645 break;
646 case I40E_MEDIA_TYPE_UNKNOWN:
647 default:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100648 cmd->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000649 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000650 }
651
Catherine Sullivane8278452015-02-06 08:52:08 +0000652 /* Set flow control settings */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100653 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000654
Catherine Sullivane8278452015-02-06 08:52:08 +0000655 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000656 case I40E_FC_FULL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100657 ethtool_link_ksettings_add_link_mode(cmd, advertising,
658 Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000659 break;
660 case I40E_FC_TX_PAUSE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100661 ethtool_link_ksettings_add_link_mode(cmd, advertising,
662 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000663 break;
664 case I40E_FC_RX_PAUSE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100665 ethtool_link_ksettings_add_link_mode(cmd, advertising,
666 Pause);
667 ethtool_link_ksettings_add_link_mode(cmd, advertising,
668 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000669 break;
670 default:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100671 ethtool_convert_link_mode_to_legacy_u32(
672 &advertising, cmd->link_modes.advertising);
673
674 advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
675
676 ethtool_convert_legacy_u32_to_link_mode(
677 cmd->link_modes.advertising, advertising);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000678 break;
679 }
680
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000681 return 0;
682}
683
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000684/**
685 * i40e_set_settings - Set Speed and Duplex
686 * @netdev: network interface device structure
687 * @ecmd: ethtool command
688 *
689 * Set speed/duplex per media_types advertised/forced
690 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100691static int i40e_set_link_ksettings(struct net_device *netdev,
692 const struct ethtool_link_ksettings *cmd)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000693{
694 struct i40e_netdev_priv *np = netdev_priv(netdev);
695 struct i40e_aq_get_phy_abilities_resp abilities;
696 struct i40e_aq_set_phy_config config;
697 struct i40e_pf *pf = np->vsi->back;
698 struct i40e_vsi *vsi = np->vsi;
699 struct i40e_hw *hw = &pf->hw;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100700 struct ethtool_link_ksettings safe_cmd;
701 struct ethtool_link_ksettings copy_cmd;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000702 i40e_status status = 0;
703 bool change = false;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400704 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000705 int err = 0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100706 u32 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000707 u32 advertise;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100708 u32 tmp;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000709
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000710 /* Changing port settings is not supported if this isn't the
711 * port's controlling PF
712 */
713 if (hw->partition_id != 1) {
714 i40e_partition_setting_complaint(pf);
715 return -EOPNOTSUPP;
716 }
717
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000718 if (vsi != pf->vsi[pf->lan_vsi])
719 return -EOPNOTSUPP;
720
721 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
722 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000723 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700724 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000725 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000726 return -EOPNOTSUPP;
727
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400728 if (hw->device_id == I40E_DEV_ID_KX_B ||
729 hw->device_id == I40E_DEV_ID_KX_C ||
730 hw->device_id == I40E_DEV_ID_20G_KR2 ||
731 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
732 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
733 return -EOPNOTSUPP;
734 }
735
Philippe Reynesa7f90942017-02-04 22:05:06 +0100736 /* copy the cmd to copy_cmd to avoid modifying the origin */
737 memcpy(&copy_cmd, cmd, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000738
Philippe Reynesa7f90942017-02-04 22:05:06 +0100739 /* get our own copy of the bits to check against */
740 memset(&safe_cmd, 0, sizeof(struct ethtool_link_ksettings));
741 i40e_get_link_ksettings(netdev, &safe_cmd);
742
743 /* save autoneg and speed out of cmd */
744 autoneg = cmd->base.autoneg;
745 ethtool_convert_link_mode_to_legacy_u32(&advertise,
746 cmd->link_modes.advertising);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000747
748 /* set autoneg and speed back to what they currently are */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100749 copy_cmd.base.autoneg = safe_cmd.base.autoneg;
750 ethtool_convert_link_mode_to_legacy_u32(
751 &tmp, safe_cmd.link_modes.advertising);
752 ethtool_convert_legacy_u32_to_link_mode(
753 copy_cmd.link_modes.advertising, tmp);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000754
Philippe Reynesa7f90942017-02-04 22:05:06 +0100755 copy_cmd.base.cmd = safe_cmd.base.cmd;
756
757 /* If copy_cmd and safe_cmd are not the same now, then they are
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000758 * trying to set something that we do not support
759 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100760 if (memcmp(&copy_cmd, &safe_cmd, sizeof(struct ethtool_link_ksettings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000761 return -EOPNOTSUPP;
762
Jacob Keller0da36b92017-04-19 09:25:55 -0400763 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400764 timeout--;
765 if (!timeout)
766 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000767 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400768 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000769
770 /* Get the current phy config */
771 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
772 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400773 if (status) {
774 err = -EAGAIN;
775 goto done;
776 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000777
Catherine Sullivan124ed152014-07-12 07:28:12 +0000778 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000779 * set below
780 */
781 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000782 config.abilities = abilities.abilities;
783
784 /* Check autoneg */
785 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000786 /* If autoneg was not already enabled */
787 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400788 /* If autoneg is not supported, return error */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100789 if (!ethtool_link_ksettings_test_link_mode(
790 &safe_cmd, supported, Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400791 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400792 err = -EINVAL;
793 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400794 }
795 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000796 config.abilities = abilities.abilities |
797 I40E_AQ_PHY_ENABLE_AN;
798 change = true;
799 }
800 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000801 /* If autoneg is currently enabled */
802 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400803 /* If autoneg is supported 10GBASE_T is the only PHY
804 * that can disable it, so otherwise return error
805 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100806 if (ethtool_link_ksettings_test_link_mode(
807 &safe_cmd, supported, Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400808 hw->phy.link_info.phy_type !=
809 I40E_PHY_TYPE_10GBASE_T) {
810 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400811 err = -EINVAL;
812 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400813 }
814 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000815 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000816 ~I40E_AQ_PHY_ENABLE_AN;
817 change = true;
818 }
819 }
820
Philippe Reynesa7f90942017-02-04 22:05:06 +0100821 ethtool_convert_link_mode_to_legacy_u32(&tmp,
822 safe_cmd.link_modes.supported);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400823 if (advertise & ~tmp) {
824 err = -EINVAL;
825 goto done;
826 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000827
828 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000829 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000830 if (advertise & ADVERTISED_1000baseT_Full ||
831 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000832 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000833 if (advertise & ADVERTISED_10000baseT_Full ||
834 advertise & ADVERTISED_10000baseKX4_Full ||
835 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000836 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700837 if (advertise & ADVERTISED_20000baseKR2_Full)
838 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000839 if (advertise & ADVERTISED_40000baseKR4_Full ||
840 advertise & ADVERTISED_40000baseCR4_Full ||
841 advertise & ADVERTISED_40000baseSR4_Full ||
842 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000843 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000844
Catherine Sullivan0002e112015-08-26 15:14:16 -0400845 /* If speed didn't get set, set it to what it currently is.
846 * This is needed because if advertise is 0 (as it is when autoneg
847 * is disabled) then speed won't get set.
848 */
849 if (!config.link_speed)
850 config.link_speed = abilities.link_speed;
851
Catherine Sullivan124ed152014-07-12 07:28:12 +0000852 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000853 /* copy over the rest of the abilities */
854 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800855 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000856 config.eee_capability = abilities.eee_capability;
857 config.eeer = abilities.eeer_val;
858 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800859 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
860 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000861
Catherine Sullivane8278452015-02-06 08:52:08 +0000862 /* save the requested speeds */
863 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000864 /* set link and auto negotiation so changes take effect */
865 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
866 /* If link is up put link down */
867 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
868 /* Tell the OS link is going down, the link will go
869 * back up when fw says it is ready asynchronously
870 */
Matt Jaredc156f852015-08-27 11:42:39 -0400871 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000872 netif_carrier_off(netdev);
873 netif_tx_stop_all_queues(netdev);
874 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000875
876 /* make the aq call */
877 status = i40e_aq_set_phy_config(hw, &config, NULL);
878 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400879 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
880 i40e_stat_str(hw, status),
881 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400882 err = -EAGAIN;
883 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000884 }
885
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400886 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000887 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400888 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
889 i40e_stat_str(hw, status),
890 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000891
892 } else {
893 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
894 }
895
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400896done:
Jacob Keller0da36b92017-04-19 09:25:55 -0400897 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400898
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000899 return err;
900}
901
Jesse Brandeburga6599722014-06-04 08:45:25 +0000902static int i40e_nway_reset(struct net_device *netdev)
903{
904 /* restart autonegotiation */
905 struct i40e_netdev_priv *np = netdev_priv(netdev);
906 struct i40e_pf *pf = np->vsi->back;
907 struct i40e_hw *hw = &pf->hw;
908 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
909 i40e_status ret = 0;
910
911 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
912 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400913 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
914 i40e_stat_str(hw, ret),
915 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000916 return -EIO;
917 }
918
919 return 0;
920}
921
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000922/**
923 * i40e_get_pauseparam - Get Flow Control status
924 * Return tx/rx-pause status
925 **/
926static void i40e_get_pauseparam(struct net_device *netdev,
927 struct ethtool_pauseparam *pause)
928{
929 struct i40e_netdev_priv *np = netdev_priv(netdev);
930 struct i40e_pf *pf = np->vsi->back;
931 struct i40e_hw *hw = &pf->hw;
932 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000933 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000934
935 pause->autoneg =
936 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
937 AUTONEG_ENABLE : AUTONEG_DISABLE);
938
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000939 /* PFC enabled so report LFC as off */
940 if (dcbx_cfg->pfc.pfcenable) {
941 pause->rx_pause = 0;
942 pause->tx_pause = 0;
943 return;
944 }
945
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000946 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000947 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000948 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000949 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000950 } else if (hw->fc.current_mode == I40E_FC_FULL) {
951 pause->rx_pause = 1;
952 pause->tx_pause = 1;
953 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000954}
955
Catherine Sullivan2becc352014-06-04 08:45:27 +0000956/**
957 * i40e_set_pauseparam - Set Flow Control parameter
958 * @netdev: network interface device structure
959 * @pause: return tx/rx flow control status
960 **/
961static int i40e_set_pauseparam(struct net_device *netdev,
962 struct ethtool_pauseparam *pause)
963{
964 struct i40e_netdev_priv *np = netdev_priv(netdev);
965 struct i40e_pf *pf = np->vsi->back;
966 struct i40e_vsi *vsi = np->vsi;
967 struct i40e_hw *hw = &pf->hw;
968 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000969 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000970 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
971 i40e_status status;
972 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000973 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000974
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000975 /* Changing the port's flow control is not supported if this isn't the
976 * port's controlling PF
977 */
978 if (hw->partition_id != 1) {
979 i40e_partition_setting_complaint(pf);
980 return -EOPNOTSUPP;
981 }
982
Catherine Sullivan2becc352014-06-04 08:45:27 +0000983 if (vsi != pf->vsi[pf->lan_vsi])
984 return -EOPNOTSUPP;
985
986 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
987 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
988 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
989 return -EOPNOTSUPP;
990 }
991
992 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -0400993 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +0000994 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
995 /* Send message that it might not necessarily work*/
996 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
997 }
998
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000999 if (dcbx_cfg->pfc.pfcenable) {
1000 netdev_info(netdev,
1001 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001002 return -EOPNOTSUPP;
1003 }
1004
1005 if (pause->rx_pause && pause->tx_pause)
1006 hw->fc.requested_mode = I40E_FC_FULL;
1007 else if (pause->rx_pause && !pause->tx_pause)
1008 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1009 else if (!pause->rx_pause && pause->tx_pause)
1010 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1011 else if (!pause->rx_pause && !pause->tx_pause)
1012 hw->fc.requested_mode = I40E_FC_NONE;
1013 else
1014 return -EINVAL;
1015
Catherine Sullivan94128512014-07-12 07:28:16 +00001016 /* Tell the OS link is going down, the link will go back up when fw
1017 * says it is ready asynchronously
1018 */
Matt Jaredc156f852015-08-27 11:42:39 -04001019 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001020 netif_carrier_off(netdev);
1021 netif_tx_stop_all_queues(netdev);
1022
Catherine Sullivan2becc352014-06-04 08:45:27 +00001023 /* Set the fc mode and only restart an if link is up*/
1024 status = i40e_set_fc(hw, &aq_failures, link_up);
1025
1026 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001027 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1028 i40e_stat_str(hw, status),
1029 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001030 err = -EAGAIN;
1031 }
1032 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001033 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1034 i40e_stat_str(hw, status),
1035 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001036 err = -EAGAIN;
1037 }
1038 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001039 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1040 i40e_stat_str(hw, status),
1041 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001042 err = -EAGAIN;
1043 }
1044
Jacob Keller0da36b92017-04-19 09:25:55 -04001045 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001046 /* Give it a little more time to try to come back */
1047 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001048 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001049 return i40e_nway_reset(netdev);
1050 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001051
1052 return err;
1053}
1054
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001055static u32 i40e_get_msglevel(struct net_device *netdev)
1056{
1057 struct i40e_netdev_priv *np = netdev_priv(netdev);
1058 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001059 u32 debug_mask = pf->hw.debug_mask;
1060
1061 if (debug_mask)
1062 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063
1064 return pf->msg_enable;
1065}
1066
1067static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1068{
1069 struct i40e_netdev_priv *np = netdev_priv(netdev);
1070 struct i40e_pf *pf = np->vsi->back;
1071
1072 if (I40E_DEBUG_USER & data)
1073 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001074 else
1075 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001076}
1077
1078static int i40e_get_regs_len(struct net_device *netdev)
1079{
1080 int reg_count = 0;
1081 int i;
1082
1083 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1084 reg_count += i40e_reg_list[i].elements;
1085
1086 return reg_count * sizeof(u32);
1087}
1088
1089static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1090 void *p)
1091{
1092 struct i40e_netdev_priv *np = netdev_priv(netdev);
1093 struct i40e_pf *pf = np->vsi->back;
1094 struct i40e_hw *hw = &pf->hw;
1095 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001096 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001097 u32 reg;
1098
1099 /* Tell ethtool which driver-version-specific regs output we have.
1100 *
1101 * At some point, if we have ethtool doing special formatting of
1102 * this data, it will rely on this version number to know how to
1103 * interpret things. Hence, this needs to be updated if/when the
1104 * diags register table is changed.
1105 */
1106 regs->version = 1;
1107
1108 /* loop through the diags reg table for what to print */
1109 ri = 0;
1110 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1111 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1112 reg = i40e_reg_list[i].offset
1113 + (j * i40e_reg_list[i].stride);
1114 reg_buf[ri++] = rd32(hw, reg);
1115 }
1116 }
1117
1118}
1119
1120static int i40e_get_eeprom(struct net_device *netdev,
1121 struct ethtool_eeprom *eeprom, u8 *bytes)
1122{
1123 struct i40e_netdev_priv *np = netdev_priv(netdev);
1124 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001125 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001126 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001127 u8 *eeprom_buff;
1128 u16 i, sectors;
1129 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001130 u32 magic;
1131
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001132#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001133 if (eeprom->len == 0)
1134 return -EINVAL;
1135
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001136 /* check for NVMUpdate access method */
1137 magic = hw->vendor_id | (hw->device_id << 16);
1138 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001139 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1140 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001141
1142 /* make sure it is the right magic for NVMUpdate */
1143 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001144 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001145 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1146 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001147 errno = -EBUSY;
1148 else
1149 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001150
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001151 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001152 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001153 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1154 ret_val, hw->aq.asq_last_status, errno,
1155 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1156 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001157
1158 return errno;
1159 }
1160
1161 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001162 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1163
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001164 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001165 if (!eeprom_buff)
1166 return -ENOMEM;
1167
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001168 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1169 if (ret_val) {
1170 dev_info(&pf->pdev->dev,
1171 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1172 ret_val, hw->aq.asq_last_status);
1173 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001174 }
1175
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001176 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1177 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1178 len = I40E_NVM_SECTOR_SIZE;
1179 last = false;
1180 for (i = 0; i < sectors; i++) {
1181 if (i == (sectors - 1)) {
1182 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1183 last = true;
1184 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001185 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1186 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001187 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001188 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001189 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001190 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001191 "read NVM failed, invalid offset 0x%x\n",
1192 offset);
1193 break;
1194 } else if (ret_val &&
1195 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1196 dev_info(&pf->pdev->dev,
1197 "read NVM failed, access, offset 0x%x\n",
1198 offset);
1199 break;
1200 } else if (ret_val) {
1201 dev_info(&pf->pdev->dev,
1202 "read NVM failed offset %d err=%d status=0x%x\n",
1203 offset, ret_val, hw->aq.asq_last_status);
1204 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001205 }
1206 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001207
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001208 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001209 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001210free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001211 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001212 return ret_val;
1213}
1214
1215static int i40e_get_eeprom_len(struct net_device *netdev)
1216{
1217 struct i40e_netdev_priv *np = netdev_priv(netdev);
1218 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001219 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001220
Lihong Yangc271dd62017-01-30 12:29:32 -08001221#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1222 if (hw->mac.type == I40E_MAC_X722) {
1223 val = X722_EEPROM_SCOPE_LIMIT + 1;
1224 return val;
1225 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001226 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1227 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1228 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1229 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001230 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001231 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232}
1233
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001234static int i40e_set_eeprom(struct net_device *netdev,
1235 struct ethtool_eeprom *eeprom, u8 *bytes)
1236{
1237 struct i40e_netdev_priv *np = netdev_priv(netdev);
1238 struct i40e_hw *hw = &np->vsi->back->hw;
1239 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001240 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001241 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001242 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001243 u32 magic;
1244
1245 /* normal ethtool set_eeprom is not supported */
1246 magic = hw->vendor_id | (hw->device_id << 16);
1247 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001248 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001249 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001250 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1251 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001252 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1253 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001254 errno = -EBUSY;
1255 else
1256 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001257
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001258 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001259 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001260 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1261 ret_val, hw->aq.asq_last_status, errno,
1262 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1263 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001264
1265 return errno;
1266}
1267
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001268static void i40e_get_drvinfo(struct net_device *netdev,
1269 struct ethtool_drvinfo *drvinfo)
1270{
1271 struct i40e_netdev_priv *np = netdev_priv(netdev);
1272 struct i40e_vsi *vsi = np->vsi;
1273 struct i40e_pf *pf = vsi->back;
1274
1275 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1276 strlcpy(drvinfo->version, i40e_driver_version_str,
1277 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001278 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001279 sizeof(drvinfo->fw_version));
1280 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1281 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001282 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001283 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001284 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001285}
1286
1287static void i40e_get_ringparam(struct net_device *netdev,
1288 struct ethtool_ringparam *ring)
1289{
1290 struct i40e_netdev_priv *np = netdev_priv(netdev);
1291 struct i40e_pf *pf = np->vsi->back;
1292 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1293
1294 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1295 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1296 ring->rx_mini_max_pending = 0;
1297 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001298 ring->rx_pending = vsi->rx_rings[0]->count;
1299 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001300 ring->rx_mini_pending = 0;
1301 ring->rx_jumbo_pending = 0;
1302}
1303
Björn Töpel74608d12017-05-24 07:55:35 +02001304static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1305{
1306 if (i40e_enabled_xdp_vsi(vsi)) {
1307 return index < vsi->num_queue_pairs ||
1308 (index >= vsi->alloc_queue_pairs &&
1309 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1310 }
1311
1312 return index < vsi->num_queue_pairs;
1313}
1314
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001315static int i40e_set_ringparam(struct net_device *netdev,
1316 struct ethtool_ringparam *ring)
1317{
1318 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1319 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001320 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001321 struct i40e_vsi *vsi = np->vsi;
1322 struct i40e_pf *pf = vsi->back;
1323 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001324 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001325 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001326 int i, err = 0;
1327
1328 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1329 return -EINVAL;
1330
Shannon Nelson1fa18372013-11-20 10:03:08 +00001331 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1332 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1333 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1334 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1335 netdev_info(netdev,
1336 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1337 ring->tx_pending, ring->rx_pending,
1338 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1339 return -EINVAL;
1340 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341
Shannon Nelson1fa18372013-11-20 10:03:08 +00001342 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1343 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001344
1345 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001346 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1347 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 return 0;
1349
Jacob Keller0da36b92017-04-19 09:25:55 -04001350 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001351 timeout--;
1352 if (!timeout)
1353 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001354 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001355 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001356
1357 if (!netif_running(vsi->netdev)) {
1358 /* simple case - set for the next time the netdev is started */
1359 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001360 vsi->tx_rings[i]->count = new_tx_count;
1361 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001362 if (i40e_enabled_xdp_vsi(vsi))
1363 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001364 }
1365 goto done;
1366 }
1367
1368 /* We can't just free everything and then setup again,
1369 * because the ISRs in MSI-X mode get passed pointers
1370 * to the Tx and Rx ring structs.
1371 */
1372
Björn Töpel74608d12017-05-24 07:55:35 +02001373 /* alloc updated Tx and XDP Tx resources */
1374 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1375 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001376 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001377 netdev_info(netdev,
1378 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001379 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001380 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001381 sizeof(struct i40e_ring), GFP_KERNEL);
1382 if (!tx_rings) {
1383 err = -ENOMEM;
1384 goto done;
1385 }
1386
Björn Töpel74608d12017-05-24 07:55:35 +02001387 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1388 if (!i40e_active_tx_ring_index(vsi, i))
1389 continue;
1390
Alexander Duyck9f65e152013-09-28 06:00:58 +00001391 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001392 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001393 /* the desc and bi pointers will be reallocated in the
1394 * setup call
1395 */
1396 tx_rings[i].desc = NULL;
1397 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001398 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1399 if (err) {
1400 while (i) {
1401 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001402 if (!i40e_active_tx_ring_index(vsi, i))
1403 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001404 i40e_free_tx_resources(&tx_rings[i]);
1405 }
1406 kfree(tx_rings);
1407 tx_rings = NULL;
1408
1409 goto done;
1410 }
1411 }
1412 }
1413
1414 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001415 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001416 netdev_info(netdev,
1417 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001418 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001419 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1420 sizeof(struct i40e_ring), GFP_KERNEL);
1421 if (!rx_rings) {
1422 err = -ENOMEM;
1423 goto free_tx;
1424 }
1425
1426 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001427 struct i40e_ring *ring;
1428 u16 unused;
1429
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001430 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001431 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001432 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001433 /* the desc and bi pointers will be reallocated in the
1434 * setup call
1435 */
1436 rx_rings[i].desc = NULL;
1437 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001438 /* this is to allow wr32 to have something to write to
1439 * during early allocation of Rx buffers
1440 */
1441 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001442 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001443 if (err)
1444 goto rx_unwind;
1445
1446 /* now allocate the Rx buffers to make sure the OS
1447 * has enough memory, any failure here means abort
1448 */
1449 ring = &rx_rings[i];
1450 unused = I40E_DESC_UNUSED(ring);
1451 err = i40e_alloc_rx_buffers(ring, unused);
1452rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001453 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001454 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001455 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001456 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 kfree(rx_rings);
1458 rx_rings = NULL;
1459
1460 goto free_tx;
1461 }
1462 }
1463 }
1464
1465 /* Bring interface down, copy in the new ring info,
1466 * then restore the interface
1467 */
1468 i40e_down(vsi);
1469
1470 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001471 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1472 if (i40e_active_tx_ring_index(vsi, i)) {
1473 i40e_free_tx_resources(vsi->tx_rings[i]);
1474 *vsi->tx_rings[i] = tx_rings[i];
1475 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001476 }
1477 kfree(tx_rings);
1478 tx_rings = NULL;
1479 }
1480
1481 if (rx_rings) {
1482 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001483 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001484 /* get the real tail offset */
1485 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1486 /* this is to fake out the allocation routine
1487 * into thinking it has to realloc everything
1488 * but the recycling logic will let us re-use
1489 * the buffers allocated above
1490 */
1491 rx_rings[i].next_to_use = 0;
1492 rx_rings[i].next_to_clean = 0;
1493 rx_rings[i].next_to_alloc = 0;
1494 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001495 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001496 }
1497 kfree(rx_rings);
1498 rx_rings = NULL;
1499 }
1500
1501 i40e_up(vsi);
1502
1503free_tx:
1504 /* error cleanup if the Rx allocations failed after getting Tx */
1505 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001506 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1507 if (i40e_active_tx_ring_index(vsi, i))
1508 i40e_free_tx_resources(vsi->tx_rings[i]);
1509 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001510 kfree(tx_rings);
1511 tx_rings = NULL;
1512 }
1513
1514done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001515 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516
1517 return err;
1518}
1519
1520static int i40e_get_sset_count(struct net_device *netdev, int sset)
1521{
1522 struct i40e_netdev_priv *np = netdev_priv(netdev);
1523 struct i40e_vsi *vsi = np->vsi;
1524 struct i40e_pf *pf = vsi->back;
1525
1526 switch (sset) {
1527 case ETH_SS_TEST:
1528 return I40E_TEST_LEN;
1529 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001530 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001531 int len = I40E_PF_STATS_LEN(netdev);
1532
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001533 if ((pf->lan_veb != I40E_NO_VEB) &&
1534 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001535 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001536 return len;
1537 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001538 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001539 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001540 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001541 return I40E_PRIV_FLAGS_STR_LEN +
1542 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543 default:
1544 return -EOPNOTSUPP;
1545 }
1546}
1547
1548static void i40e_get_ethtool_stats(struct net_device *netdev,
1549 struct ethtool_stats *stats, u64 *data)
1550{
1551 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001552 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001553 struct i40e_vsi *vsi = np->vsi;
1554 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001555 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556 int i = 0;
1557 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001559 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001560
1561 i40e_update_stats(vsi);
1562
1563 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1564 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1565 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1566 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1567 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001568 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1569 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1570 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1571 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1572 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001573 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001574 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001575 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001576
1577 if (!tx_ring)
1578 continue;
1579
1580 /* process Tx ring statistics */
1581 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001582 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001583 data[i] = tx_ring->stats.packets;
1584 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001585 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001586 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001587
1588 /* Rx ring is the 2nd half of the queue pair */
1589 rx_ring = &tx_ring[1];
1590 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001591 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001592 data[i] = rx_ring->stats.packets;
1593 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001594 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001595 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001597 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001598 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001599 return;
1600
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001601 if ((pf->lan_veb != I40E_NO_VEB) &&
1602 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001603 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001604
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001605 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1606 p = (char *)veb;
1607 p += i40e_gstrings_veb_stats[j].stat_offset;
1608 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1609 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001610 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001611 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1612 data[i++] = veb->tc_stats.tc_tx_packets[j];
1613 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1614 data[i++] = veb->tc_stats.tc_rx_packets[j];
1615 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1616 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001617 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001618 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1619 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1620 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1621 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1622 }
1623 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1624 data[i++] = pf->stats.priority_xon_tx[j];
1625 data[i++] = pf->stats.priority_xoff_tx[j];
1626 }
1627 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1628 data[i++] = pf->stats.priority_xon_rx[j];
1629 data[i++] = pf->stats.priority_xoff_rx[j];
1630 }
1631 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1632 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633}
1634
1635static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1636 u8 *data)
1637{
1638 struct i40e_netdev_priv *np = netdev_priv(netdev);
1639 struct i40e_vsi *vsi = np->vsi;
1640 struct i40e_pf *pf = vsi->back;
1641 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001642 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001643
1644 switch (stringset) {
1645 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001646 memcpy(data, i40e_gstrings_test,
1647 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001648 break;
1649 case ETH_SS_STATS:
1650 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1651 snprintf(p, ETH_GSTRING_LEN, "%s",
1652 i40e_gstrings_net_stats[i].stat_string);
1653 p += ETH_GSTRING_LEN;
1654 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001655 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1656 snprintf(p, ETH_GSTRING_LEN, "%s",
1657 i40e_gstrings_misc_stats[i].stat_string);
1658 p += ETH_GSTRING_LEN;
1659 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001660 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001661 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001663 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001664 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001665 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001666 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001667 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668 p += ETH_GSTRING_LEN;
1669 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001670 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001671 return;
1672
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001673 if ((pf->lan_veb != I40E_NO_VEB) &&
1674 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001675 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1676 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1677 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001678 p += ETH_GSTRING_LEN;
1679 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001680 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1681 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001682 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001683 p += ETH_GSTRING_LEN;
1684 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001685 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001686 p += ETH_GSTRING_LEN;
1687 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001688 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001689 p += ETH_GSTRING_LEN;
1690 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001691 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001692 p += ETH_GSTRING_LEN;
1693 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001694 }
1695 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1696 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1697 i40e_gstrings_stats[i].stat_string);
1698 p += ETH_GSTRING_LEN;
1699 }
1700 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1701 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001702 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001703 p += ETH_GSTRING_LEN;
1704 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001705 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001706 p += ETH_GSTRING_LEN;
1707 }
1708 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1709 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001710 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001711 p += ETH_GSTRING_LEN;
1712 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001713 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001714 p += ETH_GSTRING_LEN;
1715 }
1716 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1717 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001718 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001719 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001720 }
1721 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1722 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001723 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001724 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1725 snprintf(p, ETH_GSTRING_LEN, "%s",
1726 i40e_gstrings_priv_flags[i].flag_string);
1727 p += ETH_GSTRING_LEN;
1728 }
1729 if (pf->hw.pf_id != 0)
1730 break;
1731 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1732 snprintf(p, ETH_GSTRING_LEN, "%s",
1733 i40e_gl_gstrings_priv_flags[i].flag_string);
1734 p += ETH_GSTRING_LEN;
1735 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001736 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001737 default:
1738 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001739 }
1740}
1741
1742static int i40e_get_ts_info(struct net_device *dev,
1743 struct ethtool_ts_info *info)
1744{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001745 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1746
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001747 /* only report HW timestamping if PTP is enabled */
1748 if (!(pf->flags & I40E_FLAG_PTP))
1749 return ethtool_op_get_ts_info(dev, info);
1750
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001751 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1752 SOF_TIMESTAMPING_RX_SOFTWARE |
1753 SOF_TIMESTAMPING_SOFTWARE |
1754 SOF_TIMESTAMPING_TX_HARDWARE |
1755 SOF_TIMESTAMPING_RX_HARDWARE |
1756 SOF_TIMESTAMPING_RAW_HARDWARE;
1757
1758 if (pf->ptp_clock)
1759 info->phc_index = ptp_clock_index(pf->ptp_clock);
1760 else
1761 info->phc_index = -1;
1762
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001763 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001764
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001765 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001766 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1767 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1768 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1769
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001770 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001771 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1772 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1773 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1774 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1775 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1776 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1777 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1778 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001779
1780 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001781}
1782
Shannon Nelson7b086392013-11-20 10:02:59 +00001783static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001784{
Shannon Nelson7b086392013-11-20 10:02:59 +00001785 struct i40e_netdev_priv *np = netdev_priv(netdev);
1786 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001787 i40e_status status;
1788 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001789
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001790 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001791 status = i40e_get_link_status(&pf->hw, &link_up);
1792 if (status) {
1793 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1794 *data = 1;
1795 return *data;
1796 }
1797
1798 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001799 *data = 0;
1800 else
1801 *data = 1;
1802
1803 return *data;
1804}
1805
Shannon Nelson7b086392013-11-20 10:02:59 +00001806static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807{
Shannon Nelson7b086392013-11-20 10:02:59 +00001808 struct i40e_netdev_priv *np = netdev_priv(netdev);
1809 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001810
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001811 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001812 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001813
Shannon Nelson7b086392013-11-20 10:02:59 +00001814 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001815}
1816
Shannon Nelson7b086392013-11-20 10:02:59 +00001817static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001818{
Shannon Nelson7b086392013-11-20 10:02:59 +00001819 struct i40e_netdev_priv *np = netdev_priv(netdev);
1820 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001821
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001822 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001823 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001824
Shannon Nelson4443ec92014-11-13 08:23:12 +00001825 /* forcebly clear the NVM Update state machine */
1826 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1827
Shannon Nelson7b086392013-11-20 10:02:59 +00001828 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829}
1830
Shannon Nelson7b086392013-11-20 10:02:59 +00001831static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001832{
Shannon Nelson7b086392013-11-20 10:02:59 +00001833 struct i40e_netdev_priv *np = netdev_priv(netdev);
1834 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001835 u16 swc_old = pf->sw_int_count;
1836
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001837 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001838 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1839 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001840 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1841 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1842 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1843 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001844 usleep_range(1000, 2000);
1845 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001846
1847 return *data;
1848}
1849
Greg Rosee17bc412015-04-16 20:05:59 -04001850static inline bool i40e_active_vfs(struct i40e_pf *pf)
1851{
1852 struct i40e_vf *vfs = pf->vf;
1853 int i;
1854
1855 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001856 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001857 return true;
1858 return false;
1859}
1860
Greg Rose510efb22015-07-10 19:36:01 -04001861static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1862{
Alexander Duyck4b816442016-10-11 15:26:53 -07001863 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001864}
1865
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001866static void i40e_diag_test(struct net_device *netdev,
1867 struct ethtool_test *eth_test, u64 *data)
1868{
1869 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001870 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001871 struct i40e_pf *pf = np->vsi->back;
1872
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001873 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1874 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001875 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001876
Jacob Keller0da36b92017-04-19 09:25:55 -04001877 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001878
Greg Rose510efb22015-07-10 19:36:01 -04001879 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001880 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001881 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001882 data[I40E_ETH_TEST_REG] = 1;
1883 data[I40E_ETH_TEST_EEPROM] = 1;
1884 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001885 data[I40E_ETH_TEST_LINK] = 1;
1886 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04001887 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001888 goto skip_ol_tests;
1889 }
1890
Greg Rose5b86c5c2015-02-26 16:14:35 +00001891 /* If the device is online then take it offline */
1892 if (if_running)
1893 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001894 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001895 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001896 /* This reset does not affect link - if it is
1897 * changed to a type of reset that does affect
1898 * link then the following link test would have
1899 * to be moved to before the reset
1900 */
Maciej Sosin373149f2017-04-05 07:50:55 -04001901 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00001902
Shannon Nelson7b086392013-11-20 10:02:59 +00001903 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001904 eth_test->flags |= ETH_TEST_FL_FAILED;
1905
Shannon Nelson7b086392013-11-20 10:02:59 +00001906 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001907 eth_test->flags |= ETH_TEST_FL_FAILED;
1908
Shannon Nelson7b086392013-11-20 10:02:59 +00001909 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001910 eth_test->flags |= ETH_TEST_FL_FAILED;
1911
Shannon Nelsonf551b432013-11-26 10:49:12 +00001912 /* run reg test last, a reset is required after it */
1913 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1914 eth_test->flags |= ETH_TEST_FL_FAILED;
1915
Jacob Keller0da36b92017-04-19 09:25:55 -04001916 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04001917 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001918
1919 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001920 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001921 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001922 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001923 netif_info(pf, drv, netdev, "online testing starting\n");
1924
Shannon Nelson7b086392013-11-20 10:02:59 +00001925 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001926 eth_test->flags |= ETH_TEST_FL_FAILED;
1927
1928 /* Offline only tests, not run in online; pass by default */
1929 data[I40E_ETH_TEST_REG] = 0;
1930 data[I40E_ETH_TEST_EEPROM] = 0;
1931 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001932 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001933
Greg Rosee17bc412015-04-16 20:05:59 -04001934skip_ol_tests:
1935
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001936 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001937}
1938
1939static void i40e_get_wol(struct net_device *netdev,
1940 struct ethtool_wolinfo *wol)
1941{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001942 struct i40e_netdev_priv *np = netdev_priv(netdev);
1943 struct i40e_pf *pf = np->vsi->back;
1944 struct i40e_hw *hw = &pf->hw;
1945 u16 wol_nvm_bits;
1946
1947 /* NVM bit on means WoL disabled for the port */
1948 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001949 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001950 wol->supported = 0;
1951 wol->wolopts = 0;
1952 } else {
1953 wol->supported = WAKE_MAGIC;
1954 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1955 }
1956}
1957
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001958/**
1959 * i40e_set_wol - set the WakeOnLAN configuration
1960 * @netdev: the netdev in question
1961 * @wol: the ethtool WoL setting data
1962 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001963static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1964{
1965 struct i40e_netdev_priv *np = netdev_priv(netdev);
1966 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001967 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001968 struct i40e_hw *hw = &pf->hw;
1969 u16 wol_nvm_bits;
1970
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001971 /* WoL not supported if this isn't the controlling PF on the port */
1972 if (hw->partition_id != 1) {
1973 i40e_partition_setting_complaint(pf);
1974 return -EOPNOTSUPP;
1975 }
1976
1977 if (vsi != pf->vsi[pf->lan_vsi])
1978 return -EOPNOTSUPP;
1979
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001980 /* NVM bit on means WoL disabled for the port */
1981 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001982 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001983 return -EOPNOTSUPP;
1984
1985 /* only magic packet is supported */
1986 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1987 return -EOPNOTSUPP;
1988
1989 /* is this a new value? */
1990 if (pf->wol_en != !!wol->wolopts) {
1991 pf->wol_en = !!wol->wolopts;
1992 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1993 }
1994
1995 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001996}
1997
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998static int i40e_set_phys_id(struct net_device *netdev,
1999 enum ethtool_phys_id_state state)
2000{
2001 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002002 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002003 struct i40e_pf *pf = np->vsi->back;
2004 struct i40e_hw *hw = &pf->hw;
2005 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002006 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002007
2008 switch (state) {
2009 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002010 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002011 pf->led_status = i40e_led_get(hw);
2012 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002013 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2014 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2015 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002016 ret = i40e_led_get_phy(hw, &temp_status,
2017 &pf->phy_led_val);
2018 pf->led_status = temp_status;
2019 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002020 return blink_freq;
2021 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002022 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002023 i40e_led_set(hw, 0xf, false);
2024 else
2025 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002026 break;
2027 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002028 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002029 i40e_led_set(hw, 0x0, false);
2030 else
2031 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002032 break;
2033 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002034 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002035 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002036 } else {
2037 ret = i40e_led_set_phy(hw, false, pf->led_status,
2038 (pf->phy_led_val |
2039 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002040 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2041 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002042 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002043 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002044 default:
2045 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002046 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002047 if (ret)
2048 return -ENOENT;
2049 else
2050 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002051}
2052
2053/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2054 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2055 * 125us (8000 interrupts per second) == ITR(62)
2056 */
2057
Jacob Keller65e87c02016-09-12 14:18:44 -07002058/**
2059 * __i40e_get_coalesce - get per-queue coalesce settings
2060 * @netdev: the netdev to check
2061 * @ec: ethtool coalesce data structure
2062 * @queue: which queue to pick
2063 *
2064 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2065 * are per queue. If queue is <0 then we default to queue 0 as the
2066 * representative value.
2067 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002068static int __i40e_get_coalesce(struct net_device *netdev,
2069 struct ethtool_coalesce *ec,
2070 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002071{
2072 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002073 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002074 struct i40e_vsi *vsi = np->vsi;
2075
2076 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2077 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2078
Kan Lianga75e8002016-02-19 09:24:04 -05002079 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2080 * return queue 0's value to represent.
2081 */
2082 if (queue < 0) {
2083 queue = 0;
2084 } else if (queue >= vsi->num_queue_pairs) {
2085 return -EINVAL;
2086 }
2087
Jacob Keller65e87c02016-09-12 14:18:44 -07002088 rx_ring = vsi->rx_rings[queue];
2089 tx_ring = vsi->tx_rings[queue];
2090
2091 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002092 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002093
Jacob Keller65e87c02016-09-12 14:18:44 -07002094 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002095 ec->use_adaptive_tx_coalesce = 1;
2096
Jacob Keller65e87c02016-09-12 14:18:44 -07002097 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2098 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2099
Kan Lianga75e8002016-02-19 09:24:04 -05002100
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002101 /* we use the _usecs_high to store/set the interrupt rate limit
2102 * that the hardware supports, that almost but not quite
2103 * fits the original intent of the ethtool variable,
2104 * the rx_coalesce_usecs_high limits total interrupts
2105 * per second from both tx/rx sources.
2106 */
2107 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2108 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002109
2110 return 0;
2111}
2112
Jacob Keller65e87c02016-09-12 14:18:44 -07002113/**
2114 * i40e_get_coalesce - get a netdev's coalesce settings
2115 * @netdev: the netdev to check
2116 * @ec: ethtool coalesce data structure
2117 *
2118 * Gets the coalesce settings for a particular netdev. Note that if user has
2119 * modified per-queue settings, this only guarantees to represent queue 0. See
2120 * __i40e_get_coalesce for more details.
2121 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002122static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002123 struct ethtool_coalesce *ec)
2124{
Kan Lianga75e8002016-02-19 09:24:04 -05002125 return __i40e_get_coalesce(netdev, ec, -1);
2126}
2127
Jacob Keller65e87c02016-09-12 14:18:44 -07002128/**
2129 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2130 * @netdev: netdev structure
2131 * @ec: ethtool's coalesce settings
2132 * @queue: the particular queue to read
2133 *
2134 * Will read a specific queue's coalesce settings
2135 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002136static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2137 struct ethtool_coalesce *ec)
2138{
2139 return __i40e_get_coalesce(netdev, ec, queue);
2140}
2141
Jacob Keller65e87c02016-09-12 14:18:44 -07002142/**
2143 * i40e_set_itr_per_queue - set ITR values for specific queue
2144 * @vsi: the VSI to set values for
2145 * @ec: coalesce settings from ethtool
2146 * @queue: the queue to modify
2147 *
2148 * Change the ITR settings for a specific queue.
2149 **/
2150
Kan Lianga75e8002016-02-19 09:24:04 -05002151static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2152 struct ethtool_coalesce *ec,
2153 int queue)
2154{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002155 struct i40e_pf *pf = vsi->back;
2156 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002157 struct i40e_q_vector *q_vector;
2158 u16 vector, intrl;
2159
Alan Brady1c0e6a32016-11-28 16:06:02 -08002160 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002161
2162 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2163 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2164
2165 if (ec->use_adaptive_rx_coalesce)
2166 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2167 else
2168 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2169
2170 if (ec->use_adaptive_tx_coalesce)
2171 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2172 else
2173 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2174
2175 q_vector = vsi->rx_rings[queue]->q_vector;
2176 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2177 vector = vsi->base_vector + q_vector->v_idx;
2178 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2179
2180 q_vector = vsi->tx_rings[queue]->q_vector;
2181 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2182 vector = vsi->base_vector + q_vector->v_idx;
2183 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2184
2185 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2186 i40e_flush(hw);
2187}
2188
Jacob Keller65e87c02016-09-12 14:18:44 -07002189/**
2190 * __i40e_set_coalesce - set coalesce settings for particular queue
2191 * @netdev: the netdev to change
2192 * @ec: ethtool coalesce settings
2193 * @queue: the queue to change
2194 *
2195 * Sets the coalesce settings for a particular queue.
2196 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002197static int __i40e_set_coalesce(struct net_device *netdev,
2198 struct ethtool_coalesce *ec,
2199 int queue)
2200{
2201 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002202 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002203 struct i40e_vsi *vsi = np->vsi;
2204 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205 int i;
2206
2207 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2208 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2209
Alan Brady06b2dec2017-07-12 05:46:06 -04002210 if (queue < 0) {
2211 cur_rx_itr = vsi->rx_rings[0]->rx_itr_setting;
2212 cur_tx_itr = vsi->tx_rings[0]->tx_itr_setting;
2213 } else if (queue < vsi->num_queue_pairs) {
2214 cur_rx_itr = vsi->rx_rings[queue]->rx_itr_setting;
2215 cur_tx_itr = vsi->tx_rings[queue]->tx_itr_setting;
2216 } else {
2217 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2218 vsi->num_queue_pairs - 1);
2219 return -EINVAL;
2220 }
2221
2222 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2223 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2224
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002225 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2226 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2227 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2228 return -EINVAL;
2229 }
2230
Alan Brady33084062016-11-28 16:06:03 -08002231 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2232 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2233 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002234 return -EINVAL;
2235 }
2236
Alan Brady06b2dec2017-07-12 05:46:06 -04002237 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2238 ec->use_adaptive_rx_coalesce) {
2239 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2240 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002241 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002242
Alan Brady06b2dec2017-07-12 05:46:06 -04002243 if (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2244 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2245 return -EINVAL;
2246 }
2247
2248 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2249 ec->use_adaptive_tx_coalesce) {
2250 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2251 return -EINVAL;
2252 }
2253
2254 if (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2255 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2256 return -EINVAL;
2257 }
2258
2259 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2260 ec->rx_coalesce_usecs = I40E_MIN_ITR << 1;
2261
2262 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2263 ec->tx_coalesce_usecs = I40E_MIN_ITR << 1;
2264
Alan Brady33084062016-11-28 16:06:03 -08002265 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2266 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2267 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2268 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2269 vsi->int_rate_limit);
2270 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002271
Kan Lianga75e8002016-02-19 09:24:04 -05002272 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2273 * apply to all queues.
2274 */
2275 if (queue < 0) {
2276 for (i = 0; i < vsi->num_queue_pairs; i++)
2277 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002278 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002279 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002280 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002281
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002282 return 0;
2283}
2284
Jacob Keller65e87c02016-09-12 14:18:44 -07002285/**
2286 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2287 * @netdev: the netdev to change
2288 * @ec: ethtool coalesce settings
2289 *
2290 * This will set each queue to the same coalesce settings.
2291 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002292static int i40e_set_coalesce(struct net_device *netdev,
2293 struct ethtool_coalesce *ec)
2294{
2295 return __i40e_set_coalesce(netdev, ec, -1);
2296}
2297
Jacob Keller65e87c02016-09-12 14:18:44 -07002298/**
2299 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2300 * @netdev: the netdev to change
2301 * @ec: ethtool's coalesce settings
2302 * @queue: the queue to change
2303 *
2304 * Sets the specified queue's coalesce settings.
2305 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002306static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2307 struct ethtool_coalesce *ec)
2308{
2309 return __i40e_set_coalesce(netdev, ec, queue);
2310}
2311
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002312/**
2313 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2314 * @pf: pointer to the physical function struct
2315 * @cmd: ethtool rxnfc command
2316 *
2317 * Returns Success if the flow is supported, else Invalid Input.
2318 **/
2319static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2320{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002321 struct i40e_hw *hw = &pf->hw;
2322 u8 flow_pctype = 0;
2323 u64 i_set = 0;
2324
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002325 cmd->data = 0;
2326
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002327 switch (cmd->flow_type) {
2328 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002329 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2330 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002331 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002332 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2333 break;
2334 case TCP_V6_FLOW:
2335 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2336 break;
2337 case UDP_V6_FLOW:
2338 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2339 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002340 case SCTP_V4_FLOW:
2341 case AH_ESP_V4_FLOW:
2342 case AH_V4_FLOW:
2343 case ESP_V4_FLOW:
2344 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002345 case SCTP_V6_FLOW:
2346 case AH_ESP_V6_FLOW:
2347 case AH_V6_FLOW:
2348 case ESP_V6_FLOW:
2349 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002350 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002351 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2352 break;
2353 default:
2354 return -EINVAL;
2355 }
2356
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002357 /* Read flow based hash input set register */
2358 if (flow_pctype) {
2359 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2360 flow_pctype)) |
2361 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2362 flow_pctype)) << 32);
2363 }
2364
2365 /* Process bits of hash input set */
2366 if (i_set) {
2367 if (i_set & I40E_L4_SRC_MASK)
2368 cmd->data |= RXH_L4_B_0_1;
2369 if (i_set & I40E_L4_DST_MASK)
2370 cmd->data |= RXH_L4_B_2_3;
2371
2372 if (cmd->flow_type == TCP_V4_FLOW ||
2373 cmd->flow_type == UDP_V4_FLOW) {
2374 if (i_set & I40E_L3_SRC_MASK)
2375 cmd->data |= RXH_IP_SRC;
2376 if (i_set & I40E_L3_DST_MASK)
2377 cmd->data |= RXH_IP_DST;
2378 } else if (cmd->flow_type == TCP_V6_FLOW ||
2379 cmd->flow_type == UDP_V6_FLOW) {
2380 if (i_set & I40E_L3_V6_SRC_MASK)
2381 cmd->data |= RXH_IP_SRC;
2382 if (i_set & I40E_L3_V6_DST_MASK)
2383 cmd->data |= RXH_IP_DST;
2384 }
2385 }
2386
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002387 return 0;
2388}
2389
2390/**
Jacob Kellere7930952017-02-06 14:38:49 -08002391 * i40e_check_mask - Check whether a mask field is set
2392 * @mask: the full mask value
2393 * @field; mask of the field to check
2394 *
2395 * If the given mask is fully set, return positive value. If the mask for the
2396 * field is fully unset, return zero. Otherwise return a negative error code.
2397 **/
2398static int i40e_check_mask(u64 mask, u64 field)
2399{
2400 u64 value = mask & field;
2401
2402 if (value == field)
2403 return 1;
2404 else if (!value)
2405 return 0;
2406 else
2407 return -1;
2408}
2409
2410/**
2411 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2412 * @fsp: pointer to rx flow specification
2413 * @data: pointer to userdef data structure for storage
2414 *
2415 * Read the user-defined data and deconstruct the value into a structure. No
2416 * other code should read the user-defined data, so as to ensure that every
2417 * place consistently reads the value correctly.
2418 *
2419 * The user-defined field is a 64bit Big Endian format value, which we
2420 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2421 * be defined starting from the highest bits, while small bit field values
2422 * shall be defined starting from the lowest bits.
2423 *
2424 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2425 * and the filter should be rejected. The data structure will always be
2426 * modified even if FLOW_EXT is not set.
2427 *
2428 **/
2429static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2430 struct i40e_rx_flow_userdef *data)
2431{
2432 u64 value, mask;
2433 int valid;
2434
2435 /* Zero memory first so it's always consistent. */
2436 memset(data, 0, sizeof(*data));
2437
2438 if (!(fsp->flow_type & FLOW_EXT))
2439 return 0;
2440
2441 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2442 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2443
2444#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2445#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2446#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2447
2448 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2449 if (valid < 0) {
2450 return -EINVAL;
2451 } else if (valid) {
2452 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2453 data->flex_offset =
2454 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2455 data->flex_filter = true;
2456 }
2457
2458 return 0;
2459}
2460
2461/**
2462 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2463 * @fsp: pointer to rx_flow specification
2464 *
2465 * Reads the userdef data structure and properly fills in the user defined
2466 * fields of the rx_flow_spec.
2467 **/
2468static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2469 struct i40e_rx_flow_userdef *data)
2470{
2471 u64 value = 0, mask = 0;
2472
2473 if (data->flex_filter) {
2474 value |= data->flex_word;
2475 value |= (u64)data->flex_offset << 16;
2476 mask |= I40E_USERDEF_FLEX_FILTER;
2477 }
2478
2479 if (value || mask)
2480 fsp->flow_type |= FLOW_EXT;
2481
2482 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2483 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2484}
2485
2486/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002487 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2488 * @pf: Pointer to the physical function struct
2489 * @cmd: The command to get or set Rx flow classification rules
2490 * @rule_locs: Array of used rule locations
2491 *
2492 * This function populates both the total and actual rule count of
2493 * the ethtool flow classification command
2494 *
2495 * Returns 0 on success or -EMSGSIZE if entry not found
2496 **/
2497static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2498 struct ethtool_rxnfc *cmd,
2499 u32 *rule_locs)
2500{
2501 struct i40e_fdir_filter *rule;
2502 struct hlist_node *node2;
2503 int cnt = 0;
2504
2505 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002506 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002507
2508 hlist_for_each_entry_safe(rule, node2,
2509 &pf->fdir_filter_list, fdir_node) {
2510 if (cnt == cmd->rule_cnt)
2511 return -EMSGSIZE;
2512
2513 rule_locs[cnt] = rule->fd_id;
2514 cnt++;
2515 }
2516
2517 cmd->rule_cnt = cnt;
2518
2519 return 0;
2520}
2521
2522/**
2523 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2524 * @pf: Pointer to the physical function struct
2525 * @cmd: The command to get or set Rx flow classification rules
2526 *
2527 * This function looks up a filter based on the Rx flow classification
2528 * command and fills the flow spec info for it if found
2529 *
2530 * Returns 0 on success or -EINVAL if filter not found
2531 **/
2532static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2533 struct ethtool_rxnfc *cmd)
2534{
2535 struct ethtool_rx_flow_spec *fsp =
2536 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002537 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002538 struct i40e_fdir_filter *rule = NULL;
2539 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002540 u64 input_set;
2541 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002542
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002543 hlist_for_each_entry_safe(rule, node2,
2544 &pf->fdir_filter_list, fdir_node) {
2545 if (fsp->location <= rule->fd_id)
2546 break;
2547 }
2548
2549 if (!rule || fsp->location != rule->fd_id)
2550 return -EINVAL;
2551
2552 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002553 if (fsp->flow_type == IP_USER_FLOW) {
2554 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2555 fsp->h_u.usr_ip4_spec.proto = 0;
2556 fsp->m_u.usr_ip4_spec.proto = 0;
2557 }
2558
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002559 /* Reverse the src and dest notion, since the HW views them from
2560 * Tx perspective where as the user expects it from Rx filter view.
2561 */
2562 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2563 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002564 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2565 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002566
Jacob Keller36777d92017-03-07 15:05:23 -08002567 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002568 case SCTP_V4_FLOW:
2569 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2570 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002571 case TCP_V4_FLOW:
2572 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2573 break;
2574 case UDP_V4_FLOW:
2575 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2576 break;
2577 case IP_USER_FLOW:
2578 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2579 break;
2580 default:
2581 /* If we have stored a filter with a flow type not listed here
2582 * it is almost certainly a driver bug. WARN(), and then
2583 * assign the input_set as if all fields are enabled to avoid
2584 * reading unassigned memory.
2585 */
2586 WARN(1, "Missing input set index for flow_type %d\n",
2587 rule->flow_type);
2588 input_set = 0xFFFFFFFFFFFFFFFFULL;
2589 goto no_input_set;
2590 }
2591
2592 input_set = i40e_read_fd_input_set(pf, index);
2593
2594no_input_set:
2595 if (input_set & I40E_L3_SRC_MASK)
2596 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
2597
2598 if (input_set & I40E_L3_DST_MASK)
2599 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
2600
2601 if (input_set & I40E_L4_SRC_MASK)
2602 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
2603
2604 if (input_set & I40E_L4_DST_MASK)
2605 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002606
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002607 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2608 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2609 else
2610 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002611
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002612 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2613 struct i40e_vsi *vsi;
2614
2615 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2616 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002617 /* VFs are zero-indexed by the driver, but ethtool
2618 * expects them to be one-indexed, so add one here
2619 */
2620 u64 ring_vf = vsi->vf_id + 1;
2621
2622 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2623 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002624 }
2625 }
2626
Jacob Keller0e588de2017-02-06 14:38:50 -08002627 if (rule->flex_filter) {
2628 userdef.flex_filter = true;
2629 userdef.flex_word = be16_to_cpu(rule->flex_word);
2630 userdef.flex_offset = rule->flex_offset;
2631 }
2632
Jacob Kellere7930952017-02-06 14:38:49 -08002633 i40e_fill_rx_flow_user_data(fsp, &userdef);
2634
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002635 return 0;
2636}
2637
2638/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002639 * i40e_get_rxnfc - command to get RX flow classification rules
2640 * @netdev: network interface device structure
2641 * @cmd: ethtool rxnfc command
2642 *
2643 * Returns Success if the command is supported.
2644 **/
2645static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2646 u32 *rule_locs)
2647{
2648 struct i40e_netdev_priv *np = netdev_priv(netdev);
2649 struct i40e_vsi *vsi = np->vsi;
2650 struct i40e_pf *pf = vsi->back;
2651 int ret = -EOPNOTSUPP;
2652
2653 switch (cmd->cmd) {
2654 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002655 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002656 ret = 0;
2657 break;
2658 case ETHTOOL_GRXFH:
2659 ret = i40e_get_rss_hash_opts(pf, cmd);
2660 break;
2661 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002662 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002663 /* report total rule count */
2664 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002665 ret = 0;
2666 break;
2667 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002668 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002669 break;
2670 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002671 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2672 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002673 default:
2674 break;
2675 }
2676
2677 return ret;
2678}
2679
2680/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002681 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2682 * @nfc: pointer to user request
2683 * @i_setc bits currently set
2684 *
2685 * Returns value of bits to be set per user request
2686 **/
2687static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2688{
2689 u64 i_set = i_setc;
2690 u64 src_l3 = 0, dst_l3 = 0;
2691
2692 if (nfc->data & RXH_L4_B_0_1)
2693 i_set |= I40E_L4_SRC_MASK;
2694 else
2695 i_set &= ~I40E_L4_SRC_MASK;
2696 if (nfc->data & RXH_L4_B_2_3)
2697 i_set |= I40E_L4_DST_MASK;
2698 else
2699 i_set &= ~I40E_L4_DST_MASK;
2700
2701 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2702 src_l3 = I40E_L3_V6_SRC_MASK;
2703 dst_l3 = I40E_L3_V6_DST_MASK;
2704 } else if (nfc->flow_type == TCP_V4_FLOW ||
2705 nfc->flow_type == UDP_V4_FLOW) {
2706 src_l3 = I40E_L3_SRC_MASK;
2707 dst_l3 = I40E_L3_DST_MASK;
2708 } else {
2709 /* Any other flow type are not supported here */
2710 return i_set;
2711 }
2712
2713 if (nfc->data & RXH_IP_SRC)
2714 i_set |= src_l3;
2715 else
2716 i_set &= ~src_l3;
2717 if (nfc->data & RXH_IP_DST)
2718 i_set |= dst_l3;
2719 else
2720 i_set &= ~dst_l3;
2721
2722 return i_set;
2723}
2724
2725/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002726 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2727 * @pf: pointer to the physical function struct
2728 * @cmd: ethtool rxnfc command
2729 *
2730 * Returns Success if the flow input set is supported.
2731 **/
2732static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2733{
2734 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002735 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2736 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002737 u8 flow_pctype = 0;
2738 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002739
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002740 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2741 dev_err(&pf->pdev->dev,
2742 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2743 return -EOPNOTSUPP;
2744 }
2745
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002746 /* RSS does not support anything other than hashing
2747 * to queues on src and dst IPs and ports
2748 */
2749 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2750 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2751 return -EINVAL;
2752
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002753 switch (nfc->flow_type) {
2754 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002755 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002756 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002757 hena |=
2758 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002759 break;
2760 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002761 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002762 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002763 hena |=
2764 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002765 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002766 hena |=
2767 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002768 break;
2769 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002770 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002771 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002772 hena |=
2773 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2774 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002775
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002776 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002777 break;
2778 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002779 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002780 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002781 hena |=
2782 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2783 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002784
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002785 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002786 break;
2787 case AH_ESP_V4_FLOW:
2788 case AH_V4_FLOW:
2789 case ESP_V4_FLOW:
2790 case SCTP_V4_FLOW:
2791 if ((nfc->data & RXH_L4_B_0_1) ||
2792 (nfc->data & RXH_L4_B_2_3))
2793 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002794 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002795 break;
2796 case AH_ESP_V6_FLOW:
2797 case AH_V6_FLOW:
2798 case ESP_V6_FLOW:
2799 case SCTP_V6_FLOW:
2800 if ((nfc->data & RXH_L4_B_0_1) ||
2801 (nfc->data & RXH_L4_B_2_3))
2802 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002803 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002804 break;
2805 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002806 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2807 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002808 break;
2809 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002810 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2811 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002812 break;
2813 default:
2814 return -EINVAL;
2815 }
2816
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002817 if (flow_pctype) {
2818 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2819 flow_pctype)) |
2820 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2821 flow_pctype)) << 32);
2822 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2823 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2824 (u32)i_set);
2825 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2826 (u32)(i_set >> 32));
2827 hena |= BIT_ULL(flow_pctype);
2828 }
2829
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002830 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2831 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002832 i40e_flush(hw);
2833
2834 return 0;
2835}
2836
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002837/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002838 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2839 * @vsi: Pointer to the targeted VSI
2840 * @input: The filter to update or NULL to indicate deletion
2841 * @sw_idx: Software index to the filter
2842 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002843 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002844 * This function updates (or deletes) a Flow Director entry from
2845 * the hlist of the corresponding PF
2846 *
2847 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002848 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002849static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2850 struct i40e_fdir_filter *input,
2851 u16 sw_idx,
2852 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002853{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002854 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002855 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002856 struct hlist_node *node2;
2857 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002858
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002859 parent = NULL;
2860 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002861
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002862 hlist_for_each_entry_safe(rule, node2,
2863 &pf->fdir_filter_list, fdir_node) {
2864 /* hash found, or no matching entry */
2865 if (rule->fd_id >= sw_idx)
2866 break;
2867 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002868 }
2869
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002870 /* if there is an old rule occupying our place remove it */
2871 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08002872 /* Remove this rule, since we're either deleting it, or
2873 * replacing it.
2874 */
2875 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002876 hlist_del(&rule->fdir_node);
2877 kfree(rule);
2878 pf->fdir_pf_active_filters--;
2879 }
2880
Jacob Kellerc6da5252017-02-06 14:39:13 -08002881 /* If we weren't given an input, this is a delete, so just return the
2882 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002883 */
2884 if (!input)
2885 return err;
2886
Jacob Kellerc6da5252017-02-06 14:39:13 -08002887 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002888 INIT_HLIST_NODE(&input->fdir_node);
2889
2890 /* add filter to the list */
2891 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002892 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002893 else
2894 hlist_add_head(&input->fdir_node,
2895 &pf->fdir_filter_list);
2896
2897 /* update counts */
2898 pf->fdir_pf_active_filters++;
2899
2900 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002901}
2902
2903/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002904 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
2905 * @pf: pointer to PF structure
2906 *
2907 * This function searches the list of filters and determines which FLX_PIT
2908 * entries are still required. It will prune any entries which are no longer
2909 * in use after the deletion.
2910 **/
2911static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
2912{
2913 struct i40e_flex_pit *entry, *tmp;
2914 struct i40e_fdir_filter *rule;
2915
2916 /* First, we'll check the l3 table */
2917 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
2918 bool found = false;
2919
2920 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2921 if (rule->flow_type != IP_USER_FLOW)
2922 continue;
2923 if (rule->flex_filter &&
2924 rule->flex_offset == entry->src_offset) {
2925 found = true;
2926 break;
2927 }
2928 }
2929
2930 /* If we didn't find the filter, then we can prune this entry
2931 * from the list.
2932 */
2933 if (!found) {
2934 list_del(&entry->list);
2935 kfree(entry);
2936 }
2937 }
2938
2939 /* Followed by the L4 table */
2940 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
2941 bool found = false;
2942
2943 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2944 /* Skip this filter if it's L3, since we already
2945 * checked those in the above loop
2946 */
2947 if (rule->flow_type == IP_USER_FLOW)
2948 continue;
2949 if (rule->flex_filter &&
2950 rule->flex_offset == entry->src_offset) {
2951 found = true;
2952 break;
2953 }
2954 }
2955
2956 /* If we didn't find the filter, then we can prune this entry
2957 * from the list.
2958 */
2959 if (!found) {
2960 list_del(&entry->list);
2961 kfree(entry);
2962 }
2963 }
2964}
2965
2966/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002967 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2968 * @vsi: Pointer to the targeted VSI
2969 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002970 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002971 * The function removes a Flow Director filter entry from the
2972 * hlist of the corresponding PF
2973 *
2974 * Returns 0 on success
2975 */
2976static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2977 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002978{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002979 struct ethtool_rx_flow_spec *fsp =
2980 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002981 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002982 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002983
Jacob Keller0da36b92017-04-19 09:25:55 -04002984 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
2985 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002986 return -EBUSY;
2987
Jacob Keller0da36b92017-04-19 09:25:55 -04002988 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002989 return -EBUSY;
2990
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002991 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002992
Jacob Keller0e588de2017-02-06 14:38:50 -08002993 i40e_prune_flex_pit_list(pf);
2994
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002995 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002996 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002997}
2998
2999/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003000 * i40e_unused_pit_index - Find an unused PIT index for given list
3001 * @pf: the PF data structure
3002 *
3003 * Find the first unused flexible PIT index entry. We search both the L3 and
3004 * L4 flexible PIT lists so that the returned index is unique and unused by
3005 * either currently programmed L3 or L4 filters. We use a bit field as storage
3006 * to track which indexes are already used.
3007 **/
3008static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3009{
3010 unsigned long available_index = 0xFF;
3011 struct i40e_flex_pit *entry;
3012
3013 /* We need to make sure that the new index isn't in use by either L3
3014 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3015 * L4 to use the same index.
3016 */
3017
3018 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3019 clear_bit(entry->pit_index, &available_index);
3020
3021 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3022 clear_bit(entry->pit_index, &available_index);
3023
3024 return find_first_bit(&available_index, 8);
3025}
3026
3027/**
3028 * i40e_find_flex_offset - Find an existing flex src_offset
3029 * @flex_pit_list: L3 or L4 flex PIT list
3030 * @src_offset: new src_offset to find
3031 *
3032 * Searches the flex_pit_list for an existing offset. If no offset is
3033 * currently programmed, then this will return an ERR_PTR if there is no space
3034 * to add a new offset, otherwise it returns NULL.
3035 **/
3036static
3037struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3038 u16 src_offset)
3039{
3040 struct i40e_flex_pit *entry;
3041 int size = 0;
3042
3043 /* Search for the src_offset first. If we find a matching entry
3044 * already programmed, we can simply re-use it.
3045 */
3046 list_for_each_entry(entry, flex_pit_list, list) {
3047 size++;
3048 if (entry->src_offset == src_offset)
3049 return entry;
3050 }
3051
3052 /* If we haven't found an entry yet, then the provided src offset has
3053 * not yet been programmed. We will program the src offset later on,
3054 * but we need to indicate whether there is enough space to do so
3055 * here. We'll make use of ERR_PTR for this purpose.
3056 */
3057 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3058 return ERR_PTR(-ENOSPC);
3059
3060 return NULL;
3061}
3062
3063/**
3064 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3065 * @flex_pit_list: L3 or L4 flex PIT list
3066 * @src_offset: new src_offset to add
3067 * @pit_index: the PIT index to program
3068 *
3069 * This function programs the new src_offset to the list. It is expected that
3070 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3071 * that this offset is not programmed, and that the list has enough space to
3072 * store another offset.
3073 *
3074 * Returns 0 on success, and negative value on error.
3075 **/
3076static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3077 u16 src_offset,
3078 u8 pit_index)
3079{
3080 struct i40e_flex_pit *new_pit, *entry;
3081
3082 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3083 if (!new_pit)
3084 return -ENOMEM;
3085
3086 new_pit->src_offset = src_offset;
3087 new_pit->pit_index = pit_index;
3088
3089 /* We need to insert this item such that the list is sorted by
3090 * src_offset in ascending order.
3091 */
3092 list_for_each_entry(entry, flex_pit_list, list) {
3093 if (new_pit->src_offset < entry->src_offset) {
3094 list_add_tail(&new_pit->list, &entry->list);
3095 return 0;
3096 }
3097
3098 /* If we found an entry with our offset already programmed we
3099 * can simply return here, after freeing the memory. However,
3100 * if the pit_index does not match we need to report an error.
3101 */
3102 if (new_pit->src_offset == entry->src_offset) {
3103 int err = 0;
3104
3105 /* If the PIT index is not the same we can't re-use
3106 * the entry, so we must report an error.
3107 */
3108 if (new_pit->pit_index != entry->pit_index)
3109 err = -EINVAL;
3110
3111 kfree(new_pit);
3112 return err;
3113 }
3114 }
3115
3116 /* If we reached here, then we haven't yet added the item. This means
3117 * that we should add the item at the end of the list.
3118 */
3119 list_add_tail(&new_pit->list, flex_pit_list);
3120 return 0;
3121}
3122
3123/**
3124 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3125 * @pf: Pointer to the PF structure
3126 * @flex_pit_list: list of flexible src offsets in use
3127 * #flex_pit_start: index to first entry for this section of the table
3128 *
3129 * In order to handle flexible data, the hardware uses a table of values
3130 * called the FLX_PIT table. This table is used to indicate which sections of
3131 * the input correspond to what PIT index values. Unfortunately, hardware is
3132 * very restrictive about programming this table. Entries must be ordered by
3133 * src_offset in ascending order, without duplicates. Additionally, unused
3134 * entries must be set to the unused index value, and must have valid size and
3135 * length according to the src_offset ordering.
3136 *
3137 * This function will reprogram the FLX_PIT register from a book-keeping
3138 * structure that we guarantee is already ordered correctly, and has no more
3139 * than 3 entries.
3140 *
3141 * To make things easier, we only support flexible values of one word length,
3142 * rather than allowing variable length flexible values.
3143 **/
3144static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3145 struct list_head *flex_pit_list,
3146 int flex_pit_start)
3147{
3148 struct i40e_flex_pit *entry = NULL;
3149 u16 last_offset = 0;
3150 int i = 0, j = 0;
3151
3152 /* First, loop over the list of flex PIT entries, and reprogram the
3153 * registers.
3154 */
3155 list_for_each_entry(entry, flex_pit_list, list) {
3156 /* We have to be careful when programming values for the
3157 * largest SRC_OFFSET value. It is possible that adding
3158 * additional empty values at the end would overflow the space
3159 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3160 * we check here and add the empty values prior to adding the
3161 * largest value.
3162 *
3163 * To determine this, we will use a loop from i+1 to 3, which
3164 * will determine whether the unused entries would have valid
3165 * SRC_OFFSET. Note that there cannot be extra entries past
3166 * this value, because the only valid values would have been
3167 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3168 * have been added to the list in the first place.
3169 */
3170 for (j = i + 1; j < 3; j++) {
3171 u16 offset = entry->src_offset + j;
3172 int index = flex_pit_start + i;
3173 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3174 1,
3175 offset - 3);
3176
3177 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3178 i40e_write_rx_ctl(&pf->hw,
3179 I40E_PRTQF_FLX_PIT(index),
3180 value);
3181 i++;
3182 }
3183 }
3184
3185 /* Now, we can program the actual value into the table */
3186 i40e_write_rx_ctl(&pf->hw,
3187 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3188 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3189 1,
3190 entry->src_offset));
3191 i++;
3192 }
3193
3194 /* In order to program the last entries in the table, we need to
3195 * determine the valid offset. If the list is empty, we'll just start
3196 * with 0. Otherwise, we'll start with the last item offset and add 1.
3197 * This ensures that all entries have valid sizes. If we don't do this
3198 * correctly, the hardware will disable flexible field parsing.
3199 */
3200 if (!list_empty(flex_pit_list))
3201 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3202
3203 for (; i < 3; i++, last_offset++) {
3204 i40e_write_rx_ctl(&pf->hw,
3205 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3206 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3207 1,
3208 last_offset));
3209 }
3210}
3211
3212/**
3213 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3214 * @pf: pointer to the PF structure
3215 *
3216 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3217 * internal helper function for implementation details.
3218 **/
3219static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3220{
3221 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3222 I40E_FLEX_PIT_IDX_START_L3);
3223
3224 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3225 I40E_FLEX_PIT_IDX_START_L4);
3226
3227 /* We also need to program the L3 and L4 GLQF ORT register */
3228 i40e_write_rx_ctl(&pf->hw,
3229 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3230 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3231 3, 1));
3232
3233 i40e_write_rx_ctl(&pf->hw,
3234 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3235 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3236 3, 1));
3237}
3238
3239/**
Jacob Keller9229e992017-02-06 14:38:47 -08003240 * i40e_flow_str - Converts a flow_type into a human readable string
3241 * @flow_type: the flow type from a flow specification
3242 *
3243 * Currently only flow types we support are included here, and the string
3244 * value attempts to match what ethtool would use to configure this flow type.
3245 **/
3246static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3247{
3248 switch (fsp->flow_type & ~FLOW_EXT) {
3249 case TCP_V4_FLOW:
3250 return "tcp4";
3251 case UDP_V4_FLOW:
3252 return "udp4";
3253 case SCTP_V4_FLOW:
3254 return "sctp4";
3255 case IP_USER_FLOW:
3256 return "ip4";
3257 default:
3258 return "unknown";
3259 }
3260}
3261
3262/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003263 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3264 * @pit_index: PIT index to convert
3265 *
3266 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3267 * of range.
3268 **/
3269static u64 i40e_pit_index_to_mask(int pit_index)
3270{
3271 switch (pit_index) {
3272 case 0:
3273 return I40E_FLEX_50_MASK;
3274 case 1:
3275 return I40E_FLEX_51_MASK;
3276 case 2:
3277 return I40E_FLEX_52_MASK;
3278 case 3:
3279 return I40E_FLEX_53_MASK;
3280 case 4:
3281 return I40E_FLEX_54_MASK;
3282 case 5:
3283 return I40E_FLEX_55_MASK;
3284 case 6:
3285 return I40E_FLEX_56_MASK;
3286 case 7:
3287 return I40E_FLEX_57_MASK;
3288 default:
3289 return 0;
3290 }
3291}
3292
3293/**
Jacob Keller9229e992017-02-06 14:38:47 -08003294 * i40e_print_input_set - Show changes between two input sets
3295 * @vsi: the vsi being configured
3296 * @old: the old input set
3297 * @new: the new input set
3298 *
3299 * Print the difference between old and new input sets by showing which series
3300 * of words are toggled on or off. Only displays the bits we actually support
3301 * changing.
3302 **/
3303static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3304{
3305 struct i40e_pf *pf = vsi->back;
3306 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003307 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003308
3309 old_value = !!(old & I40E_L3_SRC_MASK);
3310 new_value = !!(new & I40E_L3_SRC_MASK);
3311 if (old_value != new_value)
3312 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3313 old_value ? "ON" : "OFF",
3314 new_value ? "ON" : "OFF");
3315
3316 old_value = !!(old & I40E_L3_DST_MASK);
3317 new_value = !!(new & I40E_L3_DST_MASK);
3318 if (old_value != new_value)
3319 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3320 old_value ? "ON" : "OFF",
3321 new_value ? "ON" : "OFF");
3322
3323 old_value = !!(old & I40E_L4_SRC_MASK);
3324 new_value = !!(new & I40E_L4_SRC_MASK);
3325 if (old_value != new_value)
3326 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3327 old_value ? "ON" : "OFF",
3328 new_value ? "ON" : "OFF");
3329
3330 old_value = !!(old & I40E_L4_DST_MASK);
3331 new_value = !!(new & I40E_L4_DST_MASK);
3332 if (old_value != new_value)
3333 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3334 old_value ? "ON" : "OFF",
3335 new_value ? "ON" : "OFF");
3336
3337 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3338 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3339 if (old_value != new_value)
3340 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3341 old_value ? "ON" : "OFF",
3342 new_value ? "ON" : "OFF");
3343
Jacob Keller0e588de2017-02-06 14:38:50 -08003344 /* Show change of flexible filter entries */
3345 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3346 u64 flex_mask = i40e_pit_index_to_mask(i);
3347
3348 old_value = !!(old & flex_mask);
3349 new_value = !!(new & flex_mask);
3350 if (old_value != new_value)
3351 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3352 i,
3353 old_value ? "ON" : "OFF",
3354 new_value ? "ON" : "OFF");
3355 }
3356
Jacob Keller9229e992017-02-06 14:38:47 -08003357 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3358 old);
3359 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3360 new);
3361}
3362
3363/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003364 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003365 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003366 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003367 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003368 *
Jacob Keller9229e992017-02-06 14:38:47 -08003369 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3370 * for partial matches exists with a few limitations. First, hardware only
3371 * supports masking by word boundary (2 bytes) and not per individual bit.
3372 * Second, hardware is limited to using one mask for a flow type and cannot
3373 * use a separate mask for each filter.
3374 *
3375 * To support these limitations, if we already have a configured filter for
3376 * the specified type, this function enforces that new filters of the type
3377 * match the configured input set. Otherwise, if we do not have a filter of
3378 * the specified type, we allow the input set to be updated to match the
3379 * desired filter.
3380 *
3381 * To help ensure that administrators understand why filters weren't displayed
3382 * as supported, we print a diagnostic message displaying how the input set
3383 * would change and warning to delete the preexisting filters if required.
3384 *
3385 * Returns 0 on successful input set match, and a negative return code on
3386 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003387 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003388static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003389 struct ethtool_rx_flow_spec *fsp,
3390 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003391{
Jacob Keller36777d92017-03-07 15:05:23 -08003392 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003393 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3394 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003395 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003396 bool new_flex_offset = false;
3397 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003398 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003399 u16 index, src_offset = 0;
3400 u8 pit_index = 0;
3401 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003402
3403 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003404 case SCTP_V4_FLOW:
3405 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3406 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3407 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003408 case TCP_V4_FLOW:
3409 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003410 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003411 break;
3412 case UDP_V4_FLOW:
3413 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003414 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003415 break;
3416 case IP_USER_FLOW:
3417 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003418 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003419 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003420 break;
3421 default:
3422 return -EOPNOTSUPP;
3423 }
3424
3425 /* Read the current input set from register memory. */
3426 current_mask = i40e_read_fd_input_set(pf, index);
3427 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003428
Jacob Keller9229e992017-02-06 14:38:47 -08003429 /* Determine, if any, the required changes to the input set in order
3430 * to support the provided mask.
3431 *
3432 * Hardware only supports masking at word (2 byte) granularity and does
3433 * not support full bitwise masking. This implementation simplifies
3434 * even further and only supports fully enabled or fully disabled
3435 * masks for each field, even though we could split the ip4src and
3436 * ip4dst fields.
3437 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003438 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003439 case SCTP_V4_FLOW:
3440 new_mask &= ~I40E_VERIFY_TAG_MASK;
3441 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003442 case TCP_V4_FLOW:
3443 case UDP_V4_FLOW:
3444 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3445
3446 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003447 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3448 new_mask |= I40E_L3_SRC_MASK;
3449 else if (!tcp_ip4_spec->ip4src)
3450 new_mask &= ~I40E_L3_SRC_MASK;
3451 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003452 return -EOPNOTSUPP;
3453
3454 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003455 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3456 new_mask |= I40E_L3_DST_MASK;
3457 else if (!tcp_ip4_spec->ip4dst)
3458 new_mask &= ~I40E_L3_DST_MASK;
3459 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003460 return -EOPNOTSUPP;
3461
3462 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003463 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3464 new_mask |= I40E_L4_SRC_MASK;
3465 else if (!tcp_ip4_spec->psrc)
3466 new_mask &= ~I40E_L4_SRC_MASK;
3467 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003468 return -EOPNOTSUPP;
3469
3470 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003471 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3472 new_mask |= I40E_L4_DST_MASK;
3473 else if (!tcp_ip4_spec->pdst)
3474 new_mask &= ~I40E_L4_DST_MASK;
3475 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003476 return -EOPNOTSUPP;
3477
3478 /* Filtering on Type of Service is not supported. */
3479 if (tcp_ip4_spec->tos)
3480 return -EOPNOTSUPP;
3481
3482 break;
3483 case IP_USER_FLOW:
3484 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3485
3486 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003487 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3488 new_mask |= I40E_L3_SRC_MASK;
3489 else if (!usr_ip4_spec->ip4src)
3490 new_mask &= ~I40E_L3_SRC_MASK;
3491 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003492 return -EOPNOTSUPP;
3493
3494 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003495 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3496 new_mask |= I40E_L3_DST_MASK;
3497 else if (!usr_ip4_spec->ip4dst)
3498 new_mask &= ~I40E_L3_DST_MASK;
3499 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003500 return -EOPNOTSUPP;
3501
3502 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003503 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3504 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3505 else if (!usr_ip4_spec->l4_4_bytes)
3506 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3507 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003508 return -EOPNOTSUPP;
3509
3510 /* Filtering on Type of Service is not supported. */
3511 if (usr_ip4_spec->tos)
3512 return -EOPNOTSUPP;
3513
Jacob Keller0e588de2017-02-06 14:38:50 -08003514 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003515 if (usr_ip4_spec->ip_ver)
3516 return -EINVAL;
3517
Jacob Keller0e588de2017-02-06 14:38:50 -08003518 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003519 if (usr_ip4_spec->proto)
3520 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003521
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003522 break;
3523 default:
3524 return -EOPNOTSUPP;
3525 }
3526
Jacob Keller0e588de2017-02-06 14:38:50 -08003527 /* First, clear all flexible filter entries */
3528 new_mask &= ~I40E_FLEX_INPUT_MASK;
3529
3530 /* If we have a flexible filter, try to add this offset to the correct
3531 * flexible filter PIT list. Once finished, we can update the mask.
3532 * If the src_offset changed, we will get a new mask value which will
3533 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003534 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003535 if (userdef->flex_filter) {
3536 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3537
3538 /* Flexible offset must be even, since the flexible payload
3539 * must be aligned on 2-byte boundary.
3540 */
3541 if (userdef->flex_offset & 0x1) {
3542 dev_warn(&pf->pdev->dev,
3543 "Flexible data offset must be 2-byte aligned\n");
3544 return -EINVAL;
3545 }
3546
3547 src_offset = userdef->flex_offset >> 1;
3548
3549 /* FLX_PIT source offset value is only so large */
3550 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3551 dev_warn(&pf->pdev->dev,
3552 "Flexible data must reside within first 64 bytes of the packet payload\n");
3553 return -EINVAL;
3554 }
3555
3556 /* See if this offset has already been programmed. If we get
3557 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3558 * if we get a NULL pointer, this means we will need to add
3559 * the offset.
3560 */
3561 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3562 src_offset);
3563 if (IS_ERR(flex_pit))
3564 return PTR_ERR(flex_pit);
3565
3566 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3567 * packet types, and thus we need to program both L3 and L4
3568 * flexible values. These must have identical flexible index,
3569 * as otherwise we can't correctly program the input set. So
3570 * we'll find both an L3 and L4 index and make sure they are
3571 * the same.
3572 */
3573 if (flex_l3) {
3574 l3_flex_pit =
3575 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3576 src_offset);
3577 if (IS_ERR(l3_flex_pit))
3578 return PTR_ERR(l3_flex_pit);
3579
3580 if (flex_pit) {
3581 /* If we already had a matching L4 entry, we
3582 * need to make sure that the L3 entry we
3583 * obtained uses the same index.
3584 */
3585 if (l3_flex_pit) {
3586 if (l3_flex_pit->pit_index !=
3587 flex_pit->pit_index) {
3588 return -EINVAL;
3589 }
3590 } else {
3591 new_flex_offset = true;
3592 }
3593 } else {
3594 flex_pit = l3_flex_pit;
3595 }
3596 }
3597
3598 /* If we didn't find an existing flex offset, we need to
3599 * program a new one. However, we don't immediately program it
3600 * here because we will wait to program until after we check
3601 * that it is safe to change the input set.
3602 */
3603 if (!flex_pit) {
3604 new_flex_offset = true;
3605 pit_index = i40e_unused_pit_index(pf);
3606 } else {
3607 pit_index = flex_pit->pit_index;
3608 }
3609
3610 /* Update the mask with the new offset */
3611 new_mask |= i40e_pit_index_to_mask(pit_index);
3612 }
3613
3614 /* If the mask and flexible filter offsets for this filter match the
3615 * currently programmed values we don't need any input set change, so
3616 * this filter is safe to install.
3617 */
3618 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003619 return 0;
3620
3621 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3622 i40e_flow_str(fsp));
3623 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003624 if (new_flex_offset) {
3625 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3626 pit_index, src_offset);
3627 }
Jacob Keller9229e992017-02-06 14:38:47 -08003628
3629 /* Hardware input sets are global across multiple ports, so even the
3630 * main port cannot change them when in MFP mode as this would impact
3631 * any filters on the other ports.
3632 */
3633 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3634 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003635 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003636 }
3637
3638 /* This filter requires us to update the input set. However, hardware
3639 * only supports one input set per flow type, and does not support
3640 * separate masks for each filter. This means that we can only support
3641 * a single mask for all filters of a specific type.
3642 *
3643 * If we have preexisting filters, they obviously depend on the
3644 * current programmed input set. Display a diagnostic message in this
3645 * case explaining why the filter could not be accepted.
3646 */
3647 if (*fdir_filter_count) {
3648 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3649 i40e_flow_str(fsp),
3650 *fdir_filter_count);
3651 return -EOPNOTSUPP;
3652 }
3653
3654 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003655
Jacob Keller0e588de2017-02-06 14:38:50 -08003656 /* Add the new offset and update table, if necessary */
3657 if (new_flex_offset) {
3658 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3659 pit_index);
3660 if (err)
3661 return err;
3662
3663 if (flex_l3) {
3664 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3665 src_offset,
3666 pit_index);
3667 if (err)
3668 return err;
3669 }
3670
3671 i40e_reprogram_flex_pit(pf);
3672 }
3673
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003674 return 0;
3675}
3676
3677/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003678 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003679 * @vsi: pointer to the targeted VSI
3680 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003681 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003682 * Add Flow Director filters for a specific flow spec based on their
3683 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003684 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003685static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3686 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003687{
Jacob Kellere7930952017-02-06 14:38:49 -08003688 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003689 struct ethtool_rx_flow_spec *fsp;
3690 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003691 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003692 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003693 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003694 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003695
3696 if (!vsi)
3697 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003698 pf = vsi->back;
3699
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003700 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3701 return -EOPNOTSUPP;
3702
Jacob Keller47994c12017-04-19 09:25:57 -04003703 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003704 return -ENOSPC;
3705
Jacob Keller0da36b92017-04-19 09:25:55 -04003706 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3707 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003708 return -EBUSY;
3709
Jacob Keller0da36b92017-04-19 09:25:55 -04003710 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003711 return -EBUSY;
3712
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003713 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3714
Jacob Kellere7930952017-02-06 14:38:49 -08003715 /* Parse the user-defined field */
3716 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3717 return -EINVAL;
3718
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003719 /* Extended MAC field is not supported */
3720 if (fsp->flow_type & FLOW_MAC_EXT)
3721 return -EINVAL;
3722
Jacob Keller0e588de2017-02-06 14:38:50 -08003723 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003724 if (ret)
3725 return ret;
3726
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003727 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3728 pf->hw.func_caps.fd_filters_guaranteed)) {
3729 return -EINVAL;
3730 }
3731
Jacob Keller43b15692017-02-06 14:38:48 -08003732 /* ring_cookie is either the drop index, or is a mask of the queue
3733 * index and VF id we wish to target.
3734 */
3735 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3736 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3737 } else {
3738 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3739 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3740
3741 if (!vf) {
3742 if (ring >= vsi->num_queue_pairs)
3743 return -EINVAL;
3744 dest_vsi = vsi->id;
3745 } else {
3746 /* VFs are zero-indexed, so we subtract one here */
3747 vf--;
3748
3749 if (vf >= pf->num_alloc_vfs)
3750 return -EINVAL;
3751 if (ring >= pf->vf[vf].num_queue_pairs)
3752 return -EINVAL;
3753 dest_vsi = pf->vf[vf].lan_vsi_id;
3754 }
3755 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3756 q_index = ring;
3757 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003758
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003759 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003760
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003761 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003762 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003763
3764 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003765 input->q_index = q_index;
3766 input->dest_vsi = dest_vsi;
3767 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003768 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04003769 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08003770 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3771 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08003772 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003773 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00003774
3775 /* Reverse the src and dest notion, since the HW expects them to be from
3776 * Tx perspective where as the input from user is from Rx filter view.
3777 */
3778 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
3779 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08003780 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3781 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003782
Jacob Keller0e588de2017-02-06 14:38:50 -08003783 if (userdef.flex_filter) {
3784 input->flex_filter = true;
3785 input->flex_word = cpu_to_be16(userdef.flex_word);
3786 input->flex_offset = userdef.flex_offset;
3787 }
3788
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003789 ret = i40e_add_del_fdir(vsi, input, true);
3790 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08003791 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003792
Jacob Keller01016da2017-02-06 14:38:40 -08003793 /* Add the input filter to the fdir_input_list, possibly replacing
3794 * a previous filter. Do not free the input structure after adding it
3795 * to the list as this would cause a use-after-free bug.
3796 */
3797 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
3798
3799 return 0;
3800
3801free_input:
3802 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003803 return ret;
3804}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003805
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003806/**
3807 * i40e_set_rxnfc - command to set RX flow classification rules
3808 * @netdev: network interface device structure
3809 * @cmd: ethtool rxnfc command
3810 *
3811 * Returns Success if the command is supported.
3812 **/
3813static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3814{
3815 struct i40e_netdev_priv *np = netdev_priv(netdev);
3816 struct i40e_vsi *vsi = np->vsi;
3817 struct i40e_pf *pf = vsi->back;
3818 int ret = -EOPNOTSUPP;
3819
3820 switch (cmd->cmd) {
3821 case ETHTOOL_SRXFH:
3822 ret = i40e_set_rss_hash_opt(pf, cmd);
3823 break;
3824 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003825 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003826 break;
3827 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003828 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003829 break;
3830 default:
3831 break;
3832 }
3833
3834 return ret;
3835}
3836
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003837/**
3838 * i40e_max_channels - get Max number of combined channels supported
3839 * @vsi: vsi pointer
3840 **/
3841static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
3842{
3843 /* TODO: This code assumes DCB and FD is disabled for now. */
3844 return vsi->alloc_queue_pairs;
3845}
3846
3847/**
3848 * i40e_get_channels - Get the current channels enabled and max supported etc.
3849 * @netdev: network interface device structure
3850 * @ch: ethtool channels structure
3851 *
3852 * We don't support separate tx and rx queues as channels. The other count
3853 * represents how many queues are being used for control. max_combined counts
3854 * how many queue pairs we can support. They may not be mapped 1 to 1 with
3855 * q_vectors since we support a lot more queue pairs than q_vectors.
3856 **/
3857static void i40e_get_channels(struct net_device *dev,
3858 struct ethtool_channels *ch)
3859{
3860 struct i40e_netdev_priv *np = netdev_priv(dev);
3861 struct i40e_vsi *vsi = np->vsi;
3862 struct i40e_pf *pf = vsi->back;
3863
3864 /* report maximum channels */
3865 ch->max_combined = i40e_max_channels(vsi);
3866
3867 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003868 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003869 ch->max_other = ch->other_count;
3870
3871 /* Note: This code assumes DCB is disabled for now. */
3872 ch->combined_count = vsi->num_queue_pairs;
3873}
3874
3875/**
3876 * i40e_set_channels - Set the new channels count.
3877 * @netdev: network interface device structure
3878 * @ch: ethtool channels structure
3879 *
3880 * The new channels count may not be the same as requested by the user
3881 * since it gets rounded down to a power of 2 value.
3882 **/
3883static int i40e_set_channels(struct net_device *dev,
3884 struct ethtool_channels *ch)
3885{
Jacob Keller59826d92016-07-27 12:02:35 -07003886 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003887 struct i40e_netdev_priv *np = netdev_priv(dev);
3888 unsigned int count = ch->combined_count;
3889 struct i40e_vsi *vsi = np->vsi;
3890 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07003891 struct i40e_fdir_filter *rule;
3892 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003893 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07003894 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003895
3896 /* We do not support setting channels for any other VSI at present */
3897 if (vsi->type != I40E_VSI_MAIN)
3898 return -EINVAL;
3899
3900 /* verify they are not requesting separate vectors */
3901 if (!count || ch->rx_count || ch->tx_count)
3902 return -EINVAL;
3903
3904 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003905 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003906 return -EINVAL;
3907
3908 /* verify the number of channels does not exceed hardware limits */
3909 if (count > i40e_max_channels(vsi))
3910 return -EINVAL;
3911
Jacob Keller59826d92016-07-27 12:02:35 -07003912 /* verify that the number of channels does not invalidate any current
3913 * flow director rules
3914 */
3915 hlist_for_each_entry_safe(rule, node2,
3916 &pf->fdir_filter_list, fdir_node) {
3917 if (rule->dest_ctl != drop && count <= rule->q_index) {
3918 dev_warn(&pf->pdev->dev,
3919 "Existing user defined filter %d assigns flow to queue %d\n",
3920 rule->fd_id, rule->q_index);
3921 err = -EINVAL;
3922 }
3923 }
3924
3925 if (err) {
3926 dev_err(&pf->pdev->dev,
3927 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
3928 count);
3929 return err;
3930 }
3931
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003932 /* update feature limits from largest to smallest supported values */
3933 /* TODO: Flow director limit, DCB etc */
3934
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003935 /* use rss_reconfig to rebuild with new queue count and update traffic
3936 * class queue mapping
3937 */
3938 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00003939 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003940 return 0;
3941 else
3942 return -EINVAL;
3943}
3944
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003945/**
3946 * i40e_get_rxfh_key_size - get the RSS hash key size
3947 * @netdev: network interface device structure
3948 *
3949 * Returns the table size.
3950 **/
3951static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
3952{
3953 return I40E_HKEY_ARRAY_SIZE;
3954}
3955
3956/**
3957 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
3958 * @netdev: network interface device structure
3959 *
3960 * Returns the table size.
3961 **/
3962static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
3963{
3964 return I40E_HLUT_ARRAY_SIZE;
3965}
3966
3967static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
3968 u8 *hfunc)
3969{
3970 struct i40e_netdev_priv *np = netdev_priv(netdev);
3971 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04003972 u8 *lut, *seed = NULL;
3973 int ret;
3974 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003975
3976 if (hfunc)
3977 *hfunc = ETH_RSS_HASH_TOP;
3978
3979 if (!indir)
3980 return 0;
3981
Helin Zhang043dd652015-10-21 19:56:23 -04003982 seed = key;
3983 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3984 if (!lut)
3985 return -ENOMEM;
3986 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
3987 if (ret)
3988 goto out;
3989 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3990 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003991
Helin Zhang043dd652015-10-21 19:56:23 -04003992out:
3993 kfree(lut);
3994
3995 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003996}
3997
3998/**
3999 * i40e_set_rxfh - set the rx flow hash indirection table
4000 * @netdev: network interface device structure
4001 * @indir: indirection table
4002 * @key: hash key
4003 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004004 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004005 * returns 0 after programming the table.
4006 **/
4007static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4008 const u8 *key, const u8 hfunc)
4009{
4010 struct i40e_netdev_priv *np = netdev_priv(netdev);
4011 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004012 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004013 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004014 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004015
4016 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4017 return -EOPNOTSUPP;
4018
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004019 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004020 if (!vsi->rss_hkey_user) {
4021 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4022 GFP_KERNEL);
4023 if (!vsi->rss_hkey_user)
4024 return -ENOMEM;
4025 }
4026 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4027 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004028 }
Helin Zhang28c58692015-10-26 19:44:27 -04004029 if (!vsi->rss_lut_user) {
4030 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4031 if (!vsi->rss_lut_user)
4032 return -ENOMEM;
4033 }
Helin Zhang043dd652015-10-21 19:56:23 -04004034
Helin Zhang28c58692015-10-26 19:44:27 -04004035 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004036 if (indir)
4037 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4038 vsi->rss_lut_user[i] = (u8)(indir[i]);
4039 else
4040 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4041 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004042
4043 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4044 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004045}
4046
Greg Rose7e45ab42015-02-06 08:52:19 +00004047/**
4048 * i40e_get_priv_flags - report device private flags
4049 * @dev: network interface device structure
4050 *
4051 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004052 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004053 * array.
4054 *
4055 * Returns a u32 bitmap of flags.
4056 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004057static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004058{
4059 struct i40e_netdev_priv *np = netdev_priv(dev);
4060 struct i40e_vsi *vsi = np->vsi;
4061 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004062 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004063
Alexander Duyckaca955d2017-03-10 12:22:01 -08004064 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4065 const struct i40e_priv_flags *priv_flags;
4066
4067 priv_flags = &i40e_gstrings_priv_flags[i];
4068
4069 if (priv_flags->flag & pf->flags)
4070 ret_flags |= BIT(i);
4071 }
4072
4073 if (pf->hw.pf_id != 0)
4074 return ret_flags;
4075
4076 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4077 const struct i40e_priv_flags *priv_flags;
4078
4079 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4080
4081 if (priv_flags->flag & pf->flags)
4082 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004083 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004084
4085 return ret_flags;
4086}
4087
Shannon Nelson9ac77262015-08-27 11:42:40 -04004088/**
4089 * i40e_set_priv_flags - set private flags
4090 * @dev: network interface device structure
4091 * @flags: bit flags to be set
4092 **/
4093static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4094{
4095 struct i40e_netdev_priv *np = netdev_priv(dev);
4096 struct i40e_vsi *vsi = np->vsi;
4097 struct i40e_pf *pf = vsi->back;
Jacob Keller841c9502017-06-23 04:24:50 -04004098 u64 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004099 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004100
Jacob Keller841c9502017-06-23 04:24:50 -04004101 orig_flags = READ_ONCE(pf->flags);
4102 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004103
Alexander Duyckaca955d2017-03-10 12:22:01 -08004104 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4105 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004106
Alexander Duyckaca955d2017-03-10 12:22:01 -08004107 priv_flags = &i40e_gstrings_priv_flags[i];
4108
Alexander Duyckaca955d2017-03-10 12:22:01 -08004109 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004110 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004111 else
Jacob Keller841c9502017-06-23 04:24:50 -04004112 new_flags &= ~(priv_flags->flag);
4113
4114 /* If this is a read-only flag, it can't be changed */
4115 if (priv_flags->read_only &&
4116 ((orig_flags ^ new_flags) & ~BIT(i)))
4117 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004118 }
4119
4120 if (pf->hw.pf_id != 0)
4121 goto flags_complete;
4122
4123 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4124 const struct i40e_priv_flags *priv_flags;
4125
4126 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4127
Alexander Duyckaca955d2017-03-10 12:22:01 -08004128 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004129 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004130 else
Jacob Keller841c9502017-06-23 04:24:50 -04004131 new_flags &= ~(priv_flags->flag);
4132
4133 /* If this is a read-only flag, it can't be changed */
4134 if (priv_flags->read_only &&
4135 ((orig_flags ^ new_flags) & ~BIT(i)))
4136 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004137 }
4138
4139flags_complete:
Jacob Keller841c9502017-06-23 04:24:50 -04004140 /* Before we finalize any flag changes, we need to perform some
4141 * checks to ensure that the changes are supported and safe.
4142 */
4143
4144 /* ATR eviction is not supported on all devices */
4145 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4146 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4147 return -EOPNOTSUPP;
4148
4149 /* Compare and exchange the new flags into place. If we failed, that
4150 * is if cmpxchg64 returns anything but the old value, this means that
4151 * something else has modified the flags variable since we copied it
4152 * originally. We'll just punt with an error and log something in the
4153 * message buffer.
4154 */
4155 if (cmpxchg64(&pf->flags, orig_flags, new_flags) != orig_flags) {
4156 dev_warn(&pf->pdev->dev,
4157 "Unable to update pf->flags as it was modified by another thread...\n");
4158 return -EAGAIN;
4159 }
4160
4161 changed_flags = orig_flags ^ new_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004162
4163 /* Process any additional changes needed as a result of flag changes.
4164 * The changed_flags value reflects the list of bits that were
4165 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004166 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004167
Alexander Duyckaca955d2017-03-10 12:22:01 -08004168 /* Flush current ATR settings if ATR was disabled */
4169 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4170 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004171 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004172 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004173 }
4174
Alexander Duyckaca955d2017-03-10 12:22:01 -08004175 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4176 u16 sw_flags = 0, valid_flags = 0;
4177 int ret;
4178
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004179 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4180 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4181 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4182 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4183 NULL);
4184 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4185 dev_info(&pf->pdev->dev,
4186 "couldn't set switch config bits, err %s aq_err %s\n",
4187 i40e_stat_str(&pf->hw, ret),
4188 i40e_aq_str(&pf->hw,
4189 pf->hw.aq.asq_last_status));
4190 /* not a fatal problem, just keep going */
4191 }
4192 }
4193
Alexander Duyckaca955d2017-03-10 12:22:01 -08004194 /* Issue reset to cause things to take effect, as additional bits
4195 * are added we will need to create a mask of bits requiring reset
4196 */
Mitch Williams64615b52017-08-29 05:32:30 -04004197 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4198 I40E_FLAG_LEGACY_RX |
4199 I40E_FLAG_SOURCE_PRUNING_DISABLED))
Maciej Sosin373149f2017-04-05 07:50:55 -04004200 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004201
Shannon Nelson9ac77262015-08-27 11:42:40 -04004202 return 0;
4203}
4204
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004205/**
4206 * i40e_get_module_info - get (Q)SFP+ module type info
4207 * @netdev: network interface device structure
4208 * @modinfo: module EEPROM size and layout information structure
4209 **/
4210static int i40e_get_module_info(struct net_device *netdev,
4211 struct ethtool_modinfo *modinfo)
4212{
4213 struct i40e_netdev_priv *np = netdev_priv(netdev);
4214 struct i40e_vsi *vsi = np->vsi;
4215 struct i40e_pf *pf = vsi->back;
4216 struct i40e_hw *hw = &pf->hw;
4217 u32 sff8472_comp = 0;
4218 u32 sff8472_swap = 0;
4219 u32 sff8636_rev = 0;
4220 i40e_status status;
4221 u32 type = 0;
4222
4223 /* Check if firmware supports reading module EEPROM. */
4224 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4225 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4226 return -EINVAL;
4227 }
4228
4229 status = i40e_update_link_info(hw);
4230 if (status)
4231 return -EIO;
4232
4233 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4234 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4235 return -EINVAL;
4236 }
4237
4238 type = hw->phy.link_info.module_type[0];
4239
4240 switch (type) {
4241 case I40E_MODULE_TYPE_SFP:
4242 status = i40e_aq_get_phy_register(hw,
4243 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4244 I40E_I2C_EEPROM_DEV_ADDR,
4245 I40E_MODULE_SFF_8472_COMP,
4246 &sff8472_comp, NULL);
4247 if (status)
4248 return -EIO;
4249
4250 status = i40e_aq_get_phy_register(hw,
4251 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4252 I40E_I2C_EEPROM_DEV_ADDR,
4253 I40E_MODULE_SFF_8472_SWAP,
4254 &sff8472_swap, NULL);
4255 if (status)
4256 return -EIO;
4257
4258 /* Check if the module requires address swap to access
4259 * the other EEPROM memory page.
4260 */
4261 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4262 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4263 modinfo->type = ETH_MODULE_SFF_8079;
4264 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4265 } else if (sff8472_comp == 0x00) {
4266 /* Module is not SFF-8472 compliant */
4267 modinfo->type = ETH_MODULE_SFF_8079;
4268 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4269 } else {
4270 modinfo->type = ETH_MODULE_SFF_8472;
4271 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4272 }
4273 break;
4274 case I40E_MODULE_TYPE_QSFP_PLUS:
4275 /* Read from memory page 0. */
4276 status = i40e_aq_get_phy_register(hw,
4277 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4278 0,
4279 I40E_MODULE_REVISION_ADDR,
4280 &sff8636_rev, NULL);
4281 if (status)
4282 return -EIO;
4283 /* Determine revision compliance byte */
4284 if (sff8636_rev > 0x02) {
4285 /* Module is SFF-8636 compliant */
4286 modinfo->type = ETH_MODULE_SFF_8636;
4287 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4288 } else {
4289 modinfo->type = ETH_MODULE_SFF_8436;
4290 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4291 }
4292 break;
4293 case I40E_MODULE_TYPE_QSFP28:
4294 modinfo->type = ETH_MODULE_SFF_8636;
4295 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4296 break;
4297 default:
4298 netdev_err(vsi->netdev, "Module type unrecognized\n");
4299 return -EINVAL;
4300 }
4301 return 0;
4302}
4303
4304/**
4305 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4306 * @netdev: network interface device structure
4307 * @ee: EEPROM dump request structure
4308 * @data: buffer to be filled with EEPROM contents
4309 **/
4310static int i40e_get_module_eeprom(struct net_device *netdev,
4311 struct ethtool_eeprom *ee,
4312 u8 *data)
4313{
4314 struct i40e_netdev_priv *np = netdev_priv(netdev);
4315 struct i40e_vsi *vsi = np->vsi;
4316 struct i40e_pf *pf = vsi->back;
4317 struct i40e_hw *hw = &pf->hw;
4318 bool is_sfp = false;
4319 i40e_status status;
4320 u32 value = 0;
4321 int i;
4322
4323 if (!ee || !ee->len || !data)
4324 return -EINVAL;
4325
4326 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4327 is_sfp = true;
4328
4329 for (i = 0; i < ee->len; i++) {
4330 u32 offset = i + ee->offset;
4331 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4332
4333 /* Check if we need to access the other memory page */
4334 if (is_sfp) {
4335 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4336 offset -= ETH_MODULE_SFF_8079_LEN;
4337 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4338 }
4339 } else {
4340 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4341 /* Compute memory page number and offset. */
4342 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4343 addr++;
4344 }
4345 }
4346
4347 status = i40e_aq_get_phy_register(hw,
4348 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4349 addr, offset, &value, NULL);
4350 if (status)
4351 return -EIO;
4352 data[i] = value;
4353 }
4354 return 0;
4355}
4356
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004357static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004358 .get_drvinfo = i40e_get_drvinfo,
4359 .get_regs_len = i40e_get_regs_len,
4360 .get_regs = i40e_get_regs,
4361 .nway_reset = i40e_nway_reset,
4362 .get_link = ethtool_op_get_link,
4363 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004364 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004365 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004366 .get_eeprom_len = i40e_get_eeprom_len,
4367 .get_eeprom = i40e_get_eeprom,
4368 .get_ringparam = i40e_get_ringparam,
4369 .set_ringparam = i40e_set_ringparam,
4370 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004371 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004372 .get_msglevel = i40e_get_msglevel,
4373 .set_msglevel = i40e_set_msglevel,
4374 .get_rxnfc = i40e_get_rxnfc,
4375 .set_rxnfc = i40e_set_rxnfc,
4376 .self_test = i40e_diag_test,
4377 .get_strings = i40e_get_strings,
4378 .set_phys_id = i40e_set_phys_id,
4379 .get_sset_count = i40e_get_sset_count,
4380 .get_ethtool_stats = i40e_get_ethtool_stats,
4381 .get_coalesce = i40e_get_coalesce,
4382 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004383 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4384 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4385 .get_rxfh = i40e_get_rxfh,
4386 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004387 .get_channels = i40e_get_channels,
4388 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004389 .get_module_info = i40e_get_module_info,
4390 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004391 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004392 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004393 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004394 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004395 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004396 .get_link_ksettings = i40e_get_link_ksettings,
4397 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004398};
4399
4400void i40e_set_ethtool_ops(struct net_device *netdev)
4401{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004402 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004403}