blob: 35a246f0552076b896851a3e326d237661d764d5 [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),
228 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_CAPABLE, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700229 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800230};
231
232#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000233
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700234/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800235static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
236 I40E_PRIV_FLAG("vf-true-promisc-support",
237 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700238};
239
Alexander Duyckaca955d2017-03-10 12:22:01 -0800240#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700241
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000242/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000243 * i40e_partition_setting_complaint - generic complaint for MFP restriction
244 * @pf: the PF struct
245 **/
246static void i40e_partition_setting_complaint(struct i40e_pf *pf)
247{
248 dev_info(&pf->pdev->dev,
249 "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");
250}
251
252/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700253 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
254 * @phy_types: PHY types to convert
255 * @supported: pointer to the ethtool supported variable to fill in
256 * @advertising: pointer to the ethtool advertising variable to fill in
257 *
258 **/
259static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
260 u32 *advertising)
261{
Avinash Dayanand28537042016-06-20 09:10:33 -0700262 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800263 u64 phy_types = pf->hw.phy.phy_types;
264
Catherine Sullivan06566e52016-05-03 15:13:14 -0700265 *supported = 0x0;
266 *advertising = 0x0;
267
268 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
269 *supported |= SUPPORTED_Autoneg |
270 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700271 *advertising |= ADVERTISED_Autoneg;
272 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
273 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700274 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
275 *supported |= SUPPORTED_100baseT_Full;
276 *advertising |= ADVERTISED_100baseT_Full;
277 }
278 }
279 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
280 phy_types & I40E_CAP_PHY_TYPE_XFI ||
281 phy_types & I40E_CAP_PHY_TYPE_SFI ||
282 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
283 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
284 *supported |= SUPPORTED_10000baseT_Full;
285 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
286 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
287 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
288 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
289 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
290 *supported |= SUPPORTED_Autoneg |
291 SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700292 *advertising |= ADVERTISED_Autoneg;
293 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
294 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700295 }
296 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
297 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
298 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
299 *supported |= SUPPORTED_40000baseCR4_Full;
300 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
301 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
302 *supported |= SUPPORTED_Autoneg |
303 SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700304 *advertising |= ADVERTISED_Autoneg;
305 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
306 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700307 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700308 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700309 *supported |= SUPPORTED_Autoneg |
310 SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700311 *advertising |= ADVERTISED_Autoneg;
312 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
313 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700314 }
315 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
316 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
317 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
318 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
319 *supported |= SUPPORTED_Autoneg |
320 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700321 *advertising |= ADVERTISED_Autoneg;
322 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
323 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700324 }
325 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
326 *supported |= SUPPORTED_40000baseSR4_Full;
327 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
328 *supported |= SUPPORTED_40000baseLR4_Full;
329 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
330 *supported |= SUPPORTED_40000baseKR4_Full |
331 SUPPORTED_Autoneg;
332 *advertising |= ADVERTISED_40000baseKR4_Full |
333 ADVERTISED_Autoneg;
334 }
335 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
336 *supported |= SUPPORTED_20000baseKR2_Full |
337 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700338 *advertising |= ADVERTISED_Autoneg;
339 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
340 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700341 }
342 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800343 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
344 *supported |= SUPPORTED_10000baseKR_Full |
345 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700346 *advertising |= ADVERTISED_Autoneg;
347 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800348 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
349 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700350 }
351 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
352 *supported |= SUPPORTED_10000baseKX4_Full |
353 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700354 *advertising |= ADVERTISED_Autoneg;
355 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
356 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700357 }
358 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800359 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
360 *supported |= SUPPORTED_1000baseKX_Full |
361 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700362 *advertising |= ADVERTISED_Autoneg;
363 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800364 if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER))
365 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700366 }
Carolyn Wyborny31232372016-11-21 13:03:48 -0800367 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
368 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
369 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
370 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
371 *supported |= SUPPORTED_Autoneg;
372 *advertising |= ADVERTISED_Autoneg;
373 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700374}
375
376/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000377 * i40e_get_settings_link_up - Get the Link settings for when link is up
378 * @hw: hw structure
379 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000380 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000381 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000382 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000383static void i40e_get_settings_link_up(struct i40e_hw *hw,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100384 struct ethtool_link_ksettings *cmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400385 struct net_device *netdev,
386 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000388 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000389 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700390 u32 e_advertising = 0x0;
391 u32 e_supported = 0x0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100392 u32 supported, advertising;
393
394 ethtool_convert_link_mode_to_legacy_u32(&supported,
395 cmd->link_modes.supported);
396 ethtool_convert_link_mode_to_legacy_u32(&advertising,
397 cmd->link_modes.advertising);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000398
Catherine Sullivane8278452015-02-06 08:52:08 +0000399 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000400 switch (hw_link_info->phy_type) {
401 case I40E_PHY_TYPE_40GBASE_CR4:
402 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100403 supported = SUPPORTED_Autoneg |
404 SUPPORTED_40000baseCR4_Full;
405 advertising = ADVERTISED_Autoneg |
406 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000407 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000408 case I40E_PHY_TYPE_XLAUI:
409 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000410 case I40E_PHY_TYPE_40GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100411 supported = SUPPORTED_40000baseCR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000412 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000413 case I40E_PHY_TYPE_40GBASE_SR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100414 supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000415 break;
416 case I40E_PHY_TYPE_40GBASE_LR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100417 supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000418 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000419 case I40E_PHY_TYPE_10GBASE_SR:
420 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000421 case I40E_PHY_TYPE_1000BASE_SX:
422 case I40E_PHY_TYPE_1000BASE_LX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100423 supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400424 if (hw_link_info->module_type[2] &
425 I40E_MODULE_TYPE_1000BASE_SX ||
426 hw_link_info->module_type[2] &
427 I40E_MODULE_TYPE_1000BASE_LX) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100428 supported |= SUPPORTED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400429 if (hw_link_info->requested_speeds &
430 I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100431 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400432 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000433 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100434 advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000435 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000436 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000437 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700438 case I40E_PHY_TYPE_100BASE_TX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100439 supported = SUPPORTED_Autoneg |
440 SUPPORTED_10000baseT_Full |
441 SUPPORTED_1000baseT_Full |
442 SUPPORTED_100baseT_Full;
443 advertising = ADVERTISED_Autoneg;
Catherine Sullivane8278452015-02-06 08:52:08 +0000444 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100445 advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000446 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100447 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700448 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100449 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400450 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400451 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100452 supported = SUPPORTED_Autoneg |
453 SUPPORTED_1000baseT_Full;
454 advertising = ADVERTISED_Autoneg |
455 ADVERTISED_1000baseT_Full;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400456 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000457 case I40E_PHY_TYPE_10GBASE_CR1_CU:
458 case I40E_PHY_TYPE_10GBASE_CR1:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100459 supported = SUPPORTED_Autoneg |
460 SUPPORTED_10000baseT_Full;
461 advertising = ADVERTISED_Autoneg |
462 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000463 break;
464 case I40E_PHY_TYPE_XAUI:
465 case I40E_PHY_TYPE_XFI:
466 case I40E_PHY_TYPE_SFI:
467 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000468 case I40E_PHY_TYPE_10GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100469 supported = SUPPORTED_10000baseT_Full;
470 advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000471 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000472 case I40E_PHY_TYPE_SGMII:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100473 supported = SUPPORTED_Autoneg |
474 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000475 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100476 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan48b18042015-12-09 15:50:25 -0800477 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100478 supported |= SUPPORTED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400479 if (hw_link_info->requested_speeds &
480 I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100481 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400482 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400484 case I40E_PHY_TYPE_40GBASE_KR4:
485 case I40E_PHY_TYPE_20GBASE_KR2:
486 case I40E_PHY_TYPE_10GBASE_KR:
487 case I40E_PHY_TYPE_10GBASE_KX4:
488 case I40E_PHY_TYPE_1000BASE_KX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100489 supported |= SUPPORTED_40000baseKR4_Full |
490 SUPPORTED_20000baseKR2_Full |
491 SUPPORTED_10000baseKR_Full |
492 SUPPORTED_10000baseKX4_Full |
493 SUPPORTED_1000baseKX_Full |
494 SUPPORTED_Autoneg;
495 advertising |= ADVERTISED_40000baseKR4_Full |
496 ADVERTISED_20000baseKR2_Full |
497 ADVERTISED_10000baseKR_Full |
498 ADVERTISED_10000baseKX4_Full |
499 ADVERTISED_1000baseKX_Full |
500 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400501 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800502 case I40E_PHY_TYPE_25GBASE_KR:
503 case I40E_PHY_TYPE_25GBASE_CR:
504 case I40E_PHY_TYPE_25GBASE_SR:
505 case I40E_PHY_TYPE_25GBASE_LR:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100506 supported = SUPPORTED_Autoneg;
507 advertising = ADVERTISED_Autoneg;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800508 /* TODO: add speeds when ethtool is ready to support*/
509 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000510 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000511 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000512 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
513 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000514 }
515
Catherine Sullivan06566e52016-05-03 15:13:14 -0700516 /* Now that we've worked out everything that could be supported by the
517 * current PHY type, get what is supported by the NVM and them to
518 * get what is truly supported
519 */
520 i40e_phy_type_to_ethtool(pf, &e_supported,
521 &e_advertising);
522
Philippe Reynesa7f90942017-02-04 22:05:06 +0100523 supported = supported & e_supported;
524 advertising = advertising & e_advertising;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700525
Catherine Sullivane8278452015-02-06 08:52:08 +0000526 /* Set speed and duplex */
527 switch (link_speed) {
528 case I40E_LINK_SPEED_40GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100529 cmd->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000530 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800531 case I40E_LINK_SPEED_25GB:
532#ifdef SPEED_25000
Philippe Reynesa7f90942017-02-04 22:05:06 +0100533 cmd->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800534#else
535 netdev_info(netdev,
536 "Speed is 25G, display not supported by this version of ethtool.\n");
537#endif
538 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700539 case I40E_LINK_SPEED_20GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100540 cmd->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700541 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000542 case I40E_LINK_SPEED_10GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100543 cmd->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000544 break;
545 case I40E_LINK_SPEED_1GB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100546 cmd->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000547 break;
548 case I40E_LINK_SPEED_100MB:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100549 cmd->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000550 break;
551 default:
552 break;
553 }
Philippe Reynesa7f90942017-02-04 22:05:06 +0100554 cmd->base.duplex = DUPLEX_FULL;
555
556 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
557 supported);
558 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
559 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000560}
561
562/**
563 * i40e_get_settings_link_down - Get the Link settings for when link is down
564 * @hw: hw structure
565 * @ecmd: ethtool command to fill in
566 *
567 * Reports link settings that can be determined when link is down
568 **/
569static void i40e_get_settings_link_down(struct i40e_hw *hw,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100570 struct ethtool_link_ksettings *cmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400571 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000572{
Philippe Reynesa7f90942017-02-04 22:05:06 +0100573 u32 supported, advertising;
574
Catherine Sullivane8278452015-02-06 08:52:08 +0000575 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400576 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000577 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100578 i40e_phy_type_to_ethtool(pf, &supported, &advertising);
579
580 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
581 supported);
582 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
583 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000584
585 /* With no link speed and duplex are unknown */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100586 cmd->base.speed = SPEED_UNKNOWN;
587 cmd->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000588}
589
590/**
591 * i40e_get_settings - Get Link Speed and Duplex settings
592 * @netdev: network interface device structure
593 * @ecmd: ethtool command
594 *
595 * Reports speed/duplex settings based on media_type
596 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100597static int i40e_get_link_ksettings(struct net_device *netdev,
598 struct ethtool_link_ksettings *cmd)
Catherine Sullivane8278452015-02-06 08:52:08 +0000599{
600 struct i40e_netdev_priv *np = netdev_priv(netdev);
601 struct i40e_pf *pf = np->vsi->back;
602 struct i40e_hw *hw = &pf->hw;
603 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
604 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100605 u32 advertising;
Catherine Sullivane8278452015-02-06 08:52:08 +0000606
607 if (link_up)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100608 i40e_get_settings_link_up(hw, cmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000609 else
Philippe Reynesa7f90942017-02-04 22:05:06 +0100610 i40e_get_settings_link_down(hw, cmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000611
612 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000613 /* Set autoneg settings */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100614 cmd->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000615 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000616
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000617 switch (hw->phy.media_type) {
618 case I40E_MEDIA_TYPE_BACKPLANE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100619 ethtool_link_ksettings_add_link_mode(cmd, supported,
620 Autoneg);
621 ethtool_link_ksettings_add_link_mode(cmd, supported,
622 Backplane);
623 ethtool_link_ksettings_add_link_mode(cmd, advertising,
624 Autoneg);
625 ethtool_link_ksettings_add_link_mode(cmd, advertising,
626 Backplane);
627 cmd->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000628 break;
629 case I40E_MEDIA_TYPE_BASET:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100630 ethtool_link_ksettings_add_link_mode(cmd, supported, TP);
631 ethtool_link_ksettings_add_link_mode(cmd, advertising, TP);
632 cmd->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000633 break;
634 case I40E_MEDIA_TYPE_DA:
635 case I40E_MEDIA_TYPE_CX4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100636 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
637 ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE);
638 cmd->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000639 break;
640 case I40E_MEDIA_TYPE_FIBER:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100641 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
642 cmd->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000643 break;
644 case I40E_MEDIA_TYPE_UNKNOWN:
645 default:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100646 cmd->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000647 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000648 }
649
Catherine Sullivane8278452015-02-06 08:52:08 +0000650 /* Set flow control settings */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100651 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000652
Catherine Sullivane8278452015-02-06 08:52:08 +0000653 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000654 case I40E_FC_FULL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100655 ethtool_link_ksettings_add_link_mode(cmd, advertising,
656 Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000657 break;
658 case I40E_FC_TX_PAUSE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100659 ethtool_link_ksettings_add_link_mode(cmd, advertising,
660 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000661 break;
662 case I40E_FC_RX_PAUSE:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100663 ethtool_link_ksettings_add_link_mode(cmd, advertising,
664 Pause);
665 ethtool_link_ksettings_add_link_mode(cmd, advertising,
666 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000667 break;
668 default:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100669 ethtool_convert_link_mode_to_legacy_u32(
670 &advertising, cmd->link_modes.advertising);
671
672 advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
673
674 ethtool_convert_legacy_u32_to_link_mode(
675 cmd->link_modes.advertising, advertising);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000676 break;
677 }
678
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000679 return 0;
680}
681
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000682/**
683 * i40e_set_settings - Set Speed and Duplex
684 * @netdev: network interface device structure
685 * @ecmd: ethtool command
686 *
687 * Set speed/duplex per media_types advertised/forced
688 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100689static int i40e_set_link_ksettings(struct net_device *netdev,
690 const struct ethtool_link_ksettings *cmd)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000691{
692 struct i40e_netdev_priv *np = netdev_priv(netdev);
693 struct i40e_aq_get_phy_abilities_resp abilities;
694 struct i40e_aq_set_phy_config config;
695 struct i40e_pf *pf = np->vsi->back;
696 struct i40e_vsi *vsi = np->vsi;
697 struct i40e_hw *hw = &pf->hw;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100698 struct ethtool_link_ksettings safe_cmd;
699 struct ethtool_link_ksettings copy_cmd;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000700 i40e_status status = 0;
701 bool change = false;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400702 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000703 int err = 0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100704 u32 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000705 u32 advertise;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100706 u32 tmp;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000707
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000708 /* Changing port settings is not supported if this isn't the
709 * port's controlling PF
710 */
711 if (hw->partition_id != 1) {
712 i40e_partition_setting_complaint(pf);
713 return -EOPNOTSUPP;
714 }
715
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000716 if (vsi != pf->vsi[pf->lan_vsi])
717 return -EOPNOTSUPP;
718
719 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
720 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000721 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700722 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000723 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000724 return -EOPNOTSUPP;
725
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400726 if (hw->device_id == I40E_DEV_ID_KX_B ||
727 hw->device_id == I40E_DEV_ID_KX_C ||
728 hw->device_id == I40E_DEV_ID_20G_KR2 ||
729 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
730 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
731 return -EOPNOTSUPP;
732 }
733
Philippe Reynesa7f90942017-02-04 22:05:06 +0100734 /* copy the cmd to copy_cmd to avoid modifying the origin */
735 memcpy(&copy_cmd, cmd, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000736
Philippe Reynesa7f90942017-02-04 22:05:06 +0100737 /* get our own copy of the bits to check against */
738 memset(&safe_cmd, 0, sizeof(struct ethtool_link_ksettings));
739 i40e_get_link_ksettings(netdev, &safe_cmd);
740
741 /* save autoneg and speed out of cmd */
742 autoneg = cmd->base.autoneg;
743 ethtool_convert_link_mode_to_legacy_u32(&advertise,
744 cmd->link_modes.advertising);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000745
746 /* set autoneg and speed back to what they currently are */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100747 copy_cmd.base.autoneg = safe_cmd.base.autoneg;
748 ethtool_convert_link_mode_to_legacy_u32(
749 &tmp, safe_cmd.link_modes.advertising);
750 ethtool_convert_legacy_u32_to_link_mode(
751 copy_cmd.link_modes.advertising, tmp);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000752
Philippe Reynesa7f90942017-02-04 22:05:06 +0100753 copy_cmd.base.cmd = safe_cmd.base.cmd;
754
755 /* If copy_cmd and safe_cmd are not the same now, then they are
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000756 * trying to set something that we do not support
757 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100758 if (memcmp(&copy_cmd, &safe_cmd, sizeof(struct ethtool_link_ksettings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000759 return -EOPNOTSUPP;
760
Jacob Keller0da36b92017-04-19 09:25:55 -0400761 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400762 timeout--;
763 if (!timeout)
764 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000765 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400766 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000767
768 /* Get the current phy config */
769 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
770 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400771 if (status) {
772 err = -EAGAIN;
773 goto done;
774 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000775
Catherine Sullivan124ed152014-07-12 07:28:12 +0000776 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000777 * set below
778 */
779 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000780 config.abilities = abilities.abilities;
781
782 /* Check autoneg */
783 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000784 /* If autoneg was not already enabled */
785 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400786 /* If autoneg is not supported, return error */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100787 if (!ethtool_link_ksettings_test_link_mode(
788 &safe_cmd, supported, Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400789 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400790 err = -EINVAL;
791 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400792 }
793 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000794 config.abilities = abilities.abilities |
795 I40E_AQ_PHY_ENABLE_AN;
796 change = true;
797 }
798 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000799 /* If autoneg is currently enabled */
800 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400801 /* If autoneg is supported 10GBASE_T is the only PHY
802 * that can disable it, so otherwise return error
803 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100804 if (ethtool_link_ksettings_test_link_mode(
805 &safe_cmd, supported, Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400806 hw->phy.link_info.phy_type !=
807 I40E_PHY_TYPE_10GBASE_T) {
808 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400809 err = -EINVAL;
810 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400811 }
812 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000813 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000814 ~I40E_AQ_PHY_ENABLE_AN;
815 change = true;
816 }
817 }
818
Philippe Reynesa7f90942017-02-04 22:05:06 +0100819 ethtool_convert_link_mode_to_legacy_u32(&tmp,
820 safe_cmd.link_modes.supported);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400821 if (advertise & ~tmp) {
822 err = -EINVAL;
823 goto done;
824 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000825
826 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000827 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000828 if (advertise & ADVERTISED_1000baseT_Full ||
829 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000830 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000831 if (advertise & ADVERTISED_10000baseT_Full ||
832 advertise & ADVERTISED_10000baseKX4_Full ||
833 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000834 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700835 if (advertise & ADVERTISED_20000baseKR2_Full)
836 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000837 if (advertise & ADVERTISED_40000baseKR4_Full ||
838 advertise & ADVERTISED_40000baseCR4_Full ||
839 advertise & ADVERTISED_40000baseSR4_Full ||
840 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000841 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000842
Catherine Sullivan0002e112015-08-26 15:14:16 -0400843 /* If speed didn't get set, set it to what it currently is.
844 * This is needed because if advertise is 0 (as it is when autoneg
845 * is disabled) then speed won't get set.
846 */
847 if (!config.link_speed)
848 config.link_speed = abilities.link_speed;
849
Catherine Sullivan124ed152014-07-12 07:28:12 +0000850 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000851 /* copy over the rest of the abilities */
852 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800853 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000854 config.eee_capability = abilities.eee_capability;
855 config.eeer = abilities.eeer_val;
856 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800857 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
858 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000859
Catherine Sullivane8278452015-02-06 08:52:08 +0000860 /* save the requested speeds */
861 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000862 /* set link and auto negotiation so changes take effect */
863 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
864 /* If link is up put link down */
865 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
866 /* Tell the OS link is going down, the link will go
867 * back up when fw says it is ready asynchronously
868 */
Matt Jaredc156f852015-08-27 11:42:39 -0400869 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000870 netif_carrier_off(netdev);
871 netif_tx_stop_all_queues(netdev);
872 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000873
874 /* make the aq call */
875 status = i40e_aq_set_phy_config(hw, &config, NULL);
876 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400877 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
878 i40e_stat_str(hw, status),
879 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400880 err = -EAGAIN;
881 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000882 }
883
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400884 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000885 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400886 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
887 i40e_stat_str(hw, status),
888 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000889
890 } else {
891 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
892 }
893
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400894done:
Jacob Keller0da36b92017-04-19 09:25:55 -0400895 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400896
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000897 return err;
898}
899
Jesse Brandeburga6599722014-06-04 08:45:25 +0000900static int i40e_nway_reset(struct net_device *netdev)
901{
902 /* restart autonegotiation */
903 struct i40e_netdev_priv *np = netdev_priv(netdev);
904 struct i40e_pf *pf = np->vsi->back;
905 struct i40e_hw *hw = &pf->hw;
906 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
907 i40e_status ret = 0;
908
909 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
910 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400911 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
912 i40e_stat_str(hw, ret),
913 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000914 return -EIO;
915 }
916
917 return 0;
918}
919
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000920/**
921 * i40e_get_pauseparam - Get Flow Control status
922 * Return tx/rx-pause status
923 **/
924static void i40e_get_pauseparam(struct net_device *netdev,
925 struct ethtool_pauseparam *pause)
926{
927 struct i40e_netdev_priv *np = netdev_priv(netdev);
928 struct i40e_pf *pf = np->vsi->back;
929 struct i40e_hw *hw = &pf->hw;
930 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000931 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000932
933 pause->autoneg =
934 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
935 AUTONEG_ENABLE : AUTONEG_DISABLE);
936
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000937 /* PFC enabled so report LFC as off */
938 if (dcbx_cfg->pfc.pfcenable) {
939 pause->rx_pause = 0;
940 pause->tx_pause = 0;
941 return;
942 }
943
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000944 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000945 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000946 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000947 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000948 } else if (hw->fc.current_mode == I40E_FC_FULL) {
949 pause->rx_pause = 1;
950 pause->tx_pause = 1;
951 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000952}
953
Catherine Sullivan2becc352014-06-04 08:45:27 +0000954/**
955 * i40e_set_pauseparam - Set Flow Control parameter
956 * @netdev: network interface device structure
957 * @pause: return tx/rx flow control status
958 **/
959static int i40e_set_pauseparam(struct net_device *netdev,
960 struct ethtool_pauseparam *pause)
961{
962 struct i40e_netdev_priv *np = netdev_priv(netdev);
963 struct i40e_pf *pf = np->vsi->back;
964 struct i40e_vsi *vsi = np->vsi;
965 struct i40e_hw *hw = &pf->hw;
966 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000967 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000968 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
969 i40e_status status;
970 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000971 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000972
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000973 /* Changing the port's flow control is not supported if this isn't the
974 * port's controlling PF
975 */
976 if (hw->partition_id != 1) {
977 i40e_partition_setting_complaint(pf);
978 return -EOPNOTSUPP;
979 }
980
Catherine Sullivan2becc352014-06-04 08:45:27 +0000981 if (vsi != pf->vsi[pf->lan_vsi])
982 return -EOPNOTSUPP;
983
984 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
985 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
986 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
987 return -EOPNOTSUPP;
988 }
989
990 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -0400991 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +0000992 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
993 /* Send message that it might not necessarily work*/
994 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
995 }
996
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000997 if (dcbx_cfg->pfc.pfcenable) {
998 netdev_info(netdev,
999 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001000 return -EOPNOTSUPP;
1001 }
1002
1003 if (pause->rx_pause && pause->tx_pause)
1004 hw->fc.requested_mode = I40E_FC_FULL;
1005 else if (pause->rx_pause && !pause->tx_pause)
1006 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1007 else if (!pause->rx_pause && pause->tx_pause)
1008 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1009 else if (!pause->rx_pause && !pause->tx_pause)
1010 hw->fc.requested_mode = I40E_FC_NONE;
1011 else
1012 return -EINVAL;
1013
Catherine Sullivan94128512014-07-12 07:28:16 +00001014 /* Tell the OS link is going down, the link will go back up when fw
1015 * says it is ready asynchronously
1016 */
Matt Jaredc156f852015-08-27 11:42:39 -04001017 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001018 netif_carrier_off(netdev);
1019 netif_tx_stop_all_queues(netdev);
1020
Catherine Sullivan2becc352014-06-04 08:45:27 +00001021 /* Set the fc mode and only restart an if link is up*/
1022 status = i40e_set_fc(hw, &aq_failures, link_up);
1023
1024 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001025 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1026 i40e_stat_str(hw, status),
1027 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001028 err = -EAGAIN;
1029 }
1030 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001031 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1032 i40e_stat_str(hw, status),
1033 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001034 err = -EAGAIN;
1035 }
1036 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001037 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1038 i40e_stat_str(hw, status),
1039 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001040 err = -EAGAIN;
1041 }
1042
Jacob Keller0da36b92017-04-19 09:25:55 -04001043 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001044 /* Give it a little more time to try to come back */
1045 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001046 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001047 return i40e_nway_reset(netdev);
1048 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001049
1050 return err;
1051}
1052
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001053static u32 i40e_get_msglevel(struct net_device *netdev)
1054{
1055 struct i40e_netdev_priv *np = netdev_priv(netdev);
1056 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001057 u32 debug_mask = pf->hw.debug_mask;
1058
1059 if (debug_mask)
1060 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001061
1062 return pf->msg_enable;
1063}
1064
1065static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1066{
1067 struct i40e_netdev_priv *np = netdev_priv(netdev);
1068 struct i40e_pf *pf = np->vsi->back;
1069
1070 if (I40E_DEBUG_USER & data)
1071 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001072 else
1073 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001074}
1075
1076static int i40e_get_regs_len(struct net_device *netdev)
1077{
1078 int reg_count = 0;
1079 int i;
1080
1081 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1082 reg_count += i40e_reg_list[i].elements;
1083
1084 return reg_count * sizeof(u32);
1085}
1086
1087static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1088 void *p)
1089{
1090 struct i40e_netdev_priv *np = netdev_priv(netdev);
1091 struct i40e_pf *pf = np->vsi->back;
1092 struct i40e_hw *hw = &pf->hw;
1093 u32 *reg_buf = p;
1094 int i, j, ri;
1095 u32 reg;
1096
1097 /* Tell ethtool which driver-version-specific regs output we have.
1098 *
1099 * At some point, if we have ethtool doing special formatting of
1100 * this data, it will rely on this version number to know how to
1101 * interpret things. Hence, this needs to be updated if/when the
1102 * diags register table is changed.
1103 */
1104 regs->version = 1;
1105
1106 /* loop through the diags reg table for what to print */
1107 ri = 0;
1108 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1109 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1110 reg = i40e_reg_list[i].offset
1111 + (j * i40e_reg_list[i].stride);
1112 reg_buf[ri++] = rd32(hw, reg);
1113 }
1114 }
1115
1116}
1117
1118static int i40e_get_eeprom(struct net_device *netdev,
1119 struct ethtool_eeprom *eeprom, u8 *bytes)
1120{
1121 struct i40e_netdev_priv *np = netdev_priv(netdev);
1122 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001123 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001124 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001125 u8 *eeprom_buff;
1126 u16 i, sectors;
1127 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001128 u32 magic;
1129
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001130#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001131 if (eeprom->len == 0)
1132 return -EINVAL;
1133
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001134 /* check for NVMUpdate access method */
1135 magic = hw->vendor_id | (hw->device_id << 16);
1136 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001137 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1138 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001139
1140 /* make sure it is the right magic for NVMUpdate */
1141 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001142 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001143 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1144 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001145 errno = -EBUSY;
1146 else
1147 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001148
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001149 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001150 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001151 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1152 ret_val, hw->aq.asq_last_status, errno,
1153 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1154 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001155
1156 return errno;
1157 }
1158
1159 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001160 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1161
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001162 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001163 if (!eeprom_buff)
1164 return -ENOMEM;
1165
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001166 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1167 if (ret_val) {
1168 dev_info(&pf->pdev->dev,
1169 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1170 ret_val, hw->aq.asq_last_status);
1171 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001172 }
1173
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001174 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1175 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1176 len = I40E_NVM_SECTOR_SIZE;
1177 last = false;
1178 for (i = 0; i < sectors; i++) {
1179 if (i == (sectors - 1)) {
1180 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1181 last = true;
1182 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001183 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1184 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001185 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001186 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001187 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001188 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001189 "read NVM failed, invalid offset 0x%x\n",
1190 offset);
1191 break;
1192 } else if (ret_val &&
1193 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1194 dev_info(&pf->pdev->dev,
1195 "read NVM failed, access, offset 0x%x\n",
1196 offset);
1197 break;
1198 } else if (ret_val) {
1199 dev_info(&pf->pdev->dev,
1200 "read NVM failed offset %d err=%d status=0x%x\n",
1201 offset, ret_val, hw->aq.asq_last_status);
1202 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001203 }
1204 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001205
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001206 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001207 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001208free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001209 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001210 return ret_val;
1211}
1212
1213static int i40e_get_eeprom_len(struct net_device *netdev)
1214{
1215 struct i40e_netdev_priv *np = netdev_priv(netdev);
1216 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001217 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001218
Lihong Yangc271dd62017-01-30 12:29:32 -08001219#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1220 if (hw->mac.type == I40E_MAC_X722) {
1221 val = X722_EEPROM_SCOPE_LIMIT + 1;
1222 return val;
1223 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001224 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1225 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1226 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1227 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001228 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001229 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001230}
1231
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001232static int i40e_set_eeprom(struct net_device *netdev,
1233 struct ethtool_eeprom *eeprom, u8 *bytes)
1234{
1235 struct i40e_netdev_priv *np = netdev_priv(netdev);
1236 struct i40e_hw *hw = &np->vsi->back->hw;
1237 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001238 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001239 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001240 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001241 u32 magic;
1242
1243 /* normal ethtool set_eeprom is not supported */
1244 magic = hw->vendor_id | (hw->device_id << 16);
1245 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001246 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001247 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001248 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1249 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001250 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1251 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001252 errno = -EBUSY;
1253 else
1254 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001255
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001256 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001257 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001258 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1259 ret_val, hw->aq.asq_last_status, errno,
1260 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1261 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001262
1263 return errno;
1264}
1265
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001266static void i40e_get_drvinfo(struct net_device *netdev,
1267 struct ethtool_drvinfo *drvinfo)
1268{
1269 struct i40e_netdev_priv *np = netdev_priv(netdev);
1270 struct i40e_vsi *vsi = np->vsi;
1271 struct i40e_pf *pf = vsi->back;
1272
1273 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1274 strlcpy(drvinfo->version, i40e_driver_version_str,
1275 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001276 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 sizeof(drvinfo->fw_version));
1278 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1279 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001280 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001281 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001282 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001283}
1284
1285static void i40e_get_ringparam(struct net_device *netdev,
1286 struct ethtool_ringparam *ring)
1287{
1288 struct i40e_netdev_priv *np = netdev_priv(netdev);
1289 struct i40e_pf *pf = np->vsi->back;
1290 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1291
1292 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1293 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1294 ring->rx_mini_max_pending = 0;
1295 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001296 ring->rx_pending = vsi->rx_rings[0]->count;
1297 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001298 ring->rx_mini_pending = 0;
1299 ring->rx_jumbo_pending = 0;
1300}
1301
1302static int i40e_set_ringparam(struct net_device *netdev,
1303 struct ethtool_ringparam *ring)
1304{
1305 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1306 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001307 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001308 struct i40e_vsi *vsi = np->vsi;
1309 struct i40e_pf *pf = vsi->back;
1310 u32 new_rx_count, new_tx_count;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001311 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001312 int i, err = 0;
1313
1314 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1315 return -EINVAL;
1316
Shannon Nelson1fa18372013-11-20 10:03:08 +00001317 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1318 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1319 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1320 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1321 netdev_info(netdev,
1322 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1323 ring->tx_pending, ring->rx_pending,
1324 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1325 return -EINVAL;
1326 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001327
Shannon Nelson1fa18372013-11-20 10:03:08 +00001328 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1329 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001330
1331 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001332 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1333 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001334 return 0;
1335
Jacob Keller0da36b92017-04-19 09:25:55 -04001336 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001337 timeout--;
1338 if (!timeout)
1339 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001340 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001341 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001342
1343 if (!netif_running(vsi->netdev)) {
1344 /* simple case - set for the next time the netdev is started */
1345 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001346 vsi->tx_rings[i]->count = new_tx_count;
1347 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 }
1349 goto done;
1350 }
1351
1352 /* We can't just free everything and then setup again,
1353 * because the ISRs in MSI-X mode get passed pointers
1354 * to the Tx and Rx ring structs.
1355 */
1356
1357 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001358 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001359 netdev_info(netdev,
1360 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001361 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001362 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1363 sizeof(struct i40e_ring), GFP_KERNEL);
1364 if (!tx_rings) {
1365 err = -ENOMEM;
1366 goto done;
1367 }
1368
1369 for (i = 0; i < vsi->num_queue_pairs; i++) {
1370 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001371 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001372 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001373 /* the desc and bi pointers will be reallocated in the
1374 * setup call
1375 */
1376 tx_rings[i].desc = NULL;
1377 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001378 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1379 if (err) {
1380 while (i) {
1381 i--;
1382 i40e_free_tx_resources(&tx_rings[i]);
1383 }
1384 kfree(tx_rings);
1385 tx_rings = NULL;
1386
1387 goto done;
1388 }
1389 }
1390 }
1391
1392 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001393 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001394 netdev_info(netdev,
1395 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001396 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001397 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1398 sizeof(struct i40e_ring), GFP_KERNEL);
1399 if (!rx_rings) {
1400 err = -ENOMEM;
1401 goto free_tx;
1402 }
1403
1404 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001405 struct i40e_ring *ring;
1406 u16 unused;
1407
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001408 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001409 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001410 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001411 /* the desc and bi pointers will be reallocated in the
1412 * setup call
1413 */
1414 rx_rings[i].desc = NULL;
1415 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001416 /* this is to allow wr32 to have something to write to
1417 * during early allocation of Rx buffers
1418 */
1419 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001421 if (err)
1422 goto rx_unwind;
1423
1424 /* now allocate the Rx buffers to make sure the OS
1425 * has enough memory, any failure here means abort
1426 */
1427 ring = &rx_rings[i];
1428 unused = I40E_DESC_UNUSED(ring);
1429 err = i40e_alloc_rx_buffers(ring, unused);
1430rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001431 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001432 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001433 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001434 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001435 kfree(rx_rings);
1436 rx_rings = NULL;
1437
1438 goto free_tx;
1439 }
1440 }
1441 }
1442
1443 /* Bring interface down, copy in the new ring info,
1444 * then restore the interface
1445 */
1446 i40e_down(vsi);
1447
1448 if (tx_rings) {
1449 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001450 i40e_free_tx_resources(vsi->tx_rings[i]);
1451 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001452 }
1453 kfree(tx_rings);
1454 tx_rings = NULL;
1455 }
1456
1457 if (rx_rings) {
1458 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001459 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001460 /* get the real tail offset */
1461 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1462 /* this is to fake out the allocation routine
1463 * into thinking it has to realloc everything
1464 * but the recycling logic will let us re-use
1465 * the buffers allocated above
1466 */
1467 rx_rings[i].next_to_use = 0;
1468 rx_rings[i].next_to_clean = 0;
1469 rx_rings[i].next_to_alloc = 0;
1470 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001471 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001472 }
1473 kfree(rx_rings);
1474 rx_rings = NULL;
1475 }
1476
1477 i40e_up(vsi);
1478
1479free_tx:
1480 /* error cleanup if the Rx allocations failed after getting Tx */
1481 if (tx_rings) {
1482 for (i = 0; i < vsi->num_queue_pairs; i++)
1483 i40e_free_tx_resources(&tx_rings[i]);
1484 kfree(tx_rings);
1485 tx_rings = NULL;
1486 }
1487
1488done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001489 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001490
1491 return err;
1492}
1493
1494static int i40e_get_sset_count(struct net_device *netdev, int sset)
1495{
1496 struct i40e_netdev_priv *np = netdev_priv(netdev);
1497 struct i40e_vsi *vsi = np->vsi;
1498 struct i40e_pf *pf = vsi->back;
1499
1500 switch (sset) {
1501 case ETH_SS_TEST:
1502 return I40E_TEST_LEN;
1503 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001504 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001505 int len = I40E_PF_STATS_LEN(netdev);
1506
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001507 if ((pf->lan_veb != I40E_NO_VEB) &&
1508 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001509 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001510 return len;
1511 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001512 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001513 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001514 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001515 return I40E_PRIV_FLAGS_STR_LEN +
1516 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001517 default:
1518 return -EOPNOTSUPP;
1519 }
1520}
1521
1522static void i40e_get_ethtool_stats(struct net_device *netdev,
1523 struct ethtool_stats *stats, u64 *data)
1524{
1525 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001526 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001527 struct i40e_vsi *vsi = np->vsi;
1528 struct i40e_pf *pf = vsi->back;
1529 int i = 0;
1530 char *p;
1531 int j;
1532 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001533 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534
1535 i40e_update_stats(vsi);
1536
1537 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1538 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1539 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1540 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1541 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001542 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1543 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1544 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1545 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1546 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001547 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001548 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001549 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001550
1551 if (!tx_ring)
1552 continue;
1553
1554 /* process Tx ring statistics */
1555 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001556 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001557 data[i] = tx_ring->stats.packets;
1558 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001559 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001560 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001561
1562 /* Rx ring is the 2nd half of the queue pair */
1563 rx_ring = &tx_ring[1];
1564 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001565 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001566 data[i] = rx_ring->stats.packets;
1567 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001568 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001569 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001570 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001571 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001572 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001573 return;
1574
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001575 if ((pf->lan_veb != I40E_NO_VEB) &&
1576 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001577 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001578
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001579 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1580 p = (char *)veb;
1581 p += i40e_gstrings_veb_stats[j].stat_offset;
1582 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1583 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001584 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001585 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1586 data[i++] = veb->tc_stats.tc_tx_packets[j];
1587 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1588 data[i++] = veb->tc_stats.tc_rx_packets[j];
1589 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1590 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001591 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001592 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1593 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1594 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1595 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1596 }
1597 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1598 data[i++] = pf->stats.priority_xon_tx[j];
1599 data[i++] = pf->stats.priority_xoff_tx[j];
1600 }
1601 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1602 data[i++] = pf->stats.priority_xon_rx[j];
1603 data[i++] = pf->stats.priority_xoff_rx[j];
1604 }
1605 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1606 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001607}
1608
1609static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1610 u8 *data)
1611{
1612 struct i40e_netdev_priv *np = netdev_priv(netdev);
1613 struct i40e_vsi *vsi = np->vsi;
1614 struct i40e_pf *pf = vsi->back;
1615 char *p = (char *)data;
1616 int i;
1617
1618 switch (stringset) {
1619 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001620 memcpy(data, i40e_gstrings_test,
1621 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001622 break;
1623 case ETH_SS_STATS:
1624 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1625 snprintf(p, ETH_GSTRING_LEN, "%s",
1626 i40e_gstrings_net_stats[i].stat_string);
1627 p += ETH_GSTRING_LEN;
1628 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001629 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1630 snprintf(p, ETH_GSTRING_LEN, "%s",
1631 i40e_gstrings_misc_stats[i].stat_string);
1632 p += ETH_GSTRING_LEN;
1633 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001634 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001635 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001636 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001637 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001638 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001639 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001640 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001641 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001642 p += ETH_GSTRING_LEN;
1643 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001644 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001645 return;
1646
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001647 if ((pf->lan_veb != I40E_NO_VEB) &&
1648 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001649 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1650 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1651 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652 p += ETH_GSTRING_LEN;
1653 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001654 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1655 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001656 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001657 p += ETH_GSTRING_LEN;
1658 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001659 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001660 p += ETH_GSTRING_LEN;
1661 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001662 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001663 p += ETH_GSTRING_LEN;
1664 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001665 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001666 p += ETH_GSTRING_LEN;
1667 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001668 }
1669 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1670 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1671 i40e_gstrings_stats[i].stat_string);
1672 p += ETH_GSTRING_LEN;
1673 }
1674 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1675 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001676 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001677 p += ETH_GSTRING_LEN;
1678 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001679 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001680 p += ETH_GSTRING_LEN;
1681 }
1682 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1683 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001684 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001685 p += ETH_GSTRING_LEN;
1686 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001687 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001688 p += ETH_GSTRING_LEN;
1689 }
1690 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1691 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001692 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001693 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694 }
1695 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1696 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001697 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001698 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1699 snprintf(p, ETH_GSTRING_LEN, "%s",
1700 i40e_gstrings_priv_flags[i].flag_string);
1701 p += ETH_GSTRING_LEN;
1702 }
1703 if (pf->hw.pf_id != 0)
1704 break;
1705 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1706 snprintf(p, ETH_GSTRING_LEN, "%s",
1707 i40e_gl_gstrings_priv_flags[i].flag_string);
1708 p += ETH_GSTRING_LEN;
1709 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001710 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001711 default:
1712 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001713 }
1714}
1715
1716static int i40e_get_ts_info(struct net_device *dev,
1717 struct ethtool_ts_info *info)
1718{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001719 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1720
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001721 /* only report HW timestamping if PTP is enabled */
1722 if (!(pf->flags & I40E_FLAG_PTP))
1723 return ethtool_op_get_ts_info(dev, info);
1724
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001725 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1726 SOF_TIMESTAMPING_RX_SOFTWARE |
1727 SOF_TIMESTAMPING_SOFTWARE |
1728 SOF_TIMESTAMPING_TX_HARDWARE |
1729 SOF_TIMESTAMPING_RX_HARDWARE |
1730 SOF_TIMESTAMPING_RAW_HARDWARE;
1731
1732 if (pf->ptp_clock)
1733 info->phc_index = ptp_clock_index(pf->ptp_clock);
1734 else
1735 info->phc_index = -1;
1736
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001737 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001738
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001739 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001740 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1741 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1742 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1743
1744 if (pf->flags & I40E_FLAG_PTP_L4_CAPABLE)
1745 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1746 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1747 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1748 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1749 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1750 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1751 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1752 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001753
1754 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001755}
1756
Shannon Nelson7b086392013-11-20 10:02:59 +00001757static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001758{
Shannon Nelson7b086392013-11-20 10:02:59 +00001759 struct i40e_netdev_priv *np = netdev_priv(netdev);
1760 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001761 i40e_status status;
1762 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001763
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001764 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001765 status = i40e_get_link_status(&pf->hw, &link_up);
1766 if (status) {
1767 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1768 *data = 1;
1769 return *data;
1770 }
1771
1772 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001773 *data = 0;
1774 else
1775 *data = 1;
1776
1777 return *data;
1778}
1779
Shannon Nelson7b086392013-11-20 10:02:59 +00001780static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001781{
Shannon Nelson7b086392013-11-20 10:02:59 +00001782 struct i40e_netdev_priv *np = netdev_priv(netdev);
1783 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001784
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001785 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001786 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001787
Shannon Nelson7b086392013-11-20 10:02:59 +00001788 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001789}
1790
Shannon Nelson7b086392013-11-20 10:02:59 +00001791static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001792{
Shannon Nelson7b086392013-11-20 10:02:59 +00001793 struct i40e_netdev_priv *np = netdev_priv(netdev);
1794 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001795
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001796 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001797 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001798
Shannon Nelson4443ec92014-11-13 08:23:12 +00001799 /* forcebly clear the NVM Update state machine */
1800 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1801
Shannon Nelson7b086392013-11-20 10:02:59 +00001802 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001803}
1804
Shannon Nelson7b086392013-11-20 10:02:59 +00001805static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001806{
Shannon Nelson7b086392013-11-20 10:02:59 +00001807 struct i40e_netdev_priv *np = netdev_priv(netdev);
1808 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001809 u16 swc_old = pf->sw_int_count;
1810
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001811 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001812 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1813 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001814 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1815 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1816 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1817 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001818 usleep_range(1000, 2000);
1819 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820
1821 return *data;
1822}
1823
Greg Rosee17bc412015-04-16 20:05:59 -04001824static inline bool i40e_active_vfs(struct i40e_pf *pf)
1825{
1826 struct i40e_vf *vfs = pf->vf;
1827 int i;
1828
1829 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001830 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001831 return true;
1832 return false;
1833}
1834
Greg Rose510efb22015-07-10 19:36:01 -04001835static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1836{
Alexander Duyck4b816442016-10-11 15:26:53 -07001837 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001838}
1839
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001840static void i40e_diag_test(struct net_device *netdev,
1841 struct ethtool_test *eth_test, u64 *data)
1842{
1843 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001844 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001845 struct i40e_pf *pf = np->vsi->back;
1846
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001847 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1848 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001849 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001850
Jacob Keller0da36b92017-04-19 09:25:55 -04001851 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001852
Greg Rose510efb22015-07-10 19:36:01 -04001853 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001854 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001855 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001856 data[I40E_ETH_TEST_REG] = 1;
1857 data[I40E_ETH_TEST_EEPROM] = 1;
1858 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001859 data[I40E_ETH_TEST_LINK] = 1;
1860 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04001861 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001862 goto skip_ol_tests;
1863 }
1864
Greg Rose5b86c5c2015-02-26 16:14:35 +00001865 /* If the device is online then take it offline */
1866 if (if_running)
1867 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001868 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001869 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001870 /* This reset does not affect link - if it is
1871 * changed to a type of reset that does affect
1872 * link then the following link test would have
1873 * to be moved to before the reset
1874 */
Maciej Sosin373149f2017-04-05 07:50:55 -04001875 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00001876
Shannon Nelson7b086392013-11-20 10:02:59 +00001877 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001878 eth_test->flags |= ETH_TEST_FL_FAILED;
1879
Shannon Nelson7b086392013-11-20 10:02:59 +00001880 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001881 eth_test->flags |= ETH_TEST_FL_FAILED;
1882
Shannon Nelson7b086392013-11-20 10:02:59 +00001883 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001884 eth_test->flags |= ETH_TEST_FL_FAILED;
1885
Shannon Nelsonf551b432013-11-26 10:49:12 +00001886 /* run reg test last, a reset is required after it */
1887 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1888 eth_test->flags |= ETH_TEST_FL_FAILED;
1889
Jacob Keller0da36b92017-04-19 09:25:55 -04001890 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04001891 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001892
1893 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001894 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001895 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001896 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001897 netif_info(pf, drv, netdev, "online testing starting\n");
1898
Shannon Nelson7b086392013-11-20 10:02:59 +00001899 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001900 eth_test->flags |= ETH_TEST_FL_FAILED;
1901
1902 /* Offline only tests, not run in online; pass by default */
1903 data[I40E_ETH_TEST_REG] = 0;
1904 data[I40E_ETH_TEST_EEPROM] = 0;
1905 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001906 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001907
Greg Rosee17bc412015-04-16 20:05:59 -04001908skip_ol_tests:
1909
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001910 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001911}
1912
1913static void i40e_get_wol(struct net_device *netdev,
1914 struct ethtool_wolinfo *wol)
1915{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001916 struct i40e_netdev_priv *np = netdev_priv(netdev);
1917 struct i40e_pf *pf = np->vsi->back;
1918 struct i40e_hw *hw = &pf->hw;
1919 u16 wol_nvm_bits;
1920
1921 /* NVM bit on means WoL disabled for the port */
1922 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001923 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001924 wol->supported = 0;
1925 wol->wolopts = 0;
1926 } else {
1927 wol->supported = WAKE_MAGIC;
1928 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1929 }
1930}
1931
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001932/**
1933 * i40e_set_wol - set the WakeOnLAN configuration
1934 * @netdev: the netdev in question
1935 * @wol: the ethtool WoL setting data
1936 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001937static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1938{
1939 struct i40e_netdev_priv *np = netdev_priv(netdev);
1940 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001941 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001942 struct i40e_hw *hw = &pf->hw;
1943 u16 wol_nvm_bits;
1944
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001945 /* WoL not supported if this isn't the controlling PF on the port */
1946 if (hw->partition_id != 1) {
1947 i40e_partition_setting_complaint(pf);
1948 return -EOPNOTSUPP;
1949 }
1950
1951 if (vsi != pf->vsi[pf->lan_vsi])
1952 return -EOPNOTSUPP;
1953
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001954 /* NVM bit on means WoL disabled for the port */
1955 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001956 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001957 return -EOPNOTSUPP;
1958
1959 /* only magic packet is supported */
1960 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1961 return -EOPNOTSUPP;
1962
1963 /* is this a new value? */
1964 if (pf->wol_en != !!wol->wolopts) {
1965 pf->wol_en = !!wol->wolopts;
1966 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1967 }
1968
1969 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001970}
1971
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001972static int i40e_set_phys_id(struct net_device *netdev,
1973 enum ethtool_phys_id_state state)
1974{
1975 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001976 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001977 struct i40e_pf *pf = np->vsi->back;
1978 struct i40e_hw *hw = &pf->hw;
1979 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001980 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001981
1982 switch (state) {
1983 case ETHTOOL_ID_ACTIVE:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001984 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001985 pf->led_status = i40e_led_get(hw);
1986 } else {
Kevin Scott06c0e392016-05-03 15:13:09 -07001987 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001988 ret = i40e_led_get_phy(hw, &temp_status,
1989 &pf->phy_led_val);
1990 pf->led_status = temp_status;
1991 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992 return blink_freq;
1993 case ETHTOOL_ID_ON:
Henry Tieman4f9b4302016-11-08 13:05:18 -08001994 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001995 i40e_led_set(hw, 0xf, false);
1996 else
1997 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001998 break;
1999 case ETHTOOL_ID_OFF:
Henry Tieman4f9b4302016-11-08 13:05:18 -08002000 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002001 i40e_led_set(hw, 0x0, false);
2002 else
2003 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002004 break;
2005 case ETHTOOL_ID_INACTIVE:
Henry Tieman4f9b4302016-11-08 13:05:18 -08002006 if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) {
2007 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002008 } else {
2009 ret = i40e_led_set_phy(hw, false, pf->led_status,
2010 (pf->phy_led_val |
2011 I40E_PHY_LED_MODE_ORIG));
2012 i40e_aq_set_phy_debug(hw, 0, NULL);
2013 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002014 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002015 default:
2016 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002017 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002018 if (ret)
2019 return -ENOENT;
2020 else
2021 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002022}
2023
2024/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2025 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2026 * 125us (8000 interrupts per second) == ITR(62)
2027 */
2028
Jacob Keller65e87c02016-09-12 14:18:44 -07002029/**
2030 * __i40e_get_coalesce - get per-queue coalesce settings
2031 * @netdev: the netdev to check
2032 * @ec: ethtool coalesce data structure
2033 * @queue: which queue to pick
2034 *
2035 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2036 * are per queue. If queue is <0 then we default to queue 0 as the
2037 * representative value.
2038 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002039static int __i40e_get_coalesce(struct net_device *netdev,
2040 struct ethtool_coalesce *ec,
2041 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002042{
2043 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002044 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002045 struct i40e_vsi *vsi = np->vsi;
2046
2047 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2048 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2049
Kan Lianga75e8002016-02-19 09:24:04 -05002050 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2051 * return queue 0's value to represent.
2052 */
2053 if (queue < 0) {
2054 queue = 0;
2055 } else if (queue >= vsi->num_queue_pairs) {
2056 return -EINVAL;
2057 }
2058
Jacob Keller65e87c02016-09-12 14:18:44 -07002059 rx_ring = vsi->rx_rings[queue];
2060 tx_ring = vsi->tx_rings[queue];
2061
2062 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002063 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002064
Jacob Keller65e87c02016-09-12 14:18:44 -07002065 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002066 ec->use_adaptive_tx_coalesce = 1;
2067
Jacob Keller65e87c02016-09-12 14:18:44 -07002068 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2069 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2070
Kan Lianga75e8002016-02-19 09:24:04 -05002071
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002072 /* we use the _usecs_high to store/set the interrupt rate limit
2073 * that the hardware supports, that almost but not quite
2074 * fits the original intent of the ethtool variable,
2075 * the rx_coalesce_usecs_high limits total interrupts
2076 * per second from both tx/rx sources.
2077 */
2078 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2079 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002080
2081 return 0;
2082}
2083
Jacob Keller65e87c02016-09-12 14:18:44 -07002084/**
2085 * i40e_get_coalesce - get a netdev's coalesce settings
2086 * @netdev: the netdev to check
2087 * @ec: ethtool coalesce data structure
2088 *
2089 * Gets the coalesce settings for a particular netdev. Note that if user has
2090 * modified per-queue settings, this only guarantees to represent queue 0. See
2091 * __i40e_get_coalesce for more details.
2092 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002093static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002094 struct ethtool_coalesce *ec)
2095{
Kan Lianga75e8002016-02-19 09:24:04 -05002096 return __i40e_get_coalesce(netdev, ec, -1);
2097}
2098
Jacob Keller65e87c02016-09-12 14:18:44 -07002099/**
2100 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2101 * @netdev: netdev structure
2102 * @ec: ethtool's coalesce settings
2103 * @queue: the particular queue to read
2104 *
2105 * Will read a specific queue's coalesce settings
2106 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002107static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2108 struct ethtool_coalesce *ec)
2109{
2110 return __i40e_get_coalesce(netdev, ec, queue);
2111}
2112
Jacob Keller65e87c02016-09-12 14:18:44 -07002113/**
2114 * i40e_set_itr_per_queue - set ITR values for specific queue
2115 * @vsi: the VSI to set values for
2116 * @ec: coalesce settings from ethtool
2117 * @queue: the queue to modify
2118 *
2119 * Change the ITR settings for a specific queue.
2120 **/
2121
Kan Lianga75e8002016-02-19 09:24:04 -05002122static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2123 struct ethtool_coalesce *ec,
2124 int queue)
2125{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002126 struct i40e_pf *pf = vsi->back;
2127 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002128 struct i40e_q_vector *q_vector;
2129 u16 vector, intrl;
2130
Alan Brady1c0e6a32016-11-28 16:06:02 -08002131 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002132
2133 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2134 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2135
2136 if (ec->use_adaptive_rx_coalesce)
2137 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2138 else
2139 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2140
2141 if (ec->use_adaptive_tx_coalesce)
2142 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2143 else
2144 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2145
2146 q_vector = vsi->rx_rings[queue]->q_vector;
2147 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2148 vector = vsi->base_vector + q_vector->v_idx;
2149 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2150
2151 q_vector = vsi->tx_rings[queue]->q_vector;
2152 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2153 vector = vsi->base_vector + q_vector->v_idx;
2154 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2155
2156 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2157 i40e_flush(hw);
2158}
2159
Jacob Keller65e87c02016-09-12 14:18:44 -07002160/**
2161 * __i40e_set_coalesce - set coalesce settings for particular queue
2162 * @netdev: the netdev to change
2163 * @ec: ethtool coalesce settings
2164 * @queue: the queue to change
2165 *
2166 * Sets the coalesce settings for a particular queue.
2167 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002168static int __i40e_set_coalesce(struct net_device *netdev,
2169 struct ethtool_coalesce *ec,
2170 int queue)
2171{
2172 struct i40e_netdev_priv *np = netdev_priv(netdev);
2173 struct i40e_vsi *vsi = np->vsi;
2174 struct i40e_pf *pf = vsi->back;
Alan Brady33084062016-11-28 16:06:03 -08002175 u16 intrl_reg;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002176 int i;
2177
2178 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2179 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2180
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002181 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2182 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2183 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2184 return -EINVAL;
2185 }
2186
Alan Brady33084062016-11-28 16:06:03 -08002187 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2188 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2189 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002190 return -EINVAL;
2191 }
2192
Kan Lianga75e8002016-02-19 09:24:04 -05002193 if (ec->rx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002194 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002195 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
Kan Lianga75e8002016-02-19 09:24:04 -05002196 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2197 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2198 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2199 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002200 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002201
Alan Brady33084062016-11-28 16:06:03 -08002202 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2203 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2204 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2205 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2206 vsi->int_rate_limit);
2207 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002208
Kan Lianga75e8002016-02-19 09:24:04 -05002209 if (ec->tx_coalesce_usecs == 0) {
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002210 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00002211 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
Kan Lianga75e8002016-02-19 09:24:04 -05002212 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
2213 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
2214 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2215 return -EINVAL;
2216 }
2217
2218 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2219 * apply to all queues.
2220 */
2221 if (queue < 0) {
2222 for (i = 0; i < vsi->num_queue_pairs; i++)
2223 i40e_set_itr_per_queue(vsi, ec, i);
2224 } else if (queue < vsi->num_queue_pairs) {
2225 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002226 } else {
Kan Lianga75e8002016-02-19 09:24:04 -05002227 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2228 vsi->num_queue_pairs - 1);
Mitch Williams32f5f542014-04-04 04:43:10 +00002229 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002230 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002231
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002232 return 0;
2233}
2234
Jacob Keller65e87c02016-09-12 14:18:44 -07002235/**
2236 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2237 * @netdev: the netdev to change
2238 * @ec: ethtool coalesce settings
2239 *
2240 * This will set each queue to the same coalesce settings.
2241 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002242static int i40e_set_coalesce(struct net_device *netdev,
2243 struct ethtool_coalesce *ec)
2244{
2245 return __i40e_set_coalesce(netdev, ec, -1);
2246}
2247
Jacob Keller65e87c02016-09-12 14:18:44 -07002248/**
2249 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2250 * @netdev: the netdev to change
2251 * @ec: ethtool's coalesce settings
2252 * @queue: the queue to change
2253 *
2254 * Sets the specified queue's coalesce settings.
2255 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002256static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2257 struct ethtool_coalesce *ec)
2258{
2259 return __i40e_set_coalesce(netdev, ec, queue);
2260}
2261
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002262/**
2263 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2264 * @pf: pointer to the physical function struct
2265 * @cmd: ethtool rxnfc command
2266 *
2267 * Returns Success if the flow is supported, else Invalid Input.
2268 **/
2269static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2270{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002271 struct i40e_hw *hw = &pf->hw;
2272 u8 flow_pctype = 0;
2273 u64 i_set = 0;
2274
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002275 cmd->data = 0;
2276
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002277 switch (cmd->flow_type) {
2278 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002279 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2280 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002281 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002282 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2283 break;
2284 case TCP_V6_FLOW:
2285 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2286 break;
2287 case UDP_V6_FLOW:
2288 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2289 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002290 case SCTP_V4_FLOW:
2291 case AH_ESP_V4_FLOW:
2292 case AH_V4_FLOW:
2293 case ESP_V4_FLOW:
2294 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002295 case SCTP_V6_FLOW:
2296 case AH_ESP_V6_FLOW:
2297 case AH_V6_FLOW:
2298 case ESP_V6_FLOW:
2299 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002300 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002301 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2302 break;
2303 default:
2304 return -EINVAL;
2305 }
2306
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002307 /* Read flow based hash input set register */
2308 if (flow_pctype) {
2309 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2310 flow_pctype)) |
2311 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2312 flow_pctype)) << 32);
2313 }
2314
2315 /* Process bits of hash input set */
2316 if (i_set) {
2317 if (i_set & I40E_L4_SRC_MASK)
2318 cmd->data |= RXH_L4_B_0_1;
2319 if (i_set & I40E_L4_DST_MASK)
2320 cmd->data |= RXH_L4_B_2_3;
2321
2322 if (cmd->flow_type == TCP_V4_FLOW ||
2323 cmd->flow_type == UDP_V4_FLOW) {
2324 if (i_set & I40E_L3_SRC_MASK)
2325 cmd->data |= RXH_IP_SRC;
2326 if (i_set & I40E_L3_DST_MASK)
2327 cmd->data |= RXH_IP_DST;
2328 } else if (cmd->flow_type == TCP_V6_FLOW ||
2329 cmd->flow_type == UDP_V6_FLOW) {
2330 if (i_set & I40E_L3_V6_SRC_MASK)
2331 cmd->data |= RXH_IP_SRC;
2332 if (i_set & I40E_L3_V6_DST_MASK)
2333 cmd->data |= RXH_IP_DST;
2334 }
2335 }
2336
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002337 return 0;
2338}
2339
2340/**
Jacob Kellere7930952017-02-06 14:38:49 -08002341 * i40e_check_mask - Check whether a mask field is set
2342 * @mask: the full mask value
2343 * @field; mask of the field to check
2344 *
2345 * If the given mask is fully set, return positive value. If the mask for the
2346 * field is fully unset, return zero. Otherwise return a negative error code.
2347 **/
2348static int i40e_check_mask(u64 mask, u64 field)
2349{
2350 u64 value = mask & field;
2351
2352 if (value == field)
2353 return 1;
2354 else if (!value)
2355 return 0;
2356 else
2357 return -1;
2358}
2359
2360/**
2361 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2362 * @fsp: pointer to rx flow specification
2363 * @data: pointer to userdef data structure for storage
2364 *
2365 * Read the user-defined data and deconstruct the value into a structure. No
2366 * other code should read the user-defined data, so as to ensure that every
2367 * place consistently reads the value correctly.
2368 *
2369 * The user-defined field is a 64bit Big Endian format value, which we
2370 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2371 * be defined starting from the highest bits, while small bit field values
2372 * shall be defined starting from the lowest bits.
2373 *
2374 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2375 * and the filter should be rejected. The data structure will always be
2376 * modified even if FLOW_EXT is not set.
2377 *
2378 **/
2379static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2380 struct i40e_rx_flow_userdef *data)
2381{
2382 u64 value, mask;
2383 int valid;
2384
2385 /* Zero memory first so it's always consistent. */
2386 memset(data, 0, sizeof(*data));
2387
2388 if (!(fsp->flow_type & FLOW_EXT))
2389 return 0;
2390
2391 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2392 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2393
2394#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2395#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2396#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2397
2398 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2399 if (valid < 0) {
2400 return -EINVAL;
2401 } else if (valid) {
2402 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2403 data->flex_offset =
2404 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2405 data->flex_filter = true;
2406 }
2407
2408 return 0;
2409}
2410
2411/**
2412 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2413 * @fsp: pointer to rx_flow specification
2414 *
2415 * Reads the userdef data structure and properly fills in the user defined
2416 * fields of the rx_flow_spec.
2417 **/
2418static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2419 struct i40e_rx_flow_userdef *data)
2420{
2421 u64 value = 0, mask = 0;
2422
2423 if (data->flex_filter) {
2424 value |= data->flex_word;
2425 value |= (u64)data->flex_offset << 16;
2426 mask |= I40E_USERDEF_FLEX_FILTER;
2427 }
2428
2429 if (value || mask)
2430 fsp->flow_type |= FLOW_EXT;
2431
2432 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2433 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2434}
2435
2436/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002437 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2438 * @pf: Pointer to the physical function struct
2439 * @cmd: The command to get or set Rx flow classification rules
2440 * @rule_locs: Array of used rule locations
2441 *
2442 * This function populates both the total and actual rule count of
2443 * the ethtool flow classification command
2444 *
2445 * Returns 0 on success or -EMSGSIZE if entry not found
2446 **/
2447static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2448 struct ethtool_rxnfc *cmd,
2449 u32 *rule_locs)
2450{
2451 struct i40e_fdir_filter *rule;
2452 struct hlist_node *node2;
2453 int cnt = 0;
2454
2455 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002456 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002457
2458 hlist_for_each_entry_safe(rule, node2,
2459 &pf->fdir_filter_list, fdir_node) {
2460 if (cnt == cmd->rule_cnt)
2461 return -EMSGSIZE;
2462
2463 rule_locs[cnt] = rule->fd_id;
2464 cnt++;
2465 }
2466
2467 cmd->rule_cnt = cnt;
2468
2469 return 0;
2470}
2471
2472/**
2473 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2474 * @pf: Pointer to the physical function struct
2475 * @cmd: The command to get or set Rx flow classification rules
2476 *
2477 * This function looks up a filter based on the Rx flow classification
2478 * command and fills the flow spec info for it if found
2479 *
2480 * Returns 0 on success or -EINVAL if filter not found
2481 **/
2482static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2483 struct ethtool_rxnfc *cmd)
2484{
2485 struct ethtool_rx_flow_spec *fsp =
2486 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002487 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002488 struct i40e_fdir_filter *rule = NULL;
2489 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002490 u64 input_set;
2491 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002492
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002493 hlist_for_each_entry_safe(rule, node2,
2494 &pf->fdir_filter_list, fdir_node) {
2495 if (fsp->location <= rule->fd_id)
2496 break;
2497 }
2498
2499 if (!rule || fsp->location != rule->fd_id)
2500 return -EINVAL;
2501
2502 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002503 if (fsp->flow_type == IP_USER_FLOW) {
2504 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2505 fsp->h_u.usr_ip4_spec.proto = 0;
2506 fsp->m_u.usr_ip4_spec.proto = 0;
2507 }
2508
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002509 /* Reverse the src and dest notion, since the HW views them from
2510 * Tx perspective where as the user expects it from Rx filter view.
2511 */
2512 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2513 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002514 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2515 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002516
Jacob Keller36777d92017-03-07 15:05:23 -08002517 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002518 case SCTP_V4_FLOW:
2519 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2520 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002521 case TCP_V4_FLOW:
2522 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2523 break;
2524 case UDP_V4_FLOW:
2525 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2526 break;
2527 case IP_USER_FLOW:
2528 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2529 break;
2530 default:
2531 /* If we have stored a filter with a flow type not listed here
2532 * it is almost certainly a driver bug. WARN(), and then
2533 * assign the input_set as if all fields are enabled to avoid
2534 * reading unassigned memory.
2535 */
2536 WARN(1, "Missing input set index for flow_type %d\n",
2537 rule->flow_type);
2538 input_set = 0xFFFFFFFFFFFFFFFFULL;
2539 goto no_input_set;
2540 }
2541
2542 input_set = i40e_read_fd_input_set(pf, index);
2543
2544no_input_set:
2545 if (input_set & I40E_L3_SRC_MASK)
2546 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
2547
2548 if (input_set & I40E_L3_DST_MASK)
2549 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
2550
2551 if (input_set & I40E_L4_SRC_MASK)
2552 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
2553
2554 if (input_set & I40E_L4_DST_MASK)
2555 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002556
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002557 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2558 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2559 else
2560 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002561
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002562 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2563 struct i40e_vsi *vsi;
2564
2565 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2566 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002567 /* VFs are zero-indexed by the driver, but ethtool
2568 * expects them to be one-indexed, so add one here
2569 */
2570 u64 ring_vf = vsi->vf_id + 1;
2571
2572 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2573 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002574 }
2575 }
2576
Jacob Keller0e588de2017-02-06 14:38:50 -08002577 if (rule->flex_filter) {
2578 userdef.flex_filter = true;
2579 userdef.flex_word = be16_to_cpu(rule->flex_word);
2580 userdef.flex_offset = rule->flex_offset;
2581 }
2582
Jacob Kellere7930952017-02-06 14:38:49 -08002583 i40e_fill_rx_flow_user_data(fsp, &userdef);
2584
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002585 return 0;
2586}
2587
2588/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002589 * i40e_get_rxnfc - command to get RX flow classification rules
2590 * @netdev: network interface device structure
2591 * @cmd: ethtool rxnfc command
2592 *
2593 * Returns Success if the command is supported.
2594 **/
2595static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2596 u32 *rule_locs)
2597{
2598 struct i40e_netdev_priv *np = netdev_priv(netdev);
2599 struct i40e_vsi *vsi = np->vsi;
2600 struct i40e_pf *pf = vsi->back;
2601 int ret = -EOPNOTSUPP;
2602
2603 switch (cmd->cmd) {
2604 case ETHTOOL_GRXRINGS:
Helin Zhang3e3aa212015-10-21 19:47:13 -04002605 cmd->data = vsi->num_queue_pairs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002606 ret = 0;
2607 break;
2608 case ETHTOOL_GRXFH:
2609 ret = i40e_get_rss_hash_opts(pf, cmd);
2610 break;
2611 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002612 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002613 /* report total rule count */
2614 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002615 ret = 0;
2616 break;
2617 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002618 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002619 break;
2620 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002621 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2622 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002623 default:
2624 break;
2625 }
2626
2627 return ret;
2628}
2629
2630/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002631 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2632 * @nfc: pointer to user request
2633 * @i_setc bits currently set
2634 *
2635 * Returns value of bits to be set per user request
2636 **/
2637static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2638{
2639 u64 i_set = i_setc;
2640 u64 src_l3 = 0, dst_l3 = 0;
2641
2642 if (nfc->data & RXH_L4_B_0_1)
2643 i_set |= I40E_L4_SRC_MASK;
2644 else
2645 i_set &= ~I40E_L4_SRC_MASK;
2646 if (nfc->data & RXH_L4_B_2_3)
2647 i_set |= I40E_L4_DST_MASK;
2648 else
2649 i_set &= ~I40E_L4_DST_MASK;
2650
2651 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2652 src_l3 = I40E_L3_V6_SRC_MASK;
2653 dst_l3 = I40E_L3_V6_DST_MASK;
2654 } else if (nfc->flow_type == TCP_V4_FLOW ||
2655 nfc->flow_type == UDP_V4_FLOW) {
2656 src_l3 = I40E_L3_SRC_MASK;
2657 dst_l3 = I40E_L3_DST_MASK;
2658 } else {
2659 /* Any other flow type are not supported here */
2660 return i_set;
2661 }
2662
2663 if (nfc->data & RXH_IP_SRC)
2664 i_set |= src_l3;
2665 else
2666 i_set &= ~src_l3;
2667 if (nfc->data & RXH_IP_DST)
2668 i_set |= dst_l3;
2669 else
2670 i_set &= ~dst_l3;
2671
2672 return i_set;
2673}
2674
2675/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002676 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2677 * @pf: pointer to the physical function struct
2678 * @cmd: ethtool rxnfc command
2679 *
2680 * Returns Success if the flow input set is supported.
2681 **/
2682static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2683{
2684 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002685 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2686 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002687 u8 flow_pctype = 0;
2688 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002689
2690 /* RSS does not support anything other than hashing
2691 * to queues on src and dst IPs and ports
2692 */
2693 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2694 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2695 return -EINVAL;
2696
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002697 switch (nfc->flow_type) {
2698 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002699 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2700 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2701 hena |=
2702 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002703 break;
2704 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002705 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2706 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2707 hena |=
2708 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
2709 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2710 hena |=
2711 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002712 break;
2713 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002714 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2715 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2716 hena |=
2717 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2718 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002719
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002720 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002721 break;
2722 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002723 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2724 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE)
2725 hena |=
2726 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2727 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002728
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002729 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002730 break;
2731 case AH_ESP_V4_FLOW:
2732 case AH_V4_FLOW:
2733 case ESP_V4_FLOW:
2734 case SCTP_V4_FLOW:
2735 if ((nfc->data & RXH_L4_B_0_1) ||
2736 (nfc->data & RXH_L4_B_2_3))
2737 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002738 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002739 break;
2740 case AH_ESP_V6_FLOW:
2741 case AH_V6_FLOW:
2742 case ESP_V6_FLOW:
2743 case SCTP_V6_FLOW:
2744 if ((nfc->data & RXH_L4_B_0_1) ||
2745 (nfc->data & RXH_L4_B_2_3))
2746 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002747 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002748 break;
2749 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002750 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2751 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002752 break;
2753 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002754 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2755 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002756 break;
2757 default:
2758 return -EINVAL;
2759 }
2760
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002761 if (flow_pctype) {
2762 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2763 flow_pctype)) |
2764 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2765 flow_pctype)) << 32);
2766 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2767 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2768 (u32)i_set);
2769 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2770 (u32)(i_set >> 32));
2771 hena |= BIT_ULL(flow_pctype);
2772 }
2773
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002774 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2775 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002776 i40e_flush(hw);
2777
2778 return 0;
2779}
2780
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002781/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002782 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2783 * @vsi: Pointer to the targeted VSI
2784 * @input: The filter to update or NULL to indicate deletion
2785 * @sw_idx: Software index to the filter
2786 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002787 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002788 * This function updates (or deletes) a Flow Director entry from
2789 * the hlist of the corresponding PF
2790 *
2791 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002792 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002793static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2794 struct i40e_fdir_filter *input,
2795 u16 sw_idx,
2796 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002797{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002798 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002799 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002800 struct hlist_node *node2;
2801 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002802
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002803 parent = NULL;
2804 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002805
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002806 hlist_for_each_entry_safe(rule, node2,
2807 &pf->fdir_filter_list, fdir_node) {
2808 /* hash found, or no matching entry */
2809 if (rule->fd_id >= sw_idx)
2810 break;
2811 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002812 }
2813
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002814 /* if there is an old rule occupying our place remove it */
2815 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08002816 /* Remove this rule, since we're either deleting it, or
2817 * replacing it.
2818 */
2819 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002820 hlist_del(&rule->fdir_node);
2821 kfree(rule);
2822 pf->fdir_pf_active_filters--;
2823 }
2824
Jacob Kellerc6da5252017-02-06 14:39:13 -08002825 /* If we weren't given an input, this is a delete, so just return the
2826 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002827 */
2828 if (!input)
2829 return err;
2830
Jacob Kellerc6da5252017-02-06 14:39:13 -08002831 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002832 INIT_HLIST_NODE(&input->fdir_node);
2833
2834 /* add filter to the list */
2835 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002836 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002837 else
2838 hlist_add_head(&input->fdir_node,
2839 &pf->fdir_filter_list);
2840
2841 /* update counts */
2842 pf->fdir_pf_active_filters++;
2843
2844 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002845}
2846
2847/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002848 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
2849 * @pf: pointer to PF structure
2850 *
2851 * This function searches the list of filters and determines which FLX_PIT
2852 * entries are still required. It will prune any entries which are no longer
2853 * in use after the deletion.
2854 **/
2855static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
2856{
2857 struct i40e_flex_pit *entry, *tmp;
2858 struct i40e_fdir_filter *rule;
2859
2860 /* First, we'll check the l3 table */
2861 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
2862 bool found = false;
2863
2864 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2865 if (rule->flow_type != IP_USER_FLOW)
2866 continue;
2867 if (rule->flex_filter &&
2868 rule->flex_offset == entry->src_offset) {
2869 found = true;
2870 break;
2871 }
2872 }
2873
2874 /* If we didn't find the filter, then we can prune this entry
2875 * from the list.
2876 */
2877 if (!found) {
2878 list_del(&entry->list);
2879 kfree(entry);
2880 }
2881 }
2882
2883 /* Followed by the L4 table */
2884 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
2885 bool found = false;
2886
2887 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2888 /* Skip this filter if it's L3, since we already
2889 * checked those in the above loop
2890 */
2891 if (rule->flow_type == IP_USER_FLOW)
2892 continue;
2893 if (rule->flex_filter &&
2894 rule->flex_offset == entry->src_offset) {
2895 found = true;
2896 break;
2897 }
2898 }
2899
2900 /* If we didn't find the filter, then we can prune this entry
2901 * from the list.
2902 */
2903 if (!found) {
2904 list_del(&entry->list);
2905 kfree(entry);
2906 }
2907 }
2908}
2909
2910/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002911 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2912 * @vsi: Pointer to the targeted VSI
2913 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002914 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002915 * The function removes a Flow Director filter entry from the
2916 * hlist of the corresponding PF
2917 *
2918 * Returns 0 on success
2919 */
2920static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2921 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002922{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002923 struct ethtool_rx_flow_spec *fsp =
2924 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002925 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002926 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002927
Jacob Keller0da36b92017-04-19 09:25:55 -04002928 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
2929 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002930 return -EBUSY;
2931
Jacob Keller0da36b92017-04-19 09:25:55 -04002932 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002933 return -EBUSY;
2934
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002935 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002936
Jacob Keller0e588de2017-02-06 14:38:50 -08002937 i40e_prune_flex_pit_list(pf);
2938
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002939 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002940 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002941}
2942
2943/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002944 * i40e_unused_pit_index - Find an unused PIT index for given list
2945 * @pf: the PF data structure
2946 *
2947 * Find the first unused flexible PIT index entry. We search both the L3 and
2948 * L4 flexible PIT lists so that the returned index is unique and unused by
2949 * either currently programmed L3 or L4 filters. We use a bit field as storage
2950 * to track which indexes are already used.
2951 **/
2952static u8 i40e_unused_pit_index(struct i40e_pf *pf)
2953{
2954 unsigned long available_index = 0xFF;
2955 struct i40e_flex_pit *entry;
2956
2957 /* We need to make sure that the new index isn't in use by either L3
2958 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
2959 * L4 to use the same index.
2960 */
2961
2962 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
2963 clear_bit(entry->pit_index, &available_index);
2964
2965 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
2966 clear_bit(entry->pit_index, &available_index);
2967
2968 return find_first_bit(&available_index, 8);
2969}
2970
2971/**
2972 * i40e_find_flex_offset - Find an existing flex src_offset
2973 * @flex_pit_list: L3 or L4 flex PIT list
2974 * @src_offset: new src_offset to find
2975 *
2976 * Searches the flex_pit_list for an existing offset. If no offset is
2977 * currently programmed, then this will return an ERR_PTR if there is no space
2978 * to add a new offset, otherwise it returns NULL.
2979 **/
2980static
2981struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
2982 u16 src_offset)
2983{
2984 struct i40e_flex_pit *entry;
2985 int size = 0;
2986
2987 /* Search for the src_offset first. If we find a matching entry
2988 * already programmed, we can simply re-use it.
2989 */
2990 list_for_each_entry(entry, flex_pit_list, list) {
2991 size++;
2992 if (entry->src_offset == src_offset)
2993 return entry;
2994 }
2995
2996 /* If we haven't found an entry yet, then the provided src offset has
2997 * not yet been programmed. We will program the src offset later on,
2998 * but we need to indicate whether there is enough space to do so
2999 * here. We'll make use of ERR_PTR for this purpose.
3000 */
3001 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3002 return ERR_PTR(-ENOSPC);
3003
3004 return NULL;
3005}
3006
3007/**
3008 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3009 * @flex_pit_list: L3 or L4 flex PIT list
3010 * @src_offset: new src_offset to add
3011 * @pit_index: the PIT index to program
3012 *
3013 * This function programs the new src_offset to the list. It is expected that
3014 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3015 * that this offset is not programmed, and that the list has enough space to
3016 * store another offset.
3017 *
3018 * Returns 0 on success, and negative value on error.
3019 **/
3020static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3021 u16 src_offset,
3022 u8 pit_index)
3023{
3024 struct i40e_flex_pit *new_pit, *entry;
3025
3026 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3027 if (!new_pit)
3028 return -ENOMEM;
3029
3030 new_pit->src_offset = src_offset;
3031 new_pit->pit_index = pit_index;
3032
3033 /* We need to insert this item such that the list is sorted by
3034 * src_offset in ascending order.
3035 */
3036 list_for_each_entry(entry, flex_pit_list, list) {
3037 if (new_pit->src_offset < entry->src_offset) {
3038 list_add_tail(&new_pit->list, &entry->list);
3039 return 0;
3040 }
3041
3042 /* If we found an entry with our offset already programmed we
3043 * can simply return here, after freeing the memory. However,
3044 * if the pit_index does not match we need to report an error.
3045 */
3046 if (new_pit->src_offset == entry->src_offset) {
3047 int err = 0;
3048
3049 /* If the PIT index is not the same we can't re-use
3050 * the entry, so we must report an error.
3051 */
3052 if (new_pit->pit_index != entry->pit_index)
3053 err = -EINVAL;
3054
3055 kfree(new_pit);
3056 return err;
3057 }
3058 }
3059
3060 /* If we reached here, then we haven't yet added the item. This means
3061 * that we should add the item at the end of the list.
3062 */
3063 list_add_tail(&new_pit->list, flex_pit_list);
3064 return 0;
3065}
3066
3067/**
3068 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3069 * @pf: Pointer to the PF structure
3070 * @flex_pit_list: list of flexible src offsets in use
3071 * #flex_pit_start: index to first entry for this section of the table
3072 *
3073 * In order to handle flexible data, the hardware uses a table of values
3074 * called the FLX_PIT table. This table is used to indicate which sections of
3075 * the input correspond to what PIT index values. Unfortunately, hardware is
3076 * very restrictive about programming this table. Entries must be ordered by
3077 * src_offset in ascending order, without duplicates. Additionally, unused
3078 * entries must be set to the unused index value, and must have valid size and
3079 * length according to the src_offset ordering.
3080 *
3081 * This function will reprogram the FLX_PIT register from a book-keeping
3082 * structure that we guarantee is already ordered correctly, and has no more
3083 * than 3 entries.
3084 *
3085 * To make things easier, we only support flexible values of one word length,
3086 * rather than allowing variable length flexible values.
3087 **/
3088static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3089 struct list_head *flex_pit_list,
3090 int flex_pit_start)
3091{
3092 struct i40e_flex_pit *entry = NULL;
3093 u16 last_offset = 0;
3094 int i = 0, j = 0;
3095
3096 /* First, loop over the list of flex PIT entries, and reprogram the
3097 * registers.
3098 */
3099 list_for_each_entry(entry, flex_pit_list, list) {
3100 /* We have to be careful when programming values for the
3101 * largest SRC_OFFSET value. It is possible that adding
3102 * additional empty values at the end would overflow the space
3103 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3104 * we check here and add the empty values prior to adding the
3105 * largest value.
3106 *
3107 * To determine this, we will use a loop from i+1 to 3, which
3108 * will determine whether the unused entries would have valid
3109 * SRC_OFFSET. Note that there cannot be extra entries past
3110 * this value, because the only valid values would have been
3111 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3112 * have been added to the list in the first place.
3113 */
3114 for (j = i + 1; j < 3; j++) {
3115 u16 offset = entry->src_offset + j;
3116 int index = flex_pit_start + i;
3117 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3118 1,
3119 offset - 3);
3120
3121 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3122 i40e_write_rx_ctl(&pf->hw,
3123 I40E_PRTQF_FLX_PIT(index),
3124 value);
3125 i++;
3126 }
3127 }
3128
3129 /* Now, we can program the actual value into the table */
3130 i40e_write_rx_ctl(&pf->hw,
3131 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3132 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3133 1,
3134 entry->src_offset));
3135 i++;
3136 }
3137
3138 /* In order to program the last entries in the table, we need to
3139 * determine the valid offset. If the list is empty, we'll just start
3140 * with 0. Otherwise, we'll start with the last item offset and add 1.
3141 * This ensures that all entries have valid sizes. If we don't do this
3142 * correctly, the hardware will disable flexible field parsing.
3143 */
3144 if (!list_empty(flex_pit_list))
3145 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3146
3147 for (; i < 3; i++, last_offset++) {
3148 i40e_write_rx_ctl(&pf->hw,
3149 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3150 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3151 1,
3152 last_offset));
3153 }
3154}
3155
3156/**
3157 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3158 * @pf: pointer to the PF structure
3159 *
3160 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3161 * internal helper function for implementation details.
3162 **/
3163static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3164{
3165 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3166 I40E_FLEX_PIT_IDX_START_L3);
3167
3168 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3169 I40E_FLEX_PIT_IDX_START_L4);
3170
3171 /* We also need to program the L3 and L4 GLQF ORT register */
3172 i40e_write_rx_ctl(&pf->hw,
3173 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3174 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3175 3, 1));
3176
3177 i40e_write_rx_ctl(&pf->hw,
3178 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3179 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3180 3, 1));
3181}
3182
3183/**
Jacob Keller9229e992017-02-06 14:38:47 -08003184 * i40e_flow_str - Converts a flow_type into a human readable string
3185 * @flow_type: the flow type from a flow specification
3186 *
3187 * Currently only flow types we support are included here, and the string
3188 * value attempts to match what ethtool would use to configure this flow type.
3189 **/
3190static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3191{
3192 switch (fsp->flow_type & ~FLOW_EXT) {
3193 case TCP_V4_FLOW:
3194 return "tcp4";
3195 case UDP_V4_FLOW:
3196 return "udp4";
3197 case SCTP_V4_FLOW:
3198 return "sctp4";
3199 case IP_USER_FLOW:
3200 return "ip4";
3201 default:
3202 return "unknown";
3203 }
3204}
3205
3206/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003207 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3208 * @pit_index: PIT index to convert
3209 *
3210 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3211 * of range.
3212 **/
3213static u64 i40e_pit_index_to_mask(int pit_index)
3214{
3215 switch (pit_index) {
3216 case 0:
3217 return I40E_FLEX_50_MASK;
3218 case 1:
3219 return I40E_FLEX_51_MASK;
3220 case 2:
3221 return I40E_FLEX_52_MASK;
3222 case 3:
3223 return I40E_FLEX_53_MASK;
3224 case 4:
3225 return I40E_FLEX_54_MASK;
3226 case 5:
3227 return I40E_FLEX_55_MASK;
3228 case 6:
3229 return I40E_FLEX_56_MASK;
3230 case 7:
3231 return I40E_FLEX_57_MASK;
3232 default:
3233 return 0;
3234 }
3235}
3236
3237/**
Jacob Keller9229e992017-02-06 14:38:47 -08003238 * i40e_print_input_set - Show changes between two input sets
3239 * @vsi: the vsi being configured
3240 * @old: the old input set
3241 * @new: the new input set
3242 *
3243 * Print the difference between old and new input sets by showing which series
3244 * of words are toggled on or off. Only displays the bits we actually support
3245 * changing.
3246 **/
3247static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3248{
3249 struct i40e_pf *pf = vsi->back;
3250 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003251 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003252
3253 old_value = !!(old & I40E_L3_SRC_MASK);
3254 new_value = !!(new & I40E_L3_SRC_MASK);
3255 if (old_value != new_value)
3256 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3257 old_value ? "ON" : "OFF",
3258 new_value ? "ON" : "OFF");
3259
3260 old_value = !!(old & I40E_L3_DST_MASK);
3261 new_value = !!(new & I40E_L3_DST_MASK);
3262 if (old_value != new_value)
3263 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3264 old_value ? "ON" : "OFF",
3265 new_value ? "ON" : "OFF");
3266
3267 old_value = !!(old & I40E_L4_SRC_MASK);
3268 new_value = !!(new & I40E_L4_SRC_MASK);
3269 if (old_value != new_value)
3270 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3271 old_value ? "ON" : "OFF",
3272 new_value ? "ON" : "OFF");
3273
3274 old_value = !!(old & I40E_L4_DST_MASK);
3275 new_value = !!(new & I40E_L4_DST_MASK);
3276 if (old_value != new_value)
3277 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3278 old_value ? "ON" : "OFF",
3279 new_value ? "ON" : "OFF");
3280
3281 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3282 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3283 if (old_value != new_value)
3284 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3285 old_value ? "ON" : "OFF",
3286 new_value ? "ON" : "OFF");
3287
Jacob Keller0e588de2017-02-06 14:38:50 -08003288 /* Show change of flexible filter entries */
3289 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3290 u64 flex_mask = i40e_pit_index_to_mask(i);
3291
3292 old_value = !!(old & flex_mask);
3293 new_value = !!(new & flex_mask);
3294 if (old_value != new_value)
3295 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3296 i,
3297 old_value ? "ON" : "OFF",
3298 new_value ? "ON" : "OFF");
3299 }
3300
Jacob Keller9229e992017-02-06 14:38:47 -08003301 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3302 old);
3303 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3304 new);
3305}
3306
3307/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003308 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003309 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003310 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003311 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003312 *
Jacob Keller9229e992017-02-06 14:38:47 -08003313 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3314 * for partial matches exists with a few limitations. First, hardware only
3315 * supports masking by word boundary (2 bytes) and not per individual bit.
3316 * Second, hardware is limited to using one mask for a flow type and cannot
3317 * use a separate mask for each filter.
3318 *
3319 * To support these limitations, if we already have a configured filter for
3320 * the specified type, this function enforces that new filters of the type
3321 * match the configured input set. Otherwise, if we do not have a filter of
3322 * the specified type, we allow the input set to be updated to match the
3323 * desired filter.
3324 *
3325 * To help ensure that administrators understand why filters weren't displayed
3326 * as supported, we print a diagnostic message displaying how the input set
3327 * would change and warning to delete the preexisting filters if required.
3328 *
3329 * Returns 0 on successful input set match, and a negative return code on
3330 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003331 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003332static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003333 struct ethtool_rx_flow_spec *fsp,
3334 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003335{
Jacob Keller36777d92017-03-07 15:05:23 -08003336 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003337 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3338 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003339 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003340 bool new_flex_offset = false;
3341 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003342 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003343 u16 index, src_offset = 0;
3344 u8 pit_index = 0;
3345 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003346
3347 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003348 case SCTP_V4_FLOW:
3349 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3350 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3351 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003352 case TCP_V4_FLOW:
3353 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003354 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003355 break;
3356 case UDP_V4_FLOW:
3357 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003358 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003359 break;
3360 case IP_USER_FLOW:
3361 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003362 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003363 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003364 break;
3365 default:
3366 return -EOPNOTSUPP;
3367 }
3368
3369 /* Read the current input set from register memory. */
3370 current_mask = i40e_read_fd_input_set(pf, index);
3371 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003372
Jacob Keller9229e992017-02-06 14:38:47 -08003373 /* Determine, if any, the required changes to the input set in order
3374 * to support the provided mask.
3375 *
3376 * Hardware only supports masking at word (2 byte) granularity and does
3377 * not support full bitwise masking. This implementation simplifies
3378 * even further and only supports fully enabled or fully disabled
3379 * masks for each field, even though we could split the ip4src and
3380 * ip4dst fields.
3381 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003382 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003383 case SCTP_V4_FLOW:
3384 new_mask &= ~I40E_VERIFY_TAG_MASK;
3385 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003386 case TCP_V4_FLOW:
3387 case UDP_V4_FLOW:
3388 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3389
3390 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003391 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3392 new_mask |= I40E_L3_SRC_MASK;
3393 else if (!tcp_ip4_spec->ip4src)
3394 new_mask &= ~I40E_L3_SRC_MASK;
3395 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003396 return -EOPNOTSUPP;
3397
3398 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003399 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3400 new_mask |= I40E_L3_DST_MASK;
3401 else if (!tcp_ip4_spec->ip4dst)
3402 new_mask &= ~I40E_L3_DST_MASK;
3403 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003404 return -EOPNOTSUPP;
3405
3406 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003407 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3408 new_mask |= I40E_L4_SRC_MASK;
3409 else if (!tcp_ip4_spec->psrc)
3410 new_mask &= ~I40E_L4_SRC_MASK;
3411 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003412 return -EOPNOTSUPP;
3413
3414 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003415 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3416 new_mask |= I40E_L4_DST_MASK;
3417 else if (!tcp_ip4_spec->pdst)
3418 new_mask &= ~I40E_L4_DST_MASK;
3419 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003420 return -EOPNOTSUPP;
3421
3422 /* Filtering on Type of Service is not supported. */
3423 if (tcp_ip4_spec->tos)
3424 return -EOPNOTSUPP;
3425
3426 break;
3427 case IP_USER_FLOW:
3428 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3429
3430 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003431 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3432 new_mask |= I40E_L3_SRC_MASK;
3433 else if (!usr_ip4_spec->ip4src)
3434 new_mask &= ~I40E_L3_SRC_MASK;
3435 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003436 return -EOPNOTSUPP;
3437
3438 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003439 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3440 new_mask |= I40E_L3_DST_MASK;
3441 else if (!usr_ip4_spec->ip4dst)
3442 new_mask &= ~I40E_L3_DST_MASK;
3443 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003444 return -EOPNOTSUPP;
3445
3446 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003447 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3448 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3449 else if (!usr_ip4_spec->l4_4_bytes)
3450 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3451 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003452 return -EOPNOTSUPP;
3453
3454 /* Filtering on Type of Service is not supported. */
3455 if (usr_ip4_spec->tos)
3456 return -EOPNOTSUPP;
3457
Jacob Keller0e588de2017-02-06 14:38:50 -08003458 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003459 if (usr_ip4_spec->ip_ver)
3460 return -EINVAL;
3461
Jacob Keller0e588de2017-02-06 14:38:50 -08003462 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003463 if (usr_ip4_spec->proto)
3464 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003465
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003466 break;
3467 default:
3468 return -EOPNOTSUPP;
3469 }
3470
Jacob Keller0e588de2017-02-06 14:38:50 -08003471 /* First, clear all flexible filter entries */
3472 new_mask &= ~I40E_FLEX_INPUT_MASK;
3473
3474 /* If we have a flexible filter, try to add this offset to the correct
3475 * flexible filter PIT list. Once finished, we can update the mask.
3476 * If the src_offset changed, we will get a new mask value which will
3477 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003478 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003479 if (userdef->flex_filter) {
3480 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3481
3482 /* Flexible offset must be even, since the flexible payload
3483 * must be aligned on 2-byte boundary.
3484 */
3485 if (userdef->flex_offset & 0x1) {
3486 dev_warn(&pf->pdev->dev,
3487 "Flexible data offset must be 2-byte aligned\n");
3488 return -EINVAL;
3489 }
3490
3491 src_offset = userdef->flex_offset >> 1;
3492
3493 /* FLX_PIT source offset value is only so large */
3494 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3495 dev_warn(&pf->pdev->dev,
3496 "Flexible data must reside within first 64 bytes of the packet payload\n");
3497 return -EINVAL;
3498 }
3499
3500 /* See if this offset has already been programmed. If we get
3501 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3502 * if we get a NULL pointer, this means we will need to add
3503 * the offset.
3504 */
3505 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3506 src_offset);
3507 if (IS_ERR(flex_pit))
3508 return PTR_ERR(flex_pit);
3509
3510 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3511 * packet types, and thus we need to program both L3 and L4
3512 * flexible values. These must have identical flexible index,
3513 * as otherwise we can't correctly program the input set. So
3514 * we'll find both an L3 and L4 index and make sure they are
3515 * the same.
3516 */
3517 if (flex_l3) {
3518 l3_flex_pit =
3519 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3520 src_offset);
3521 if (IS_ERR(l3_flex_pit))
3522 return PTR_ERR(l3_flex_pit);
3523
3524 if (flex_pit) {
3525 /* If we already had a matching L4 entry, we
3526 * need to make sure that the L3 entry we
3527 * obtained uses the same index.
3528 */
3529 if (l3_flex_pit) {
3530 if (l3_flex_pit->pit_index !=
3531 flex_pit->pit_index) {
3532 return -EINVAL;
3533 }
3534 } else {
3535 new_flex_offset = true;
3536 }
3537 } else {
3538 flex_pit = l3_flex_pit;
3539 }
3540 }
3541
3542 /* If we didn't find an existing flex offset, we need to
3543 * program a new one. However, we don't immediately program it
3544 * here because we will wait to program until after we check
3545 * that it is safe to change the input set.
3546 */
3547 if (!flex_pit) {
3548 new_flex_offset = true;
3549 pit_index = i40e_unused_pit_index(pf);
3550 } else {
3551 pit_index = flex_pit->pit_index;
3552 }
3553
3554 /* Update the mask with the new offset */
3555 new_mask |= i40e_pit_index_to_mask(pit_index);
3556 }
3557
3558 /* If the mask and flexible filter offsets for this filter match the
3559 * currently programmed values we don't need any input set change, so
3560 * this filter is safe to install.
3561 */
3562 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003563 return 0;
3564
3565 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3566 i40e_flow_str(fsp));
3567 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003568 if (new_flex_offset) {
3569 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3570 pit_index, src_offset);
3571 }
Jacob Keller9229e992017-02-06 14:38:47 -08003572
3573 /* Hardware input sets are global across multiple ports, so even the
3574 * main port cannot change them when in MFP mode as this would impact
3575 * any filters on the other ports.
3576 */
3577 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3578 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003579 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003580 }
3581
3582 /* This filter requires us to update the input set. However, hardware
3583 * only supports one input set per flow type, and does not support
3584 * separate masks for each filter. This means that we can only support
3585 * a single mask for all filters of a specific type.
3586 *
3587 * If we have preexisting filters, they obviously depend on the
3588 * current programmed input set. Display a diagnostic message in this
3589 * case explaining why the filter could not be accepted.
3590 */
3591 if (*fdir_filter_count) {
3592 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3593 i40e_flow_str(fsp),
3594 *fdir_filter_count);
3595 return -EOPNOTSUPP;
3596 }
3597
3598 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003599
Jacob Keller0e588de2017-02-06 14:38:50 -08003600 /* Add the new offset and update table, if necessary */
3601 if (new_flex_offset) {
3602 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3603 pit_index);
3604 if (err)
3605 return err;
3606
3607 if (flex_l3) {
3608 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3609 src_offset,
3610 pit_index);
3611 if (err)
3612 return err;
3613 }
3614
3615 i40e_reprogram_flex_pit(pf);
3616 }
3617
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003618 return 0;
3619}
3620
3621/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003622 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003623 * @vsi: pointer to the targeted VSI
3624 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003625 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003626 * Add Flow Director filters for a specific flow spec based on their
3627 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003628 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003629static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3630 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003631{
Jacob Kellere7930952017-02-06 14:38:49 -08003632 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003633 struct ethtool_rx_flow_spec *fsp;
3634 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003635 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003636 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003637 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003638 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003639
3640 if (!vsi)
3641 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003642 pf = vsi->back;
3643
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003644 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3645 return -EOPNOTSUPP;
3646
Jacob Keller47994c12017-04-19 09:25:57 -04003647 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003648 return -ENOSPC;
3649
Jacob Keller0da36b92017-04-19 09:25:55 -04003650 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3651 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003652 return -EBUSY;
3653
Jacob Keller0da36b92017-04-19 09:25:55 -04003654 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003655 return -EBUSY;
3656
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003657 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3658
Jacob Kellere7930952017-02-06 14:38:49 -08003659 /* Parse the user-defined field */
3660 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3661 return -EINVAL;
3662
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003663 /* Extended MAC field is not supported */
3664 if (fsp->flow_type & FLOW_MAC_EXT)
3665 return -EINVAL;
3666
Jacob Keller0e588de2017-02-06 14:38:50 -08003667 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003668 if (ret)
3669 return ret;
3670
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003671 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3672 pf->hw.func_caps.fd_filters_guaranteed)) {
3673 return -EINVAL;
3674 }
3675
Jacob Keller43b15692017-02-06 14:38:48 -08003676 /* ring_cookie is either the drop index, or is a mask of the queue
3677 * index and VF id we wish to target.
3678 */
3679 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3680 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3681 } else {
3682 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3683 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3684
3685 if (!vf) {
3686 if (ring >= vsi->num_queue_pairs)
3687 return -EINVAL;
3688 dest_vsi = vsi->id;
3689 } else {
3690 /* VFs are zero-indexed, so we subtract one here */
3691 vf--;
3692
3693 if (vf >= pf->num_alloc_vfs)
3694 return -EINVAL;
3695 if (ring >= pf->vf[vf].num_queue_pairs)
3696 return -EINVAL;
3697 dest_vsi = pf->vf[vf].lan_vsi_id;
3698 }
3699 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3700 q_index = ring;
3701 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003702
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003703 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003704
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003705 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003706 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003707
3708 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003709 input->q_index = q_index;
3710 input->dest_vsi = dest_vsi;
3711 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003712 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04003713 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08003714 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3715 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08003716 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003717 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00003718
3719 /* Reverse the src and dest notion, since the HW expects them to be from
3720 * Tx perspective where as the input from user is from Rx filter view.
3721 */
3722 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
3723 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08003724 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3725 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003726
Jacob Keller0e588de2017-02-06 14:38:50 -08003727 if (userdef.flex_filter) {
3728 input->flex_filter = true;
3729 input->flex_word = cpu_to_be16(userdef.flex_word);
3730 input->flex_offset = userdef.flex_offset;
3731 }
3732
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003733 ret = i40e_add_del_fdir(vsi, input, true);
3734 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08003735 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003736
Jacob Keller01016da2017-02-06 14:38:40 -08003737 /* Add the input filter to the fdir_input_list, possibly replacing
3738 * a previous filter. Do not free the input structure after adding it
3739 * to the list as this would cause a use-after-free bug.
3740 */
3741 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
3742
3743 return 0;
3744
3745free_input:
3746 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003747 return ret;
3748}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003749
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003750/**
3751 * i40e_set_rxnfc - command to set RX flow classification rules
3752 * @netdev: network interface device structure
3753 * @cmd: ethtool rxnfc command
3754 *
3755 * Returns Success if the command is supported.
3756 **/
3757static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3758{
3759 struct i40e_netdev_priv *np = netdev_priv(netdev);
3760 struct i40e_vsi *vsi = np->vsi;
3761 struct i40e_pf *pf = vsi->back;
3762 int ret = -EOPNOTSUPP;
3763
3764 switch (cmd->cmd) {
3765 case ETHTOOL_SRXFH:
3766 ret = i40e_set_rss_hash_opt(pf, cmd);
3767 break;
3768 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003769 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003770 break;
3771 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003772 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003773 break;
3774 default:
3775 break;
3776 }
3777
3778 return ret;
3779}
3780
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003781/**
3782 * i40e_max_channels - get Max number of combined channels supported
3783 * @vsi: vsi pointer
3784 **/
3785static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
3786{
3787 /* TODO: This code assumes DCB and FD is disabled for now. */
3788 return vsi->alloc_queue_pairs;
3789}
3790
3791/**
3792 * i40e_get_channels - Get the current channels enabled and max supported etc.
3793 * @netdev: network interface device structure
3794 * @ch: ethtool channels structure
3795 *
3796 * We don't support separate tx and rx queues as channels. The other count
3797 * represents how many queues are being used for control. max_combined counts
3798 * how many queue pairs we can support. They may not be mapped 1 to 1 with
3799 * q_vectors since we support a lot more queue pairs than q_vectors.
3800 **/
3801static void i40e_get_channels(struct net_device *dev,
3802 struct ethtool_channels *ch)
3803{
3804 struct i40e_netdev_priv *np = netdev_priv(dev);
3805 struct i40e_vsi *vsi = np->vsi;
3806 struct i40e_pf *pf = vsi->back;
3807
3808 /* report maximum channels */
3809 ch->max_combined = i40e_max_channels(vsi);
3810
3811 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003812 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003813 ch->max_other = ch->other_count;
3814
3815 /* Note: This code assumes DCB is disabled for now. */
3816 ch->combined_count = vsi->num_queue_pairs;
3817}
3818
3819/**
3820 * i40e_set_channels - Set the new channels count.
3821 * @netdev: network interface device structure
3822 * @ch: ethtool channels structure
3823 *
3824 * The new channels count may not be the same as requested by the user
3825 * since it gets rounded down to a power of 2 value.
3826 **/
3827static int i40e_set_channels(struct net_device *dev,
3828 struct ethtool_channels *ch)
3829{
Jacob Keller59826d92016-07-27 12:02:35 -07003830 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003831 struct i40e_netdev_priv *np = netdev_priv(dev);
3832 unsigned int count = ch->combined_count;
3833 struct i40e_vsi *vsi = np->vsi;
3834 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07003835 struct i40e_fdir_filter *rule;
3836 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003837 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07003838 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003839
3840 /* We do not support setting channels for any other VSI at present */
3841 if (vsi->type != I40E_VSI_MAIN)
3842 return -EINVAL;
3843
3844 /* verify they are not requesting separate vectors */
3845 if (!count || ch->rx_count || ch->tx_count)
3846 return -EINVAL;
3847
3848 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003849 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003850 return -EINVAL;
3851
3852 /* verify the number of channels does not exceed hardware limits */
3853 if (count > i40e_max_channels(vsi))
3854 return -EINVAL;
3855
Jacob Keller59826d92016-07-27 12:02:35 -07003856 /* verify that the number of channels does not invalidate any current
3857 * flow director rules
3858 */
3859 hlist_for_each_entry_safe(rule, node2,
3860 &pf->fdir_filter_list, fdir_node) {
3861 if (rule->dest_ctl != drop && count <= rule->q_index) {
3862 dev_warn(&pf->pdev->dev,
3863 "Existing user defined filter %d assigns flow to queue %d\n",
3864 rule->fd_id, rule->q_index);
3865 err = -EINVAL;
3866 }
3867 }
3868
3869 if (err) {
3870 dev_err(&pf->pdev->dev,
3871 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
3872 count);
3873 return err;
3874 }
3875
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003876 /* update feature limits from largest to smallest supported values */
3877 /* TODO: Flow director limit, DCB etc */
3878
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003879 /* use rss_reconfig to rebuild with new queue count and update traffic
3880 * class queue mapping
3881 */
3882 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00003883 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003884 return 0;
3885 else
3886 return -EINVAL;
3887}
3888
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003889/**
3890 * i40e_get_rxfh_key_size - get the RSS hash key size
3891 * @netdev: network interface device structure
3892 *
3893 * Returns the table size.
3894 **/
3895static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
3896{
3897 return I40E_HKEY_ARRAY_SIZE;
3898}
3899
3900/**
3901 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
3902 * @netdev: network interface device structure
3903 *
3904 * Returns the table size.
3905 **/
3906static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
3907{
3908 return I40E_HLUT_ARRAY_SIZE;
3909}
3910
3911static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
3912 u8 *hfunc)
3913{
3914 struct i40e_netdev_priv *np = netdev_priv(netdev);
3915 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04003916 u8 *lut, *seed = NULL;
3917 int ret;
3918 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003919
3920 if (hfunc)
3921 *hfunc = ETH_RSS_HASH_TOP;
3922
3923 if (!indir)
3924 return 0;
3925
Helin Zhang043dd652015-10-21 19:56:23 -04003926 seed = key;
3927 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3928 if (!lut)
3929 return -ENOMEM;
3930 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
3931 if (ret)
3932 goto out;
3933 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3934 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003935
Helin Zhang043dd652015-10-21 19:56:23 -04003936out:
3937 kfree(lut);
3938
3939 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003940}
3941
3942/**
3943 * i40e_set_rxfh - set the rx flow hash indirection table
3944 * @netdev: network interface device structure
3945 * @indir: indirection table
3946 * @key: hash key
3947 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04003948 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003949 * returns 0 after programming the table.
3950 **/
3951static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
3952 const u8 *key, const u8 hfunc)
3953{
3954 struct i40e_netdev_priv *np = netdev_priv(netdev);
3955 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07003956 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04003957 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04003958 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003959
3960 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3961 return -EOPNOTSUPP;
3962
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003963 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04003964 if (!vsi->rss_hkey_user) {
3965 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
3966 GFP_KERNEL);
3967 if (!vsi->rss_hkey_user)
3968 return -ENOMEM;
3969 }
3970 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
3971 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003972 }
Helin Zhang28c58692015-10-26 19:44:27 -04003973 if (!vsi->rss_lut_user) {
3974 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3975 if (!vsi->rss_lut_user)
3976 return -ENOMEM;
3977 }
Helin Zhang043dd652015-10-21 19:56:23 -04003978
Helin Zhang28c58692015-10-26 19:44:27 -04003979 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07003980 if (indir)
3981 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3982 vsi->rss_lut_user[i] = (u8)(indir[i]);
3983 else
3984 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
3985 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04003986
3987 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
3988 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003989}
3990
Greg Rose7e45ab42015-02-06 08:52:19 +00003991/**
3992 * i40e_get_priv_flags - report device private flags
3993 * @dev: network interface device structure
3994 *
3995 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08003996 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00003997 * array.
3998 *
3999 * Returns a u32 bitmap of flags.
4000 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004001static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004002{
4003 struct i40e_netdev_priv *np = netdev_priv(dev);
4004 struct i40e_vsi *vsi = np->vsi;
4005 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004006 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004007
Alexander Duyckaca955d2017-03-10 12:22:01 -08004008 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4009 const struct i40e_priv_flags *priv_flags;
4010
4011 priv_flags = &i40e_gstrings_priv_flags[i];
4012
4013 if (priv_flags->flag & pf->flags)
4014 ret_flags |= BIT(i);
4015 }
4016
4017 if (pf->hw.pf_id != 0)
4018 return ret_flags;
4019
4020 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4021 const struct i40e_priv_flags *priv_flags;
4022
4023 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4024
4025 if (priv_flags->flag & pf->flags)
4026 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004027 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004028
4029 return ret_flags;
4030}
4031
Shannon Nelson9ac77262015-08-27 11:42:40 -04004032/**
4033 * i40e_set_priv_flags - set private flags
4034 * @dev: network interface device structure
4035 * @flags: bit flags to be set
4036 **/
4037static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4038{
4039 struct i40e_netdev_priv *np = netdev_priv(dev);
4040 struct i40e_vsi *vsi = np->vsi;
4041 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004042 u64 changed_flags;
4043 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004044
Alexander Duyckaca955d2017-03-10 12:22:01 -08004045 changed_flags = pf->flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004046
Alexander Duyckaca955d2017-03-10 12:22:01 -08004047 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4048 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004049
Alexander Duyckaca955d2017-03-10 12:22:01 -08004050 priv_flags = &i40e_gstrings_priv_flags[i];
4051
4052 if (priv_flags->read_only)
4053 continue;
4054
4055 if (flags & BIT(i))
4056 pf->flags |= priv_flags->flag;
4057 else
4058 pf->flags &= ~(priv_flags->flag);
4059 }
4060
4061 if (pf->hw.pf_id != 0)
4062 goto flags_complete;
4063
4064 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4065 const struct i40e_priv_flags *priv_flags;
4066
4067 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4068
4069 if (priv_flags->read_only)
4070 continue;
4071
4072 if (flags & BIT(i + j))
4073 pf->flags |= priv_flags->flag;
4074 else
4075 pf->flags &= ~(priv_flags->flag);
4076 }
4077
4078flags_complete:
Alexander Duyckc424d4a2017-03-14 10:15:26 -07004079 /* check for flags that changed */
Alexander Duyckaca955d2017-03-10 12:22:01 -08004080 changed_flags ^= pf->flags;
4081
4082 /* Process any additional changes needed as a result of flag changes.
4083 * The changed_flags value reflects the list of bits that were
4084 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004085 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004086
Alexander Duyckaca955d2017-03-10 12:22:01 -08004087 /* Flush current ATR settings if ATR was disabled */
4088 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4089 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004090 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004091 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004092 }
4093
Alexander Duyckaca955d2017-03-10 12:22:01 -08004094 /* Only allow ATR evict on hardware that is capable of handling it */
Jacob Keller47994c12017-04-19 09:25:57 -04004095 if (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE)
Alexander Duyckaca955d2017-03-10 12:22:01 -08004096 pf->flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE;
Shannon Nelson1cdfd882015-09-28 14:12:34 -04004097
Alexander Duyckaca955d2017-03-10 12:22:01 -08004098 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4099 u16 sw_flags = 0, valid_flags = 0;
4100 int ret;
4101
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004102 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4103 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4104 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4105 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4106 NULL);
4107 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4108 dev_info(&pf->pdev->dev,
4109 "couldn't set switch config bits, err %s aq_err %s\n",
4110 i40e_stat_str(&pf->hw, ret),
4111 i40e_aq_str(&pf->hw,
4112 pf->hw.aq.asq_last_status));
4113 /* not a fatal problem, just keep going */
4114 }
4115 }
4116
Alexander Duyckaca955d2017-03-10 12:22:01 -08004117 /* Issue reset to cause things to take effect, as additional bits
4118 * are added we will need to create a mask of bits requiring reset
4119 */
Alexander Duyckc424d4a2017-03-14 10:15:26 -07004120 if ((changed_flags & I40E_FLAG_VEB_STATS_ENABLED) ||
4121 ((changed_flags & I40E_FLAG_LEGACY_RX) && netif_running(dev)))
Maciej Sosin373149f2017-04-05 07:50:55 -04004122 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004123
Shannon Nelson9ac77262015-08-27 11:42:40 -04004124 return 0;
4125}
4126
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004127static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004128 .get_drvinfo = i40e_get_drvinfo,
4129 .get_regs_len = i40e_get_regs_len,
4130 .get_regs = i40e_get_regs,
4131 .nway_reset = i40e_nway_reset,
4132 .get_link = ethtool_op_get_link,
4133 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004134 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004135 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004136 .get_eeprom_len = i40e_get_eeprom_len,
4137 .get_eeprom = i40e_get_eeprom,
4138 .get_ringparam = i40e_get_ringparam,
4139 .set_ringparam = i40e_set_ringparam,
4140 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004141 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004142 .get_msglevel = i40e_get_msglevel,
4143 .set_msglevel = i40e_set_msglevel,
4144 .get_rxnfc = i40e_get_rxnfc,
4145 .set_rxnfc = i40e_set_rxnfc,
4146 .self_test = i40e_diag_test,
4147 .get_strings = i40e_get_strings,
4148 .set_phys_id = i40e_set_phys_id,
4149 .get_sset_count = i40e_get_sset_count,
4150 .get_ethtool_stats = i40e_get_ethtool_stats,
4151 .get_coalesce = i40e_get_coalesce,
4152 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004153 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4154 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4155 .get_rxfh = i40e_get_rxfh,
4156 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004157 .get_channels = i40e_get_channels,
4158 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004159 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004160 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004161 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004162 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004163 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004164 .get_link_ksettings = i40e_get_link_ksettings,
4165 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004166};
4167
4168void i40e_set_ethtool_ops(struct net_device *netdev)
4169{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004170 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004171}