blob: fc6a5eef141c6fa8653ecf2bcbbfaab0312e8f69 [file] [log] [blame]
Jeff Kirsherae06c702018-03-22 10:08:48 -07001// SPDX-License-Identifier: GPL-2.0
Jeff Kirsher51dce242018-04-26 08:08:09 -07002/* Copyright(c) 2013 - 2018 Intel Corporation. */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003
4/* ethtool support for i40e */
5
6#include "i40e.h"
7#include "i40e_diag.h"
8
9struct i40e_stats {
10 char stat_string[ETH_GSTRING_LEN];
11 int sizeof_stat;
12 int stat_offset;
13};
14
15#define I40E_STAT(_type, _name, _stat) { \
16 .stat_string = _name, \
17 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
18 .stat_offset = offsetof(_type, _stat) \
19}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000020
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000021#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000022 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000023#define I40E_PF_STAT(_name, _stat) \
24 I40E_STAT(struct i40e_pf, _name, _stat)
25#define I40E_VSI_STAT(_name, _stat) \
26 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000027#define I40E_VEB_STAT(_name, _stat) \
28 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000029
30static const struct i40e_stats i40e_gstrings_net_stats[] = {
31 I40E_NETDEV_STAT(rx_packets),
32 I40E_NETDEV_STAT(tx_packets),
33 I40E_NETDEV_STAT(rx_bytes),
34 I40E_NETDEV_STAT(tx_bytes),
35 I40E_NETDEV_STAT(rx_errors),
36 I40E_NETDEV_STAT(tx_errors),
37 I40E_NETDEV_STAT(rx_dropped),
38 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000039 I40E_NETDEV_STAT(collisions),
40 I40E_NETDEV_STAT(rx_length_errors),
41 I40E_NETDEV_STAT(rx_crc_errors),
42};
43
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000044static const struct i40e_stats i40e_gstrings_veb_stats[] = {
45 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
46 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
47 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
48 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
49 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
50 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
51 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
52 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
53 I40E_VEB_STAT("rx_discards", stats.rx_discards),
54 I40E_VEB_STAT("tx_discards", stats.tx_discards),
55 I40E_VEB_STAT("tx_errors", stats.tx_errors),
56 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
57};
58
Shannon Nelson41a9e552014-04-23 04:50:20 +000059static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000060 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
61 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
62 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
63 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000064 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
65 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000066 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040067 I40E_VSI_STAT("tx_linearize", tx_linearize),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040068 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080069 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
70 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000071};
72
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000073/* These PF_STATs might look like duplicates of some NETDEV_STATs,
74 * but they are separate. This device supports Virtualization, and
75 * as such might have several netdevs supporting VMDq and FCoE going
76 * through a single port. The NETDEV_STATs are for individual netdevs
77 * seen at the top of the stack, and the PF_STATs are for the physical
78 * function at the bottom of the stack hosting those netdevs.
79 *
80 * The PF_STATs are appended to the netdev stats only when ethtool -S
81 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
82 */
Joe Perchesfe180a52016-09-26 20:17:01 -070083static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000084 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
85 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +000086 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
87 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
88 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
89 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
90 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
91 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000092 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
93 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000094 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -040095 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
97 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
98 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +000099 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000100 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000101 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
102 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
103 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
104 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
105 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
Alice Michaeldbd668e2017-10-27 11:06:48 -0400106 I40E_PF_STAT("priority_xon_rx", stats.priority_xon_rx),
107 I40E_PF_STAT("priority_xoff_rx", stats.priority_xoff_rx),
108 I40E_PF_STAT("priority_xon_tx", stats.priority_xon_tx),
109 I40E_PF_STAT("priority_xoff_tx", stats.priority_xoff_tx),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000110 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
111 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
112 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
113 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
114 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
115 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
116 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
117 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
118 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
119 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
120 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
121 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
122 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
123 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
124 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
125 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
126 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
127 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
128 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800129 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000130 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jacob Keller2955fac2017-05-03 10:28:58 -0700131 I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000132 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000133 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400134 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400135 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000136 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400137 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000138
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000139 /* LPI stats */
140 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
141 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
142 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
143 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000144};
145
146#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000147 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
148 * 2 /* Tx and Rx together */ \
149 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000150#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
151#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000152#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000153#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000154 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000155 I40E_QUEUE_STATS_LEN((n)))
156#define I40E_PFC_STATS_LEN ( \
157 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
158 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
159 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
160 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
161 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
162 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400163#define I40E_VEB_TC_STATS_LEN ( \
164 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
165 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
166 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
167 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
168 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000169#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400170#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000171#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
172 I40E_PFC_STATS_LEN + \
173 I40E_VSI_STATS_LEN((n)))
174
175enum i40e_ethtool_test_id {
176 I40E_ETH_TEST_REG = 0,
177 I40E_ETH_TEST_EEPROM,
178 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000179 I40E_ETH_TEST_LINK,
180};
181
182static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
183 "Register test (offline)",
184 "Eeprom test (offline)",
185 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000186 "Link test (on/offline)"
187};
188
189#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
190
Alexander Duyckaca955d2017-03-10 12:22:01 -0800191struct i40e_priv_flags {
192 char flag_string[ETH_GSTRING_LEN];
193 u64 flag;
194 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000195};
196
Alexander Duyckaca955d2017-03-10 12:22:01 -0800197#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
198 .flag_string = _name, \
199 .flag = _flag, \
200 .read_only = _read_only, \
201}
202
203static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
204 /* NOTE: MFP setting cannot be changed */
205 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
206 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
207 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
208 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700209 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Mariusz Stachurac3880bd2017-11-14 07:00:50 -0500210 I40E_PRIV_FLAG("link-down-on-close",
211 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700212 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400213 I40E_PRIV_FLAG("disable-source-pruning",
214 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Dave Ertmanc61c8fe2017-12-27 08:18:21 -0500215 I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800216};
217
218#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000219
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700220/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800221static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
222 I40E_PRIV_FLAG("vf-true-promisc-support",
223 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700224};
225
Alexander Duyckaca955d2017-03-10 12:22:01 -0800226#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700227
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000228/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000229 * i40e_partition_setting_complaint - generic complaint for MFP restriction
230 * @pf: the PF struct
231 **/
232static void i40e_partition_setting_complaint(struct i40e_pf *pf)
233{
234 dev_info(&pf->pdev->dev,
235 "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");
236}
237
238/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700239 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
Alan Brady52e2d022017-10-05 14:53:35 -0700240 * @pf: PF struct with phy_types
Alan Brady1eaae512017-10-05 14:53:41 -0700241 * @ks: ethtool link ksettings struct to fill out
Catherine Sullivan06566e52016-05-03 15:13:14 -0700242 *
243 **/
Alan Brady1eaae512017-10-05 14:53:41 -0700244static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
245 struct ethtool_link_ksettings *ks)
Catherine Sullivan06566e52016-05-03 15:13:14 -0700246{
Avinash Dayanand28537042016-06-20 09:10:33 -0700247 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800248 u64 phy_types = pf->hw.phy.phy_types;
249
Alan Brady1eaae512017-10-05 14:53:41 -0700250 ethtool_link_ksettings_zero_link_mode(ks, supported);
251 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700252
253 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
Alan Brady1eaae512017-10-05 14:53:41 -0700254 ethtool_link_ksettings_add_link_mode(ks, supported,
255 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700256 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700257 ethtool_link_ksettings_add_link_mode(ks, advertising,
258 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400259 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady1eaae512017-10-05 14:53:41 -0700260 ethtool_link_ksettings_add_link_mode(ks, supported,
261 100baseT_Full);
262 ethtool_link_ksettings_add_link_mode(ks, advertising,
263 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700264 }
265 }
266 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
267 phy_types & I40E_CAP_PHY_TYPE_XFI ||
268 phy_types & I40E_CAP_PHY_TYPE_SFI ||
269 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
Alan Brady1eaae512017-10-05 14:53:41 -0700270 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
271 ethtool_link_ksettings_add_link_mode(ks, supported,
272 10000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700273 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700274 ethtool_link_ksettings_add_link_mode(ks, advertising,
275 10000baseT_Full);
276 }
277 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
278 ethtool_link_ksettings_add_link_mode(ks, supported,
279 10000baseT_Full);
280 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
281 ethtool_link_ksettings_add_link_mode(ks, advertising,
282 10000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700283 }
284 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
285 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
286 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
Alan Brady1eaae512017-10-05 14:53:41 -0700287 ethtool_link_ksettings_add_link_mode(ks, supported,
288 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700289 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
290 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700291 ethtool_link_ksettings_add_link_mode(ks, supported,
292 40000baseCR4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700293 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700294 ethtool_link_ksettings_add_link_mode(ks, advertising,
295 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700296 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700297 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700298 ethtool_link_ksettings_add_link_mode(ks, supported,
299 100baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700300 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady1eaae512017-10-05 14:53:41 -0700301 ethtool_link_ksettings_add_link_mode(ks, advertising,
302 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700303 }
Alan Brady1eaae512017-10-05 14:53:41 -0700304 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
305 ethtool_link_ksettings_add_link_mode(ks, supported,
306 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700308 ethtool_link_ksettings_add_link_mode(ks, advertising,
309 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700310 }
311 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700312 ethtool_link_ksettings_add_link_mode(ks, supported,
313 40000baseSR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700314 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700315 ethtool_link_ksettings_add_link_mode(ks, supported,
316 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700317 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700318 ethtool_link_ksettings_add_link_mode(ks, supported,
319 40000baseLR4_Full);
320 ethtool_link_ksettings_add_link_mode(ks, advertising,
321 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700322 }
323 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
Alan Brady1eaae512017-10-05 14:53:41 -0700324 ethtool_link_ksettings_add_link_mode(ks, supported,
325 20000baseKR2_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700326 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700327 ethtool_link_ksettings_add_link_mode(ks, advertising,
328 20000baseKR2_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700329 }
330 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700331 ethtool_link_ksettings_add_link_mode(ks, supported,
332 10000baseKX4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700333 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700334 ethtool_link_ksettings_add_link_mode(ks, advertising,
335 10000baseKX4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700336 }
Alan Brady6987bd252017-10-05 14:53:38 -0700337 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
338 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700339 ethtool_link_ksettings_add_link_mode(ks, supported,
340 10000baseKR_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700341 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700342 ethtool_link_ksettings_add_link_mode(ks, advertising,
343 10000baseKR_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700344 }
Alan Brady6987bd252017-10-05 14:53:38 -0700345 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
346 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700347 ethtool_link_ksettings_add_link_mode(ks, supported,
348 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700349 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700350 ethtool_link_ksettings_add_link_mode(ks, advertising,
351 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700352 }
Alan Brady1eaae512017-10-05 14:53:41 -0700353 /* need to add 25G PHY types */
354 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
355 ethtool_link_ksettings_add_link_mode(ks, supported,
356 25000baseKR_Full);
357 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
358 ethtool_link_ksettings_add_link_mode(ks, advertising,
359 25000baseKR_Full);
360 }
361 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
362 ethtool_link_ksettings_add_link_mode(ks, supported,
363 25000baseCR_Full);
364 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
365 ethtool_link_ksettings_add_link_mode(ks, advertising,
366 25000baseCR_Full);
367 }
368 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800369 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
Alan Brady1eaae512017-10-05 14:53:41 -0700370 ethtool_link_ksettings_add_link_mode(ks, supported,
371 25000baseSR_Full);
372 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
373 ethtool_link_ksettings_add_link_mode(ks, advertising,
374 25000baseSR_Full);
375 }
376 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
377 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
378 ethtool_link_ksettings_add_link_mode(ks, supported,
379 25000baseCR_Full);
380 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
381 ethtool_link_ksettings_add_link_mode(ks, advertising,
382 25000baseCR_Full);
383 }
384 /* need to add new 10G PHY types */
385 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
386 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
387 ethtool_link_ksettings_add_link_mode(ks, supported,
388 10000baseCR_Full);
389 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
390 ethtool_link_ksettings_add_link_mode(ks, advertising,
391 10000baseCR_Full);
392 }
393 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
394 ethtool_link_ksettings_add_link_mode(ks, supported,
395 10000baseSR_Full);
396 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
397 ethtool_link_ksettings_add_link_mode(ks, advertising,
398 10000baseSR_Full);
399 }
400 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
401 ethtool_link_ksettings_add_link_mode(ks, supported,
402 10000baseLR_Full);
403 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
404 ethtool_link_ksettings_add_link_mode(ks, advertising,
405 10000baseLR_Full);
406 }
407 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
408 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
409 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
410 ethtool_link_ksettings_add_link_mode(ks, supported,
411 1000baseX_Full);
412 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
413 ethtool_link_ksettings_add_link_mode(ks, advertising,
414 1000baseX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700415 }
416 /* Autoneg PHY types */
417 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
418 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
419 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
420 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800421 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700422 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
423 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
424 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
425 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
426 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
427 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
430 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
431 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
432 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
433 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
434 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
435 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
436 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
437 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
438 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700439 ethtool_link_ksettings_add_link_mode(ks, supported,
440 Autoneg);
441 ethtool_link_ksettings_add_link_mode(ks, advertising,
442 Autoneg);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800443 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700444}
445
446/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000447 * i40e_get_settings_link_up - Get the Link settings for when link is up
448 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700449 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000450 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700451 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000452 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000453static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700454 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400455 struct net_device *netdev,
456 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000457{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000458 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Alan Brady1eaae512017-10-05 14:53:41 -0700459 struct ethtool_link_ksettings cap_ksettings;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000460 u32 link_speed = hw_link_info->link_speed;
461
Catherine Sullivane8278452015-02-06 08:52:08 +0000462 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000463 switch (hw_link_info->phy_type) {
464 case I40E_PHY_TYPE_40GBASE_CR4:
465 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Alan Brady79f04a32017-10-05 14:53:42 -0700466 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
467 ethtool_link_ksettings_add_link_mode(ks, supported,
468 40000baseCR4_Full);
469 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
470 ethtool_link_ksettings_add_link_mode(ks, advertising,
471 40000baseCR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000472 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000473 case I40E_PHY_TYPE_XLAUI:
474 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000475 case I40E_PHY_TYPE_40GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700476 ethtool_link_ksettings_add_link_mode(ks, supported,
477 40000baseCR4_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000478 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000479 case I40E_PHY_TYPE_40GBASE_SR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700480 ethtool_link_ksettings_add_link_mode(ks, supported,
481 40000baseSR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000482 break;
483 case I40E_PHY_TYPE_40GBASE_LR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700484 ethtool_link_ksettings_add_link_mode(ks, supported,
485 40000baseLR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000486 break;
Alan Brady79f04a32017-10-05 14:53:42 -0700487 case I40E_PHY_TYPE_25GBASE_SR:
488 case I40E_PHY_TYPE_25GBASE_LR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000489 case I40E_PHY_TYPE_10GBASE_SR:
490 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000491 case I40E_PHY_TYPE_1000BASE_SX:
492 case I40E_PHY_TYPE_1000BASE_LX:
Alan Brady79f04a32017-10-05 14:53:42 -0700493 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
494 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
495 ethtool_link_ksettings_add_link_mode(ks, supported,
496 25000baseSR_Full);
497 ethtool_link_ksettings_add_link_mode(ks, advertising,
498 25000baseSR_Full);
499 ethtool_link_ksettings_add_link_mode(ks, supported,
500 10000baseSR_Full);
501 ethtool_link_ksettings_add_link_mode(ks, advertising,
502 10000baseSR_Full);
503 ethtool_link_ksettings_add_link_mode(ks, supported,
504 10000baseLR_Full);
505 ethtool_link_ksettings_add_link_mode(ks, advertising,
506 10000baseLR_Full);
507 ethtool_link_ksettings_add_link_mode(ks, supported,
508 1000baseX_Full);
509 ethtool_link_ksettings_add_link_mode(ks, advertising,
510 1000baseX_Full);
511 ethtool_link_ksettings_add_link_mode(ks, supported,
512 10000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400513 if (hw_link_info->module_type[2] &
514 I40E_MODULE_TYPE_1000BASE_SX ||
515 hw_link_info->module_type[2] &
516 I40E_MODULE_TYPE_1000BASE_LX) {
Alan Brady79f04a32017-10-05 14:53:42 -0700517 ethtool_link_ksettings_add_link_mode(ks, supported,
518 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400519 if (hw_link_info->requested_speeds &
520 I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700521 ethtool_link_ksettings_add_link_mode(
522 ks, advertising, 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400523 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000524 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700525 ethtool_link_ksettings_add_link_mode(ks, advertising,
526 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000527 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000528 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000529 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700530 case I40E_PHY_TYPE_100BASE_TX:
Alan Brady79f04a32017-10-05 14:53:42 -0700531 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
532 ethtool_link_ksettings_add_link_mode(ks, supported,
533 10000baseT_Full);
534 ethtool_link_ksettings_add_link_mode(ks, supported,
535 1000baseT_Full);
536 ethtool_link_ksettings_add_link_mode(ks, supported,
537 100baseT_Full);
538 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivane8278452015-02-06 08:52:08 +0000539 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700540 ethtool_link_ksettings_add_link_mode(ks, advertising,
541 10000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000542 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700543 ethtool_link_ksettings_add_link_mode(ks, advertising,
544 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700545 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700546 ethtool_link_ksettings_add_link_mode(ks, advertising,
547 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400548 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400549 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Alan Brady79f04a32017-10-05 14:53:42 -0700550 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
551 ethtool_link_ksettings_add_link_mode(ks, supported,
552 1000baseT_Full);
553 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
554 ethtool_link_ksettings_add_link_mode(ks, advertising,
555 1000baseT_Full);
Catherine Sullivan48becae2015-09-28 14:12:41 -0400556 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000557 case I40E_PHY_TYPE_10GBASE_CR1_CU:
558 case I40E_PHY_TYPE_10GBASE_CR1:
Alan Brady79f04a32017-10-05 14:53:42 -0700559 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
560 ethtool_link_ksettings_add_link_mode(ks, supported,
561 10000baseT_Full);
562 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
563 ethtool_link_ksettings_add_link_mode(ks, advertising,
564 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000565 break;
566 case I40E_PHY_TYPE_XAUI:
567 case I40E_PHY_TYPE_XFI:
568 case I40E_PHY_TYPE_SFI:
569 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000570 case I40E_PHY_TYPE_10GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700571 ethtool_link_ksettings_add_link_mode(ks, supported,
572 10000baseT_Full);
573 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
574 ethtool_link_ksettings_add_link_mode(ks, advertising,
575 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000576 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000577 case I40E_PHY_TYPE_SGMII:
Alan Brady79f04a32017-10-05 14:53:42 -0700578 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
579 ethtool_link_ksettings_add_link_mode(ks, supported,
580 1000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000581 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700582 ethtool_link_ksettings_add_link_mode(ks, advertising,
583 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400584 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady79f04a32017-10-05 14:53:42 -0700585 ethtool_link_ksettings_add_link_mode(ks, supported,
586 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400587 if (hw_link_info->requested_speeds &
588 I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700589 ethtool_link_ksettings_add_link_mode(
590 ks, advertising, 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400591 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000592 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400593 case I40E_PHY_TYPE_40GBASE_KR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700594 case I40E_PHY_TYPE_25GBASE_KR:
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400595 case I40E_PHY_TYPE_20GBASE_KR2:
596 case I40E_PHY_TYPE_10GBASE_KR:
597 case I40E_PHY_TYPE_10GBASE_KX4:
598 case I40E_PHY_TYPE_1000BASE_KX:
Alan Brady79f04a32017-10-05 14:53:42 -0700599 ethtool_link_ksettings_add_link_mode(ks, supported,
600 40000baseKR4_Full);
601 ethtool_link_ksettings_add_link_mode(ks, supported,
602 25000baseKR_Full);
603 ethtool_link_ksettings_add_link_mode(ks, supported,
604 20000baseKR2_Full);
605 ethtool_link_ksettings_add_link_mode(ks, supported,
606 10000baseKR_Full);
607 ethtool_link_ksettings_add_link_mode(ks, supported,
608 10000baseKX4_Full);
609 ethtool_link_ksettings_add_link_mode(ks, supported,
610 1000baseKX_Full);
611 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
612 ethtool_link_ksettings_add_link_mode(ks, advertising,
613 40000baseKR4_Full);
614 ethtool_link_ksettings_add_link_mode(ks, advertising,
615 25000baseKR_Full);
616 ethtool_link_ksettings_add_link_mode(ks, advertising,
617 20000baseKR2_Full);
618 ethtool_link_ksettings_add_link_mode(ks, advertising,
619 10000baseKR_Full);
620 ethtool_link_ksettings_add_link_mode(ks, advertising,
621 10000baseKX4_Full);
622 ethtool_link_ksettings_add_link_mode(ks, advertising,
623 1000baseKX_Full);
624 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400625 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800626 case I40E_PHY_TYPE_25GBASE_CR:
Alan Brady79f04a32017-10-05 14:53:42 -0700627 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
628 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
629 ethtool_link_ksettings_add_link_mode(ks, supported,
630 25000baseCR_Full);
631 ethtool_link_ksettings_add_link_mode(ks, advertising,
632 25000baseCR_Full);
633 break;
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700634 case I40E_PHY_TYPE_25GBASE_AOC:
635 case I40E_PHY_TYPE_25GBASE_ACC:
Alan Brady79f04a32017-10-05 14:53:42 -0700636 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
637 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
638 ethtool_link_ksettings_add_link_mode(ks, supported,
639 25000baseCR_Full);
640
641 ethtool_link_ksettings_add_link_mode(ks, advertising,
642 25000baseCR_Full);
643 ethtool_link_ksettings_add_link_mode(ks, supported,
644 10000baseCR_Full);
645 ethtool_link_ksettings_add_link_mode(ks, advertising,
646 10000baseCR_Full);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800647 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000648 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000649 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700650 netdev_info(netdev,
651 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000652 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000653 }
654
Catherine Sullivan06566e52016-05-03 15:13:14 -0700655 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700656 * current PHY type, get what is supported by the NVM and intersect
657 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700658 */
Alan Brady1eaae512017-10-05 14:53:41 -0700659 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
660 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
661 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700662
Catherine Sullivane8278452015-02-06 08:52:08 +0000663 /* Set speed and duplex */
664 switch (link_speed) {
665 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700666 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000667 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800668 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700669 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800670 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700671 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700672 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700673 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000674 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700675 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000676 break;
677 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700678 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000679 break;
680 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700681 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000682 break;
683 default:
684 break;
685 }
Alan Brady1c142e12017-10-05 14:53:31 -0700686 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000687}
688
689/**
690 * i40e_get_settings_link_down - Get the Link settings for when link is down
691 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700692 * @ks: ethtool ksettings to fill in
693 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000694 *
695 * Reports link settings that can be determined when link is down
696 **/
697static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700698 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400699 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000700{
Catherine Sullivane8278452015-02-06 08:52:08 +0000701 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400702 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000703 */
Alan Brady1eaae512017-10-05 14:53:41 -0700704 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000705
706 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700707 ks->base.speed = SPEED_UNKNOWN;
708 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000709}
710
711/**
Alan Brady1c142e12017-10-05 14:53:31 -0700712 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000713 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700714 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000715 *
716 * Reports speed/duplex settings based on media_type
717 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100718static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700719 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000720{
721 struct i40e_netdev_priv *np = netdev_priv(netdev);
722 struct i40e_pf *pf = np->vsi->back;
723 struct i40e_hw *hw = &pf->hw;
724 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
725 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700726
727 ethtool_link_ksettings_zero_link_mode(ks, supported);
728 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000729
730 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700731 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000732 else
Alan Brady1c142e12017-10-05 14:53:31 -0700733 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000734
735 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000736 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700737 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
738 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000739
Alan Bradya03af692017-10-05 14:53:37 -0700740 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000741 switch (hw->phy.media_type) {
742 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700743 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
744 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
745 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700746 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100747 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700748 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000749 break;
750 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700751 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
752 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
753 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000754 break;
755 case I40E_MEDIA_TYPE_DA:
756 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700757 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
758 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
759 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000760 break;
761 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700762 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
763 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000764 break;
765 case I40E_MEDIA_TYPE_UNKNOWN:
766 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700767 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000768 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000769 }
770
Catherine Sullivane8278452015-02-06 08:52:08 +0000771 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700772 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000773
Catherine Sullivane8278452015-02-06 08:52:08 +0000774 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000775 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700776 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000777 break;
778 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700779 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100780 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000781 break;
782 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700783 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700784 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100785 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000786 break;
787 default:
Alan Brady5f434992017-10-05 14:53:34 -0700788 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
789 ethtool_link_ksettings_del_link_mode(ks, advertising,
790 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000791 break;
792 }
793
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000794 return 0;
795}
796
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000797/**
Alan Brady1c142e12017-10-05 14:53:31 -0700798 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000799 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700800 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000801 *
802 * Set speed/duplex per media_types advertised/forced
803 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100804static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700805 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000806{
807 struct i40e_netdev_priv *np = netdev_priv(netdev);
808 struct i40e_aq_get_phy_abilities_resp abilities;
Alan Brady636b62d2017-10-05 14:53:43 -0700809 struct ethtool_link_ksettings safe_ks;
810 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000811 struct i40e_aq_set_phy_config config;
812 struct i40e_pf *pf = np->vsi->back;
813 struct i40e_vsi *vsi = np->vsi;
814 struct i40e_hw *hw = &pf->hw;
Alan Brady636b62d2017-10-05 14:53:43 -0700815 bool autoneg_changed = false;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000816 i40e_status status = 0;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400817 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000818 int err = 0;
Alan Bradycee91992017-10-05 14:53:44 -0700819 u8 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000820
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000821 /* Changing port settings is not supported if this isn't the
822 * port's controlling PF
823 */
824 if (hw->partition_id != 1) {
825 i40e_partition_setting_complaint(pf);
826 return -EOPNOTSUPP;
827 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000828 if (vsi != pf->vsi[pf->lan_vsi])
829 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000830 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
831 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000832 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700833 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000834 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000835 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400836 if (hw->device_id == I40E_DEV_ID_KX_B ||
837 hw->device_id == I40E_DEV_ID_KX_C ||
838 hw->device_id == I40E_DEV_ID_20G_KR2 ||
Patryk Małek88244a42018-03-19 09:28:03 -0700839 hw->device_id == I40E_DEV_ID_20G_KR2_A ||
Patryk Małek3f8c84372018-03-19 09:28:04 -0700840 hw->device_id == I40E_DEV_ID_25G_B ||
Patryk Małek88244a42018-03-19 09:28:03 -0700841 hw->device_id == I40E_DEV_ID_KX_X722) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400842 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
843 return -EOPNOTSUPP;
844 }
845
Alan Brady1c142e12017-10-05 14:53:31 -0700846 /* copy the ksettings to copy_ks to avoid modifying the origin */
847 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000848
Alan Bradycee91992017-10-05 14:53:44 -0700849 /* save autoneg out of ksettings */
850 autoneg = copy_ks.base.autoneg;
851
Philippe Reynesa7f90942017-02-04 22:05:06 +0100852 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700853 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
Alan Bradycee91992017-10-05 14:53:44 -0700854 safe_ks.base.cmd = copy_ks.base.cmd;
855 safe_ks.base.link_mode_masks_nwords =
856 copy_ks.base.link_mode_masks_nwords;
Alan Brady1c142e12017-10-05 14:53:31 -0700857 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100858
Jan Sokolowski32c23b42018-03-19 09:28:03 -0700859 /* Get link modes supported by hardware and check against modes
860 * requested by the user. Return an error if unsupported mode was set.
861 */
862 if (!bitmap_subset(copy_ks.link_modes.advertising,
863 safe_ks.link_modes.supported,
864 __ETHTOOL_LINK_MODE_MASK_NBITS))
865 return -EINVAL;
866
Alan Bradycee91992017-10-05 14:53:44 -0700867 /* set autoneg back to what it currently is */
Alan Brady1c142e12017-10-05 14:53:31 -0700868 copy_ks.base.autoneg = safe_ks.base.autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000869
Alan Bradycee91992017-10-05 14:53:44 -0700870 /* If copy_ks.base and safe_ks.base are not the same now, then they are
871 * trying to set something that we do not support.
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000872 */
Alan Bradycee91992017-10-05 14:53:44 -0700873 if (memcmp(&copy_ks.base, &safe_ks.base,
874 sizeof(struct ethtool_link_settings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000875 return -EOPNOTSUPP;
876
Jacob Keller0da36b92017-04-19 09:25:55 -0400877 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400878 timeout--;
879 if (!timeout)
880 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000881 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400882 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000883
884 /* Get the current phy config */
885 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
886 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400887 if (status) {
888 err = -EAGAIN;
889 goto done;
890 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000891
Catherine Sullivan124ed152014-07-12 07:28:12 +0000892 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000893 * set below
894 */
895 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000896 config.abilities = abilities.abilities;
897
898 /* Check autoneg */
899 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000900 /* If autoneg was not already enabled */
901 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400902 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700903 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
904 supported,
905 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400906 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400907 err = -EINVAL;
908 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400909 }
910 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000911 config.abilities = abilities.abilities |
912 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700913 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000914 }
915 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000916 /* If autoneg is currently enabled */
917 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400918 /* If autoneg is supported 10GBASE_T is the only PHY
919 * that can disable it, so otherwise return error
920 */
Alan Brady1c142e12017-10-05 14:53:31 -0700921 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
922 supported,
923 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400924 hw->phy.link_info.phy_type !=
925 I40E_PHY_TYPE_10GBASE_T) {
926 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400927 err = -EINVAL;
928 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400929 }
930 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000931 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000932 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700933 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000934 }
935 }
936
Alan Bradycee91992017-10-05 14:53:44 -0700937 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
938 100baseT_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000939 config.link_speed |= I40E_LINK_SPEED_100MB;
Alan Bradycee91992017-10-05 14:53:44 -0700940 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
941 1000baseT_Full) ||
942 ethtool_link_ksettings_test_link_mode(ks, advertising,
943 1000baseX_Full) ||
944 ethtool_link_ksettings_test_link_mode(ks, advertising,
945 1000baseKX_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000946 config.link_speed |= I40E_LINK_SPEED_1GB;
Alan Bradycee91992017-10-05 14:53:44 -0700947 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
948 10000baseT_Full) ||
949 ethtool_link_ksettings_test_link_mode(ks, advertising,
950 10000baseKX4_Full) ||
951 ethtool_link_ksettings_test_link_mode(ks, advertising,
952 10000baseKR_Full) ||
953 ethtool_link_ksettings_test_link_mode(ks, advertising,
954 10000baseCR_Full) ||
955 ethtool_link_ksettings_test_link_mode(ks, advertising,
Jakub Pawlak6ee4d322018-04-20 01:41:35 -0700956 10000baseSR_Full) ||
957 ethtool_link_ksettings_test_link_mode(ks, advertising,
958 10000baseLR_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000959 config.link_speed |= I40E_LINK_SPEED_10GB;
Alan Bradycee91992017-10-05 14:53:44 -0700960 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
961 20000baseKR2_Full))
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700962 config.link_speed |= I40E_LINK_SPEED_20GB;
Alan Bradycee91992017-10-05 14:53:44 -0700963 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
964 25000baseCR_Full) ||
965 ethtool_link_ksettings_test_link_mode(ks, advertising,
966 25000baseKR_Full) ||
967 ethtool_link_ksettings_test_link_mode(ks, advertising,
968 25000baseSR_Full))
969 config.link_speed |= I40E_LINK_SPEED_25GB;
970 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
971 40000baseKR4_Full) ||
972 ethtool_link_ksettings_test_link_mode(ks, advertising,
973 40000baseCR4_Full) ||
974 ethtool_link_ksettings_test_link_mode(ks, advertising,
975 40000baseSR4_Full) ||
976 ethtool_link_ksettings_test_link_mode(ks, advertising,
977 40000baseLR4_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000978 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000979
Catherine Sullivan0002e112015-08-26 15:14:16 -0400980 /* If speed didn't get set, set it to what it currently is.
981 * This is needed because if advertise is 0 (as it is when autoneg
982 * is disabled) then speed won't get set.
983 */
984 if (!config.link_speed)
985 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -0700986 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000987 /* copy over the rest of the abilities */
988 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800989 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000990 config.eee_capability = abilities.eee_capability;
991 config.eeer = abilities.eeer_val;
992 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800993 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
994 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000995
Catherine Sullivane8278452015-02-06 08:52:08 +0000996 /* save the requested speeds */
997 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000998 /* set link and auto negotiation so changes take effect */
999 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1000 /* If link is up put link down */
1001 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
1002 /* Tell the OS link is going down, the link will go
1003 * back up when fw says it is ready asynchronously
1004 */
Matt Jaredc156f852015-08-27 11:42:39 -04001005 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001006 netif_carrier_off(netdev);
1007 netif_tx_stop_all_queues(netdev);
1008 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001009
1010 /* make the aq call */
1011 status = i40e_aq_set_phy_config(hw, &config, NULL);
1012 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001013 netdev_info(netdev,
1014 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001015 i40e_stat_str(hw, status),
1016 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001017 err = -EAGAIN;
1018 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001019 }
1020
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001021 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001022 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001023 netdev_dbg(netdev,
1024 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001025 i40e_stat_str(hw, status),
1026 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001027
1028 } else {
1029 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1030 }
1031
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001032done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001033 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001034
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001035 return err;
1036}
1037
Jesse Brandeburga6599722014-06-04 08:45:25 +00001038static int i40e_nway_reset(struct net_device *netdev)
1039{
1040 /* restart autonegotiation */
1041 struct i40e_netdev_priv *np = netdev_priv(netdev);
1042 struct i40e_pf *pf = np->vsi->back;
1043 struct i40e_hw *hw = &pf->hw;
1044 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1045 i40e_status ret = 0;
1046
1047 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1048 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001049 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1050 i40e_stat_str(hw, ret),
1051 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001052 return -EIO;
1053 }
1054
1055 return 0;
1056}
1057
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001058/**
1059 * i40e_get_pauseparam - Get Flow Control status
Jacob Kellerf5254422018-04-20 01:41:33 -07001060 * @netdev: netdevice structure
1061 * @pause: buffer to return pause parameters
1062 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001063 * Return tx/rx-pause status
1064 **/
1065static void i40e_get_pauseparam(struct net_device *netdev,
1066 struct ethtool_pauseparam *pause)
1067{
1068 struct i40e_netdev_priv *np = netdev_priv(netdev);
1069 struct i40e_pf *pf = np->vsi->back;
1070 struct i40e_hw *hw = &pf->hw;
1071 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001072 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001073
1074 pause->autoneg =
1075 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1076 AUTONEG_ENABLE : AUTONEG_DISABLE);
1077
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001078 /* PFC enabled so report LFC as off */
1079 if (dcbx_cfg->pfc.pfcenable) {
1080 pause->rx_pause = 0;
1081 pause->tx_pause = 0;
1082 return;
1083 }
1084
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001085 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001086 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001087 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001088 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001089 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1090 pause->rx_pause = 1;
1091 pause->tx_pause = 1;
1092 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001093}
1094
Catherine Sullivan2becc352014-06-04 08:45:27 +00001095/**
1096 * i40e_set_pauseparam - Set Flow Control parameter
1097 * @netdev: network interface device structure
1098 * @pause: return tx/rx flow control status
1099 **/
1100static int i40e_set_pauseparam(struct net_device *netdev,
1101 struct ethtool_pauseparam *pause)
1102{
1103 struct i40e_netdev_priv *np = netdev_priv(netdev);
1104 struct i40e_pf *pf = np->vsi->back;
1105 struct i40e_vsi *vsi = np->vsi;
1106 struct i40e_hw *hw = &pf->hw;
1107 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001108 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001109 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1110 i40e_status status;
1111 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001112 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001113
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001114 /* Changing the port's flow control is not supported if this isn't the
1115 * port's controlling PF
1116 */
1117 if (hw->partition_id != 1) {
1118 i40e_partition_setting_complaint(pf);
1119 return -EOPNOTSUPP;
1120 }
1121
Catherine Sullivan2becc352014-06-04 08:45:27 +00001122 if (vsi != pf->vsi[pf->lan_vsi])
1123 return -EOPNOTSUPP;
1124
1125 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1126 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1127 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1128 return -EOPNOTSUPP;
1129 }
1130
1131 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001132 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001133 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1134 /* Send message that it might not necessarily work*/
1135 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1136 }
1137
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001138 if (dcbx_cfg->pfc.pfcenable) {
1139 netdev_info(netdev,
1140 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001141 return -EOPNOTSUPP;
1142 }
1143
1144 if (pause->rx_pause && pause->tx_pause)
1145 hw->fc.requested_mode = I40E_FC_FULL;
1146 else if (pause->rx_pause && !pause->tx_pause)
1147 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1148 else if (!pause->rx_pause && pause->tx_pause)
1149 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1150 else if (!pause->rx_pause && !pause->tx_pause)
1151 hw->fc.requested_mode = I40E_FC_NONE;
1152 else
1153 return -EINVAL;
1154
Catherine Sullivan94128512014-07-12 07:28:16 +00001155 /* Tell the OS link is going down, the link will go back up when fw
1156 * says it is ready asynchronously
1157 */
Matt Jaredc156f852015-08-27 11:42:39 -04001158 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001159 netif_carrier_off(netdev);
1160 netif_tx_stop_all_queues(netdev);
1161
Catherine Sullivan2becc352014-06-04 08:45:27 +00001162 /* Set the fc mode and only restart an if link is up*/
1163 status = i40e_set_fc(hw, &aq_failures, link_up);
1164
1165 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001166 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1167 i40e_stat_str(hw, status),
1168 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001169 err = -EAGAIN;
1170 }
1171 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001172 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1173 i40e_stat_str(hw, status),
1174 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001175 err = -EAGAIN;
1176 }
1177 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001178 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1179 i40e_stat_str(hw, status),
1180 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001181 err = -EAGAIN;
1182 }
1183
Jacob Keller0da36b92017-04-19 09:25:55 -04001184 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001185 /* Give it a little more time to try to come back */
1186 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001187 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001188 return i40e_nway_reset(netdev);
1189 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001190
1191 return err;
1192}
1193
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001194static u32 i40e_get_msglevel(struct net_device *netdev)
1195{
1196 struct i40e_netdev_priv *np = netdev_priv(netdev);
1197 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001198 u32 debug_mask = pf->hw.debug_mask;
1199
1200 if (debug_mask)
1201 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001202
1203 return pf->msg_enable;
1204}
1205
1206static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1207{
1208 struct i40e_netdev_priv *np = netdev_priv(netdev);
1209 struct i40e_pf *pf = np->vsi->back;
1210
1211 if (I40E_DEBUG_USER & data)
1212 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001213 else
1214 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001215}
1216
1217static int i40e_get_regs_len(struct net_device *netdev)
1218{
1219 int reg_count = 0;
1220 int i;
1221
1222 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1223 reg_count += i40e_reg_list[i].elements;
1224
1225 return reg_count * sizeof(u32);
1226}
1227
1228static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1229 void *p)
1230{
1231 struct i40e_netdev_priv *np = netdev_priv(netdev);
1232 struct i40e_pf *pf = np->vsi->back;
1233 struct i40e_hw *hw = &pf->hw;
1234 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001235 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001236 u32 reg;
1237
1238 /* Tell ethtool which driver-version-specific regs output we have.
1239 *
1240 * At some point, if we have ethtool doing special formatting of
1241 * this data, it will rely on this version number to know how to
1242 * interpret things. Hence, this needs to be updated if/when the
1243 * diags register table is changed.
1244 */
1245 regs->version = 1;
1246
1247 /* loop through the diags reg table for what to print */
1248 ri = 0;
1249 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1250 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1251 reg = i40e_reg_list[i].offset
1252 + (j * i40e_reg_list[i].stride);
1253 reg_buf[ri++] = rd32(hw, reg);
1254 }
1255 }
1256
1257}
1258
1259static int i40e_get_eeprom(struct net_device *netdev,
1260 struct ethtool_eeprom *eeprom, u8 *bytes)
1261{
1262 struct i40e_netdev_priv *np = netdev_priv(netdev);
1263 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001264 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001265 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001266 u8 *eeprom_buff;
1267 u16 i, sectors;
1268 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001269 u32 magic;
1270
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001271#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001272 if (eeprom->len == 0)
1273 return -EINVAL;
1274
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001275 /* check for NVMUpdate access method */
1276 magic = hw->vendor_id | (hw->device_id << 16);
1277 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001278 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1279 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001280
1281 /* make sure it is the right magic for NVMUpdate */
1282 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001283 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001284 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1285 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001286 errno = -EBUSY;
1287 else
1288 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001289
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001290 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001291 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001292 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1293 ret_val, hw->aq.asq_last_status, errno,
1294 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1295 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001296
1297 return errno;
1298 }
1299
1300 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1302
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001303 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001304 if (!eeprom_buff)
1305 return -ENOMEM;
1306
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001307 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1308 if (ret_val) {
1309 dev_info(&pf->pdev->dev,
1310 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1311 ret_val, hw->aq.asq_last_status);
1312 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001313 }
1314
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001315 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1316 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1317 len = I40E_NVM_SECTOR_SIZE;
1318 last = false;
1319 for (i = 0; i < sectors; i++) {
1320 if (i == (sectors - 1)) {
1321 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1322 last = true;
1323 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001324 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1325 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001326 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001327 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001328 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001329 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001330 "read NVM failed, invalid offset 0x%x\n",
1331 offset);
1332 break;
1333 } else if (ret_val &&
1334 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1335 dev_info(&pf->pdev->dev,
1336 "read NVM failed, access, offset 0x%x\n",
1337 offset);
1338 break;
1339 } else if (ret_val) {
1340 dev_info(&pf->pdev->dev,
1341 "read NVM failed offset %d err=%d status=0x%x\n",
1342 offset, ret_val, hw->aq.asq_last_status);
1343 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001344 }
1345 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001346
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001347 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001348 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001349free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001350 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001351 return ret_val;
1352}
1353
1354static int i40e_get_eeprom_len(struct net_device *netdev)
1355{
1356 struct i40e_netdev_priv *np = netdev_priv(netdev);
1357 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001358 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001359
Lihong Yangc271dd62017-01-30 12:29:32 -08001360#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1361 if (hw->mac.type == I40E_MAC_X722) {
1362 val = X722_EEPROM_SCOPE_LIMIT + 1;
1363 return val;
1364 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001365 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1366 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1367 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1368 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001369 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001370 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001371}
1372
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001373static int i40e_set_eeprom(struct net_device *netdev,
1374 struct ethtool_eeprom *eeprom, u8 *bytes)
1375{
1376 struct i40e_netdev_priv *np = netdev_priv(netdev);
1377 struct i40e_hw *hw = &np->vsi->back->hw;
1378 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001379 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001380 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001381 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001382 u32 magic;
1383
1384 /* normal ethtool set_eeprom is not supported */
1385 magic = hw->vendor_id | (hw->device_id << 16);
1386 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001387 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001388 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001389 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1390 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001391 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1392 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001393 errno = -EBUSY;
1394 else
1395 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001396
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001397 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001398 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001399 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1400 ret_val, hw->aq.asq_last_status, errno,
1401 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1402 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001403
1404 return errno;
1405}
1406
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001407static void i40e_get_drvinfo(struct net_device *netdev,
1408 struct ethtool_drvinfo *drvinfo)
1409{
1410 struct i40e_netdev_priv *np = netdev_priv(netdev);
1411 struct i40e_vsi *vsi = np->vsi;
1412 struct i40e_pf *pf = vsi->back;
1413
1414 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1415 strlcpy(drvinfo->version, i40e_driver_version_str,
1416 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001417 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001418 sizeof(drvinfo->fw_version));
1419 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1420 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001421 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001422 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001423 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001424}
1425
1426static void i40e_get_ringparam(struct net_device *netdev,
1427 struct ethtool_ringparam *ring)
1428{
1429 struct i40e_netdev_priv *np = netdev_priv(netdev);
1430 struct i40e_pf *pf = np->vsi->back;
1431 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1432
1433 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1434 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1435 ring->rx_mini_max_pending = 0;
1436 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001437 ring->rx_pending = vsi->rx_rings[0]->count;
1438 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001439 ring->rx_mini_pending = 0;
1440 ring->rx_jumbo_pending = 0;
1441}
1442
Björn Töpel74608d12017-05-24 07:55:35 +02001443static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1444{
1445 if (i40e_enabled_xdp_vsi(vsi)) {
1446 return index < vsi->num_queue_pairs ||
1447 (index >= vsi->alloc_queue_pairs &&
1448 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1449 }
1450
1451 return index < vsi->num_queue_pairs;
1452}
1453
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001454static int i40e_set_ringparam(struct net_device *netdev,
1455 struct ethtool_ringparam *ring)
1456{
1457 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1458 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001459 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001460 struct i40e_vsi *vsi = np->vsi;
1461 struct i40e_pf *pf = vsi->back;
1462 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001463 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001464 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001465 int i, err = 0;
1466
1467 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1468 return -EINVAL;
1469
Shannon Nelson1fa18372013-11-20 10:03:08 +00001470 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1471 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1472 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1473 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1474 netdev_info(netdev,
1475 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1476 ring->tx_pending, ring->rx_pending,
1477 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1478 return -EINVAL;
1479 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480
Shannon Nelson1fa18372013-11-20 10:03:08 +00001481 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1482 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001483
1484 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001485 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1486 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001487 return 0;
1488
Jacob Keller0da36b92017-04-19 09:25:55 -04001489 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001490 timeout--;
1491 if (!timeout)
1492 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001493 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001494 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495
1496 if (!netif_running(vsi->netdev)) {
1497 /* simple case - set for the next time the netdev is started */
1498 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001499 vsi->tx_rings[i]->count = new_tx_count;
1500 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001501 if (i40e_enabled_xdp_vsi(vsi))
1502 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001503 }
1504 goto done;
1505 }
1506
1507 /* We can't just free everything and then setup again,
1508 * because the ISRs in MSI-X mode get passed pointers
1509 * to the Tx and Rx ring structs.
1510 */
1511
Björn Töpel74608d12017-05-24 07:55:35 +02001512 /* alloc updated Tx and XDP Tx resources */
1513 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1514 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001515 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001516 netdev_info(netdev,
1517 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001518 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001519 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001520 sizeof(struct i40e_ring), GFP_KERNEL);
1521 if (!tx_rings) {
1522 err = -ENOMEM;
1523 goto done;
1524 }
1525
Björn Töpel74608d12017-05-24 07:55:35 +02001526 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1527 if (!i40e_active_tx_ring_index(vsi, i))
1528 continue;
1529
Alexander Duyck9f65e152013-09-28 06:00:58 +00001530 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001531 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001532 /* the desc and bi pointers will be reallocated in the
1533 * setup call
1534 */
1535 tx_rings[i].desc = NULL;
1536 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001537 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1538 if (err) {
1539 while (i) {
1540 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001541 if (!i40e_active_tx_ring_index(vsi, i))
1542 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543 i40e_free_tx_resources(&tx_rings[i]);
1544 }
1545 kfree(tx_rings);
1546 tx_rings = NULL;
1547
1548 goto done;
1549 }
1550 }
1551 }
1552
1553 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001554 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555 netdev_info(netdev,
1556 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001557 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1559 sizeof(struct i40e_ring), GFP_KERNEL);
1560 if (!rx_rings) {
1561 err = -ENOMEM;
1562 goto free_tx;
1563 }
1564
1565 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001566 struct i40e_ring *ring;
1567 u16 unused;
1568
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001569 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001570 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001572 /* the desc and bi pointers will be reallocated in the
1573 * setup call
1574 */
1575 rx_rings[i].desc = NULL;
1576 rx_rings[i].rx_bi = NULL;
Jesper Dangaard Brouer87128822018-01-03 11:25:23 +01001577 /* Clear cloned XDP RX-queue info before setup call */
1578 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
Tushar Dave2f7679e2016-10-26 10:49:27 -07001579 /* this is to allow wr32 to have something to write to
1580 * during early allocation of Rx buffers
1581 */
1582 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001583 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001584 if (err)
1585 goto rx_unwind;
1586
1587 /* now allocate the Rx buffers to make sure the OS
1588 * has enough memory, any failure here means abort
1589 */
1590 ring = &rx_rings[i];
1591 unused = I40E_DESC_UNUSED(ring);
1592 err = i40e_alloc_rx_buffers(ring, unused);
1593rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001595 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001597 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001598 kfree(rx_rings);
1599 rx_rings = NULL;
1600
1601 goto free_tx;
1602 }
1603 }
1604 }
1605
1606 /* Bring interface down, copy in the new ring info,
1607 * then restore the interface
1608 */
1609 i40e_down(vsi);
1610
1611 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001612 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1613 if (i40e_active_tx_ring_index(vsi, i)) {
1614 i40e_free_tx_resources(vsi->tx_rings[i]);
1615 *vsi->tx_rings[i] = tx_rings[i];
1616 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001617 }
1618 kfree(tx_rings);
1619 tx_rings = NULL;
1620 }
1621
1622 if (rx_rings) {
1623 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001624 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001625 /* get the real tail offset */
1626 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1627 /* this is to fake out the allocation routine
1628 * into thinking it has to realloc everything
1629 * but the recycling logic will let us re-use
1630 * the buffers allocated above
1631 */
1632 rx_rings[i].next_to_use = 0;
1633 rx_rings[i].next_to_clean = 0;
1634 rx_rings[i].next_to_alloc = 0;
1635 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001636 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001637 }
1638 kfree(rx_rings);
1639 rx_rings = NULL;
1640 }
1641
1642 i40e_up(vsi);
1643
1644free_tx:
1645 /* error cleanup if the Rx allocations failed after getting Tx */
1646 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001647 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1648 if (i40e_active_tx_ring_index(vsi, i))
1649 i40e_free_tx_resources(vsi->tx_rings[i]);
1650 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001651 kfree(tx_rings);
1652 tx_rings = NULL;
1653 }
1654
1655done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001656 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001657
1658 return err;
1659}
1660
1661static int i40e_get_sset_count(struct net_device *netdev, int sset)
1662{
1663 struct i40e_netdev_priv *np = netdev_priv(netdev);
1664 struct i40e_vsi *vsi = np->vsi;
1665 struct i40e_pf *pf = vsi->back;
1666
1667 switch (sset) {
1668 case ETH_SS_TEST:
1669 return I40E_TEST_LEN;
1670 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001671 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001672 int len = I40E_PF_STATS_LEN(netdev);
1673
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001674 if ((pf->lan_veb != I40E_NO_VEB) &&
1675 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001676 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001677 return len;
1678 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001679 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001680 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001681 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001682 return I40E_PRIV_FLAGS_STR_LEN +
1683 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001684 default:
1685 return -EOPNOTSUPP;
1686 }
1687}
1688
1689static void i40e_get_ethtool_stats(struct net_device *netdev,
1690 struct ethtool_stats *stats, u64 *data)
1691{
1692 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001693 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001694 struct i40e_vsi *vsi = np->vsi;
1695 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001696 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001697 int i = 0;
1698 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001699 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001700 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001701
1702 i40e_update_stats(vsi);
1703
1704 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1705 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1706 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1707 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1708 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001709 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1710 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1711 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1712 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1713 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001714 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001715 for (j = 0; j < vsi->num_queue_pairs; j++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07001716 tx_ring = READ_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001717
1718 if (!tx_ring)
1719 continue;
1720
1721 /* process Tx ring statistics */
1722 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001723 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001724 data[i] = tx_ring->stats.packets;
1725 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001726 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001727 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001728
1729 /* Rx ring is the 2nd half of the queue pair */
1730 rx_ring = &tx_ring[1];
1731 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001732 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001733 data[i] = rx_ring->stats.packets;
1734 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001735 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001736 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001737 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001738 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001739 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001740 return;
1741
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001742 if ((pf->lan_veb != I40E_NO_VEB) &&
1743 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001744 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001745
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001746 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1747 p = (char *)veb;
1748 p += i40e_gstrings_veb_stats[j].stat_offset;
1749 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1750 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001751 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001752 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1753 data[i++] = veb->tc_stats.tc_tx_packets[j];
1754 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1755 data[i++] = veb->tc_stats.tc_rx_packets[j];
1756 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1757 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001758 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001759 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1760 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1761 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1762 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1763 }
1764 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1765 data[i++] = pf->stats.priority_xon_tx[j];
1766 data[i++] = pf->stats.priority_xoff_tx[j];
1767 }
1768 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1769 data[i++] = pf->stats.priority_xon_rx[j];
1770 data[i++] = pf->stats.priority_xoff_rx[j];
1771 }
1772 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1773 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774}
1775
1776static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1777 u8 *data)
1778{
1779 struct i40e_netdev_priv *np = netdev_priv(netdev);
1780 struct i40e_vsi *vsi = np->vsi;
1781 struct i40e_pf *pf = vsi->back;
1782 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001783 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001784
1785 switch (stringset) {
1786 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001787 memcpy(data, i40e_gstrings_test,
1788 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001789 break;
1790 case ETH_SS_STATS:
1791 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1792 snprintf(p, ETH_GSTRING_LEN, "%s",
1793 i40e_gstrings_net_stats[i].stat_string);
1794 p += ETH_GSTRING_LEN;
1795 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001796 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1797 snprintf(p, ETH_GSTRING_LEN, "%s",
1798 i40e_gstrings_misc_stats[i].stat_string);
1799 p += ETH_GSTRING_LEN;
1800 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001801 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001802 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001803 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001804 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001805 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001806 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001807 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001808 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001809 p += ETH_GSTRING_LEN;
1810 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001811 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001812 return;
1813
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001814 if ((pf->lan_veb != I40E_NO_VEB) &&
1815 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001816 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1817 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1818 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819 p += ETH_GSTRING_LEN;
1820 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001821 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1822 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001823 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001824 p += ETH_GSTRING_LEN;
1825 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001826 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001827 p += ETH_GSTRING_LEN;
1828 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001829 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001830 p += ETH_GSTRING_LEN;
1831 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001832 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001833 p += ETH_GSTRING_LEN;
1834 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001835 }
1836 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1837 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1838 i40e_gstrings_stats[i].stat_string);
1839 p += ETH_GSTRING_LEN;
1840 }
1841 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1842 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001843 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001844 p += ETH_GSTRING_LEN;
1845 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001846 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001847 p += ETH_GSTRING_LEN;
1848 }
1849 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1850 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001851 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001852 p += ETH_GSTRING_LEN;
1853 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001854 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001855 p += ETH_GSTRING_LEN;
1856 }
1857 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1858 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001859 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001860 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001861 }
1862 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1863 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001864 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001865 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1866 snprintf(p, ETH_GSTRING_LEN, "%s",
1867 i40e_gstrings_priv_flags[i].flag_string);
1868 p += ETH_GSTRING_LEN;
1869 }
1870 if (pf->hw.pf_id != 0)
1871 break;
1872 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1873 snprintf(p, ETH_GSTRING_LEN, "%s",
1874 i40e_gl_gstrings_priv_flags[i].flag_string);
1875 p += ETH_GSTRING_LEN;
1876 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001877 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001878 default:
1879 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001880 }
1881}
1882
1883static int i40e_get_ts_info(struct net_device *dev,
1884 struct ethtool_ts_info *info)
1885{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001886 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1887
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001888 /* only report HW timestamping if PTP is enabled */
1889 if (!(pf->flags & I40E_FLAG_PTP))
1890 return ethtool_op_get_ts_info(dev, info);
1891
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001892 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1893 SOF_TIMESTAMPING_RX_SOFTWARE |
1894 SOF_TIMESTAMPING_SOFTWARE |
1895 SOF_TIMESTAMPING_TX_HARDWARE |
1896 SOF_TIMESTAMPING_RX_HARDWARE |
1897 SOF_TIMESTAMPING_RAW_HARDWARE;
1898
1899 if (pf->ptp_clock)
1900 info->phc_index = ptp_clock_index(pf->ptp_clock);
1901 else
1902 info->phc_index = -1;
1903
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001904 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001905
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001906 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001907 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1908 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1909 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1910
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001911 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001912 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1913 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1914 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1915 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1916 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1917 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1918 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1919 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001920
1921 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001922}
1923
Shannon Nelson7b086392013-11-20 10:02:59 +00001924static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001925{
Shannon Nelson7b086392013-11-20 10:02:59 +00001926 struct i40e_netdev_priv *np = netdev_priv(netdev);
1927 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001928 i40e_status status;
1929 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001930
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001931 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001932 status = i40e_get_link_status(&pf->hw, &link_up);
1933 if (status) {
1934 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1935 *data = 1;
1936 return *data;
1937 }
1938
1939 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001940 *data = 0;
1941 else
1942 *data = 1;
1943
1944 return *data;
1945}
1946
Shannon Nelson7b086392013-11-20 10:02:59 +00001947static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948{
Shannon Nelson7b086392013-11-20 10:02:59 +00001949 struct i40e_netdev_priv *np = netdev_priv(netdev);
1950 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001951
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001952 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001953 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001954
Shannon Nelson7b086392013-11-20 10:02:59 +00001955 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001956}
1957
Shannon Nelson7b086392013-11-20 10:02:59 +00001958static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001959{
Shannon Nelson7b086392013-11-20 10:02:59 +00001960 struct i40e_netdev_priv *np = netdev_priv(netdev);
1961 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001962
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001963 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001964 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001965
Shannon Nelson4443ec92014-11-13 08:23:12 +00001966 /* forcebly clear the NVM Update state machine */
1967 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1968
Shannon Nelson7b086392013-11-20 10:02:59 +00001969 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001970}
1971
Shannon Nelson7b086392013-11-20 10:02:59 +00001972static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001973{
Shannon Nelson7b086392013-11-20 10:02:59 +00001974 struct i40e_netdev_priv *np = netdev_priv(netdev);
1975 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001976 u16 swc_old = pf->sw_int_count;
1977
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001978 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001979 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1980 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001981 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1982 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1983 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1984 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001985 usleep_range(1000, 2000);
1986 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001987
1988 return *data;
1989}
1990
Greg Rosee17bc412015-04-16 20:05:59 -04001991static inline bool i40e_active_vfs(struct i40e_pf *pf)
1992{
1993 struct i40e_vf *vfs = pf->vf;
1994 int i;
1995
1996 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001997 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001998 return true;
1999 return false;
2000}
2001
Greg Rose510efb22015-07-10 19:36:01 -04002002static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2003{
Alexander Duyck4b816442016-10-11 15:26:53 -07002004 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04002005}
2006
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002007static void i40e_diag_test(struct net_device *netdev,
2008 struct ethtool_test *eth_test, u64 *data)
2009{
2010 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002011 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002012 struct i40e_pf *pf = np->vsi->back;
2013
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002014 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2015 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002016 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002017
Jacob Keller0da36b92017-04-19 09:25:55 -04002018 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002019
Greg Rose510efb22015-07-10 19:36:01 -04002020 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002021 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002022 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002023 data[I40E_ETH_TEST_REG] = 1;
2024 data[I40E_ETH_TEST_EEPROM] = 1;
2025 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002026 data[I40E_ETH_TEST_LINK] = 1;
2027 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002028 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002029 goto skip_ol_tests;
2030 }
2031
Greg Rose5b86c5c2015-02-26 16:14:35 +00002032 /* If the device is online then take it offline */
2033 if (if_running)
2034 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002035 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002036 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002037 /* This reset does not affect link - if it is
2038 * changed to a type of reset that does affect
2039 * link then the following link test would have
2040 * to be moved to before the reset
2041 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002042 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002043
Shannon Nelson7b086392013-11-20 10:02:59 +00002044 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002045 eth_test->flags |= ETH_TEST_FL_FAILED;
2046
Shannon Nelson7b086392013-11-20 10:02:59 +00002047 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002048 eth_test->flags |= ETH_TEST_FL_FAILED;
2049
Shannon Nelson7b086392013-11-20 10:02:59 +00002050 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002051 eth_test->flags |= ETH_TEST_FL_FAILED;
2052
Shannon Nelsonf551b432013-11-26 10:49:12 +00002053 /* run reg test last, a reset is required after it */
2054 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2055 eth_test->flags |= ETH_TEST_FL_FAILED;
2056
Jacob Keller0da36b92017-04-19 09:25:55 -04002057 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002058 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002059
2060 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002061 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002062 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002063 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002064 netif_info(pf, drv, netdev, "online testing starting\n");
2065
Shannon Nelson7b086392013-11-20 10:02:59 +00002066 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002067 eth_test->flags |= ETH_TEST_FL_FAILED;
2068
2069 /* Offline only tests, not run in online; pass by default */
2070 data[I40E_ETH_TEST_REG] = 0;
2071 data[I40E_ETH_TEST_EEPROM] = 0;
2072 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002073 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002074
Greg Rosee17bc412015-04-16 20:05:59 -04002075skip_ol_tests:
2076
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002077 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002078}
2079
2080static void i40e_get_wol(struct net_device *netdev,
2081 struct ethtool_wolinfo *wol)
2082{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002083 struct i40e_netdev_priv *np = netdev_priv(netdev);
2084 struct i40e_pf *pf = np->vsi->back;
2085 struct i40e_hw *hw = &pf->hw;
2086 u16 wol_nvm_bits;
2087
2088 /* NVM bit on means WoL disabled for the port */
2089 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002090 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002091 wol->supported = 0;
2092 wol->wolopts = 0;
2093 } else {
2094 wol->supported = WAKE_MAGIC;
2095 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2096 }
2097}
2098
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002099/**
2100 * i40e_set_wol - set the WakeOnLAN configuration
2101 * @netdev: the netdev in question
2102 * @wol: the ethtool WoL setting data
2103 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002104static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2105{
2106 struct i40e_netdev_priv *np = netdev_priv(netdev);
2107 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002108 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002109 struct i40e_hw *hw = &pf->hw;
2110 u16 wol_nvm_bits;
2111
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002112 /* WoL not supported if this isn't the controlling PF on the port */
2113 if (hw->partition_id != 1) {
2114 i40e_partition_setting_complaint(pf);
2115 return -EOPNOTSUPP;
2116 }
2117
2118 if (vsi != pf->vsi[pf->lan_vsi])
2119 return -EOPNOTSUPP;
2120
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002121 /* NVM bit on means WoL disabled for the port */
2122 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002123 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002124 return -EOPNOTSUPP;
2125
2126 /* only magic packet is supported */
2127 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2128 return -EOPNOTSUPP;
2129
2130 /* is this a new value? */
2131 if (pf->wol_en != !!wol->wolopts) {
2132 pf->wol_en = !!wol->wolopts;
2133 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2134 }
2135
2136 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002137}
2138
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002139static int i40e_set_phys_id(struct net_device *netdev,
2140 enum ethtool_phys_id_state state)
2141{
2142 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002143 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144 struct i40e_pf *pf = np->vsi->back;
2145 struct i40e_hw *hw = &pf->hw;
2146 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002147 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002148
2149 switch (state) {
2150 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002151 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002152 pf->led_status = i40e_led_get(hw);
2153 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002154 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2155 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2156 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002157 ret = i40e_led_get_phy(hw, &temp_status,
2158 &pf->phy_led_val);
2159 pf->led_status = temp_status;
2160 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002161 return blink_freq;
2162 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002163 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002164 i40e_led_set(hw, 0xf, false);
2165 else
2166 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002167 break;
2168 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002169 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002170 i40e_led_set(hw, 0x0, false);
2171 else
2172 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002173 break;
2174 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002175 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002176 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002177 } else {
2178 ret = i40e_led_set_phy(hw, false, pf->led_status,
2179 (pf->phy_led_val |
2180 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002181 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2182 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002183 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002185 default:
2186 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002187 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002188 if (ret)
2189 return -ENOENT;
2190 else
2191 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002192}
2193
2194/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2195 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2196 * 125us (8000 interrupts per second) == ITR(62)
2197 */
2198
Jacob Keller65e87c02016-09-12 14:18:44 -07002199/**
2200 * __i40e_get_coalesce - get per-queue coalesce settings
2201 * @netdev: the netdev to check
2202 * @ec: ethtool coalesce data structure
2203 * @queue: which queue to pick
2204 *
2205 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2206 * are per queue. If queue is <0 then we default to queue 0 as the
2207 * representative value.
2208 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002209static int __i40e_get_coalesce(struct net_device *netdev,
2210 struct ethtool_coalesce *ec,
2211 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212{
2213 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002214 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002215 struct i40e_vsi *vsi = np->vsi;
2216
2217 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2218 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2219
Alan Bradya03af692017-10-05 14:53:37 -07002220 /* rx and tx usecs has per queue value. If user doesn't specify the
2221 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002222 */
Alan Bradya03af692017-10-05 14:53:37 -07002223 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002224 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002225 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002226 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002227
Jacob Keller65e87c02016-09-12 14:18:44 -07002228 rx_ring = vsi->rx_rings[queue];
2229 tx_ring = vsi->tx_rings[queue];
2230
Alexander Duyck40588ca2017-12-29 08:49:28 -05002231 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002232 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002233
Alexander Duyck40588ca2017-12-29 08:49:28 -05002234 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002235 ec->use_adaptive_tx_coalesce = 1;
2236
Alexander Duyck40588ca2017-12-29 08:49:28 -05002237 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2238 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
Jacob Keller65e87c02016-09-12 14:18:44 -07002239
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002240 /* we use the _usecs_high to store/set the interrupt rate limit
2241 * that the hardware supports, that almost but not quite
2242 * fits the original intent of the ethtool variable,
2243 * the rx_coalesce_usecs_high limits total interrupts
2244 * per second from both tx/rx sources.
2245 */
2246 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2247 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002248
2249 return 0;
2250}
2251
Jacob Keller65e87c02016-09-12 14:18:44 -07002252/**
2253 * i40e_get_coalesce - get a netdev's coalesce settings
2254 * @netdev: the netdev to check
2255 * @ec: ethtool coalesce data structure
2256 *
2257 * Gets the coalesce settings for a particular netdev. Note that if user has
2258 * modified per-queue settings, this only guarantees to represent queue 0. See
2259 * __i40e_get_coalesce for more details.
2260 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002261static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002262 struct ethtool_coalesce *ec)
2263{
Kan Lianga75e8002016-02-19 09:24:04 -05002264 return __i40e_get_coalesce(netdev, ec, -1);
2265}
2266
Jacob Keller65e87c02016-09-12 14:18:44 -07002267/**
2268 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2269 * @netdev: netdev structure
2270 * @ec: ethtool's coalesce settings
2271 * @queue: the particular queue to read
2272 *
2273 * Will read a specific queue's coalesce settings
2274 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002275static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2276 struct ethtool_coalesce *ec)
2277{
2278 return __i40e_get_coalesce(netdev, ec, queue);
2279}
2280
Jacob Keller65e87c02016-09-12 14:18:44 -07002281/**
2282 * i40e_set_itr_per_queue - set ITR values for specific queue
2283 * @vsi: the VSI to set values for
2284 * @ec: coalesce settings from ethtool
2285 * @queue: the queue to modify
2286 *
2287 * Change the ITR settings for a specific queue.
2288 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002289static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2290 struct ethtool_coalesce *ec,
2291 int queue)
2292{
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002293 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2294 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002295 struct i40e_pf *pf = vsi->back;
2296 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002297 struct i40e_q_vector *q_vector;
Alexander Duyck8b99b112017-12-29 08:50:44 -05002298 u16 intrl;
Kan Lianga75e8002016-02-19 09:24:04 -05002299
Alan Brady1c0e6a32016-11-28 16:06:02 -08002300 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002301
Alexander Duyck92418fb2017-12-29 08:51:08 -05002302 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2303 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
Kan Lianga75e8002016-02-19 09:24:04 -05002304
2305 if (ec->use_adaptive_rx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002306 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002307 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002308 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002309
2310 if (ec->use_adaptive_tx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002311 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002312 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002313 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002314
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002315 q_vector = rx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002316 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
Kan Lianga75e8002016-02-19 09:24:04 -05002317
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002318 q_vector = tx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002319 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2320
2321 /* The interrupt handler itself will take care of programming
2322 * the Tx and Rx ITR values based on the values we have entered
2323 * into the q_vector, no need to write the values now.
2324 */
Kan Lianga75e8002016-02-19 09:24:04 -05002325
Alexander Duyck8b99b112017-12-29 08:50:44 -05002326 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
Kan Lianga75e8002016-02-19 09:24:04 -05002327 i40e_flush(hw);
2328}
2329
Jacob Keller65e87c02016-09-12 14:18:44 -07002330/**
2331 * __i40e_set_coalesce - set coalesce settings for particular queue
2332 * @netdev: the netdev to change
2333 * @ec: ethtool coalesce settings
2334 * @queue: the queue to change
2335 *
2336 * Sets the coalesce settings for a particular queue.
2337 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002338static int __i40e_set_coalesce(struct net_device *netdev,
2339 struct ethtool_coalesce *ec,
2340 int queue)
2341{
2342 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002343 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002344 struct i40e_vsi *vsi = np->vsi;
2345 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002346 int i;
2347
2348 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2349 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2350
Alan Brady06b2dec2017-07-12 05:46:06 -04002351 if (queue < 0) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002352 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2353 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002354 } else if (queue < vsi->num_queue_pairs) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002355 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2356 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002357 } else {
2358 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2359 vsi->num_queue_pairs - 1);
2360 return -EINVAL;
2361 }
2362
2363 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2364 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2365
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002366 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2367 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2368 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2369 return -EINVAL;
2370 }
2371
Alan Brady33084062016-11-28 16:06:03 -08002372 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2373 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2374 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002375 return -EINVAL;
2376 }
2377
Alan Brady06b2dec2017-07-12 05:46:06 -04002378 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2379 ec->use_adaptive_rx_coalesce) {
2380 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2381 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002382 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002383
Alexander Duyck92418fb2017-12-29 08:51:08 -05002384 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002385 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2386 return -EINVAL;
2387 }
2388
2389 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2390 ec->use_adaptive_tx_coalesce) {
2391 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2392 return -EINVAL;
2393 }
2394
Alexander Duyck92418fb2017-12-29 08:51:08 -05002395 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002396 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2397 return -EINVAL;
2398 }
2399
2400 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002401 ec->rx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002402
2403 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002404 ec->tx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002405
Alan Brady33084062016-11-28 16:06:03 -08002406 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2407 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2408 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2409 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2410 vsi->int_rate_limit);
2411 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002412
Alan Bradya03af692017-10-05 14:53:37 -07002413 /* rx and tx usecs has per queue value. If user doesn't specify the
2414 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002415 */
2416 if (queue < 0) {
2417 for (i = 0; i < vsi->num_queue_pairs; i++)
2418 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002419 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002420 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002421 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002422
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002423 return 0;
2424}
2425
Jacob Keller65e87c02016-09-12 14:18:44 -07002426/**
2427 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2428 * @netdev: the netdev to change
2429 * @ec: ethtool coalesce settings
2430 *
2431 * This will set each queue to the same coalesce settings.
2432 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002433static int i40e_set_coalesce(struct net_device *netdev,
2434 struct ethtool_coalesce *ec)
2435{
2436 return __i40e_set_coalesce(netdev, ec, -1);
2437}
2438
Jacob Keller65e87c02016-09-12 14:18:44 -07002439/**
2440 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2441 * @netdev: the netdev to change
2442 * @ec: ethtool's coalesce settings
2443 * @queue: the queue to change
2444 *
2445 * Sets the specified queue's coalesce settings.
2446 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002447static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2448 struct ethtool_coalesce *ec)
2449{
2450 return __i40e_set_coalesce(netdev, ec, queue);
2451}
2452
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002453/**
2454 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2455 * @pf: pointer to the physical function struct
2456 * @cmd: ethtool rxnfc command
2457 *
2458 * Returns Success if the flow is supported, else Invalid Input.
2459 **/
2460static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2461{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002462 struct i40e_hw *hw = &pf->hw;
2463 u8 flow_pctype = 0;
2464 u64 i_set = 0;
2465
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002466 cmd->data = 0;
2467
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002468 switch (cmd->flow_type) {
2469 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002470 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2471 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002472 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002473 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2474 break;
2475 case TCP_V6_FLOW:
2476 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2477 break;
2478 case UDP_V6_FLOW:
2479 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2480 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002481 case SCTP_V4_FLOW:
2482 case AH_ESP_V4_FLOW:
2483 case AH_V4_FLOW:
2484 case ESP_V4_FLOW:
2485 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002486 case SCTP_V6_FLOW:
2487 case AH_ESP_V6_FLOW:
2488 case AH_V6_FLOW:
2489 case ESP_V6_FLOW:
2490 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002491 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002492 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2493 break;
2494 default:
2495 return -EINVAL;
2496 }
2497
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002498 /* Read flow based hash input set register */
2499 if (flow_pctype) {
2500 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2501 flow_pctype)) |
2502 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2503 flow_pctype)) << 32);
2504 }
2505
2506 /* Process bits of hash input set */
2507 if (i_set) {
2508 if (i_set & I40E_L4_SRC_MASK)
2509 cmd->data |= RXH_L4_B_0_1;
2510 if (i_set & I40E_L4_DST_MASK)
2511 cmd->data |= RXH_L4_B_2_3;
2512
2513 if (cmd->flow_type == TCP_V4_FLOW ||
2514 cmd->flow_type == UDP_V4_FLOW) {
2515 if (i_set & I40E_L3_SRC_MASK)
2516 cmd->data |= RXH_IP_SRC;
2517 if (i_set & I40E_L3_DST_MASK)
2518 cmd->data |= RXH_IP_DST;
2519 } else if (cmd->flow_type == TCP_V6_FLOW ||
2520 cmd->flow_type == UDP_V6_FLOW) {
2521 if (i_set & I40E_L3_V6_SRC_MASK)
2522 cmd->data |= RXH_IP_SRC;
2523 if (i_set & I40E_L3_V6_DST_MASK)
2524 cmd->data |= RXH_IP_DST;
2525 }
2526 }
2527
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002528 return 0;
2529}
2530
2531/**
Jacob Kellere7930952017-02-06 14:38:49 -08002532 * i40e_check_mask - Check whether a mask field is set
2533 * @mask: the full mask value
Jacob Kellerf5254422018-04-20 01:41:33 -07002534 * @field: mask of the field to check
Jacob Kellere7930952017-02-06 14:38:49 -08002535 *
2536 * If the given mask is fully set, return positive value. If the mask for the
2537 * field is fully unset, return zero. Otherwise return a negative error code.
2538 **/
2539static int i40e_check_mask(u64 mask, u64 field)
2540{
2541 u64 value = mask & field;
2542
2543 if (value == field)
2544 return 1;
2545 else if (!value)
2546 return 0;
2547 else
2548 return -1;
2549}
2550
2551/**
2552 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2553 * @fsp: pointer to rx flow specification
2554 * @data: pointer to userdef data structure for storage
2555 *
2556 * Read the user-defined data and deconstruct the value into a structure. No
2557 * other code should read the user-defined data, so as to ensure that every
2558 * place consistently reads the value correctly.
2559 *
2560 * The user-defined field is a 64bit Big Endian format value, which we
2561 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2562 * be defined starting from the highest bits, while small bit field values
2563 * shall be defined starting from the lowest bits.
2564 *
2565 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2566 * and the filter should be rejected. The data structure will always be
2567 * modified even if FLOW_EXT is not set.
2568 *
2569 **/
2570static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2571 struct i40e_rx_flow_userdef *data)
2572{
2573 u64 value, mask;
2574 int valid;
2575
2576 /* Zero memory first so it's always consistent. */
2577 memset(data, 0, sizeof(*data));
2578
2579 if (!(fsp->flow_type & FLOW_EXT))
2580 return 0;
2581
2582 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2583 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2584
2585#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2586#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2587#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2588
2589 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2590 if (valid < 0) {
2591 return -EINVAL;
2592 } else if (valid) {
2593 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2594 data->flex_offset =
2595 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2596 data->flex_filter = true;
2597 }
2598
2599 return 0;
2600}
2601
2602/**
2603 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2604 * @fsp: pointer to rx_flow specification
Jacob Kellerf5254422018-04-20 01:41:33 -07002605 * @data: pointer to return userdef data
Jacob Kellere7930952017-02-06 14:38:49 -08002606 *
2607 * Reads the userdef data structure and properly fills in the user defined
2608 * fields of the rx_flow_spec.
2609 **/
2610static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2611 struct i40e_rx_flow_userdef *data)
2612{
2613 u64 value = 0, mask = 0;
2614
2615 if (data->flex_filter) {
2616 value |= data->flex_word;
2617 value |= (u64)data->flex_offset << 16;
2618 mask |= I40E_USERDEF_FLEX_FILTER;
2619 }
2620
2621 if (value || mask)
2622 fsp->flow_type |= FLOW_EXT;
2623
2624 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2625 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2626}
2627
2628/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002629 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2630 * @pf: Pointer to the physical function struct
2631 * @cmd: The command to get or set Rx flow classification rules
2632 * @rule_locs: Array of used rule locations
2633 *
2634 * This function populates both the total and actual rule count of
2635 * the ethtool flow classification command
2636 *
2637 * Returns 0 on success or -EMSGSIZE if entry not found
2638 **/
2639static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2640 struct ethtool_rxnfc *cmd,
2641 u32 *rule_locs)
2642{
2643 struct i40e_fdir_filter *rule;
2644 struct hlist_node *node2;
2645 int cnt = 0;
2646
2647 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002648 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002649
2650 hlist_for_each_entry_safe(rule, node2,
2651 &pf->fdir_filter_list, fdir_node) {
2652 if (cnt == cmd->rule_cnt)
2653 return -EMSGSIZE;
2654
2655 rule_locs[cnt] = rule->fd_id;
2656 cnt++;
2657 }
2658
2659 cmd->rule_cnt = cnt;
2660
2661 return 0;
2662}
2663
2664/**
2665 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2666 * @pf: Pointer to the physical function struct
2667 * @cmd: The command to get or set Rx flow classification rules
2668 *
2669 * This function looks up a filter based on the Rx flow classification
2670 * command and fills the flow spec info for it if found
2671 *
2672 * Returns 0 on success or -EINVAL if filter not found
2673 **/
2674static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2675 struct ethtool_rxnfc *cmd)
2676{
2677 struct ethtool_rx_flow_spec *fsp =
2678 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002679 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002680 struct i40e_fdir_filter *rule = NULL;
2681 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002682 u64 input_set;
2683 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002684
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002685 hlist_for_each_entry_safe(rule, node2,
2686 &pf->fdir_filter_list, fdir_node) {
2687 if (fsp->location <= rule->fd_id)
2688 break;
2689 }
2690
2691 if (!rule || fsp->location != rule->fd_id)
2692 return -EINVAL;
2693
2694 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002695 if (fsp->flow_type == IP_USER_FLOW) {
2696 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2697 fsp->h_u.usr_ip4_spec.proto = 0;
2698 fsp->m_u.usr_ip4_spec.proto = 0;
2699 }
2700
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002701 /* Reverse the src and dest notion, since the HW views them from
2702 * Tx perspective where as the user expects it from Rx filter view.
2703 */
2704 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2705 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002706 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2707 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002708
Jacob Keller36777d92017-03-07 15:05:23 -08002709 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002710 case SCTP_V4_FLOW:
2711 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2712 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002713 case TCP_V4_FLOW:
2714 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2715 break;
2716 case UDP_V4_FLOW:
2717 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2718 break;
2719 case IP_USER_FLOW:
2720 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2721 break;
2722 default:
2723 /* If we have stored a filter with a flow type not listed here
2724 * it is almost certainly a driver bug. WARN(), and then
2725 * assign the input_set as if all fields are enabled to avoid
2726 * reading unassigned memory.
2727 */
2728 WARN(1, "Missing input set index for flow_type %d\n",
2729 rule->flow_type);
2730 input_set = 0xFFFFFFFFFFFFFFFFULL;
2731 goto no_input_set;
2732 }
2733
2734 input_set = i40e_read_fd_input_set(pf, index);
2735
2736no_input_set:
2737 if (input_set & I40E_L3_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002738 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002739
2740 if (input_set & I40E_L3_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002741 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002742
2743 if (input_set & I40E_L4_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002744 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002745
2746 if (input_set & I40E_L4_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002747 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002748
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002749 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2750 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2751 else
2752 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002753
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002754 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2755 struct i40e_vsi *vsi;
2756
2757 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2758 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002759 /* VFs are zero-indexed by the driver, but ethtool
2760 * expects them to be one-indexed, so add one here
2761 */
2762 u64 ring_vf = vsi->vf_id + 1;
2763
2764 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2765 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002766 }
2767 }
2768
Jacob Keller0e588de2017-02-06 14:38:50 -08002769 if (rule->flex_filter) {
2770 userdef.flex_filter = true;
2771 userdef.flex_word = be16_to_cpu(rule->flex_word);
2772 userdef.flex_offset = rule->flex_offset;
2773 }
2774
Jacob Kellere7930952017-02-06 14:38:49 -08002775 i40e_fill_rx_flow_user_data(fsp, &userdef);
2776
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002777 return 0;
2778}
2779
2780/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002781 * i40e_get_rxnfc - command to get RX flow classification rules
2782 * @netdev: network interface device structure
2783 * @cmd: ethtool rxnfc command
Jacob Kellerf5254422018-04-20 01:41:33 -07002784 * @rule_locs: pointer to store rule data
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002785 *
2786 * Returns Success if the command is supported.
2787 **/
2788static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2789 u32 *rule_locs)
2790{
2791 struct i40e_netdev_priv *np = netdev_priv(netdev);
2792 struct i40e_vsi *vsi = np->vsi;
2793 struct i40e_pf *pf = vsi->back;
2794 int ret = -EOPNOTSUPP;
2795
2796 switch (cmd->cmd) {
2797 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002798 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002799 ret = 0;
2800 break;
2801 case ETHTOOL_GRXFH:
2802 ret = i40e_get_rss_hash_opts(pf, cmd);
2803 break;
2804 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002805 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002806 /* report total rule count */
2807 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002808 ret = 0;
2809 break;
2810 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002811 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002812 break;
2813 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002814 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2815 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002816 default:
2817 break;
2818 }
2819
2820 return ret;
2821}
2822
2823/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002824 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2825 * @nfc: pointer to user request
Jacob Kellerf5254422018-04-20 01:41:33 -07002826 * @i_setc: bits currently set
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002827 *
2828 * Returns value of bits to be set per user request
2829 **/
2830static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2831{
2832 u64 i_set = i_setc;
2833 u64 src_l3 = 0, dst_l3 = 0;
2834
2835 if (nfc->data & RXH_L4_B_0_1)
2836 i_set |= I40E_L4_SRC_MASK;
2837 else
2838 i_set &= ~I40E_L4_SRC_MASK;
2839 if (nfc->data & RXH_L4_B_2_3)
2840 i_set |= I40E_L4_DST_MASK;
2841 else
2842 i_set &= ~I40E_L4_DST_MASK;
2843
2844 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2845 src_l3 = I40E_L3_V6_SRC_MASK;
2846 dst_l3 = I40E_L3_V6_DST_MASK;
2847 } else if (nfc->flow_type == TCP_V4_FLOW ||
2848 nfc->flow_type == UDP_V4_FLOW) {
2849 src_l3 = I40E_L3_SRC_MASK;
2850 dst_l3 = I40E_L3_DST_MASK;
2851 } else {
2852 /* Any other flow type are not supported here */
2853 return i_set;
2854 }
2855
2856 if (nfc->data & RXH_IP_SRC)
2857 i_set |= src_l3;
2858 else
2859 i_set &= ~src_l3;
2860 if (nfc->data & RXH_IP_DST)
2861 i_set |= dst_l3;
2862 else
2863 i_set &= ~dst_l3;
2864
2865 return i_set;
2866}
2867
2868/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002869 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2870 * @pf: pointer to the physical function struct
Jacob Kellerf5254422018-04-20 01:41:33 -07002871 * @nfc: ethtool rxnfc command
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002872 *
2873 * Returns Success if the flow input set is supported.
2874 **/
2875static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2876{
2877 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002878 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2879 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002880 u8 flow_pctype = 0;
2881 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002882
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002883 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2884 dev_err(&pf->pdev->dev,
2885 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2886 return -EOPNOTSUPP;
2887 }
2888
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002889 /* RSS does not support anything other than hashing
2890 * to queues on src and dst IPs and ports
2891 */
2892 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2893 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2894 return -EINVAL;
2895
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002896 switch (nfc->flow_type) {
2897 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002898 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002899 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002900 hena |=
2901 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002902 break;
2903 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002904 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002905 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002906 hena |=
2907 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002908 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002909 hena |=
2910 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002911 break;
2912 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002913 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002914 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002915 hena |=
2916 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2917 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002918
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002919 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002920 break;
2921 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002922 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002923 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002924 hena |=
2925 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2926 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002927
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002928 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002929 break;
2930 case AH_ESP_V4_FLOW:
2931 case AH_V4_FLOW:
2932 case ESP_V4_FLOW:
2933 case SCTP_V4_FLOW:
2934 if ((nfc->data & RXH_L4_B_0_1) ||
2935 (nfc->data & RXH_L4_B_2_3))
2936 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002937 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002938 break;
2939 case AH_ESP_V6_FLOW:
2940 case AH_V6_FLOW:
2941 case ESP_V6_FLOW:
2942 case SCTP_V6_FLOW:
2943 if ((nfc->data & RXH_L4_B_0_1) ||
2944 (nfc->data & RXH_L4_B_2_3))
2945 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002946 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002947 break;
2948 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002949 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2950 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002951 break;
2952 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002953 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2954 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002955 break;
2956 default:
2957 return -EINVAL;
2958 }
2959
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002960 if (flow_pctype) {
2961 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2962 flow_pctype)) |
2963 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2964 flow_pctype)) << 32);
2965 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2966 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2967 (u32)i_set);
2968 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2969 (u32)(i_set >> 32));
2970 hena |= BIT_ULL(flow_pctype);
2971 }
2972
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002973 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2974 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002975 i40e_flush(hw);
2976
2977 return 0;
2978}
2979
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002980/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002981 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2982 * @vsi: Pointer to the targeted VSI
2983 * @input: The filter to update or NULL to indicate deletion
2984 * @sw_idx: Software index to the filter
2985 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002986 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002987 * This function updates (or deletes) a Flow Director entry from
2988 * the hlist of the corresponding PF
2989 *
2990 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002991 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002992static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2993 struct i40e_fdir_filter *input,
2994 u16 sw_idx,
2995 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002996{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002997 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002998 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002999 struct hlist_node *node2;
3000 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003001
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003002 parent = NULL;
3003 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003004
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003005 hlist_for_each_entry_safe(rule, node2,
3006 &pf->fdir_filter_list, fdir_node) {
3007 /* hash found, or no matching entry */
3008 if (rule->fd_id >= sw_idx)
3009 break;
3010 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003011 }
3012
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003013 /* if there is an old rule occupying our place remove it */
3014 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08003015 /* Remove this rule, since we're either deleting it, or
3016 * replacing it.
3017 */
3018 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003019 hlist_del(&rule->fdir_node);
3020 kfree(rule);
3021 pf->fdir_pf_active_filters--;
3022 }
3023
Jacob Kellerc6da5252017-02-06 14:39:13 -08003024 /* If we weren't given an input, this is a delete, so just return the
3025 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003026 */
3027 if (!input)
3028 return err;
3029
Jacob Kellerc6da5252017-02-06 14:39:13 -08003030 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003031 INIT_HLIST_NODE(&input->fdir_node);
3032
3033 /* add filter to the list */
3034 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003035 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003036 else
3037 hlist_add_head(&input->fdir_node,
3038 &pf->fdir_filter_list);
3039
3040 /* update counts */
3041 pf->fdir_pf_active_filters++;
3042
3043 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003044}
3045
3046/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003047 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3048 * @pf: pointer to PF structure
3049 *
3050 * This function searches the list of filters and determines which FLX_PIT
3051 * entries are still required. It will prune any entries which are no longer
3052 * in use after the deletion.
3053 **/
3054static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3055{
3056 struct i40e_flex_pit *entry, *tmp;
3057 struct i40e_fdir_filter *rule;
3058
3059 /* First, we'll check the l3 table */
3060 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3061 bool found = false;
3062
3063 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3064 if (rule->flow_type != IP_USER_FLOW)
3065 continue;
3066 if (rule->flex_filter &&
3067 rule->flex_offset == entry->src_offset) {
3068 found = true;
3069 break;
3070 }
3071 }
3072
3073 /* If we didn't find the filter, then we can prune this entry
3074 * from the list.
3075 */
3076 if (!found) {
3077 list_del(&entry->list);
3078 kfree(entry);
3079 }
3080 }
3081
3082 /* Followed by the L4 table */
3083 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3084 bool found = false;
3085
3086 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3087 /* Skip this filter if it's L3, since we already
3088 * checked those in the above loop
3089 */
3090 if (rule->flow_type == IP_USER_FLOW)
3091 continue;
3092 if (rule->flex_filter &&
3093 rule->flex_offset == entry->src_offset) {
3094 found = true;
3095 break;
3096 }
3097 }
3098
3099 /* If we didn't find the filter, then we can prune this entry
3100 * from the list.
3101 */
3102 if (!found) {
3103 list_del(&entry->list);
3104 kfree(entry);
3105 }
3106 }
3107}
3108
3109/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003110 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3111 * @vsi: Pointer to the targeted VSI
3112 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003113 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003114 * The function removes a Flow Director filter entry from the
3115 * hlist of the corresponding PF
3116 *
3117 * Returns 0 on success
3118 */
3119static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3120 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003121{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003122 struct ethtool_rx_flow_spec *fsp =
3123 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003124 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003125 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003126
Jacob Keller0da36b92017-04-19 09:25:55 -04003127 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3128 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003129 return -EBUSY;
3130
Jacob Keller0da36b92017-04-19 09:25:55 -04003131 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003132 return -EBUSY;
3133
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003134 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003135
Jacob Keller0e588de2017-02-06 14:38:50 -08003136 i40e_prune_flex_pit_list(pf);
3137
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003138 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003139 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003140}
3141
3142/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003143 * i40e_unused_pit_index - Find an unused PIT index for given list
3144 * @pf: the PF data structure
3145 *
3146 * Find the first unused flexible PIT index entry. We search both the L3 and
3147 * L4 flexible PIT lists so that the returned index is unique and unused by
3148 * either currently programmed L3 or L4 filters. We use a bit field as storage
3149 * to track which indexes are already used.
3150 **/
3151static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3152{
3153 unsigned long available_index = 0xFF;
3154 struct i40e_flex_pit *entry;
3155
3156 /* We need to make sure that the new index isn't in use by either L3
3157 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3158 * L4 to use the same index.
3159 */
3160
3161 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3162 clear_bit(entry->pit_index, &available_index);
3163
3164 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3165 clear_bit(entry->pit_index, &available_index);
3166
3167 return find_first_bit(&available_index, 8);
3168}
3169
3170/**
3171 * i40e_find_flex_offset - Find an existing flex src_offset
3172 * @flex_pit_list: L3 or L4 flex PIT list
3173 * @src_offset: new src_offset to find
3174 *
3175 * Searches the flex_pit_list for an existing offset. If no offset is
3176 * currently programmed, then this will return an ERR_PTR if there is no space
3177 * to add a new offset, otherwise it returns NULL.
3178 **/
3179static
3180struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3181 u16 src_offset)
3182{
3183 struct i40e_flex_pit *entry;
3184 int size = 0;
3185
3186 /* Search for the src_offset first. If we find a matching entry
3187 * already programmed, we can simply re-use it.
3188 */
3189 list_for_each_entry(entry, flex_pit_list, list) {
3190 size++;
3191 if (entry->src_offset == src_offset)
3192 return entry;
3193 }
3194
3195 /* If we haven't found an entry yet, then the provided src offset has
3196 * not yet been programmed. We will program the src offset later on,
3197 * but we need to indicate whether there is enough space to do so
3198 * here. We'll make use of ERR_PTR for this purpose.
3199 */
3200 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3201 return ERR_PTR(-ENOSPC);
3202
3203 return NULL;
3204}
3205
3206/**
3207 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3208 * @flex_pit_list: L3 or L4 flex PIT list
3209 * @src_offset: new src_offset to add
3210 * @pit_index: the PIT index to program
3211 *
3212 * This function programs the new src_offset to the list. It is expected that
3213 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3214 * that this offset is not programmed, and that the list has enough space to
3215 * store another offset.
3216 *
3217 * Returns 0 on success, and negative value on error.
3218 **/
3219static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3220 u16 src_offset,
3221 u8 pit_index)
3222{
3223 struct i40e_flex_pit *new_pit, *entry;
3224
3225 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3226 if (!new_pit)
3227 return -ENOMEM;
3228
3229 new_pit->src_offset = src_offset;
3230 new_pit->pit_index = pit_index;
3231
3232 /* We need to insert this item such that the list is sorted by
3233 * src_offset in ascending order.
3234 */
3235 list_for_each_entry(entry, flex_pit_list, list) {
3236 if (new_pit->src_offset < entry->src_offset) {
3237 list_add_tail(&new_pit->list, &entry->list);
3238 return 0;
3239 }
3240
3241 /* If we found an entry with our offset already programmed we
3242 * can simply return here, after freeing the memory. However,
3243 * if the pit_index does not match we need to report an error.
3244 */
3245 if (new_pit->src_offset == entry->src_offset) {
3246 int err = 0;
3247
3248 /* If the PIT index is not the same we can't re-use
3249 * the entry, so we must report an error.
3250 */
3251 if (new_pit->pit_index != entry->pit_index)
3252 err = -EINVAL;
3253
3254 kfree(new_pit);
3255 return err;
3256 }
3257 }
3258
3259 /* If we reached here, then we haven't yet added the item. This means
3260 * that we should add the item at the end of the list.
3261 */
3262 list_add_tail(&new_pit->list, flex_pit_list);
3263 return 0;
3264}
3265
3266/**
3267 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3268 * @pf: Pointer to the PF structure
3269 * @flex_pit_list: list of flexible src offsets in use
Jacob Kellerf5254422018-04-20 01:41:33 -07003270 * @flex_pit_start: index to first entry for this section of the table
Jacob Keller0e588de2017-02-06 14:38:50 -08003271 *
3272 * In order to handle flexible data, the hardware uses a table of values
3273 * called the FLX_PIT table. This table is used to indicate which sections of
3274 * the input correspond to what PIT index values. Unfortunately, hardware is
3275 * very restrictive about programming this table. Entries must be ordered by
3276 * src_offset in ascending order, without duplicates. Additionally, unused
3277 * entries must be set to the unused index value, and must have valid size and
3278 * length according to the src_offset ordering.
3279 *
3280 * This function will reprogram the FLX_PIT register from a book-keeping
3281 * structure that we guarantee is already ordered correctly, and has no more
3282 * than 3 entries.
3283 *
3284 * To make things easier, we only support flexible values of one word length,
3285 * rather than allowing variable length flexible values.
3286 **/
3287static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3288 struct list_head *flex_pit_list,
3289 int flex_pit_start)
3290{
3291 struct i40e_flex_pit *entry = NULL;
3292 u16 last_offset = 0;
3293 int i = 0, j = 0;
3294
3295 /* First, loop over the list of flex PIT entries, and reprogram the
3296 * registers.
3297 */
3298 list_for_each_entry(entry, flex_pit_list, list) {
3299 /* We have to be careful when programming values for the
3300 * largest SRC_OFFSET value. It is possible that adding
3301 * additional empty values at the end would overflow the space
3302 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3303 * we check here and add the empty values prior to adding the
3304 * largest value.
3305 *
3306 * To determine this, we will use a loop from i+1 to 3, which
3307 * will determine whether the unused entries would have valid
3308 * SRC_OFFSET. Note that there cannot be extra entries past
3309 * this value, because the only valid values would have been
3310 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3311 * have been added to the list in the first place.
3312 */
3313 for (j = i + 1; j < 3; j++) {
3314 u16 offset = entry->src_offset + j;
3315 int index = flex_pit_start + i;
3316 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3317 1,
3318 offset - 3);
3319
3320 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3321 i40e_write_rx_ctl(&pf->hw,
3322 I40E_PRTQF_FLX_PIT(index),
3323 value);
3324 i++;
3325 }
3326 }
3327
3328 /* Now, we can program the actual value into the table */
3329 i40e_write_rx_ctl(&pf->hw,
3330 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3331 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3332 1,
3333 entry->src_offset));
3334 i++;
3335 }
3336
3337 /* In order to program the last entries in the table, we need to
3338 * determine the valid offset. If the list is empty, we'll just start
3339 * with 0. Otherwise, we'll start with the last item offset and add 1.
3340 * This ensures that all entries have valid sizes. If we don't do this
3341 * correctly, the hardware will disable flexible field parsing.
3342 */
3343 if (!list_empty(flex_pit_list))
3344 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3345
3346 for (; i < 3; i++, last_offset++) {
3347 i40e_write_rx_ctl(&pf->hw,
3348 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3349 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3350 1,
3351 last_offset));
3352 }
3353}
3354
3355/**
3356 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3357 * @pf: pointer to the PF structure
3358 *
3359 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3360 * internal helper function for implementation details.
3361 **/
3362static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3363{
3364 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3365 I40E_FLEX_PIT_IDX_START_L3);
3366
3367 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3368 I40E_FLEX_PIT_IDX_START_L4);
3369
3370 /* We also need to program the L3 and L4 GLQF ORT register */
3371 i40e_write_rx_ctl(&pf->hw,
3372 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3373 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3374 3, 1));
3375
3376 i40e_write_rx_ctl(&pf->hw,
3377 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3378 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3379 3, 1));
3380}
3381
3382/**
Jacob Keller9229e992017-02-06 14:38:47 -08003383 * i40e_flow_str - Converts a flow_type into a human readable string
Jacob Kellerf5254422018-04-20 01:41:33 -07003384 * @fsp: the flow specification
Jacob Keller9229e992017-02-06 14:38:47 -08003385 *
3386 * Currently only flow types we support are included here, and the string
3387 * value attempts to match what ethtool would use to configure this flow type.
3388 **/
3389static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3390{
3391 switch (fsp->flow_type & ~FLOW_EXT) {
3392 case TCP_V4_FLOW:
3393 return "tcp4";
3394 case UDP_V4_FLOW:
3395 return "udp4";
3396 case SCTP_V4_FLOW:
3397 return "sctp4";
3398 case IP_USER_FLOW:
3399 return "ip4";
3400 default:
3401 return "unknown";
3402 }
3403}
3404
3405/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003406 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3407 * @pit_index: PIT index to convert
3408 *
3409 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3410 * of range.
3411 **/
3412static u64 i40e_pit_index_to_mask(int pit_index)
3413{
3414 switch (pit_index) {
3415 case 0:
3416 return I40E_FLEX_50_MASK;
3417 case 1:
3418 return I40E_FLEX_51_MASK;
3419 case 2:
3420 return I40E_FLEX_52_MASK;
3421 case 3:
3422 return I40E_FLEX_53_MASK;
3423 case 4:
3424 return I40E_FLEX_54_MASK;
3425 case 5:
3426 return I40E_FLEX_55_MASK;
3427 case 6:
3428 return I40E_FLEX_56_MASK;
3429 case 7:
3430 return I40E_FLEX_57_MASK;
3431 default:
3432 return 0;
3433 }
3434}
3435
3436/**
Jacob Keller9229e992017-02-06 14:38:47 -08003437 * i40e_print_input_set - Show changes between two input sets
3438 * @vsi: the vsi being configured
3439 * @old: the old input set
3440 * @new: the new input set
3441 *
3442 * Print the difference between old and new input sets by showing which series
3443 * of words are toggled on or off. Only displays the bits we actually support
3444 * changing.
3445 **/
3446static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3447{
3448 struct i40e_pf *pf = vsi->back;
3449 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003450 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003451
3452 old_value = !!(old & I40E_L3_SRC_MASK);
3453 new_value = !!(new & I40E_L3_SRC_MASK);
3454 if (old_value != new_value)
3455 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3456 old_value ? "ON" : "OFF",
3457 new_value ? "ON" : "OFF");
3458
3459 old_value = !!(old & I40E_L3_DST_MASK);
3460 new_value = !!(new & I40E_L3_DST_MASK);
3461 if (old_value != new_value)
3462 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3463 old_value ? "ON" : "OFF",
3464 new_value ? "ON" : "OFF");
3465
3466 old_value = !!(old & I40E_L4_SRC_MASK);
3467 new_value = !!(new & I40E_L4_SRC_MASK);
3468 if (old_value != new_value)
3469 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3470 old_value ? "ON" : "OFF",
3471 new_value ? "ON" : "OFF");
3472
3473 old_value = !!(old & I40E_L4_DST_MASK);
3474 new_value = !!(new & I40E_L4_DST_MASK);
3475 if (old_value != new_value)
3476 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3477 old_value ? "ON" : "OFF",
3478 new_value ? "ON" : "OFF");
3479
3480 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3481 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3482 if (old_value != new_value)
3483 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3484 old_value ? "ON" : "OFF",
3485 new_value ? "ON" : "OFF");
3486
Jacob Keller0e588de2017-02-06 14:38:50 -08003487 /* Show change of flexible filter entries */
3488 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3489 u64 flex_mask = i40e_pit_index_to_mask(i);
3490
3491 old_value = !!(old & flex_mask);
3492 new_value = !!(new & flex_mask);
3493 if (old_value != new_value)
3494 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3495 i,
3496 old_value ? "ON" : "OFF",
3497 new_value ? "ON" : "OFF");
3498 }
3499
Jacob Keller9229e992017-02-06 14:38:47 -08003500 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3501 old);
3502 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3503 new);
3504}
3505
3506/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003507 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003508 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003509 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003510 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003511 *
Jacob Keller9229e992017-02-06 14:38:47 -08003512 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3513 * for partial matches exists with a few limitations. First, hardware only
3514 * supports masking by word boundary (2 bytes) and not per individual bit.
3515 * Second, hardware is limited to using one mask for a flow type and cannot
3516 * use a separate mask for each filter.
3517 *
3518 * To support these limitations, if we already have a configured filter for
3519 * the specified type, this function enforces that new filters of the type
3520 * match the configured input set. Otherwise, if we do not have a filter of
3521 * the specified type, we allow the input set to be updated to match the
3522 * desired filter.
3523 *
3524 * To help ensure that administrators understand why filters weren't displayed
3525 * as supported, we print a diagnostic message displaying how the input set
3526 * would change and warning to delete the preexisting filters if required.
3527 *
3528 * Returns 0 on successful input set match, and a negative return code on
3529 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003530 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003531static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003532 struct ethtool_rx_flow_spec *fsp,
3533 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003534{
Jacob Keller36777d92017-03-07 15:05:23 -08003535 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003536 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3537 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003538 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003539 bool new_flex_offset = false;
3540 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003541 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003542 u16 index, src_offset = 0;
3543 u8 pit_index = 0;
3544 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003545
3546 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003547 case SCTP_V4_FLOW:
3548 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3549 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3550 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003551 case TCP_V4_FLOW:
3552 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003553 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003554 break;
3555 case UDP_V4_FLOW:
3556 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003557 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003558 break;
3559 case IP_USER_FLOW:
3560 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003561 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003562 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003563 break;
3564 default:
3565 return -EOPNOTSUPP;
3566 }
3567
3568 /* Read the current input set from register memory. */
3569 current_mask = i40e_read_fd_input_set(pf, index);
3570 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003571
Jacob Keller9229e992017-02-06 14:38:47 -08003572 /* Determine, if any, the required changes to the input set in order
3573 * to support the provided mask.
3574 *
3575 * Hardware only supports masking at word (2 byte) granularity and does
3576 * not support full bitwise masking. This implementation simplifies
3577 * even further and only supports fully enabled or fully disabled
3578 * masks for each field, even though we could split the ip4src and
3579 * ip4dst fields.
3580 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003581 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003582 case SCTP_V4_FLOW:
3583 new_mask &= ~I40E_VERIFY_TAG_MASK;
3584 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003585 case TCP_V4_FLOW:
3586 case UDP_V4_FLOW:
3587 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3588
3589 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003590 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3591 new_mask |= I40E_L3_SRC_MASK;
3592 else if (!tcp_ip4_spec->ip4src)
3593 new_mask &= ~I40E_L3_SRC_MASK;
3594 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003595 return -EOPNOTSUPP;
3596
3597 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003598 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3599 new_mask |= I40E_L3_DST_MASK;
3600 else if (!tcp_ip4_spec->ip4dst)
3601 new_mask &= ~I40E_L3_DST_MASK;
3602 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003603 return -EOPNOTSUPP;
3604
3605 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003606 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3607 new_mask |= I40E_L4_SRC_MASK;
3608 else if (!tcp_ip4_spec->psrc)
3609 new_mask &= ~I40E_L4_SRC_MASK;
3610 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003611 return -EOPNOTSUPP;
3612
3613 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003614 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3615 new_mask |= I40E_L4_DST_MASK;
3616 else if (!tcp_ip4_spec->pdst)
3617 new_mask &= ~I40E_L4_DST_MASK;
3618 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003619 return -EOPNOTSUPP;
3620
3621 /* Filtering on Type of Service is not supported. */
3622 if (tcp_ip4_spec->tos)
3623 return -EOPNOTSUPP;
3624
3625 break;
3626 case IP_USER_FLOW:
3627 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3628
3629 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003630 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3631 new_mask |= I40E_L3_SRC_MASK;
3632 else if (!usr_ip4_spec->ip4src)
3633 new_mask &= ~I40E_L3_SRC_MASK;
3634 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003635 return -EOPNOTSUPP;
3636
3637 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003638 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3639 new_mask |= I40E_L3_DST_MASK;
3640 else if (!usr_ip4_spec->ip4dst)
3641 new_mask &= ~I40E_L3_DST_MASK;
3642 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003643 return -EOPNOTSUPP;
3644
3645 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003646 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3647 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3648 else if (!usr_ip4_spec->l4_4_bytes)
3649 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3650 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003651 return -EOPNOTSUPP;
3652
3653 /* Filtering on Type of Service is not supported. */
3654 if (usr_ip4_spec->tos)
3655 return -EOPNOTSUPP;
3656
Jacob Keller0e588de2017-02-06 14:38:50 -08003657 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003658 if (usr_ip4_spec->ip_ver)
3659 return -EINVAL;
3660
Jacob Keller0e588de2017-02-06 14:38:50 -08003661 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003662 if (usr_ip4_spec->proto)
3663 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003664
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003665 break;
3666 default:
3667 return -EOPNOTSUPP;
3668 }
3669
Jacob Keller0e588de2017-02-06 14:38:50 -08003670 /* First, clear all flexible filter entries */
3671 new_mask &= ~I40E_FLEX_INPUT_MASK;
3672
3673 /* If we have a flexible filter, try to add this offset to the correct
3674 * flexible filter PIT list. Once finished, we can update the mask.
3675 * If the src_offset changed, we will get a new mask value which will
3676 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003677 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003678 if (userdef->flex_filter) {
3679 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3680
3681 /* Flexible offset must be even, since the flexible payload
3682 * must be aligned on 2-byte boundary.
3683 */
3684 if (userdef->flex_offset & 0x1) {
3685 dev_warn(&pf->pdev->dev,
3686 "Flexible data offset must be 2-byte aligned\n");
3687 return -EINVAL;
3688 }
3689
3690 src_offset = userdef->flex_offset >> 1;
3691
3692 /* FLX_PIT source offset value is only so large */
3693 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3694 dev_warn(&pf->pdev->dev,
3695 "Flexible data must reside within first 64 bytes of the packet payload\n");
3696 return -EINVAL;
3697 }
3698
3699 /* See if this offset has already been programmed. If we get
3700 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3701 * if we get a NULL pointer, this means we will need to add
3702 * the offset.
3703 */
3704 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3705 src_offset);
3706 if (IS_ERR(flex_pit))
3707 return PTR_ERR(flex_pit);
3708
3709 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3710 * packet types, and thus we need to program both L3 and L4
3711 * flexible values. These must have identical flexible index,
3712 * as otherwise we can't correctly program the input set. So
3713 * we'll find both an L3 and L4 index and make sure they are
3714 * the same.
3715 */
3716 if (flex_l3) {
3717 l3_flex_pit =
3718 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3719 src_offset);
3720 if (IS_ERR(l3_flex_pit))
3721 return PTR_ERR(l3_flex_pit);
3722
3723 if (flex_pit) {
3724 /* If we already had a matching L4 entry, we
3725 * need to make sure that the L3 entry we
3726 * obtained uses the same index.
3727 */
3728 if (l3_flex_pit) {
3729 if (l3_flex_pit->pit_index !=
3730 flex_pit->pit_index) {
3731 return -EINVAL;
3732 }
3733 } else {
3734 new_flex_offset = true;
3735 }
3736 } else {
3737 flex_pit = l3_flex_pit;
3738 }
3739 }
3740
3741 /* If we didn't find an existing flex offset, we need to
3742 * program a new one. However, we don't immediately program it
3743 * here because we will wait to program until after we check
3744 * that it is safe to change the input set.
3745 */
3746 if (!flex_pit) {
3747 new_flex_offset = true;
3748 pit_index = i40e_unused_pit_index(pf);
3749 } else {
3750 pit_index = flex_pit->pit_index;
3751 }
3752
3753 /* Update the mask with the new offset */
3754 new_mask |= i40e_pit_index_to_mask(pit_index);
3755 }
3756
3757 /* If the mask and flexible filter offsets for this filter match the
3758 * currently programmed values we don't need any input set change, so
3759 * this filter is safe to install.
3760 */
3761 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003762 return 0;
3763
3764 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3765 i40e_flow_str(fsp));
3766 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003767 if (new_flex_offset) {
3768 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3769 pit_index, src_offset);
3770 }
Jacob Keller9229e992017-02-06 14:38:47 -08003771
3772 /* Hardware input sets are global across multiple ports, so even the
3773 * main port cannot change them when in MFP mode as this would impact
3774 * any filters on the other ports.
3775 */
3776 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3777 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003778 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003779 }
3780
3781 /* This filter requires us to update the input set. However, hardware
3782 * only supports one input set per flow type, and does not support
3783 * separate masks for each filter. This means that we can only support
3784 * a single mask for all filters of a specific type.
3785 *
3786 * If we have preexisting filters, they obviously depend on the
3787 * current programmed input set. Display a diagnostic message in this
3788 * case explaining why the filter could not be accepted.
3789 */
3790 if (*fdir_filter_count) {
3791 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3792 i40e_flow_str(fsp),
3793 *fdir_filter_count);
3794 return -EOPNOTSUPP;
3795 }
3796
3797 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003798
Jacob Keller02b40162017-12-27 08:24:12 -05003799 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
3800 * frames. If we're programming the input set for IPv4/Other, we also
3801 * need to program the IPv4/Fragmented input set. Since we don't have
3802 * separate support, we'll always assume and enforce that the two flow
3803 * types must have matching input sets.
3804 */
3805 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
3806 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
3807 new_mask);
3808
Jacob Keller0e588de2017-02-06 14:38:50 -08003809 /* Add the new offset and update table, if necessary */
3810 if (new_flex_offset) {
3811 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3812 pit_index);
3813 if (err)
3814 return err;
3815
3816 if (flex_l3) {
3817 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3818 src_offset,
3819 pit_index);
3820 if (err)
3821 return err;
3822 }
3823
3824 i40e_reprogram_flex_pit(pf);
3825 }
3826
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003827 return 0;
3828}
3829
3830/**
Jacob Keller443ee712017-12-27 08:25:32 -05003831 * i40e_match_fdir_filter - Return true of two filters match
3832 * @a: pointer to filter struct
3833 * @b: pointer to filter struct
3834 *
3835 * Returns true if the two filters match exactly the same criteria. I.e. they
3836 * match the same flow type and have the same parameters. We don't need to
3837 * check any input-set since all filters of the same flow type must use the
3838 * same input set.
3839 **/
3840static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
3841 struct i40e_fdir_filter *b)
3842{
3843 /* The filters do not much if any of these criteria differ. */
3844 if (a->dst_ip != b->dst_ip ||
3845 a->src_ip != b->src_ip ||
3846 a->dst_port != b->dst_port ||
3847 a->src_port != b->src_port ||
3848 a->flow_type != b->flow_type ||
3849 a->ip4_proto != b->ip4_proto)
3850 return false;
3851
3852 return true;
3853}
3854
3855/**
3856 * i40e_disallow_matching_filters - Check that new filters differ
3857 * @vsi: pointer to the targeted VSI
3858 * @input: new filter to check
3859 *
3860 * Due to hardware limitations, it is not possible for two filters that match
3861 * similar criteria to be programmed at the same time. This is true for a few
3862 * reasons:
3863 *
3864 * (a) all filters matching a particular flow type must use the same input
3865 * set, that is they must match the same criteria.
3866 * (b) different flow types will never match the same packet, as the flow type
3867 * is decided by hardware before checking which rules apply.
3868 * (c) hardware has no way to distinguish which order filters apply in.
3869 *
3870 * Due to this, we can't really support using the location data to order
3871 * filters in the hardware parsing. It is technically possible for the user to
3872 * request two filters matching the same criteria but which select different
3873 * queues. In this case, rather than keep both filters in the list, we reject
3874 * the 2nd filter when the user requests adding it.
3875 *
3876 * This avoids needing to track location for programming the filter to
3877 * hardware, and ensures that we avoid some strange scenarios involving
3878 * deleting filters which match the same criteria.
3879 **/
3880static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
3881 struct i40e_fdir_filter *input)
3882{
3883 struct i40e_pf *pf = vsi->back;
3884 struct i40e_fdir_filter *rule;
3885 struct hlist_node *node2;
3886
3887 /* Loop through every filter, and check that it doesn't match */
3888 hlist_for_each_entry_safe(rule, node2,
3889 &pf->fdir_filter_list, fdir_node) {
3890 /* Don't check the filters match if they share the same fd_id,
3891 * since the new filter is actually just updating the target
3892 * of the old filter.
3893 */
3894 if (rule->fd_id == input->fd_id)
3895 continue;
3896
3897 /* If any filters match, then print a warning message to the
3898 * kernel message buffer and bail out.
3899 */
3900 if (i40e_match_fdir_filter(rule, input)) {
3901 dev_warn(&pf->pdev->dev,
3902 "Existing user defined filter %d already matches this flow.\n",
3903 rule->fd_id);
3904 return -EINVAL;
3905 }
3906 }
3907
3908 return 0;
3909}
3910
3911/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003912 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003913 * @vsi: pointer to the targeted VSI
3914 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003915 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003916 * Add Flow Director filters for a specific flow spec based on their
3917 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003918 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003919static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3920 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003921{
Jacob Kellere7930952017-02-06 14:38:49 -08003922 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003923 struct ethtool_rx_flow_spec *fsp;
3924 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003925 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003926 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003927 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003928 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003929
3930 if (!vsi)
3931 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003932 pf = vsi->back;
3933
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003934 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3935 return -EOPNOTSUPP;
3936
Jacob Keller134201a2018-03-16 01:26:32 -07003937 if (test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003938 return -ENOSPC;
3939
Jacob Keller0da36b92017-04-19 09:25:55 -04003940 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3941 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003942 return -EBUSY;
3943
Jacob Keller0da36b92017-04-19 09:25:55 -04003944 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003945 return -EBUSY;
3946
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003947 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3948
Jacob Kellere7930952017-02-06 14:38:49 -08003949 /* Parse the user-defined field */
3950 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3951 return -EINVAL;
3952
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003953 /* Extended MAC field is not supported */
3954 if (fsp->flow_type & FLOW_MAC_EXT)
3955 return -EINVAL;
3956
Jacob Keller0e588de2017-02-06 14:38:50 -08003957 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003958 if (ret)
3959 return ret;
3960
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003961 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3962 pf->hw.func_caps.fd_filters_guaranteed)) {
3963 return -EINVAL;
3964 }
3965
Jacob Keller43b15692017-02-06 14:38:48 -08003966 /* ring_cookie is either the drop index, or is a mask of the queue
3967 * index and VF id we wish to target.
3968 */
3969 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3970 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3971 } else {
3972 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3973 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3974
3975 if (!vf) {
3976 if (ring >= vsi->num_queue_pairs)
3977 return -EINVAL;
3978 dest_vsi = vsi->id;
3979 } else {
3980 /* VFs are zero-indexed, so we subtract one here */
3981 vf--;
3982
3983 if (vf >= pf->num_alloc_vfs)
3984 return -EINVAL;
3985 if (ring >= pf->vf[vf].num_queue_pairs)
3986 return -EINVAL;
3987 dest_vsi = pf->vf[vf].lan_vsi_id;
3988 }
3989 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3990 q_index = ring;
3991 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003992
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003993 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003994
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003995 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003996 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003997
3998 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003999 input->q_index = q_index;
4000 input->dest_vsi = dest_vsi;
4001 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004002 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04004003 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08004004 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4005 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08004006 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004007 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00004008
4009 /* Reverse the src and dest notion, since the HW expects them to be from
4010 * Tx perspective where as the input from user is from Rx filter view.
4011 */
4012 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4013 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08004014 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4015 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004016
Jacob Keller0e588de2017-02-06 14:38:50 -08004017 if (userdef.flex_filter) {
4018 input->flex_filter = true;
4019 input->flex_word = cpu_to_be16(userdef.flex_word);
4020 input->flex_offset = userdef.flex_offset;
4021 }
4022
Jacob Keller443ee712017-12-27 08:25:32 -05004023 /* Avoid programming two filters with identical match criteria. */
4024 ret = i40e_disallow_matching_filters(vsi, input);
4025 if (ret)
4026 goto free_filter_memory;
4027
Jacob Keller01016da2017-02-06 14:38:40 -08004028 /* Add the input filter to the fdir_input_list, possibly replacing
4029 * a previous filter. Do not free the input structure after adding it
4030 * to the list as this would cause a use-after-free bug.
4031 */
4032 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Patryk Małekca6e1d02017-12-27 07:32:31 -05004033 ret = i40e_add_del_fdir(vsi, input, true);
4034 if (ret)
4035 goto remove_sw_rule;
Jacob Keller01016da2017-02-06 14:38:40 -08004036 return 0;
4037
Patryk Małekca6e1d02017-12-27 07:32:31 -05004038remove_sw_rule:
4039 hlist_del(&input->fdir_node);
4040 pf->fdir_pf_active_filters--;
Jacob Keller443ee712017-12-27 08:25:32 -05004041free_filter_memory:
Jacob Keller01016da2017-02-06 14:38:40 -08004042 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004043 return ret;
4044}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08004045
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004046/**
4047 * i40e_set_rxnfc - command to set RX flow classification rules
4048 * @netdev: network interface device structure
4049 * @cmd: ethtool rxnfc command
4050 *
4051 * Returns Success if the command is supported.
4052 **/
4053static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4054{
4055 struct i40e_netdev_priv *np = netdev_priv(netdev);
4056 struct i40e_vsi *vsi = np->vsi;
4057 struct i40e_pf *pf = vsi->back;
4058 int ret = -EOPNOTSUPP;
4059
4060 switch (cmd->cmd) {
4061 case ETHTOOL_SRXFH:
4062 ret = i40e_set_rss_hash_opt(pf, cmd);
4063 break;
4064 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00004065 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004066 break;
4067 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004068 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004069 break;
4070 default:
4071 break;
4072 }
4073
4074 return ret;
4075}
4076
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004077/**
4078 * i40e_max_channels - get Max number of combined channels supported
4079 * @vsi: vsi pointer
4080 **/
4081static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4082{
4083 /* TODO: This code assumes DCB and FD is disabled for now. */
4084 return vsi->alloc_queue_pairs;
4085}
4086
4087/**
4088 * i40e_get_channels - Get the current channels enabled and max supported etc.
Jacob Kellerf5254422018-04-20 01:41:33 -07004089 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004090 * @ch: ethtool channels structure
4091 *
4092 * We don't support separate tx and rx queues as channels. The other count
4093 * represents how many queues are being used for control. max_combined counts
4094 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4095 * q_vectors since we support a lot more queue pairs than q_vectors.
4096 **/
4097static void i40e_get_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004098 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004099{
4100 struct i40e_netdev_priv *np = netdev_priv(dev);
4101 struct i40e_vsi *vsi = np->vsi;
4102 struct i40e_pf *pf = vsi->back;
4103
4104 /* report maximum channels */
4105 ch->max_combined = i40e_max_channels(vsi);
4106
4107 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004108 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004109 ch->max_other = ch->other_count;
4110
4111 /* Note: This code assumes DCB is disabled for now. */
4112 ch->combined_count = vsi->num_queue_pairs;
4113}
4114
4115/**
4116 * i40e_set_channels - Set the new channels count.
Jacob Kellerf5254422018-04-20 01:41:33 -07004117 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004118 * @ch: ethtool channels structure
4119 *
4120 * The new channels count may not be the same as requested by the user
4121 * since it gets rounded down to a power of 2 value.
4122 **/
4123static int i40e_set_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004124 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004125{
Jacob Keller59826d92016-07-27 12:02:35 -07004126 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004127 struct i40e_netdev_priv *np = netdev_priv(dev);
4128 unsigned int count = ch->combined_count;
4129 struct i40e_vsi *vsi = np->vsi;
4130 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004131 struct i40e_fdir_filter *rule;
4132 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004133 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004134 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004135
4136 /* We do not support setting channels for any other VSI at present */
4137 if (vsi->type != I40E_VSI_MAIN)
4138 return -EINVAL;
4139
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004140 /* We do not support setting channels via ethtool when TCs are
4141 * configured through mqprio
4142 */
4143 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4144 return -EINVAL;
4145
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004146 /* verify they are not requesting separate vectors */
4147 if (!count || ch->rx_count || ch->tx_count)
4148 return -EINVAL;
4149
4150 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004151 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004152 return -EINVAL;
4153
4154 /* verify the number of channels does not exceed hardware limits */
4155 if (count > i40e_max_channels(vsi))
4156 return -EINVAL;
4157
Jacob Keller59826d92016-07-27 12:02:35 -07004158 /* verify that the number of channels does not invalidate any current
4159 * flow director rules
4160 */
4161 hlist_for_each_entry_safe(rule, node2,
4162 &pf->fdir_filter_list, fdir_node) {
4163 if (rule->dest_ctl != drop && count <= rule->q_index) {
4164 dev_warn(&pf->pdev->dev,
4165 "Existing user defined filter %d assigns flow to queue %d\n",
4166 rule->fd_id, rule->q_index);
4167 err = -EINVAL;
4168 }
4169 }
4170
4171 if (err) {
4172 dev_err(&pf->pdev->dev,
4173 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4174 count);
4175 return err;
4176 }
4177
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004178 /* update feature limits from largest to smallest supported values */
4179 /* TODO: Flow director limit, DCB etc */
4180
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004181 /* use rss_reconfig to rebuild with new queue count and update traffic
4182 * class queue mapping
4183 */
4184 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004185 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004186 return 0;
4187 else
4188 return -EINVAL;
4189}
4190
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004191/**
4192 * i40e_get_rxfh_key_size - get the RSS hash key size
4193 * @netdev: network interface device structure
4194 *
4195 * Returns the table size.
4196 **/
4197static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4198{
4199 return I40E_HKEY_ARRAY_SIZE;
4200}
4201
4202/**
4203 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4204 * @netdev: network interface device structure
4205 *
4206 * Returns the table size.
4207 **/
4208static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4209{
4210 return I40E_HLUT_ARRAY_SIZE;
4211}
4212
Alan Brady21675bd2017-10-05 14:53:33 -07004213/**
4214 * i40e_get_rxfh - get the rx flow hash indirection table
4215 * @netdev: network interface device structure
4216 * @indir: indirection table
4217 * @key: hash key
4218 * @hfunc: hash function
4219 *
4220 * Reads the indirection table directly from the hardware. Returns 0 on
4221 * success.
4222 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004223static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4224 u8 *hfunc)
4225{
4226 struct i40e_netdev_priv *np = netdev_priv(netdev);
4227 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004228 u8 *lut, *seed = NULL;
4229 int ret;
4230 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004231
4232 if (hfunc)
4233 *hfunc = ETH_RSS_HASH_TOP;
4234
4235 if (!indir)
4236 return 0;
4237
Helin Zhang043dd652015-10-21 19:56:23 -04004238 seed = key;
4239 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4240 if (!lut)
4241 return -ENOMEM;
4242 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4243 if (ret)
4244 goto out;
4245 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4246 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004247
Helin Zhang043dd652015-10-21 19:56:23 -04004248out:
4249 kfree(lut);
4250
4251 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004252}
4253
4254/**
4255 * i40e_set_rxfh - set the rx flow hash indirection table
4256 * @netdev: network interface device structure
4257 * @indir: indirection table
4258 * @key: hash key
Jacob Kellerf5254422018-04-20 01:41:33 -07004259 * @hfunc: hash function to use
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004260 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004261 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004262 * returns 0 after programming the table.
4263 **/
4264static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4265 const u8 *key, const u8 hfunc)
4266{
4267 struct i40e_netdev_priv *np = netdev_priv(netdev);
4268 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004269 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004270 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004271 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004272
4273 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4274 return -EOPNOTSUPP;
4275
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004276 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004277 if (!vsi->rss_hkey_user) {
4278 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4279 GFP_KERNEL);
4280 if (!vsi->rss_hkey_user)
4281 return -ENOMEM;
4282 }
4283 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4284 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004285 }
Helin Zhang28c58692015-10-26 19:44:27 -04004286 if (!vsi->rss_lut_user) {
4287 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4288 if (!vsi->rss_lut_user)
4289 return -ENOMEM;
4290 }
Helin Zhang043dd652015-10-21 19:56:23 -04004291
Helin Zhang28c58692015-10-26 19:44:27 -04004292 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004293 if (indir)
4294 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4295 vsi->rss_lut_user[i] = (u8)(indir[i]);
4296 else
4297 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4298 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004299
4300 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4301 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004302}
4303
Greg Rose7e45ab42015-02-06 08:52:19 +00004304/**
4305 * i40e_get_priv_flags - report device private flags
4306 * @dev: network interface device structure
4307 *
4308 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004309 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004310 * array.
4311 *
4312 * Returns a u32 bitmap of flags.
4313 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004314static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004315{
4316 struct i40e_netdev_priv *np = netdev_priv(dev);
4317 struct i40e_vsi *vsi = np->vsi;
4318 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004319 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004320
Alexander Duyckaca955d2017-03-10 12:22:01 -08004321 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4322 const struct i40e_priv_flags *priv_flags;
4323
4324 priv_flags = &i40e_gstrings_priv_flags[i];
4325
4326 if (priv_flags->flag & pf->flags)
4327 ret_flags |= BIT(i);
4328 }
4329
4330 if (pf->hw.pf_id != 0)
4331 return ret_flags;
4332
4333 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4334 const struct i40e_priv_flags *priv_flags;
4335
4336 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4337
4338 if (priv_flags->flag & pf->flags)
4339 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004340 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004341
4342 return ret_flags;
4343}
4344
Shannon Nelson9ac77262015-08-27 11:42:40 -04004345/**
4346 * i40e_set_priv_flags - set private flags
4347 * @dev: network interface device structure
4348 * @flags: bit flags to be set
4349 **/
4350static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4351{
4352 struct i40e_netdev_priv *np = netdev_priv(dev);
4353 struct i40e_vsi *vsi = np->vsi;
4354 struct i40e_pf *pf = vsi->back;
Alice Michael60f481b2017-12-27 08:17:50 -05004355 u64 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004356 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004357
Jacob Keller841c9502017-06-23 04:24:50 -04004358 orig_flags = READ_ONCE(pf->flags);
4359 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004360
Alexander Duyckaca955d2017-03-10 12:22:01 -08004361 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4362 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004363
Alexander Duyckaca955d2017-03-10 12:22:01 -08004364 priv_flags = &i40e_gstrings_priv_flags[i];
4365
Alexander Duyckaca955d2017-03-10 12:22:01 -08004366 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004367 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004368 else
Jacob Keller841c9502017-06-23 04:24:50 -04004369 new_flags &= ~(priv_flags->flag);
4370
4371 /* If this is a read-only flag, it can't be changed */
4372 if (priv_flags->read_only &&
4373 ((orig_flags ^ new_flags) & ~BIT(i)))
4374 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004375 }
4376
4377 if (pf->hw.pf_id != 0)
4378 goto flags_complete;
4379
4380 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4381 const struct i40e_priv_flags *priv_flags;
4382
4383 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4384
Alexander Duyckaca955d2017-03-10 12:22:01 -08004385 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004386 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004387 else
Jacob Keller841c9502017-06-23 04:24:50 -04004388 new_flags &= ~(priv_flags->flag);
4389
4390 /* If this is a read-only flag, it can't be changed */
4391 if (priv_flags->read_only &&
4392 ((orig_flags ^ new_flags) & ~BIT(i)))
4393 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004394 }
4395
4396flags_complete:
Alan Bradyfe09ed02017-12-29 08:50:34 -05004397 changed_flags = orig_flags ^ new_flags;
4398
Jacob Keller841c9502017-06-23 04:24:50 -04004399 /* Before we finalize any flag changes, we need to perform some
4400 * checks to ensure that the changes are supported and safe.
4401 */
4402
4403 /* ATR eviction is not supported on all devices */
4404 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4405 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4406 return -EOPNOTSUPP;
4407
Alan Bradyfe09ed02017-12-29 08:50:34 -05004408 /* If the driver detected FW LLDP was disabled on init, this flag could
4409 * be set, however we do not support _changing_ the flag if NPAR is
4410 * enabled or FW API version < 1.7. There are situations where older
4411 * FW versions/NPAR enabled PFs could disable LLDP, however we _must_
4412 * not allow the user to enable/disable LLDP with this flag on
4413 * unsupported FW versions.
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004414 */
Alan Bradyfe09ed02017-12-29 08:50:34 -05004415 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
Dave Ertman7b634352018-01-22 12:00:37 -05004416 if (!(pf->hw_features & I40E_HW_STOPPABLE_FW_LLDP)) {
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004417 dev_warn(&pf->pdev->dev,
Dave Ertman7b634352018-01-22 12:00:37 -05004418 "Device does not support changing FW LLDP\n");
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004419 return -EOPNOTSUPP;
4420 }
4421 }
4422
Jacob Keller886ff142018-03-16 01:26:36 -07004423 /* Now that we've checked to ensure that the new flags are valid, load
4424 * them into place. Since we only modify flags either (a) during
4425 * initialization or (b) while holding the RTNL lock, we don't need
4426 * anything fancy here.
Jacob Keller841c9502017-06-23 04:24:50 -04004427 */
Jacob Keller886ff142018-03-16 01:26:36 -07004428 pf->flags = new_flags;
Jacob Keller841c9502017-06-23 04:24:50 -04004429
Alexander Duyckaca955d2017-03-10 12:22:01 -08004430 /* Process any additional changes needed as a result of flag changes.
4431 * The changed_flags value reflects the list of bits that were
4432 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004433 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004434
Alexander Duyckaca955d2017-03-10 12:22:01 -08004435 /* Flush current ATR settings if ATR was disabled */
4436 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4437 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller134201a2018-03-16 01:26:32 -07004438 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
Jacob Keller0da36b92017-04-19 09:25:55 -04004439 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004440 }
4441
Alexander Duyckaca955d2017-03-10 12:22:01 -08004442 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4443 u16 sw_flags = 0, valid_flags = 0;
4444 int ret;
4445
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004446 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4447 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4448 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4449 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07004450 0, NULL);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004451 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4452 dev_info(&pf->pdev->dev,
4453 "couldn't set switch config bits, err %s aq_err %s\n",
4454 i40e_stat_str(&pf->hw, ret),
4455 i40e_aq_str(&pf->hw,
4456 pf->hw.aq.asq_last_status));
4457 /* not a fatal problem, just keep going */
4458 }
4459 }
4460
Paweł Jabłoński17b4d252017-12-29 08:50:20 -05004461 if ((changed_flags & pf->flags &
4462 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4463 (pf->flags & I40E_FLAG_MFP_ENABLED))
4464 dev_warn(&pf->pdev->dev,
4465 "Turning on link-down-on-close flag may affect other partitions\n");
4466
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004467 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4468 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4469 struct i40e_dcbx_config *dcbcfg;
4470 int i;
4471
4472 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4473 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4474 /* reset local_dcbx_config to default */
4475 dcbcfg = &pf->hw.local_dcbx_config;
4476 dcbcfg->etscfg.willing = 1;
4477 dcbcfg->etscfg.maxtcs = 0;
4478 dcbcfg->etscfg.tcbwtable[0] = 100;
4479 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4480 dcbcfg->etscfg.tcbwtable[i] = 0;
4481 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4482 dcbcfg->etscfg.prioritytable[i] = 0;
4483 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4484 dcbcfg->pfc.willing = 1;
4485 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4486 } else {
4487 i40e_aq_start_lldp(&pf->hw, NULL);
4488 }
4489 }
4490
Alexander Duyckaca955d2017-03-10 12:22:01 -08004491 /* Issue reset to cause things to take effect, as additional bits
4492 * are added we will need to create a mask of bits requiring reset
4493 */
Mitch Williams64615b52017-08-29 05:32:30 -04004494 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4495 I40E_FLAG_LEGACY_RX |
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004496 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4497 I40E_FLAG_DISABLE_FW_LLDP))
Maciej Sosin373149f2017-04-05 07:50:55 -04004498 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004499
Shannon Nelson9ac77262015-08-27 11:42:40 -04004500 return 0;
4501}
4502
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004503/**
4504 * i40e_get_module_info - get (Q)SFP+ module type info
4505 * @netdev: network interface device structure
4506 * @modinfo: module EEPROM size and layout information structure
4507 **/
4508static int i40e_get_module_info(struct net_device *netdev,
4509 struct ethtool_modinfo *modinfo)
4510{
4511 struct i40e_netdev_priv *np = netdev_priv(netdev);
4512 struct i40e_vsi *vsi = np->vsi;
4513 struct i40e_pf *pf = vsi->back;
4514 struct i40e_hw *hw = &pf->hw;
4515 u32 sff8472_comp = 0;
4516 u32 sff8472_swap = 0;
4517 u32 sff8636_rev = 0;
4518 i40e_status status;
4519 u32 type = 0;
4520
4521 /* Check if firmware supports reading module EEPROM. */
4522 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4523 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4524 return -EINVAL;
4525 }
4526
4527 status = i40e_update_link_info(hw);
4528 if (status)
4529 return -EIO;
4530
4531 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4532 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4533 return -EINVAL;
4534 }
4535
4536 type = hw->phy.link_info.module_type[0];
4537
4538 switch (type) {
4539 case I40E_MODULE_TYPE_SFP:
4540 status = i40e_aq_get_phy_register(hw,
4541 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4542 I40E_I2C_EEPROM_DEV_ADDR,
4543 I40E_MODULE_SFF_8472_COMP,
4544 &sff8472_comp, NULL);
4545 if (status)
4546 return -EIO;
4547
4548 status = i40e_aq_get_phy_register(hw,
4549 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4550 I40E_I2C_EEPROM_DEV_ADDR,
4551 I40E_MODULE_SFF_8472_SWAP,
4552 &sff8472_swap, NULL);
4553 if (status)
4554 return -EIO;
4555
4556 /* Check if the module requires address swap to access
4557 * the other EEPROM memory page.
4558 */
4559 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4560 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4561 modinfo->type = ETH_MODULE_SFF_8079;
4562 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4563 } else if (sff8472_comp == 0x00) {
4564 /* Module is not SFF-8472 compliant */
4565 modinfo->type = ETH_MODULE_SFF_8079;
4566 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4567 } else {
4568 modinfo->type = ETH_MODULE_SFF_8472;
4569 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4570 }
4571 break;
4572 case I40E_MODULE_TYPE_QSFP_PLUS:
4573 /* Read from memory page 0. */
4574 status = i40e_aq_get_phy_register(hw,
4575 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4576 0,
4577 I40E_MODULE_REVISION_ADDR,
4578 &sff8636_rev, NULL);
4579 if (status)
4580 return -EIO;
4581 /* Determine revision compliance byte */
4582 if (sff8636_rev > 0x02) {
4583 /* Module is SFF-8636 compliant */
4584 modinfo->type = ETH_MODULE_SFF_8636;
4585 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4586 } else {
4587 modinfo->type = ETH_MODULE_SFF_8436;
4588 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4589 }
4590 break;
4591 case I40E_MODULE_TYPE_QSFP28:
4592 modinfo->type = ETH_MODULE_SFF_8636;
4593 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4594 break;
4595 default:
4596 netdev_err(vsi->netdev, "Module type unrecognized\n");
4597 return -EINVAL;
4598 }
4599 return 0;
4600}
4601
4602/**
4603 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4604 * @netdev: network interface device structure
4605 * @ee: EEPROM dump request structure
4606 * @data: buffer to be filled with EEPROM contents
4607 **/
4608static int i40e_get_module_eeprom(struct net_device *netdev,
4609 struct ethtool_eeprom *ee,
4610 u8 *data)
4611{
4612 struct i40e_netdev_priv *np = netdev_priv(netdev);
4613 struct i40e_vsi *vsi = np->vsi;
4614 struct i40e_pf *pf = vsi->back;
4615 struct i40e_hw *hw = &pf->hw;
4616 bool is_sfp = false;
4617 i40e_status status;
4618 u32 value = 0;
4619 int i;
4620
4621 if (!ee || !ee->len || !data)
4622 return -EINVAL;
4623
4624 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4625 is_sfp = true;
4626
4627 for (i = 0; i < ee->len; i++) {
4628 u32 offset = i + ee->offset;
4629 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4630
4631 /* Check if we need to access the other memory page */
4632 if (is_sfp) {
4633 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4634 offset -= ETH_MODULE_SFF_8079_LEN;
4635 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4636 }
4637 } else {
4638 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4639 /* Compute memory page number and offset. */
4640 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4641 addr++;
4642 }
4643 }
4644
4645 status = i40e_aq_get_phy_register(hw,
4646 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4647 addr, offset, &value, NULL);
4648 if (status)
4649 return -EIO;
4650 data[i] = value;
4651 }
4652 return 0;
4653}
4654
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004655static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004656 .get_drvinfo = i40e_get_drvinfo,
4657 .get_regs_len = i40e_get_regs_len,
4658 .get_regs = i40e_get_regs,
4659 .nway_reset = i40e_nway_reset,
4660 .get_link = ethtool_op_get_link,
4661 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004662 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004663 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004664 .get_eeprom_len = i40e_get_eeprom_len,
4665 .get_eeprom = i40e_get_eeprom,
4666 .get_ringparam = i40e_get_ringparam,
4667 .set_ringparam = i40e_set_ringparam,
4668 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004669 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004670 .get_msglevel = i40e_get_msglevel,
4671 .set_msglevel = i40e_set_msglevel,
4672 .get_rxnfc = i40e_get_rxnfc,
4673 .set_rxnfc = i40e_set_rxnfc,
4674 .self_test = i40e_diag_test,
4675 .get_strings = i40e_get_strings,
4676 .set_phys_id = i40e_set_phys_id,
4677 .get_sset_count = i40e_get_sset_count,
4678 .get_ethtool_stats = i40e_get_ethtool_stats,
4679 .get_coalesce = i40e_get_coalesce,
4680 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004681 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4682 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4683 .get_rxfh = i40e_get_rxfh,
4684 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004685 .get_channels = i40e_get_channels,
4686 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004687 .get_module_info = i40e_get_module_info,
4688 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004689 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004690 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004691 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004692 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004693 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004694 .get_link_ksettings = i40e_get_link_ksettings,
4695 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004696};
4697
4698void i40e_set_ethtool_ops(struct net_device *netdev)
4699{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004700 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004701}