blob: 6947a2a571cb2df2aae4e820344ee16dd3487c27 [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[] = {
Jacob Kellerbf1c39e2018-05-17 01:08:37 -070045 I40E_VEB_STAT("veb.rx_bytes", stats.rx_bytes),
46 I40E_VEB_STAT("veb.tx_bytes", stats.tx_bytes),
47 I40E_VEB_STAT("veb.rx_unicast", stats.rx_unicast),
48 I40E_VEB_STAT("veb.tx_unicast", stats.tx_unicast),
49 I40E_VEB_STAT("veb.rx_multicast", stats.rx_multicast),
50 I40E_VEB_STAT("veb.tx_multicast", stats.tx_multicast),
51 I40E_VEB_STAT("veb.rx_broadcast", stats.rx_broadcast),
52 I40E_VEB_STAT("veb.tx_broadcast", stats.tx_broadcast),
53 I40E_VEB_STAT("veb.rx_discards", stats.rx_discards),
54 I40E_VEB_STAT("veb.tx_discards", stats.tx_discards),
55 I40E_VEB_STAT("veb.tx_errors", stats.tx_errors),
56 I40E_VEB_STAT("veb.rx_unknown_protocol", stats.rx_unknown_protocol),
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000057};
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[] = {
Jacob Kellerbf1c39e2018-05-17 01:08:37 -070085 I40E_PF_STAT("port.rx_bytes", stats.eth.rx_bytes),
86 I40E_PF_STAT("port.tx_bytes", stats.eth.tx_bytes),
87 I40E_PF_STAT("port.rx_unicast", stats.eth.rx_unicast),
88 I40E_PF_STAT("port.tx_unicast", stats.eth.tx_unicast),
89 I40E_PF_STAT("port.rx_multicast", stats.eth.rx_multicast),
90 I40E_PF_STAT("port.tx_multicast", stats.eth.tx_multicast),
91 I40E_PF_STAT("port.rx_broadcast", stats.eth.rx_broadcast),
92 I40E_PF_STAT("port.tx_broadcast", stats.eth.tx_broadcast),
93 I40E_PF_STAT("port.tx_errors", stats.eth.tx_errors),
94 I40E_PF_STAT("port.rx_dropped", stats.eth.rx_discards),
95 I40E_PF_STAT("port.tx_dropped_link_down", stats.tx_dropped_link_down),
96 I40E_PF_STAT("port.rx_crc_errors", stats.crc_errors),
97 I40E_PF_STAT("port.illegal_bytes", stats.illegal_bytes),
98 I40E_PF_STAT("port.mac_local_faults", stats.mac_local_faults),
99 I40E_PF_STAT("port.mac_remote_faults", stats.mac_remote_faults),
100 I40E_PF_STAT("port.tx_timeout", tx_timeout_count),
101 I40E_PF_STAT("port.rx_csum_bad", hw_csum_rx_error),
102 I40E_PF_STAT("port.rx_length_errors", stats.rx_length_errors),
103 I40E_PF_STAT("port.link_xon_rx", stats.link_xon_rx),
104 I40E_PF_STAT("port.link_xoff_rx", stats.link_xoff_rx),
105 I40E_PF_STAT("port.link_xon_tx", stats.link_xon_tx),
106 I40E_PF_STAT("port.link_xoff_tx", stats.link_xoff_tx),
107 I40E_PF_STAT("port.rx_size_64", stats.rx_size_64),
108 I40E_PF_STAT("port.rx_size_127", stats.rx_size_127),
109 I40E_PF_STAT("port.rx_size_255", stats.rx_size_255),
110 I40E_PF_STAT("port.rx_size_511", stats.rx_size_511),
111 I40E_PF_STAT("port.rx_size_1023", stats.rx_size_1023),
112 I40E_PF_STAT("port.rx_size_1522", stats.rx_size_1522),
113 I40E_PF_STAT("port.rx_size_big", stats.rx_size_big),
114 I40E_PF_STAT("port.tx_size_64", stats.tx_size_64),
115 I40E_PF_STAT("port.tx_size_127", stats.tx_size_127),
116 I40E_PF_STAT("port.tx_size_255", stats.tx_size_255),
117 I40E_PF_STAT("port.tx_size_511", stats.tx_size_511),
118 I40E_PF_STAT("port.tx_size_1023", stats.tx_size_1023),
119 I40E_PF_STAT("port.tx_size_1522", stats.tx_size_1522),
120 I40E_PF_STAT("port.tx_size_big", stats.tx_size_big),
121 I40E_PF_STAT("port.rx_undersize", stats.rx_undersize),
122 I40E_PF_STAT("port.rx_fragments", stats.rx_fragments),
123 I40E_PF_STAT("port.rx_oversize", stats.rx_oversize),
124 I40E_PF_STAT("port.rx_jabber", stats.rx_jabber),
125 I40E_PF_STAT("port.VF_admin_queue_requests", vf_aq_requests),
126 I40E_PF_STAT("port.arq_overflows", arq_overflows),
127 I40E_PF_STAT("port.tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
128 I40E_PF_STAT("port.rx_hwtstamp_cleared", rx_hwtstamp_cleared),
129 I40E_PF_STAT("port.tx_hwtstamp_skipped", tx_hwtstamp_skipped),
130 I40E_PF_STAT("port.fdir_flush_cnt", fd_flush_cnt),
131 I40E_PF_STAT("port.fdir_atr_match", stats.fd_atr_match),
132 I40E_PF_STAT("port.fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
133 I40E_PF_STAT("port.fdir_atr_status", stats.fd_atr_status),
134 I40E_PF_STAT("port.fdir_sb_match", stats.fd_sb_match),
135 I40E_PF_STAT("port.fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000136
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000137 /* LPI stats */
Jacob Kellerbf1c39e2018-05-17 01:08:37 -0700138 I40E_PF_STAT("port.tx_lpi_status", stats.tx_lpi_status),
139 I40E_PF_STAT("port.rx_lpi_status", stats.rx_lpi_status),
140 I40E_PF_STAT("port.tx_lpi_count", stats.tx_lpi_count),
141 I40E_PF_STAT("port.rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000142};
143
Jacob Kellerb8312362018-05-17 01:08:34 -0700144/* We use num_tx_queues here as a proxy for the maximum number of queues
145 * available because we always allocate queues symmetrically.
146 */
147#define I40E_MAX_NUM_QUEUES(n) ((n)->num_tx_queues)
148#define I40E_QUEUE_STATS_LEN(n) \
149 (I40E_MAX_NUM_QUEUES(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000150 * 2 /* Tx and Rx together */ \
151 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000152#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
Jacob Keller132ee002018-05-10 05:59:43 -0700153#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000154#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jacob Keller132ee002018-05-10 05:59:43 -0700155#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000156 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000157 I40E_QUEUE_STATS_LEN((n)))
158#define I40E_PFC_STATS_LEN ( \
159 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
160 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
161 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
162 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
163 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
164 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400165#define I40E_VEB_TC_STATS_LEN ( \
166 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
167 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
168 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
169 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
170 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000171#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400172#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000173#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
174 I40E_PFC_STATS_LEN + \
175 I40E_VSI_STATS_LEN((n)))
176
177enum i40e_ethtool_test_id {
178 I40E_ETH_TEST_REG = 0,
179 I40E_ETH_TEST_EEPROM,
180 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000181 I40E_ETH_TEST_LINK,
182};
183
184static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
185 "Register test (offline)",
186 "Eeprom test (offline)",
187 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000188 "Link test (on/offline)"
189};
190
191#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
192
Alexander Duyckaca955d2017-03-10 12:22:01 -0800193struct i40e_priv_flags {
194 char flag_string[ETH_GSTRING_LEN];
195 u64 flag;
196 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000197};
198
Alexander Duyckaca955d2017-03-10 12:22:01 -0800199#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
200 .flag_string = _name, \
201 .flag = _flag, \
202 .read_only = _read_only, \
203}
204
205static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
206 /* NOTE: MFP setting cannot be changed */
207 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
208 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
209 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
210 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700211 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Mariusz Stachurac3880bd2017-11-14 07:00:50 -0500212 I40E_PRIV_FLAG("link-down-on-close",
213 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700214 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400215 I40E_PRIV_FLAG("disable-source-pruning",
216 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Dave Ertmanc61c8fe2017-12-27 08:18:21 -0500217 I40E_PRIV_FLAG("disable-fw-lldp", I40E_FLAG_DISABLE_FW_LLDP, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800218};
219
220#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000221
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700222/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800223static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
224 I40E_PRIV_FLAG("vf-true-promisc-support",
225 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700226};
227
Alexander Duyckaca955d2017-03-10 12:22:01 -0800228#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700229
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000230/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000231 * i40e_partition_setting_complaint - generic complaint for MFP restriction
232 * @pf: the PF struct
233 **/
234static void i40e_partition_setting_complaint(struct i40e_pf *pf)
235{
236 dev_info(&pf->pdev->dev,
237 "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");
238}
239
240/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700241 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
Alan Brady52e2d022017-10-05 14:53:35 -0700242 * @pf: PF struct with phy_types
Alan Brady1eaae512017-10-05 14:53:41 -0700243 * @ks: ethtool link ksettings struct to fill out
Catherine Sullivan06566e52016-05-03 15:13:14 -0700244 *
245 **/
Alan Brady1eaae512017-10-05 14:53:41 -0700246static void i40e_phy_type_to_ethtool(struct i40e_pf *pf,
247 struct ethtool_link_ksettings *ks)
Catherine Sullivan06566e52016-05-03 15:13:14 -0700248{
Avinash Dayanand28537042016-06-20 09:10:33 -0700249 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800250 u64 phy_types = pf->hw.phy.phy_types;
251
Alan Brady1eaae512017-10-05 14:53:41 -0700252 ethtool_link_ksettings_zero_link_mode(ks, supported);
253 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700254
255 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
Alan Brady1eaae512017-10-05 14:53:41 -0700256 ethtool_link_ksettings_add_link_mode(ks, supported,
257 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700258 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700259 ethtool_link_ksettings_add_link_mode(ks, advertising,
260 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400261 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady1eaae512017-10-05 14:53:41 -0700262 ethtool_link_ksettings_add_link_mode(ks, supported,
263 100baseT_Full);
264 ethtool_link_ksettings_add_link_mode(ks, advertising,
265 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700266 }
267 }
268 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
269 phy_types & I40E_CAP_PHY_TYPE_XFI ||
270 phy_types & I40E_CAP_PHY_TYPE_SFI ||
271 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
Alan Brady1eaae512017-10-05 14:53:41 -0700272 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) {
273 ethtool_link_ksettings_add_link_mode(ks, supported,
274 10000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700275 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700276 ethtool_link_ksettings_add_link_mode(ks, advertising,
277 10000baseT_Full);
278 }
279 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_T) {
280 ethtool_link_ksettings_add_link_mode(ks, supported,
281 10000baseT_Full);
282 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
283 ethtool_link_ksettings_add_link_mode(ks, advertising,
284 10000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700285 }
286 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
287 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
288 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
Alan Brady1eaae512017-10-05 14:53:41 -0700289 ethtool_link_ksettings_add_link_mode(ks, supported,
290 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700291 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
292 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700293 ethtool_link_ksettings_add_link_mode(ks, supported,
294 40000baseCR4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700295 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700296 ethtool_link_ksettings_add_link_mode(ks, advertising,
297 40000baseCR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700298 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700299 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700300 ethtool_link_ksettings_add_link_mode(ks, supported,
301 100baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700302 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady1eaae512017-10-05 14:53:41 -0700303 ethtool_link_ksettings_add_link_mode(ks, advertising,
304 100baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700305 }
Alan Brady1eaae512017-10-05 14:53:41 -0700306 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T) {
307 ethtool_link_ksettings_add_link_mode(ks, supported,
308 1000baseT_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700309 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700310 ethtool_link_ksettings_add_link_mode(ks, advertising,
311 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700312 }
313 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700314 ethtool_link_ksettings_add_link_mode(ks, supported,
315 40000baseSR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700316 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
Alan Brady1eaae512017-10-05 14:53:41 -0700317 ethtool_link_ksettings_add_link_mode(ks, supported,
318 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700319 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700320 ethtool_link_ksettings_add_link_mode(ks, supported,
321 40000baseLR4_Full);
322 ethtool_link_ksettings_add_link_mode(ks, advertising,
323 40000baseLR4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700324 }
325 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
Alan Brady1eaae512017-10-05 14:53:41 -0700326 ethtool_link_ksettings_add_link_mode(ks, supported,
327 20000baseKR2_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700328 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700329 ethtool_link_ksettings_add_link_mode(ks, advertising,
330 20000baseKR2_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700331 }
332 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
Alan Brady1eaae512017-10-05 14:53:41 -0700333 ethtool_link_ksettings_add_link_mode(ks, supported,
334 10000baseKX4_Full);
Avinash Dayanand28537042016-06-20 09:10:33 -0700335 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700336 ethtool_link_ksettings_add_link_mode(ks, advertising,
337 10000baseKX4_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700338 }
Alan Brady6987bd252017-10-05 14:53:38 -0700339 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
340 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700341 ethtool_link_ksettings_add_link_mode(ks, supported,
342 10000baseKR_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700343 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700344 ethtool_link_ksettings_add_link_mode(ks, advertising,
345 10000baseKR_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700346 }
Alan Brady6987bd252017-10-05 14:53:38 -0700347 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
348 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
Alan Brady1eaae512017-10-05 14:53:41 -0700349 ethtool_link_ksettings_add_link_mode(ks, supported,
350 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700351 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady1eaae512017-10-05 14:53:41 -0700352 ethtool_link_ksettings_add_link_mode(ks, advertising,
353 1000baseKX_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700354 }
Alan Brady1eaae512017-10-05 14:53:41 -0700355 /* need to add 25G PHY types */
356 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR) {
357 ethtool_link_ksettings_add_link_mode(ks, supported,
358 25000baseKR_Full);
359 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
360 ethtool_link_ksettings_add_link_mode(ks, advertising,
361 25000baseKR_Full);
362 }
363 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR) {
364 ethtool_link_ksettings_add_link_mode(ks, supported,
365 25000baseCR_Full);
366 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
367 ethtool_link_ksettings_add_link_mode(ks, advertising,
368 25000baseCR_Full);
369 }
370 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800371 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
Alan Brady1eaae512017-10-05 14:53:41 -0700372 ethtool_link_ksettings_add_link_mode(ks, supported,
373 25000baseSR_Full);
374 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
375 ethtool_link_ksettings_add_link_mode(ks, advertising,
376 25000baseSR_Full);
377 }
378 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_AOC ||
379 phy_types & I40E_CAP_PHY_TYPE_25GBASE_ACC) {
380 ethtool_link_ksettings_add_link_mode(ks, supported,
381 25000baseCR_Full);
382 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_25GB)
383 ethtool_link_ksettings_add_link_mode(ks, advertising,
384 25000baseCR_Full);
385 }
386 /* need to add new 10G PHY types */
387 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
388 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU) {
389 ethtool_link_ksettings_add_link_mode(ks, supported,
390 10000baseCR_Full);
391 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
392 ethtool_link_ksettings_add_link_mode(ks, advertising,
393 10000baseCR_Full);
394 }
395 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR) {
396 ethtool_link_ksettings_add_link_mode(ks, supported,
397 10000baseSR_Full);
398 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
399 ethtool_link_ksettings_add_link_mode(ks, advertising,
400 10000baseSR_Full);
401 }
402 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
403 ethtool_link_ksettings_add_link_mode(ks, supported,
404 10000baseLR_Full);
405 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
406 ethtool_link_ksettings_add_link_mode(ks, advertising,
407 10000baseLR_Full);
408 }
409 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
410 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
411 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
412 ethtool_link_ksettings_add_link_mode(ks, supported,
413 1000baseX_Full);
414 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
415 ethtool_link_ksettings_add_link_mode(ks, advertising,
416 1000baseX_Full);
Alan Brady6987bd252017-10-05 14:53:38 -0700417 }
418 /* Autoneg PHY types */
419 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
420 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
421 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
422 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800423 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700424 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
425 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
426 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
427 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
428 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
429 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
430 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
431 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
432 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
433 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
434 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
435 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
436 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
437 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
438 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
439 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
440 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady1eaae512017-10-05 14:53:41 -0700441 ethtool_link_ksettings_add_link_mode(ks, supported,
442 Autoneg);
443 ethtool_link_ksettings_add_link_mode(ks, advertising,
444 Autoneg);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800445 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700446}
447
448/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000449 * i40e_get_settings_link_up - Get the Link settings for when link is up
450 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700451 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000452 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700453 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000454 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000455static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700456 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400457 struct net_device *netdev,
458 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000459{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000460 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Alan Brady1eaae512017-10-05 14:53:41 -0700461 struct ethtool_link_ksettings cap_ksettings;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000462 u32 link_speed = hw_link_info->link_speed;
463
Catherine Sullivane8278452015-02-06 08:52:08 +0000464 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000465 switch (hw_link_info->phy_type) {
466 case I40E_PHY_TYPE_40GBASE_CR4:
467 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Alan Brady79f04a32017-10-05 14:53:42 -0700468 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
469 ethtool_link_ksettings_add_link_mode(ks, supported,
470 40000baseCR4_Full);
471 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
472 ethtool_link_ksettings_add_link_mode(ks, advertising,
473 40000baseCR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000474 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000475 case I40E_PHY_TYPE_XLAUI:
476 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000477 case I40E_PHY_TYPE_40GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700478 ethtool_link_ksettings_add_link_mode(ks, supported,
479 40000baseCR4_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000480 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000481 case I40E_PHY_TYPE_40GBASE_SR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700482 ethtool_link_ksettings_add_link_mode(ks, supported,
483 40000baseSR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000484 break;
485 case I40E_PHY_TYPE_40GBASE_LR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700486 ethtool_link_ksettings_add_link_mode(ks, supported,
487 40000baseLR4_Full);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000488 break;
Alan Brady79f04a32017-10-05 14:53:42 -0700489 case I40E_PHY_TYPE_25GBASE_SR:
490 case I40E_PHY_TYPE_25GBASE_LR:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000491 case I40E_PHY_TYPE_10GBASE_SR:
492 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000493 case I40E_PHY_TYPE_1000BASE_SX:
494 case I40E_PHY_TYPE_1000BASE_LX:
Alan Brady79f04a32017-10-05 14:53:42 -0700495 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
496 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
497 ethtool_link_ksettings_add_link_mode(ks, supported,
498 25000baseSR_Full);
499 ethtool_link_ksettings_add_link_mode(ks, advertising,
500 25000baseSR_Full);
501 ethtool_link_ksettings_add_link_mode(ks, supported,
502 10000baseSR_Full);
503 ethtool_link_ksettings_add_link_mode(ks, advertising,
504 10000baseSR_Full);
505 ethtool_link_ksettings_add_link_mode(ks, supported,
506 10000baseLR_Full);
507 ethtool_link_ksettings_add_link_mode(ks, advertising,
508 10000baseLR_Full);
509 ethtool_link_ksettings_add_link_mode(ks, supported,
510 1000baseX_Full);
511 ethtool_link_ksettings_add_link_mode(ks, advertising,
512 1000baseX_Full);
513 ethtool_link_ksettings_add_link_mode(ks, supported,
514 10000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400515 if (hw_link_info->module_type[2] &
516 I40E_MODULE_TYPE_1000BASE_SX ||
517 hw_link_info->module_type[2] &
518 I40E_MODULE_TYPE_1000BASE_LX) {
Alan Brady79f04a32017-10-05 14:53:42 -0700519 ethtool_link_ksettings_add_link_mode(ks, supported,
520 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400521 if (hw_link_info->requested_speeds &
522 I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700523 ethtool_link_ksettings_add_link_mode(
524 ks, advertising, 1000baseT_Full);
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400525 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000526 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700527 ethtool_link_ksettings_add_link_mode(ks, advertising,
528 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000529 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000530 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000531 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700532 case I40E_PHY_TYPE_100BASE_TX:
Alan Brady79f04a32017-10-05 14:53:42 -0700533 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
534 ethtool_link_ksettings_add_link_mode(ks, supported,
535 10000baseT_Full);
536 ethtool_link_ksettings_add_link_mode(ks, supported,
537 1000baseT_Full);
538 ethtool_link_ksettings_add_link_mode(ks, supported,
539 100baseT_Full);
540 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivane8278452015-02-06 08:52:08 +0000541 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700542 ethtool_link_ksettings_add_link_mode(ks, advertising,
543 10000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000544 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700545 ethtool_link_ksettings_add_link_mode(ks, advertising,
546 1000baseT_Full);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700547 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700548 ethtool_link_ksettings_add_link_mode(ks, advertising,
549 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400550 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400551 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Alan Brady79f04a32017-10-05 14:53:42 -0700552 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
553 ethtool_link_ksettings_add_link_mode(ks, supported,
554 1000baseT_Full);
555 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
556 ethtool_link_ksettings_add_link_mode(ks, advertising,
557 1000baseT_Full);
Catherine Sullivan48becae2015-09-28 14:12:41 -0400558 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000559 case I40E_PHY_TYPE_10GBASE_CR1_CU:
560 case I40E_PHY_TYPE_10GBASE_CR1:
Alan Brady79f04a32017-10-05 14:53:42 -0700561 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
562 ethtool_link_ksettings_add_link_mode(ks, supported,
563 10000baseT_Full);
564 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
565 ethtool_link_ksettings_add_link_mode(ks, advertising,
566 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000567 break;
568 case I40E_PHY_TYPE_XAUI:
569 case I40E_PHY_TYPE_XFI:
570 case I40E_PHY_TYPE_SFI:
571 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000572 case I40E_PHY_TYPE_10GBASE_AOC:
Alan Brady79f04a32017-10-05 14:53:42 -0700573 ethtool_link_ksettings_add_link_mode(ks, supported,
574 10000baseT_Full);
575 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
576 ethtool_link_ksettings_add_link_mode(ks, advertising,
577 10000baseT_Full);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000578 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000579 case I40E_PHY_TYPE_SGMII:
Alan Brady79f04a32017-10-05 14:53:42 -0700580 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
581 ethtool_link_ksettings_add_link_mode(ks, supported,
582 1000baseT_Full);
Catherine Sullivane8278452015-02-06 08:52:08 +0000583 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Alan Brady79f04a32017-10-05 14:53:42 -0700584 ethtool_link_ksettings_add_link_mode(ks, advertising,
585 1000baseT_Full);
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400586 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Alan Brady79f04a32017-10-05 14:53:42 -0700587 ethtool_link_ksettings_add_link_mode(ks, supported,
588 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400589 if (hw_link_info->requested_speeds &
590 I40E_LINK_SPEED_100MB)
Alan Brady79f04a32017-10-05 14:53:42 -0700591 ethtool_link_ksettings_add_link_mode(
592 ks, advertising, 100baseT_Full);
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400593 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000594 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400595 case I40E_PHY_TYPE_40GBASE_KR4:
Alan Brady79f04a32017-10-05 14:53:42 -0700596 case I40E_PHY_TYPE_25GBASE_KR:
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400597 case I40E_PHY_TYPE_20GBASE_KR2:
598 case I40E_PHY_TYPE_10GBASE_KR:
599 case I40E_PHY_TYPE_10GBASE_KX4:
600 case I40E_PHY_TYPE_1000BASE_KX:
Alan Brady79f04a32017-10-05 14:53:42 -0700601 ethtool_link_ksettings_add_link_mode(ks, supported,
602 40000baseKR4_Full);
603 ethtool_link_ksettings_add_link_mode(ks, supported,
604 25000baseKR_Full);
605 ethtool_link_ksettings_add_link_mode(ks, supported,
606 20000baseKR2_Full);
607 ethtool_link_ksettings_add_link_mode(ks, supported,
608 10000baseKR_Full);
609 ethtool_link_ksettings_add_link_mode(ks, supported,
610 10000baseKX4_Full);
611 ethtool_link_ksettings_add_link_mode(ks, supported,
612 1000baseKX_Full);
613 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
614 ethtool_link_ksettings_add_link_mode(ks, advertising,
615 40000baseKR4_Full);
616 ethtool_link_ksettings_add_link_mode(ks, advertising,
617 25000baseKR_Full);
618 ethtool_link_ksettings_add_link_mode(ks, advertising,
619 20000baseKR2_Full);
620 ethtool_link_ksettings_add_link_mode(ks, advertising,
621 10000baseKR_Full);
622 ethtool_link_ksettings_add_link_mode(ks, advertising,
623 10000baseKX4_Full);
624 ethtool_link_ksettings_add_link_mode(ks, advertising,
625 1000baseKX_Full);
626 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400627 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800628 case I40E_PHY_TYPE_25GBASE_CR:
Alan Brady79f04a32017-10-05 14:53:42 -0700629 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
630 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
631 ethtool_link_ksettings_add_link_mode(ks, supported,
632 25000baseCR_Full);
633 ethtool_link_ksettings_add_link_mode(ks, advertising,
634 25000baseCR_Full);
635 break;
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700636 case I40E_PHY_TYPE_25GBASE_AOC:
637 case I40E_PHY_TYPE_25GBASE_ACC:
Alan Brady79f04a32017-10-05 14:53:42 -0700638 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
639 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
640 ethtool_link_ksettings_add_link_mode(ks, supported,
641 25000baseCR_Full);
642
643 ethtool_link_ksettings_add_link_mode(ks, advertising,
644 25000baseCR_Full);
645 ethtool_link_ksettings_add_link_mode(ks, supported,
646 10000baseCR_Full);
647 ethtool_link_ksettings_add_link_mode(ks, advertising,
648 10000baseCR_Full);
Carolyn Wyborny31232372016-11-21 13:03:48 -0800649 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000650 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000651 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700652 netdev_info(netdev,
653 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000654 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000655 }
656
Catherine Sullivan06566e52016-05-03 15:13:14 -0700657 /* Now that we've worked out everything that could be supported by the
Alan Brady91a5c442017-10-05 14:53:36 -0700658 * current PHY type, get what is supported by the NVM and intersect
659 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700660 */
Alan Brady1eaae512017-10-05 14:53:41 -0700661 memset(&cap_ksettings, 0, sizeof(struct ethtool_link_ksettings));
662 i40e_phy_type_to_ethtool(pf, &cap_ksettings);
663 ethtool_intersect_link_masks(ks, &cap_ksettings);
Catherine Sullivan06566e52016-05-03 15:13:14 -0700664
Catherine Sullivane8278452015-02-06 08:52:08 +0000665 /* Set speed and duplex */
666 switch (link_speed) {
667 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700668 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000669 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800670 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700671 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800672 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700673 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700674 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700675 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000676 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700677 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000678 break;
679 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700680 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000681 break;
682 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700683 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000684 break;
685 default:
686 break;
687 }
Alan Brady1c142e12017-10-05 14:53:31 -0700688 ks->base.duplex = DUPLEX_FULL;
Catherine Sullivane8278452015-02-06 08:52:08 +0000689}
690
691/**
692 * i40e_get_settings_link_down - Get the Link settings for when link is down
693 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700694 * @ks: ethtool ksettings to fill in
695 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000696 *
697 * Reports link settings that can be determined when link is down
698 **/
699static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700700 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400701 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000702{
Catherine Sullivane8278452015-02-06 08:52:08 +0000703 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400704 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000705 */
Alan Brady1eaae512017-10-05 14:53:41 -0700706 i40e_phy_type_to_ethtool(pf, ks);
Catherine Sullivane8278452015-02-06 08:52:08 +0000707
708 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700709 ks->base.speed = SPEED_UNKNOWN;
710 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000711}
712
713/**
Alan Brady1c142e12017-10-05 14:53:31 -0700714 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000715 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700716 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000717 *
718 * Reports speed/duplex settings based on media_type
719 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100720static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700721 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000722{
723 struct i40e_netdev_priv *np = netdev_priv(netdev);
724 struct i40e_pf *pf = np->vsi->back;
725 struct i40e_hw *hw = &pf->hw;
726 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
727 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Alan Brady5f434992017-10-05 14:53:34 -0700728
729 ethtool_link_ksettings_zero_link_mode(ks, supported);
730 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000731
732 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700733 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000734 else
Alan Brady1c142e12017-10-05 14:53:31 -0700735 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000736
737 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000738 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700739 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
740 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000741
Alan Bradya03af692017-10-05 14:53:37 -0700742 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000743 switch (hw->phy.media_type) {
744 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700745 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
746 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
747 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700748 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100749 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700750 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000751 break;
752 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700753 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
754 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
755 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000756 break;
757 case I40E_MEDIA_TYPE_DA:
758 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700759 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
760 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
761 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000762 break;
763 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700764 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
765 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000766 break;
767 case I40E_MEDIA_TYPE_UNKNOWN:
768 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700769 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000770 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000771 }
772
Catherine Sullivane8278452015-02-06 08:52:08 +0000773 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700774 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000775
Catherine Sullivane8278452015-02-06 08:52:08 +0000776 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000777 case I40E_FC_FULL:
Alan Bradya03af692017-10-05 14:53:37 -0700778 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000779 break;
780 case I40E_FC_TX_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 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700785 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700786 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100787 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000788 break;
789 default:
Alan Brady5f434992017-10-05 14:53:34 -0700790 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
791 ethtool_link_ksettings_del_link_mode(ks, advertising,
792 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000793 break;
794 }
795
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000796 return 0;
797}
798
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000799/**
Alan Brady1c142e12017-10-05 14:53:31 -0700800 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000801 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700802 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000803 *
804 * Set speed/duplex per media_types advertised/forced
805 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100806static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700807 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000808{
809 struct i40e_netdev_priv *np = netdev_priv(netdev);
810 struct i40e_aq_get_phy_abilities_resp abilities;
Alan Brady636b62d2017-10-05 14:53:43 -0700811 struct ethtool_link_ksettings safe_ks;
812 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000813 struct i40e_aq_set_phy_config config;
814 struct i40e_pf *pf = np->vsi->back;
815 struct i40e_vsi *vsi = np->vsi;
816 struct i40e_hw *hw = &pf->hw;
Alan Brady636b62d2017-10-05 14:53:43 -0700817 bool autoneg_changed = false;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000818 i40e_status status = 0;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400819 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000820 int err = 0;
Alan Bradycee91992017-10-05 14:53:44 -0700821 u8 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000822
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000823 /* Changing port settings is not supported if this isn't the
824 * port's controlling PF
825 */
826 if (hw->partition_id != 1) {
827 i40e_partition_setting_complaint(pf);
828 return -EOPNOTSUPP;
829 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000830 if (vsi != pf->vsi[pf->lan_vsi])
831 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000832 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
833 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000834 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700835 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000836 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000837 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400838 if (hw->device_id == I40E_DEV_ID_KX_B ||
839 hw->device_id == I40E_DEV_ID_KX_C ||
840 hw->device_id == I40E_DEV_ID_20G_KR2 ||
Patryk Małek88244a42018-03-19 09:28:03 -0700841 hw->device_id == I40E_DEV_ID_20G_KR2_A ||
Patryk Małek3f8c84372018-03-19 09:28:04 -0700842 hw->device_id == I40E_DEV_ID_25G_B ||
Patryk Małek88244a42018-03-19 09:28:03 -0700843 hw->device_id == I40E_DEV_ID_KX_X722) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400844 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
845 return -EOPNOTSUPP;
846 }
847
Alan Brady1c142e12017-10-05 14:53:31 -0700848 /* copy the ksettings to copy_ks to avoid modifying the origin */
849 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000850
Alan Bradycee91992017-10-05 14:53:44 -0700851 /* save autoneg out of ksettings */
852 autoneg = copy_ks.base.autoneg;
853
Philippe Reynesa7f90942017-02-04 22:05:06 +0100854 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700855 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
Alan Bradycee91992017-10-05 14:53:44 -0700856 safe_ks.base.cmd = copy_ks.base.cmd;
857 safe_ks.base.link_mode_masks_nwords =
858 copy_ks.base.link_mode_masks_nwords;
Alan Brady1c142e12017-10-05 14:53:31 -0700859 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100860
Jan Sokolowski32c23b42018-03-19 09:28:03 -0700861 /* Get link modes supported by hardware and check against modes
862 * requested by the user. Return an error if unsupported mode was set.
863 */
864 if (!bitmap_subset(copy_ks.link_modes.advertising,
865 safe_ks.link_modes.supported,
866 __ETHTOOL_LINK_MODE_MASK_NBITS))
867 return -EINVAL;
868
Alan Bradycee91992017-10-05 14:53:44 -0700869 /* set autoneg back to what it currently is */
Alan Brady1c142e12017-10-05 14:53:31 -0700870 copy_ks.base.autoneg = safe_ks.base.autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000871
Alan Bradycee91992017-10-05 14:53:44 -0700872 /* If copy_ks.base and safe_ks.base are not the same now, then they are
873 * trying to set something that we do not support.
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000874 */
Alan Bradycee91992017-10-05 14:53:44 -0700875 if (memcmp(&copy_ks.base, &safe_ks.base,
876 sizeof(struct ethtool_link_settings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000877 return -EOPNOTSUPP;
878
Jacob Keller0da36b92017-04-19 09:25:55 -0400879 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400880 timeout--;
881 if (!timeout)
882 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000883 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400884 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000885
886 /* Get the current phy config */
887 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
888 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400889 if (status) {
890 err = -EAGAIN;
891 goto done;
892 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000893
Catherine Sullivan124ed152014-07-12 07:28:12 +0000894 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000895 * set below
896 */
897 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000898 config.abilities = abilities.abilities;
899
900 /* Check autoneg */
901 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000902 /* If autoneg was not already enabled */
903 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400904 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700905 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
906 supported,
907 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400908 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400909 err = -EINVAL;
910 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400911 }
912 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000913 config.abilities = abilities.abilities |
914 I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700915 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000916 }
917 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000918 /* If autoneg is currently enabled */
919 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400920 /* If autoneg is supported 10GBASE_T is the only PHY
921 * that can disable it, so otherwise return error
922 */
Alan Brady1c142e12017-10-05 14:53:31 -0700923 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
924 supported,
925 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400926 hw->phy.link_info.phy_type !=
927 I40E_PHY_TYPE_10GBASE_T) {
928 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400929 err = -EINVAL;
930 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400931 }
932 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000933 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000934 ~I40E_AQ_PHY_ENABLE_AN;
Alan Brady636b62d2017-10-05 14:53:43 -0700935 autoneg_changed = true;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000936 }
937 }
938
Alan Bradycee91992017-10-05 14:53:44 -0700939 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
940 100baseT_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000941 config.link_speed |= I40E_LINK_SPEED_100MB;
Alan Bradycee91992017-10-05 14:53:44 -0700942 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
943 1000baseT_Full) ||
944 ethtool_link_ksettings_test_link_mode(ks, advertising,
945 1000baseX_Full) ||
946 ethtool_link_ksettings_test_link_mode(ks, advertising,
947 1000baseKX_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000948 config.link_speed |= I40E_LINK_SPEED_1GB;
Alan Bradycee91992017-10-05 14:53:44 -0700949 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
950 10000baseT_Full) ||
951 ethtool_link_ksettings_test_link_mode(ks, advertising,
952 10000baseKX4_Full) ||
953 ethtool_link_ksettings_test_link_mode(ks, advertising,
954 10000baseKR_Full) ||
955 ethtool_link_ksettings_test_link_mode(ks, advertising,
956 10000baseCR_Full) ||
957 ethtool_link_ksettings_test_link_mode(ks, advertising,
Jakub Pawlak6ee4d322018-04-20 01:41:35 -0700958 10000baseSR_Full) ||
959 ethtool_link_ksettings_test_link_mode(ks, advertising,
960 10000baseLR_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000961 config.link_speed |= I40E_LINK_SPEED_10GB;
Alan Bradycee91992017-10-05 14:53:44 -0700962 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
963 20000baseKR2_Full))
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700964 config.link_speed |= I40E_LINK_SPEED_20GB;
Alan Bradycee91992017-10-05 14:53:44 -0700965 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
966 25000baseCR_Full) ||
967 ethtool_link_ksettings_test_link_mode(ks, advertising,
968 25000baseKR_Full) ||
969 ethtool_link_ksettings_test_link_mode(ks, advertising,
970 25000baseSR_Full))
971 config.link_speed |= I40E_LINK_SPEED_25GB;
972 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
973 40000baseKR4_Full) ||
974 ethtool_link_ksettings_test_link_mode(ks, advertising,
975 40000baseCR4_Full) ||
976 ethtool_link_ksettings_test_link_mode(ks, advertising,
977 40000baseSR4_Full) ||
978 ethtool_link_ksettings_test_link_mode(ks, advertising,
979 40000baseLR4_Full))
Catherine Sullivan124ed152014-07-12 07:28:12 +0000980 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000981
Catherine Sullivan0002e112015-08-26 15:14:16 -0400982 /* If speed didn't get set, set it to what it currently is.
983 * This is needed because if advertise is 0 (as it is when autoneg
984 * is disabled) then speed won't get set.
985 */
986 if (!config.link_speed)
987 config.link_speed = abilities.link_speed;
Alan Brady636b62d2017-10-05 14:53:43 -0700988 if (autoneg_changed || abilities.link_speed != config.link_speed) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000989 /* copy over the rest of the abilities */
990 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800991 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000992 config.eee_capability = abilities.eee_capability;
993 config.eeer = abilities.eeer_val;
994 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800995 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
996 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000997
Catherine Sullivane8278452015-02-06 08:52:08 +0000998 /* save the requested speeds */
999 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +00001000 /* set link and auto negotiation so changes take effect */
1001 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1002 /* If link is up put link down */
1003 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
1004 /* Tell the OS link is going down, the link will go
1005 * back up when fw says it is ready asynchronously
1006 */
Matt Jaredc156f852015-08-27 11:42:39 -04001007 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001008 netif_carrier_off(netdev);
1009 netif_tx_stop_all_queues(netdev);
1010 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001011
1012 /* make the aq call */
1013 status = i40e_aq_set_phy_config(hw, &config, NULL);
1014 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -07001015 netdev_info(netdev,
1016 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001017 i40e_stat_str(hw, status),
1018 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001019 err = -EAGAIN;
1020 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001021 }
1022
Catherine Sullivan0a862b42015-08-31 19:54:53 -04001023 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001024 if (status)
Alan Bradya03af692017-10-05 14:53:37 -07001025 netdev_dbg(netdev,
1026 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -04001027 i40e_stat_str(hw, status),
1028 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001029
1030 } else {
1031 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
1032 }
1033
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001034done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001035 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001036
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00001037 return err;
1038}
1039
Jesse Brandeburga6599722014-06-04 08:45:25 +00001040static int i40e_nway_reset(struct net_device *netdev)
1041{
1042 /* restart autonegotiation */
1043 struct i40e_netdev_priv *np = netdev_priv(netdev);
1044 struct i40e_pf *pf = np->vsi->back;
1045 struct i40e_hw *hw = &pf->hw;
1046 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1047 i40e_status ret = 0;
1048
1049 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
1050 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001051 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1052 i40e_stat_str(hw, ret),
1053 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +00001054 return -EIO;
1055 }
1056
1057 return 0;
1058}
1059
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001060/**
1061 * i40e_get_pauseparam - Get Flow Control status
Jacob Kellerf5254422018-04-20 01:41:33 -07001062 * @netdev: netdevice structure
1063 * @pause: buffer to return pause parameters
1064 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001065 * Return tx/rx-pause status
1066 **/
1067static void i40e_get_pauseparam(struct net_device *netdev,
1068 struct ethtool_pauseparam *pause)
1069{
1070 struct i40e_netdev_priv *np = netdev_priv(netdev);
1071 struct i40e_pf *pf = np->vsi->back;
1072 struct i40e_hw *hw = &pf->hw;
1073 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001074 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001075
1076 pause->autoneg =
1077 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1078 AUTONEG_ENABLE : AUTONEG_DISABLE);
1079
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001080 /* PFC enabled so report LFC as off */
1081 if (dcbx_cfg->pfc.pfcenable) {
1082 pause->rx_pause = 0;
1083 pause->tx_pause = 0;
1084 return;
1085 }
1086
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001087 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001088 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001089 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001090 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +00001091 } else if (hw->fc.current_mode == I40E_FC_FULL) {
1092 pause->rx_pause = 1;
1093 pause->tx_pause = 1;
1094 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001095}
1096
Catherine Sullivan2becc352014-06-04 08:45:27 +00001097/**
1098 * i40e_set_pauseparam - Set Flow Control parameter
1099 * @netdev: network interface device structure
1100 * @pause: return tx/rx flow control status
1101 **/
1102static int i40e_set_pauseparam(struct net_device *netdev,
1103 struct ethtool_pauseparam *pause)
1104{
1105 struct i40e_netdev_priv *np = netdev_priv(netdev);
1106 struct i40e_pf *pf = np->vsi->back;
1107 struct i40e_vsi *vsi = np->vsi;
1108 struct i40e_hw *hw = &pf->hw;
1109 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001110 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001111 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
1112 i40e_status status;
1113 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001114 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +00001115
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001116 /* Changing the port's flow control is not supported if this isn't the
1117 * port's controlling PF
1118 */
1119 if (hw->partition_id != 1) {
1120 i40e_partition_setting_complaint(pf);
1121 return -EOPNOTSUPP;
1122 }
1123
Catherine Sullivan2becc352014-06-04 08:45:27 +00001124 if (vsi != pf->vsi[pf->lan_vsi])
1125 return -EOPNOTSUPP;
1126
1127 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
1128 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
1129 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
1130 return -EOPNOTSUPP;
1131 }
1132
1133 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -04001134 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +00001135 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
1136 /* Send message that it might not necessarily work*/
1137 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
1138 }
1139
Neerav Parikh4b7698c2014-11-12 00:18:57 +00001140 if (dcbx_cfg->pfc.pfcenable) {
1141 netdev_info(netdev,
1142 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001143 return -EOPNOTSUPP;
1144 }
1145
1146 if (pause->rx_pause && pause->tx_pause)
1147 hw->fc.requested_mode = I40E_FC_FULL;
1148 else if (pause->rx_pause && !pause->tx_pause)
1149 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1150 else if (!pause->rx_pause && pause->tx_pause)
1151 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1152 else if (!pause->rx_pause && !pause->tx_pause)
1153 hw->fc.requested_mode = I40E_FC_NONE;
1154 else
1155 return -EINVAL;
1156
Catherine Sullivan94128512014-07-12 07:28:16 +00001157 /* Tell the OS link is going down, the link will go back up when fw
1158 * says it is ready asynchronously
1159 */
Matt Jaredc156f852015-08-27 11:42:39 -04001160 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001161 netif_carrier_off(netdev);
1162 netif_tx_stop_all_queues(netdev);
1163
Catherine Sullivan2becc352014-06-04 08:45:27 +00001164 /* Set the fc mode and only restart an if link is up*/
1165 status = i40e_set_fc(hw, &aq_failures, link_up);
1166
1167 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001168 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1169 i40e_stat_str(hw, status),
1170 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001171 err = -EAGAIN;
1172 }
1173 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001174 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1175 i40e_stat_str(hw, status),
1176 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001177 err = -EAGAIN;
1178 }
1179 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001180 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1181 i40e_stat_str(hw, status),
1182 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001183 err = -EAGAIN;
1184 }
1185
Jacob Keller0da36b92017-04-19 09:25:55 -04001186 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001187 /* Give it a little more time to try to come back */
1188 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001189 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001190 return i40e_nway_reset(netdev);
1191 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001192
1193 return err;
1194}
1195
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001196static u32 i40e_get_msglevel(struct net_device *netdev)
1197{
1198 struct i40e_netdev_priv *np = netdev_priv(netdev);
1199 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001200 u32 debug_mask = pf->hw.debug_mask;
1201
1202 if (debug_mask)
1203 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001204
1205 return pf->msg_enable;
1206}
1207
1208static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1209{
1210 struct i40e_netdev_priv *np = netdev_priv(netdev);
1211 struct i40e_pf *pf = np->vsi->back;
1212
1213 if (I40E_DEBUG_USER & data)
1214 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001215 else
1216 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001217}
1218
1219static int i40e_get_regs_len(struct net_device *netdev)
1220{
1221 int reg_count = 0;
1222 int i;
1223
1224 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1225 reg_count += i40e_reg_list[i].elements;
1226
1227 return reg_count * sizeof(u32);
1228}
1229
1230static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1231 void *p)
1232{
1233 struct i40e_netdev_priv *np = netdev_priv(netdev);
1234 struct i40e_pf *pf = np->vsi->back;
1235 struct i40e_hw *hw = &pf->hw;
1236 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001237 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001238 u32 reg;
1239
1240 /* Tell ethtool which driver-version-specific regs output we have.
1241 *
1242 * At some point, if we have ethtool doing special formatting of
1243 * this data, it will rely on this version number to know how to
1244 * interpret things. Hence, this needs to be updated if/when the
1245 * diags register table is changed.
1246 */
1247 regs->version = 1;
1248
1249 /* loop through the diags reg table for what to print */
1250 ri = 0;
1251 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1252 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1253 reg = i40e_reg_list[i].offset
1254 + (j * i40e_reg_list[i].stride);
1255 reg_buf[ri++] = rd32(hw, reg);
1256 }
1257 }
1258
1259}
1260
1261static int i40e_get_eeprom(struct net_device *netdev,
1262 struct ethtool_eeprom *eeprom, u8 *bytes)
1263{
1264 struct i40e_netdev_priv *np = netdev_priv(netdev);
1265 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001266 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001267 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001268 u8 *eeprom_buff;
1269 u16 i, sectors;
1270 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001271 u32 magic;
1272
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001273#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001274 if (eeprom->len == 0)
1275 return -EINVAL;
1276
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001277 /* check for NVMUpdate access method */
1278 magic = hw->vendor_id | (hw->device_id << 16);
1279 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001280 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1281 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001282
1283 /* make sure it is the right magic for NVMUpdate */
1284 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001285 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001286 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1287 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001288 errno = -EBUSY;
1289 else
1290 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001291
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001292 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001293 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001294 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1295 ret_val, hw->aq.asq_last_status, errno,
1296 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1297 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001298
1299 return errno;
1300 }
1301
1302 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001303 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1304
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001305 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001306 if (!eeprom_buff)
1307 return -ENOMEM;
1308
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001309 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1310 if (ret_val) {
1311 dev_info(&pf->pdev->dev,
1312 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1313 ret_val, hw->aq.asq_last_status);
1314 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001315 }
1316
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001317 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1318 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1319 len = I40E_NVM_SECTOR_SIZE;
1320 last = false;
1321 for (i = 0; i < sectors; i++) {
1322 if (i == (sectors - 1)) {
1323 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1324 last = true;
1325 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001326 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1327 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001328 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001329 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001330 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001331 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001332 "read NVM failed, invalid offset 0x%x\n",
1333 offset);
1334 break;
1335 } else if (ret_val &&
1336 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1337 dev_info(&pf->pdev->dev,
1338 "read NVM failed, access, offset 0x%x\n",
1339 offset);
1340 break;
1341 } else if (ret_val) {
1342 dev_info(&pf->pdev->dev,
1343 "read NVM failed offset %d err=%d status=0x%x\n",
1344 offset, ret_val, hw->aq.asq_last_status);
1345 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001346 }
1347 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001348
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001349 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001350 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001351free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001352 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001353 return ret_val;
1354}
1355
1356static int i40e_get_eeprom_len(struct net_device *netdev)
1357{
1358 struct i40e_netdev_priv *np = netdev_priv(netdev);
1359 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001360 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001361
Lihong Yangc271dd62017-01-30 12:29:32 -08001362#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1363 if (hw->mac.type == I40E_MAC_X722) {
1364 val = X722_EEPROM_SCOPE_LIMIT + 1;
1365 return val;
1366 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001367 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1368 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1369 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1370 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001371 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001372 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001373}
1374
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001375static int i40e_set_eeprom(struct net_device *netdev,
1376 struct ethtool_eeprom *eeprom, u8 *bytes)
1377{
1378 struct i40e_netdev_priv *np = netdev_priv(netdev);
1379 struct i40e_hw *hw = &np->vsi->back->hw;
1380 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001381 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001382 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001383 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001384 u32 magic;
1385
1386 /* normal ethtool set_eeprom is not supported */
1387 magic = hw->vendor_id | (hw->device_id << 16);
1388 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001389 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001390 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001391 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1392 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001393 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1394 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001395 errno = -EBUSY;
1396 else
1397 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001398
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001399 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001400 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001401 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1402 ret_val, hw->aq.asq_last_status, errno,
1403 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1404 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001405
1406 return errno;
1407}
1408
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001409static void i40e_get_drvinfo(struct net_device *netdev,
1410 struct ethtool_drvinfo *drvinfo)
1411{
1412 struct i40e_netdev_priv *np = netdev_priv(netdev);
1413 struct i40e_vsi *vsi = np->vsi;
1414 struct i40e_pf *pf = vsi->back;
1415
1416 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1417 strlcpy(drvinfo->version, i40e_driver_version_str,
1418 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001419 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 sizeof(drvinfo->fw_version));
1421 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1422 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001423 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001424 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001425 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001426}
1427
1428static void i40e_get_ringparam(struct net_device *netdev,
1429 struct ethtool_ringparam *ring)
1430{
1431 struct i40e_netdev_priv *np = netdev_priv(netdev);
1432 struct i40e_pf *pf = np->vsi->back;
1433 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1434
1435 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1436 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1437 ring->rx_mini_max_pending = 0;
1438 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001439 ring->rx_pending = vsi->rx_rings[0]->count;
1440 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001441 ring->rx_mini_pending = 0;
1442 ring->rx_jumbo_pending = 0;
1443}
1444
Björn Töpel74608d12017-05-24 07:55:35 +02001445static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1446{
1447 if (i40e_enabled_xdp_vsi(vsi)) {
1448 return index < vsi->num_queue_pairs ||
1449 (index >= vsi->alloc_queue_pairs &&
1450 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1451 }
1452
1453 return index < vsi->num_queue_pairs;
1454}
1455
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456static int i40e_set_ringparam(struct net_device *netdev,
1457 struct ethtool_ringparam *ring)
1458{
1459 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1460 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001461 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001462 struct i40e_vsi *vsi = np->vsi;
1463 struct i40e_pf *pf = vsi->back;
1464 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001465 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001466 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001467 int i, err = 0;
1468
1469 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1470 return -EINVAL;
1471
Shannon Nelson1fa18372013-11-20 10:03:08 +00001472 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1473 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1474 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1475 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1476 netdev_info(netdev,
1477 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1478 ring->tx_pending, ring->rx_pending,
1479 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1480 return -EINVAL;
1481 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001482
Shannon Nelson1fa18372013-11-20 10:03:08 +00001483 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1484 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001485
1486 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001487 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1488 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001489 return 0;
1490
Jacob Keller0da36b92017-04-19 09:25:55 -04001491 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001492 timeout--;
1493 if (!timeout)
1494 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001495 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001496 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001497
1498 if (!netif_running(vsi->netdev)) {
1499 /* simple case - set for the next time the netdev is started */
1500 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001501 vsi->tx_rings[i]->count = new_tx_count;
1502 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001503 if (i40e_enabled_xdp_vsi(vsi))
1504 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001505 }
1506 goto done;
1507 }
1508
1509 /* We can't just free everything and then setup again,
1510 * because the ISRs in MSI-X mode get passed pointers
1511 * to the Tx and Rx ring structs.
1512 */
1513
Björn Töpel74608d12017-05-24 07:55:35 +02001514 /* alloc updated Tx and XDP Tx resources */
1515 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1516 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001517 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001518 netdev_info(netdev,
1519 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001520 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001521 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001522 sizeof(struct i40e_ring), GFP_KERNEL);
1523 if (!tx_rings) {
1524 err = -ENOMEM;
1525 goto done;
1526 }
1527
Björn Töpel74608d12017-05-24 07:55:35 +02001528 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1529 if (!i40e_active_tx_ring_index(vsi, i))
1530 continue;
1531
Alexander Duyck9f65e152013-09-28 06:00:58 +00001532 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001533 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001534 /* the desc and bi pointers will be reallocated in the
1535 * setup call
1536 */
1537 tx_rings[i].desc = NULL;
1538 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001539 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1540 if (err) {
1541 while (i) {
1542 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001543 if (!i40e_active_tx_ring_index(vsi, i))
1544 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001545 i40e_free_tx_resources(&tx_rings[i]);
1546 }
1547 kfree(tx_rings);
1548 tx_rings = NULL;
1549
1550 goto done;
1551 }
1552 }
1553 }
1554
1555 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001556 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557 netdev_info(netdev,
1558 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001559 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001560 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1561 sizeof(struct i40e_ring), GFP_KERNEL);
1562 if (!rx_rings) {
1563 err = -ENOMEM;
1564 goto free_tx;
1565 }
1566
1567 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001568 struct i40e_ring *ring;
1569 u16 unused;
1570
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001571 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001572 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001573 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001574 /* the desc and bi pointers will be reallocated in the
1575 * setup call
1576 */
1577 rx_rings[i].desc = NULL;
1578 rx_rings[i].rx_bi = NULL;
Jesper Dangaard Brouer87128822018-01-03 11:25:23 +01001579 /* Clear cloned XDP RX-queue info before setup call */
1580 memset(&rx_rings[i].xdp_rxq, 0, sizeof(rx_rings[i].xdp_rxq));
Tushar Dave2f7679e2016-10-26 10:49:27 -07001581 /* this is to allow wr32 to have something to write to
1582 * during early allocation of Rx buffers
1583 */
1584 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001585 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001586 if (err)
1587 goto rx_unwind;
1588
1589 /* now allocate the Rx buffers to make sure the OS
1590 * has enough memory, any failure here means abort
1591 */
1592 ring = &rx_rings[i];
1593 unused = I40E_DESC_UNUSED(ring);
1594 err = i40e_alloc_rx_buffers(ring, unused);
1595rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001596 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001597 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001598 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001599 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 kfree(rx_rings);
1601 rx_rings = NULL;
1602
1603 goto free_tx;
1604 }
1605 }
1606 }
1607
1608 /* Bring interface down, copy in the new ring info,
1609 * then restore the interface
1610 */
1611 i40e_down(vsi);
1612
1613 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001614 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1615 if (i40e_active_tx_ring_index(vsi, i)) {
1616 i40e_free_tx_resources(vsi->tx_rings[i]);
1617 *vsi->tx_rings[i] = tx_rings[i];
1618 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619 }
1620 kfree(tx_rings);
1621 tx_rings = NULL;
1622 }
1623
1624 if (rx_rings) {
1625 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001626 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001627 /* get the real tail offset */
1628 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1629 /* this is to fake out the allocation routine
1630 * into thinking it has to realloc everything
1631 * but the recycling logic will let us re-use
1632 * the buffers allocated above
1633 */
1634 rx_rings[i].next_to_use = 0;
1635 rx_rings[i].next_to_clean = 0;
1636 rx_rings[i].next_to_alloc = 0;
1637 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001638 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001639 }
1640 kfree(rx_rings);
1641 rx_rings = NULL;
1642 }
1643
1644 i40e_up(vsi);
1645
1646free_tx:
1647 /* error cleanup if the Rx allocations failed after getting Tx */
1648 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001649 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1650 if (i40e_active_tx_ring_index(vsi, i))
1651 i40e_free_tx_resources(vsi->tx_rings[i]);
1652 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001653 kfree(tx_rings);
1654 tx_rings = NULL;
1655 }
1656
1657done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001658 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001659
1660 return err;
1661}
1662
Jacob Kellerec29bbf2018-05-17 01:08:39 -07001663/**
1664 * i40e_get_stats_count - return the stats count for a device
1665 * @netdev: the netdev to return the count for
1666 *
1667 * Returns the total number of statistics for this netdev. Note that even
1668 * though this is a function, it is required that the count for a specific
1669 * netdev must never change. Basing the count on static values such as the
1670 * maximum number of queues or the device type is ok. However, the API for
1671 * obtaining stats is *not* safe against changes based on non-static
1672 * values such as the *current* number of queues, or runtime flags.
1673 *
1674 * If a statistic is not always enabled, return it as part of the count
1675 * anyways, always return its string, and report its value as zero.
1676 **/
Jacob Keller0ded9c62018-05-10 05:59:41 -07001677static int i40e_get_stats_count(struct net_device *netdev)
1678{
1679 struct i40e_netdev_priv *np = netdev_priv(netdev);
1680 struct i40e_vsi *vsi = np->vsi;
1681 struct i40e_pf *pf = vsi->back;
1682
Jacob Keller9955d492018-05-17 01:08:33 -07001683 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1)
1684 return I40E_PF_STATS_LEN(netdev) + I40E_VEB_STATS_TOTAL;
1685 else
Jacob Keller0ded9c62018-05-10 05:59:41 -07001686 return I40E_VSI_STATS_LEN(netdev);
Jacob Keller0ded9c62018-05-10 05:59:41 -07001687}
1688
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001689static int i40e_get_sset_count(struct net_device *netdev, int sset)
1690{
1691 struct i40e_netdev_priv *np = netdev_priv(netdev);
1692 struct i40e_vsi *vsi = np->vsi;
1693 struct i40e_pf *pf = vsi->back;
1694
1695 switch (sset) {
1696 case ETH_SS_TEST:
1697 return I40E_TEST_LEN;
1698 case ETH_SS_STATS:
Jacob Keller0ded9c62018-05-10 05:59:41 -07001699 return i40e_get_stats_count(netdev);
Greg Rose7e45ab42015-02-06 08:52:19 +00001700 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001701 return I40E_PRIV_FLAGS_STR_LEN +
1702 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001703 default:
1704 return -EOPNOTSUPP;
1705 }
1706}
1707
Jacob Kellerec29bbf2018-05-17 01:08:39 -07001708/**
1709 * i40e_get_ethtool_stats - copy stat values into supplied buffer
1710 * @netdev: the netdev to collect stats for
1711 * @stats: ethtool stats command structure
1712 * @data: ethtool supplied buffer
1713 *
1714 * Copy the stats values for this netdev into the buffer. Expects data to be
1715 * pre-allocated to the size returned by i40e_get_stats_count.. Note that all
1716 * statistics must be copied in a static order, and the count must not change
1717 * for a given netdev. See i40e_get_stats_count for more details.
1718 *
1719 * If a statistic is not currently valid (such as a disabled queue), this
1720 * function reports its value as zero.
1721 **/
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001722static void i40e_get_ethtool_stats(struct net_device *netdev,
1723 struct ethtool_stats *stats, u64 *data)
1724{
1725 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001726 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001727 struct i40e_vsi *vsi = np->vsi;
1728 struct i40e_pf *pf = vsi->back;
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001729 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001730 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001731 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001732 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001733
1734 i40e_update_stats(vsi);
1735
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001736 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1737 p = (char *)net_stats + i40e_gstrings_net_stats[i].stat_offset;
1738 *(data++) = (i40e_gstrings_net_stats[i].sizeof_stat ==
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001739 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1740 }
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001741 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1742 p = (char *)vsi + i40e_gstrings_misc_stats[i].stat_offset;
1743 *(data++) = (i40e_gstrings_misc_stats[i].sizeof_stat ==
Shannon Nelson41a9e552014-04-23 04:50:20 +00001744 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1745 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001746 rcu_read_lock();
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001747 for (i = 0; i < I40E_MAX_NUM_QUEUES(netdev) ; i++) {
1748 tx_ring = READ_ONCE(vsi->tx_rings[i]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001749
Jacob Kellerb8312362018-05-17 01:08:34 -07001750 if (!tx_ring) {
1751 /* Bump the stat counter to skip these stats, and make
1752 * sure the memory is zero'd
1753 */
Jacob Kellere08696d2018-05-17 01:08:38 -07001754 *(data++) = 0;
1755 *(data++) = 0;
1756 *(data++) = 0;
1757 *(data++) = 0;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001758 continue;
Jacob Kellerb8312362018-05-17 01:08:34 -07001759 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001760
1761 /* process Tx ring statistics */
1762 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001763 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Jacob Kellere08696d2018-05-17 01:08:38 -07001764 data[0] = tx_ring->stats.packets;
1765 data[1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001766 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Jacob Kellere08696d2018-05-17 01:08:38 -07001767 data += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001768
1769 /* Rx ring is the 2nd half of the queue pair */
1770 rx_ring = &tx_ring[1];
1771 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001772 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Jacob Kellere08696d2018-05-17 01:08:38 -07001773 data[0] = rx_ring->stats.packets;
1774 data[1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001775 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Jacob Kellere08696d2018-05-17 01:08:38 -07001776 data += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001777 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001778 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001779 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001780 return;
1781
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001782 if ((pf->lan_veb != I40E_NO_VEB) &&
1783 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001784 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001785
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001786 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001787 p = (char *)veb;
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001788 p += i40e_gstrings_veb_stats[i].stat_offset;
1789 *(data++) = (i40e_gstrings_veb_stats[i].sizeof_stat ==
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001790 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001791 }
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001792 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1793 *(data++) = veb->tc_stats.tc_tx_packets[i];
1794 *(data++) = veb->tc_stats.tc_tx_bytes[i];
1795 *(data++) = veb->tc_stats.tc_rx_packets[i];
1796 *(data++) = veb->tc_stats.tc_rx_bytes[i];
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001797 }
Jacob Keller9955d492018-05-17 01:08:33 -07001798 } else {
Jacob Kellere08696d2018-05-17 01:08:38 -07001799 data += I40E_VEB_STATS_TOTAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001800 }
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001801 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1802 p = (char *)pf + i40e_gstrings_stats[i].stat_offset;
1803 *(data++) = (i40e_gstrings_stats[i].sizeof_stat ==
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001804 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1805 }
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001806 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1807 *(data++) = pf->stats.priority_xon_tx[i];
1808 *(data++) = pf->stats.priority_xoff_tx[i];
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001809 }
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001810 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1811 *(data++) = pf->stats.priority_xon_rx[i];
1812 *(data++) = pf->stats.priority_xoff_rx[i];
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001813 }
Jacob Keller3f76bdb2018-05-17 01:08:40 -07001814 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
1815 *(data++) = pf->stats.priority_xon_2_xoff[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001816}
1817
Jacob Kellerec29bbf2018-05-17 01:08:39 -07001818/**
1819 * i40e_get_stat_strings - copy stat strings into supplied buffer
1820 * @netdev: the netdev to collect strings for
1821 * @data: supplied buffer to copy strings into
1822 *
1823 * Copy the strings related to stats for this netdev. Expects data to be
1824 * pre-allocated with the size reported by i40e_get_stats_count. Note that the
1825 * strings must be copied in a static order and the total count must not
1826 * change for a given netdev. See i40e_get_stats_count for more details.
1827 **/
Jacob Keller019b9cd2018-05-17 01:08:35 -07001828static void i40e_get_stat_strings(struct net_device *netdev, u8 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001829{
1830 struct i40e_netdev_priv *np = netdev_priv(netdev);
1831 struct i40e_vsi *vsi = np->vsi;
1832 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001833 unsigned int i;
Jacob Keller9b10df52018-05-17 01:08:36 -07001834 u8 *p = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001835
Jacob Keller019b9cd2018-05-17 01:08:35 -07001836 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001837 snprintf(data, ETH_GSTRING_LEN, "%s",
Jacob Keller019b9cd2018-05-17 01:08:35 -07001838 i40e_gstrings_net_stats[i].stat_string);
Jacob Kellere08696d2018-05-17 01:08:38 -07001839 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001840 }
1841 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001842 snprintf(data, ETH_GSTRING_LEN, "%s",
Jacob Keller019b9cd2018-05-17 01:08:35 -07001843 i40e_gstrings_misc_stats[i].stat_string);
Jacob Kellere08696d2018-05-17 01:08:38 -07001844 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001845 }
1846 for (i = 0; i < I40E_MAX_NUM_QUEUES(netdev); i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001847 snprintf(data, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1848 data += ETH_GSTRING_LEN;
1849 snprintf(data, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1850 data += ETH_GSTRING_LEN;
1851 snprintf(data, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1852 data += ETH_GSTRING_LEN;
1853 snprintf(data, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1854 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001855 }
1856 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
1857 return;
1858
1859 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001860 snprintf(data, ETH_GSTRING_LEN, "%s",
Jacob Keller019b9cd2018-05-17 01:08:35 -07001861 i40e_gstrings_veb_stats[i].stat_string);
Jacob Kellere08696d2018-05-17 01:08:38 -07001862 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001863 }
1864 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001865 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001866 "veb.tc_%u_tx_packets", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001867 data += ETH_GSTRING_LEN;
1868 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001869 "veb.tc_%u_tx_bytes", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001870 data += ETH_GSTRING_LEN;
1871 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001872 "veb.tc_%u_rx_packets", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001873 data += ETH_GSTRING_LEN;
1874 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001875 "veb.tc_%u_rx_bytes", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001876 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001877 }
1878
1879 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001880 snprintf(data, ETH_GSTRING_LEN, "%s",
Jacob Keller019b9cd2018-05-17 01:08:35 -07001881 i40e_gstrings_stats[i].stat_string);
Jacob Kellere08696d2018-05-17 01:08:38 -07001882 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001883 }
1884 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001885 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001886 "port.tx_priority_%u_xon", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001887 data += ETH_GSTRING_LEN;
1888 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001889 "port.tx_priority_%u_xoff", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001890 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001891 }
1892 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001893 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001894 "port.rx_priority_%u_xon", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001895 data += ETH_GSTRING_LEN;
1896 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001897 "port.rx_priority_%u_xoff", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001898 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001899 }
1900 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
Jacob Kellere08696d2018-05-17 01:08:38 -07001901 snprintf(data, ETH_GSTRING_LEN,
Jacob Keller019b9cd2018-05-17 01:08:35 -07001902 "port.rx_priority_%u_xon_2_xoff", i);
Jacob Kellere08696d2018-05-17 01:08:38 -07001903 data += ETH_GSTRING_LEN;
Jacob Keller019b9cd2018-05-17 01:08:35 -07001904 }
Jacob Keller9b10df52018-05-17 01:08:36 -07001905
1906 WARN_ONCE(p - data != i40e_get_stats_count(netdev) * ETH_GSTRING_LEN,
1907 "stat strings count mismatch!");
Jacob Keller019b9cd2018-05-17 01:08:35 -07001908}
1909
1910static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
1911{
1912 struct i40e_netdev_priv *np = netdev_priv(netdev);
1913 struct i40e_vsi *vsi = np->vsi;
1914 struct i40e_pf *pf = vsi->back;
1915 char *p = (char *)data;
1916 unsigned int i;
1917
1918 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1919 snprintf(p, ETH_GSTRING_LEN, "%s",
1920 i40e_gstrings_priv_flags[i].flag_string);
1921 p += ETH_GSTRING_LEN;
1922 }
1923 if (pf->hw.pf_id != 0)
1924 return;
1925 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1926 snprintf(p, ETH_GSTRING_LEN, "%s",
1927 i40e_gl_gstrings_priv_flags[i].flag_string);
1928 p += ETH_GSTRING_LEN;
1929 }
1930}
1931
1932static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1933 u8 *data)
1934{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001935 switch (stringset) {
1936 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001937 memcpy(data, i40e_gstrings_test,
1938 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001939 break;
1940 case ETH_SS_STATS:
Jacob Keller019b9cd2018-05-17 01:08:35 -07001941 i40e_get_stat_strings(netdev, data);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001942 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001943 case ETH_SS_PRIV_FLAGS:
Jacob Keller019b9cd2018-05-17 01:08:35 -07001944 i40e_get_priv_flag_strings(netdev, data);
Greg Rose7e45ab42015-02-06 08:52:19 +00001945 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001946 default:
1947 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001948 }
1949}
1950
1951static int i40e_get_ts_info(struct net_device *dev,
1952 struct ethtool_ts_info *info)
1953{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001954 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1955
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001956 /* only report HW timestamping if PTP is enabled */
1957 if (!(pf->flags & I40E_FLAG_PTP))
1958 return ethtool_op_get_ts_info(dev, info);
1959
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001960 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1961 SOF_TIMESTAMPING_RX_SOFTWARE |
1962 SOF_TIMESTAMPING_SOFTWARE |
1963 SOF_TIMESTAMPING_TX_HARDWARE |
1964 SOF_TIMESTAMPING_RX_HARDWARE |
1965 SOF_TIMESTAMPING_RAW_HARDWARE;
1966
1967 if (pf->ptp_clock)
1968 info->phc_index = ptp_clock_index(pf->ptp_clock);
1969 else
1970 info->phc_index = -1;
1971
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001972 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001973
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001974 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001975 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1976 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1977 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1978
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001979 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001980 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1981 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1982 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1983 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1984 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1985 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1986 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1987 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001988
1989 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001990}
1991
Shannon Nelson7b086392013-11-20 10:02:59 +00001992static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001993{
Shannon Nelson7b086392013-11-20 10:02:59 +00001994 struct i40e_netdev_priv *np = netdev_priv(netdev);
1995 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001996 i40e_status status;
1997 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001998
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001999 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04002000 status = i40e_get_link_status(&pf->hw, &link_up);
2001 if (status) {
2002 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
2003 *data = 1;
2004 return *data;
2005 }
2006
2007 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002008 *data = 0;
2009 else
2010 *data = 1;
2011
2012 return *data;
2013}
2014
Shannon Nelson7b086392013-11-20 10:02:59 +00002015static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002016{
Shannon Nelson7b086392013-11-20 10:02:59 +00002017 struct i40e_netdev_priv *np = netdev_priv(netdev);
2018 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002019
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002020 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00002021 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002022
Shannon Nelson7b086392013-11-20 10:02:59 +00002023 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002024}
2025
Shannon Nelson7b086392013-11-20 10:02:59 +00002026static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002027{
Shannon Nelson7b086392013-11-20 10:02:59 +00002028 struct i40e_netdev_priv *np = netdev_priv(netdev);
2029 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002030
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002031 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00002032 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002033
Shannon Nelson4443ec92014-11-13 08:23:12 +00002034 /* forcebly clear the NVM Update state machine */
2035 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
2036
Shannon Nelson7b086392013-11-20 10:02:59 +00002037 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002038}
2039
Shannon Nelson7b086392013-11-20 10:02:59 +00002040static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002041{
Shannon Nelson7b086392013-11-20 10:02:59 +00002042 struct i40e_netdev_priv *np = netdev_priv(netdev);
2043 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00002044 u16 swc_old = pf->sw_int_count;
2045
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002046 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00002047 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
2048 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00002049 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
2050 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
2051 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
2052 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00002053 usleep_range(1000, 2000);
2054 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002055
2056 return *data;
2057}
2058
Greg Rosee17bc412015-04-16 20:05:59 -04002059static inline bool i40e_active_vfs(struct i40e_pf *pf)
2060{
2061 struct i40e_vf *vfs = pf->vf;
2062 int i;
2063
2064 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04002065 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04002066 return true;
2067 return false;
2068}
2069
Greg Rose510efb22015-07-10 19:36:01 -04002070static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
2071{
Alexander Duyck4b816442016-10-11 15:26:53 -07002072 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04002073}
2074
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002075static void i40e_diag_test(struct net_device *netdev,
2076 struct ethtool_test *eth_test, u64 *data)
2077{
2078 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002079 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002080 struct i40e_pf *pf = np->vsi->back;
2081
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002082 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
2083 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002084 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002085
Jacob Keller0da36b92017-04-19 09:25:55 -04002086 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002087
Greg Rose510efb22015-07-10 19:36:01 -04002088 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04002089 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04002090 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04002091 data[I40E_ETH_TEST_REG] = 1;
2092 data[I40E_ETH_TEST_EEPROM] = 1;
2093 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04002094 data[I40E_ETH_TEST_LINK] = 1;
2095 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04002096 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04002097 goto skip_ol_tests;
2098 }
2099
Greg Rose5b86c5c2015-02-26 16:14:35 +00002100 /* If the device is online then take it offline */
2101 if (if_running)
2102 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01002103 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002104 else
Greg Roseb4e53f02015-07-10 19:36:03 -04002105 /* This reset does not affect link - if it is
2106 * changed to a type of reset that does affect
2107 * link then the following link test would have
2108 * to be moved to before the reset
2109 */
Maciej Sosin373149f2017-04-05 07:50:55 -04002110 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00002111
Shannon Nelson7b086392013-11-20 10:02:59 +00002112 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002113 eth_test->flags |= ETH_TEST_FL_FAILED;
2114
Shannon Nelson7b086392013-11-20 10:02:59 +00002115 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002116 eth_test->flags |= ETH_TEST_FL_FAILED;
2117
Shannon Nelson7b086392013-11-20 10:02:59 +00002118 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002119 eth_test->flags |= ETH_TEST_FL_FAILED;
2120
Shannon Nelsonf551b432013-11-26 10:49:12 +00002121 /* run reg test last, a reset is required after it */
2122 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
2123 eth_test->flags |= ETH_TEST_FL_FAILED;
2124
Jacob Keller0da36b92017-04-19 09:25:55 -04002125 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04002126 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00002127
2128 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01002129 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002130 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002131 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002132 netif_info(pf, drv, netdev, "online testing starting\n");
2133
Shannon Nelson7b086392013-11-20 10:02:59 +00002134 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002135 eth_test->flags |= ETH_TEST_FL_FAILED;
2136
2137 /* Offline only tests, not run in online; pass by default */
2138 data[I40E_ETH_TEST_REG] = 0;
2139 data[I40E_ETH_TEST_EEPROM] = 0;
2140 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002141 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00002142
Greg Rosee17bc412015-04-16 20:05:59 -04002143skip_ol_tests:
2144
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00002145 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002146}
2147
2148static void i40e_get_wol(struct net_device *netdev,
2149 struct ethtool_wolinfo *wol)
2150{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002151 struct i40e_netdev_priv *np = netdev_priv(netdev);
2152 struct i40e_pf *pf = np->vsi->back;
2153 struct i40e_hw *hw = &pf->hw;
2154 u16 wol_nvm_bits;
2155
2156 /* NVM bit on means WoL disabled for the port */
2157 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002158 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002159 wol->supported = 0;
2160 wol->wolopts = 0;
2161 } else {
2162 wol->supported = WAKE_MAGIC;
2163 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
2164 }
2165}
2166
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002167/**
2168 * i40e_set_wol - set the WakeOnLAN configuration
2169 * @netdev: the netdev in question
2170 * @wol: the ethtool WoL setting data
2171 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002172static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2173{
2174 struct i40e_netdev_priv *np = netdev_priv(netdev);
2175 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002176 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002177 struct i40e_hw *hw = &pf->hw;
2178 u16 wol_nvm_bits;
2179
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00002180 /* WoL not supported if this isn't the controlling PF on the port */
2181 if (hw->partition_id != 1) {
2182 i40e_partition_setting_complaint(pf);
2183 return -EOPNOTSUPP;
2184 }
2185
2186 if (vsi != pf->vsi[pf->lan_vsi])
2187 return -EOPNOTSUPP;
2188
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002189 /* NVM bit on means WoL disabled for the port */
2190 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002191 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002192 return -EOPNOTSUPP;
2193
2194 /* only magic packet is supported */
2195 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
2196 return -EOPNOTSUPP;
2197
2198 /* is this a new value? */
2199 if (pf->wol_en != !!wol->wolopts) {
2200 pf->wol_en = !!wol->wolopts;
2201 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
2202 }
2203
2204 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002205}
2206
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002207static int i40e_set_phys_id(struct net_device *netdev,
2208 enum ethtool_phys_id_state state)
2209{
2210 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002211 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002212 struct i40e_pf *pf = np->vsi->back;
2213 struct i40e_hw *hw = &pf->hw;
2214 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002215 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002216
2217 switch (state) {
2218 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002219 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002220 pf->led_status = i40e_led_get(hw);
2221 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002222 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2223 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2224 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002225 ret = i40e_led_get_phy(hw, &temp_status,
2226 &pf->phy_led_val);
2227 pf->led_status = temp_status;
2228 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229 return blink_freq;
2230 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002231 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002232 i40e_led_set(hw, 0xf, false);
2233 else
2234 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002235 break;
2236 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002237 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002238 i40e_led_set(hw, 0x0, false);
2239 else
2240 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002241 break;
2242 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002243 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002244 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002245 } else {
2246 ret = i40e_led_set_phy(hw, false, pf->led_status,
2247 (pf->phy_led_val |
2248 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002249 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2250 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002251 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002252 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002253 default:
2254 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002255 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002256 if (ret)
2257 return -ENOENT;
2258 else
2259 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002260}
2261
2262/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2263 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2264 * 125us (8000 interrupts per second) == ITR(62)
2265 */
2266
Jacob Keller65e87c02016-09-12 14:18:44 -07002267/**
2268 * __i40e_get_coalesce - get per-queue coalesce settings
2269 * @netdev: the netdev to check
2270 * @ec: ethtool coalesce data structure
2271 * @queue: which queue to pick
2272 *
2273 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2274 * are per queue. If queue is <0 then we default to queue 0 as the
2275 * representative value.
2276 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002277static int __i40e_get_coalesce(struct net_device *netdev,
2278 struct ethtool_coalesce *ec,
2279 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002280{
2281 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002282 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002283 struct i40e_vsi *vsi = np->vsi;
2284
2285 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2286 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2287
Alan Bradya03af692017-10-05 14:53:37 -07002288 /* rx and tx usecs has per queue value. If user doesn't specify the
2289 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002290 */
Alan Bradya03af692017-10-05 14:53:37 -07002291 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002292 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002293 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002294 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002295
Jacob Keller65e87c02016-09-12 14:18:44 -07002296 rx_ring = vsi->rx_rings[queue];
2297 tx_ring = vsi->tx_rings[queue];
2298
Alexander Duyck40588ca2017-12-29 08:49:28 -05002299 if (ITR_IS_DYNAMIC(rx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002300 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002301
Alexander Duyck40588ca2017-12-29 08:49:28 -05002302 if (ITR_IS_DYNAMIC(tx_ring->itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002303 ec->use_adaptive_tx_coalesce = 1;
2304
Alexander Duyck40588ca2017-12-29 08:49:28 -05002305 ec->rx_coalesce_usecs = rx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
2306 ec->tx_coalesce_usecs = tx_ring->itr_setting & ~I40E_ITR_DYNAMIC;
Jacob Keller65e87c02016-09-12 14:18:44 -07002307
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002308 /* we use the _usecs_high to store/set the interrupt rate limit
2309 * that the hardware supports, that almost but not quite
2310 * fits the original intent of the ethtool variable,
2311 * the rx_coalesce_usecs_high limits total interrupts
2312 * per second from both tx/rx sources.
2313 */
2314 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2315 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002316
2317 return 0;
2318}
2319
Jacob Keller65e87c02016-09-12 14:18:44 -07002320/**
2321 * i40e_get_coalesce - get a netdev's coalesce settings
2322 * @netdev: the netdev to check
2323 * @ec: ethtool coalesce data structure
2324 *
2325 * Gets the coalesce settings for a particular netdev. Note that if user has
2326 * modified per-queue settings, this only guarantees to represent queue 0. See
2327 * __i40e_get_coalesce for more details.
2328 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002329static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002330 struct ethtool_coalesce *ec)
2331{
Kan Lianga75e8002016-02-19 09:24:04 -05002332 return __i40e_get_coalesce(netdev, ec, -1);
2333}
2334
Jacob Keller65e87c02016-09-12 14:18:44 -07002335/**
2336 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2337 * @netdev: netdev structure
2338 * @ec: ethtool's coalesce settings
2339 * @queue: the particular queue to read
2340 *
2341 * Will read a specific queue's coalesce settings
2342 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002343static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2344 struct ethtool_coalesce *ec)
2345{
2346 return __i40e_get_coalesce(netdev, ec, queue);
2347}
2348
Jacob Keller65e87c02016-09-12 14:18:44 -07002349/**
2350 * i40e_set_itr_per_queue - set ITR values for specific queue
2351 * @vsi: the VSI to set values for
2352 * @ec: coalesce settings from ethtool
2353 * @queue: the queue to modify
2354 *
2355 * Change the ITR settings for a specific queue.
2356 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002357static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2358 struct ethtool_coalesce *ec,
2359 int queue)
2360{
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002361 struct i40e_ring *rx_ring = vsi->rx_rings[queue];
2362 struct i40e_ring *tx_ring = vsi->tx_rings[queue];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002363 struct i40e_pf *pf = vsi->back;
2364 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002365 struct i40e_q_vector *q_vector;
Alexander Duyck8b99b112017-12-29 08:50:44 -05002366 u16 intrl;
Kan Lianga75e8002016-02-19 09:24:04 -05002367
Alan Brady1c0e6a32016-11-28 16:06:02 -08002368 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002369
Alexander Duyck92418fb2017-12-29 08:51:08 -05002370 rx_ring->itr_setting = ITR_REG_ALIGN(ec->rx_coalesce_usecs);
2371 tx_ring->itr_setting = ITR_REG_ALIGN(ec->tx_coalesce_usecs);
Kan Lianga75e8002016-02-19 09:24:04 -05002372
2373 if (ec->use_adaptive_rx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002374 rx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002375 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002376 rx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002377
2378 if (ec->use_adaptive_tx_coalesce)
Alexander Duyck40588ca2017-12-29 08:49:28 -05002379 tx_ring->itr_setting |= I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002380 else
Alexander Duyck40588ca2017-12-29 08:49:28 -05002381 tx_ring->itr_setting &= ~I40E_ITR_DYNAMIC;
Kan Lianga75e8002016-02-19 09:24:04 -05002382
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002383 q_vector = rx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002384 q_vector->rx.target_itr = ITR_TO_REG(rx_ring->itr_setting);
Kan Lianga75e8002016-02-19 09:24:04 -05002385
Alexander Duyckb5b5f372017-12-27 08:15:51 -05002386 q_vector = tx_ring->q_vector;
Alexander Duyck556fdfd2017-12-29 08:51:25 -05002387 q_vector->tx.target_itr = ITR_TO_REG(tx_ring->itr_setting);
2388
2389 /* The interrupt handler itself will take care of programming
2390 * the Tx and Rx ITR values based on the values we have entered
2391 * into the q_vector, no need to write the values now.
2392 */
Kan Lianga75e8002016-02-19 09:24:04 -05002393
Alexander Duyck8b99b112017-12-29 08:50:44 -05002394 wr32(hw, I40E_PFINT_RATEN(q_vector->reg_idx), intrl);
Kan Lianga75e8002016-02-19 09:24:04 -05002395 i40e_flush(hw);
2396}
2397
Jacob Keller65e87c02016-09-12 14:18:44 -07002398/**
2399 * __i40e_set_coalesce - set coalesce settings for particular queue
2400 * @netdev: the netdev to change
2401 * @ec: ethtool coalesce settings
2402 * @queue: the queue to change
2403 *
2404 * Sets the coalesce settings for a particular queue.
2405 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002406static int __i40e_set_coalesce(struct net_device *netdev,
2407 struct ethtool_coalesce *ec,
2408 int queue)
2409{
2410 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002411 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002412 struct i40e_vsi *vsi = np->vsi;
2413 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002414 int i;
2415
2416 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2417 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2418
Alan Brady06b2dec2017-07-12 05:46:06 -04002419 if (queue < 0) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002420 cur_rx_itr = vsi->rx_rings[0]->itr_setting;
2421 cur_tx_itr = vsi->tx_rings[0]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002422 } else if (queue < vsi->num_queue_pairs) {
Alexander Duyck40588ca2017-12-29 08:49:28 -05002423 cur_rx_itr = vsi->rx_rings[queue]->itr_setting;
2424 cur_tx_itr = vsi->tx_rings[queue]->itr_setting;
Alan Brady06b2dec2017-07-12 05:46:06 -04002425 } else {
2426 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2427 vsi->num_queue_pairs - 1);
2428 return -EINVAL;
2429 }
2430
2431 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2432 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2433
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002434 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2435 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2436 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2437 return -EINVAL;
2438 }
2439
Alan Brady33084062016-11-28 16:06:03 -08002440 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2441 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2442 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002443 return -EINVAL;
2444 }
2445
Alan Brady06b2dec2017-07-12 05:46:06 -04002446 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2447 ec->use_adaptive_rx_coalesce) {
2448 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2449 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002450 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002451
Alexander Duyck92418fb2017-12-29 08:51:08 -05002452 if (ec->rx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002453 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2454 return -EINVAL;
2455 }
2456
2457 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2458 ec->use_adaptive_tx_coalesce) {
2459 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2460 return -EINVAL;
2461 }
2462
Alexander Duyck92418fb2017-12-29 08:51:08 -05002463 if (ec->tx_coalesce_usecs > I40E_MAX_ITR) {
Alan Brady06b2dec2017-07-12 05:46:06 -04002464 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2465 return -EINVAL;
2466 }
2467
2468 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002469 ec->rx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002470
2471 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
Alexander Duyck92418fb2017-12-29 08:51:08 -05002472 ec->tx_coalesce_usecs = I40E_MIN_ITR;
Alan Brady06b2dec2017-07-12 05:46:06 -04002473
Alan Brady33084062016-11-28 16:06:03 -08002474 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2475 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2476 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2477 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2478 vsi->int_rate_limit);
2479 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002480
Alan Bradya03af692017-10-05 14:53:37 -07002481 /* rx and tx usecs has per queue value. If user doesn't specify the
2482 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002483 */
2484 if (queue < 0) {
2485 for (i = 0; i < vsi->num_queue_pairs; i++)
2486 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002487 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002488 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002489 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002490
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002491 return 0;
2492}
2493
Jacob Keller65e87c02016-09-12 14:18:44 -07002494/**
2495 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2496 * @netdev: the netdev to change
2497 * @ec: ethtool coalesce settings
2498 *
2499 * This will set each queue to the same coalesce settings.
2500 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002501static int i40e_set_coalesce(struct net_device *netdev,
2502 struct ethtool_coalesce *ec)
2503{
2504 return __i40e_set_coalesce(netdev, ec, -1);
2505}
2506
Jacob Keller65e87c02016-09-12 14:18:44 -07002507/**
2508 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2509 * @netdev: the netdev to change
2510 * @ec: ethtool's coalesce settings
2511 * @queue: the queue to change
2512 *
2513 * Sets the specified queue's coalesce settings.
2514 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002515static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2516 struct ethtool_coalesce *ec)
2517{
2518 return __i40e_set_coalesce(netdev, ec, queue);
2519}
2520
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002521/**
2522 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2523 * @pf: pointer to the physical function struct
2524 * @cmd: ethtool rxnfc command
2525 *
2526 * Returns Success if the flow is supported, else Invalid Input.
2527 **/
2528static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2529{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002530 struct i40e_hw *hw = &pf->hw;
2531 u8 flow_pctype = 0;
2532 u64 i_set = 0;
2533
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002534 cmd->data = 0;
2535
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002536 switch (cmd->flow_type) {
2537 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002538 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2539 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002540 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002541 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2542 break;
2543 case TCP_V6_FLOW:
2544 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2545 break;
2546 case UDP_V6_FLOW:
2547 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2548 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002549 case SCTP_V4_FLOW:
2550 case AH_ESP_V4_FLOW:
2551 case AH_V4_FLOW:
2552 case ESP_V4_FLOW:
2553 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002554 case SCTP_V6_FLOW:
2555 case AH_ESP_V6_FLOW:
2556 case AH_V6_FLOW:
2557 case ESP_V6_FLOW:
2558 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002559 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002560 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2561 break;
2562 default:
2563 return -EINVAL;
2564 }
2565
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002566 /* Read flow based hash input set register */
2567 if (flow_pctype) {
2568 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2569 flow_pctype)) |
2570 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2571 flow_pctype)) << 32);
2572 }
2573
2574 /* Process bits of hash input set */
2575 if (i_set) {
2576 if (i_set & I40E_L4_SRC_MASK)
2577 cmd->data |= RXH_L4_B_0_1;
2578 if (i_set & I40E_L4_DST_MASK)
2579 cmd->data |= RXH_L4_B_2_3;
2580
2581 if (cmd->flow_type == TCP_V4_FLOW ||
2582 cmd->flow_type == UDP_V4_FLOW) {
2583 if (i_set & I40E_L3_SRC_MASK)
2584 cmd->data |= RXH_IP_SRC;
2585 if (i_set & I40E_L3_DST_MASK)
2586 cmd->data |= RXH_IP_DST;
2587 } else if (cmd->flow_type == TCP_V6_FLOW ||
2588 cmd->flow_type == UDP_V6_FLOW) {
2589 if (i_set & I40E_L3_V6_SRC_MASK)
2590 cmd->data |= RXH_IP_SRC;
2591 if (i_set & I40E_L3_V6_DST_MASK)
2592 cmd->data |= RXH_IP_DST;
2593 }
2594 }
2595
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002596 return 0;
2597}
2598
2599/**
Jacob Kellere7930952017-02-06 14:38:49 -08002600 * i40e_check_mask - Check whether a mask field is set
2601 * @mask: the full mask value
Jacob Kellerf5254422018-04-20 01:41:33 -07002602 * @field: mask of the field to check
Jacob Kellere7930952017-02-06 14:38:49 -08002603 *
2604 * If the given mask is fully set, return positive value. If the mask for the
2605 * field is fully unset, return zero. Otherwise return a negative error code.
2606 **/
2607static int i40e_check_mask(u64 mask, u64 field)
2608{
2609 u64 value = mask & field;
2610
2611 if (value == field)
2612 return 1;
2613 else if (!value)
2614 return 0;
2615 else
2616 return -1;
2617}
2618
2619/**
2620 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2621 * @fsp: pointer to rx flow specification
2622 * @data: pointer to userdef data structure for storage
2623 *
2624 * Read the user-defined data and deconstruct the value into a structure. No
2625 * other code should read the user-defined data, so as to ensure that every
2626 * place consistently reads the value correctly.
2627 *
2628 * The user-defined field is a 64bit Big Endian format value, which we
2629 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2630 * be defined starting from the highest bits, while small bit field values
2631 * shall be defined starting from the lowest bits.
2632 *
2633 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2634 * and the filter should be rejected. The data structure will always be
2635 * modified even if FLOW_EXT is not set.
2636 *
2637 **/
2638static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2639 struct i40e_rx_flow_userdef *data)
2640{
2641 u64 value, mask;
2642 int valid;
2643
2644 /* Zero memory first so it's always consistent. */
2645 memset(data, 0, sizeof(*data));
2646
2647 if (!(fsp->flow_type & FLOW_EXT))
2648 return 0;
2649
2650 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2651 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2652
2653#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2654#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2655#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2656
2657 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2658 if (valid < 0) {
2659 return -EINVAL;
2660 } else if (valid) {
2661 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2662 data->flex_offset =
2663 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2664 data->flex_filter = true;
2665 }
2666
2667 return 0;
2668}
2669
2670/**
2671 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2672 * @fsp: pointer to rx_flow specification
Jacob Kellerf5254422018-04-20 01:41:33 -07002673 * @data: pointer to return userdef data
Jacob Kellere7930952017-02-06 14:38:49 -08002674 *
2675 * Reads the userdef data structure and properly fills in the user defined
2676 * fields of the rx_flow_spec.
2677 **/
2678static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2679 struct i40e_rx_flow_userdef *data)
2680{
2681 u64 value = 0, mask = 0;
2682
2683 if (data->flex_filter) {
2684 value |= data->flex_word;
2685 value |= (u64)data->flex_offset << 16;
2686 mask |= I40E_USERDEF_FLEX_FILTER;
2687 }
2688
2689 if (value || mask)
2690 fsp->flow_type |= FLOW_EXT;
2691
2692 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2693 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2694}
2695
2696/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002697 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2698 * @pf: Pointer to the physical function struct
2699 * @cmd: The command to get or set Rx flow classification rules
2700 * @rule_locs: Array of used rule locations
2701 *
2702 * This function populates both the total and actual rule count of
2703 * the ethtool flow classification command
2704 *
2705 * Returns 0 on success or -EMSGSIZE if entry not found
2706 **/
2707static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2708 struct ethtool_rxnfc *cmd,
2709 u32 *rule_locs)
2710{
2711 struct i40e_fdir_filter *rule;
2712 struct hlist_node *node2;
2713 int cnt = 0;
2714
2715 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002716 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002717
2718 hlist_for_each_entry_safe(rule, node2,
2719 &pf->fdir_filter_list, fdir_node) {
2720 if (cnt == cmd->rule_cnt)
2721 return -EMSGSIZE;
2722
2723 rule_locs[cnt] = rule->fd_id;
2724 cnt++;
2725 }
2726
2727 cmd->rule_cnt = cnt;
2728
2729 return 0;
2730}
2731
2732/**
2733 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2734 * @pf: Pointer to the physical function struct
2735 * @cmd: The command to get or set Rx flow classification rules
2736 *
2737 * This function looks up a filter based on the Rx flow classification
2738 * command and fills the flow spec info for it if found
2739 *
2740 * Returns 0 on success or -EINVAL if filter not found
2741 **/
2742static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2743 struct ethtool_rxnfc *cmd)
2744{
2745 struct ethtool_rx_flow_spec *fsp =
2746 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002747 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002748 struct i40e_fdir_filter *rule = NULL;
2749 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002750 u64 input_set;
2751 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002752
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002753 hlist_for_each_entry_safe(rule, node2,
2754 &pf->fdir_filter_list, fdir_node) {
2755 if (fsp->location <= rule->fd_id)
2756 break;
2757 }
2758
2759 if (!rule || fsp->location != rule->fd_id)
2760 return -EINVAL;
2761
2762 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002763 if (fsp->flow_type == IP_USER_FLOW) {
2764 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2765 fsp->h_u.usr_ip4_spec.proto = 0;
2766 fsp->m_u.usr_ip4_spec.proto = 0;
2767 }
2768
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002769 /* Reverse the src and dest notion, since the HW views them from
2770 * Tx perspective where as the user expects it from Rx filter view.
2771 */
2772 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2773 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002774 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2775 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002776
Jacob Keller36777d92017-03-07 15:05:23 -08002777 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002778 case SCTP_V4_FLOW:
2779 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2780 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002781 case TCP_V4_FLOW:
2782 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2783 break;
2784 case UDP_V4_FLOW:
2785 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2786 break;
2787 case IP_USER_FLOW:
2788 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2789 break;
2790 default:
2791 /* If we have stored a filter with a flow type not listed here
2792 * it is almost certainly a driver bug. WARN(), and then
2793 * assign the input_set as if all fields are enabled to avoid
2794 * reading unassigned memory.
2795 */
2796 WARN(1, "Missing input set index for flow_type %d\n",
2797 rule->flow_type);
2798 input_set = 0xFFFFFFFFFFFFFFFFULL;
2799 goto no_input_set;
2800 }
2801
2802 input_set = i40e_read_fd_input_set(pf, index);
2803
2804no_input_set:
2805 if (input_set & I40E_L3_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002806 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002807
2808 if (input_set & I40E_L3_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002809 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFFFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002810
2811 if (input_set & I40E_L4_SRC_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002812 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFF);
Jacob Keller36777d92017-03-07 15:05:23 -08002813
2814 if (input_set & I40E_L4_DST_MASK)
Jacob Keller40339af2017-12-27 08:26:33 -05002815 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002816
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002817 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2818 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2819 else
2820 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002821
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002822 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2823 struct i40e_vsi *vsi;
2824
2825 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2826 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002827 /* VFs are zero-indexed by the driver, but ethtool
2828 * expects them to be one-indexed, so add one here
2829 */
2830 u64 ring_vf = vsi->vf_id + 1;
2831
2832 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2833 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002834 }
2835 }
2836
Jacob Keller0e588de2017-02-06 14:38:50 -08002837 if (rule->flex_filter) {
2838 userdef.flex_filter = true;
2839 userdef.flex_word = be16_to_cpu(rule->flex_word);
2840 userdef.flex_offset = rule->flex_offset;
2841 }
2842
Jacob Kellere7930952017-02-06 14:38:49 -08002843 i40e_fill_rx_flow_user_data(fsp, &userdef);
2844
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002845 return 0;
2846}
2847
2848/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002849 * i40e_get_rxnfc - command to get RX flow classification rules
2850 * @netdev: network interface device structure
2851 * @cmd: ethtool rxnfc command
Jacob Kellerf5254422018-04-20 01:41:33 -07002852 * @rule_locs: pointer to store rule data
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002853 *
2854 * Returns Success if the command is supported.
2855 **/
2856static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2857 u32 *rule_locs)
2858{
2859 struct i40e_netdev_priv *np = netdev_priv(netdev);
2860 struct i40e_vsi *vsi = np->vsi;
2861 struct i40e_pf *pf = vsi->back;
2862 int ret = -EOPNOTSUPP;
2863
2864 switch (cmd->cmd) {
2865 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002866 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002867 ret = 0;
2868 break;
2869 case ETHTOOL_GRXFH:
2870 ret = i40e_get_rss_hash_opts(pf, cmd);
2871 break;
2872 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002873 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002874 /* report total rule count */
2875 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002876 ret = 0;
2877 break;
2878 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002879 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002880 break;
2881 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002882 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2883 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002884 default:
2885 break;
2886 }
2887
2888 return ret;
2889}
2890
2891/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002892 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2893 * @nfc: pointer to user request
Jacob Kellerf5254422018-04-20 01:41:33 -07002894 * @i_setc: bits currently set
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002895 *
2896 * Returns value of bits to be set per user request
2897 **/
2898static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2899{
2900 u64 i_set = i_setc;
2901 u64 src_l3 = 0, dst_l3 = 0;
2902
2903 if (nfc->data & RXH_L4_B_0_1)
2904 i_set |= I40E_L4_SRC_MASK;
2905 else
2906 i_set &= ~I40E_L4_SRC_MASK;
2907 if (nfc->data & RXH_L4_B_2_3)
2908 i_set |= I40E_L4_DST_MASK;
2909 else
2910 i_set &= ~I40E_L4_DST_MASK;
2911
2912 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2913 src_l3 = I40E_L3_V6_SRC_MASK;
2914 dst_l3 = I40E_L3_V6_DST_MASK;
2915 } else if (nfc->flow_type == TCP_V4_FLOW ||
2916 nfc->flow_type == UDP_V4_FLOW) {
2917 src_l3 = I40E_L3_SRC_MASK;
2918 dst_l3 = I40E_L3_DST_MASK;
2919 } else {
2920 /* Any other flow type are not supported here */
2921 return i_set;
2922 }
2923
2924 if (nfc->data & RXH_IP_SRC)
2925 i_set |= src_l3;
2926 else
2927 i_set &= ~src_l3;
2928 if (nfc->data & RXH_IP_DST)
2929 i_set |= dst_l3;
2930 else
2931 i_set &= ~dst_l3;
2932
2933 return i_set;
2934}
2935
2936/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002937 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2938 * @pf: pointer to the physical function struct
Jacob Kellerf5254422018-04-20 01:41:33 -07002939 * @nfc: ethtool rxnfc command
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002940 *
2941 * Returns Success if the flow input set is supported.
2942 **/
2943static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2944{
2945 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002946 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2947 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002948 u8 flow_pctype = 0;
2949 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002950
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002951 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2952 dev_err(&pf->pdev->dev,
2953 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2954 return -EOPNOTSUPP;
2955 }
2956
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002957 /* RSS does not support anything other than hashing
2958 * to queues on src and dst IPs and ports
2959 */
2960 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2961 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2962 return -EINVAL;
2963
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002964 switch (nfc->flow_type) {
2965 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002966 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002967 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002968 hena |=
2969 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002970 break;
2971 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002972 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002973 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002974 hena |=
2975 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002976 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002977 hena |=
2978 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002979 break;
2980 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002981 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002982 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002983 hena |=
2984 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2985 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002986
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002987 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002988 break;
2989 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002990 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002991 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002992 hena |=
2993 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2994 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002995
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002996 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002997 break;
2998 case AH_ESP_V4_FLOW:
2999 case AH_V4_FLOW:
3000 case ESP_V4_FLOW:
3001 case SCTP_V4_FLOW:
3002 if ((nfc->data & RXH_L4_B_0_1) ||
3003 (nfc->data & RXH_L4_B_2_3))
3004 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003005 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003006 break;
3007 case AH_ESP_V6_FLOW:
3008 case AH_V6_FLOW:
3009 case ESP_V6_FLOW:
3010 case SCTP_V6_FLOW:
3011 if ((nfc->data & RXH_L4_B_0_1) ||
3012 (nfc->data & RXH_L4_B_2_3))
3013 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003014 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003015 break;
3016 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003017 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
3018 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003019 break;
3020 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04003021 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
3022 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003023 break;
3024 default:
3025 return -EINVAL;
3026 }
3027
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07003028 if (flow_pctype) {
3029 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
3030 flow_pctype)) |
3031 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
3032 flow_pctype)) << 32);
3033 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
3034 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
3035 (u32)i_set);
3036 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
3037 (u32)(i_set >> 32));
3038 hena |= BIT_ULL(flow_pctype);
3039 }
3040
Shannon Nelson272cdaf22016-02-17 16:12:21 -08003041 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
3042 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003043 i40e_flush(hw);
3044
3045 return 0;
3046}
3047
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003048/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003049 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
3050 * @vsi: Pointer to the targeted VSI
3051 * @input: The filter to update or NULL to indicate deletion
3052 * @sw_idx: Software index to the filter
3053 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003054 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003055 * This function updates (or deletes) a Flow Director entry from
3056 * the hlist of the corresponding PF
3057 *
3058 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003059 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003060static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
3061 struct i40e_fdir_filter *input,
3062 u16 sw_idx,
3063 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003064{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003065 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003066 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003067 struct hlist_node *node2;
3068 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003069
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003070 parent = NULL;
3071 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003072
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003073 hlist_for_each_entry_safe(rule, node2,
3074 &pf->fdir_filter_list, fdir_node) {
3075 /* hash found, or no matching entry */
3076 if (rule->fd_id >= sw_idx)
3077 break;
3078 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003079 }
3080
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003081 /* if there is an old rule occupying our place remove it */
3082 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08003083 /* Remove this rule, since we're either deleting it, or
3084 * replacing it.
3085 */
3086 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003087 hlist_del(&rule->fdir_node);
3088 kfree(rule);
3089 pf->fdir_pf_active_filters--;
3090 }
3091
Jacob Kellerc6da5252017-02-06 14:39:13 -08003092 /* If we weren't given an input, this is a delete, so just return the
3093 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003094 */
3095 if (!input)
3096 return err;
3097
Jacob Kellerc6da5252017-02-06 14:39:13 -08003098 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003099 INIT_HLIST_NODE(&input->fdir_node);
3100
3101 /* add filter to the list */
3102 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07003103 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003104 else
3105 hlist_add_head(&input->fdir_node,
3106 &pf->fdir_filter_list);
3107
3108 /* update counts */
3109 pf->fdir_pf_active_filters++;
3110
3111 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003112}
3113
3114/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003115 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
3116 * @pf: pointer to PF structure
3117 *
3118 * This function searches the list of filters and determines which FLX_PIT
3119 * entries are still required. It will prune any entries which are no longer
3120 * in use after the deletion.
3121 **/
3122static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
3123{
3124 struct i40e_flex_pit *entry, *tmp;
3125 struct i40e_fdir_filter *rule;
3126
3127 /* First, we'll check the l3 table */
3128 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
3129 bool found = false;
3130
3131 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3132 if (rule->flow_type != IP_USER_FLOW)
3133 continue;
3134 if (rule->flex_filter &&
3135 rule->flex_offset == entry->src_offset) {
3136 found = true;
3137 break;
3138 }
3139 }
3140
3141 /* If we didn't find the filter, then we can prune this entry
3142 * from the list.
3143 */
3144 if (!found) {
3145 list_del(&entry->list);
3146 kfree(entry);
3147 }
3148 }
3149
3150 /* Followed by the L4 table */
3151 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
3152 bool found = false;
3153
3154 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
3155 /* Skip this filter if it's L3, since we already
3156 * checked those in the above loop
3157 */
3158 if (rule->flow_type == IP_USER_FLOW)
3159 continue;
3160 if (rule->flex_filter &&
3161 rule->flex_offset == entry->src_offset) {
3162 found = true;
3163 break;
3164 }
3165 }
3166
3167 /* If we didn't find the filter, then we can prune this entry
3168 * from the list.
3169 */
3170 if (!found) {
3171 list_del(&entry->list);
3172 kfree(entry);
3173 }
3174 }
3175}
3176
3177/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003178 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
3179 * @vsi: Pointer to the targeted VSI
3180 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003181 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003182 * The function removes a Flow Director filter entry from the
3183 * hlist of the corresponding PF
3184 *
3185 * Returns 0 on success
3186 */
3187static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
3188 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003189{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003190 struct ethtool_rx_flow_spec *fsp =
3191 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003192 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003193 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00003194
Jacob Keller0da36b92017-04-19 09:25:55 -04003195 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3196 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003197 return -EBUSY;
3198
Jacob Keller0da36b92017-04-19 09:25:55 -04003199 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003200 return -EBUSY;
3201
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003202 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003203
Jacob Keller0e588de2017-02-06 14:38:50 -08003204 i40e_prune_flex_pit_list(pf);
3205
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003206 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003207 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003208}
3209
3210/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003211 * i40e_unused_pit_index - Find an unused PIT index for given list
3212 * @pf: the PF data structure
3213 *
3214 * Find the first unused flexible PIT index entry. We search both the L3 and
3215 * L4 flexible PIT lists so that the returned index is unique and unused by
3216 * either currently programmed L3 or L4 filters. We use a bit field as storage
3217 * to track which indexes are already used.
3218 **/
3219static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3220{
3221 unsigned long available_index = 0xFF;
3222 struct i40e_flex_pit *entry;
3223
3224 /* We need to make sure that the new index isn't in use by either L3
3225 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3226 * L4 to use the same index.
3227 */
3228
3229 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3230 clear_bit(entry->pit_index, &available_index);
3231
3232 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3233 clear_bit(entry->pit_index, &available_index);
3234
3235 return find_first_bit(&available_index, 8);
3236}
3237
3238/**
3239 * i40e_find_flex_offset - Find an existing flex src_offset
3240 * @flex_pit_list: L3 or L4 flex PIT list
3241 * @src_offset: new src_offset to find
3242 *
3243 * Searches the flex_pit_list for an existing offset. If no offset is
3244 * currently programmed, then this will return an ERR_PTR if there is no space
3245 * to add a new offset, otherwise it returns NULL.
3246 **/
3247static
3248struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3249 u16 src_offset)
3250{
3251 struct i40e_flex_pit *entry;
3252 int size = 0;
3253
3254 /* Search for the src_offset first. If we find a matching entry
3255 * already programmed, we can simply re-use it.
3256 */
3257 list_for_each_entry(entry, flex_pit_list, list) {
3258 size++;
3259 if (entry->src_offset == src_offset)
3260 return entry;
3261 }
3262
3263 /* If we haven't found an entry yet, then the provided src offset has
3264 * not yet been programmed. We will program the src offset later on,
3265 * but we need to indicate whether there is enough space to do so
3266 * here. We'll make use of ERR_PTR for this purpose.
3267 */
3268 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3269 return ERR_PTR(-ENOSPC);
3270
3271 return NULL;
3272}
3273
3274/**
3275 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3276 * @flex_pit_list: L3 or L4 flex PIT list
3277 * @src_offset: new src_offset to add
3278 * @pit_index: the PIT index to program
3279 *
3280 * This function programs the new src_offset to the list. It is expected that
3281 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3282 * that this offset is not programmed, and that the list has enough space to
3283 * store another offset.
3284 *
3285 * Returns 0 on success, and negative value on error.
3286 **/
3287static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3288 u16 src_offset,
3289 u8 pit_index)
3290{
3291 struct i40e_flex_pit *new_pit, *entry;
3292
3293 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3294 if (!new_pit)
3295 return -ENOMEM;
3296
3297 new_pit->src_offset = src_offset;
3298 new_pit->pit_index = pit_index;
3299
3300 /* We need to insert this item such that the list is sorted by
3301 * src_offset in ascending order.
3302 */
3303 list_for_each_entry(entry, flex_pit_list, list) {
3304 if (new_pit->src_offset < entry->src_offset) {
3305 list_add_tail(&new_pit->list, &entry->list);
3306 return 0;
3307 }
3308
3309 /* If we found an entry with our offset already programmed we
3310 * can simply return here, after freeing the memory. However,
3311 * if the pit_index does not match we need to report an error.
3312 */
3313 if (new_pit->src_offset == entry->src_offset) {
3314 int err = 0;
3315
3316 /* If the PIT index is not the same we can't re-use
3317 * the entry, so we must report an error.
3318 */
3319 if (new_pit->pit_index != entry->pit_index)
3320 err = -EINVAL;
3321
3322 kfree(new_pit);
3323 return err;
3324 }
3325 }
3326
3327 /* If we reached here, then we haven't yet added the item. This means
3328 * that we should add the item at the end of the list.
3329 */
3330 list_add_tail(&new_pit->list, flex_pit_list);
3331 return 0;
3332}
3333
3334/**
3335 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3336 * @pf: Pointer to the PF structure
3337 * @flex_pit_list: list of flexible src offsets in use
Jacob Kellerf5254422018-04-20 01:41:33 -07003338 * @flex_pit_start: index to first entry for this section of the table
Jacob Keller0e588de2017-02-06 14:38:50 -08003339 *
3340 * In order to handle flexible data, the hardware uses a table of values
3341 * called the FLX_PIT table. This table is used to indicate which sections of
3342 * the input correspond to what PIT index values. Unfortunately, hardware is
3343 * very restrictive about programming this table. Entries must be ordered by
3344 * src_offset in ascending order, without duplicates. Additionally, unused
3345 * entries must be set to the unused index value, and must have valid size and
3346 * length according to the src_offset ordering.
3347 *
3348 * This function will reprogram the FLX_PIT register from a book-keeping
3349 * structure that we guarantee is already ordered correctly, and has no more
3350 * than 3 entries.
3351 *
3352 * To make things easier, we only support flexible values of one word length,
3353 * rather than allowing variable length flexible values.
3354 **/
3355static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3356 struct list_head *flex_pit_list,
3357 int flex_pit_start)
3358{
3359 struct i40e_flex_pit *entry = NULL;
3360 u16 last_offset = 0;
3361 int i = 0, j = 0;
3362
3363 /* First, loop over the list of flex PIT entries, and reprogram the
3364 * registers.
3365 */
3366 list_for_each_entry(entry, flex_pit_list, list) {
3367 /* We have to be careful when programming values for the
3368 * largest SRC_OFFSET value. It is possible that adding
3369 * additional empty values at the end would overflow the space
3370 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3371 * we check here and add the empty values prior to adding the
3372 * largest value.
3373 *
3374 * To determine this, we will use a loop from i+1 to 3, which
3375 * will determine whether the unused entries would have valid
3376 * SRC_OFFSET. Note that there cannot be extra entries past
3377 * this value, because the only valid values would have been
3378 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3379 * have been added to the list in the first place.
3380 */
3381 for (j = i + 1; j < 3; j++) {
3382 u16 offset = entry->src_offset + j;
3383 int index = flex_pit_start + i;
3384 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3385 1,
3386 offset - 3);
3387
3388 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3389 i40e_write_rx_ctl(&pf->hw,
3390 I40E_PRTQF_FLX_PIT(index),
3391 value);
3392 i++;
3393 }
3394 }
3395
3396 /* Now, we can program the actual value into the table */
3397 i40e_write_rx_ctl(&pf->hw,
3398 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3399 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3400 1,
3401 entry->src_offset));
3402 i++;
3403 }
3404
3405 /* In order to program the last entries in the table, we need to
3406 * determine the valid offset. If the list is empty, we'll just start
3407 * with 0. Otherwise, we'll start with the last item offset and add 1.
3408 * This ensures that all entries have valid sizes. If we don't do this
3409 * correctly, the hardware will disable flexible field parsing.
3410 */
3411 if (!list_empty(flex_pit_list))
3412 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3413
3414 for (; i < 3; i++, last_offset++) {
3415 i40e_write_rx_ctl(&pf->hw,
3416 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3417 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3418 1,
3419 last_offset));
3420 }
3421}
3422
3423/**
3424 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3425 * @pf: pointer to the PF structure
3426 *
3427 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3428 * internal helper function for implementation details.
3429 **/
3430static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3431{
3432 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3433 I40E_FLEX_PIT_IDX_START_L3);
3434
3435 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3436 I40E_FLEX_PIT_IDX_START_L4);
3437
3438 /* We also need to program the L3 and L4 GLQF ORT register */
3439 i40e_write_rx_ctl(&pf->hw,
3440 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3441 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3442 3, 1));
3443
3444 i40e_write_rx_ctl(&pf->hw,
3445 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3446 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3447 3, 1));
3448}
3449
3450/**
Jacob Keller9229e992017-02-06 14:38:47 -08003451 * i40e_flow_str - Converts a flow_type into a human readable string
Jacob Kellerf5254422018-04-20 01:41:33 -07003452 * @fsp: the flow specification
Jacob Keller9229e992017-02-06 14:38:47 -08003453 *
3454 * Currently only flow types we support are included here, and the string
3455 * value attempts to match what ethtool would use to configure this flow type.
3456 **/
3457static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3458{
3459 switch (fsp->flow_type & ~FLOW_EXT) {
3460 case TCP_V4_FLOW:
3461 return "tcp4";
3462 case UDP_V4_FLOW:
3463 return "udp4";
3464 case SCTP_V4_FLOW:
3465 return "sctp4";
3466 case IP_USER_FLOW:
3467 return "ip4";
3468 default:
3469 return "unknown";
3470 }
3471}
3472
3473/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003474 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3475 * @pit_index: PIT index to convert
3476 *
3477 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3478 * of range.
3479 **/
3480static u64 i40e_pit_index_to_mask(int pit_index)
3481{
3482 switch (pit_index) {
3483 case 0:
3484 return I40E_FLEX_50_MASK;
3485 case 1:
3486 return I40E_FLEX_51_MASK;
3487 case 2:
3488 return I40E_FLEX_52_MASK;
3489 case 3:
3490 return I40E_FLEX_53_MASK;
3491 case 4:
3492 return I40E_FLEX_54_MASK;
3493 case 5:
3494 return I40E_FLEX_55_MASK;
3495 case 6:
3496 return I40E_FLEX_56_MASK;
3497 case 7:
3498 return I40E_FLEX_57_MASK;
3499 default:
3500 return 0;
3501 }
3502}
3503
3504/**
Jacob Keller9229e992017-02-06 14:38:47 -08003505 * i40e_print_input_set - Show changes between two input sets
3506 * @vsi: the vsi being configured
3507 * @old: the old input set
3508 * @new: the new input set
3509 *
3510 * Print the difference between old and new input sets by showing which series
3511 * of words are toggled on or off. Only displays the bits we actually support
3512 * changing.
3513 **/
3514static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3515{
3516 struct i40e_pf *pf = vsi->back;
3517 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003518 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003519
3520 old_value = !!(old & I40E_L3_SRC_MASK);
3521 new_value = !!(new & I40E_L3_SRC_MASK);
3522 if (old_value != new_value)
3523 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3524 old_value ? "ON" : "OFF",
3525 new_value ? "ON" : "OFF");
3526
3527 old_value = !!(old & I40E_L3_DST_MASK);
3528 new_value = !!(new & I40E_L3_DST_MASK);
3529 if (old_value != new_value)
3530 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3531 old_value ? "ON" : "OFF",
3532 new_value ? "ON" : "OFF");
3533
3534 old_value = !!(old & I40E_L4_SRC_MASK);
3535 new_value = !!(new & I40E_L4_SRC_MASK);
3536 if (old_value != new_value)
3537 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3538 old_value ? "ON" : "OFF",
3539 new_value ? "ON" : "OFF");
3540
3541 old_value = !!(old & I40E_L4_DST_MASK);
3542 new_value = !!(new & I40E_L4_DST_MASK);
3543 if (old_value != new_value)
3544 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3545 old_value ? "ON" : "OFF",
3546 new_value ? "ON" : "OFF");
3547
3548 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3549 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3550 if (old_value != new_value)
3551 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3552 old_value ? "ON" : "OFF",
3553 new_value ? "ON" : "OFF");
3554
Jacob Keller0e588de2017-02-06 14:38:50 -08003555 /* Show change of flexible filter entries */
3556 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3557 u64 flex_mask = i40e_pit_index_to_mask(i);
3558
3559 old_value = !!(old & flex_mask);
3560 new_value = !!(new & flex_mask);
3561 if (old_value != new_value)
3562 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3563 i,
3564 old_value ? "ON" : "OFF",
3565 new_value ? "ON" : "OFF");
3566 }
3567
Jacob Keller9229e992017-02-06 14:38:47 -08003568 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3569 old);
3570 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3571 new);
3572}
3573
3574/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003575 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003576 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003577 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003578 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003579 *
Jacob Keller9229e992017-02-06 14:38:47 -08003580 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3581 * for partial matches exists with a few limitations. First, hardware only
3582 * supports masking by word boundary (2 bytes) and not per individual bit.
3583 * Second, hardware is limited to using one mask for a flow type and cannot
3584 * use a separate mask for each filter.
3585 *
3586 * To support these limitations, if we already have a configured filter for
3587 * the specified type, this function enforces that new filters of the type
3588 * match the configured input set. Otherwise, if we do not have a filter of
3589 * the specified type, we allow the input set to be updated to match the
3590 * desired filter.
3591 *
3592 * To help ensure that administrators understand why filters weren't displayed
3593 * as supported, we print a diagnostic message displaying how the input set
3594 * would change and warning to delete the preexisting filters if required.
3595 *
3596 * Returns 0 on successful input set match, and a negative return code on
3597 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003598 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003599static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003600 struct ethtool_rx_flow_spec *fsp,
3601 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003602{
Jacob Keller36777d92017-03-07 15:05:23 -08003603 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003604 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3605 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003606 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003607 bool new_flex_offset = false;
3608 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003609 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003610 u16 index, src_offset = 0;
3611 u8 pit_index = 0;
3612 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003613
3614 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003615 case SCTP_V4_FLOW:
3616 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3617 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3618 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003619 case TCP_V4_FLOW:
3620 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003621 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003622 break;
3623 case UDP_V4_FLOW:
3624 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003625 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003626 break;
3627 case IP_USER_FLOW:
3628 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003629 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003630 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003631 break;
3632 default:
3633 return -EOPNOTSUPP;
3634 }
3635
3636 /* Read the current input set from register memory. */
3637 current_mask = i40e_read_fd_input_set(pf, index);
3638 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003639
Jacob Keller9229e992017-02-06 14:38:47 -08003640 /* Determine, if any, the required changes to the input set in order
3641 * to support the provided mask.
3642 *
3643 * Hardware only supports masking at word (2 byte) granularity and does
3644 * not support full bitwise masking. This implementation simplifies
3645 * even further and only supports fully enabled or fully disabled
3646 * masks for each field, even though we could split the ip4src and
3647 * ip4dst fields.
3648 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003649 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003650 case SCTP_V4_FLOW:
3651 new_mask &= ~I40E_VERIFY_TAG_MASK;
3652 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003653 case TCP_V4_FLOW:
3654 case UDP_V4_FLOW:
3655 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3656
3657 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003658 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3659 new_mask |= I40E_L3_SRC_MASK;
3660 else if (!tcp_ip4_spec->ip4src)
3661 new_mask &= ~I40E_L3_SRC_MASK;
3662 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003663 return -EOPNOTSUPP;
3664
3665 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003666 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3667 new_mask |= I40E_L3_DST_MASK;
3668 else if (!tcp_ip4_spec->ip4dst)
3669 new_mask &= ~I40E_L3_DST_MASK;
3670 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003671 return -EOPNOTSUPP;
3672
3673 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003674 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3675 new_mask |= I40E_L4_SRC_MASK;
3676 else if (!tcp_ip4_spec->psrc)
3677 new_mask &= ~I40E_L4_SRC_MASK;
3678 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003679 return -EOPNOTSUPP;
3680
3681 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003682 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3683 new_mask |= I40E_L4_DST_MASK;
3684 else if (!tcp_ip4_spec->pdst)
3685 new_mask &= ~I40E_L4_DST_MASK;
3686 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003687 return -EOPNOTSUPP;
3688
3689 /* Filtering on Type of Service is not supported. */
3690 if (tcp_ip4_spec->tos)
3691 return -EOPNOTSUPP;
3692
3693 break;
3694 case IP_USER_FLOW:
3695 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3696
3697 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003698 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3699 new_mask |= I40E_L3_SRC_MASK;
3700 else if (!usr_ip4_spec->ip4src)
3701 new_mask &= ~I40E_L3_SRC_MASK;
3702 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003703 return -EOPNOTSUPP;
3704
3705 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003706 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3707 new_mask |= I40E_L3_DST_MASK;
3708 else if (!usr_ip4_spec->ip4dst)
3709 new_mask &= ~I40E_L3_DST_MASK;
3710 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003711 return -EOPNOTSUPP;
3712
3713 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003714 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3715 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3716 else if (!usr_ip4_spec->l4_4_bytes)
3717 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3718 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003719 return -EOPNOTSUPP;
3720
3721 /* Filtering on Type of Service is not supported. */
3722 if (usr_ip4_spec->tos)
3723 return -EOPNOTSUPP;
3724
Jacob Keller0e588de2017-02-06 14:38:50 -08003725 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003726 if (usr_ip4_spec->ip_ver)
3727 return -EINVAL;
3728
Jacob Keller0e588de2017-02-06 14:38:50 -08003729 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003730 if (usr_ip4_spec->proto)
3731 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003732
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003733 break;
3734 default:
3735 return -EOPNOTSUPP;
3736 }
3737
Jacob Keller0e588de2017-02-06 14:38:50 -08003738 /* First, clear all flexible filter entries */
3739 new_mask &= ~I40E_FLEX_INPUT_MASK;
3740
3741 /* If we have a flexible filter, try to add this offset to the correct
3742 * flexible filter PIT list. Once finished, we can update the mask.
3743 * If the src_offset changed, we will get a new mask value which will
3744 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003745 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003746 if (userdef->flex_filter) {
3747 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3748
3749 /* Flexible offset must be even, since the flexible payload
3750 * must be aligned on 2-byte boundary.
3751 */
3752 if (userdef->flex_offset & 0x1) {
3753 dev_warn(&pf->pdev->dev,
3754 "Flexible data offset must be 2-byte aligned\n");
3755 return -EINVAL;
3756 }
3757
3758 src_offset = userdef->flex_offset >> 1;
3759
3760 /* FLX_PIT source offset value is only so large */
3761 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3762 dev_warn(&pf->pdev->dev,
3763 "Flexible data must reside within first 64 bytes of the packet payload\n");
3764 return -EINVAL;
3765 }
3766
3767 /* See if this offset has already been programmed. If we get
3768 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3769 * if we get a NULL pointer, this means we will need to add
3770 * the offset.
3771 */
3772 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3773 src_offset);
3774 if (IS_ERR(flex_pit))
3775 return PTR_ERR(flex_pit);
3776
3777 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3778 * packet types, and thus we need to program both L3 and L4
3779 * flexible values. These must have identical flexible index,
3780 * as otherwise we can't correctly program the input set. So
3781 * we'll find both an L3 and L4 index and make sure they are
3782 * the same.
3783 */
3784 if (flex_l3) {
3785 l3_flex_pit =
3786 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3787 src_offset);
3788 if (IS_ERR(l3_flex_pit))
3789 return PTR_ERR(l3_flex_pit);
3790
3791 if (flex_pit) {
3792 /* If we already had a matching L4 entry, we
3793 * need to make sure that the L3 entry we
3794 * obtained uses the same index.
3795 */
3796 if (l3_flex_pit) {
3797 if (l3_flex_pit->pit_index !=
3798 flex_pit->pit_index) {
3799 return -EINVAL;
3800 }
3801 } else {
3802 new_flex_offset = true;
3803 }
3804 } else {
3805 flex_pit = l3_flex_pit;
3806 }
3807 }
3808
3809 /* If we didn't find an existing flex offset, we need to
3810 * program a new one. However, we don't immediately program it
3811 * here because we will wait to program until after we check
3812 * that it is safe to change the input set.
3813 */
3814 if (!flex_pit) {
3815 new_flex_offset = true;
3816 pit_index = i40e_unused_pit_index(pf);
3817 } else {
3818 pit_index = flex_pit->pit_index;
3819 }
3820
3821 /* Update the mask with the new offset */
3822 new_mask |= i40e_pit_index_to_mask(pit_index);
3823 }
3824
3825 /* If the mask and flexible filter offsets for this filter match the
3826 * currently programmed values we don't need any input set change, so
3827 * this filter is safe to install.
3828 */
3829 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003830 return 0;
3831
3832 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3833 i40e_flow_str(fsp));
3834 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003835 if (new_flex_offset) {
3836 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3837 pit_index, src_offset);
3838 }
Jacob Keller9229e992017-02-06 14:38:47 -08003839
3840 /* Hardware input sets are global across multiple ports, so even the
3841 * main port cannot change them when in MFP mode as this would impact
3842 * any filters on the other ports.
3843 */
3844 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3845 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003846 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003847 }
3848
3849 /* This filter requires us to update the input set. However, hardware
3850 * only supports one input set per flow type, and does not support
3851 * separate masks for each filter. This means that we can only support
3852 * a single mask for all filters of a specific type.
3853 *
3854 * If we have preexisting filters, they obviously depend on the
3855 * current programmed input set. Display a diagnostic message in this
3856 * case explaining why the filter could not be accepted.
3857 */
3858 if (*fdir_filter_count) {
3859 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3860 i40e_flow_str(fsp),
3861 *fdir_filter_count);
3862 return -EOPNOTSUPP;
3863 }
3864
3865 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003866
Jacob Keller02b40162017-12-27 08:24:12 -05003867 /* IP_USER_FLOW filters match both IPv4/Other and IPv4/Fragmented
3868 * frames. If we're programming the input set for IPv4/Other, we also
3869 * need to program the IPv4/Fragmented input set. Since we don't have
3870 * separate support, we'll always assume and enforce that the two flow
3871 * types must have matching input sets.
3872 */
3873 if (index == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER)
3874 i40e_write_fd_input_set(pf, I40E_FILTER_PCTYPE_FRAG_IPV4,
3875 new_mask);
3876
Jacob Keller0e588de2017-02-06 14:38:50 -08003877 /* Add the new offset and update table, if necessary */
3878 if (new_flex_offset) {
3879 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3880 pit_index);
3881 if (err)
3882 return err;
3883
3884 if (flex_l3) {
3885 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3886 src_offset,
3887 pit_index);
3888 if (err)
3889 return err;
3890 }
3891
3892 i40e_reprogram_flex_pit(pf);
3893 }
3894
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003895 return 0;
3896}
3897
3898/**
Jacob Keller443ee712017-12-27 08:25:32 -05003899 * i40e_match_fdir_filter - Return true of two filters match
3900 * @a: pointer to filter struct
3901 * @b: pointer to filter struct
3902 *
3903 * Returns true if the two filters match exactly the same criteria. I.e. they
3904 * match the same flow type and have the same parameters. We don't need to
3905 * check any input-set since all filters of the same flow type must use the
3906 * same input set.
3907 **/
3908static bool i40e_match_fdir_filter(struct i40e_fdir_filter *a,
3909 struct i40e_fdir_filter *b)
3910{
3911 /* The filters do not much if any of these criteria differ. */
3912 if (a->dst_ip != b->dst_ip ||
3913 a->src_ip != b->src_ip ||
3914 a->dst_port != b->dst_port ||
3915 a->src_port != b->src_port ||
3916 a->flow_type != b->flow_type ||
3917 a->ip4_proto != b->ip4_proto)
3918 return false;
3919
3920 return true;
3921}
3922
3923/**
3924 * i40e_disallow_matching_filters - Check that new filters differ
3925 * @vsi: pointer to the targeted VSI
3926 * @input: new filter to check
3927 *
3928 * Due to hardware limitations, it is not possible for two filters that match
3929 * similar criteria to be programmed at the same time. This is true for a few
3930 * reasons:
3931 *
3932 * (a) all filters matching a particular flow type must use the same input
3933 * set, that is they must match the same criteria.
3934 * (b) different flow types will never match the same packet, as the flow type
3935 * is decided by hardware before checking which rules apply.
3936 * (c) hardware has no way to distinguish which order filters apply in.
3937 *
3938 * Due to this, we can't really support using the location data to order
3939 * filters in the hardware parsing. It is technically possible for the user to
3940 * request two filters matching the same criteria but which select different
3941 * queues. In this case, rather than keep both filters in the list, we reject
3942 * the 2nd filter when the user requests adding it.
3943 *
3944 * This avoids needing to track location for programming the filter to
3945 * hardware, and ensures that we avoid some strange scenarios involving
3946 * deleting filters which match the same criteria.
3947 **/
3948static int i40e_disallow_matching_filters(struct i40e_vsi *vsi,
3949 struct i40e_fdir_filter *input)
3950{
3951 struct i40e_pf *pf = vsi->back;
3952 struct i40e_fdir_filter *rule;
3953 struct hlist_node *node2;
3954
3955 /* Loop through every filter, and check that it doesn't match */
3956 hlist_for_each_entry_safe(rule, node2,
3957 &pf->fdir_filter_list, fdir_node) {
3958 /* Don't check the filters match if they share the same fd_id,
3959 * since the new filter is actually just updating the target
3960 * of the old filter.
3961 */
3962 if (rule->fd_id == input->fd_id)
3963 continue;
3964
3965 /* If any filters match, then print a warning message to the
3966 * kernel message buffer and bail out.
3967 */
3968 if (i40e_match_fdir_filter(rule, input)) {
3969 dev_warn(&pf->pdev->dev,
3970 "Existing user defined filter %d already matches this flow.\n",
3971 rule->fd_id);
3972 return -EINVAL;
3973 }
3974 }
3975
3976 return 0;
3977}
3978
3979/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003980 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003981 * @vsi: pointer to the targeted VSI
3982 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003983 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003984 * Add Flow Director filters for a specific flow spec based on their
3985 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003986 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003987static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3988 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003989{
Jacob Kellere7930952017-02-06 14:38:49 -08003990 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003991 struct ethtool_rx_flow_spec *fsp;
3992 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003993 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003994 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003995 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003996 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003997
3998 if (!vsi)
3999 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004000 pf = vsi->back;
4001
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004002 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
4003 return -EOPNOTSUPP;
4004
Jacob Keller134201a2018-03-16 01:26:32 -07004005 if (test_bit(__I40E_FD_SB_AUTO_DISABLED, pf->state))
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004006 return -ENOSPC;
4007
Jacob Keller0da36b92017-04-19 09:25:55 -04004008 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
4009 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00004010 return -EBUSY;
4011
Jacob Keller0da36b92017-04-19 09:25:55 -04004012 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00004013 return -EBUSY;
4014
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00004015 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
4016
Jacob Kellere7930952017-02-06 14:38:49 -08004017 /* Parse the user-defined field */
4018 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
4019 return -EINVAL;
4020
Jacob Keller1ec8dea2017-02-06 14:39:12 -08004021 /* Extended MAC field is not supported */
4022 if (fsp->flow_type & FLOW_MAC_EXT)
4023 return -EINVAL;
4024
Jacob Keller0e588de2017-02-06 14:38:50 -08004025 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08004026 if (ret)
4027 return ret;
4028
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004029 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
4030 pf->hw.func_caps.fd_filters_guaranteed)) {
4031 return -EINVAL;
4032 }
4033
Jacob Keller43b15692017-02-06 14:38:48 -08004034 /* ring_cookie is either the drop index, or is a mask of the queue
4035 * index and VF id we wish to target.
4036 */
4037 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
4038 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
4039 } else {
4040 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
4041 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
4042
4043 if (!vf) {
4044 if (ring >= vsi->num_queue_pairs)
4045 return -EINVAL;
4046 dest_vsi = vsi->id;
4047 } else {
4048 /* VFs are zero-indexed, so we subtract one here */
4049 vf--;
4050
4051 if (vf >= pf->num_alloc_vfs)
4052 return -EINVAL;
4053 if (ring >= pf->vf[vf].num_queue_pairs)
4054 return -EINVAL;
4055 dest_vsi = pf->vf[vf].lan_vsi_id;
4056 }
4057 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
4058 q_index = ring;
4059 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004060
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004061 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004062
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004063 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004064 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004065
4066 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08004067 input->q_index = q_index;
4068 input->dest_vsi = dest_vsi;
4069 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004070 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04004071 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08004072 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4073 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08004074 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004075 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00004076
4077 /* Reverse the src and dest notion, since the HW expects them to be from
4078 * Tx perspective where as the input from user is from Rx filter view.
4079 */
4080 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
4081 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08004082 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
4083 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004084
Jacob Keller0e588de2017-02-06 14:38:50 -08004085 if (userdef.flex_filter) {
4086 input->flex_filter = true;
4087 input->flex_word = cpu_to_be16(userdef.flex_word);
4088 input->flex_offset = userdef.flex_offset;
4089 }
4090
Jacob Keller443ee712017-12-27 08:25:32 -05004091 /* Avoid programming two filters with identical match criteria. */
4092 ret = i40e_disallow_matching_filters(vsi, input);
4093 if (ret)
4094 goto free_filter_memory;
4095
Jacob Keller01016da2017-02-06 14:38:40 -08004096 /* Add the input filter to the fdir_input_list, possibly replacing
4097 * a previous filter. Do not free the input structure after adding it
4098 * to the list as this would cause a use-after-free bug.
4099 */
4100 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Patryk Małekca6e1d02017-12-27 07:32:31 -05004101 ret = i40e_add_del_fdir(vsi, input, true);
4102 if (ret)
4103 goto remove_sw_rule;
Jacob Keller01016da2017-02-06 14:38:40 -08004104 return 0;
4105
Patryk Małekca6e1d02017-12-27 07:32:31 -05004106remove_sw_rule:
4107 hlist_del(&input->fdir_node);
4108 pf->fdir_pf_active_filters--;
Jacob Keller443ee712017-12-27 08:25:32 -05004109free_filter_memory:
Jacob Keller01016da2017-02-06 14:38:40 -08004110 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004111 return ret;
4112}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08004113
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004114/**
4115 * i40e_set_rxnfc - command to set RX flow classification rules
4116 * @netdev: network interface device structure
4117 * @cmd: ethtool rxnfc command
4118 *
4119 * Returns Success if the command is supported.
4120 **/
4121static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
4122{
4123 struct i40e_netdev_priv *np = netdev_priv(netdev);
4124 struct i40e_vsi *vsi = np->vsi;
4125 struct i40e_pf *pf = vsi->back;
4126 int ret = -EOPNOTSUPP;
4127
4128 switch (cmd->cmd) {
4129 case ETHTOOL_SRXFH:
4130 ret = i40e_set_rss_hash_opt(pf, cmd);
4131 break;
4132 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00004133 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004134 break;
4135 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00004136 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004137 break;
4138 default:
4139 break;
4140 }
4141
4142 return ret;
4143}
4144
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004145/**
4146 * i40e_max_channels - get Max number of combined channels supported
4147 * @vsi: vsi pointer
4148 **/
4149static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
4150{
4151 /* TODO: This code assumes DCB and FD is disabled for now. */
4152 return vsi->alloc_queue_pairs;
4153}
4154
4155/**
4156 * i40e_get_channels - Get the current channels enabled and max supported etc.
Jacob Kellerf5254422018-04-20 01:41:33 -07004157 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004158 * @ch: ethtool channels structure
4159 *
4160 * We don't support separate tx and rx queues as channels. The other count
4161 * represents how many queues are being used for control. max_combined counts
4162 * how many queue pairs we can support. They may not be mapped 1 to 1 with
4163 * q_vectors since we support a lot more queue pairs than q_vectors.
4164 **/
4165static void i40e_get_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004166 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004167{
4168 struct i40e_netdev_priv *np = netdev_priv(dev);
4169 struct i40e_vsi *vsi = np->vsi;
4170 struct i40e_pf *pf = vsi->back;
4171
4172 /* report maximum channels */
4173 ch->max_combined = i40e_max_channels(vsi);
4174
4175 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004176 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004177 ch->max_other = ch->other_count;
4178
4179 /* Note: This code assumes DCB is disabled for now. */
4180 ch->combined_count = vsi->num_queue_pairs;
4181}
4182
4183/**
4184 * i40e_set_channels - Set the new channels count.
Jacob Kellerf5254422018-04-20 01:41:33 -07004185 * @dev: network interface device structure
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004186 * @ch: ethtool channels structure
4187 *
4188 * The new channels count may not be the same as requested by the user
4189 * since it gets rounded down to a power of 2 value.
4190 **/
4191static int i40e_set_channels(struct net_device *dev,
Jacob Kellerf5254422018-04-20 01:41:33 -07004192 struct ethtool_channels *ch)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004193{
Jacob Keller59826d92016-07-27 12:02:35 -07004194 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004195 struct i40e_netdev_priv *np = netdev_priv(dev);
4196 unsigned int count = ch->combined_count;
4197 struct i40e_vsi *vsi = np->vsi;
4198 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07004199 struct i40e_fdir_filter *rule;
4200 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004201 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07004202 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004203
4204 /* We do not support setting channels for any other VSI at present */
4205 if (vsi->type != I40E_VSI_MAIN)
4206 return -EINVAL;
4207
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07004208 /* We do not support setting channels via ethtool when TCs are
4209 * configured through mqprio
4210 */
4211 if (pf->flags & I40E_FLAG_TC_MQPRIO)
4212 return -EINVAL;
4213
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004214 /* verify they are not requesting separate vectors */
4215 if (!count || ch->rx_count || ch->tx_count)
4216 return -EINVAL;
4217
4218 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08004219 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004220 return -EINVAL;
4221
4222 /* verify the number of channels does not exceed hardware limits */
4223 if (count > i40e_max_channels(vsi))
4224 return -EINVAL;
4225
Jacob Keller59826d92016-07-27 12:02:35 -07004226 /* verify that the number of channels does not invalidate any current
4227 * flow director rules
4228 */
4229 hlist_for_each_entry_safe(rule, node2,
4230 &pf->fdir_filter_list, fdir_node) {
4231 if (rule->dest_ctl != drop && count <= rule->q_index) {
4232 dev_warn(&pf->pdev->dev,
4233 "Existing user defined filter %d assigns flow to queue %d\n",
4234 rule->fd_id, rule->q_index);
4235 err = -EINVAL;
4236 }
4237 }
4238
4239 if (err) {
4240 dev_err(&pf->pdev->dev,
4241 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
4242 count);
4243 return err;
4244 }
4245
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004246 /* update feature limits from largest to smallest supported values */
4247 /* TODO: Flow director limit, DCB etc */
4248
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004249 /* use rss_reconfig to rebuild with new queue count and update traffic
4250 * class queue mapping
4251 */
4252 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00004253 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004254 return 0;
4255 else
4256 return -EINVAL;
4257}
4258
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004259/**
4260 * i40e_get_rxfh_key_size - get the RSS hash key size
4261 * @netdev: network interface device structure
4262 *
4263 * Returns the table size.
4264 **/
4265static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
4266{
4267 return I40E_HKEY_ARRAY_SIZE;
4268}
4269
4270/**
4271 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
4272 * @netdev: network interface device structure
4273 *
4274 * Returns the table size.
4275 **/
4276static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
4277{
4278 return I40E_HLUT_ARRAY_SIZE;
4279}
4280
Alan Brady21675bd2017-10-05 14:53:33 -07004281/**
4282 * i40e_get_rxfh - get the rx flow hash indirection table
4283 * @netdev: network interface device structure
4284 * @indir: indirection table
4285 * @key: hash key
4286 * @hfunc: hash function
4287 *
4288 * Reads the indirection table directly from the hardware. Returns 0 on
4289 * success.
4290 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004291static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
4292 u8 *hfunc)
4293{
4294 struct i40e_netdev_priv *np = netdev_priv(netdev);
4295 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04004296 u8 *lut, *seed = NULL;
4297 int ret;
4298 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004299
4300 if (hfunc)
4301 *hfunc = ETH_RSS_HASH_TOP;
4302
4303 if (!indir)
4304 return 0;
4305
Helin Zhang043dd652015-10-21 19:56:23 -04004306 seed = key;
4307 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4308 if (!lut)
4309 return -ENOMEM;
4310 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4311 if (ret)
4312 goto out;
4313 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4314 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004315
Helin Zhang043dd652015-10-21 19:56:23 -04004316out:
4317 kfree(lut);
4318
4319 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004320}
4321
4322/**
4323 * i40e_set_rxfh - set the rx flow hash indirection table
4324 * @netdev: network interface device structure
4325 * @indir: indirection table
4326 * @key: hash key
Jacob Kellerf5254422018-04-20 01:41:33 -07004327 * @hfunc: hash function to use
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004328 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004329 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004330 * returns 0 after programming the table.
4331 **/
4332static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4333 const u8 *key, const u8 hfunc)
4334{
4335 struct i40e_netdev_priv *np = netdev_priv(netdev);
4336 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004337 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004338 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004339 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004340
4341 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4342 return -EOPNOTSUPP;
4343
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004344 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004345 if (!vsi->rss_hkey_user) {
4346 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4347 GFP_KERNEL);
4348 if (!vsi->rss_hkey_user)
4349 return -ENOMEM;
4350 }
4351 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4352 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004353 }
Helin Zhang28c58692015-10-26 19:44:27 -04004354 if (!vsi->rss_lut_user) {
4355 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4356 if (!vsi->rss_lut_user)
4357 return -ENOMEM;
4358 }
Helin Zhang043dd652015-10-21 19:56:23 -04004359
Helin Zhang28c58692015-10-26 19:44:27 -04004360 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004361 if (indir)
4362 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4363 vsi->rss_lut_user[i] = (u8)(indir[i]);
4364 else
4365 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4366 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004367
4368 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4369 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004370}
4371
Greg Rose7e45ab42015-02-06 08:52:19 +00004372/**
4373 * i40e_get_priv_flags - report device private flags
4374 * @dev: network interface device structure
4375 *
4376 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004377 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004378 * array.
4379 *
4380 * Returns a u32 bitmap of flags.
4381 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004382static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004383{
4384 struct i40e_netdev_priv *np = netdev_priv(dev);
4385 struct i40e_vsi *vsi = np->vsi;
4386 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004387 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004388
Alexander Duyckaca955d2017-03-10 12:22:01 -08004389 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4390 const struct i40e_priv_flags *priv_flags;
4391
4392 priv_flags = &i40e_gstrings_priv_flags[i];
4393
4394 if (priv_flags->flag & pf->flags)
4395 ret_flags |= BIT(i);
4396 }
4397
4398 if (pf->hw.pf_id != 0)
4399 return ret_flags;
4400
4401 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4402 const struct i40e_priv_flags *priv_flags;
4403
4404 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4405
4406 if (priv_flags->flag & pf->flags)
4407 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004408 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004409
4410 return ret_flags;
4411}
4412
Shannon Nelson9ac77262015-08-27 11:42:40 -04004413/**
4414 * i40e_set_priv_flags - set private flags
4415 * @dev: network interface device structure
4416 * @flags: bit flags to be set
4417 **/
4418static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4419{
4420 struct i40e_netdev_priv *np = netdev_priv(dev);
4421 struct i40e_vsi *vsi = np->vsi;
4422 struct i40e_pf *pf = vsi->back;
Alice Michael60f481b2017-12-27 08:17:50 -05004423 u64 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004424 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004425
Jacob Keller841c9502017-06-23 04:24:50 -04004426 orig_flags = READ_ONCE(pf->flags);
4427 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004428
Alexander Duyckaca955d2017-03-10 12:22:01 -08004429 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4430 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004431
Alexander Duyckaca955d2017-03-10 12:22:01 -08004432 priv_flags = &i40e_gstrings_priv_flags[i];
4433
Alexander Duyckaca955d2017-03-10 12:22:01 -08004434 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004435 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004436 else
Jacob Keller841c9502017-06-23 04:24:50 -04004437 new_flags &= ~(priv_flags->flag);
4438
4439 /* If this is a read-only flag, it can't be changed */
4440 if (priv_flags->read_only &&
4441 ((orig_flags ^ new_flags) & ~BIT(i)))
4442 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004443 }
4444
4445 if (pf->hw.pf_id != 0)
4446 goto flags_complete;
4447
4448 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4449 const struct i40e_priv_flags *priv_flags;
4450
4451 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4452
Alexander Duyckaca955d2017-03-10 12:22:01 -08004453 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004454 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004455 else
Jacob Keller841c9502017-06-23 04:24:50 -04004456 new_flags &= ~(priv_flags->flag);
4457
4458 /* If this is a read-only flag, it can't be changed */
4459 if (priv_flags->read_only &&
4460 ((orig_flags ^ new_flags) & ~BIT(i)))
4461 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004462 }
4463
4464flags_complete:
Alan Bradyfe09ed02017-12-29 08:50:34 -05004465 changed_flags = orig_flags ^ new_flags;
4466
Jacob Keller841c9502017-06-23 04:24:50 -04004467 /* Before we finalize any flag changes, we need to perform some
4468 * checks to ensure that the changes are supported and safe.
4469 */
4470
4471 /* ATR eviction is not supported on all devices */
4472 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4473 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4474 return -EOPNOTSUPP;
4475
Alan Bradyfe09ed02017-12-29 08:50:34 -05004476 /* If the driver detected FW LLDP was disabled on init, this flag could
4477 * be set, however we do not support _changing_ the flag if NPAR is
4478 * enabled or FW API version < 1.7. There are situations where older
4479 * FW versions/NPAR enabled PFs could disable LLDP, however we _must_
4480 * not allow the user to enable/disable LLDP with this flag on
4481 * unsupported FW versions.
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004482 */
Alan Bradyfe09ed02017-12-29 08:50:34 -05004483 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
Dave Ertman7b634352018-01-22 12:00:37 -05004484 if (!(pf->hw_features & I40E_HW_STOPPABLE_FW_LLDP)) {
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004485 dev_warn(&pf->pdev->dev,
Dave Ertman7b634352018-01-22 12:00:37 -05004486 "Device does not support changing FW LLDP\n");
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004487 return -EOPNOTSUPP;
4488 }
4489 }
4490
Jacob Keller886ff142018-03-16 01:26:36 -07004491 /* Now that we've checked to ensure that the new flags are valid, load
4492 * them into place. Since we only modify flags either (a) during
4493 * initialization or (b) while holding the RTNL lock, we don't need
4494 * anything fancy here.
Jacob Keller841c9502017-06-23 04:24:50 -04004495 */
Jacob Keller886ff142018-03-16 01:26:36 -07004496 pf->flags = new_flags;
Jacob Keller841c9502017-06-23 04:24:50 -04004497
Alexander Duyckaca955d2017-03-10 12:22:01 -08004498 /* Process any additional changes needed as a result of flag changes.
4499 * The changed_flags value reflects the list of bits that were
4500 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004501 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004502
Alexander Duyckaca955d2017-03-10 12:22:01 -08004503 /* Flush current ATR settings if ATR was disabled */
4504 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4505 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller134201a2018-03-16 01:26:32 -07004506 set_bit(__I40E_FD_ATR_AUTO_DISABLED, pf->state);
Jacob Keller0da36b92017-04-19 09:25:55 -04004507 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004508 }
4509
Alexander Duyckaca955d2017-03-10 12:22:01 -08004510 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4511 u16 sw_flags = 0, valid_flags = 0;
4512 int ret;
4513
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004514 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4515 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4516 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4517 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
Amritha Nambiar5efe0c62017-10-27 02:35:45 -07004518 0, NULL);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004519 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4520 dev_info(&pf->pdev->dev,
4521 "couldn't set switch config bits, err %s aq_err %s\n",
4522 i40e_stat_str(&pf->hw, ret),
4523 i40e_aq_str(&pf->hw,
4524 pf->hw.aq.asq_last_status));
4525 /* not a fatal problem, just keep going */
4526 }
4527 }
4528
Paweł Jabłoński17b4d252017-12-29 08:50:20 -05004529 if ((changed_flags & pf->flags &
4530 I40E_FLAG_LINK_DOWN_ON_CLOSE_ENABLED) &&
4531 (pf->flags & I40E_FLAG_MFP_ENABLED))
4532 dev_warn(&pf->pdev->dev,
4533 "Turning on link-down-on-close flag may affect other partitions\n");
4534
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004535 if (changed_flags & I40E_FLAG_DISABLE_FW_LLDP) {
4536 if (pf->flags & I40E_FLAG_DISABLE_FW_LLDP) {
4537 struct i40e_dcbx_config *dcbcfg;
4538 int i;
4539
4540 i40e_aq_stop_lldp(&pf->hw, true, NULL);
4541 i40e_aq_set_dcb_parameters(&pf->hw, true, NULL);
4542 /* reset local_dcbx_config to default */
4543 dcbcfg = &pf->hw.local_dcbx_config;
4544 dcbcfg->etscfg.willing = 1;
4545 dcbcfg->etscfg.maxtcs = 0;
4546 dcbcfg->etscfg.tcbwtable[0] = 100;
4547 for (i = 1; i < I40E_MAX_TRAFFIC_CLASS; i++)
4548 dcbcfg->etscfg.tcbwtable[i] = 0;
4549 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
4550 dcbcfg->etscfg.prioritytable[i] = 0;
4551 dcbcfg->etscfg.tsatable[0] = I40E_IEEE_TSA_ETS;
4552 dcbcfg->pfc.willing = 1;
4553 dcbcfg->pfc.pfccap = I40E_MAX_TRAFFIC_CLASS;
4554 } else {
4555 i40e_aq_start_lldp(&pf->hw, NULL);
4556 }
4557 }
4558
Alexander Duyckaca955d2017-03-10 12:22:01 -08004559 /* Issue reset to cause things to take effect, as additional bits
4560 * are added we will need to create a mask of bits requiring reset
4561 */
Mitch Williams64615b52017-08-29 05:32:30 -04004562 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4563 I40E_FLAG_LEGACY_RX |
Dave Ertmanc61c8fe2017-12-27 08:18:21 -05004564 I40E_FLAG_SOURCE_PRUNING_DISABLED |
4565 I40E_FLAG_DISABLE_FW_LLDP))
Maciej Sosin373149f2017-04-05 07:50:55 -04004566 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004567
Shannon Nelson9ac77262015-08-27 11:42:40 -04004568 return 0;
4569}
4570
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004571/**
4572 * i40e_get_module_info - get (Q)SFP+ module type info
4573 * @netdev: network interface device structure
4574 * @modinfo: module EEPROM size and layout information structure
4575 **/
4576static int i40e_get_module_info(struct net_device *netdev,
4577 struct ethtool_modinfo *modinfo)
4578{
4579 struct i40e_netdev_priv *np = netdev_priv(netdev);
4580 struct i40e_vsi *vsi = np->vsi;
4581 struct i40e_pf *pf = vsi->back;
4582 struct i40e_hw *hw = &pf->hw;
4583 u32 sff8472_comp = 0;
4584 u32 sff8472_swap = 0;
4585 u32 sff8636_rev = 0;
4586 i40e_status status;
4587 u32 type = 0;
4588
4589 /* Check if firmware supports reading module EEPROM. */
4590 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4591 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4592 return -EINVAL;
4593 }
4594
4595 status = i40e_update_link_info(hw);
4596 if (status)
4597 return -EIO;
4598
4599 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4600 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4601 return -EINVAL;
4602 }
4603
4604 type = hw->phy.link_info.module_type[0];
4605
4606 switch (type) {
4607 case I40E_MODULE_TYPE_SFP:
4608 status = i40e_aq_get_phy_register(hw,
4609 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4610 I40E_I2C_EEPROM_DEV_ADDR,
4611 I40E_MODULE_SFF_8472_COMP,
4612 &sff8472_comp, NULL);
4613 if (status)
4614 return -EIO;
4615
4616 status = i40e_aq_get_phy_register(hw,
4617 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4618 I40E_I2C_EEPROM_DEV_ADDR,
4619 I40E_MODULE_SFF_8472_SWAP,
4620 &sff8472_swap, NULL);
4621 if (status)
4622 return -EIO;
4623
4624 /* Check if the module requires address swap to access
4625 * the other EEPROM memory page.
4626 */
4627 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4628 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4629 modinfo->type = ETH_MODULE_SFF_8079;
4630 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4631 } else if (sff8472_comp == 0x00) {
4632 /* Module is not SFF-8472 compliant */
4633 modinfo->type = ETH_MODULE_SFF_8079;
4634 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4635 } else {
4636 modinfo->type = ETH_MODULE_SFF_8472;
4637 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4638 }
4639 break;
4640 case I40E_MODULE_TYPE_QSFP_PLUS:
4641 /* Read from memory page 0. */
4642 status = i40e_aq_get_phy_register(hw,
4643 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4644 0,
4645 I40E_MODULE_REVISION_ADDR,
4646 &sff8636_rev, NULL);
4647 if (status)
4648 return -EIO;
4649 /* Determine revision compliance byte */
4650 if (sff8636_rev > 0x02) {
4651 /* Module is SFF-8636 compliant */
4652 modinfo->type = ETH_MODULE_SFF_8636;
4653 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4654 } else {
4655 modinfo->type = ETH_MODULE_SFF_8436;
4656 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4657 }
4658 break;
4659 case I40E_MODULE_TYPE_QSFP28:
4660 modinfo->type = ETH_MODULE_SFF_8636;
4661 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4662 break;
4663 default:
4664 netdev_err(vsi->netdev, "Module type unrecognized\n");
4665 return -EINVAL;
4666 }
4667 return 0;
4668}
4669
4670/**
4671 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4672 * @netdev: network interface device structure
4673 * @ee: EEPROM dump request structure
4674 * @data: buffer to be filled with EEPROM contents
4675 **/
4676static int i40e_get_module_eeprom(struct net_device *netdev,
4677 struct ethtool_eeprom *ee,
4678 u8 *data)
4679{
4680 struct i40e_netdev_priv *np = netdev_priv(netdev);
4681 struct i40e_vsi *vsi = np->vsi;
4682 struct i40e_pf *pf = vsi->back;
4683 struct i40e_hw *hw = &pf->hw;
4684 bool is_sfp = false;
4685 i40e_status status;
4686 u32 value = 0;
4687 int i;
4688
4689 if (!ee || !ee->len || !data)
4690 return -EINVAL;
4691
4692 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4693 is_sfp = true;
4694
4695 for (i = 0; i < ee->len; i++) {
4696 u32 offset = i + ee->offset;
4697 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4698
4699 /* Check if we need to access the other memory page */
4700 if (is_sfp) {
4701 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4702 offset -= ETH_MODULE_SFF_8079_LEN;
4703 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4704 }
4705 } else {
4706 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4707 /* Compute memory page number and offset. */
4708 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4709 addr++;
4710 }
4711 }
4712
4713 status = i40e_aq_get_phy_register(hw,
4714 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4715 addr, offset, &value, NULL);
4716 if (status)
4717 return -EIO;
4718 data[i] = value;
4719 }
4720 return 0;
4721}
4722
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004723static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004724 .get_drvinfo = i40e_get_drvinfo,
4725 .get_regs_len = i40e_get_regs_len,
4726 .get_regs = i40e_get_regs,
4727 .nway_reset = i40e_nway_reset,
4728 .get_link = ethtool_op_get_link,
4729 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004730 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004731 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004732 .get_eeprom_len = i40e_get_eeprom_len,
4733 .get_eeprom = i40e_get_eeprom,
4734 .get_ringparam = i40e_get_ringparam,
4735 .set_ringparam = i40e_set_ringparam,
4736 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004737 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004738 .get_msglevel = i40e_get_msglevel,
4739 .set_msglevel = i40e_set_msglevel,
4740 .get_rxnfc = i40e_get_rxnfc,
4741 .set_rxnfc = i40e_set_rxnfc,
4742 .self_test = i40e_diag_test,
4743 .get_strings = i40e_get_strings,
4744 .set_phys_id = i40e_set_phys_id,
4745 .get_sset_count = i40e_get_sset_count,
4746 .get_ethtool_stats = i40e_get_ethtool_stats,
4747 .get_coalesce = i40e_get_coalesce,
4748 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004749 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4750 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4751 .get_rxfh = i40e_get_rxfh,
4752 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004753 .get_channels = i40e_get_channels,
4754 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004755 .get_module_info = i40e_get_module_info,
4756 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004757 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004758 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004759 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004760 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004761 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004762 .get_link_ksettings = i40e_get_link_ksettings,
4763 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004764};
4765
4766void i40e_set_ethtool_ops(struct net_device *netdev)
4767{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004768 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004769}