blob: 329e59eae4a1811986bcc080762533007e19c8f9 [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) \
Jacob Keller132ee002018-05-10 05:59:43 -070022 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000023#define I40E_PF_STAT(_name, _stat) \
Jacob Keller132ee002018-05-10 05:59:43 -070024 I40E_STAT(struct i40e_pf, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000025#define I40E_VSI_STAT(_name, _stat) \
Jacob Keller132ee002018-05-10 05:59:43 -070026 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000027#define I40E_VEB_STAT(_name, _stat) \
Jacob Keller132ee002018-05-10 05:59:43 -070028 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),
Harshitha Ramamurthy3f76d012018-05-10 05:59:45 -070069 I40E_VSI_STAT("tx_busy", tx_busy),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080070 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
71 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000072};
73
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000074/* These PF_STATs might look like duplicates of some NETDEV_STATs,
75 * but they are separate. This device supports Virtualization, and
76 * as such might have several netdevs supporting VMDq and FCoE going
77 * through a single port. The NETDEV_STATs are for individual netdevs
78 * seen at the top of the stack, and the PF_STATs are for the physical
79 * function at the bottom of the stack hosting those netdevs.
80 *
81 * The PF_STATs are appended to the netdev stats only when ethtool -S
82 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
83 */
Joe Perchesfe180a52016-09-26 20:17:01 -070084static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000085 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
86 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +000087 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
88 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
89 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
90 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
91 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
92 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000093 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
94 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000095 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -040096 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000097 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
98 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
99 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000100 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000101 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000102 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
103 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
104 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
105 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
106 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
107 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
108 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
109 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
110 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
111 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
112 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
113 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
114 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
115 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
116 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
117 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
118 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
119 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
120 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
121 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
122 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
123 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
124 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
125 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800126 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000127 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jacob Keller2955fac2017-05-03 10:28:58 -0700128 I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000129 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000130 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400131 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400132 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000133 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400134 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000135
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000136 /* LPI stats */
137 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
138 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
139 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
140 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000141};
142
143#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000144 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
145 * 2 /* Tx and Rx together */ \
146 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000147#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
Jacob Keller132ee002018-05-10 05:59:43 -0700148#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000149#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jacob Keller132ee002018-05-10 05:59:43 -0700150#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000151 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000152 I40E_QUEUE_STATS_LEN((n)))
153#define I40E_PFC_STATS_LEN ( \
154 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
155 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
156 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
157 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
158 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
159 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400160#define I40E_VEB_TC_STATS_LEN ( \
161 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
162 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
163 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
164 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
165 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000166#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400167#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000168#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
169 I40E_PFC_STATS_LEN + \
170 I40E_VSI_STATS_LEN((n)))
171
172enum i40e_ethtool_test_id {
173 I40E_ETH_TEST_REG = 0,
174 I40E_ETH_TEST_EEPROM,
175 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000176 I40E_ETH_TEST_LINK,
177};
178
179static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
180 "Register test (offline)",
181 "Eeprom test (offline)",
182 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000183 "Link test (on/offline)"
184};
185
186#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
187
Alexander Duyckaca955d2017-03-10 12:22:01 -0800188struct i40e_priv_flags {
189 char flag_string[ETH_GSTRING_LEN];
190 u64 flag;
191 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000192};
193
Alexander Duyckaca955d2017-03-10 12:22:01 -0800194#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
195 .flag_string = _name, \
196 .flag = _flag, \
197 .read_only = _read_only, \
198}
199
200static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
201 /* NOTE: MFP setting cannot be changed */
202 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
203 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
204 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
205 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700206 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Mariusz Stachurac3880bd2017-11-14 07:00:50 -0500207 I40E_PRIV_FLAG("link-down-on-close",
208 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700209 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400210 I40E_PRIV_FLAG("disable-source-pruning",
211 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Dave Ertmanc61c8fe2017-12-27 08:18:21 -0500212 I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800213};
214
215#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000216
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700217/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800218static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
219 I40E_PRIV_FLAG("vf-true-promisc-support",
220 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700221};
222
Alexander Duyckaca955d2017-03-10 12:22:01 -0800223#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700224
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000225/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000226 * i40e_partition_setting_complaint - generic complaint for MFP restriction
227 * @pf: the PF struct
228 **/
229static void i40e_partition_setting_complaint(struct i40e_pf *pf)
230{
231 dev_info(&pf->pdev->dev,
232 "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");
233}
234
235/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700236 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
Alan Brady52e2d022017-10-05 14:53:35 -0700237 * @pf: PF struct with phy_types
Alan Brady1eaae512017-10-05 14:53:41 -0700238 * @ks: ethtool link ksettings struct to fill out
Catherine Sullivan06566e52016-05-03 15:13:14 -0700239 *
240 **/
Alan Brady1eaae512017-10-05 14:53:41 -0700241static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
242 struct ethtool_link_ksettings *ks)
Catherine Sullivan06566e52016-05-03 15:13:14 -0700243{
Avinash Dayanand28537042016-06-20 09:10:33 -0700244 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800245 u64 phy_types = pf->hw.phy.phy_types;
246
Alan Brady1eaae512017-10-05 14:53:41 -0700247 ethtool_link_ksettings_zero_link_mode(ks, supported);
248 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700249
250 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
Alan Brady1eaae512017-10-05 14:53:41 -0700251 ethtool_link_ksettings_add_link_mode(ks, supported,
252 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700253 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700254 ethtool_link_ksettings_add_link_mode(ks, advertising,
255 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400256 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady1eaae512017-10-05 14:53:41 -0700257 ethtool_link_ksettings_add_link_mode(ks, supported,
258 100baseT_Full);
259 ethtool_link_ksettings_add_link_mode(ks, advertising,
260 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700261 }
262 }
263 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
264 phy_types & I40E_CAP_PHY_TYPE_XFI ||
265 phy_types & I40E_CAP_PHY_TYPE_SFI ||
266 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
Alan Brady1eaae512017-10-05 14:53:41 -0700267 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
268 ethtool_link_ksettings_add_link_mode(ks, supported,
269 10000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700270 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700271 ethtool_link_ksettings_add_link_mode(ks, advertising,
272 10000baseT_Full);
273 }
274 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
275 ethtool_link_ksettings_add_link_mode(ks, supported,
276 10000baseT_Full);
277 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
278 ethtool_link_ksettings_add_link_mode(ks, advertising,
279 10000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700280 }
281 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
282 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
283 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
Alan Brady1eaae512017-10-05 14:53:41 -0700284 ethtool_link_ksettings_add_link_mode(ks, supported,
285 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700286 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
287 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700288 ethtool_link_ksettings_add_link_mode(ks, supported,
289 40000baseCR4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700290 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700291 ethtool_link_ksettings_add_link_mode(ks, advertising,
292 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700293 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700294 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700295 ethtool_link_ksettings_add_link_mode(ks, supported,
296 100baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700297 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady1eaae512017-10-05 14:53:41 -0700298 ethtool_link_ksettings_add_link_mode(ks, advertising,
299 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700300 }
Alan Brady1eaae512017-10-05 14:53:41 -0700301 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
302 ethtool_link_ksettings_add_link_mode(ks, supported,
303 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700305 ethtool_link_ksettings_add_link_mode(ks, advertising,
306 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700307 }
308 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700309 ethtool_link_ksettings_add_link_mode(ks, supported,
310 40000baseSR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700311 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700312 ethtool_link_ksettings_add_link_mode(ks, supported,
313 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700314 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700315 ethtool_link_ksettings_add_link_mode(ks, supported,
316 40000baseLR4_Full);
317 ethtool_link_ksettings_add_link_mode(ks, advertising,
318 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700319 }
320 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
Alan Brady1eaae512017-10-05 14:53:41 -0700321 ethtool_link_ksettings_add_link_mode(ks, supported,
322 20000baseKR2_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700323 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700324 ethtool_link_ksettings_add_link_mode(ks, advertising,
325 20000baseKR2_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700326 }
327 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700328 ethtool_link_ksettings_add_link_mode(ks, supported,
329 10000baseKX4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700330 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700331 ethtool_link_ksettings_add_link_mode(ks, advertising,
332 10000baseKX4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700333 }
Alan Brady6987bd252017-10-05 14:53:38 -0700334 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
335 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700336 ethtool_link_ksettings_add_link_mode(ks, supported,
337 10000baseKR_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700338 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700339 ethtool_link_ksettings_add_link_mode(ks, advertising,
340 10000baseKR_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700341 }
Alan Brady6987bd252017-10-05 14:53:38 -0700342 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
343 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700344 ethtool_link_ksettings_add_link_mode(ks, supported,
345 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700346 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700347 ethtool_link_ksettings_add_link_mode(ks, advertising,
348 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700349 }
Alan Brady1eaae512017-10-05 14:53:41 -0700350 /* need to add 25G PHY types */
351 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
352 ethtool_link_ksettings_add_link_mode(ks, supported,
353 25000baseKR_Full);
354 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
355 ethtool_link_ksettings_add_link_mode(ks, advertising,
356 25000baseKR_Full);
357 }
358 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
359 ethtool_link_ksettings_add_link_mode(ks, supported,
360 25000baseCR_Full);
361 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
362 ethtool_link_ksettings_add_link_mode(ks, advertising,
363 25000baseCR_Full);
364 }
365 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800366 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
Alan Brady1eaae512017-10-05 14:53:41 -0700367 ethtool_link_ksettings_add_link_mode(ks, supported,
368 25000baseSR_Full);
369 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
370 ethtool_link_ksettings_add_link_mode(ks, advertising,
371 25000baseSR_Full);
372 }
373 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
374 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
375 ethtool_link_ksettings_add_link_mode(ks, supported,
376 25000baseCR_Full);
377 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
378 ethtool_link_ksettings_add_link_mode(ks, advertising,
379 25000baseCR_Full);
380 }
381 /* need to add new 10G PHY types */
382 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
383 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
384 ethtool_link_ksettings_add_link_mode(ks, supported,
385 10000baseCR_Full);
386 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
387 ethtool_link_ksettings_add_link_mode(ks, advertising,
388 10000baseCR_Full);
389 }
390 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
391 ethtool_link_ksettings_add_link_mode(ks, supported,
392 10000baseSR_Full);
393 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
394 ethtool_link_ksettings_add_link_mode(ks, advertising,
395 10000baseSR_Full);
396 }
397 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
398 ethtool_link_ksettings_add_link_mode(ks, supported,
399 10000baseLR_Full);
400 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
401 ethtool_link_ksettings_add_link_mode(ks, advertising,
402 10000baseLR_Full);
403 }
404 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
405 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
406 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
407 ethtool_link_ksettings_add_link_mode(ks, supported,
408 1000baseX_Full);
409 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
410 ethtool_link_ksettings_add_link_mode(ks, advertising,
411 1000baseX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700412 }
413 /* Autoneg PHY types */
414 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
415 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
416 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
417 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800418 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700419 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
420 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
421 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
422 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
423 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
424 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
425 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
426 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
427 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
430 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
431 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
432 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
433 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
434 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
435 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700436 ethtool_link_ksettings_add_link_mode(ks, supported,
437 Autoneg);
438 ethtool_link_ksettings_add_link_mode(ks, advertising,
439 Autoneg);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800440 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700441}
442
443/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000444 * i40e_get_settings_link_up - Get the Link settings for when link is up
445 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700446 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000447 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700448 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000449 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000450static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700451 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400452 struct net_device *netdev,
453 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000454{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000455 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Alan Brady1eaae512017-10-05 14:53:41 -0700456 struct ethtool_link_ksettings cap_ksettings;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000457 u32 link_speed = hw_link_info->link_speed;
458
Catherine Sullivane8278452015-02-06 08:52:08 +0000459 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000460 switch (hw_link_info->phy_type) {
461 case I40E_PHY_TYPE_40GBASE_CR4:
462 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Alan Brady79f04a32017-10-05 14:53:42 -0700463 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
464 ethtool_link_ksettings_add_link_mode(ks, supported,
465 40000baseCR4_Full);
466 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
467 ethtool_link_ksettings_add_link_mode(ks, advertising,
468 40000baseCR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000469 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000470 case I40E_PHY_TYPE_XLAUI:
471 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000472 case I40E_PHY_TYPE_40GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700473 ethtool_link_ksettings_add_link_mode(ks, supported,
474 40000baseCR4_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000475 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000476 case I40E_PHY_TYPE_40GBASE_SR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700477 ethtool_link_ksettings_add_link_mode(ks, supported,
478 40000baseSR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000479 break;
480 case I40E_PHY_TYPE_40GBASE_LR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700481 ethtool_link_ksettings_add_link_mode(ks, supported,
482 40000baseLR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000483 break;
Alan Brady79f04a32017-10-05 14:53:42 -0700484 case I40E_PHY_TYPE_25GBASE_SR:
485 case I40E_PHY_TYPE_25GBASE_LR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000486 case I40E_PHY_TYPE_10GBASE_SR:
487 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000488 case I40E_PHY_TYPE_1000BASE_SX:
489 case I40E_PHY_TYPE_1000BASE_LX:
Alan Brady79f04a32017-10-05 14:53:42 -0700490 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
491 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
492 ethtool_link_ksettings_add_link_mode(ks, supported,
493 25000baseSR_Full);
494 ethtool_link_ksettings_add_link_mode(ks, advertising,
495 25000baseSR_Full);
496 ethtool_link_ksettings_add_link_mode(ks, supported,
497 10000baseSR_Full);
498 ethtool_link_ksettings_add_link_mode(ks, advertising,
499 10000baseSR_Full);
500 ethtool_link_ksettings_add_link_mode(ks, supported,
501 10000baseLR_Full);
502 ethtool_link_ksettings_add_link_mode(ks, advertising,
503 10000baseLR_Full);
504 ethtool_link_ksettings_add_link_mode(ks, supported,
505 1000baseX_Full);
506 ethtool_link_ksettings_add_link_mode(ks, advertising,
507 1000baseX_Full);
508 ethtool_link_ksettings_add_link_mode(ks, supported,
509 10000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400510 if (hw_link_info->module_type[2] &
511 I40E_MODULE_TYPE_1000BASE_SX ||
512 hw_link_info->module_type[2] &
513 I40E_MODULE_TYPE_1000BASE_LX) {
Alan Brady79f04a32017-10-05 14:53:42 -0700514 ethtool_link_ksettings_add_link_mode(ks, supported,
515 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400516 if (hw_link_info->requested_speeds &
517 I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700518 ethtool_link_ksettings_add_link_mode(
519 ks, advertising, 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400520 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000521 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700522 ethtool_link_ksettings_add_link_mode(ks, advertising,
523 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000524 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000525 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000526 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700527 case I40E_PHY_TYPE_100BASE_TX:
Alan Brady79f04a32017-10-05 14:53:42 -0700528 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
529 ethtool_link_ksettings_add_link_mode(ks, supported,
530 10000baseT_Full);
531 ethtool_link_ksettings_add_link_mode(ks, supported,
532 1000baseT_Full);
533 ethtool_link_ksettings_add_link_mode(ks, supported,
534 100baseT_Full);
535 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivane8278452015-02-06 08:52:08 +0000536 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700537 ethtool_link_ksettings_add_link_mode(ks, advertising,
538 10000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000539 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700540 ethtool_link_ksettings_add_link_mode(ks, advertising,
541 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700542 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700543 ethtool_link_ksettings_add_link_mode(ks, advertising,
544 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400545 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400546 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Alan Brady79f04a32017-10-05 14:53:42 -0700547 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
548 ethtool_link_ksettings_add_link_mode(ks, supported,
549 1000baseT_Full);
550 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
551 ethtool_link_ksettings_add_link_mode(ks, advertising,
552 1000baseT_Full);
Catherine Sullivan48becae2015-09-28 14:12:41 -0400553 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000554 case I40E_PHY_TYPE_10GBASE_CR1_CU:
555 case I40E_PHY_TYPE_10GBASE_CR1:
Alan Brady79f04a32017-10-05 14:53:42 -0700556 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
557 ethtool_link_ksettings_add_link_mode(ks, supported,
558 10000baseT_Full);
559 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
560 ethtool_link_ksettings_add_link_mode(ks, advertising,
561 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000562 break;
563 case I40E_PHY_TYPE_XAUI:
564 case I40E_PHY_TYPE_XFI:
565 case I40E_PHY_TYPE_SFI:
566 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000567 case I40E_PHY_TYPE_10GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700568 ethtool_link_ksettings_add_link_mode(ks, supported,
569 10000baseT_Full);
570 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
571 ethtool_link_ksettings_add_link_mode(ks, advertising,
572 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000573 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000574 case I40E_PHY_TYPE_SGMII:
Alan Brady79f04a32017-10-05 14:53:42 -0700575 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
576 ethtool_link_ksettings_add_link_mode(ks, supported,
577 1000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000578 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700579 ethtool_link_ksettings_add_link_mode(ks, advertising,
580 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400581 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady79f04a32017-10-05 14:53:42 -0700582 ethtool_link_ksettings_add_link_mode(ks, supported,
583 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400584 if (hw_link_info->requested_speeds &
585 I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700586 ethtool_link_ksettings_add_link_mode(
587 ks, advertising, 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400588 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000589 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400590 case I40E_PHY_TYPE_40GBASE_KR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700591 case I40E_PHY_TYPE_25GBASE_KR:
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400592 case I40E_PHY_TYPE_20GBASE_KR2:
593 case I40E_PHY_TYPE_10GBASE_KR:
594 case I40E_PHY_TYPE_10GBASE_KX4:
595 case I40E_PHY_TYPE_1000BASE_KX:
Alan Brady79f04a32017-10-05 14:53:42 -0700596 ethtool_link_ksettings_add_link_mode(ks, supported,
597 40000baseKR4_Full);
598 ethtool_link_ksettings_add_link_mode(ks, supported,
599 25000baseKR_Full);
600 ethtool_link_ksettings_add_link_mode(ks, supported,
601 20000baseKR2_Full);
602 ethtool_link_ksettings_add_link_mode(ks, supported,
603 10000baseKR_Full);
604 ethtool_link_ksettings_add_link_mode(ks, supported,
605 10000baseKX4_Full);
606 ethtool_link_ksettings_add_link_mode(ks, supported,
607 1000baseKX_Full);
608 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
609 ethtool_link_ksettings_add_link_mode(ks, advertising,
610 40000baseKR4_Full);
611 ethtool_link_ksettings_add_link_mode(ks, advertising,
612 25000baseKR_Full);
613 ethtool_link_ksettings_add_link_mode(ks, advertising,
614 20000baseKR2_Full);
615 ethtool_link_ksettings_add_link_mode(ks, advertising,
616 10000baseKR_Full);
617 ethtool_link_ksettings_add_link_mode(ks, advertising,
618 10000baseKX4_Full);
619 ethtool_link_ksettings_add_link_mode(ks, advertising,
620 1000baseKX_Full);
621 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400622 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800623 case I40E_PHY_TYPE_25GBASE_CR:
Alan Brady79f04a32017-10-05 14:53:42 -0700624 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
625 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
626 ethtool_link_ksettings_add_link_mode(ks, supported,
627 25000baseCR_Full);
628 ethtool_link_ksettings_add_link_mode(ks, advertising,
629 25000baseCR_Full);
630 break;
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700631 case I40E_PHY_TYPE_25GBASE_AOC:
632 case I40E_PHY_TYPE_25GBASE_ACC:
Alan Brady79f04a32017-10-05 14:53:42 -0700633 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
634 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
635 ethtool_link_ksettings_add_link_mode(ks, supported,
636 25000baseCR_Full);
637
638 ethtool_link_ksettings_add_link_mode(ks, advertising,
639 25000baseCR_Full);
640 ethtool_link_ksettings_add_link_mode(ks, supported,
641 10000baseCR_Full);
642 ethtool_link_ksettings_add_link_mode(ks, advertising,
643 10000baseCR_Full);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800644 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000645 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000646 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700647 netdev_info(netdev,
648 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000649 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000650 }
651
Catherine Sullivan06566e52016-05-03 15:13:14 -0700652 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700653 * current PHY type, get what is supported by the NVM and intersect
654 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700655 */
Alan Brady1eaae512017-10-05 14:53:41 -0700656 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
657 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
658 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700659
Catherine Sullivane8278452015-02-06 08:52:08 +0000660 /* Set speed and duplex */
661 switch (link_speed) {
662 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700663 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000664 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800665 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700666 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800667 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700668 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700669 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700670 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000671 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700672 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000673 break;
674 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700675 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000676 break;
677 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700678 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000679 break;
680 default:
681 break;
682 }
Alan Brady1c142e12017-10-05 14:53:31 -0700683 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000684}
685
686/**
687 * i40e_get_settings_link_down - Get the Link settings for when link is down
688 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700689 * @ks: ethtool ksettings to fill in
690 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000691 *
692 * Reports link settings that can be determined when link is down
693 **/
694static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700695 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400696 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000697{
Catherine Sullivane8278452015-02-06 08:52:08 +0000698 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400699 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000700 */
Alan Brady1eaae512017-10-05 14:53:41 -0700701 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000702
703 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700704 ks->base.speed = SPEED_UNKNOWN;
705 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000706}
707
708/**
Alan Brady1c142e12017-10-05 14:53:31 -0700709 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000710 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700711 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000712 *
713 * Reports speed/duplex settings based on media_type
714 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100715static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700716 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000717{
718 struct i40e_netdev_priv *np = netdev_priv(netdev);
719 struct i40e_pf *pf = np->vsi->back;
720 struct i40e_hw *hw = &pf->hw;
721 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
722 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700723
724 ethtool_link_ksettings_zero_link_mode(ks, supported);
725 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000726
727 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700728 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000729 else
Alan Brady1c142e12017-10-05 14:53:31 -0700730 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000731
732 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000733 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700734 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
735 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000736
Alan Bradya03af692017-10-05 14:53:37 -0700737 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000738 switch (hw->phy.media_type) {
739 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700740 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
741 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
742 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700743 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100744 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700745 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000746 break;
747 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700748 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
749 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
750 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000751 break;
752 case I40E_MEDIA_TYPE_DA:
753 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700754 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
755 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
756 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000757 break;
758 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700759 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
760 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000761 break;
762 case I40E_MEDIA_TYPE_UNKNOWN:
763 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700764 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000765 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000766 }
767
Catherine Sullivane8278452015-02-06 08:52:08 +0000768 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700769 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000770
Catherine Sullivane8278452015-02-06 08:52:08 +0000771 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000772 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700773 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000774 break;
775 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700776 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100777 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000778 break;
779 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700780 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700781 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100782 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000783 break;
784 default:
Alan Brady5f434992017-10-05 14:53:34 -0700785 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
786 ethtool_link_ksettings_del_link_mode(ks, advertising,
787 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000788 break;
789 }
790
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000791 return 0;
792}
793
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000794/**
Alan Brady1c142e12017-10-05 14:53:31 -0700795 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000796 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700797 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000798 *
799 * Set speed/duplex per media_types advertised/forced
800 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100801static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700802 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000803{
804 struct i40e_netdev_priv *np = netdev_priv(netdev);
805 struct i40e_aq_get_phy_abilities_resp abilities;
Alan Brady636b62d2017-10-05 14:53:43 -0700806 struct ethtool_link_ksettings safe_ks;
807 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000808 struct i40e_aq_set_phy_config config;
809 struct i40e_pf *pf = np->vsi->back;
810 struct i40e_vsi *vsi = np->vsi;
811 struct i40e_hw *hw = &pf->hw;
Alan Brady636b62d2017-10-05 14:53:43 -0700812 bool autoneg_changed = false;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000813 i40e_status status = 0;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400814 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000815 int err = 0;
Alan Bradycee91992017-10-05 14:53:44 -0700816 u8 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000817
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000818 /* Changing port settings is not supported if this isn't the
819 * port's controlling PF
820 */
821 if (hw->partition_id != 1) {
822 i40e_partition_setting_complaint(pf);
823 return -EOPNOTSUPP;
824 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000825 if (vsi != pf->vsi[pf->lan_vsi])
826 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000827 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
828 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000829 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700830 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000831 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000832 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400833 if (hw->device_id == I40E_DEV_ID_KX_B ||
834 hw->device_id == I40E_DEV_ID_KX_C ||
835 hw->device_id == I40E_DEV_ID_20G_KR2 ||
Patryk Małek88244a42018-03-19 09:28:03 -0700836 hw->device_id == I40E_DEV_ID_20G_KR2_A ||
Patryk Małek3f8c84372018-03-19 09:28:04 -0700837 hw->device_id == I40E_DEV_ID_25G_B ||
Patryk Małek88244a42018-03-19 09:28:03 -0700838 hw->device_id == I40E_DEV_ID_KX_X722) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400839 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
840 return -EOPNOTSUPP;
841 }
842
Alan Brady1c142e12017-10-05 14:53:31 -0700843 /* copy the ksettings to copy_ks to avoid modifying the origin */
844 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000845
Alan Bradycee91992017-10-05 14:53:44 -0700846 /* save autoneg out of ksettings */
847 autoneg = copy_ks.base.autoneg;
848
Philippe Reynesa7f90942017-02-04 22:05:06 +0100849 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700850 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
Alan Bradycee91992017-10-05 14:53:44 -0700851 safe_ks.base.cmd = copy_ks.base.cmd;
852 safe_ks.base.link_mode_masks_nwords =
853 copy_ks.base.link_mode_masks_nwords;
Alan Brady1c142e12017-10-05 14:53:31 -0700854 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100855
Jan Sokolowski32c23b42018-03-19 09:28:03 -0700856 /* Get link modes supported by hardware and check against modes
857 * requested by the user. Return an error if unsupported mode was set.
858 */
859 if (!bitmap_subset(copy_ks.link_modes.advertising,
860 safe_ks.link_modes.supported,
861 __ETHTOOL_LINK_MODE_MASK_NBITS))
862 return -EINVAL;
863
Alan Bradycee91992017-10-05 14:53:44 -0700864 /* set autoneg back to what it currently is */
Alan Brady1c142e12017-10-05 14:53:31 -0700865 copy_ks.base.autoneg = safe_ks.base.autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000866
Alan Bradycee91992017-10-05 14:53:44 -0700867 /* If copy_ks.base and safe_ks.base are not the same now, then they are
868 * trying to set something that we do not support.
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000869 */
Alan Bradycee91992017-10-05 14:53:44 -0700870 if (memcmp(&copy_ks.base, &safe_ks.base,
871 sizeof(struct ethtool_link_settings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000872 return -EOPNOTSUPP;
873
Jacob Keller0da36b92017-04-19 09:25:55 -0400874 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400875 timeout--;
876 if (!timeout)
877 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000878 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400879 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000880
881 /* Get the current phy config */
882 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
883 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400884 if (status) {
885 err = -EAGAIN;
886 goto done;
887 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000888
Catherine Sullivan124ed152014-07-12 07:28:12 +0000889 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000890 * set below
891 */
892 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000893 config.abilities = abilities.abilities;
894
895 /* Check autoneg */
896 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000897 /* If autoneg was not already enabled */
898 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400899 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700900 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
901 supported,
902 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400903 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400904 err = -EINVAL;
905 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400906 }
907 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000908 config.abilities = abilities.abilities |
909 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700910 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000911 }
912 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000913 /* If autoneg is currently enabled */
914 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400915 /* If autoneg is supported 10GBASE_T is the only PHY
916 * that can disable it, so otherwise return error
917 */
Alan Brady1c142e12017-10-05 14:53:31 -0700918 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
919 supported,
920 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400921 hw->phy.link_info.phy_type !=
922 I40E_PHY_TYPE_10GBASE_T) {
923 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400924 err = -EINVAL;
925 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400926 }
927 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000928 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000929 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700930 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000931 }
932 }
933
Alan Bradycee91992017-10-05 14:53:44 -0700934 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
935 100baseT_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000936 config.link_speed |= I40E_LINK_SPEED_100MB;
Alan Bradycee91992017-10-05 14:53:44 -0700937 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
938 1000baseT_Full) ||
939 ethtool_link_ksettings_test_link_mode(ks, advertising,
940 1000baseX_Full) ||
941 ethtool_link_ksettings_test_link_mode(ks, advertising,
942 1000baseKX_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000943 config.link_speed |= I40E_LINK_SPEED_1GB;
Alan Bradycee91992017-10-05 14:53:44 -0700944 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
945 10000baseT_Full) ||
946 ethtool_link_ksettings_test_link_mode(ks, advertising,
947 10000baseKX4_Full) ||
948 ethtool_link_ksettings_test_link_mode(ks, advertising,
949 10000baseKR_Full) ||
950 ethtool_link_ksettings_test_link_mode(ks, advertising,
951 10000baseCR_Full) ||
952 ethtool_link_ksettings_test_link_mode(ks, advertising,
Jakub Pawlak6ee4d322018-04-20 01:41:35 -0700953 10000baseSR_Full) ||
954 ethtool_link_ksettings_test_link_mode(ks, advertising,
955 10000baseLR_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000956 config.link_speed |= I40E_LINK_SPEED_10GB;
Alan Bradycee91992017-10-05 14:53:44 -0700957 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
958 20000baseKR2_Full))
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700959 config.link_speed |= I40E_LINK_SPEED_20GB;
Alan Bradycee91992017-10-05 14:53:44 -0700960 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
961 25000baseCR_Full) ||
962 ethtool_link_ksettings_test_link_mode(ks, advertising,
963 25000baseKR_Full) ||
964 ethtool_link_ksettings_test_link_mode(ks, advertising,
965 25000baseSR_Full))
966 config.link_speed |= I40E_LINK_SPEED_25GB;
967 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
968 40000baseKR4_Full) ||
969 ethtool_link_ksettings_test_link_mode(ks, advertising,
970 40000baseCR4_Full) ||
971 ethtool_link_ksettings_test_link_mode(ks, advertising,
972 40000baseSR4_Full) ||
973 ethtool_link_ksettings_test_link_mode(ks, advertising,
974 40000baseLR4_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000975 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000976
Catherine Sullivan0002e112015-08-26 15:14:16 -0400977 /* If speed didn't get set, set it to what it currently is.
978 * This is needed because if advertise is 0 (as it is when autoneg
979 * is disabled) then speed won't get set.
980 */
981 if (!config.link_speed)
982 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -0700983 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000984 /* copy over the rest of the abilities */
985 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800986 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000987 config.eee_capability = abilities.eee_capability;
988 config.eeer = abilities.eeer_val;
989 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800990 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
991 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000992
Catherine Sullivane8278452015-02-06 08:52:08 +0000993 /* save the requested speeds */
994 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000995 /* set link and auto negotiation so changes take effect */
996 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
997 /* If link is up put link down */
998 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
999 /* Tell the OS link is going down, the link will go
1000 * back up when fw says it is ready asynchronously
1001 */
Matt Jaredc156f852015-08-27 11:42:39 -04001002 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001003 netif_carrier_off(netdev);
1004 netif_tx_stop_all_queues(netdev);
1005 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001006
1007 /* make the aq call */
1008 status = i40e_aq_set_phy_config(hw, &config, NULL);
1009 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001010 netdev_info(netdev,
1011 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001012 i40e_stat_str(hw, status),
1013 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001014 err = -EAGAIN;
1015 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001016 }
1017
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001018 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001019 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001020 netdev_dbg(netdev,
1021 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001022 i40e_stat_str(hw, status),
1023 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001024
1025 } else {
1026 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1027 }
1028
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001029done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001030 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001031
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001032 return err;
1033}
1034
Jesse Brandeburga6599722014-06-04 08:45:25 +00001035static int i40e_nway_reset(struct net_device *netdev)
1036{
1037 /* restart autonegotiation */
1038 struct i40e_netdev_priv *np = netdev_priv(netdev);
1039 struct i40e_pf *pf = np->vsi->back;
1040 struct i40e_hw *hw = &pf->hw;
1041 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1042 i40e_status ret = 0;
1043
1044 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1045 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001046 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1047 i40e_stat_str(hw, ret),
1048 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001049 return -EIO;
1050 }
1051
1052 return 0;
1053}
1054
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001055/**
1056 * i40e_get_pauseparam - Get Flow Control status
Jacob Kellerf5254422018-04-20 01:41:33 -07001057 * @netdev: netdevice structure
1058 * @pause: buffer to return pause parameters
1059 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001060 * Return tx/rx-pause status
1061 **/
1062static void i40e_get_pauseparam(struct net_device *netdev,
1063 struct ethtool_pauseparam *pause)
1064{
1065 struct i40e_netdev_priv *np = netdev_priv(netdev);
1066 struct i40e_pf *pf = np->vsi->back;
1067 struct i40e_hw *hw = &pf->hw;
1068 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001069 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001070
1071 pause->autoneg =
1072 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1073 AUTONEG_ENABLE : AUTONEG_DISABLE);
1074
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001075 /* PFC enabled so report LFC as off */
1076 if (dcbx_cfg->pfc.pfcenable) {
1077 pause->rx_pause = 0;
1078 pause->tx_pause = 0;
1079 return;
1080 }
1081
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001082 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001083 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001084 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001085 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001086 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1087 pause->rx_pause = 1;
1088 pause->tx_pause = 1;
1089 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001090}
1091
Catherine Sullivan2becc352014-06-04 08:45:27 +00001092/**
1093 * i40e_set_pauseparam - Set Flow Control parameter
1094 * @netdev: network interface device structure
1095 * @pause: return tx/rx flow control status
1096 **/
1097static int i40e_set_pauseparam(struct net_device *netdev,
1098 struct ethtool_pauseparam *pause)
1099{
1100 struct i40e_netdev_priv *np = netdev_priv(netdev);
1101 struct i40e_pf *pf = np->vsi->back;
1102 struct i40e_vsi *vsi = np->vsi;
1103 struct i40e_hw *hw = &pf->hw;
1104 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001105 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001106 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1107 i40e_status status;
1108 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001109 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001110
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001111 /* Changing the port's flow control is not supported if this isn't the
1112 * port's controlling PF
1113 */
1114 if (hw->partition_id != 1) {
1115 i40e_partition_setting_complaint(pf);
1116 return -EOPNOTSUPP;
1117 }
1118
Catherine Sullivan2becc352014-06-04 08:45:27 +00001119 if (vsi != pf->vsi[pf->lan_vsi])
1120 return -EOPNOTSUPP;
1121
1122 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1123 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1124 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1125 return -EOPNOTSUPP;
1126 }
1127
1128 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001129 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001130 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1131 /* Send message that it might not necessarily work*/
1132 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1133 }
1134
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001135 if (dcbx_cfg->pfc.pfcenable) {
1136 netdev_info(netdev,
1137 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001138 return -EOPNOTSUPP;
1139 }
1140
1141 if (pause->rx_pause && pause->tx_pause)
1142 hw->fc.requested_mode = I40E_FC_FULL;
1143 else if (pause->rx_pause && !pause->tx_pause)
1144 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1145 else if (!pause->rx_pause && pause->tx_pause)
1146 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1147 else if (!pause->rx_pause && !pause->tx_pause)
1148 hw->fc.requested_mode = I40E_FC_NONE;
1149 else
1150 return -EINVAL;
1151
Catherine Sullivan94128512014-07-12 07:28:16 +00001152 /* Tell the OS link is going down, the link will go back up when fw
1153 * says it is ready asynchronously
1154 */
Matt Jaredc156f852015-08-27 11:42:39 -04001155 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001156 netif_carrier_off(netdev);
1157 netif_tx_stop_all_queues(netdev);
1158
Catherine Sullivan2becc352014-06-04 08:45:27 +00001159 /* Set the fc mode and only restart an if link is up*/
1160 status = i40e_set_fc(hw, &aq_failures, link_up);
1161
1162 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001163 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1164 i40e_stat_str(hw, status),
1165 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001166 err = -EAGAIN;
1167 }
1168 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001169 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1170 i40e_stat_str(hw, status),
1171 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001172 err = -EAGAIN;
1173 }
1174 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001175 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1176 i40e_stat_str(hw, status),
1177 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001178 err = -EAGAIN;
1179 }
1180
Jacob Keller0da36b92017-04-19 09:25:55 -04001181 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001182 /* Give it a little more time to try to come back */
1183 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001184 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001185 return i40e_nway_reset(netdev);
1186 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001187
1188 return err;
1189}
1190
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001191static u32 i40e_get_msglevel(struct net_device *netdev)
1192{
1193 struct i40e_netdev_priv *np = netdev_priv(netdev);
1194 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001195 u32 debug_mask = pf->hw.debug_mask;
1196
1197 if (debug_mask)
1198 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001199
1200 return pf->msg_enable;
1201}
1202
1203static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1204{
1205 struct i40e_netdev_priv *np = netdev_priv(netdev);
1206 struct i40e_pf *pf = np->vsi->back;
1207
1208 if (I40E_DEBUG_USER & data)
1209 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001210 else
1211 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001212}
1213
1214static int i40e_get_regs_len(struct net_device *netdev)
1215{
1216 int reg_count = 0;
1217 int i;
1218
1219 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1220 reg_count += i40e_reg_list[i].elements;
1221
1222 return reg_count * sizeof(u32);
1223}
1224
1225static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1226 void *p)
1227{
1228 struct i40e_netdev_priv *np = netdev_priv(netdev);
1229 struct i40e_pf *pf = np->vsi->back;
1230 struct i40e_hw *hw = &pf->hw;
1231 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001232 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001233 u32 reg;
1234
1235 /* Tell ethtool which driver-version-specific regs output we have.
1236 *
1237 * At some point, if we have ethtool doing special formatting of
1238 * this data, it will rely on this version number to know how to
1239 * interpret things. Hence, this needs to be updated if/when the
1240 * diags register table is changed.
1241 */
1242 regs->version = 1;
1243
1244 /* loop through the diags reg table for what to print */
1245 ri = 0;
1246 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1247 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1248 reg = i40e_reg_list[i].offset
1249 + (j * i40e_reg_list[i].stride);
1250 reg_buf[ri++] = rd32(hw, reg);
1251 }
1252 }
1253
1254}
1255
1256static int i40e_get_eeprom(struct net_device *netdev,
1257 struct ethtool_eeprom *eeprom, u8 *bytes)
1258{
1259 struct i40e_netdev_priv *np = netdev_priv(netdev);
1260 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001261 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001262 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001263 u8 *eeprom_buff;
1264 u16 i, sectors;
1265 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001266 u32 magic;
1267
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001268#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 if (eeprom->len == 0)
1270 return -EINVAL;
1271
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001272 /* check for NVMUpdate access method */
1273 magic = hw->vendor_id | (hw->device_id << 16);
1274 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001275 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1276 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001277
1278 /* make sure it is the right magic for NVMUpdate */
1279 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001280 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001281 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1282 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001283 errno = -EBUSY;
1284 else
1285 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001286
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001287 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001288 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001289 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1290 ret_val, hw->aq.asq_last_status, errno,
1291 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1292 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001293
1294 return errno;
1295 }
1296
1297 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001298 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1299
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001300 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001301 if (!eeprom_buff)
1302 return -ENOMEM;
1303
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001304 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1305 if (ret_val) {
1306 dev_info(&pf->pdev->dev,
1307 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1308 ret_val, hw->aq.asq_last_status);
1309 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001310 }
1311
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001312 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1313 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1314 len = I40E_NVM_SECTOR_SIZE;
1315 last = false;
1316 for (i = 0; i < sectors; i++) {
1317 if (i == (sectors - 1)) {
1318 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1319 last = true;
1320 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001321 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1322 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001323 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001324 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001325 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001326 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001327 "read NVM failed, invalid offset 0x%x\n",
1328 offset);
1329 break;
1330 } else if (ret_val &&
1331 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1332 dev_info(&pf->pdev->dev,
1333 "read NVM failed, access, offset 0x%x\n",
1334 offset);
1335 break;
1336 } else if (ret_val) {
1337 dev_info(&pf->pdev->dev,
1338 "read NVM failed offset %d err=%d status=0x%x\n",
1339 offset, ret_val, hw->aq.asq_last_status);
1340 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001341 }
1342 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001343
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001344 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001345 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001346free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001347 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348 return ret_val;
1349}
1350
1351static int i40e_get_eeprom_len(struct net_device *netdev)
1352{
1353 struct i40e_netdev_priv *np = netdev_priv(netdev);
1354 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001355 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001356
Lihong Yangc271dd62017-01-30 12:29:32 -08001357#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1358 if (hw->mac.type == I40E_MAC_X722) {
1359 val = X722_EEPROM_SCOPE_LIMIT + 1;
1360 return val;
1361 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001362 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1363 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1364 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1365 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001366 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001367 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001368}
1369
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001370static int i40e_set_eeprom(struct net_device *netdev,
1371 struct ethtool_eeprom *eeprom, u8 *bytes)
1372{
1373 struct i40e_netdev_priv *np = netdev_priv(netdev);
1374 struct i40e_hw *hw = &np->vsi->back->hw;
1375 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001376 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001377 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001378 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001379 u32 magic;
1380
1381 /* normal ethtool set_eeprom is not supported */
1382 magic = hw->vendor_id | (hw->device_id << 16);
1383 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001384 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001385 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001386 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1387 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001388 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1389 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001390 errno = -EBUSY;
1391 else
1392 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001393
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001394 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001395 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001396 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1397 ret_val, hw->aq.asq_last_status, errno,
1398 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1399 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001400
1401 return errno;
1402}
1403
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001404static void i40e_get_drvinfo(struct net_device *netdev,
1405 struct ethtool_drvinfo *drvinfo)
1406{
1407 struct i40e_netdev_priv *np = netdev_priv(netdev);
1408 struct i40e_vsi *vsi = np->vsi;
1409 struct i40e_pf *pf = vsi->back;
1410
1411 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1412 strlcpy(drvinfo->version, i40e_driver_version_str,
1413 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001414 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001415 sizeof(drvinfo->fw_version));
1416 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1417 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001418 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001419 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001420 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001421}
1422
1423static void i40e_get_ringparam(struct net_device *netdev,
1424 struct ethtool_ringparam *ring)
1425{
1426 struct i40e_netdev_priv *np = netdev_priv(netdev);
1427 struct i40e_pf *pf = np->vsi->back;
1428 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1429
1430 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1431 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1432 ring->rx_mini_max_pending = 0;
1433 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001434 ring->rx_pending = vsi->rx_rings[0]->count;
1435 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001436 ring->rx_mini_pending = 0;
1437 ring->rx_jumbo_pending = 0;
1438}
1439
Björn Töpel74608d12017-05-24 07:55:35 +02001440static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1441{
1442 if (i40e_enabled_xdp_vsi(vsi)) {
1443 return index < vsi->num_queue_pairs ||
1444 (index >= vsi->alloc_queue_pairs &&
1445 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1446 }
1447
1448 return index < vsi->num_queue_pairs;
1449}
1450
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001451static int i40e_set_ringparam(struct net_device *netdev,
1452 struct ethtool_ringparam *ring)
1453{
1454 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1455 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001456 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001457 struct i40e_vsi *vsi = np->vsi;
1458 struct i40e_pf *pf = vsi->back;
1459 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001460 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001461 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001462 int i, err = 0;
1463
1464 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1465 return -EINVAL;
1466
Shannon Nelson1fa18372013-11-20 10:03:08 +00001467 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1468 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1469 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1470 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1471 netdev_info(netdev,
1472 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1473 ring->tx_pending, ring->rx_pending,
1474 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1475 return -EINVAL;
1476 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001477
Shannon Nelson1fa18372013-11-20 10:03:08 +00001478 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1479 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001480
1481 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001482 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1483 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001484 return 0;
1485
Jacob Keller0da36b92017-04-19 09:25:55 -04001486 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001487 timeout--;
1488 if (!timeout)
1489 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001490 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001491 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001492
1493 if (!netif_running(vsi->netdev)) {
1494 /* simple case - set for the next time the netdev is started */
1495 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001496 vsi->tx_rings[i]->count = new_tx_count;
1497 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001498 if (i40e_enabled_xdp_vsi(vsi))
1499 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500 }
1501 goto done;
1502 }
1503
1504 /* We can't just free everything and then setup again,
1505 * because the ISRs in MSI-X mode get passed pointers
1506 * to the Tx and Rx ring structs.
1507 */
1508
Björn Töpel74608d12017-05-24 07:55:35 +02001509 /* alloc updated Tx and XDP Tx resources */
1510 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1511 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001512 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001513 netdev_info(netdev,
1514 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001515 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001516 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001517 sizeof(struct i40e_ring), GFP_KERNEL);
1518 if (!tx_rings) {
1519 err = -ENOMEM;
1520 goto done;
1521 }
1522
Björn Töpel74608d12017-05-24 07:55:35 +02001523 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1524 if (!i40e_active_tx_ring_index(vsi, i))
1525 continue;
1526
Alexander Duyck9f65e152013-09-28 06:00:58 +00001527 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001528 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001529 /* the desc and bi pointers will be reallocated in the
1530 * setup call
1531 */
1532 tx_rings[i].desc = NULL;
1533 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001534 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1535 if (err) {
1536 while (i) {
1537 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001538 if (!i40e_active_tx_ring_index(vsi, i))
1539 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001540 i40e_free_tx_resources(&tx_rings[i]);
1541 }
1542 kfree(tx_rings);
1543 tx_rings = NULL;
1544
1545 goto done;
1546 }
1547 }
1548 }
1549
1550 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001551 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001552 netdev_info(netdev,
1553 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001554 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001555 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1556 sizeof(struct i40e_ring), GFP_KERNEL);
1557 if (!rx_rings) {
1558 err = -ENOMEM;
1559 goto free_tx;
1560 }
1561
1562 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001563 struct i40e_ring *ring;
1564 u16 unused;
1565
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001566 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001567 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001568 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001569 /* the desc and bi pointers will be reallocated in the
1570 * setup call
1571 */
1572 rx_rings[i].desc = NULL;
1573 rx_rings[i].rx_bi = NULL;
Jesper Dangaard Brouer87128822018-01-03 11:25:23 +01001574 /* Clear cloned XDP RX-queue info before setup call */
1575 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
Tushar Dave2f7679e2016-10-26 10:49:27 -07001576 /* this is to allow wr32 to have something to write to
1577 * during early allocation of Rx buffers
1578 */
1579 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001581 if (err)
1582 goto rx_unwind;
1583
1584 /* now allocate the Rx buffers to make sure the OS
1585 * has enough memory, any failure here means abort
1586 */
1587 ring = &rx_rings[i];
1588 unused = I40E_DESC_UNUSED(ring);
1589 err = i40e_alloc_rx_buffers(ring, unused);
1590rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001591 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001592 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001593 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001594 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001595 kfree(rx_rings);
1596 rx_rings = NULL;
1597
1598 goto free_tx;
1599 }
1600 }
1601 }
1602
1603 /* Bring interface down, copy in the new ring info,
1604 * then restore the interface
1605 */
1606 i40e_down(vsi);
1607
1608 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001609 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1610 if (i40e_active_tx_ring_index(vsi, i)) {
1611 i40e_free_tx_resources(vsi->tx_rings[i]);
1612 *vsi->tx_rings[i] = tx_rings[i];
1613 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001614 }
1615 kfree(tx_rings);
1616 tx_rings = NULL;
1617 }
1618
1619 if (rx_rings) {
1620 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001621 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001622 /* get the real tail offset */
1623 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1624 /* this is to fake out the allocation routine
1625 * into thinking it has to realloc everything
1626 * but the recycling logic will let us re-use
1627 * the buffers allocated above
1628 */
1629 rx_rings[i].next_to_use = 0;
1630 rx_rings[i].next_to_clean = 0;
1631 rx_rings[i].next_to_alloc = 0;
1632 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001633 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001634 }
1635 kfree(rx_rings);
1636 rx_rings = NULL;
1637 }
1638
1639 i40e_up(vsi);
1640
1641free_tx:
1642 /* error cleanup if the Rx allocations failed after getting Tx */
1643 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001644 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1645 if (i40e_active_tx_ring_index(vsi, i))
1646 i40e_free_tx_resources(vsi->tx_rings[i]);
1647 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001648 kfree(tx_rings);
1649 tx_rings = NULL;
1650 }
1651
1652done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001653 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001654
1655 return err;
1656}
1657
Jacob Keller0ded9c62018-05-10 05:59:41 -07001658static int i40e_get_stats_count(struct net_device *netdev)
1659{
1660 struct i40e_netdev_priv *np = netdev_priv(netdev);
1661 struct i40e_vsi *vsi = np->vsi;
1662 struct i40e_pf *pf = vsi->back;
1663
1664 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
1665 if (pf->lan_veb != I40E_NO_VEB &&
1666 pf->flags & I40E_FLAG_VEB_STATS_ENABLED)
1667 return I40E_PF_STATS_LEN(netdev) + I40E_VEB_STATS_TOTAL;
1668 else
1669 return I40E_PF_STATS_LEN(netdev);
1670 } else {
1671 return I40E_VSI_STATS_LEN(netdev);
1672 }
1673}
1674
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001675static int i40e_get_sset_count(struct net_device *netdev, int sset)
1676{
1677 struct i40e_netdev_priv *np = netdev_priv(netdev);
1678 struct i40e_vsi *vsi = np->vsi;
1679 struct i40e_pf *pf = vsi->back;
1680
1681 switch (sset) {
1682 case ETH_SS_TEST:
1683 return I40E_TEST_LEN;
1684 case ETH_SS_STATS:
Jacob Keller0ded9c62018-05-10 05:59:41 -07001685 return i40e_get_stats_count(netdev);
Greg Rose7e45ab42015-02-06 08:52:19 +00001686 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001687 return I40E_PRIV_FLAGS_STR_LEN +
1688 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001689 default:
1690 return -EOPNOTSUPP;
1691 }
1692}
1693
1694static void i40e_get_ethtool_stats(struct net_device *netdev,
1695 struct ethtool_stats *stats, u64 *data)
1696{
1697 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001698 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001699 struct i40e_vsi *vsi = np->vsi;
1700 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001701 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001702 int i = 0;
1703 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001704 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001705 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001706
1707 i40e_update_stats(vsi);
1708
1709 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1710 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1711 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1712 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1713 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001714 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1715 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1716 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1717 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1718 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001719 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001720 for (j = 0; j < vsi->num_queue_pairs; j++) {
Mark Rutland6aa7de02017-10-23 14:07:29 -07001721 tx_ring = READ_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001722
1723 if (!tx_ring)
1724 continue;
1725
1726 /* process Tx ring statistics */
1727 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001728 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001729 data[i] = tx_ring->stats.packets;
1730 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001731 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001732 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001733
1734 /* Rx ring is the 2nd half of the queue pair */
1735 rx_ring = &tx_ring[1];
1736 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001737 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001738 data[i] = rx_ring->stats.packets;
1739 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001740 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001741 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001742 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001743 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001744 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001745 return;
1746
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001747 if ((pf->lan_veb != I40E_NO_VEB) &&
1748 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001749 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001750
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001751 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1752 p = (char *)veb;
1753 p += i40e_gstrings_veb_stats[j].stat_offset;
1754 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1755 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001756 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001757 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1758 data[i++] = veb->tc_stats.tc_tx_packets[j];
1759 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1760 data[i++] = veb->tc_stats.tc_rx_packets[j];
1761 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1762 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001763 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001764 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1765 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1766 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1767 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1768 }
1769 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1770 data[i++] = pf->stats.priority_xon_tx[j];
1771 data[i++] = pf->stats.priority_xoff_tx[j];
1772 }
1773 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1774 data[i++] = pf->stats.priority_xon_rx[j];
1775 data[i++] = pf->stats.priority_xoff_rx[j];
1776 }
1777 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1778 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001779}
1780
1781static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1782 u8 *data)
1783{
1784 struct i40e_netdev_priv *np = netdev_priv(netdev);
1785 struct i40e_vsi *vsi = np->vsi;
1786 struct i40e_pf *pf = vsi->back;
1787 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001788 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001789
1790 switch (stringset) {
1791 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001792 memcpy(data, i40e_gstrings_test,
1793 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001794 break;
1795 case ETH_SS_STATS:
1796 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1797 snprintf(p, ETH_GSTRING_LEN, "%s",
1798 i40e_gstrings_net_stats[i].stat_string);
1799 p += ETH_GSTRING_LEN;
1800 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001801 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1802 snprintf(p, ETH_GSTRING_LEN, "%s",
1803 i40e_gstrings_misc_stats[i].stat_string);
1804 p += ETH_GSTRING_LEN;
1805 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001806 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001807 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001808 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001809 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001810 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001811 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001812 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001813 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001814 p += ETH_GSTRING_LEN;
1815 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001816 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001817 return;
1818
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001819 if ((pf->lan_veb != I40E_NO_VEB) &&
1820 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001821 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1822 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1823 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001824 p += ETH_GSTRING_LEN;
1825 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001826 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1827 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001828 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001829 p += ETH_GSTRING_LEN;
1830 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001831 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001832 p += ETH_GSTRING_LEN;
1833 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001834 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001835 p += ETH_GSTRING_LEN;
1836 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001837 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001838 p += ETH_GSTRING_LEN;
1839 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001840 }
1841 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1842 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1843 i40e_gstrings_stats[i].stat_string);
1844 p += ETH_GSTRING_LEN;
1845 }
1846 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1847 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001848 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001849 p += ETH_GSTRING_LEN;
1850 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001851 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001852 p += ETH_GSTRING_LEN;
1853 }
1854 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1855 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001856 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001857 p += ETH_GSTRING_LEN;
1858 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001859 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001860 p += ETH_GSTRING_LEN;
1861 }
1862 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1863 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001864 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001865 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001866 }
1867 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1868 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001869 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001870 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1871 snprintf(p, ETH_GSTRING_LEN, "%s",
1872 i40e_gstrings_priv_flags[i].flag_string);
1873 p += ETH_GSTRING_LEN;
1874 }
1875 if (pf->hw.pf_id != 0)
1876 break;
1877 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1878 snprintf(p, ETH_GSTRING_LEN, "%s",
1879 i40e_gl_gstrings_priv_flags[i].flag_string);
1880 p += ETH_GSTRING_LEN;
1881 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001882 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001883 default:
1884 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001885 }
1886}
1887
1888static int i40e_get_ts_info(struct net_device *dev,
1889 struct ethtool_ts_info *info)
1890{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001891 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1892
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001893 /* only report HW timestamping if PTP is enabled */
1894 if (!(pf->flags & I40E_FLAG_PTP))
1895 return ethtool_op_get_ts_info(dev, info);
1896
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001897 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1898 SOF_TIMESTAMPING_RX_SOFTWARE |
1899 SOF_TIMESTAMPING_SOFTWARE |
1900 SOF_TIMESTAMPING_TX_HARDWARE |
1901 SOF_TIMESTAMPING_RX_HARDWARE |
1902 SOF_TIMESTAMPING_RAW_HARDWARE;
1903
1904 if (pf->ptp_clock)
1905 info->phc_index = ptp_clock_index(pf->ptp_clock);
1906 else
1907 info->phc_index = -1;
1908
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001909 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001910
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001911 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001912 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1913 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1914 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1915
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001916 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001917 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1918 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1919 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1920 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1921 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1922 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1923 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1924 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001925
1926 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001927}
1928
Shannon Nelson7b086392013-11-20 10:02:59 +00001929static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930{
Shannon Nelson7b086392013-11-20 10:02:59 +00001931 struct i40e_netdev_priv *np = netdev_priv(netdev);
1932 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001933 i40e_status status;
1934 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001935
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001936 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001937 status = i40e_get_link_status(&pf->hw, &link_up);
1938 if (status) {
1939 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1940 *data = 1;
1941 return *data;
1942 }
1943
1944 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001945 *data = 0;
1946 else
1947 *data = 1;
1948
1949 return *data;
1950}
1951
Shannon Nelson7b086392013-11-20 10:02:59 +00001952static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001953{
Shannon Nelson7b086392013-11-20 10:02:59 +00001954 struct i40e_netdev_priv *np = netdev_priv(netdev);
1955 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001956
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001957 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001958 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001959
Shannon Nelson7b086392013-11-20 10:02:59 +00001960 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001961}
1962
Shannon Nelson7b086392013-11-20 10:02:59 +00001963static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001964{
Shannon Nelson7b086392013-11-20 10:02:59 +00001965 struct i40e_netdev_priv *np = netdev_priv(netdev);
1966 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001967
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001968 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001969 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001970
Shannon Nelson4443ec92014-11-13 08:23:12 +00001971 /* forcebly clear the NVM Update state machine */
1972 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1973
Shannon Nelson7b086392013-11-20 10:02:59 +00001974 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001975}
1976
Shannon Nelson7b086392013-11-20 10:02:59 +00001977static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001978{
Shannon Nelson7b086392013-11-20 10:02:59 +00001979 struct i40e_netdev_priv *np = netdev_priv(netdev);
1980 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001981 u16 swc_old = pf->sw_int_count;
1982
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001983 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001984 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1985 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001986 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1987 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1988 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1989 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001990 usleep_range(1000, 2000);
1991 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001992
1993 return *data;
1994}
1995
Greg Rosee17bc412015-04-16 20:05:59 -04001996static inline bool i40e_active_vfs(struct i40e_pf *pf)
1997{
1998 struct i40e_vf *vfs = pf->vf;
1999 int i;
2000
2001 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04002002 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04002003 return true;
2004 return false;
2005}
2006
Greg Rose510efb22015-07-10 19:36:01 -04002007static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2008{
Alexander Duyck4b816442016-10-11 15:26:53 -07002009 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04002010}
2011
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002012static void i40e_diag_test(struct net_device *netdev,
2013 struct ethtool_test *eth_test, u64 *data)
2014{
2015 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002016 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002017 struct i40e_pf *pf = np->vsi->back;
2018
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002019 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2020 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002021 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002022
Jacob Keller0da36b92017-04-19 09:25:55 -04002023 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002024
Greg Rose510efb22015-07-10 19:36:01 -04002025 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002026 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002027 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002028 data[I40E_ETH_TEST_REG] = 1;
2029 data[I40E_ETH_TEST_EEPROM] = 1;
2030 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002031 data[I40E_ETH_TEST_LINK] = 1;
2032 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002033 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002034 goto skip_ol_tests;
2035 }
2036
Greg Rose5b86c5c2015-02-26 16:14:35 +00002037 /* If the device is online then take it offline */
2038 if (if_running)
2039 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002040 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002041 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002042 /* This reset does not affect link - if it is
2043 * changed to a type of reset that does affect
2044 * link then the following link test would have
2045 * to be moved to before the reset
2046 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002047 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002048
Shannon Nelson7b086392013-11-20 10:02:59 +00002049 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002050 eth_test->flags |= ETH_TEST_FL_FAILED;
2051
Shannon Nelson7b086392013-11-20 10:02:59 +00002052 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002053 eth_test->flags |= ETH_TEST_FL_FAILED;
2054
Shannon Nelson7b086392013-11-20 10:02:59 +00002055 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002056 eth_test->flags |= ETH_TEST_FL_FAILED;
2057
Shannon Nelsonf551b432013-11-26 10:49:12 +00002058 /* run reg test last, a reset is required after it */
2059 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2060 eth_test->flags |= ETH_TEST_FL_FAILED;
2061
Jacob Keller0da36b92017-04-19 09:25:55 -04002062 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002063 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002064
2065 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002066 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002067 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002068 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002069 netif_info(pf, drv, netdev, "online testing starting\n");
2070
Shannon Nelson7b086392013-11-20 10:02:59 +00002071 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002072 eth_test->flags |= ETH_TEST_FL_FAILED;
2073
2074 /* Offline only tests, not run in online; pass by default */
2075 data[I40E_ETH_TEST_REG] = 0;
2076 data[I40E_ETH_TEST_EEPROM] = 0;
2077 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002078 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002079
Greg Rosee17bc412015-04-16 20:05:59 -04002080skip_ol_tests:
2081
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002082 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002083}
2084
2085static void i40e_get_wol(struct net_device *netdev,
2086 struct ethtool_wolinfo *wol)
2087{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002088 struct i40e_netdev_priv *np = netdev_priv(netdev);
2089 struct i40e_pf *pf = np->vsi->back;
2090 struct i40e_hw *hw = &pf->hw;
2091 u16 wol_nvm_bits;
2092
2093 /* NVM bit on means WoL disabled for the port */
2094 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002095 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002096 wol->supported = 0;
2097 wol->wolopts = 0;
2098 } else {
2099 wol->supported = WAKE_MAGIC;
2100 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2101 }
2102}
2103
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002104/**
2105 * i40e_set_wol - set the WakeOnLAN configuration
2106 * @netdev: the netdev in question
2107 * @wol: the ethtool WoL setting data
2108 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002109static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2110{
2111 struct i40e_netdev_priv *np = netdev_priv(netdev);
2112 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002113 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002114 struct i40e_hw *hw = &pf->hw;
2115 u16 wol_nvm_bits;
2116
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002117 /* WoL not supported if this isn't the controlling PF on the port */
2118 if (hw->partition_id != 1) {
2119 i40e_partition_setting_complaint(pf);
2120 return -EOPNOTSUPP;
2121 }
2122
2123 if (vsi != pf->vsi[pf->lan_vsi])
2124 return -EOPNOTSUPP;
2125
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002126 /* NVM bit on means WoL disabled for the port */
2127 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002128 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002129 return -EOPNOTSUPP;
2130
2131 /* only magic packet is supported */
2132 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2133 return -EOPNOTSUPP;
2134
2135 /* is this a new value? */
2136 if (pf->wol_en != !!wol->wolopts) {
2137 pf->wol_en = !!wol->wolopts;
2138 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2139 }
2140
2141 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142}
2143
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002144static int i40e_set_phys_id(struct net_device *netdev,
2145 enum ethtool_phys_id_state state)
2146{
2147 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002148 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002149 struct i40e_pf *pf = np->vsi->back;
2150 struct i40e_hw *hw = &pf->hw;
2151 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002152 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002153
2154 switch (state) {
2155 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002156 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002157 pf->led_status = i40e_led_get(hw);
2158 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002159 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2160 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2161 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002162 ret = i40e_led_get_phy(hw, &temp_status,
2163 &pf->phy_led_val);
2164 pf->led_status = temp_status;
2165 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002166 return blink_freq;
2167 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002168 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002169 i40e_led_set(hw, 0xf, false);
2170 else
2171 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002172 break;
2173 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002174 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002175 i40e_led_set(hw, 0x0, false);
2176 else
2177 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002178 break;
2179 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002180 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002181 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002182 } else {
2183 ret = i40e_led_set_phy(hw, false, pf->led_status,
2184 (pf->phy_led_val |
2185 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002186 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2187 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002188 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002189 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002190 default:
2191 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002192 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002193 if (ret)
2194 return -ENOENT;
2195 else
2196 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002197}
2198
2199/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2200 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2201 * 125us (8000 interrupts per second) == ITR(62)
2202 */
2203
Jacob Keller65e87c02016-09-12 14:18:44 -07002204/**
2205 * __i40e_get_coalesce - get per-queue coalesce settings
2206 * @netdev: the netdev to check
2207 * @ec: ethtool coalesce data structure
2208 * @queue: which queue to pick
2209 *
2210 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2211 * are per queue. If queue is <0 then we default to queue 0 as the
2212 * representative value.
2213 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002214static int __i40e_get_coalesce(struct net_device *netdev,
2215 struct ethtool_coalesce *ec,
2216 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002217{
2218 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002219 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002220 struct i40e_vsi *vsi = np->vsi;
2221
2222 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2223 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2224
Alan Bradya03af692017-10-05 14:53:37 -07002225 /* rx and tx usecs has per queue value. If user doesn't specify the
2226 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002227 */
Alan Bradya03af692017-10-05 14:53:37 -07002228 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002229 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002230 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002231 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002232
Jacob Keller65e87c02016-09-12 14:18:44 -07002233 rx_ring = vsi->rx_rings[queue];
2234 tx_ring = vsi->tx_rings[queue];
2235
Alexander Duyck40588ca2017-12-29 08:49:28 -05002236 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002237 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002238
Alexander Duyck40588ca2017-12-29 08:49:28 -05002239 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002240 ec->use_adaptive_tx_coalesce = 1;
2241
Alexander Duyck40588ca2017-12-29 08:49:28 -05002242 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2243 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
Jacob Keller65e87c02016-09-12 14:18:44 -07002244
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002245 /* we use the _usecs_high to store/set the interrupt rate limit
2246 * that the hardware supports, that almost but not quite
2247 * fits the original intent of the ethtool variable,
2248 * the rx_coalesce_usecs_high limits total interrupts
2249 * per second from both tx/rx sources.
2250 */
2251 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2252 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002253
2254 return 0;
2255}
2256
Jacob Keller65e87c02016-09-12 14:18:44 -07002257/**
2258 * i40e_get_coalesce - get a netdev's coalesce settings
2259 * @netdev: the netdev to check
2260 * @ec: ethtool coalesce data structure
2261 *
2262 * Gets the coalesce settings for a particular netdev. Note that if user has
2263 * modified per-queue settings, this only guarantees to represent queue 0. See
2264 * __i40e_get_coalesce for more details.
2265 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002266static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002267 struct ethtool_coalesce *ec)
2268{
Kan Lianga75e8002016-02-19 09:24:04 -05002269 return __i40e_get_coalesce(netdev, ec, -1);
2270}
2271
Jacob Keller65e87c02016-09-12 14:18:44 -07002272/**
2273 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2274 * @netdev: netdev structure
2275 * @ec: ethtool's coalesce settings
2276 * @queue: the particular queue to read
2277 *
2278 * Will read a specific queue's coalesce settings
2279 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002280static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2281 struct ethtool_coalesce *ec)
2282{
2283 return __i40e_get_coalesce(netdev, ec, queue);
2284}
2285
Jacob Keller65e87c02016-09-12 14:18:44 -07002286/**
2287 * i40e_set_itr_per_queue - set ITR values for specific queue
2288 * @vsi: the VSI to set values for
2289 * @ec: coalesce settings from ethtool
2290 * @queue: the queue to modify
2291 *
2292 * Change the ITR settings for a specific queue.
2293 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002294static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2295 struct ethtool_coalesce *ec,
2296 int queue)
2297{
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002298 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2299 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002300 struct i40e_pf *pf = vsi->back;
2301 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002302 struct i40e_q_vector *q_vector;
Alexander Duyck8b99b112017-12-29 08:50:44 -05002303 u16 intrl;
Kan Lianga75e8002016-02-19 09:24:04 -05002304
Alan Brady1c0e6a32016-11-28 16:06:02 -08002305 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002306
Alexander Duyck92418fb2017-12-29 08:51:08 -05002307 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2308 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
Kan Lianga75e8002016-02-19 09:24:04 -05002309
2310 if (ec->use_adaptive_rx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002311 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002312 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002313 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002314
2315 if (ec->use_adaptive_tx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002316 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002317 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002318 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002319
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002320 q_vector = rx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002321 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
Kan Lianga75e8002016-02-19 09:24:04 -05002322
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002323 q_vector = tx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002324 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2325
2326 /* The interrupt handler itself will take care of programming
2327 * the Tx and Rx ITR values based on the values we have entered
2328 * into the q_vector, no need to write the values now.
2329 */
Kan Lianga75e8002016-02-19 09:24:04 -05002330
Alexander Duyck8b99b112017-12-29 08:50:44 -05002331 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
Kan Lianga75e8002016-02-19 09:24:04 -05002332 i40e_flush(hw);
2333}
2334
Jacob Keller65e87c02016-09-12 14:18:44 -07002335/**
2336 * __i40e_set_coalesce - set coalesce settings for particular queue
2337 * @netdev: the netdev to change
2338 * @ec: ethtool coalesce settings
2339 * @queue: the queue to change
2340 *
2341 * Sets the coalesce settings for a particular queue.
2342 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002343static int __i40e_set_coalesce(struct net_device *netdev,
2344 struct ethtool_coalesce *ec,
2345 int queue)
2346{
2347 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002348 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002349 struct i40e_vsi *vsi = np->vsi;
2350 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002351 int i;
2352
2353 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2354 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2355
Alan Brady06b2dec2017-07-12 05:46:06 -04002356 if (queue < 0) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002357 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2358 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002359 } else if (queue < vsi->num_queue_pairs) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002360 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2361 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002362 } else {
2363 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2364 vsi->num_queue_pairs - 1);
2365 return -EINVAL;
2366 }
2367
2368 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2369 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2370
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002371 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2372 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2373 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2374 return -EINVAL;
2375 }
2376
Alan Brady33084062016-11-28 16:06:03 -08002377 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2378 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2379 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002380 return -EINVAL;
2381 }
2382
Alan Brady06b2dec2017-07-12 05:46:06 -04002383 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2384 ec->use_adaptive_rx_coalesce) {
2385 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2386 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002387 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002388
Alexander Duyck92418fb2017-12-29 08:51:08 -05002389 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002390 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2391 return -EINVAL;
2392 }
2393
2394 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2395 ec->use_adaptive_tx_coalesce) {
2396 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2397 return -EINVAL;
2398 }
2399
Alexander Duyck92418fb2017-12-29 08:51:08 -05002400 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002401 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2402 return -EINVAL;
2403 }
2404
2405 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002406 ec->rx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002407
2408 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002409 ec->tx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002410
Alan Brady33084062016-11-28 16:06:03 -08002411 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2412 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2413 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2414 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2415 vsi->int_rate_limit);
2416 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002417
Alan Bradya03af692017-10-05 14:53:37 -07002418 /* rx and tx usecs has per queue value. If user doesn't specify the
2419 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002420 */
2421 if (queue < 0) {
2422 for (i = 0; i < vsi->num_queue_pairs; i++)
2423 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002424 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002425 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002426 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002427
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002428 return 0;
2429}
2430
Jacob Keller65e87c02016-09-12 14:18:44 -07002431/**
2432 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2433 * @netdev: the netdev to change
2434 * @ec: ethtool coalesce settings
2435 *
2436 * This will set each queue to the same coalesce settings.
2437 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002438static int i40e_set_coalesce(struct net_device *netdev,
2439 struct ethtool_coalesce *ec)
2440{
2441 return __i40e_set_coalesce(netdev, ec, -1);
2442}
2443
Jacob Keller65e87c02016-09-12 14:18:44 -07002444/**
2445 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2446 * @netdev: the netdev to change
2447 * @ec: ethtool's coalesce settings
2448 * @queue: the queue to change
2449 *
2450 * Sets the specified queue's coalesce settings.
2451 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002452static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2453 struct ethtool_coalesce *ec)
2454{
2455 return __i40e_set_coalesce(netdev, ec, queue);
2456}
2457
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002458/**
2459 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2460 * @pf: pointer to the physical function struct
2461 * @cmd: ethtool rxnfc command
2462 *
2463 * Returns Success if the flow is supported, else Invalid Input.
2464 **/
2465static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2466{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002467 struct i40e_hw *hw = &pf->hw;
2468 u8 flow_pctype = 0;
2469 u64 i_set = 0;
2470
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002471 cmd->data = 0;
2472
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002473 switch (cmd->flow_type) {
2474 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002475 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2476 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002477 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002478 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2479 break;
2480 case TCP_V6_FLOW:
2481 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2482 break;
2483 case UDP_V6_FLOW:
2484 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2485 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002486 case SCTP_V4_FLOW:
2487 case AH_ESP_V4_FLOW:
2488 case AH_V4_FLOW:
2489 case ESP_V4_FLOW:
2490 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002491 case SCTP_V6_FLOW:
2492 case AH_ESP_V6_FLOW:
2493 case AH_V6_FLOW:
2494 case ESP_V6_FLOW:
2495 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002496 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002497 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2498 break;
2499 default:
2500 return -EINVAL;
2501 }
2502
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002503 /* Read flow based hash input set register */
2504 if (flow_pctype) {
2505 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2506 flow_pctype)) |
2507 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2508 flow_pctype)) << 32);
2509 }
2510
2511 /* Process bits of hash input set */
2512 if (i_set) {
2513 if (i_set & I40E_L4_SRC_MASK)
2514 cmd->data |= RXH_L4_B_0_1;
2515 if (i_set & I40E_L4_DST_MASK)
2516 cmd->data |= RXH_L4_B_2_3;
2517
2518 if (cmd->flow_type == TCP_V4_FLOW ||
2519 cmd->flow_type == UDP_V4_FLOW) {
2520 if (i_set & I40E_L3_SRC_MASK)
2521 cmd->data |= RXH_IP_SRC;
2522 if (i_set & I40E_L3_DST_MASK)
2523 cmd->data |= RXH_IP_DST;
2524 } else if (cmd->flow_type == TCP_V6_FLOW ||
2525 cmd->flow_type == UDP_V6_FLOW) {
2526 if (i_set & I40E_L3_V6_SRC_MASK)
2527 cmd->data |= RXH_IP_SRC;
2528 if (i_set & I40E_L3_V6_DST_MASK)
2529 cmd->data |= RXH_IP_DST;
2530 }
2531 }
2532
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002533 return 0;
2534}
2535
2536/**
Jacob Kellere7930952017-02-06 14:38:49 -08002537 * i40e_check_mask - Check whether a mask field is set
2538 * @mask: the full mask value
Jacob Kellerf5254422018-04-20 01:41:33 -07002539 * @field: mask of the field to check
Jacob Kellere7930952017-02-06 14:38:49 -08002540 *
2541 * If the given mask is fully set, return positive value. If the mask for the
2542 * field is fully unset, return zero. Otherwise return a negative error code.
2543 **/
2544static int i40e_check_mask(u64 mask, u64 field)
2545{
2546 u64 value = mask & field;
2547
2548 if (value == field)
2549 return 1;
2550 else if (!value)
2551 return 0;
2552 else
2553 return -1;
2554}
2555
2556/**
2557 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2558 * @fsp: pointer to rx flow specification
2559 * @data: pointer to userdef data structure for storage
2560 *
2561 * Read the user-defined data and deconstruct the value into a structure. No
2562 * other code should read the user-defined data, so as to ensure that every
2563 * place consistently reads the value correctly.
2564 *
2565 * The user-defined field is a 64bit Big Endian format value, which we
2566 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2567 * be defined starting from the highest bits, while small bit field values
2568 * shall be defined starting from the lowest bits.
2569 *
2570 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2571 * and the filter should be rejected. The data structure will always be
2572 * modified even if FLOW_EXT is not set.
2573 *
2574 **/
2575static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2576 struct i40e_rx_flow_userdef *data)
2577{
2578 u64 value, mask;
2579 int valid;
2580
2581 /* Zero memory first so it's always consistent. */
2582 memset(data, 0, sizeof(*data));
2583
2584 if (!(fsp->flow_type & FLOW_EXT))
2585 return 0;
2586
2587 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2588 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2589
2590#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2591#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2592#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2593
2594 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2595 if (valid < 0) {
2596 return -EINVAL;
2597 } else if (valid) {
2598 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2599 data->flex_offset =
2600 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2601 data->flex_filter = true;
2602 }
2603
2604 return 0;
2605}
2606
2607/**
2608 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2609 * @fsp: pointer to rx_flow specification
Jacob Kellerf5254422018-04-20 01:41:33 -07002610 * @data: pointer to return userdef data
Jacob Kellere7930952017-02-06 14:38:49 -08002611 *
2612 * Reads the userdef data structure and properly fills in the user defined
2613 * fields of the rx_flow_spec.
2614 **/
2615static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2616 struct i40e_rx_flow_userdef *data)
2617{
2618 u64 value = 0, mask = 0;
2619
2620 if (data->flex_filter) {
2621 value |= data->flex_word;
2622 value |= (u64)data->flex_offset << 16;
2623 mask |= I40E_USERDEF_FLEX_FILTER;
2624 }
2625
2626 if (value || mask)
2627 fsp->flow_type |= FLOW_EXT;
2628
2629 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2630 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2631}
2632
2633/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002634 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2635 * @pf: Pointer to the physical function struct
2636 * @cmd: The command to get or set Rx flow classification rules
2637 * @rule_locs: Array of used rule locations
2638 *
2639 * This function populates both the total and actual rule count of
2640 * the ethtool flow classification command
2641 *
2642 * Returns 0 on success or -EMSGSIZE if entry not found
2643 **/
2644static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2645 struct ethtool_rxnfc *cmd,
2646 u32 *rule_locs)
2647{
2648 struct i40e_fdir_filter *rule;
2649 struct hlist_node *node2;
2650 int cnt = 0;
2651
2652 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002653 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002654
2655 hlist_for_each_entry_safe(rule, node2,
2656 &pf->fdir_filter_list, fdir_node) {
2657 if (cnt == cmd->rule_cnt)
2658 return -EMSGSIZE;
2659
2660 rule_locs[cnt] = rule->fd_id;
2661 cnt++;
2662 }
2663
2664 cmd->rule_cnt = cnt;
2665
2666 return 0;
2667}
2668
2669/**
2670 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2671 * @pf: Pointer to the physical function struct
2672 * @cmd: The command to get or set Rx flow classification rules
2673 *
2674 * This function looks up a filter based on the Rx flow classification
2675 * command and fills the flow spec info for it if found
2676 *
2677 * Returns 0 on success or -EINVAL if filter not found
2678 **/
2679static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2680 struct ethtool_rxnfc *cmd)
2681{
2682 struct ethtool_rx_flow_spec *fsp =
2683 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002684 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002685 struct i40e_fdir_filter *rule = NULL;
2686 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002687 u64 input_set;
2688 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002689
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002690 hlist_for_each_entry_safe(rule, node2,
2691 &pf->fdir_filter_list, fdir_node) {
2692 if (fsp->location <= rule->fd_id)
2693 break;
2694 }
2695
2696 if (!rule || fsp->location != rule->fd_id)
2697 return -EINVAL;
2698
2699 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002700 if (fsp->flow_type == IP_USER_FLOW) {
2701 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2702 fsp->h_u.usr_ip4_spec.proto = 0;
2703 fsp->m_u.usr_ip4_spec.proto = 0;
2704 }
2705
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002706 /* Reverse the src and dest notion, since the HW views them from
2707 * Tx perspective where as the user expects it from Rx filter view.
2708 */
2709 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2710 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002711 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2712 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002713
Jacob Keller36777d92017-03-07 15:05:23 -08002714 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002715 case SCTP_V4_FLOW:
2716 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2717 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002718 case TCP_V4_FLOW:
2719 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2720 break;
2721 case UDP_V4_FLOW:
2722 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2723 break;
2724 case IP_USER_FLOW:
2725 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2726 break;
2727 default:
2728 /* If we have stored a filter with a flow type not listed here
2729 * it is almost certainly a driver bug. WARN(), and then
2730 * assign the input_set as if all fields are enabled to avoid
2731 * reading unassigned memory.
2732 */
2733 WARN(1, "Missing input set index for flow_type %d\n",
2734 rule->flow_type);
2735 input_set = 0xFFFFFFFFFFFFFFFFULL;
2736 goto no_input_set;
2737 }
2738
2739 input_set = i40e_read_fd_input_set(pf, index);
2740
2741no_input_set:
2742 if (input_set & I40E_L3_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002743 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002744
2745 if (input_set & I40E_L3_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002746 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002747
2748 if (input_set & I40E_L4_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002749 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002750
2751 if (input_set & I40E_L4_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002752 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002753
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002754 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2755 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2756 else
2757 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002758
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002759 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2760 struct i40e_vsi *vsi;
2761
2762 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2763 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002764 /* VFs are zero-indexed by the driver, but ethtool
2765 * expects them to be one-indexed, so add one here
2766 */
2767 u64 ring_vf = vsi->vf_id + 1;
2768
2769 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2770 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002771 }
2772 }
2773
Jacob Keller0e588de2017-02-06 14:38:50 -08002774 if (rule->flex_filter) {
2775 userdef.flex_filter = true;
2776 userdef.flex_word = be16_to_cpu(rule->flex_word);
2777 userdef.flex_offset = rule->flex_offset;
2778 }
2779
Jacob Kellere7930952017-02-06 14:38:49 -08002780 i40e_fill_rx_flow_user_data(fsp, &userdef);
2781
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002782 return 0;
2783}
2784
2785/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002786 * i40e_get_rxnfc - command to get RX flow classification rules
2787 * @netdev: network interface device structure
2788 * @cmd: ethtool rxnfc command
Jacob Kellerf5254422018-04-20 01:41:33 -07002789 * @rule_locs: pointer to store rule data
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002790 *
2791 * Returns Success if the command is supported.
2792 **/
2793static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2794 u32 *rule_locs)
2795{
2796 struct i40e_netdev_priv *np = netdev_priv(netdev);
2797 struct i40e_vsi *vsi = np->vsi;
2798 struct i40e_pf *pf = vsi->back;
2799 int ret = -EOPNOTSUPP;
2800
2801 switch (cmd->cmd) {
2802 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002803 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002804 ret = 0;
2805 break;
2806 case ETHTOOL_GRXFH:
2807 ret = i40e_get_rss_hash_opts(pf, cmd);
2808 break;
2809 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002810 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002811 /* report total rule count */
2812 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002813 ret = 0;
2814 break;
2815 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002816 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002817 break;
2818 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002819 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2820 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002821 default:
2822 break;
2823 }
2824
2825 return ret;
2826}
2827
2828/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002829 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2830 * @nfc: pointer to user request
Jacob Kellerf5254422018-04-20 01:41:33 -07002831 * @i_setc: bits currently set
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002832 *
2833 * Returns value of bits to be set per user request
2834 **/
2835static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2836{
2837 u64 i_set = i_setc;
2838 u64 src_l3 = 0, dst_l3 = 0;
2839
2840 if (nfc->data & RXH_L4_B_0_1)
2841 i_set |= I40E_L4_SRC_MASK;
2842 else
2843 i_set &= ~I40E_L4_SRC_MASK;
2844 if (nfc->data & RXH_L4_B_2_3)
2845 i_set |= I40E_L4_DST_MASK;
2846 else
2847 i_set &= ~I40E_L4_DST_MASK;
2848
2849 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2850 src_l3 = I40E_L3_V6_SRC_MASK;
2851 dst_l3 = I40E_L3_V6_DST_MASK;
2852 } else if (nfc->flow_type == TCP_V4_FLOW ||
2853 nfc->flow_type == UDP_V4_FLOW) {
2854 src_l3 = I40E_L3_SRC_MASK;
2855 dst_l3 = I40E_L3_DST_MASK;
2856 } else {
2857 /* Any other flow type are not supported here */
2858 return i_set;
2859 }
2860
2861 if (nfc->data & RXH_IP_SRC)
2862 i_set |= src_l3;
2863 else
2864 i_set &= ~src_l3;
2865 if (nfc->data & RXH_IP_DST)
2866 i_set |= dst_l3;
2867 else
2868 i_set &= ~dst_l3;
2869
2870 return i_set;
2871}
2872
2873/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002874 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2875 * @pf: pointer to the physical function struct
Jacob Kellerf5254422018-04-20 01:41:33 -07002876 * @nfc: ethtool rxnfc command
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002877 *
2878 * Returns Success if the flow input set is supported.
2879 **/
2880static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2881{
2882 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002883 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2884 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002885 u8 flow_pctype = 0;
2886 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002887
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002888 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2889 dev_err(&pf->pdev->dev,
2890 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2891 return -EOPNOTSUPP;
2892 }
2893
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002894 /* RSS does not support anything other than hashing
2895 * to queues on src and dst IPs and ports
2896 */
2897 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2898 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2899 return -EINVAL;
2900
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002901 switch (nfc->flow_type) {
2902 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002903 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002904 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002905 hena |=
2906 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002907 break;
2908 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002909 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002910 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002911 hena |=
2912 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002913 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002914 hena |=
2915 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002916 break;
2917 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002918 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002919 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002920 hena |=
2921 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2922 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002923
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002924 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002925 break;
2926 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002927 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002928 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002929 hena |=
2930 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2931 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002932
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002933 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002934 break;
2935 case AH_ESP_V4_FLOW:
2936 case AH_V4_FLOW:
2937 case ESP_V4_FLOW:
2938 case SCTP_V4_FLOW:
2939 if ((nfc->data & RXH_L4_B_0_1) ||
2940 (nfc->data & RXH_L4_B_2_3))
2941 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002942 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002943 break;
2944 case AH_ESP_V6_FLOW:
2945 case AH_V6_FLOW:
2946 case ESP_V6_FLOW:
2947 case SCTP_V6_FLOW:
2948 if ((nfc->data & RXH_L4_B_0_1) ||
2949 (nfc->data & RXH_L4_B_2_3))
2950 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002951 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002952 break;
2953 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002954 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2955 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002956 break;
2957 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002958 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2959 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002960 break;
2961 default:
2962 return -EINVAL;
2963 }
2964
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002965 if (flow_pctype) {
2966 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2967 flow_pctype)) |
2968 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2969 flow_pctype)) << 32);
2970 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2971 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2972 (u32)i_set);
2973 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2974 (u32)(i_set >> 32));
2975 hena |= BIT_ULL(flow_pctype);
2976 }
2977
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002978 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2979 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002980 i40e_flush(hw);
2981
2982 return 0;
2983}
2984
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002985/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002986 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2987 * @vsi: Pointer to the targeted VSI
2988 * @input: The filter to update or NULL to indicate deletion
2989 * @sw_idx: Software index to the filter
2990 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002991 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002992 * This function updates (or deletes) a Flow Director entry from
2993 * the hlist of the corresponding PF
2994 *
2995 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002996 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002997static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2998 struct i40e_fdir_filter *input,
2999 u16 sw_idx,
3000 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003001{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003002 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003003 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003004 struct hlist_node *node2;
3005 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003006
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003007 parent = NULL;
3008 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003009
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003010 hlist_for_each_entry_safe(rule, node2,
3011 &pf->fdir_filter_list, fdir_node) {
3012 /* hash found, or no matching entry */
3013 if (rule->fd_id >= sw_idx)
3014 break;
3015 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003016 }
3017
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003018 /* if there is an old rule occupying our place remove it */
3019 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08003020 /* Remove this rule, since we're either deleting it, or
3021 * replacing it.
3022 */
3023 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003024 hlist_del(&rule->fdir_node);
3025 kfree(rule);
3026 pf->fdir_pf_active_filters--;
3027 }
3028
Jacob Kellerc6da5252017-02-06 14:39:13 -08003029 /* If we weren't given an input, this is a delete, so just return the
3030 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003031 */
3032 if (!input)
3033 return err;
3034
Jacob Kellerc6da5252017-02-06 14:39:13 -08003035 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003036 INIT_HLIST_NODE(&input->fdir_node);
3037
3038 /* add filter to the list */
3039 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003040 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003041 else
3042 hlist_add_head(&input->fdir_node,
3043 &pf->fdir_filter_list);
3044
3045 /* update counts */
3046 pf->fdir_pf_active_filters++;
3047
3048 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003049}
3050
3051/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003052 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3053 * @pf: pointer to PF structure
3054 *
3055 * This function searches the list of filters and determines which FLX_PIT
3056 * entries are still required. It will prune any entries which are no longer
3057 * in use after the deletion.
3058 **/
3059static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3060{
3061 struct i40e_flex_pit *entry, *tmp;
3062 struct i40e_fdir_filter *rule;
3063
3064 /* First, we'll check the l3 table */
3065 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3066 bool found = false;
3067
3068 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3069 if (rule->flow_type != IP_USER_FLOW)
3070 continue;
3071 if (rule->flex_filter &&
3072 rule->flex_offset == entry->src_offset) {
3073 found = true;
3074 break;
3075 }
3076 }
3077
3078 /* If we didn't find the filter, then we can prune this entry
3079 * from the list.
3080 */
3081 if (!found) {
3082 list_del(&entry->list);
3083 kfree(entry);
3084 }
3085 }
3086
3087 /* Followed by the L4 table */
3088 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3089 bool found = false;
3090
3091 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3092 /* Skip this filter if it's L3, since we already
3093 * checked those in the above loop
3094 */
3095 if (rule->flow_type == IP_USER_FLOW)
3096 continue;
3097 if (rule->flex_filter &&
3098 rule->flex_offset == entry->src_offset) {
3099 found = true;
3100 break;
3101 }
3102 }
3103
3104 /* If we didn't find the filter, then we can prune this entry
3105 * from the list.
3106 */
3107 if (!found) {
3108 list_del(&entry->list);
3109 kfree(entry);
3110 }
3111 }
3112}
3113
3114/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003115 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3116 * @vsi: Pointer to the targeted VSI
3117 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003118 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003119 * The function removes a Flow Director filter entry from the
3120 * hlist of the corresponding PF
3121 *
3122 * Returns 0 on success
3123 */
3124static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3125 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003126{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003127 struct ethtool_rx_flow_spec *fsp =
3128 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003129 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003130 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003131
Jacob Keller0da36b92017-04-19 09:25:55 -04003132 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3133 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003134 return -EBUSY;
3135
Jacob Keller0da36b92017-04-19 09:25:55 -04003136 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003137 return -EBUSY;
3138
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003139 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003140
Jacob Keller0e588de2017-02-06 14:38:50 -08003141 i40e_prune_flex_pit_list(pf);
3142
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003143 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003144 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003145}
3146
3147/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003148 * i40e_unused_pit_index - Find an unused PIT index for given list
3149 * @pf: the PF data structure
3150 *
3151 * Find the first unused flexible PIT index entry. We search both the L3 and
3152 * L4 flexible PIT lists so that the returned index is unique and unused by
3153 * either currently programmed L3 or L4 filters. We use a bit field as storage
3154 * to track which indexes are already used.
3155 **/
3156static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3157{
3158 unsigned long available_index = 0xFF;
3159 struct i40e_flex_pit *entry;
3160
3161 /* We need to make sure that the new index isn't in use by either L3
3162 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3163 * L4 to use the same index.
3164 */
3165
3166 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3167 clear_bit(entry->pit_index, &available_index);
3168
3169 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3170 clear_bit(entry->pit_index, &available_index);
3171
3172 return find_first_bit(&available_index, 8);
3173}
3174
3175/**
3176 * i40e_find_flex_offset - Find an existing flex src_offset
3177 * @flex_pit_list: L3 or L4 flex PIT list
3178 * @src_offset: new src_offset to find
3179 *
3180 * Searches the flex_pit_list for an existing offset. If no offset is
3181 * currently programmed, then this will return an ERR_PTR if there is no space
3182 * to add a new offset, otherwise it returns NULL.
3183 **/
3184static
3185struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3186 u16 src_offset)
3187{
3188 struct i40e_flex_pit *entry;
3189 int size = 0;
3190
3191 /* Search for the src_offset first. If we find a matching entry
3192 * already programmed, we can simply re-use it.
3193 */
3194 list_for_each_entry(entry, flex_pit_list, list) {
3195 size++;
3196 if (entry->src_offset == src_offset)
3197 return entry;
3198 }
3199
3200 /* If we haven't found an entry yet, then the provided src offset has
3201 * not yet been programmed. We will program the src offset later on,
3202 * but we need to indicate whether there is enough space to do so
3203 * here. We'll make use of ERR_PTR for this purpose.
3204 */
3205 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3206 return ERR_PTR(-ENOSPC);
3207
3208 return NULL;
3209}
3210
3211/**
3212 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3213 * @flex_pit_list: L3 or L4 flex PIT list
3214 * @src_offset: new src_offset to add
3215 * @pit_index: the PIT index to program
3216 *
3217 * This function programs the new src_offset to the list. It is expected that
3218 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3219 * that this offset is not programmed, and that the list has enough space to
3220 * store another offset.
3221 *
3222 * Returns 0 on success, and negative value on error.
3223 **/
3224static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3225 u16 src_offset,
3226 u8 pit_index)
3227{
3228 struct i40e_flex_pit *new_pit, *entry;
3229
3230 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3231 if (!new_pit)
3232 return -ENOMEM;
3233
3234 new_pit->src_offset = src_offset;
3235 new_pit->pit_index = pit_index;
3236
3237 /* We need to insert this item such that the list is sorted by
3238 * src_offset in ascending order.
3239 */
3240 list_for_each_entry(entry, flex_pit_list, list) {
3241 if (new_pit->src_offset < entry->src_offset) {
3242 list_add_tail(&new_pit->list, &entry->list);
3243 return 0;
3244 }
3245
3246 /* If we found an entry with our offset already programmed we
3247 * can simply return here, after freeing the memory. However,
3248 * if the pit_index does not match we need to report an error.
3249 */
3250 if (new_pit->src_offset == entry->src_offset) {
3251 int err = 0;
3252
3253 /* If the PIT index is not the same we can't re-use
3254 * the entry, so we must report an error.
3255 */
3256 if (new_pit->pit_index != entry->pit_index)
3257 err = -EINVAL;
3258
3259 kfree(new_pit);
3260 return err;
3261 }
3262 }
3263
3264 /* If we reached here, then we haven't yet added the item. This means
3265 * that we should add the item at the end of the list.
3266 */
3267 list_add_tail(&new_pit->list, flex_pit_list);
3268 return 0;
3269}
3270
3271/**
3272 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3273 * @pf: Pointer to the PF structure
3274 * @flex_pit_list: list of flexible src offsets in use
Jacob Kellerf5254422018-04-20 01:41:33 -07003275 * @flex_pit_start: index to first entry for this section of the table
Jacob Keller0e588de2017-02-06 14:38:50 -08003276 *
3277 * In order to handle flexible data, the hardware uses a table of values
3278 * called the FLX_PIT table. This table is used to indicate which sections of
3279 * the input correspond to what PIT index values. Unfortunately, hardware is
3280 * very restrictive about programming this table. Entries must be ordered by
3281 * src_offset in ascending order, without duplicates. Additionally, unused
3282 * entries must be set to the unused index value, and must have valid size and
3283 * length according to the src_offset ordering.
3284 *
3285 * This function will reprogram the FLX_PIT register from a book-keeping
3286 * structure that we guarantee is already ordered correctly, and has no more
3287 * than 3 entries.
3288 *
3289 * To make things easier, we only support flexible values of one word length,
3290 * rather than allowing variable length flexible values.
3291 **/
3292static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3293 struct list_head *flex_pit_list,
3294 int flex_pit_start)
3295{
3296 struct i40e_flex_pit *entry = NULL;
3297 u16 last_offset = 0;
3298 int i = 0, j = 0;
3299
3300 /* First, loop over the list of flex PIT entries, and reprogram the
3301 * registers.
3302 */
3303 list_for_each_entry(entry, flex_pit_list, list) {
3304 /* We have to be careful when programming values for the
3305 * largest SRC_OFFSET value. It is possible that adding
3306 * additional empty values at the end would overflow the space
3307 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3308 * we check here and add the empty values prior to adding the
3309 * largest value.
3310 *
3311 * To determine this, we will use a loop from i+1 to 3, which
3312 * will determine whether the unused entries would have valid
3313 * SRC_OFFSET. Note that there cannot be extra entries past
3314 * this value, because the only valid values would have been
3315 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3316 * have been added to the list in the first place.
3317 */
3318 for (j = i + 1; j < 3; j++) {
3319 u16 offset = entry->src_offset + j;
3320 int index = flex_pit_start + i;
3321 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3322 1,
3323 offset - 3);
3324
3325 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3326 i40e_write_rx_ctl(&pf->hw,
3327 I40E_PRTQF_FLX_PIT(index),
3328 value);
3329 i++;
3330 }
3331 }
3332
3333 /* Now, we can program the actual value into the table */
3334 i40e_write_rx_ctl(&pf->hw,
3335 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3336 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3337 1,
3338 entry->src_offset));
3339 i++;
3340 }
3341
3342 /* In order to program the last entries in the table, we need to
3343 * determine the valid offset. If the list is empty, we'll just start
3344 * with 0. Otherwise, we'll start with the last item offset and add 1.
3345 * This ensures that all entries have valid sizes. If we don't do this
3346 * correctly, the hardware will disable flexible field parsing.
3347 */
3348 if (!list_empty(flex_pit_list))
3349 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3350
3351 for (; i < 3; i++, last_offset++) {
3352 i40e_write_rx_ctl(&pf->hw,
3353 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3354 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3355 1,
3356 last_offset));
3357 }
3358}
3359
3360/**
3361 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3362 * @pf: pointer to the PF structure
3363 *
3364 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3365 * internal helper function for implementation details.
3366 **/
3367static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3368{
3369 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3370 I40E_FLEX_PIT_IDX_START_L3);
3371
3372 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3373 I40E_FLEX_PIT_IDX_START_L4);
3374
3375 /* We also need to program the L3 and L4 GLQF ORT register */
3376 i40e_write_rx_ctl(&pf->hw,
3377 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3378 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3379 3, 1));
3380
3381 i40e_write_rx_ctl(&pf->hw,
3382 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3383 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3384 3, 1));
3385}
3386
3387/**
Jacob Keller9229e992017-02-06 14:38:47 -08003388 * i40e_flow_str - Converts a flow_type into a human readable string
Jacob Kellerf5254422018-04-20 01:41:33 -07003389 * @fsp: the flow specification
Jacob Keller9229e992017-02-06 14:38:47 -08003390 *
3391 * Currently only flow types we support are included here, and the string
3392 * value attempts to match what ethtool would use to configure this flow type.
3393 **/
3394static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3395{
3396 switch (fsp->flow_type & ~FLOW_EXT) {
3397 case TCP_V4_FLOW:
3398 return "tcp4";
3399 case UDP_V4_FLOW:
3400 return "udp4";
3401 case SCTP_V4_FLOW:
3402 return "sctp4";
3403 case IP_USER_FLOW:
3404 return "ip4";
3405 default:
3406 return "unknown";
3407 }
3408}
3409
3410/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003411 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3412 * @pit_index: PIT index to convert
3413 *
3414 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3415 * of range.
3416 **/
3417static u64 i40e_pit_index_to_mask(int pit_index)
3418{
3419 switch (pit_index) {
3420 case 0:
3421 return I40E_FLEX_50_MASK;
3422 case 1:
3423 return I40E_FLEX_51_MASK;
3424 case 2:
3425 return I40E_FLEX_52_MASK;
3426 case 3:
3427 return I40E_FLEX_53_MASK;
3428 case 4:
3429 return I40E_FLEX_54_MASK;
3430 case 5:
3431 return I40E_FLEX_55_MASK;
3432 case 6:
3433 return I40E_FLEX_56_MASK;
3434 case 7:
3435 return I40E_FLEX_57_MASK;
3436 default:
3437 return 0;
3438 }
3439}
3440
3441/**
Jacob Keller9229e992017-02-06 14:38:47 -08003442 * i40e_print_input_set - Show changes between two input sets
3443 * @vsi: the vsi being configured
3444 * @old: the old input set
3445 * @new: the new input set
3446 *
3447 * Print the difference between old and new input sets by showing which series
3448 * of words are toggled on or off. Only displays the bits we actually support
3449 * changing.
3450 **/
3451static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3452{
3453 struct i40e_pf *pf = vsi->back;
3454 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003455 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003456
3457 old_value = !!(old & I40E_L3_SRC_MASK);
3458 new_value = !!(new & I40E_L3_SRC_MASK);
3459 if (old_value != new_value)
3460 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3461 old_value ? "ON" : "OFF",
3462 new_value ? "ON" : "OFF");
3463
3464 old_value = !!(old & I40E_L3_DST_MASK);
3465 new_value = !!(new & I40E_L3_DST_MASK);
3466 if (old_value != new_value)
3467 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3468 old_value ? "ON" : "OFF",
3469 new_value ? "ON" : "OFF");
3470
3471 old_value = !!(old & I40E_L4_SRC_MASK);
3472 new_value = !!(new & I40E_L4_SRC_MASK);
3473 if (old_value != new_value)
3474 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3475 old_value ? "ON" : "OFF",
3476 new_value ? "ON" : "OFF");
3477
3478 old_value = !!(old & I40E_L4_DST_MASK);
3479 new_value = !!(new & I40E_L4_DST_MASK);
3480 if (old_value != new_value)
3481 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3482 old_value ? "ON" : "OFF",
3483 new_value ? "ON" : "OFF");
3484
3485 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3486 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3487 if (old_value != new_value)
3488 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3489 old_value ? "ON" : "OFF",
3490 new_value ? "ON" : "OFF");
3491
Jacob Keller0e588de2017-02-06 14:38:50 -08003492 /* Show change of flexible filter entries */
3493 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3494 u64 flex_mask = i40e_pit_index_to_mask(i);
3495
3496 old_value = !!(old & flex_mask);
3497 new_value = !!(new & flex_mask);
3498 if (old_value != new_value)
3499 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3500 i,
3501 old_value ? "ON" : "OFF",
3502 new_value ? "ON" : "OFF");
3503 }
3504
Jacob Keller9229e992017-02-06 14:38:47 -08003505 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3506 old);
3507 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3508 new);
3509}
3510
3511/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003512 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003513 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003514 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003515 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003516 *
Jacob Keller9229e992017-02-06 14:38:47 -08003517 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3518 * for partial matches exists with a few limitations. First, hardware only
3519 * supports masking by word boundary (2 bytes) and not per individual bit.
3520 * Second, hardware is limited to using one mask for a flow type and cannot
3521 * use a separate mask for each filter.
3522 *
3523 * To support these limitations, if we already have a configured filter for
3524 * the specified type, this function enforces that new filters of the type
3525 * match the configured input set. Otherwise, if we do not have a filter of
3526 * the specified type, we allow the input set to be updated to match the
3527 * desired filter.
3528 *
3529 * To help ensure that administrators understand why filters weren't displayed
3530 * as supported, we print a diagnostic message displaying how the input set
3531 * would change and warning to delete the preexisting filters if required.
3532 *
3533 * Returns 0 on successful input set match, and a negative return code on
3534 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003535 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003536static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003537 struct ethtool_rx_flow_spec *fsp,
3538 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003539{
Jacob Keller36777d92017-03-07 15:05:23 -08003540 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003541 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3542 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003543 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003544 bool new_flex_offset = false;
3545 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003546 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003547 u16 index, src_offset = 0;
3548 u8 pit_index = 0;
3549 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003550
3551 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003552 case SCTP_V4_FLOW:
3553 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3554 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3555 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003556 case TCP_V4_FLOW:
3557 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003558 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003559 break;
3560 case UDP_V4_FLOW:
3561 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003562 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003563 break;
3564 case IP_USER_FLOW:
3565 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003566 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003567 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003568 break;
3569 default:
3570 return -EOPNOTSUPP;
3571 }
3572
3573 /* Read the current input set from register memory. */
3574 current_mask = i40e_read_fd_input_set(pf, index);
3575 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003576
Jacob Keller9229e992017-02-06 14:38:47 -08003577 /* Determine, if any, the required changes to the input set in order
3578 * to support the provided mask.
3579 *
3580 * Hardware only supports masking at word (2 byte) granularity and does
3581 * not support full bitwise masking. This implementation simplifies
3582 * even further and only supports fully enabled or fully disabled
3583 * masks for each field, even though we could split the ip4src and
3584 * ip4dst fields.
3585 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003586 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003587 case SCTP_V4_FLOW:
3588 new_mask &= ~I40E_VERIFY_TAG_MASK;
3589 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003590 case TCP_V4_FLOW:
3591 case UDP_V4_FLOW:
3592 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3593
3594 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003595 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3596 new_mask |= I40E_L3_SRC_MASK;
3597 else if (!tcp_ip4_spec->ip4src)
3598 new_mask &= ~I40E_L3_SRC_MASK;
3599 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003600 return -EOPNOTSUPP;
3601
3602 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003603 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3604 new_mask |= I40E_L3_DST_MASK;
3605 else if (!tcp_ip4_spec->ip4dst)
3606 new_mask &= ~I40E_L3_DST_MASK;
3607 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003608 return -EOPNOTSUPP;
3609
3610 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003611 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3612 new_mask |= I40E_L4_SRC_MASK;
3613 else if (!tcp_ip4_spec->psrc)
3614 new_mask &= ~I40E_L4_SRC_MASK;
3615 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003616 return -EOPNOTSUPP;
3617
3618 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003619 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3620 new_mask |= I40E_L4_DST_MASK;
3621 else if (!tcp_ip4_spec->pdst)
3622 new_mask &= ~I40E_L4_DST_MASK;
3623 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003624 return -EOPNOTSUPP;
3625
3626 /* Filtering on Type of Service is not supported. */
3627 if (tcp_ip4_spec->tos)
3628 return -EOPNOTSUPP;
3629
3630 break;
3631 case IP_USER_FLOW:
3632 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3633
3634 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003635 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3636 new_mask |= I40E_L3_SRC_MASK;
3637 else if (!usr_ip4_spec->ip4src)
3638 new_mask &= ~I40E_L3_SRC_MASK;
3639 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003640 return -EOPNOTSUPP;
3641
3642 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003643 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3644 new_mask |= I40E_L3_DST_MASK;
3645 else if (!usr_ip4_spec->ip4dst)
3646 new_mask &= ~I40E_L3_DST_MASK;
3647 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003648 return -EOPNOTSUPP;
3649
3650 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003651 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3652 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3653 else if (!usr_ip4_spec->l4_4_bytes)
3654 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3655 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003656 return -EOPNOTSUPP;
3657
3658 /* Filtering on Type of Service is not supported. */
3659 if (usr_ip4_spec->tos)
3660 return -EOPNOTSUPP;
3661
Jacob Keller0e588de2017-02-06 14:38:50 -08003662 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003663 if (usr_ip4_spec->ip_ver)
3664 return -EINVAL;
3665
Jacob Keller0e588de2017-02-06 14:38:50 -08003666 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003667 if (usr_ip4_spec->proto)
3668 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003669
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003670 break;
3671 default:
3672 return -EOPNOTSUPP;
3673 }
3674
Jacob Keller0e588de2017-02-06 14:38:50 -08003675 /* First, clear all flexible filter entries */
3676 new_mask &= ~I40E_FLEX_INPUT_MASK;
3677
3678 /* If we have a flexible filter, try to add this offset to the correct
3679 * flexible filter PIT list. Once finished, we can update the mask.
3680 * If the src_offset changed, we will get a new mask value which will
3681 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003682 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003683 if (userdef->flex_filter) {
3684 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3685
3686 /* Flexible offset must be even, since the flexible payload
3687 * must be aligned on 2-byte boundary.
3688 */
3689 if (userdef->flex_offset & 0x1) {
3690 dev_warn(&pf->pdev->dev,
3691 "Flexible data offset must be 2-byte aligned\n");
3692 return -EINVAL;
3693 }
3694
3695 src_offset = userdef->flex_offset >> 1;
3696
3697 /* FLX_PIT source offset value is only so large */
3698 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3699 dev_warn(&pf->pdev->dev,
3700 "Flexible data must reside within first 64 bytes of the packet payload\n");
3701 return -EINVAL;
3702 }
3703
3704 /* See if this offset has already been programmed. If we get
3705 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3706 * if we get a NULL pointer, this means we will need to add
3707 * the offset.
3708 */
3709 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3710 src_offset);
3711 if (IS_ERR(flex_pit))
3712 return PTR_ERR(flex_pit);
3713
3714 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3715 * packet types, and thus we need to program both L3 and L4
3716 * flexible values. These must have identical flexible index,
3717 * as otherwise we can't correctly program the input set. So
3718 * we'll find both an L3 and L4 index and make sure they are
3719 * the same.
3720 */
3721 if (flex_l3) {
3722 l3_flex_pit =
3723 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3724 src_offset);
3725 if (IS_ERR(l3_flex_pit))
3726 return PTR_ERR(l3_flex_pit);
3727
3728 if (flex_pit) {
3729 /* If we already had a matching L4 entry, we
3730 * need to make sure that the L3 entry we
3731 * obtained uses the same index.
3732 */
3733 if (l3_flex_pit) {
3734 if (l3_flex_pit->pit_index !=
3735 flex_pit->pit_index) {
3736 return -EINVAL;
3737 }
3738 } else {
3739 new_flex_offset = true;
3740 }
3741 } else {
3742 flex_pit = l3_flex_pit;
3743 }
3744 }
3745
3746 /* If we didn't find an existing flex offset, we need to
3747 * program a new one. However, we don't immediately program it
3748 * here because we will wait to program until after we check
3749 * that it is safe to change the input set.
3750 */
3751 if (!flex_pit) {
3752 new_flex_offset = true;
3753 pit_index = i40e_unused_pit_index(pf);
3754 } else {
3755 pit_index = flex_pit->pit_index;
3756 }
3757
3758 /* Update the mask with the new offset */
3759 new_mask |= i40e_pit_index_to_mask(pit_index);
3760 }
3761
3762 /* If the mask and flexible filter offsets for this filter match the
3763 * currently programmed values we don't need any input set change, so
3764 * this filter is safe to install.
3765 */
3766 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003767 return 0;
3768
3769 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3770 i40e_flow_str(fsp));
3771 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003772 if (new_flex_offset) {
3773 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3774 pit_index, src_offset);
3775 }
Jacob Keller9229e992017-02-06 14:38:47 -08003776
3777 /* Hardware input sets are global across multiple ports, so even the
3778 * main port cannot change them when in MFP mode as this would impact
3779 * any filters on the other ports.
3780 */
3781 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3782 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003783 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003784 }
3785
3786 /* This filter requires us to update the input set. However, hardware
3787 * only supports one input set per flow type, and does not support
3788 * separate masks for each filter. This means that we can only support
3789 * a single mask for all filters of a specific type.
3790 *
3791 * If we have preexisting filters, they obviously depend on the
3792 * current programmed input set. Display a diagnostic message in this
3793 * case explaining why the filter could not be accepted.
3794 */
3795 if (*fdir_filter_count) {
3796 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3797 i40e_flow_str(fsp),
3798 *fdir_filter_count);
3799 return -EOPNOTSUPP;
3800 }
3801
3802 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003803
Jacob Keller02b40162017-12-27 08:24:12 -05003804 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
3805 * frames. If we're programming the input set for IPv4/Other, we also
3806 * need to program the IPv4/Fragmented input set. Since we don't have
3807 * separate support, we'll always assume and enforce that the two flow
3808 * types must have matching input sets.
3809 */
3810 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
3811 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
3812 new_mask);
3813
Jacob Keller0e588de2017-02-06 14:38:50 -08003814 /* Add the new offset and update table, if necessary */
3815 if (new_flex_offset) {
3816 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3817 pit_index);
3818 if (err)
3819 return err;
3820
3821 if (flex_l3) {
3822 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3823 src_offset,
3824 pit_index);
3825 if (err)
3826 return err;
3827 }
3828
3829 i40e_reprogram_flex_pit(pf);
3830 }
3831
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003832 return 0;
3833}
3834
3835/**
Jacob Keller443ee712017-12-27 08:25:32 -05003836 * i40e_match_fdir_filter - Return true of two filters match
3837 * @a: pointer to filter struct
3838 * @b: pointer to filter struct
3839 *
3840 * Returns true if the two filters match exactly the same criteria. I.e. they
3841 * match the same flow type and have the same parameters. We don't need to
3842 * check any input-set since all filters of the same flow type must use the
3843 * same input set.
3844 **/
3845static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
3846 struct i40e_fdir_filter *b)
3847{
3848 /* The filters do not much if any of these criteria differ. */
3849 if (a->dst_ip != b->dst_ip ||
3850 a->src_ip != b->src_ip ||
3851 a->dst_port != b->dst_port ||
3852 a->src_port != b->src_port ||
3853 a->flow_type != b->flow_type ||
3854 a->ip4_proto != b->ip4_proto)
3855 return false;
3856
3857 return true;
3858}
3859
3860/**
3861 * i40e_disallow_matching_filters - Check that new filters differ
3862 * @vsi: pointer to the targeted VSI
3863 * @input: new filter to check
3864 *
3865 * Due to hardware limitations, it is not possible for two filters that match
3866 * similar criteria to be programmed at the same time. This is true for a few
3867 * reasons:
3868 *
3869 * (a) all filters matching a particular flow type must use the same input
3870 * set, that is they must match the same criteria.
3871 * (b) different flow types will never match the same packet, as the flow type
3872 * is decided by hardware before checking which rules apply.
3873 * (c) hardware has no way to distinguish which order filters apply in.
3874 *
3875 * Due to this, we can't really support using the location data to order
3876 * filters in the hardware parsing. It is technically possible for the user to
3877 * request two filters matching the same criteria but which select different
3878 * queues. In this case, rather than keep both filters in the list, we reject
3879 * the 2nd filter when the user requests adding it.
3880 *
3881 * This avoids needing to track location for programming the filter to
3882 * hardware, and ensures that we avoid some strange scenarios involving
3883 * deleting filters which match the same criteria.
3884 **/
3885static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
3886 struct i40e_fdir_filter *input)
3887{
3888 struct i40e_pf *pf = vsi->back;
3889 struct i40e_fdir_filter *rule;
3890 struct hlist_node *node2;
3891
3892 /* Loop through every filter, and check that it doesn't match */
3893 hlist_for_each_entry_safe(rule, node2,
3894 &pf->fdir_filter_list, fdir_node) {
3895 /* Don't check the filters match if they share the same fd_id,
3896 * since the new filter is actually just updating the target
3897 * of the old filter.
3898 */
3899 if (rule->fd_id == input->fd_id)
3900 continue;
3901
3902 /* If any filters match, then print a warning message to the
3903 * kernel message buffer and bail out.
3904 */
3905 if (i40e_match_fdir_filter(rule, input)) {
3906 dev_warn(&pf->pdev->dev,
3907 "Existing user defined filter %d already matches this flow.\n",
3908 rule->fd_id);
3909 return -EINVAL;
3910 }
3911 }
3912
3913 return 0;
3914}
3915
3916/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003917 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003918 * @vsi: pointer to the targeted VSI
3919 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003920 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003921 * Add Flow Director filters for a specific flow spec based on their
3922 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003923 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003924static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3925 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003926{
Jacob Kellere7930952017-02-06 14:38:49 -08003927 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003928 struct ethtool_rx_flow_spec *fsp;
3929 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003930 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003931 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003932 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003933 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003934
3935 if (!vsi)
3936 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003937 pf = vsi->back;
3938
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003939 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3940 return -EOPNOTSUPP;
3941
Jacob Keller134201a2018-03-16 01:26:32 -07003942 if (test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003943 return -ENOSPC;
3944
Jacob Keller0da36b92017-04-19 09:25:55 -04003945 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3946 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003947 return -EBUSY;
3948
Jacob Keller0da36b92017-04-19 09:25:55 -04003949 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003950 return -EBUSY;
3951
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003952 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3953
Jacob Kellere7930952017-02-06 14:38:49 -08003954 /* Parse the user-defined field */
3955 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3956 return -EINVAL;
3957
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003958 /* Extended MAC field is not supported */
3959 if (fsp->flow_type & FLOW_MAC_EXT)
3960 return -EINVAL;
3961
Jacob Keller0e588de2017-02-06 14:38:50 -08003962 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003963 if (ret)
3964 return ret;
3965
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003966 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3967 pf->hw.func_caps.fd_filters_guaranteed)) {
3968 return -EINVAL;
3969 }
3970
Jacob Keller43b15692017-02-06 14:38:48 -08003971 /* ring_cookie is either the drop index, or is a mask of the queue
3972 * index and VF id we wish to target.
3973 */
3974 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3975 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3976 } else {
3977 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3978 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3979
3980 if (!vf) {
3981 if (ring >= vsi->num_queue_pairs)
3982 return -EINVAL;
3983 dest_vsi = vsi->id;
3984 } else {
3985 /* VFs are zero-indexed, so we subtract one here */
3986 vf--;
3987
3988 if (vf >= pf->num_alloc_vfs)
3989 return -EINVAL;
3990 if (ring >= pf->vf[vf].num_queue_pairs)
3991 return -EINVAL;
3992 dest_vsi = pf->vf[vf].lan_vsi_id;
3993 }
3994 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3995 q_index = ring;
3996 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003997
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003998 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003999
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004000 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004001 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004002
4003 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08004004 input->q_index = q_index;
4005 input->dest_vsi = dest_vsi;
4006 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004007 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04004008 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08004009 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4010 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08004011 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004012 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00004013
4014 /* Reverse the src and dest notion, since the HW expects them to be from
4015 * Tx perspective where as the input from user is from Rx filter view.
4016 */
4017 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4018 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08004019 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4020 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004021
Jacob Keller0e588de2017-02-06 14:38:50 -08004022 if (userdef.flex_filter) {
4023 input->flex_filter = true;
4024 input->flex_word = cpu_to_be16(userdef.flex_word);
4025 input->flex_offset = userdef.flex_offset;
4026 }
4027
Jacob Keller443ee712017-12-27 08:25:32 -05004028 /* Avoid programming two filters with identical match criteria. */
4029 ret = i40e_disallow_matching_filters(vsi, input);
4030 if (ret)
4031 goto free_filter_memory;
4032
Jacob Keller01016da2017-02-06 14:38:40 -08004033 /* Add the input filter to the fdir_input_list, possibly replacing
4034 * a previous filter. Do not free the input structure after adding it
4035 * to the list as this would cause a use-after-free bug.
4036 */
4037 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Patryk Małekca6e1d02017-12-27 07:32:31 -05004038 ret = i40e_add_del_fdir(vsi, input, true);
4039 if (ret)
4040 goto remove_sw_rule;
Jacob Keller01016da2017-02-06 14:38:40 -08004041 return 0;
4042
Patryk Małekca6e1d02017-12-27 07:32:31 -05004043remove_sw_rule:
4044 hlist_del(&input->fdir_node);
4045 pf->fdir_pf_active_filters--;
Jacob Keller443ee712017-12-27 08:25:32 -05004046free_filter_memory:
Jacob Keller01016da2017-02-06 14:38:40 -08004047 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004048 return ret;
4049}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08004050
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004051/**
4052 * i40e_set_rxnfc - command to set RX flow classification rules
4053 * @netdev: network interface device structure
4054 * @cmd: ethtool rxnfc command
4055 *
4056 * Returns Success if the command is supported.
4057 **/
4058static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4059{
4060 struct i40e_netdev_priv *np = netdev_priv(netdev);
4061 struct i40e_vsi *vsi = np->vsi;
4062 struct i40e_pf *pf = vsi->back;
4063 int ret = -EOPNOTSUPP;
4064
4065 switch (cmd->cmd) {
4066 case ETHTOOL_SRXFH:
4067 ret = i40e_set_rss_hash_opt(pf, cmd);
4068 break;
4069 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00004070 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004071 break;
4072 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004073 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004074 break;
4075 default:
4076 break;
4077 }
4078
4079 return ret;
4080}
4081
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004082/**
4083 * i40e_max_channels - get Max number of combined channels supported
4084 * @vsi: vsi pointer
4085 **/
4086static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4087{
4088 /* TODO: This code assumes DCB and FD is disabled for now. */
4089 return vsi->alloc_queue_pairs;
4090}
4091
4092/**
4093 * i40e_get_channels - Get the current channels enabled and max supported etc.
Jacob Kellerf5254422018-04-20 01:41:33 -07004094 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004095 * @ch: ethtool channels structure
4096 *
4097 * We don't support separate tx and rx queues as channels. The other count
4098 * represents how many queues are being used for control. max_combined counts
4099 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4100 * q_vectors since we support a lot more queue pairs than q_vectors.
4101 **/
4102static void i40e_get_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004103 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004104{
4105 struct i40e_netdev_priv *np = netdev_priv(dev);
4106 struct i40e_vsi *vsi = np->vsi;
4107 struct i40e_pf *pf = vsi->back;
4108
4109 /* report maximum channels */
4110 ch->max_combined = i40e_max_channels(vsi);
4111
4112 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004113 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004114 ch->max_other = ch->other_count;
4115
4116 /* Note: This code assumes DCB is disabled for now. */
4117 ch->combined_count = vsi->num_queue_pairs;
4118}
4119
4120/**
4121 * i40e_set_channels - Set the new channels count.
Jacob Kellerf5254422018-04-20 01:41:33 -07004122 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004123 * @ch: ethtool channels structure
4124 *
4125 * The new channels count may not be the same as requested by the user
4126 * since it gets rounded down to a power of 2 value.
4127 **/
4128static int i40e_set_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004129 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004130{
Jacob Keller59826d92016-07-27 12:02:35 -07004131 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004132 struct i40e_netdev_priv *np = netdev_priv(dev);
4133 unsigned int count = ch->combined_count;
4134 struct i40e_vsi *vsi = np->vsi;
4135 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004136 struct i40e_fdir_filter *rule;
4137 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004138 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004139 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004140
4141 /* We do not support setting channels for any other VSI at present */
4142 if (vsi->type != I40E_VSI_MAIN)
4143 return -EINVAL;
4144
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004145 /* We do not support setting channels via ethtool when TCs are
4146 * configured through mqprio
4147 */
4148 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4149 return -EINVAL;
4150
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004151 /* verify they are not requesting separate vectors */
4152 if (!count || ch->rx_count || ch->tx_count)
4153 return -EINVAL;
4154
4155 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004156 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004157 return -EINVAL;
4158
4159 /* verify the number of channels does not exceed hardware limits */
4160 if (count > i40e_max_channels(vsi))
4161 return -EINVAL;
4162
Jacob Keller59826d92016-07-27 12:02:35 -07004163 /* verify that the number of channels does not invalidate any current
4164 * flow director rules
4165 */
4166 hlist_for_each_entry_safe(rule, node2,
4167 &pf->fdir_filter_list, fdir_node) {
4168 if (rule->dest_ctl != drop && count <= rule->q_index) {
4169 dev_warn(&pf->pdev->dev,
4170 "Existing user defined filter %d assigns flow to queue %d\n",
4171 rule->fd_id, rule->q_index);
4172 err = -EINVAL;
4173 }
4174 }
4175
4176 if (err) {
4177 dev_err(&pf->pdev->dev,
4178 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4179 count);
4180 return err;
4181 }
4182
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004183 /* update feature limits from largest to smallest supported values */
4184 /* TODO: Flow director limit, DCB etc */
4185
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004186 /* use rss_reconfig to rebuild with new queue count and update traffic
4187 * class queue mapping
4188 */
4189 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004190 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004191 return 0;
4192 else
4193 return -EINVAL;
4194}
4195
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004196/**
4197 * i40e_get_rxfh_key_size - get the RSS hash key size
4198 * @netdev: network interface device structure
4199 *
4200 * Returns the table size.
4201 **/
4202static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4203{
4204 return I40E_HKEY_ARRAY_SIZE;
4205}
4206
4207/**
4208 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4209 * @netdev: network interface device structure
4210 *
4211 * Returns the table size.
4212 **/
4213static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4214{
4215 return I40E_HLUT_ARRAY_SIZE;
4216}
4217
Alan Brady21675bd2017-10-05 14:53:33 -07004218/**
4219 * i40e_get_rxfh - get the rx flow hash indirection table
4220 * @netdev: network interface device structure
4221 * @indir: indirection table
4222 * @key: hash key
4223 * @hfunc: hash function
4224 *
4225 * Reads the indirection table directly from the hardware. Returns 0 on
4226 * success.
4227 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004228static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4229 u8 *hfunc)
4230{
4231 struct i40e_netdev_priv *np = netdev_priv(netdev);
4232 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004233 u8 *lut, *seed = NULL;
4234 int ret;
4235 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004236
4237 if (hfunc)
4238 *hfunc = ETH_RSS_HASH_TOP;
4239
4240 if (!indir)
4241 return 0;
4242
Helin Zhang043dd652015-10-21 19:56:23 -04004243 seed = key;
4244 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4245 if (!lut)
4246 return -ENOMEM;
4247 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4248 if (ret)
4249 goto out;
4250 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4251 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004252
Helin Zhang043dd652015-10-21 19:56:23 -04004253out:
4254 kfree(lut);
4255
4256 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004257}
4258
4259/**
4260 * i40e_set_rxfh - set the rx flow hash indirection table
4261 * @netdev: network interface device structure
4262 * @indir: indirection table
4263 * @key: hash key
Jacob Kellerf5254422018-04-20 01:41:33 -07004264 * @hfunc: hash function to use
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004265 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004266 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004267 * returns 0 after programming the table.
4268 **/
4269static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4270 const u8 *key, const u8 hfunc)
4271{
4272 struct i40e_netdev_priv *np = netdev_priv(netdev);
4273 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004274 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004275 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004276 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004277
4278 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4279 return -EOPNOTSUPP;
4280
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004281 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004282 if (!vsi->rss_hkey_user) {
4283 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4284 GFP_KERNEL);
4285 if (!vsi->rss_hkey_user)
4286 return -ENOMEM;
4287 }
4288 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4289 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004290 }
Helin Zhang28c58692015-10-26 19:44:27 -04004291 if (!vsi->rss_lut_user) {
4292 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4293 if (!vsi->rss_lut_user)
4294 return -ENOMEM;
4295 }
Helin Zhang043dd652015-10-21 19:56:23 -04004296
Helin Zhang28c58692015-10-26 19:44:27 -04004297 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004298 if (indir)
4299 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4300 vsi->rss_lut_user[i] = (u8)(indir[i]);
4301 else
4302 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4303 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004304
4305 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4306 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004307}
4308
Greg Rose7e45ab42015-02-06 08:52:19 +00004309/**
4310 * i40e_get_priv_flags - report device private flags
4311 * @dev: network interface device structure
4312 *
4313 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004314 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004315 * array.
4316 *
4317 * Returns a u32 bitmap of flags.
4318 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004319static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004320{
4321 struct i40e_netdev_priv *np = netdev_priv(dev);
4322 struct i40e_vsi *vsi = np->vsi;
4323 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004324 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004325
Alexander Duyckaca955d2017-03-10 12:22:01 -08004326 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4327 const struct i40e_priv_flags *priv_flags;
4328
4329 priv_flags = &i40e_gstrings_priv_flags[i];
4330
4331 if (priv_flags->flag & pf->flags)
4332 ret_flags |= BIT(i);
4333 }
4334
4335 if (pf->hw.pf_id != 0)
4336 return ret_flags;
4337
4338 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4339 const struct i40e_priv_flags *priv_flags;
4340
4341 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4342
4343 if (priv_flags->flag & pf->flags)
4344 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004345 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004346
4347 return ret_flags;
4348}
4349
Shannon Nelson9ac77262015-08-27 11:42:40 -04004350/**
4351 * i40e_set_priv_flags - set private flags
4352 * @dev: network interface device structure
4353 * @flags: bit flags to be set
4354 **/
4355static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4356{
4357 struct i40e_netdev_priv *np = netdev_priv(dev);
4358 struct i40e_vsi *vsi = np->vsi;
4359 struct i40e_pf *pf = vsi->back;
Alice Michael60f481b2017-12-27 08:17:50 -05004360 u64 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004361 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004362
Jacob Keller841c9502017-06-23 04:24:50 -04004363 orig_flags = READ_ONCE(pf->flags);
4364 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004365
Alexander Duyckaca955d2017-03-10 12:22:01 -08004366 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4367 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004368
Alexander Duyckaca955d2017-03-10 12:22:01 -08004369 priv_flags = &i40e_gstrings_priv_flags[i];
4370
Alexander Duyckaca955d2017-03-10 12:22:01 -08004371 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004372 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004373 else
Jacob Keller841c9502017-06-23 04:24:50 -04004374 new_flags &= ~(priv_flags->flag);
4375
4376 /* If this is a read-only flag, it can't be changed */
4377 if (priv_flags->read_only &&
4378 ((orig_flags ^ new_flags) & ~BIT(i)))
4379 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004380 }
4381
4382 if (pf->hw.pf_id != 0)
4383 goto flags_complete;
4384
4385 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4386 const struct i40e_priv_flags *priv_flags;
4387
4388 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4389
Alexander Duyckaca955d2017-03-10 12:22:01 -08004390 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004391 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004392 else
Jacob Keller841c9502017-06-23 04:24:50 -04004393 new_flags &= ~(priv_flags->flag);
4394
4395 /* If this is a read-only flag, it can't be changed */
4396 if (priv_flags->read_only &&
4397 ((orig_flags ^ new_flags) & ~BIT(i)))
4398 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004399 }
4400
4401flags_complete:
Alan Bradyfe09ed02017-12-29 08:50:34 -05004402 changed_flags = orig_flags ^ new_flags;
4403
Jacob Keller841c9502017-06-23 04:24:50 -04004404 /* Before we finalize any flag changes, we need to perform some
4405 * checks to ensure that the changes are supported and safe.
4406 */
4407
4408 /* ATR eviction is not supported on all devices */
4409 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4410 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4411 return -EOPNOTSUPP;
4412
Alan Bradyfe09ed02017-12-29 08:50:34 -05004413 /* If the driver detected FW LLDP was disabled on init, this flag could
4414 * be set, however we do not support _changing_ the flag if NPAR is
4415 * enabled or FW API version < 1.7. There are situations where older
4416 * FW versions/NPAR enabled PFs could disable LLDP, however we _must_
4417 * not allow the user to enable/disable LLDP with this flag on
4418 * unsupported FW versions.
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004419 */
Alan Bradyfe09ed02017-12-29 08:50:34 -05004420 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
Dave Ertman7b634352018-01-22 12:00:37 -05004421 if (!(pf->hw_features & I40E_HW_STOPPABLE_FW_LLDP)) {
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004422 dev_warn(&pf->pdev->dev,
Dave Ertman7b634352018-01-22 12:00:37 -05004423 "Device does not support changing FW LLDP\n");
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004424 return -EOPNOTSUPP;
4425 }
4426 }
4427
Jacob Keller886ff142018-03-16 01:26:36 -07004428 /* Now that we've checked to ensure that the new flags are valid, load
4429 * them into place. Since we only modify flags either (a) during
4430 * initialization or (b) while holding the RTNL lock, we don't need
4431 * anything fancy here.
Jacob Keller841c9502017-06-23 04:24:50 -04004432 */
Jacob Keller886ff142018-03-16 01:26:36 -07004433 pf->flags = new_flags;
Jacob Keller841c9502017-06-23 04:24:50 -04004434
Alexander Duyckaca955d2017-03-10 12:22:01 -08004435 /* Process any additional changes needed as a result of flag changes.
4436 * The changed_flags value reflects the list of bits that were
4437 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004438 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004439
Alexander Duyckaca955d2017-03-10 12:22:01 -08004440 /* Flush current ATR settings if ATR was disabled */
4441 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4442 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller134201a2018-03-16 01:26:32 -07004443 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
Jacob Keller0da36b92017-04-19 09:25:55 -04004444 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004445 }
4446
Alexander Duyckaca955d2017-03-10 12:22:01 -08004447 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4448 u16 sw_flags = 0, valid_flags = 0;
4449 int ret;
4450
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004451 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4452 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4453 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4454 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07004455 0, NULL);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004456 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4457 dev_info(&pf->pdev->dev,
4458 "couldn't set switch config bits, err %s aq_err %s\n",
4459 i40e_stat_str(&pf->hw, ret),
4460 i40e_aq_str(&pf->hw,
4461 pf->hw.aq.asq_last_status));
4462 /* not a fatal problem, just keep going */
4463 }
4464 }
4465
Paweł Jabłoński17b4d252017-12-29 08:50:20 -05004466 if ((changed_flags & pf->flags &
4467 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4468 (pf->flags & I40E_FLAG_MFP_ENABLED))
4469 dev_warn(&pf->pdev->dev,
4470 "Turning on link-down-on-close flag may affect other partitions\n");
4471
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004472 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4473 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4474 struct i40e_dcbx_config *dcbcfg;
4475 int i;
4476
4477 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4478 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4479 /* reset local_dcbx_config to default */
4480 dcbcfg = &pf->hw.local_dcbx_config;
4481 dcbcfg->etscfg.willing = 1;
4482 dcbcfg->etscfg.maxtcs = 0;
4483 dcbcfg->etscfg.tcbwtable[0] = 100;
4484 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4485 dcbcfg->etscfg.tcbwtable[i] = 0;
4486 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4487 dcbcfg->etscfg.prioritytable[i] = 0;
4488 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4489 dcbcfg->pfc.willing = 1;
4490 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4491 } else {
4492 i40e_aq_start_lldp(&pf->hw, NULL);
4493 }
4494 }
4495
Alexander Duyckaca955d2017-03-10 12:22:01 -08004496 /* Issue reset to cause things to take effect, as additional bits
4497 * are added we will need to create a mask of bits requiring reset
4498 */
Mitch Williams64615b52017-08-29 05:32:30 -04004499 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4500 I40E_FLAG_LEGACY_RX |
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004501 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4502 I40E_FLAG_DISABLE_FW_LLDP))
Maciej Sosin373149f2017-04-05 07:50:55 -04004503 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004504
Shannon Nelson9ac77262015-08-27 11:42:40 -04004505 return 0;
4506}
4507
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004508/**
4509 * i40e_get_module_info - get (Q)SFP+ module type info
4510 * @netdev: network interface device structure
4511 * @modinfo: module EEPROM size and layout information structure
4512 **/
4513static int i40e_get_module_info(struct net_device *netdev,
4514 struct ethtool_modinfo *modinfo)
4515{
4516 struct i40e_netdev_priv *np = netdev_priv(netdev);
4517 struct i40e_vsi *vsi = np->vsi;
4518 struct i40e_pf *pf = vsi->back;
4519 struct i40e_hw *hw = &pf->hw;
4520 u32 sff8472_comp = 0;
4521 u32 sff8472_swap = 0;
4522 u32 sff8636_rev = 0;
4523 i40e_status status;
4524 u32 type = 0;
4525
4526 /* Check if firmware supports reading module EEPROM. */
4527 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4528 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4529 return -EINVAL;
4530 }
4531
4532 status = i40e_update_link_info(hw);
4533 if (status)
4534 return -EIO;
4535
4536 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4537 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4538 return -EINVAL;
4539 }
4540
4541 type = hw->phy.link_info.module_type[0];
4542
4543 switch (type) {
4544 case I40E_MODULE_TYPE_SFP:
4545 status = i40e_aq_get_phy_register(hw,
4546 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4547 I40E_I2C_EEPROM_DEV_ADDR,
4548 I40E_MODULE_SFF_8472_COMP,
4549 &sff8472_comp, NULL);
4550 if (status)
4551 return -EIO;
4552
4553 status = i40e_aq_get_phy_register(hw,
4554 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4555 I40E_I2C_EEPROM_DEV_ADDR,
4556 I40E_MODULE_SFF_8472_SWAP,
4557 &sff8472_swap, NULL);
4558 if (status)
4559 return -EIO;
4560
4561 /* Check if the module requires address swap to access
4562 * the other EEPROM memory page.
4563 */
4564 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4565 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4566 modinfo->type = ETH_MODULE_SFF_8079;
4567 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4568 } else if (sff8472_comp == 0x00) {
4569 /* Module is not SFF-8472 compliant */
4570 modinfo->type = ETH_MODULE_SFF_8079;
4571 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4572 } else {
4573 modinfo->type = ETH_MODULE_SFF_8472;
4574 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4575 }
4576 break;
4577 case I40E_MODULE_TYPE_QSFP_PLUS:
4578 /* Read from memory page 0. */
4579 status = i40e_aq_get_phy_register(hw,
4580 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4581 0,
4582 I40E_MODULE_REVISION_ADDR,
4583 &sff8636_rev, NULL);
4584 if (status)
4585 return -EIO;
4586 /* Determine revision compliance byte */
4587 if (sff8636_rev > 0x02) {
4588 /* Module is SFF-8636 compliant */
4589 modinfo->type = ETH_MODULE_SFF_8636;
4590 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4591 } else {
4592 modinfo->type = ETH_MODULE_SFF_8436;
4593 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4594 }
4595 break;
4596 case I40E_MODULE_TYPE_QSFP28:
4597 modinfo->type = ETH_MODULE_SFF_8636;
4598 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4599 break;
4600 default:
4601 netdev_err(vsi->netdev, "Module type unrecognized\n");
4602 return -EINVAL;
4603 }
4604 return 0;
4605}
4606
4607/**
4608 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4609 * @netdev: network interface device structure
4610 * @ee: EEPROM dump request structure
4611 * @data: buffer to be filled with EEPROM contents
4612 **/
4613static int i40e_get_module_eeprom(struct net_device *netdev,
4614 struct ethtool_eeprom *ee,
4615 u8 *data)
4616{
4617 struct i40e_netdev_priv *np = netdev_priv(netdev);
4618 struct i40e_vsi *vsi = np->vsi;
4619 struct i40e_pf *pf = vsi->back;
4620 struct i40e_hw *hw = &pf->hw;
4621 bool is_sfp = false;
4622 i40e_status status;
4623 u32 value = 0;
4624 int i;
4625
4626 if (!ee || !ee->len || !data)
4627 return -EINVAL;
4628
4629 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4630 is_sfp = true;
4631
4632 for (i = 0; i < ee->len; i++) {
4633 u32 offset = i + ee->offset;
4634 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4635
4636 /* Check if we need to access the other memory page */
4637 if (is_sfp) {
4638 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4639 offset -= ETH_MODULE_SFF_8079_LEN;
4640 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4641 }
4642 } else {
4643 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4644 /* Compute memory page number and offset. */
4645 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4646 addr++;
4647 }
4648 }
4649
4650 status = i40e_aq_get_phy_register(hw,
4651 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4652 addr, offset, &value, NULL);
4653 if (status)
4654 return -EIO;
4655 data[i] = value;
4656 }
4657 return 0;
4658}
4659
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004660static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004661 .get_drvinfo = i40e_get_drvinfo,
4662 .get_regs_len = i40e_get_regs_len,
4663 .get_regs = i40e_get_regs,
4664 .nway_reset = i40e_nway_reset,
4665 .get_link = ethtool_op_get_link,
4666 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004667 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004668 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004669 .get_eeprom_len = i40e_get_eeprom_len,
4670 .get_eeprom = i40e_get_eeprom,
4671 .get_ringparam = i40e_get_ringparam,
4672 .set_ringparam = i40e_set_ringparam,
4673 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004674 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004675 .get_msglevel = i40e_get_msglevel,
4676 .set_msglevel = i40e_set_msglevel,
4677 .get_rxnfc = i40e_get_rxnfc,
4678 .set_rxnfc = i40e_set_rxnfc,
4679 .self_test = i40e_diag_test,
4680 .get_strings = i40e_get_strings,
4681 .set_phys_id = i40e_set_phys_id,
4682 .get_sset_count = i40e_get_sset_count,
4683 .get_ethtool_stats = i40e_get_ethtool_stats,
4684 .get_coalesce = i40e_get_coalesce,
4685 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004686 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4687 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4688 .get_rxfh = i40e_get_rxfh,
4689 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004690 .get_channels = i40e_get_channels,
4691 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004692 .get_module_info = i40e_get_module_info,
4693 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004694 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004695 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004696 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004697 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004698 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004699 .get_link_ksettings = i40e_get_link_ksettings,
4700 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004701};
4702
4703void i40e_set_ethtool_ops(struct net_device *netdev)
4704{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004705 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004706}