blob: f4a70ef3f2e02e3989dfbc744dea720ef3b6ed38 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Shannon Nelson66fc3602016-01-13 16:51:42 -08004 * Copyright(c) 2013 - 2016 Intel Corporation.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27/* ethtool support for i40e */
28
29#include "i40e.h"
30#include "i40e_diag.h"
31
32struct i40e_stats {
33 char stat_string[ETH_GSTRING_LEN];
34 int sizeof_stat;
35 int stat_offset;
36};
37
38#define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
42}
Shannon Nelsonfad177d2014-11-11 20:07:27 +000043
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000044#define I40E_NETDEV_STAT(_net_stat) \
Shannon Nelsonfad177d2014-11-11 20:07:27 +000045 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000046#define I40E_PF_STAT(_name, _stat) \
47 I40E_STAT(struct i40e_pf, _name, _stat)
48#define I40E_VSI_STAT(_name, _stat) \
49 I40E_STAT(struct i40e_vsi, _name, _stat)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000050#define I40E_VEB_STAT(_name, _stat) \
51 I40E_STAT(struct i40e_veb, _name, _stat)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000052
53static const struct i40e_stats i40e_gstrings_net_stats[] = {
54 I40E_NETDEV_STAT(rx_packets),
55 I40E_NETDEV_STAT(tx_packets),
56 I40E_NETDEV_STAT(rx_bytes),
57 I40E_NETDEV_STAT(tx_bytes),
58 I40E_NETDEV_STAT(rx_errors),
59 I40E_NETDEV_STAT(tx_errors),
60 I40E_NETDEV_STAT(rx_dropped),
61 I40E_NETDEV_STAT(tx_dropped),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000062 I40E_NETDEV_STAT(collisions),
63 I40E_NETDEV_STAT(rx_length_errors),
64 I40E_NETDEV_STAT(rx_crc_errors),
65};
66
Shannon Nelson8eab9cf2014-04-23 04:49:55 +000067static const struct i40e_stats i40e_gstrings_veb_stats[] = {
68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes),
69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes),
70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast),
71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast),
72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast),
73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast),
74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast),
75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast),
76 I40E_VEB_STAT("rx_discards", stats.rx_discards),
77 I40E_VEB_STAT("tx_discards", stats.tx_discards),
78 I40E_VEB_STAT("tx_errors", stats.tx_errors),
79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol),
80};
81
Shannon Nelson41a9e552014-04-23 04:50:20 +000082static const struct i40e_stats i40e_gstrings_misc_stats[] = {
Shannon Nelson418631d2014-04-23 04:50:07 +000083 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
Shannon Nelson41a9e552014-04-23 04:50:20 +000087 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
Shannon Nelson418631d2014-04-23 04:50:07 +000089 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
Anjali Singhai Jain2fc3d712015-08-27 11:42:29 -040090 I40E_VSI_STAT("tx_linearize", tx_linearize),
Anjali Singhai Jain164c9f52015-10-21 19:47:08 -040091 I40E_VSI_STAT("tx_force_wb", tx_force_wb),
Jesse Brandeburgc40918c2016-01-04 10:33:10 -080092 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed),
93 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
Shannon Nelson41a9e552014-04-23 04:50:20 +000094};
95
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000096/* These PF_STATs might look like duplicates of some NETDEV_STATs,
97 * but they are separate. This device supports Virtualization, and
98 * as such might have several netdevs supporting VMDq and FCoE going
99 * through a single port. The NETDEV_STATs are for individual netdevs
100 * seen at the top of the stack, and the PF_STATs are for the physical
101 * function at the bottom of the stack hosting those netdevs.
102 *
103 * The PF_STATs are appended to the netdev stats only when ethtool -S
104 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
105 */
Joe Perchesfe180a52016-09-26 20:17:01 -0700106static const struct i40e_stats i40e_gstrings_stats[] = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000107 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
108 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000109 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
110 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
111 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
112 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
113 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
114 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000115 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
116 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000117 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400118 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000119 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
120 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
121 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000122 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000123 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000124 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
125 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
126 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
127 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
128 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
129 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
130 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
131 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
132 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
133 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
134 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
135 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
136 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
137 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
138 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
139 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
140 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
141 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
142 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
143 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
144 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
145 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
146 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
147 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Mitch Williams1d0a4ad2015-12-23 12:05:48 -0800148 I40E_PF_STAT("arq_overflows", arq_overflows),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000149 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Jacob Keller2955fac2017-05-03 10:28:58 -0700150 I40E_PF_STAT("tx_hwtstamp_skipped", tx_hwtstamp_skipped),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400153 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400154 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000155 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400156 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000157
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000158 /* LPI stats */
159 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
160 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
161 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
162 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000163};
164
165#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000166 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
167 * 2 /* Tx and Rx together */ \
168 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000169#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
170#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000171#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000172#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000173 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000174 I40E_QUEUE_STATS_LEN((n)))
175#define I40E_PFC_STATS_LEN ( \
176 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
177 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
178 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
179 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
180 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
181 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400182#define I40E_VEB_TC_STATS_LEN ( \
183 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
184 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
185 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
186 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
187 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000188#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400189#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000190#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
191 I40E_PFC_STATS_LEN + \
192 I40E_VSI_STATS_LEN((n)))
193
194enum i40e_ethtool_test_id {
195 I40E_ETH_TEST_REG = 0,
196 I40E_ETH_TEST_EEPROM,
197 I40E_ETH_TEST_INTR,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000198 I40E_ETH_TEST_LINK,
199};
200
201static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
202 "Register test (offline)",
203 "Eeprom test (offline)",
204 "Interrupt test (offline)",
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000205 "Link test (on/offline)"
206};
207
208#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
209
Alexander Duyckaca955d2017-03-10 12:22:01 -0800210struct i40e_priv_flags {
211 char flag_string[ETH_GSTRING_LEN];
212 u64 flag;
213 bool read_only;
Greg Rose7e45ab42015-02-06 08:52:19 +0000214};
215
Alexander Duyckaca955d2017-03-10 12:22:01 -0800216#define I40E_PRIV_FLAG(_name, _flag, _read_only) { \
217 .flag_string = _name, \
218 .flag = _flag, \
219 .read_only = _read_only, \
220}
221
222static const struct i40e_priv_flags i40e_gstrings_priv_flags[] = {
223 /* NOTE: MFP setting cannot be changed */
224 I40E_PRIV_FLAG("MFP", I40E_FLAG_MFP_ENABLED, 1),
225 I40E_PRIV_FLAG("LinkPolling", I40E_FLAG_LINK_POLLING_ENABLED, 0),
226 I40E_PRIV_FLAG("flow-director-atr", I40E_FLAG_FD_ATR_ENABLED, 0),
227 I40E_PRIV_FLAG("veb-stats", I40E_FLAG_VEB_STATS_ENABLED, 0),
Jacob Keller6964e532017-06-12 15:38:36 -0700228 I40E_PRIV_FLAG("hw-atr-eviction", I40E_FLAG_HW_ATR_EVICT_ENABLED, 0),
Alexander Duyckc424d4a2017-03-14 10:15:26 -0700229 I40E_PRIV_FLAG("legacy-rx", I40E_FLAG_LEGACY_RX, 0),
Mitch Williams64615b52017-08-29 05:32:30 -0400230 I40E_PRIV_FLAG("disable-source-pruning",
231 I40E_FLAG_SOURCE_PRUNING_DISABLED, 0),
Alexander Duyckaca955d2017-03-10 12:22:01 -0800232};
233
234#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gstrings_priv_flags)
Greg Rose7e45ab42015-02-06 08:52:19 +0000235
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700236/* Private flags with a global effect, restricted to PF 0 */
Alexander Duyckaca955d2017-03-10 12:22:01 -0800237static const struct i40e_priv_flags i40e_gl_gstrings_priv_flags[] = {
238 I40E_PRIV_FLAG("vf-true-promisc-support",
239 I40E_FLAG_TRUE_PROMISC_SUPPORT, 0),
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700240};
241
Alexander Duyckaca955d2017-03-10 12:22:01 -0800242#define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_gstrings_priv_flags)
Jacob Kellerd182a5c2016-10-25 16:08:50 -0700243
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000244/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000245 * i40e_partition_setting_complaint - generic complaint for MFP restriction
246 * @pf: the PF struct
247 **/
248static void i40e_partition_setting_complaint(struct i40e_pf *pf)
249{
250 dev_info(&pf->pdev->dev,
251 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n");
252}
253
254/**
Catherine Sullivan06566e52016-05-03 15:13:14 -0700255 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes
256 * @phy_types: PHY types to convert
257 * @supported: pointer to the ethtool supported variable to fill in
258 * @advertising: pointer to the ethtool advertising variable to fill in
259 *
260 **/
261static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported,
262 u32 *advertising)
263{
Avinash Dayanand28537042016-06-20 09:10:33 -0700264 struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800265 u64 phy_types = pf->hw.phy.phy_types;
266
Catherine Sullivan06566e52016-05-03 15:13:14 -0700267 *supported = 0x0;
268 *advertising = 0x0;
269
270 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
271 *supported |= SUPPORTED_Autoneg |
272 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700273 *advertising |= ADVERTISED_Autoneg;
274 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
275 *advertising |= ADVERTISED_1000baseT_Full;
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400276 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700277 *supported |= SUPPORTED_100baseT_Full;
278 *advertising |= ADVERTISED_100baseT_Full;
279 }
280 }
281 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
282 phy_types & I40E_CAP_PHY_TYPE_XFI ||
283 phy_types & I40E_CAP_PHY_TYPE_SFI ||
284 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
285 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
286 *supported |= SUPPORTED_10000baseT_Full;
287 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
288 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
289 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
290 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
291 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
292 *supported |= SUPPORTED_Autoneg |
293 SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700294 *advertising |= ADVERTISED_Autoneg;
295 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
296 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700297 }
298 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
299 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
300 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
301 *supported |= SUPPORTED_40000baseCR4_Full;
302 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
303 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
304 *supported |= SUPPORTED_Autoneg |
305 SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700306 *advertising |= ADVERTISED_Autoneg;
307 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
308 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700309 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700310 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700311 *supported |= SUPPORTED_Autoneg |
312 SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700313 *advertising |= ADVERTISED_Autoneg;
314 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
315 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700316 }
317 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
318 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
319 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
320 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
321 *supported |= SUPPORTED_Autoneg |
322 SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700323 *advertising |= ADVERTISED_Autoneg;
324 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
325 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700326 }
327 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
328 *supported |= SUPPORTED_40000baseSR4_Full;
329 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
330 *supported |= SUPPORTED_40000baseLR4_Full;
331 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
332 *supported |= SUPPORTED_40000baseKR4_Full |
333 SUPPORTED_Autoneg;
334 *advertising |= ADVERTISED_40000baseKR4_Full |
335 ADVERTISED_Autoneg;
336 }
337 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
338 *supported |= SUPPORTED_20000baseKR2_Full |
339 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700340 *advertising |= ADVERTISED_Autoneg;
341 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
342 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700343 }
344 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400345 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800346 *supported |= SUPPORTED_10000baseKR_Full |
347 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700348 *advertising |= ADVERTISED_Autoneg;
349 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400350 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800351 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700352 }
353 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
354 *supported |= SUPPORTED_10000baseKX4_Full |
355 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700356 *advertising |= ADVERTISED_Autoneg;
357 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
358 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700359 }
360 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400361 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800362 *supported |= SUPPORTED_1000baseKX_Full |
363 SUPPORTED_Autoneg;
Avinash Dayanand28537042016-06-20 09:10:33 -0700364 *advertising |= ADVERTISED_Autoneg;
365 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400366 if (!(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER))
Harshitha Ramamurthy4ad9f4f2016-11-08 13:05:09 -0800367 *advertising |= ADVERTISED_1000baseKX_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700368 }
Carolyn Wyborny31232372016-11-21 13:03:48 -0800369 if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
370 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
371 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
372 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) {
373 *supported |= SUPPORTED_Autoneg;
374 *advertising |= ADVERTISED_Autoneg;
375 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700376}
377
378/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000379 * i40e_get_settings_link_up - Get the Link settings for when link is up
380 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700381 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000382 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700383 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000384 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000385static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700386 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400387 struct net_device *netdev,
388 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000389{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000390 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000391 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700392 u32 e_advertising = 0x0;
393 u32 e_supported = 0x0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100394 u32 supported, advertising;
395
396 ethtool_convert_link_mode_to_legacy_u32(&supported,
Alan Brady1c142e12017-10-05 14:53:31 -0700397 ks->link_modes.supported);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100398 ethtool_convert_link_mode_to_legacy_u32(&advertising,
Alan Brady1c142e12017-10-05 14:53:31 -0700399 ks->link_modes.advertising);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000400
Catherine Sullivane8278452015-02-06 08:52:08 +0000401 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000402 switch (hw_link_info->phy_type) {
403 case I40E_PHY_TYPE_40GBASE_CR4:
404 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100405 supported = SUPPORTED_Autoneg |
406 SUPPORTED_40000baseCR4_Full;
407 advertising = ADVERTISED_Autoneg |
408 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000409 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000410 case I40E_PHY_TYPE_XLAUI:
411 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000412 case I40E_PHY_TYPE_40GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100413 supported = SUPPORTED_40000baseCR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000414 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000415 case I40E_PHY_TYPE_40GBASE_SR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100416 supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000417 break;
418 case I40E_PHY_TYPE_40GBASE_LR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100419 supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000420 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000421 case I40E_PHY_TYPE_10GBASE_SR:
422 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000423 case I40E_PHY_TYPE_1000BASE_SX:
424 case I40E_PHY_TYPE_1000BASE_LX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100425 supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400426 if (hw_link_info->module_type[2] &
427 I40E_MODULE_TYPE_1000BASE_SX ||
428 hw_link_info->module_type[2] &
429 I40E_MODULE_TYPE_1000BASE_LX) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100430 supported |= SUPPORTED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400431 if (hw_link_info->requested_speeds &
432 I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100433 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400434 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000435 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100436 advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000437 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000438 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000439 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700440 case I40E_PHY_TYPE_100BASE_TX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100441 supported = SUPPORTED_Autoneg |
442 SUPPORTED_10000baseT_Full |
443 SUPPORTED_1000baseT_Full |
444 SUPPORTED_100baseT_Full;
445 advertising = ADVERTISED_Autoneg;
Catherine Sullivane8278452015-02-06 08:52:08 +0000446 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100447 advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000448 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100449 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700450 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100451 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400452 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400453 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100454 supported = SUPPORTED_Autoneg |
455 SUPPORTED_1000baseT_Full;
456 advertising = ADVERTISED_Autoneg |
457 ADVERTISED_1000baseT_Full;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400458 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000459 case I40E_PHY_TYPE_10GBASE_CR1_CU:
460 case I40E_PHY_TYPE_10GBASE_CR1:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100461 supported = SUPPORTED_Autoneg |
462 SUPPORTED_10000baseT_Full;
463 advertising = ADVERTISED_Autoneg |
464 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000465 break;
466 case I40E_PHY_TYPE_XAUI:
467 case I40E_PHY_TYPE_XFI:
468 case I40E_PHY_TYPE_SFI:
469 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000470 case I40E_PHY_TYPE_10GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100471 supported = SUPPORTED_10000baseT_Full;
472 advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000473 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000474 case I40E_PHY_TYPE_SGMII:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100475 supported = SUPPORTED_Autoneg |
476 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000477 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100478 advertising |= ADVERTISED_1000baseT_Full;
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400479 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100480 supported |= SUPPORTED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400481 if (hw_link_info->requested_speeds &
482 I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100483 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400484 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000485 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400486 case I40E_PHY_TYPE_40GBASE_KR4:
487 case I40E_PHY_TYPE_20GBASE_KR2:
488 case I40E_PHY_TYPE_10GBASE_KR:
489 case I40E_PHY_TYPE_10GBASE_KX4:
490 case I40E_PHY_TYPE_1000BASE_KX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100491 supported |= SUPPORTED_40000baseKR4_Full |
492 SUPPORTED_20000baseKR2_Full |
493 SUPPORTED_10000baseKR_Full |
494 SUPPORTED_10000baseKX4_Full |
495 SUPPORTED_1000baseKX_Full |
496 SUPPORTED_Autoneg;
497 advertising |= ADVERTISED_40000baseKR4_Full |
498 ADVERTISED_20000baseKR2_Full |
499 ADVERTISED_10000baseKR_Full |
500 ADVERTISED_10000baseKX4_Full |
501 ADVERTISED_1000baseKX_Full |
502 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400503 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800504 case I40E_PHY_TYPE_25GBASE_KR:
505 case I40E_PHY_TYPE_25GBASE_CR:
506 case I40E_PHY_TYPE_25GBASE_SR:
507 case I40E_PHY_TYPE_25GBASE_LR:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100508 supported = SUPPORTED_Autoneg;
509 advertising = ADVERTISED_Autoneg;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800510 /* TODO: add speeds when ethtool is ready to support*/
511 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000512 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000513 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000514 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
515 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000516 }
517
Catherine Sullivan06566e52016-05-03 15:13:14 -0700518 /* Now that we've worked out everything that could be supported by the
519 * current PHY type, get what is supported by the NVM and them to
520 * get what is truly supported
521 */
522 i40e_phy_type_to_ethtool(pf, &e_supported,
523 &e_advertising);
524
Philippe Reynesa7f90942017-02-04 22:05:06 +0100525 supported = supported & e_supported;
526 advertising = advertising & e_advertising;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700527
Catherine Sullivane8278452015-02-06 08:52:08 +0000528 /* Set speed and duplex */
529 switch (link_speed) {
530 case I40E_LINK_SPEED_40GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700531 ks->base.speed = SPEED_40000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000532 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800533 case I40E_LINK_SPEED_25GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700534 ks->base.speed = SPEED_25000;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800535 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700536 case I40E_LINK_SPEED_20GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700537 ks->base.speed = SPEED_20000;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700538 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000539 case I40E_LINK_SPEED_10GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700540 ks->base.speed = SPEED_10000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000541 break;
542 case I40E_LINK_SPEED_1GB:
Alan Brady1c142e12017-10-05 14:53:31 -0700543 ks->base.speed = SPEED_1000;
Catherine Sullivane8278452015-02-06 08:52:08 +0000544 break;
545 case I40E_LINK_SPEED_100MB:
Alan Brady1c142e12017-10-05 14:53:31 -0700546 ks->base.speed = SPEED_100;
Catherine Sullivane8278452015-02-06 08:52:08 +0000547 break;
548 default:
549 break;
550 }
Alan Brady1c142e12017-10-05 14:53:31 -0700551 ks->base.duplex = DUPLEX_FULL;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100552
Alan Brady1c142e12017-10-05 14:53:31 -0700553 ethtool_convert_legacy_u32_to_link_mode(ks->link_modes.supported,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100554 supported);
Alan Brady1c142e12017-10-05 14:53:31 -0700555 ethtool_convert_legacy_u32_to_link_mode(ks->link_modes.advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100556 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000557}
558
559/**
560 * i40e_get_settings_link_down - Get the Link settings for when link is down
561 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700562 * @ks: ethtool ksettings to fill in
563 * @pf: pointer to physical function struct
Catherine Sullivane8278452015-02-06 08:52:08 +0000564 *
565 * Reports link settings that can be determined when link is down
566 **/
567static void i40e_get_settings_link_down(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700568 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400569 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000570{
Philippe Reynesa7f90942017-02-04 22:05:06 +0100571 u32 supported, advertising;
572
Catherine Sullivane8278452015-02-06 08:52:08 +0000573 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400574 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000575 */
Philippe Reynesa7f90942017-02-04 22:05:06 +0100576 i40e_phy_type_to_ethtool(pf, &supported, &advertising);
577
Alan Brady1c142e12017-10-05 14:53:31 -0700578 ethtool_convert_legacy_u32_to_link_mode(ks->link_modes.supported,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100579 supported);
Alan Brady1c142e12017-10-05 14:53:31 -0700580 ethtool_convert_legacy_u32_to_link_mode(ks->link_modes.advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100581 advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000582
583 /* With no link speed and duplex are unknown */
Alan Brady1c142e12017-10-05 14:53:31 -0700584 ks->base.speed = SPEED_UNKNOWN;
585 ks->base.duplex = DUPLEX_UNKNOWN;
Catherine Sullivane8278452015-02-06 08:52:08 +0000586}
587
588/**
Alan Brady1c142e12017-10-05 14:53:31 -0700589 * i40e_get_link_ksettings - Get Link Speed and Duplex settings
Catherine Sullivane8278452015-02-06 08:52:08 +0000590 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700591 * @ks: ethtool ksettings
Catherine Sullivane8278452015-02-06 08:52:08 +0000592 *
593 * Reports speed/duplex settings based on media_type
594 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100595static int i40e_get_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700596 struct ethtool_link_ksettings *ks)
Catherine Sullivane8278452015-02-06 08:52:08 +0000597{
598 struct i40e_netdev_priv *np = netdev_priv(netdev);
599 struct i40e_pf *pf = np->vsi->back;
600 struct i40e_hw *hw = &pf->hw;
601 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
602 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100603 u32 advertising;
Catherine Sullivane8278452015-02-06 08:52:08 +0000604
605 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700606 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000607 else
Alan Brady1c142e12017-10-05 14:53:31 -0700608 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000609
610 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000611 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700612 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
613 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000614
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000615 switch (hw->phy.media_type) {
616 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Brady1c142e12017-10-05 14:53:31 -0700617 ethtool_link_ksettings_add_link_mode(ks, supported,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100618 Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700619 ethtool_link_ksettings_add_link_mode(ks, supported,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100620 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700621 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100622 Autoneg);
Alan Brady1c142e12017-10-05 14:53:31 -0700623 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100624 Backplane);
Alan Brady1c142e12017-10-05 14:53:31 -0700625 ks->base.port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000626 break;
627 case I40E_MEDIA_TYPE_BASET:
Alan Brady1c142e12017-10-05 14:53:31 -0700628 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
629 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
630 ks->base.port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000631 break;
632 case I40E_MEDIA_TYPE_DA:
633 case I40E_MEDIA_TYPE_CX4:
Alan Brady1c142e12017-10-05 14:53:31 -0700634 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
635 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
636 ks->base.port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000637 break;
638 case I40E_MEDIA_TYPE_FIBER:
Alan Brady1c142e12017-10-05 14:53:31 -0700639 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
640 ks->base.port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000641 break;
642 case I40E_MEDIA_TYPE_UNKNOWN:
643 default:
Alan Brady1c142e12017-10-05 14:53:31 -0700644 ks->base.port = PORT_OTHER;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000645 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000646 }
647
Catherine Sullivane8278452015-02-06 08:52:08 +0000648 /* Set flow control settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700649 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000650
Catherine Sullivane8278452015-02-06 08:52:08 +0000651 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000652 case I40E_FC_FULL:
Alan Brady1c142e12017-10-05 14:53:31 -0700653 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100654 Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000655 break;
656 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700657 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100658 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000659 break;
660 case I40E_FC_RX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700661 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100662 Pause);
Alan Brady1c142e12017-10-05 14:53:31 -0700663 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100664 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000665 break;
666 default:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100667 ethtool_convert_link_mode_to_legacy_u32(
Alan Brady1c142e12017-10-05 14:53:31 -0700668 &advertising, ks->link_modes.advertising);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100669
670 advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause);
671
672 ethtool_convert_legacy_u32_to_link_mode(
Alan Brady1c142e12017-10-05 14:53:31 -0700673 ks->link_modes.advertising, advertising);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000674 break;
675 }
676
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000677 return 0;
678}
679
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000680/**
Alan Brady1c142e12017-10-05 14:53:31 -0700681 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000682 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700683 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000684 *
685 * Set speed/duplex per media_types advertised/forced
686 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100687static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700688 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000689{
690 struct i40e_netdev_priv *np = netdev_priv(netdev);
691 struct i40e_aq_get_phy_abilities_resp abilities;
692 struct i40e_aq_set_phy_config config;
693 struct i40e_pf *pf = np->vsi->back;
694 struct i40e_vsi *vsi = np->vsi;
695 struct i40e_hw *hw = &pf->hw;
Alan Brady1c142e12017-10-05 14:53:31 -0700696 struct ethtool_link_ksettings safe_ks;
697 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000698 i40e_status status = 0;
699 bool change = false;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400700 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000701 int err = 0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100702 u32 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000703 u32 advertise;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100704 u32 tmp;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000705
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000706 /* Changing port settings is not supported if this isn't the
707 * port's controlling PF
708 */
709 if (hw->partition_id != 1) {
710 i40e_partition_setting_complaint(pf);
711 return -EOPNOTSUPP;
712 }
713
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000714 if (vsi != pf->vsi[pf->lan_vsi])
715 return -EOPNOTSUPP;
716
717 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
718 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000719 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700720 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000721 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000722 return -EOPNOTSUPP;
723
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400724 if (hw->device_id == I40E_DEV_ID_KX_B ||
725 hw->device_id == I40E_DEV_ID_KX_C ||
726 hw->device_id == I40E_DEV_ID_20G_KR2 ||
727 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
728 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
729 return -EOPNOTSUPP;
730 }
731
Alan Brady1c142e12017-10-05 14:53:31 -0700732 /* copy the ksettings to copy_ks to avoid modifying the origin */
733 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000734
Philippe Reynesa7f90942017-02-04 22:05:06 +0100735 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700736 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
737 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100738
Alan Brady1c142e12017-10-05 14:53:31 -0700739 /* save autoneg and speed out of ksettings */
740 autoneg = ks->base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100741 ethtool_convert_link_mode_to_legacy_u32(&advertise,
Alan Brady1c142e12017-10-05 14:53:31 -0700742 ks->link_modes.advertising);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000743
744 /* set autoneg and speed back to what they currently are */
Alan Brady1c142e12017-10-05 14:53:31 -0700745 copy_ks.base.autoneg = safe_ks.base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100746 ethtool_convert_link_mode_to_legacy_u32(
Alan Brady1c142e12017-10-05 14:53:31 -0700747 &tmp, safe_ks.link_modes.advertising);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100748 ethtool_convert_legacy_u32_to_link_mode(
Alan Brady1c142e12017-10-05 14:53:31 -0700749 copy_ks.link_modes.advertising, tmp);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000750
Alan Brady1c142e12017-10-05 14:53:31 -0700751 copy_ks.base.cmd = safe_ks.base.cmd;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100752
Alan Brady1c142e12017-10-05 14:53:31 -0700753 /* If copy_ks and safe_ks are not the same now, then they are
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000754 * trying to set something that we do not support
755 */
Alan Brady1c142e12017-10-05 14:53:31 -0700756 if (memcmp(&copy_ks, &safe_ks, sizeof(struct ethtool_link_ksettings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000757 return -EOPNOTSUPP;
758
Jacob Keller0da36b92017-04-19 09:25:55 -0400759 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400760 timeout--;
761 if (!timeout)
762 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000763 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400764 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000765
766 /* Get the current phy config */
767 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
768 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400769 if (status) {
770 err = -EAGAIN;
771 goto done;
772 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000773
Catherine Sullivan124ed152014-07-12 07:28:12 +0000774 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000775 * set below
776 */
777 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000778 config.abilities = abilities.abilities;
779
780 /* Check autoneg */
781 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000782 /* If autoneg was not already enabled */
783 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400784 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700785 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
786 supported,
787 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400788 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400789 err = -EINVAL;
790 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400791 }
792 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000793 config.abilities = abilities.abilities |
794 I40E_AQ_PHY_ENABLE_AN;
795 change = true;
796 }
797 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000798 /* If autoneg is currently enabled */
799 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400800 /* If autoneg is supported 10GBASE_T is the only PHY
801 * that can disable it, so otherwise return error
802 */
Alan Brady1c142e12017-10-05 14:53:31 -0700803 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
804 supported,
805 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400806 hw->phy.link_info.phy_type !=
807 I40E_PHY_TYPE_10GBASE_T) {
808 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400809 err = -EINVAL;
810 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400811 }
812 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000813 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000814 ~I40E_AQ_PHY_ENABLE_AN;
815 change = true;
816 }
817 }
818
Philippe Reynesa7f90942017-02-04 22:05:06 +0100819 ethtool_convert_link_mode_to_legacy_u32(&tmp,
Alan Brady1c142e12017-10-05 14:53:31 -0700820 safe_ks.link_modes.supported);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400821 if (advertise & ~tmp) {
822 err = -EINVAL;
823 goto done;
824 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000825
826 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000827 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000828 if (advertise & ADVERTISED_1000baseT_Full ||
829 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000830 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000831 if (advertise & ADVERTISED_10000baseT_Full ||
832 advertise & ADVERTISED_10000baseKX4_Full ||
833 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000834 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700835 if (advertise & ADVERTISED_20000baseKR2_Full)
836 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000837 if (advertise & ADVERTISED_40000baseKR4_Full ||
838 advertise & ADVERTISED_40000baseCR4_Full ||
839 advertise & ADVERTISED_40000baseSR4_Full ||
840 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000841 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000842
Catherine Sullivan0002e112015-08-26 15:14:16 -0400843 /* If speed didn't get set, set it to what it currently is.
844 * This is needed because if advertise is 0 (as it is when autoneg
845 * is disabled) then speed won't get set.
846 */
847 if (!config.link_speed)
848 config.link_speed = abilities.link_speed;
849
Catherine Sullivan124ed152014-07-12 07:28:12 +0000850 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000851 /* copy over the rest of the abilities */
852 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800853 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000854 config.eee_capability = abilities.eee_capability;
855 config.eeer = abilities.eeer_val;
856 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800857 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
858 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000859
Catherine Sullivane8278452015-02-06 08:52:08 +0000860 /* save the requested speeds */
861 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000862 /* set link and auto negotiation so changes take effect */
863 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
864 /* If link is up put link down */
865 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
866 /* Tell the OS link is going down, the link will go
867 * back up when fw says it is ready asynchronously
868 */
Matt Jaredc156f852015-08-27 11:42:39 -0400869 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000870 netif_carrier_off(netdev);
871 netif_tx_stop_all_queues(netdev);
872 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000873
874 /* make the aq call */
875 status = i40e_aq_set_phy_config(hw, &config, NULL);
876 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400877 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
878 i40e_stat_str(hw, status),
879 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400880 err = -EAGAIN;
881 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000882 }
883
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400884 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000885 if (status)
Catherine Sullivan52e96892015-09-28 14:16:59 -0400886 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n",
887 i40e_stat_str(hw, status),
888 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000889
890 } else {
891 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
892 }
893
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400894done:
Jacob Keller0da36b92017-04-19 09:25:55 -0400895 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400896
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000897 return err;
898}
899
Jesse Brandeburga6599722014-06-04 08:45:25 +0000900static int i40e_nway_reset(struct net_device *netdev)
901{
902 /* restart autonegotiation */
903 struct i40e_netdev_priv *np = netdev_priv(netdev);
904 struct i40e_pf *pf = np->vsi->back;
905 struct i40e_hw *hw = &pf->hw;
906 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
907 i40e_status ret = 0;
908
909 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
910 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400911 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
912 i40e_stat_str(hw, ret),
913 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000914 return -EIO;
915 }
916
917 return 0;
918}
919
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000920/**
921 * i40e_get_pauseparam - Get Flow Control status
922 * Return tx/rx-pause status
923 **/
924static void i40e_get_pauseparam(struct net_device *netdev,
925 struct ethtool_pauseparam *pause)
926{
927 struct i40e_netdev_priv *np = netdev_priv(netdev);
928 struct i40e_pf *pf = np->vsi->back;
929 struct i40e_hw *hw = &pf->hw;
930 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000931 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000932
933 pause->autoneg =
934 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
935 AUTONEG_ENABLE : AUTONEG_DISABLE);
936
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000937 /* PFC enabled so report LFC as off */
938 if (dcbx_cfg->pfc.pfcenable) {
939 pause->rx_pause = 0;
940 pause->tx_pause = 0;
941 return;
942 }
943
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000944 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000945 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000946 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000947 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000948 } else if (hw->fc.current_mode == I40E_FC_FULL) {
949 pause->rx_pause = 1;
950 pause->tx_pause = 1;
951 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000952}
953
Catherine Sullivan2becc352014-06-04 08:45:27 +0000954/**
955 * i40e_set_pauseparam - Set Flow Control parameter
956 * @netdev: network interface device structure
957 * @pause: return tx/rx flow control status
958 **/
959static int i40e_set_pauseparam(struct net_device *netdev,
960 struct ethtool_pauseparam *pause)
961{
962 struct i40e_netdev_priv *np = netdev_priv(netdev);
963 struct i40e_pf *pf = np->vsi->back;
964 struct i40e_vsi *vsi = np->vsi;
965 struct i40e_hw *hw = &pf->hw;
966 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000967 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000968 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
969 i40e_status status;
970 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000971 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000972
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000973 /* Changing the port's flow control is not supported if this isn't the
974 * port's controlling PF
975 */
976 if (hw->partition_id != 1) {
977 i40e_partition_setting_complaint(pf);
978 return -EOPNOTSUPP;
979 }
980
Catherine Sullivan2becc352014-06-04 08:45:27 +0000981 if (vsi != pf->vsi[pf->lan_vsi])
982 return -EOPNOTSUPP;
983
984 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
985 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
986 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
987 return -EOPNOTSUPP;
988 }
989
990 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -0400991 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +0000992 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
993 /* Send message that it might not necessarily work*/
994 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
995 }
996
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000997 if (dcbx_cfg->pfc.pfcenable) {
998 netdev_info(netdev,
999 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +00001000 return -EOPNOTSUPP;
1001 }
1002
1003 if (pause->rx_pause && pause->tx_pause)
1004 hw->fc.requested_mode = I40E_FC_FULL;
1005 else if (pause->rx_pause && !pause->tx_pause)
1006 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
1007 else if (!pause->rx_pause && pause->tx_pause)
1008 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1009 else if (!pause->rx_pause && !pause->tx_pause)
1010 hw->fc.requested_mode = I40E_FC_NONE;
1011 else
1012 return -EINVAL;
1013
Catherine Sullivan94128512014-07-12 07:28:16 +00001014 /* Tell the OS link is going down, the link will go back up when fw
1015 * says it is ready asynchronously
1016 */
Matt Jaredc156f852015-08-27 11:42:39 -04001017 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001018 netif_carrier_off(netdev);
1019 netif_tx_stop_all_queues(netdev);
1020
Catherine Sullivan2becc352014-06-04 08:45:27 +00001021 /* Set the fc mode and only restart an if link is up*/
1022 status = i40e_set_fc(hw, &aq_failures, link_up);
1023
1024 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001025 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1026 i40e_stat_str(hw, status),
1027 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001028 err = -EAGAIN;
1029 }
1030 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001031 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1032 i40e_stat_str(hw, status),
1033 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001034 err = -EAGAIN;
1035 }
1036 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001037 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1038 i40e_stat_str(hw, status),
1039 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001040 err = -EAGAIN;
1041 }
1042
Jacob Keller0da36b92017-04-19 09:25:55 -04001043 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001044 /* Give it a little more time to try to come back */
1045 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001046 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001047 return i40e_nway_reset(netdev);
1048 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001049
1050 return err;
1051}
1052
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001053static u32 i40e_get_msglevel(struct net_device *netdev)
1054{
1055 struct i40e_netdev_priv *np = netdev_priv(netdev);
1056 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001057 u32 debug_mask = pf->hw.debug_mask;
1058
1059 if (debug_mask)
1060 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001061
1062 return pf->msg_enable;
1063}
1064
1065static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1066{
1067 struct i40e_netdev_priv *np = netdev_priv(netdev);
1068 struct i40e_pf *pf = np->vsi->back;
1069
1070 if (I40E_DEBUG_USER & data)
1071 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001072 else
1073 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001074}
1075
1076static int i40e_get_regs_len(struct net_device *netdev)
1077{
1078 int reg_count = 0;
1079 int i;
1080
1081 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1082 reg_count += i40e_reg_list[i].elements;
1083
1084 return reg_count * sizeof(u32);
1085}
1086
1087static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1088 void *p)
1089{
1090 struct i40e_netdev_priv *np = netdev_priv(netdev);
1091 struct i40e_pf *pf = np->vsi->back;
1092 struct i40e_hw *hw = &pf->hw;
1093 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001094 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001095 u32 reg;
1096
1097 /* Tell ethtool which driver-version-specific regs output we have.
1098 *
1099 * At some point, if we have ethtool doing special formatting of
1100 * this data, it will rely on this version number to know how to
1101 * interpret things. Hence, this needs to be updated if/when the
1102 * diags register table is changed.
1103 */
1104 regs->version = 1;
1105
1106 /* loop through the diags reg table for what to print */
1107 ri = 0;
1108 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1109 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1110 reg = i40e_reg_list[i].offset
1111 + (j * i40e_reg_list[i].stride);
1112 reg_buf[ri++] = rd32(hw, reg);
1113 }
1114 }
1115
1116}
1117
1118static int i40e_get_eeprom(struct net_device *netdev,
1119 struct ethtool_eeprom *eeprom, u8 *bytes)
1120{
1121 struct i40e_netdev_priv *np = netdev_priv(netdev);
1122 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001123 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001124 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001125 u8 *eeprom_buff;
1126 u16 i, sectors;
1127 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001128 u32 magic;
1129
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001130#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001131 if (eeprom->len == 0)
1132 return -EINVAL;
1133
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001134 /* check for NVMUpdate access method */
1135 magic = hw->vendor_id | (hw->device_id << 16);
1136 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001137 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1138 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001139
1140 /* make sure it is the right magic for NVMUpdate */
1141 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001142 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001143 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1144 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001145 errno = -EBUSY;
1146 else
1147 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001148
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001149 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001150 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001151 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1152 ret_val, hw->aq.asq_last_status, errno,
1153 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1154 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001155
1156 return errno;
1157 }
1158
1159 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001160 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1161
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001162 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001163 if (!eeprom_buff)
1164 return -ENOMEM;
1165
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001166 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1167 if (ret_val) {
1168 dev_info(&pf->pdev->dev,
1169 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1170 ret_val, hw->aq.asq_last_status);
1171 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001172 }
1173
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001174 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1175 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1176 len = I40E_NVM_SECTOR_SIZE;
1177 last = false;
1178 for (i = 0; i < sectors; i++) {
1179 if (i == (sectors - 1)) {
1180 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1181 last = true;
1182 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001183 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1184 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001185 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001186 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001187 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001188 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001189 "read NVM failed, invalid offset 0x%x\n",
1190 offset);
1191 break;
1192 } else if (ret_val &&
1193 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1194 dev_info(&pf->pdev->dev,
1195 "read NVM failed, access, offset 0x%x\n",
1196 offset);
1197 break;
1198 } else if (ret_val) {
1199 dev_info(&pf->pdev->dev,
1200 "read NVM failed offset %d err=%d status=0x%x\n",
1201 offset, ret_val, hw->aq.asq_last_status);
1202 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001203 }
1204 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001205
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001206 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001207 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001208free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001209 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001210 return ret_val;
1211}
1212
1213static int i40e_get_eeprom_len(struct net_device *netdev)
1214{
1215 struct i40e_netdev_priv *np = netdev_priv(netdev);
1216 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001217 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001218
Lihong Yangc271dd62017-01-30 12:29:32 -08001219#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1220 if (hw->mac.type == I40E_MAC_X722) {
1221 val = X722_EEPROM_SCOPE_LIMIT + 1;
1222 return val;
1223 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001224 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1225 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1226 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1227 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001228 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001229 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001230}
1231
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001232static int i40e_set_eeprom(struct net_device *netdev,
1233 struct ethtool_eeprom *eeprom, u8 *bytes)
1234{
1235 struct i40e_netdev_priv *np = netdev_priv(netdev);
1236 struct i40e_hw *hw = &np->vsi->back->hw;
1237 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001238 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001239 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001240 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001241 u32 magic;
1242
1243 /* normal ethtool set_eeprom is not supported */
1244 magic = hw->vendor_id | (hw->device_id << 16);
1245 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001246 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001247 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001248 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1249 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001250 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1251 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001252 errno = -EBUSY;
1253 else
1254 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001255
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001256 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001257 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001258 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1259 ret_val, hw->aq.asq_last_status, errno,
1260 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1261 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001262
1263 return errno;
1264}
1265
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001266static void i40e_get_drvinfo(struct net_device *netdev,
1267 struct ethtool_drvinfo *drvinfo)
1268{
1269 struct i40e_netdev_priv *np = netdev_priv(netdev);
1270 struct i40e_vsi *vsi = np->vsi;
1271 struct i40e_pf *pf = vsi->back;
1272
1273 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1274 strlcpy(drvinfo->version, i40e_driver_version_str,
1275 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001276 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001277 sizeof(drvinfo->fw_version));
1278 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1279 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001280 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001281 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001282 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001283}
1284
1285static void i40e_get_ringparam(struct net_device *netdev,
1286 struct ethtool_ringparam *ring)
1287{
1288 struct i40e_netdev_priv *np = netdev_priv(netdev);
1289 struct i40e_pf *pf = np->vsi->back;
1290 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1291
1292 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1293 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1294 ring->rx_mini_max_pending = 0;
1295 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001296 ring->rx_pending = vsi->rx_rings[0]->count;
1297 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001298 ring->rx_mini_pending = 0;
1299 ring->rx_jumbo_pending = 0;
1300}
1301
Björn Töpel74608d12017-05-24 07:55:35 +02001302static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1303{
1304 if (i40e_enabled_xdp_vsi(vsi)) {
1305 return index < vsi->num_queue_pairs ||
1306 (index >= vsi->alloc_queue_pairs &&
1307 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1308 }
1309
1310 return index < vsi->num_queue_pairs;
1311}
1312
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001313static int i40e_set_ringparam(struct net_device *netdev,
1314 struct ethtool_ringparam *ring)
1315{
1316 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1317 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001318 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001319 struct i40e_vsi *vsi = np->vsi;
1320 struct i40e_pf *pf = vsi->back;
1321 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001322 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001323 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001324 int i, err = 0;
1325
1326 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1327 return -EINVAL;
1328
Shannon Nelson1fa18372013-11-20 10:03:08 +00001329 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1330 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1331 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1332 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1333 netdev_info(netdev,
1334 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1335 ring->tx_pending, ring->rx_pending,
1336 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1337 return -EINVAL;
1338 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001339
Shannon Nelson1fa18372013-11-20 10:03:08 +00001340 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1341 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001342
1343 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001344 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1345 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001346 return 0;
1347
Jacob Keller0da36b92017-04-19 09:25:55 -04001348 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001349 timeout--;
1350 if (!timeout)
1351 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001352 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001353 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001354
1355 if (!netif_running(vsi->netdev)) {
1356 /* simple case - set for the next time the netdev is started */
1357 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001358 vsi->tx_rings[i]->count = new_tx_count;
1359 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001360 if (i40e_enabled_xdp_vsi(vsi))
1361 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001362 }
1363 goto done;
1364 }
1365
1366 /* We can't just free everything and then setup again,
1367 * because the ISRs in MSI-X mode get passed pointers
1368 * to the Tx and Rx ring structs.
1369 */
1370
Björn Töpel74608d12017-05-24 07:55:35 +02001371 /* alloc updated Tx and XDP Tx resources */
1372 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1373 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001374 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001375 netdev_info(netdev,
1376 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001377 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001378 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001379 sizeof(struct i40e_ring), GFP_KERNEL);
1380 if (!tx_rings) {
1381 err = -ENOMEM;
1382 goto done;
1383 }
1384
Björn Töpel74608d12017-05-24 07:55:35 +02001385 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1386 if (!i40e_active_tx_ring_index(vsi, i))
1387 continue;
1388
Alexander Duyck9f65e152013-09-28 06:00:58 +00001389 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001390 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001391 /* the desc and bi pointers will be reallocated in the
1392 * setup call
1393 */
1394 tx_rings[i].desc = NULL;
1395 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001396 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1397 if (err) {
1398 while (i) {
1399 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001400 if (!i40e_active_tx_ring_index(vsi, i))
1401 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001402 i40e_free_tx_resources(&tx_rings[i]);
1403 }
1404 kfree(tx_rings);
1405 tx_rings = NULL;
1406
1407 goto done;
1408 }
1409 }
1410 }
1411
1412 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001413 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001414 netdev_info(netdev,
1415 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001416 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001417 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1418 sizeof(struct i40e_ring), GFP_KERNEL);
1419 if (!rx_rings) {
1420 err = -ENOMEM;
1421 goto free_tx;
1422 }
1423
1424 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001425 struct i40e_ring *ring;
1426 u16 unused;
1427
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001428 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001429 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001430 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001431 /* the desc and bi pointers will be reallocated in the
1432 * setup call
1433 */
1434 rx_rings[i].desc = NULL;
1435 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001436 /* this is to allow wr32 to have something to write to
1437 * during early allocation of Rx buffers
1438 */
1439 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001440 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001441 if (err)
1442 goto rx_unwind;
1443
1444 /* now allocate the Rx buffers to make sure the OS
1445 * has enough memory, any failure here means abort
1446 */
1447 ring = &rx_rings[i];
1448 unused = I40E_DESC_UNUSED(ring);
1449 err = i40e_alloc_rx_buffers(ring, unused);
1450rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001451 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001452 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001453 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001454 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001455 kfree(rx_rings);
1456 rx_rings = NULL;
1457
1458 goto free_tx;
1459 }
1460 }
1461 }
1462
1463 /* Bring interface down, copy in the new ring info,
1464 * then restore the interface
1465 */
1466 i40e_down(vsi);
1467
1468 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001469 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1470 if (i40e_active_tx_ring_index(vsi, i)) {
1471 i40e_free_tx_resources(vsi->tx_rings[i]);
1472 *vsi->tx_rings[i] = tx_rings[i];
1473 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001474 }
1475 kfree(tx_rings);
1476 tx_rings = NULL;
1477 }
1478
1479 if (rx_rings) {
1480 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001481 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001482 /* get the real tail offset */
1483 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1484 /* this is to fake out the allocation routine
1485 * into thinking it has to realloc everything
1486 * but the recycling logic will let us re-use
1487 * the buffers allocated above
1488 */
1489 rx_rings[i].next_to_use = 0;
1490 rx_rings[i].next_to_clean = 0;
1491 rx_rings[i].next_to_alloc = 0;
1492 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001493 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001494 }
1495 kfree(rx_rings);
1496 rx_rings = NULL;
1497 }
1498
1499 i40e_up(vsi);
1500
1501free_tx:
1502 /* error cleanup if the Rx allocations failed after getting Tx */
1503 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001504 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1505 if (i40e_active_tx_ring_index(vsi, i))
1506 i40e_free_tx_resources(vsi->tx_rings[i]);
1507 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001508 kfree(tx_rings);
1509 tx_rings = NULL;
1510 }
1511
1512done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001513 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001514
1515 return err;
1516}
1517
1518static int i40e_get_sset_count(struct net_device *netdev, int sset)
1519{
1520 struct i40e_netdev_priv *np = netdev_priv(netdev);
1521 struct i40e_vsi *vsi = np->vsi;
1522 struct i40e_pf *pf = vsi->back;
1523
1524 switch (sset) {
1525 case ETH_SS_TEST:
1526 return I40E_TEST_LEN;
1527 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001528 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001529 int len = I40E_PF_STATS_LEN(netdev);
1530
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001531 if ((pf->lan_veb != I40E_NO_VEB) &&
1532 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001533 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001534 return len;
1535 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001536 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001537 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001538 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001539 return I40E_PRIV_FLAGS_STR_LEN +
1540 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001541 default:
1542 return -EOPNOTSUPP;
1543 }
1544}
1545
1546static void i40e_get_ethtool_stats(struct net_device *netdev,
1547 struct ethtool_stats *stats, u64 *data)
1548{
1549 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001550 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001551 struct i40e_vsi *vsi = np->vsi;
1552 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001553 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554 int i = 0;
1555 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001556 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001557 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001558
1559 i40e_update_stats(vsi);
1560
1561 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1562 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1563 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1564 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1565 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001566 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1567 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1568 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1569 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1570 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001571 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001572 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001573 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001574
1575 if (!tx_ring)
1576 continue;
1577
1578 /* process Tx ring statistics */
1579 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001580 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001581 data[i] = tx_ring->stats.packets;
1582 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001583 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001584 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001585
1586 /* Rx ring is the 2nd half of the queue pair */
1587 rx_ring = &tx_ring[1];
1588 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001589 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001590 data[i] = rx_ring->stats.packets;
1591 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001592 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001593 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001595 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001596 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001597 return;
1598
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001599 if ((pf->lan_veb != I40E_NO_VEB) &&
1600 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001601 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001602
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001603 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1604 p = (char *)veb;
1605 p += i40e_gstrings_veb_stats[j].stat_offset;
1606 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1607 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001608 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001609 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1610 data[i++] = veb->tc_stats.tc_tx_packets[j];
1611 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1612 data[i++] = veb->tc_stats.tc_rx_packets[j];
1613 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1614 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001615 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001616 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1617 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1618 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1619 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1620 }
1621 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1622 data[i++] = pf->stats.priority_xon_tx[j];
1623 data[i++] = pf->stats.priority_xoff_tx[j];
1624 }
1625 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1626 data[i++] = pf->stats.priority_xon_rx[j];
1627 data[i++] = pf->stats.priority_xoff_rx[j];
1628 }
1629 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1630 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001631}
1632
1633static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1634 u8 *data)
1635{
1636 struct i40e_netdev_priv *np = netdev_priv(netdev);
1637 struct i40e_vsi *vsi = np->vsi;
1638 struct i40e_pf *pf = vsi->back;
1639 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001640 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001641
1642 switch (stringset) {
1643 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001644 memcpy(data, i40e_gstrings_test,
1645 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001646 break;
1647 case ETH_SS_STATS:
1648 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1649 snprintf(p, ETH_GSTRING_LEN, "%s",
1650 i40e_gstrings_net_stats[i].stat_string);
1651 p += ETH_GSTRING_LEN;
1652 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001653 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1654 snprintf(p, ETH_GSTRING_LEN, "%s",
1655 i40e_gstrings_misc_stats[i].stat_string);
1656 p += ETH_GSTRING_LEN;
1657 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001659 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001660 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001661 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001662 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001663 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001664 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001665 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001666 p += ETH_GSTRING_LEN;
1667 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001668 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001669 return;
1670
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001671 if ((pf->lan_veb != I40E_NO_VEB) &&
1672 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001673 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1674 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1675 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001676 p += ETH_GSTRING_LEN;
1677 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001678 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1679 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001680 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001681 p += ETH_GSTRING_LEN;
1682 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001683 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001684 p += ETH_GSTRING_LEN;
1685 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001686 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001687 p += ETH_GSTRING_LEN;
1688 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001689 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001690 p += ETH_GSTRING_LEN;
1691 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001692 }
1693 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1694 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1695 i40e_gstrings_stats[i].stat_string);
1696 p += ETH_GSTRING_LEN;
1697 }
1698 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1699 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001700 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001701 p += ETH_GSTRING_LEN;
1702 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001703 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001704 p += ETH_GSTRING_LEN;
1705 }
1706 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1707 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001708 "port.rx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001709 p += ETH_GSTRING_LEN;
1710 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001711 "port.rx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001712 p += ETH_GSTRING_LEN;
1713 }
1714 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1715 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001716 "port.rx_priority_%d_xon_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001717 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001718 }
1719 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1720 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001721 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001722 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1723 snprintf(p, ETH_GSTRING_LEN, "%s",
1724 i40e_gstrings_priv_flags[i].flag_string);
1725 p += ETH_GSTRING_LEN;
1726 }
1727 if (pf->hw.pf_id != 0)
1728 break;
1729 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1730 snprintf(p, ETH_GSTRING_LEN, "%s",
1731 i40e_gl_gstrings_priv_flags[i].flag_string);
1732 p += ETH_GSTRING_LEN;
1733 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001734 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001735 default:
1736 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001737 }
1738}
1739
1740static int i40e_get_ts_info(struct net_device *dev,
1741 struct ethtool_ts_info *info)
1742{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001743 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1744
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001745 /* only report HW timestamping if PTP is enabled */
1746 if (!(pf->flags & I40E_FLAG_PTP))
1747 return ethtool_op_get_ts_info(dev, info);
1748
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001749 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1750 SOF_TIMESTAMPING_RX_SOFTWARE |
1751 SOF_TIMESTAMPING_SOFTWARE |
1752 SOF_TIMESTAMPING_TX_HARDWARE |
1753 SOF_TIMESTAMPING_RX_HARDWARE |
1754 SOF_TIMESTAMPING_RAW_HARDWARE;
1755
1756 if (pf->ptp_clock)
1757 info->phc_index = ptp_clock_index(pf->ptp_clock);
1758 else
1759 info->phc_index = -1;
1760
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001761 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001762
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001763 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001764 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1765 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1766 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1767
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001768 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001769 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1770 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1771 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1772 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1773 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1774 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1775 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1776 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001777
1778 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001779}
1780
Shannon Nelson7b086392013-11-20 10:02:59 +00001781static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001782{
Shannon Nelson7b086392013-11-20 10:02:59 +00001783 struct i40e_netdev_priv *np = netdev_priv(netdev);
1784 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001785 i40e_status status;
1786 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001787
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001788 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001789 status = i40e_get_link_status(&pf->hw, &link_up);
1790 if (status) {
1791 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1792 *data = 1;
1793 return *data;
1794 }
1795
1796 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797 *data = 0;
1798 else
1799 *data = 1;
1800
1801 return *data;
1802}
1803
Shannon Nelson7b086392013-11-20 10:02:59 +00001804static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001805{
Shannon Nelson7b086392013-11-20 10:02:59 +00001806 struct i40e_netdev_priv *np = netdev_priv(netdev);
1807 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001808
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001809 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001810 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811
Shannon Nelson7b086392013-11-20 10:02:59 +00001812 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001813}
1814
Shannon Nelson7b086392013-11-20 10:02:59 +00001815static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001816{
Shannon Nelson7b086392013-11-20 10:02:59 +00001817 struct i40e_netdev_priv *np = netdev_priv(netdev);
1818 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001820 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001821 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001822
Shannon Nelson4443ec92014-11-13 08:23:12 +00001823 /* forcebly clear the NVM Update state machine */
1824 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1825
Shannon Nelson7b086392013-11-20 10:02:59 +00001826 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001827}
1828
Shannon Nelson7b086392013-11-20 10:02:59 +00001829static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001830{
Shannon Nelson7b086392013-11-20 10:02:59 +00001831 struct i40e_netdev_priv *np = netdev_priv(netdev);
1832 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001833 u16 swc_old = pf->sw_int_count;
1834
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001835 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001836 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1837 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001838 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1839 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1840 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1841 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001842 usleep_range(1000, 2000);
1843 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001844
1845 return *data;
1846}
1847
Greg Rosee17bc412015-04-16 20:05:59 -04001848static inline bool i40e_active_vfs(struct i40e_pf *pf)
1849{
1850 struct i40e_vf *vfs = pf->vf;
1851 int i;
1852
1853 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001854 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001855 return true;
1856 return false;
1857}
1858
Greg Rose510efb22015-07-10 19:36:01 -04001859static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1860{
Alexander Duyck4b816442016-10-11 15:26:53 -07001861 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001862}
1863
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001864static void i40e_diag_test(struct net_device *netdev,
1865 struct ethtool_test *eth_test, u64 *data)
1866{
1867 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001868 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001869 struct i40e_pf *pf = np->vsi->back;
1870
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001871 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1872 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001873 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001874
Jacob Keller0da36b92017-04-19 09:25:55 -04001875 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001876
Greg Rose510efb22015-07-10 19:36:01 -04001877 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001878 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001879 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001880 data[I40E_ETH_TEST_REG] = 1;
1881 data[I40E_ETH_TEST_EEPROM] = 1;
1882 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001883 data[I40E_ETH_TEST_LINK] = 1;
1884 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04001885 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001886 goto skip_ol_tests;
1887 }
1888
Greg Rose5b86c5c2015-02-26 16:14:35 +00001889 /* If the device is online then take it offline */
1890 if (if_running)
1891 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001892 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001893 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001894 /* This reset does not affect link - if it is
1895 * changed to a type of reset that does affect
1896 * link then the following link test would have
1897 * to be moved to before the reset
1898 */
Maciej Sosin373149f2017-04-05 07:50:55 -04001899 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00001900
Shannon Nelson7b086392013-11-20 10:02:59 +00001901 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001902 eth_test->flags |= ETH_TEST_FL_FAILED;
1903
Shannon Nelson7b086392013-11-20 10:02:59 +00001904 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001905 eth_test->flags |= ETH_TEST_FL_FAILED;
1906
Shannon Nelson7b086392013-11-20 10:02:59 +00001907 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001908 eth_test->flags |= ETH_TEST_FL_FAILED;
1909
Shannon Nelsonf551b432013-11-26 10:49:12 +00001910 /* run reg test last, a reset is required after it */
1911 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1912 eth_test->flags |= ETH_TEST_FL_FAILED;
1913
Jacob Keller0da36b92017-04-19 09:25:55 -04001914 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04001915 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001916
1917 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001918 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001919 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001920 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001921 netif_info(pf, drv, netdev, "online testing starting\n");
1922
Shannon Nelson7b086392013-11-20 10:02:59 +00001923 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001924 eth_test->flags |= ETH_TEST_FL_FAILED;
1925
1926 /* Offline only tests, not run in online; pass by default */
1927 data[I40E_ETH_TEST_REG] = 0;
1928 data[I40E_ETH_TEST_EEPROM] = 0;
1929 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001930 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001931
Greg Rosee17bc412015-04-16 20:05:59 -04001932skip_ol_tests:
1933
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001934 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001935}
1936
1937static void i40e_get_wol(struct net_device *netdev,
1938 struct ethtool_wolinfo *wol)
1939{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001940 struct i40e_netdev_priv *np = netdev_priv(netdev);
1941 struct i40e_pf *pf = np->vsi->back;
1942 struct i40e_hw *hw = &pf->hw;
1943 u16 wol_nvm_bits;
1944
1945 /* NVM bit on means WoL disabled for the port */
1946 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001947 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001948 wol->supported = 0;
1949 wol->wolopts = 0;
1950 } else {
1951 wol->supported = WAKE_MAGIC;
1952 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1953 }
1954}
1955
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001956/**
1957 * i40e_set_wol - set the WakeOnLAN configuration
1958 * @netdev: the netdev in question
1959 * @wol: the ethtool WoL setting data
1960 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001961static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1962{
1963 struct i40e_netdev_priv *np = netdev_priv(netdev);
1964 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001965 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001966 struct i40e_hw *hw = &pf->hw;
1967 u16 wol_nvm_bits;
1968
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001969 /* WoL not supported if this isn't the controlling PF on the port */
1970 if (hw->partition_id != 1) {
1971 i40e_partition_setting_complaint(pf);
1972 return -EOPNOTSUPP;
1973 }
1974
1975 if (vsi != pf->vsi[pf->lan_vsi])
1976 return -EOPNOTSUPP;
1977
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001978 /* NVM bit on means WoL disabled for the port */
1979 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001980 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001981 return -EOPNOTSUPP;
1982
1983 /* only magic packet is supported */
1984 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1985 return -EOPNOTSUPP;
1986
1987 /* is this a new value? */
1988 if (pf->wol_en != !!wol->wolopts) {
1989 pf->wol_en = !!wol->wolopts;
1990 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1991 }
1992
1993 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001994}
1995
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001996static int i40e_set_phys_id(struct net_device *netdev,
1997 enum ethtool_phys_id_state state)
1998{
1999 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002000 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002001 struct i40e_pf *pf = np->vsi->back;
2002 struct i40e_hw *hw = &pf->hw;
2003 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002004 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002005
2006 switch (state) {
2007 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002008 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002009 pf->led_status = i40e_led_get(hw);
2010 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002011 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2012 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2013 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002014 ret = i40e_led_get_phy(hw, &temp_status,
2015 &pf->phy_led_val);
2016 pf->led_status = temp_status;
2017 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002018 return blink_freq;
2019 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002020 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002021 i40e_led_set(hw, 0xf, false);
2022 else
2023 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002024 break;
2025 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002026 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002027 i40e_led_set(hw, 0x0, false);
2028 else
2029 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002030 break;
2031 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002032 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002033 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002034 } else {
2035 ret = i40e_led_set_phy(hw, false, pf->led_status,
2036 (pf->phy_led_val |
2037 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002038 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2039 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002040 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002041 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002042 default:
2043 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002044 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002045 if (ret)
2046 return -ENOENT;
2047 else
2048 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002049}
2050
2051/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2052 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2053 * 125us (8000 interrupts per second) == ITR(62)
2054 */
2055
Jacob Keller65e87c02016-09-12 14:18:44 -07002056/**
2057 * __i40e_get_coalesce - get per-queue coalesce settings
2058 * @netdev: the netdev to check
2059 * @ec: ethtool coalesce data structure
2060 * @queue: which queue to pick
2061 *
2062 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2063 * are per queue. If queue is <0 then we default to queue 0 as the
2064 * representative value.
2065 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002066static int __i40e_get_coalesce(struct net_device *netdev,
2067 struct ethtool_coalesce *ec,
2068 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002069{
2070 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002071 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002072 struct i40e_vsi *vsi = np->vsi;
2073
2074 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2075 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2076
Kan Lianga75e8002016-02-19 09:24:04 -05002077 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2078 * return queue 0's value to represent.
2079 */
2080 if (queue < 0) {
2081 queue = 0;
2082 } else if (queue >= vsi->num_queue_pairs) {
2083 return -EINVAL;
2084 }
2085
Jacob Keller65e87c02016-09-12 14:18:44 -07002086 rx_ring = vsi->rx_rings[queue];
2087 tx_ring = vsi->tx_rings[queue];
2088
2089 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002090 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002091
Jacob Keller65e87c02016-09-12 14:18:44 -07002092 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002093 ec->use_adaptive_tx_coalesce = 1;
2094
Jacob Keller65e87c02016-09-12 14:18:44 -07002095 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2096 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2097
Kan Lianga75e8002016-02-19 09:24:04 -05002098
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002099 /* we use the _usecs_high to store/set the interrupt rate limit
2100 * that the hardware supports, that almost but not quite
2101 * fits the original intent of the ethtool variable,
2102 * the rx_coalesce_usecs_high limits total interrupts
2103 * per second from both tx/rx sources.
2104 */
2105 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2106 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002107
2108 return 0;
2109}
2110
Jacob Keller65e87c02016-09-12 14:18:44 -07002111/**
2112 * i40e_get_coalesce - get a netdev's coalesce settings
2113 * @netdev: the netdev to check
2114 * @ec: ethtool coalesce data structure
2115 *
2116 * Gets the coalesce settings for a particular netdev. Note that if user has
2117 * modified per-queue settings, this only guarantees to represent queue 0. See
2118 * __i40e_get_coalesce for more details.
2119 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002120static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002121 struct ethtool_coalesce *ec)
2122{
Kan Lianga75e8002016-02-19 09:24:04 -05002123 return __i40e_get_coalesce(netdev, ec, -1);
2124}
2125
Jacob Keller65e87c02016-09-12 14:18:44 -07002126/**
2127 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2128 * @netdev: netdev structure
2129 * @ec: ethtool's coalesce settings
2130 * @queue: the particular queue to read
2131 *
2132 * Will read a specific queue's coalesce settings
2133 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002134static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2135 struct ethtool_coalesce *ec)
2136{
2137 return __i40e_get_coalesce(netdev, ec, queue);
2138}
2139
Jacob Keller65e87c02016-09-12 14:18:44 -07002140/**
2141 * i40e_set_itr_per_queue - set ITR values for specific queue
2142 * @vsi: the VSI to set values for
2143 * @ec: coalesce settings from ethtool
2144 * @queue: the queue to modify
2145 *
2146 * Change the ITR settings for a specific queue.
2147 **/
2148
Kan Lianga75e8002016-02-19 09:24:04 -05002149static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2150 struct ethtool_coalesce *ec,
2151 int queue)
2152{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002153 struct i40e_pf *pf = vsi->back;
2154 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002155 struct i40e_q_vector *q_vector;
2156 u16 vector, intrl;
2157
Alan Brady1c0e6a32016-11-28 16:06:02 -08002158 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002159
2160 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2161 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2162
2163 if (ec->use_adaptive_rx_coalesce)
2164 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2165 else
2166 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2167
2168 if (ec->use_adaptive_tx_coalesce)
2169 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2170 else
2171 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2172
2173 q_vector = vsi->rx_rings[queue]->q_vector;
2174 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2175 vector = vsi->base_vector + q_vector->v_idx;
2176 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2177
2178 q_vector = vsi->tx_rings[queue]->q_vector;
2179 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2180 vector = vsi->base_vector + q_vector->v_idx;
2181 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2182
2183 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2184 i40e_flush(hw);
2185}
2186
Jacob Keller65e87c02016-09-12 14:18:44 -07002187/**
2188 * __i40e_set_coalesce - set coalesce settings for particular queue
2189 * @netdev: the netdev to change
2190 * @ec: ethtool coalesce settings
2191 * @queue: the queue to change
2192 *
2193 * Sets the coalesce settings for a particular queue.
2194 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002195static int __i40e_set_coalesce(struct net_device *netdev,
2196 struct ethtool_coalesce *ec,
2197 int queue)
2198{
2199 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002200 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002201 struct i40e_vsi *vsi = np->vsi;
2202 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002203 int i;
2204
2205 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2206 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2207
Alan Brady06b2dec2017-07-12 05:46:06 -04002208 if (queue < 0) {
2209 cur_rx_itr = vsi->rx_rings[0]->rx_itr_setting;
2210 cur_tx_itr = vsi->tx_rings[0]->tx_itr_setting;
2211 } else if (queue < vsi->num_queue_pairs) {
2212 cur_rx_itr = vsi->rx_rings[queue]->rx_itr_setting;
2213 cur_tx_itr = vsi->tx_rings[queue]->tx_itr_setting;
2214 } else {
2215 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2216 vsi->num_queue_pairs - 1);
2217 return -EINVAL;
2218 }
2219
2220 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2221 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2222
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002223 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2224 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2225 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2226 return -EINVAL;
2227 }
2228
Alan Brady33084062016-11-28 16:06:03 -08002229 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2230 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2231 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002232 return -EINVAL;
2233 }
2234
Alan Brady06b2dec2017-07-12 05:46:06 -04002235 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2236 ec->use_adaptive_rx_coalesce) {
2237 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2238 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002239 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002240
Alan Brady06b2dec2017-07-12 05:46:06 -04002241 if (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2242 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2243 return -EINVAL;
2244 }
2245
2246 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2247 ec->use_adaptive_tx_coalesce) {
2248 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2249 return -EINVAL;
2250 }
2251
2252 if (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2253 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2254 return -EINVAL;
2255 }
2256
2257 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2258 ec->rx_coalesce_usecs = I40E_MIN_ITR << 1;
2259
2260 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2261 ec->tx_coalesce_usecs = I40E_MIN_ITR << 1;
2262
Alan Brady33084062016-11-28 16:06:03 -08002263 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2264 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2265 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2266 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2267 vsi->int_rate_limit);
2268 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002269
Kan Lianga75e8002016-02-19 09:24:04 -05002270 /* rx and tx usecs has per queue value. If user doesn't specify the queue,
2271 * apply to all queues.
2272 */
2273 if (queue < 0) {
2274 for (i = 0; i < vsi->num_queue_pairs; i++)
2275 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002276 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002277 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002278 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002279
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002280 return 0;
2281}
2282
Jacob Keller65e87c02016-09-12 14:18:44 -07002283/**
2284 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2285 * @netdev: the netdev to change
2286 * @ec: ethtool coalesce settings
2287 *
2288 * This will set each queue to the same coalesce settings.
2289 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002290static int i40e_set_coalesce(struct net_device *netdev,
2291 struct ethtool_coalesce *ec)
2292{
2293 return __i40e_set_coalesce(netdev, ec, -1);
2294}
2295
Jacob Keller65e87c02016-09-12 14:18:44 -07002296/**
2297 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2298 * @netdev: the netdev to change
2299 * @ec: ethtool's coalesce settings
2300 * @queue: the queue to change
2301 *
2302 * Sets the specified queue's coalesce settings.
2303 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002304static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2305 struct ethtool_coalesce *ec)
2306{
2307 return __i40e_set_coalesce(netdev, ec, queue);
2308}
2309
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002310/**
2311 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2312 * @pf: pointer to the physical function struct
2313 * @cmd: ethtool rxnfc command
2314 *
2315 * Returns Success if the flow is supported, else Invalid Input.
2316 **/
2317static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2318{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002319 struct i40e_hw *hw = &pf->hw;
2320 u8 flow_pctype = 0;
2321 u64 i_set = 0;
2322
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002323 cmd->data = 0;
2324
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002325 switch (cmd->flow_type) {
2326 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002327 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2328 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002329 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002330 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2331 break;
2332 case TCP_V6_FLOW:
2333 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2334 break;
2335 case UDP_V6_FLOW:
2336 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2337 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002338 case SCTP_V4_FLOW:
2339 case AH_ESP_V4_FLOW:
2340 case AH_V4_FLOW:
2341 case ESP_V4_FLOW:
2342 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002343 case SCTP_V6_FLOW:
2344 case AH_ESP_V6_FLOW:
2345 case AH_V6_FLOW:
2346 case ESP_V6_FLOW:
2347 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002348 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002349 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2350 break;
2351 default:
2352 return -EINVAL;
2353 }
2354
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002355 /* Read flow based hash input set register */
2356 if (flow_pctype) {
2357 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2358 flow_pctype)) |
2359 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2360 flow_pctype)) << 32);
2361 }
2362
2363 /* Process bits of hash input set */
2364 if (i_set) {
2365 if (i_set & I40E_L4_SRC_MASK)
2366 cmd->data |= RXH_L4_B_0_1;
2367 if (i_set & I40E_L4_DST_MASK)
2368 cmd->data |= RXH_L4_B_2_3;
2369
2370 if (cmd->flow_type == TCP_V4_FLOW ||
2371 cmd->flow_type == UDP_V4_FLOW) {
2372 if (i_set & I40E_L3_SRC_MASK)
2373 cmd->data |= RXH_IP_SRC;
2374 if (i_set & I40E_L3_DST_MASK)
2375 cmd->data |= RXH_IP_DST;
2376 } else if (cmd->flow_type == TCP_V6_FLOW ||
2377 cmd->flow_type == UDP_V6_FLOW) {
2378 if (i_set & I40E_L3_V6_SRC_MASK)
2379 cmd->data |= RXH_IP_SRC;
2380 if (i_set & I40E_L3_V6_DST_MASK)
2381 cmd->data |= RXH_IP_DST;
2382 }
2383 }
2384
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002385 return 0;
2386}
2387
2388/**
Jacob Kellere7930952017-02-06 14:38:49 -08002389 * i40e_check_mask - Check whether a mask field is set
2390 * @mask: the full mask value
2391 * @field; mask of the field to check
2392 *
2393 * If the given mask is fully set, return positive value. If the mask for the
2394 * field is fully unset, return zero. Otherwise return a negative error code.
2395 **/
2396static int i40e_check_mask(u64 mask, u64 field)
2397{
2398 u64 value = mask & field;
2399
2400 if (value == field)
2401 return 1;
2402 else if (!value)
2403 return 0;
2404 else
2405 return -1;
2406}
2407
2408/**
2409 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2410 * @fsp: pointer to rx flow specification
2411 * @data: pointer to userdef data structure for storage
2412 *
2413 * Read the user-defined data and deconstruct the value into a structure. No
2414 * other code should read the user-defined data, so as to ensure that every
2415 * place consistently reads the value correctly.
2416 *
2417 * The user-defined field is a 64bit Big Endian format value, which we
2418 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2419 * be defined starting from the highest bits, while small bit field values
2420 * shall be defined starting from the lowest bits.
2421 *
2422 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2423 * and the filter should be rejected. The data structure will always be
2424 * modified even if FLOW_EXT is not set.
2425 *
2426 **/
2427static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2428 struct i40e_rx_flow_userdef *data)
2429{
2430 u64 value, mask;
2431 int valid;
2432
2433 /* Zero memory first so it's always consistent. */
2434 memset(data, 0, sizeof(*data));
2435
2436 if (!(fsp->flow_type & FLOW_EXT))
2437 return 0;
2438
2439 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2440 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2441
2442#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2443#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2444#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2445
2446 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2447 if (valid < 0) {
2448 return -EINVAL;
2449 } else if (valid) {
2450 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2451 data->flex_offset =
2452 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2453 data->flex_filter = true;
2454 }
2455
2456 return 0;
2457}
2458
2459/**
2460 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2461 * @fsp: pointer to rx_flow specification
2462 *
2463 * Reads the userdef data structure and properly fills in the user defined
2464 * fields of the rx_flow_spec.
2465 **/
2466static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2467 struct i40e_rx_flow_userdef *data)
2468{
2469 u64 value = 0, mask = 0;
2470
2471 if (data->flex_filter) {
2472 value |= data->flex_word;
2473 value |= (u64)data->flex_offset << 16;
2474 mask |= I40E_USERDEF_FLEX_FILTER;
2475 }
2476
2477 if (value || mask)
2478 fsp->flow_type |= FLOW_EXT;
2479
2480 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2481 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2482}
2483
2484/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002485 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2486 * @pf: Pointer to the physical function struct
2487 * @cmd: The command to get or set Rx flow classification rules
2488 * @rule_locs: Array of used rule locations
2489 *
2490 * This function populates both the total and actual rule count of
2491 * the ethtool flow classification command
2492 *
2493 * Returns 0 on success or -EMSGSIZE if entry not found
2494 **/
2495static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2496 struct ethtool_rxnfc *cmd,
2497 u32 *rule_locs)
2498{
2499 struct i40e_fdir_filter *rule;
2500 struct hlist_node *node2;
2501 int cnt = 0;
2502
2503 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002504 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002505
2506 hlist_for_each_entry_safe(rule, node2,
2507 &pf->fdir_filter_list, fdir_node) {
2508 if (cnt == cmd->rule_cnt)
2509 return -EMSGSIZE;
2510
2511 rule_locs[cnt] = rule->fd_id;
2512 cnt++;
2513 }
2514
2515 cmd->rule_cnt = cnt;
2516
2517 return 0;
2518}
2519
2520/**
2521 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2522 * @pf: Pointer to the physical function struct
2523 * @cmd: The command to get or set Rx flow classification rules
2524 *
2525 * This function looks up a filter based on the Rx flow classification
2526 * command and fills the flow spec info for it if found
2527 *
2528 * Returns 0 on success or -EINVAL if filter not found
2529 **/
2530static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2531 struct ethtool_rxnfc *cmd)
2532{
2533 struct ethtool_rx_flow_spec *fsp =
2534 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002535 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002536 struct i40e_fdir_filter *rule = NULL;
2537 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002538 u64 input_set;
2539 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002540
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002541 hlist_for_each_entry_safe(rule, node2,
2542 &pf->fdir_filter_list, fdir_node) {
2543 if (fsp->location <= rule->fd_id)
2544 break;
2545 }
2546
2547 if (!rule || fsp->location != rule->fd_id)
2548 return -EINVAL;
2549
2550 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002551 if (fsp->flow_type == IP_USER_FLOW) {
2552 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2553 fsp->h_u.usr_ip4_spec.proto = 0;
2554 fsp->m_u.usr_ip4_spec.proto = 0;
2555 }
2556
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002557 /* Reverse the src and dest notion, since the HW views them from
2558 * Tx perspective where as the user expects it from Rx filter view.
2559 */
2560 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2561 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002562 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2563 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002564
Jacob Keller36777d92017-03-07 15:05:23 -08002565 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002566 case SCTP_V4_FLOW:
2567 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2568 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002569 case TCP_V4_FLOW:
2570 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2571 break;
2572 case UDP_V4_FLOW:
2573 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2574 break;
2575 case IP_USER_FLOW:
2576 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2577 break;
2578 default:
2579 /* If we have stored a filter with a flow type not listed here
2580 * it is almost certainly a driver bug. WARN(), and then
2581 * assign the input_set as if all fields are enabled to avoid
2582 * reading unassigned memory.
2583 */
2584 WARN(1, "Missing input set index for flow_type %d\n",
2585 rule->flow_type);
2586 input_set = 0xFFFFFFFFFFFFFFFFULL;
2587 goto no_input_set;
2588 }
2589
2590 input_set = i40e_read_fd_input_set(pf, index);
2591
2592no_input_set:
2593 if (input_set & I40E_L3_SRC_MASK)
2594 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
2595
2596 if (input_set & I40E_L3_DST_MASK)
2597 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
2598
2599 if (input_set & I40E_L4_SRC_MASK)
2600 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
2601
2602 if (input_set & I40E_L4_DST_MASK)
2603 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002604
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002605 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2606 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2607 else
2608 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002609
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002610 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2611 struct i40e_vsi *vsi;
2612
2613 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2614 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002615 /* VFs are zero-indexed by the driver, but ethtool
2616 * expects them to be one-indexed, so add one here
2617 */
2618 u64 ring_vf = vsi->vf_id + 1;
2619
2620 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2621 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002622 }
2623 }
2624
Jacob Keller0e588de2017-02-06 14:38:50 -08002625 if (rule->flex_filter) {
2626 userdef.flex_filter = true;
2627 userdef.flex_word = be16_to_cpu(rule->flex_word);
2628 userdef.flex_offset = rule->flex_offset;
2629 }
2630
Jacob Kellere7930952017-02-06 14:38:49 -08002631 i40e_fill_rx_flow_user_data(fsp, &userdef);
2632
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002633 return 0;
2634}
2635
2636/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002637 * i40e_get_rxnfc - command to get RX flow classification rules
2638 * @netdev: network interface device structure
2639 * @cmd: ethtool rxnfc command
2640 *
2641 * Returns Success if the command is supported.
2642 **/
2643static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2644 u32 *rule_locs)
2645{
2646 struct i40e_netdev_priv *np = netdev_priv(netdev);
2647 struct i40e_vsi *vsi = np->vsi;
2648 struct i40e_pf *pf = vsi->back;
2649 int ret = -EOPNOTSUPP;
2650
2651 switch (cmd->cmd) {
2652 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002653 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002654 ret = 0;
2655 break;
2656 case ETHTOOL_GRXFH:
2657 ret = i40e_get_rss_hash_opts(pf, cmd);
2658 break;
2659 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002660 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002661 /* report total rule count */
2662 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002663 ret = 0;
2664 break;
2665 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002666 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002667 break;
2668 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002669 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2670 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002671 default:
2672 break;
2673 }
2674
2675 return ret;
2676}
2677
2678/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002679 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2680 * @nfc: pointer to user request
2681 * @i_setc bits currently set
2682 *
2683 * Returns value of bits to be set per user request
2684 **/
2685static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2686{
2687 u64 i_set = i_setc;
2688 u64 src_l3 = 0, dst_l3 = 0;
2689
2690 if (nfc->data & RXH_L4_B_0_1)
2691 i_set |= I40E_L4_SRC_MASK;
2692 else
2693 i_set &= ~I40E_L4_SRC_MASK;
2694 if (nfc->data & RXH_L4_B_2_3)
2695 i_set |= I40E_L4_DST_MASK;
2696 else
2697 i_set &= ~I40E_L4_DST_MASK;
2698
2699 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2700 src_l3 = I40E_L3_V6_SRC_MASK;
2701 dst_l3 = I40E_L3_V6_DST_MASK;
2702 } else if (nfc->flow_type == TCP_V4_FLOW ||
2703 nfc->flow_type == UDP_V4_FLOW) {
2704 src_l3 = I40E_L3_SRC_MASK;
2705 dst_l3 = I40E_L3_DST_MASK;
2706 } else {
2707 /* Any other flow type are not supported here */
2708 return i_set;
2709 }
2710
2711 if (nfc->data & RXH_IP_SRC)
2712 i_set |= src_l3;
2713 else
2714 i_set &= ~src_l3;
2715 if (nfc->data & RXH_IP_DST)
2716 i_set |= dst_l3;
2717 else
2718 i_set &= ~dst_l3;
2719
2720 return i_set;
2721}
2722
2723/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002724 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2725 * @pf: pointer to the physical function struct
2726 * @cmd: ethtool rxnfc command
2727 *
2728 * Returns Success if the flow input set is supported.
2729 **/
2730static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2731{
2732 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002733 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2734 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002735 u8 flow_pctype = 0;
2736 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002737
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002738 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2739 dev_err(&pf->pdev->dev,
2740 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2741 return -EOPNOTSUPP;
2742 }
2743
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002744 /* RSS does not support anything other than hashing
2745 * to queues on src and dst IPs and ports
2746 */
2747 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2748 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2749 return -EINVAL;
2750
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002751 switch (nfc->flow_type) {
2752 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002753 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002754 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002755 hena |=
2756 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002757 break;
2758 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002759 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002760 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002761 hena |=
2762 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002763 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002764 hena |=
2765 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002766 break;
2767 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002768 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002769 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002770 hena |=
2771 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2772 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002773
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002774 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002775 break;
2776 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002777 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002778 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002779 hena |=
2780 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2781 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002782
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002783 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002784 break;
2785 case AH_ESP_V4_FLOW:
2786 case AH_V4_FLOW:
2787 case ESP_V4_FLOW:
2788 case SCTP_V4_FLOW:
2789 if ((nfc->data & RXH_L4_B_0_1) ||
2790 (nfc->data & RXH_L4_B_2_3))
2791 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002792 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002793 break;
2794 case AH_ESP_V6_FLOW:
2795 case AH_V6_FLOW:
2796 case ESP_V6_FLOW:
2797 case SCTP_V6_FLOW:
2798 if ((nfc->data & RXH_L4_B_0_1) ||
2799 (nfc->data & RXH_L4_B_2_3))
2800 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002801 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002802 break;
2803 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002804 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2805 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002806 break;
2807 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002808 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2809 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002810 break;
2811 default:
2812 return -EINVAL;
2813 }
2814
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002815 if (flow_pctype) {
2816 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2817 flow_pctype)) |
2818 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2819 flow_pctype)) << 32);
2820 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2821 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2822 (u32)i_set);
2823 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2824 (u32)(i_set >> 32));
2825 hena |= BIT_ULL(flow_pctype);
2826 }
2827
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002828 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2829 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002830 i40e_flush(hw);
2831
2832 return 0;
2833}
2834
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002835/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002836 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2837 * @vsi: Pointer to the targeted VSI
2838 * @input: The filter to update or NULL to indicate deletion
2839 * @sw_idx: Software index to the filter
2840 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002841 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002842 * This function updates (or deletes) a Flow Director entry from
2843 * the hlist of the corresponding PF
2844 *
2845 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002846 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002847static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2848 struct i40e_fdir_filter *input,
2849 u16 sw_idx,
2850 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002851{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002852 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002853 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002854 struct hlist_node *node2;
2855 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002856
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002857 parent = NULL;
2858 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002859
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002860 hlist_for_each_entry_safe(rule, node2,
2861 &pf->fdir_filter_list, fdir_node) {
2862 /* hash found, or no matching entry */
2863 if (rule->fd_id >= sw_idx)
2864 break;
2865 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002866 }
2867
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002868 /* if there is an old rule occupying our place remove it */
2869 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08002870 /* Remove this rule, since we're either deleting it, or
2871 * replacing it.
2872 */
2873 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002874 hlist_del(&rule->fdir_node);
2875 kfree(rule);
2876 pf->fdir_pf_active_filters--;
2877 }
2878
Jacob Kellerc6da5252017-02-06 14:39:13 -08002879 /* If we weren't given an input, this is a delete, so just return the
2880 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002881 */
2882 if (!input)
2883 return err;
2884
Jacob Kellerc6da5252017-02-06 14:39:13 -08002885 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002886 INIT_HLIST_NODE(&input->fdir_node);
2887
2888 /* add filter to the list */
2889 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002890 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002891 else
2892 hlist_add_head(&input->fdir_node,
2893 &pf->fdir_filter_list);
2894
2895 /* update counts */
2896 pf->fdir_pf_active_filters++;
2897
2898 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002899}
2900
2901/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002902 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
2903 * @pf: pointer to PF structure
2904 *
2905 * This function searches the list of filters and determines which FLX_PIT
2906 * entries are still required. It will prune any entries which are no longer
2907 * in use after the deletion.
2908 **/
2909static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
2910{
2911 struct i40e_flex_pit *entry, *tmp;
2912 struct i40e_fdir_filter *rule;
2913
2914 /* First, we'll check the l3 table */
2915 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
2916 bool found = false;
2917
2918 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2919 if (rule->flow_type != IP_USER_FLOW)
2920 continue;
2921 if (rule->flex_filter &&
2922 rule->flex_offset == entry->src_offset) {
2923 found = true;
2924 break;
2925 }
2926 }
2927
2928 /* If we didn't find the filter, then we can prune this entry
2929 * from the list.
2930 */
2931 if (!found) {
2932 list_del(&entry->list);
2933 kfree(entry);
2934 }
2935 }
2936
2937 /* Followed by the L4 table */
2938 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
2939 bool found = false;
2940
2941 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2942 /* Skip this filter if it's L3, since we already
2943 * checked those in the above loop
2944 */
2945 if (rule->flow_type == IP_USER_FLOW)
2946 continue;
2947 if (rule->flex_filter &&
2948 rule->flex_offset == entry->src_offset) {
2949 found = true;
2950 break;
2951 }
2952 }
2953
2954 /* If we didn't find the filter, then we can prune this entry
2955 * from the list.
2956 */
2957 if (!found) {
2958 list_del(&entry->list);
2959 kfree(entry);
2960 }
2961 }
2962}
2963
2964/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002965 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2966 * @vsi: Pointer to the targeted VSI
2967 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002968 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002969 * The function removes a Flow Director filter entry from the
2970 * hlist of the corresponding PF
2971 *
2972 * Returns 0 on success
2973 */
2974static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2975 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002976{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002977 struct ethtool_rx_flow_spec *fsp =
2978 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002979 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002980 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002981
Jacob Keller0da36b92017-04-19 09:25:55 -04002982 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
2983 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002984 return -EBUSY;
2985
Jacob Keller0da36b92017-04-19 09:25:55 -04002986 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002987 return -EBUSY;
2988
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002989 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002990
Jacob Keller0e588de2017-02-06 14:38:50 -08002991 i40e_prune_flex_pit_list(pf);
2992
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002993 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002994 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002995}
2996
2997/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002998 * i40e_unused_pit_index - Find an unused PIT index for given list
2999 * @pf: the PF data structure
3000 *
3001 * Find the first unused flexible PIT index entry. We search both the L3 and
3002 * L4 flexible PIT lists so that the returned index is unique and unused by
3003 * either currently programmed L3 or L4 filters. We use a bit field as storage
3004 * to track which indexes are already used.
3005 **/
3006static u8 i40e_unused_pit_index(struct i40e_pf *pf)
3007{
3008 unsigned long available_index = 0xFF;
3009 struct i40e_flex_pit *entry;
3010
3011 /* We need to make sure that the new index isn't in use by either L3
3012 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3013 * L4 to use the same index.
3014 */
3015
3016 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3017 clear_bit(entry->pit_index, &available_index);
3018
3019 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3020 clear_bit(entry->pit_index, &available_index);
3021
3022 return find_first_bit(&available_index, 8);
3023}
3024
3025/**
3026 * i40e_find_flex_offset - Find an existing flex src_offset
3027 * @flex_pit_list: L3 or L4 flex PIT list
3028 * @src_offset: new src_offset to find
3029 *
3030 * Searches the flex_pit_list for an existing offset. If no offset is
3031 * currently programmed, then this will return an ERR_PTR if there is no space
3032 * to add a new offset, otherwise it returns NULL.
3033 **/
3034static
3035struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3036 u16 src_offset)
3037{
3038 struct i40e_flex_pit *entry;
3039 int size = 0;
3040
3041 /* Search for the src_offset first. If we find a matching entry
3042 * already programmed, we can simply re-use it.
3043 */
3044 list_for_each_entry(entry, flex_pit_list, list) {
3045 size++;
3046 if (entry->src_offset == src_offset)
3047 return entry;
3048 }
3049
3050 /* If we haven't found an entry yet, then the provided src offset has
3051 * not yet been programmed. We will program the src offset later on,
3052 * but we need to indicate whether there is enough space to do so
3053 * here. We'll make use of ERR_PTR for this purpose.
3054 */
3055 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3056 return ERR_PTR(-ENOSPC);
3057
3058 return NULL;
3059}
3060
3061/**
3062 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3063 * @flex_pit_list: L3 or L4 flex PIT list
3064 * @src_offset: new src_offset to add
3065 * @pit_index: the PIT index to program
3066 *
3067 * This function programs the new src_offset to the list. It is expected that
3068 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3069 * that this offset is not programmed, and that the list has enough space to
3070 * store another offset.
3071 *
3072 * Returns 0 on success, and negative value on error.
3073 **/
3074static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3075 u16 src_offset,
3076 u8 pit_index)
3077{
3078 struct i40e_flex_pit *new_pit, *entry;
3079
3080 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3081 if (!new_pit)
3082 return -ENOMEM;
3083
3084 new_pit->src_offset = src_offset;
3085 new_pit->pit_index = pit_index;
3086
3087 /* We need to insert this item such that the list is sorted by
3088 * src_offset in ascending order.
3089 */
3090 list_for_each_entry(entry, flex_pit_list, list) {
3091 if (new_pit->src_offset < entry->src_offset) {
3092 list_add_tail(&new_pit->list, &entry->list);
3093 return 0;
3094 }
3095
3096 /* If we found an entry with our offset already programmed we
3097 * can simply return here, after freeing the memory. However,
3098 * if the pit_index does not match we need to report an error.
3099 */
3100 if (new_pit->src_offset == entry->src_offset) {
3101 int err = 0;
3102
3103 /* If the PIT index is not the same we can't re-use
3104 * the entry, so we must report an error.
3105 */
3106 if (new_pit->pit_index != entry->pit_index)
3107 err = -EINVAL;
3108
3109 kfree(new_pit);
3110 return err;
3111 }
3112 }
3113
3114 /* If we reached here, then we haven't yet added the item. This means
3115 * that we should add the item at the end of the list.
3116 */
3117 list_add_tail(&new_pit->list, flex_pit_list);
3118 return 0;
3119}
3120
3121/**
3122 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3123 * @pf: Pointer to the PF structure
3124 * @flex_pit_list: list of flexible src offsets in use
3125 * #flex_pit_start: index to first entry for this section of the table
3126 *
3127 * In order to handle flexible data, the hardware uses a table of values
3128 * called the FLX_PIT table. This table is used to indicate which sections of
3129 * the input correspond to what PIT index values. Unfortunately, hardware is
3130 * very restrictive about programming this table. Entries must be ordered by
3131 * src_offset in ascending order, without duplicates. Additionally, unused
3132 * entries must be set to the unused index value, and must have valid size and
3133 * length according to the src_offset ordering.
3134 *
3135 * This function will reprogram the FLX_PIT register from a book-keeping
3136 * structure that we guarantee is already ordered correctly, and has no more
3137 * than 3 entries.
3138 *
3139 * To make things easier, we only support flexible values of one word length,
3140 * rather than allowing variable length flexible values.
3141 **/
3142static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3143 struct list_head *flex_pit_list,
3144 int flex_pit_start)
3145{
3146 struct i40e_flex_pit *entry = NULL;
3147 u16 last_offset = 0;
3148 int i = 0, j = 0;
3149
3150 /* First, loop over the list of flex PIT entries, and reprogram the
3151 * registers.
3152 */
3153 list_for_each_entry(entry, flex_pit_list, list) {
3154 /* We have to be careful when programming values for the
3155 * largest SRC_OFFSET value. It is possible that adding
3156 * additional empty values at the end would overflow the space
3157 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3158 * we check here and add the empty values prior to adding the
3159 * largest value.
3160 *
3161 * To determine this, we will use a loop from i+1 to 3, which
3162 * will determine whether the unused entries would have valid
3163 * SRC_OFFSET. Note that there cannot be extra entries past
3164 * this value, because the only valid values would have been
3165 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3166 * have been added to the list in the first place.
3167 */
3168 for (j = i + 1; j < 3; j++) {
3169 u16 offset = entry->src_offset + j;
3170 int index = flex_pit_start + i;
3171 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3172 1,
3173 offset - 3);
3174
3175 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3176 i40e_write_rx_ctl(&pf->hw,
3177 I40E_PRTQF_FLX_PIT(index),
3178 value);
3179 i++;
3180 }
3181 }
3182
3183 /* Now, we can program the actual value into the table */
3184 i40e_write_rx_ctl(&pf->hw,
3185 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3186 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3187 1,
3188 entry->src_offset));
3189 i++;
3190 }
3191
3192 /* In order to program the last entries in the table, we need to
3193 * determine the valid offset. If the list is empty, we'll just start
3194 * with 0. Otherwise, we'll start with the last item offset and add 1.
3195 * This ensures that all entries have valid sizes. If we don't do this
3196 * correctly, the hardware will disable flexible field parsing.
3197 */
3198 if (!list_empty(flex_pit_list))
3199 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3200
3201 for (; i < 3; i++, last_offset++) {
3202 i40e_write_rx_ctl(&pf->hw,
3203 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3204 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3205 1,
3206 last_offset));
3207 }
3208}
3209
3210/**
3211 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3212 * @pf: pointer to the PF structure
3213 *
3214 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3215 * internal helper function for implementation details.
3216 **/
3217static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3218{
3219 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3220 I40E_FLEX_PIT_IDX_START_L3);
3221
3222 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3223 I40E_FLEX_PIT_IDX_START_L4);
3224
3225 /* We also need to program the L3 and L4 GLQF ORT register */
3226 i40e_write_rx_ctl(&pf->hw,
3227 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3228 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3229 3, 1));
3230
3231 i40e_write_rx_ctl(&pf->hw,
3232 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3233 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3234 3, 1));
3235}
3236
3237/**
Jacob Keller9229e992017-02-06 14:38:47 -08003238 * i40e_flow_str - Converts a flow_type into a human readable string
3239 * @flow_type: the flow type from a flow specification
3240 *
3241 * Currently only flow types we support are included here, and the string
3242 * value attempts to match what ethtool would use to configure this flow type.
3243 **/
3244static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3245{
3246 switch (fsp->flow_type & ~FLOW_EXT) {
3247 case TCP_V4_FLOW:
3248 return "tcp4";
3249 case UDP_V4_FLOW:
3250 return "udp4";
3251 case SCTP_V4_FLOW:
3252 return "sctp4";
3253 case IP_USER_FLOW:
3254 return "ip4";
3255 default:
3256 return "unknown";
3257 }
3258}
3259
3260/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003261 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3262 * @pit_index: PIT index to convert
3263 *
3264 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3265 * of range.
3266 **/
3267static u64 i40e_pit_index_to_mask(int pit_index)
3268{
3269 switch (pit_index) {
3270 case 0:
3271 return I40E_FLEX_50_MASK;
3272 case 1:
3273 return I40E_FLEX_51_MASK;
3274 case 2:
3275 return I40E_FLEX_52_MASK;
3276 case 3:
3277 return I40E_FLEX_53_MASK;
3278 case 4:
3279 return I40E_FLEX_54_MASK;
3280 case 5:
3281 return I40E_FLEX_55_MASK;
3282 case 6:
3283 return I40E_FLEX_56_MASK;
3284 case 7:
3285 return I40E_FLEX_57_MASK;
3286 default:
3287 return 0;
3288 }
3289}
3290
3291/**
Jacob Keller9229e992017-02-06 14:38:47 -08003292 * i40e_print_input_set - Show changes between two input sets
3293 * @vsi: the vsi being configured
3294 * @old: the old input set
3295 * @new: the new input set
3296 *
3297 * Print the difference between old and new input sets by showing which series
3298 * of words are toggled on or off. Only displays the bits we actually support
3299 * changing.
3300 **/
3301static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3302{
3303 struct i40e_pf *pf = vsi->back;
3304 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003305 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003306
3307 old_value = !!(old & I40E_L3_SRC_MASK);
3308 new_value = !!(new & I40E_L3_SRC_MASK);
3309 if (old_value != new_value)
3310 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3311 old_value ? "ON" : "OFF",
3312 new_value ? "ON" : "OFF");
3313
3314 old_value = !!(old & I40E_L3_DST_MASK);
3315 new_value = !!(new & I40E_L3_DST_MASK);
3316 if (old_value != new_value)
3317 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3318 old_value ? "ON" : "OFF",
3319 new_value ? "ON" : "OFF");
3320
3321 old_value = !!(old & I40E_L4_SRC_MASK);
3322 new_value = !!(new & I40E_L4_SRC_MASK);
3323 if (old_value != new_value)
3324 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3325 old_value ? "ON" : "OFF",
3326 new_value ? "ON" : "OFF");
3327
3328 old_value = !!(old & I40E_L4_DST_MASK);
3329 new_value = !!(new & I40E_L4_DST_MASK);
3330 if (old_value != new_value)
3331 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3332 old_value ? "ON" : "OFF",
3333 new_value ? "ON" : "OFF");
3334
3335 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3336 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3337 if (old_value != new_value)
3338 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3339 old_value ? "ON" : "OFF",
3340 new_value ? "ON" : "OFF");
3341
Jacob Keller0e588de2017-02-06 14:38:50 -08003342 /* Show change of flexible filter entries */
3343 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3344 u64 flex_mask = i40e_pit_index_to_mask(i);
3345
3346 old_value = !!(old & flex_mask);
3347 new_value = !!(new & flex_mask);
3348 if (old_value != new_value)
3349 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3350 i,
3351 old_value ? "ON" : "OFF",
3352 new_value ? "ON" : "OFF");
3353 }
3354
Jacob Keller9229e992017-02-06 14:38:47 -08003355 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3356 old);
3357 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3358 new);
3359}
3360
3361/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003362 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003363 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003364 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003365 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003366 *
Jacob Keller9229e992017-02-06 14:38:47 -08003367 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3368 * for partial matches exists with a few limitations. First, hardware only
3369 * supports masking by word boundary (2 bytes) and not per individual bit.
3370 * Second, hardware is limited to using one mask for a flow type and cannot
3371 * use a separate mask for each filter.
3372 *
3373 * To support these limitations, if we already have a configured filter for
3374 * the specified type, this function enforces that new filters of the type
3375 * match the configured input set. Otherwise, if we do not have a filter of
3376 * the specified type, we allow the input set to be updated to match the
3377 * desired filter.
3378 *
3379 * To help ensure that administrators understand why filters weren't displayed
3380 * as supported, we print a diagnostic message displaying how the input set
3381 * would change and warning to delete the preexisting filters if required.
3382 *
3383 * Returns 0 on successful input set match, and a negative return code on
3384 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003385 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003386static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003387 struct ethtool_rx_flow_spec *fsp,
3388 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003389{
Jacob Keller36777d92017-03-07 15:05:23 -08003390 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003391 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3392 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003393 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003394 bool new_flex_offset = false;
3395 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003396 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003397 u16 index, src_offset = 0;
3398 u8 pit_index = 0;
3399 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003400
3401 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003402 case SCTP_V4_FLOW:
3403 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3404 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3405 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003406 case TCP_V4_FLOW:
3407 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003408 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003409 break;
3410 case UDP_V4_FLOW:
3411 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003412 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003413 break;
3414 case IP_USER_FLOW:
3415 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003416 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003417 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003418 break;
3419 default:
3420 return -EOPNOTSUPP;
3421 }
3422
3423 /* Read the current input set from register memory. */
3424 current_mask = i40e_read_fd_input_set(pf, index);
3425 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003426
Jacob Keller9229e992017-02-06 14:38:47 -08003427 /* Determine, if any, the required changes to the input set in order
3428 * to support the provided mask.
3429 *
3430 * Hardware only supports masking at word (2 byte) granularity and does
3431 * not support full bitwise masking. This implementation simplifies
3432 * even further and only supports fully enabled or fully disabled
3433 * masks for each field, even though we could split the ip4src and
3434 * ip4dst fields.
3435 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003436 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003437 case SCTP_V4_FLOW:
3438 new_mask &= ~I40E_VERIFY_TAG_MASK;
3439 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003440 case TCP_V4_FLOW:
3441 case UDP_V4_FLOW:
3442 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3443
3444 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003445 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3446 new_mask |= I40E_L3_SRC_MASK;
3447 else if (!tcp_ip4_spec->ip4src)
3448 new_mask &= ~I40E_L3_SRC_MASK;
3449 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003450 return -EOPNOTSUPP;
3451
3452 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003453 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3454 new_mask |= I40E_L3_DST_MASK;
3455 else if (!tcp_ip4_spec->ip4dst)
3456 new_mask &= ~I40E_L3_DST_MASK;
3457 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003458 return -EOPNOTSUPP;
3459
3460 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003461 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3462 new_mask |= I40E_L4_SRC_MASK;
3463 else if (!tcp_ip4_spec->psrc)
3464 new_mask &= ~I40E_L4_SRC_MASK;
3465 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003466 return -EOPNOTSUPP;
3467
3468 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003469 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3470 new_mask |= I40E_L4_DST_MASK;
3471 else if (!tcp_ip4_spec->pdst)
3472 new_mask &= ~I40E_L4_DST_MASK;
3473 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003474 return -EOPNOTSUPP;
3475
3476 /* Filtering on Type of Service is not supported. */
3477 if (tcp_ip4_spec->tos)
3478 return -EOPNOTSUPP;
3479
3480 break;
3481 case IP_USER_FLOW:
3482 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3483
3484 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003485 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3486 new_mask |= I40E_L3_SRC_MASK;
3487 else if (!usr_ip4_spec->ip4src)
3488 new_mask &= ~I40E_L3_SRC_MASK;
3489 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003490 return -EOPNOTSUPP;
3491
3492 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003493 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3494 new_mask |= I40E_L3_DST_MASK;
3495 else if (!usr_ip4_spec->ip4dst)
3496 new_mask &= ~I40E_L3_DST_MASK;
3497 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003498 return -EOPNOTSUPP;
3499
3500 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003501 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3502 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3503 else if (!usr_ip4_spec->l4_4_bytes)
3504 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3505 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003506 return -EOPNOTSUPP;
3507
3508 /* Filtering on Type of Service is not supported. */
3509 if (usr_ip4_spec->tos)
3510 return -EOPNOTSUPP;
3511
Jacob Keller0e588de2017-02-06 14:38:50 -08003512 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003513 if (usr_ip4_spec->ip_ver)
3514 return -EINVAL;
3515
Jacob Keller0e588de2017-02-06 14:38:50 -08003516 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003517 if (usr_ip4_spec->proto)
3518 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003519
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003520 break;
3521 default:
3522 return -EOPNOTSUPP;
3523 }
3524
Jacob Keller0e588de2017-02-06 14:38:50 -08003525 /* First, clear all flexible filter entries */
3526 new_mask &= ~I40E_FLEX_INPUT_MASK;
3527
3528 /* If we have a flexible filter, try to add this offset to the correct
3529 * flexible filter PIT list. Once finished, we can update the mask.
3530 * If the src_offset changed, we will get a new mask value which will
3531 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003532 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003533 if (userdef->flex_filter) {
3534 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3535
3536 /* Flexible offset must be even, since the flexible payload
3537 * must be aligned on 2-byte boundary.
3538 */
3539 if (userdef->flex_offset & 0x1) {
3540 dev_warn(&pf->pdev->dev,
3541 "Flexible data offset must be 2-byte aligned\n");
3542 return -EINVAL;
3543 }
3544
3545 src_offset = userdef->flex_offset >> 1;
3546
3547 /* FLX_PIT source offset value is only so large */
3548 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3549 dev_warn(&pf->pdev->dev,
3550 "Flexible data must reside within first 64 bytes of the packet payload\n");
3551 return -EINVAL;
3552 }
3553
3554 /* See if this offset has already been programmed. If we get
3555 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3556 * if we get a NULL pointer, this means we will need to add
3557 * the offset.
3558 */
3559 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3560 src_offset);
3561 if (IS_ERR(flex_pit))
3562 return PTR_ERR(flex_pit);
3563
3564 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3565 * packet types, and thus we need to program both L3 and L4
3566 * flexible values. These must have identical flexible index,
3567 * as otherwise we can't correctly program the input set. So
3568 * we'll find both an L3 and L4 index and make sure they are
3569 * the same.
3570 */
3571 if (flex_l3) {
3572 l3_flex_pit =
3573 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3574 src_offset);
3575 if (IS_ERR(l3_flex_pit))
3576 return PTR_ERR(l3_flex_pit);
3577
3578 if (flex_pit) {
3579 /* If we already had a matching L4 entry, we
3580 * need to make sure that the L3 entry we
3581 * obtained uses the same index.
3582 */
3583 if (l3_flex_pit) {
3584 if (l3_flex_pit->pit_index !=
3585 flex_pit->pit_index) {
3586 return -EINVAL;
3587 }
3588 } else {
3589 new_flex_offset = true;
3590 }
3591 } else {
3592 flex_pit = l3_flex_pit;
3593 }
3594 }
3595
3596 /* If we didn't find an existing flex offset, we need to
3597 * program a new one. However, we don't immediately program it
3598 * here because we will wait to program until after we check
3599 * that it is safe to change the input set.
3600 */
3601 if (!flex_pit) {
3602 new_flex_offset = true;
3603 pit_index = i40e_unused_pit_index(pf);
3604 } else {
3605 pit_index = flex_pit->pit_index;
3606 }
3607
3608 /* Update the mask with the new offset */
3609 new_mask |= i40e_pit_index_to_mask(pit_index);
3610 }
3611
3612 /* If the mask and flexible filter offsets for this filter match the
3613 * currently programmed values we don't need any input set change, so
3614 * this filter is safe to install.
3615 */
3616 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003617 return 0;
3618
3619 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3620 i40e_flow_str(fsp));
3621 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003622 if (new_flex_offset) {
3623 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3624 pit_index, src_offset);
3625 }
Jacob Keller9229e992017-02-06 14:38:47 -08003626
3627 /* Hardware input sets are global across multiple ports, so even the
3628 * main port cannot change them when in MFP mode as this would impact
3629 * any filters on the other ports.
3630 */
3631 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3632 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003633 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003634 }
3635
3636 /* This filter requires us to update the input set. However, hardware
3637 * only supports one input set per flow type, and does not support
3638 * separate masks for each filter. This means that we can only support
3639 * a single mask for all filters of a specific type.
3640 *
3641 * If we have preexisting filters, they obviously depend on the
3642 * current programmed input set. Display a diagnostic message in this
3643 * case explaining why the filter could not be accepted.
3644 */
3645 if (*fdir_filter_count) {
3646 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3647 i40e_flow_str(fsp),
3648 *fdir_filter_count);
3649 return -EOPNOTSUPP;
3650 }
3651
3652 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003653
Jacob Keller0e588de2017-02-06 14:38:50 -08003654 /* Add the new offset and update table, if necessary */
3655 if (new_flex_offset) {
3656 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3657 pit_index);
3658 if (err)
3659 return err;
3660
3661 if (flex_l3) {
3662 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3663 src_offset,
3664 pit_index);
3665 if (err)
3666 return err;
3667 }
3668
3669 i40e_reprogram_flex_pit(pf);
3670 }
3671
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003672 return 0;
3673}
3674
3675/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003676 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003677 * @vsi: pointer to the targeted VSI
3678 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003679 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003680 * Add Flow Director filters for a specific flow spec based on their
3681 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003682 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003683static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3684 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003685{
Jacob Kellere7930952017-02-06 14:38:49 -08003686 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003687 struct ethtool_rx_flow_spec *fsp;
3688 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003689 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003690 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003691 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003692 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003693
3694 if (!vsi)
3695 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003696 pf = vsi->back;
3697
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003698 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3699 return -EOPNOTSUPP;
3700
Jacob Keller47994c12017-04-19 09:25:57 -04003701 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003702 return -ENOSPC;
3703
Jacob Keller0da36b92017-04-19 09:25:55 -04003704 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3705 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003706 return -EBUSY;
3707
Jacob Keller0da36b92017-04-19 09:25:55 -04003708 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003709 return -EBUSY;
3710
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003711 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3712
Jacob Kellere7930952017-02-06 14:38:49 -08003713 /* Parse the user-defined field */
3714 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3715 return -EINVAL;
3716
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003717 /* Extended MAC field is not supported */
3718 if (fsp->flow_type & FLOW_MAC_EXT)
3719 return -EINVAL;
3720
Jacob Keller0e588de2017-02-06 14:38:50 -08003721 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003722 if (ret)
3723 return ret;
3724
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003725 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3726 pf->hw.func_caps.fd_filters_guaranteed)) {
3727 return -EINVAL;
3728 }
3729
Jacob Keller43b15692017-02-06 14:38:48 -08003730 /* ring_cookie is either the drop index, or is a mask of the queue
3731 * index and VF id we wish to target.
3732 */
3733 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3734 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3735 } else {
3736 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3737 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3738
3739 if (!vf) {
3740 if (ring >= vsi->num_queue_pairs)
3741 return -EINVAL;
3742 dest_vsi = vsi->id;
3743 } else {
3744 /* VFs are zero-indexed, so we subtract one here */
3745 vf--;
3746
3747 if (vf >= pf->num_alloc_vfs)
3748 return -EINVAL;
3749 if (ring >= pf->vf[vf].num_queue_pairs)
3750 return -EINVAL;
3751 dest_vsi = pf->vf[vf].lan_vsi_id;
3752 }
3753 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3754 q_index = ring;
3755 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003756
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003757 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003758
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003759 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003760 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003761
3762 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003763 input->q_index = q_index;
3764 input->dest_vsi = dest_vsi;
3765 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003766 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04003767 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08003768 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3769 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08003770 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003771 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00003772
3773 /* Reverse the src and dest notion, since the HW expects them to be from
3774 * Tx perspective where as the input from user is from Rx filter view.
3775 */
3776 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
3777 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08003778 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3779 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003780
Jacob Keller0e588de2017-02-06 14:38:50 -08003781 if (userdef.flex_filter) {
3782 input->flex_filter = true;
3783 input->flex_word = cpu_to_be16(userdef.flex_word);
3784 input->flex_offset = userdef.flex_offset;
3785 }
3786
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003787 ret = i40e_add_del_fdir(vsi, input, true);
3788 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08003789 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003790
Jacob Keller01016da2017-02-06 14:38:40 -08003791 /* Add the input filter to the fdir_input_list, possibly replacing
3792 * a previous filter. Do not free the input structure after adding it
3793 * to the list as this would cause a use-after-free bug.
3794 */
3795 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
3796
3797 return 0;
3798
3799free_input:
3800 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003801 return ret;
3802}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003803
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003804/**
3805 * i40e_set_rxnfc - command to set RX flow classification rules
3806 * @netdev: network interface device structure
3807 * @cmd: ethtool rxnfc command
3808 *
3809 * Returns Success if the command is supported.
3810 **/
3811static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3812{
3813 struct i40e_netdev_priv *np = netdev_priv(netdev);
3814 struct i40e_vsi *vsi = np->vsi;
3815 struct i40e_pf *pf = vsi->back;
3816 int ret = -EOPNOTSUPP;
3817
3818 switch (cmd->cmd) {
3819 case ETHTOOL_SRXFH:
3820 ret = i40e_set_rss_hash_opt(pf, cmd);
3821 break;
3822 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003823 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003824 break;
3825 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003826 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003827 break;
3828 default:
3829 break;
3830 }
3831
3832 return ret;
3833}
3834
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003835/**
3836 * i40e_max_channels - get Max number of combined channels supported
3837 * @vsi: vsi pointer
3838 **/
3839static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
3840{
3841 /* TODO: This code assumes DCB and FD is disabled for now. */
3842 return vsi->alloc_queue_pairs;
3843}
3844
3845/**
3846 * i40e_get_channels - Get the current channels enabled and max supported etc.
3847 * @netdev: network interface device structure
3848 * @ch: ethtool channels structure
3849 *
3850 * We don't support separate tx and rx queues as channels. The other count
3851 * represents how many queues are being used for control. max_combined counts
3852 * how many queue pairs we can support. They may not be mapped 1 to 1 with
3853 * q_vectors since we support a lot more queue pairs than q_vectors.
3854 **/
3855static void i40e_get_channels(struct net_device *dev,
3856 struct ethtool_channels *ch)
3857{
3858 struct i40e_netdev_priv *np = netdev_priv(dev);
3859 struct i40e_vsi *vsi = np->vsi;
3860 struct i40e_pf *pf = vsi->back;
3861
3862 /* report maximum channels */
3863 ch->max_combined = i40e_max_channels(vsi);
3864
3865 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003866 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003867 ch->max_other = ch->other_count;
3868
3869 /* Note: This code assumes DCB is disabled for now. */
3870 ch->combined_count = vsi->num_queue_pairs;
3871}
3872
3873/**
3874 * i40e_set_channels - Set the new channels count.
3875 * @netdev: network interface device structure
3876 * @ch: ethtool channels structure
3877 *
3878 * The new channels count may not be the same as requested by the user
3879 * since it gets rounded down to a power of 2 value.
3880 **/
3881static int i40e_set_channels(struct net_device *dev,
3882 struct ethtool_channels *ch)
3883{
Jacob Keller59826d92016-07-27 12:02:35 -07003884 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003885 struct i40e_netdev_priv *np = netdev_priv(dev);
3886 unsigned int count = ch->combined_count;
3887 struct i40e_vsi *vsi = np->vsi;
3888 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07003889 struct i40e_fdir_filter *rule;
3890 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003891 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07003892 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003893
3894 /* We do not support setting channels for any other VSI at present */
3895 if (vsi->type != I40E_VSI_MAIN)
3896 return -EINVAL;
3897
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07003898 /* We do not support setting channels via ethtool when TCs are
3899 * configured through mqprio
3900 */
3901 if (pf->flags & I40E_FLAG_TC_MQPRIO)
3902 return -EINVAL;
3903
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003904 /* verify they are not requesting separate vectors */
3905 if (!count || ch->rx_count || ch->tx_count)
3906 return -EINVAL;
3907
3908 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003909 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003910 return -EINVAL;
3911
3912 /* verify the number of channels does not exceed hardware limits */
3913 if (count > i40e_max_channels(vsi))
3914 return -EINVAL;
3915
Jacob Keller59826d92016-07-27 12:02:35 -07003916 /* verify that the number of channels does not invalidate any current
3917 * flow director rules
3918 */
3919 hlist_for_each_entry_safe(rule, node2,
3920 &pf->fdir_filter_list, fdir_node) {
3921 if (rule->dest_ctl != drop && count <= rule->q_index) {
3922 dev_warn(&pf->pdev->dev,
3923 "Existing user defined filter %d assigns flow to queue %d\n",
3924 rule->fd_id, rule->q_index);
3925 err = -EINVAL;
3926 }
3927 }
3928
3929 if (err) {
3930 dev_err(&pf->pdev->dev,
3931 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
3932 count);
3933 return err;
3934 }
3935
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003936 /* update feature limits from largest to smallest supported values */
3937 /* TODO: Flow director limit, DCB etc */
3938
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003939 /* use rss_reconfig to rebuild with new queue count and update traffic
3940 * class queue mapping
3941 */
3942 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00003943 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003944 return 0;
3945 else
3946 return -EINVAL;
3947}
3948
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003949/**
3950 * i40e_get_rxfh_key_size - get the RSS hash key size
3951 * @netdev: network interface device structure
3952 *
3953 * Returns the table size.
3954 **/
3955static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
3956{
3957 return I40E_HKEY_ARRAY_SIZE;
3958}
3959
3960/**
3961 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
3962 * @netdev: network interface device structure
3963 *
3964 * Returns the table size.
3965 **/
3966static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
3967{
3968 return I40E_HLUT_ARRAY_SIZE;
3969}
3970
Alan Brady21675bd2017-10-05 14:53:33 -07003971/**
3972 * i40e_get_rxfh - get the rx flow hash indirection table
3973 * @netdev: network interface device structure
3974 * @indir: indirection table
3975 * @key: hash key
3976 * @hfunc: hash function
3977 *
3978 * Reads the indirection table directly from the hardware. Returns 0 on
3979 * success.
3980 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003981static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
3982 u8 *hfunc)
3983{
3984 struct i40e_netdev_priv *np = netdev_priv(netdev);
3985 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04003986 u8 *lut, *seed = NULL;
3987 int ret;
3988 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003989
3990 if (hfunc)
3991 *hfunc = ETH_RSS_HASH_TOP;
3992
3993 if (!indir)
3994 return 0;
3995
Helin Zhang043dd652015-10-21 19:56:23 -04003996 seed = key;
3997 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3998 if (!lut)
3999 return -ENOMEM;
4000 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
4001 if (ret)
4002 goto out;
4003 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4004 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004005
Helin Zhang043dd652015-10-21 19:56:23 -04004006out:
4007 kfree(lut);
4008
4009 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004010}
4011
4012/**
4013 * i40e_set_rxfh - set the rx flow hash indirection table
4014 * @netdev: network interface device structure
4015 * @indir: indirection table
4016 * @key: hash key
4017 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004018 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004019 * returns 0 after programming the table.
4020 **/
4021static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4022 const u8 *key, const u8 hfunc)
4023{
4024 struct i40e_netdev_priv *np = netdev_priv(netdev);
4025 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004026 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004027 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004028 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004029
4030 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4031 return -EOPNOTSUPP;
4032
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004033 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004034 if (!vsi->rss_hkey_user) {
4035 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4036 GFP_KERNEL);
4037 if (!vsi->rss_hkey_user)
4038 return -ENOMEM;
4039 }
4040 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4041 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004042 }
Helin Zhang28c58692015-10-26 19:44:27 -04004043 if (!vsi->rss_lut_user) {
4044 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4045 if (!vsi->rss_lut_user)
4046 return -ENOMEM;
4047 }
Helin Zhang043dd652015-10-21 19:56:23 -04004048
Helin Zhang28c58692015-10-26 19:44:27 -04004049 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004050 if (indir)
4051 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4052 vsi->rss_lut_user[i] = (u8)(indir[i]);
4053 else
4054 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4055 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004056
4057 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4058 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004059}
4060
Greg Rose7e45ab42015-02-06 08:52:19 +00004061/**
4062 * i40e_get_priv_flags - report device private flags
4063 * @dev: network interface device structure
4064 *
4065 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004066 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004067 * array.
4068 *
4069 * Returns a u32 bitmap of flags.
4070 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004071static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004072{
4073 struct i40e_netdev_priv *np = netdev_priv(dev);
4074 struct i40e_vsi *vsi = np->vsi;
4075 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004076 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004077
Alexander Duyckaca955d2017-03-10 12:22:01 -08004078 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4079 const struct i40e_priv_flags *priv_flags;
4080
4081 priv_flags = &i40e_gstrings_priv_flags[i];
4082
4083 if (priv_flags->flag & pf->flags)
4084 ret_flags |= BIT(i);
4085 }
4086
4087 if (pf->hw.pf_id != 0)
4088 return ret_flags;
4089
4090 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4091 const struct i40e_priv_flags *priv_flags;
4092
4093 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4094
4095 if (priv_flags->flag & pf->flags)
4096 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004097 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004098
4099 return ret_flags;
4100}
4101
Shannon Nelson9ac77262015-08-27 11:42:40 -04004102/**
4103 * i40e_set_priv_flags - set private flags
4104 * @dev: network interface device structure
4105 * @flags: bit flags to be set
4106 **/
4107static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4108{
4109 struct i40e_netdev_priv *np = netdev_priv(dev);
4110 struct i40e_vsi *vsi = np->vsi;
4111 struct i40e_pf *pf = vsi->back;
Jacob Kellerb74f5712017-09-01 13:54:07 -07004112 u32 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004113 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004114
Jacob Keller841c9502017-06-23 04:24:50 -04004115 orig_flags = READ_ONCE(pf->flags);
4116 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004117
Alexander Duyckaca955d2017-03-10 12:22:01 -08004118 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4119 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004120
Alexander Duyckaca955d2017-03-10 12:22:01 -08004121 priv_flags = &i40e_gstrings_priv_flags[i];
4122
Alexander Duyckaca955d2017-03-10 12:22:01 -08004123 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004124 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004125 else
Jacob Keller841c9502017-06-23 04:24:50 -04004126 new_flags &= ~(priv_flags->flag);
4127
4128 /* If this is a read-only flag, it can't be changed */
4129 if (priv_flags->read_only &&
4130 ((orig_flags ^ new_flags) & ~BIT(i)))
4131 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004132 }
4133
4134 if (pf->hw.pf_id != 0)
4135 goto flags_complete;
4136
4137 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4138 const struct i40e_priv_flags *priv_flags;
4139
4140 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4141
Alexander Duyckaca955d2017-03-10 12:22:01 -08004142 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004143 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004144 else
Jacob Keller841c9502017-06-23 04:24:50 -04004145 new_flags &= ~(priv_flags->flag);
4146
4147 /* If this is a read-only flag, it can't be changed */
4148 if (priv_flags->read_only &&
4149 ((orig_flags ^ new_flags) & ~BIT(i)))
4150 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004151 }
4152
4153flags_complete:
Jacob Keller841c9502017-06-23 04:24:50 -04004154 /* Before we finalize any flag changes, we need to perform some
4155 * checks to ensure that the changes are supported and safe.
4156 */
4157
4158 /* ATR eviction is not supported on all devices */
4159 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4160 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4161 return -EOPNOTSUPP;
4162
4163 /* Compare and exchange the new flags into place. If we failed, that
Jacob Kellerb74f5712017-09-01 13:54:07 -07004164 * is if cmpxchg returns anything but the old value, this means that
Jacob Keller841c9502017-06-23 04:24:50 -04004165 * something else has modified the flags variable since we copied it
4166 * originally. We'll just punt with an error and log something in the
4167 * message buffer.
4168 */
Jacob Kellerb74f5712017-09-01 13:54:07 -07004169 if (cmpxchg(&pf->flags, orig_flags, new_flags) != orig_flags) {
Jacob Keller841c9502017-06-23 04:24:50 -04004170 dev_warn(&pf->pdev->dev,
4171 "Unable to update pf->flags as it was modified by another thread...\n");
4172 return -EAGAIN;
4173 }
4174
4175 changed_flags = orig_flags ^ new_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004176
4177 /* Process any additional changes needed as a result of flag changes.
4178 * The changed_flags value reflects the list of bits that were
4179 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004180 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004181
Alexander Duyckaca955d2017-03-10 12:22:01 -08004182 /* Flush current ATR settings if ATR was disabled */
4183 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4184 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004185 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004186 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004187 }
4188
Alexander Duyckaca955d2017-03-10 12:22:01 -08004189 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4190 u16 sw_flags = 0, valid_flags = 0;
4191 int ret;
4192
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004193 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4194 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4195 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4196 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4197 NULL);
4198 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4199 dev_info(&pf->pdev->dev,
4200 "couldn't set switch config bits, err %s aq_err %s\n",
4201 i40e_stat_str(&pf->hw, ret),
4202 i40e_aq_str(&pf->hw,
4203 pf->hw.aq.asq_last_status));
4204 /* not a fatal problem, just keep going */
4205 }
4206 }
4207
Alexander Duyckaca955d2017-03-10 12:22:01 -08004208 /* Issue reset to cause things to take effect, as additional bits
4209 * are added we will need to create a mask of bits requiring reset
4210 */
Mitch Williams64615b52017-08-29 05:32:30 -04004211 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4212 I40E_FLAG_LEGACY_RX |
4213 I40E_FLAG_SOURCE_PRUNING_DISABLED))
Maciej Sosin373149f2017-04-05 07:50:55 -04004214 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004215
Shannon Nelson9ac77262015-08-27 11:42:40 -04004216 return 0;
4217}
4218
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004219/**
4220 * i40e_get_module_info - get (Q)SFP+ module type info
4221 * @netdev: network interface device structure
4222 * @modinfo: module EEPROM size and layout information structure
4223 **/
4224static int i40e_get_module_info(struct net_device *netdev,
4225 struct ethtool_modinfo *modinfo)
4226{
4227 struct i40e_netdev_priv *np = netdev_priv(netdev);
4228 struct i40e_vsi *vsi = np->vsi;
4229 struct i40e_pf *pf = vsi->back;
4230 struct i40e_hw *hw = &pf->hw;
4231 u32 sff8472_comp = 0;
4232 u32 sff8472_swap = 0;
4233 u32 sff8636_rev = 0;
4234 i40e_status status;
4235 u32 type = 0;
4236
4237 /* Check if firmware supports reading module EEPROM. */
4238 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4239 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4240 return -EINVAL;
4241 }
4242
4243 status = i40e_update_link_info(hw);
4244 if (status)
4245 return -EIO;
4246
4247 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4248 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4249 return -EINVAL;
4250 }
4251
4252 type = hw->phy.link_info.module_type[0];
4253
4254 switch (type) {
4255 case I40E_MODULE_TYPE_SFP:
4256 status = i40e_aq_get_phy_register(hw,
4257 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4258 I40E_I2C_EEPROM_DEV_ADDR,
4259 I40E_MODULE_SFF_8472_COMP,
4260 &sff8472_comp, NULL);
4261 if (status)
4262 return -EIO;
4263
4264 status = i40e_aq_get_phy_register(hw,
4265 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4266 I40E_I2C_EEPROM_DEV_ADDR,
4267 I40E_MODULE_SFF_8472_SWAP,
4268 &sff8472_swap, NULL);
4269 if (status)
4270 return -EIO;
4271
4272 /* Check if the module requires address swap to access
4273 * the other EEPROM memory page.
4274 */
4275 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4276 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4277 modinfo->type = ETH_MODULE_SFF_8079;
4278 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4279 } else if (sff8472_comp == 0x00) {
4280 /* Module is not SFF-8472 compliant */
4281 modinfo->type = ETH_MODULE_SFF_8079;
4282 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4283 } else {
4284 modinfo->type = ETH_MODULE_SFF_8472;
4285 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4286 }
4287 break;
4288 case I40E_MODULE_TYPE_QSFP_PLUS:
4289 /* Read from memory page 0. */
4290 status = i40e_aq_get_phy_register(hw,
4291 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4292 0,
4293 I40E_MODULE_REVISION_ADDR,
4294 &sff8636_rev, NULL);
4295 if (status)
4296 return -EIO;
4297 /* Determine revision compliance byte */
4298 if (sff8636_rev > 0x02) {
4299 /* Module is SFF-8636 compliant */
4300 modinfo->type = ETH_MODULE_SFF_8636;
4301 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4302 } else {
4303 modinfo->type = ETH_MODULE_SFF_8436;
4304 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4305 }
4306 break;
4307 case I40E_MODULE_TYPE_QSFP28:
4308 modinfo->type = ETH_MODULE_SFF_8636;
4309 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4310 break;
4311 default:
4312 netdev_err(vsi->netdev, "Module type unrecognized\n");
4313 return -EINVAL;
4314 }
4315 return 0;
4316}
4317
4318/**
4319 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4320 * @netdev: network interface device structure
4321 * @ee: EEPROM dump request structure
4322 * @data: buffer to be filled with EEPROM contents
4323 **/
4324static int i40e_get_module_eeprom(struct net_device *netdev,
4325 struct ethtool_eeprom *ee,
4326 u8 *data)
4327{
4328 struct i40e_netdev_priv *np = netdev_priv(netdev);
4329 struct i40e_vsi *vsi = np->vsi;
4330 struct i40e_pf *pf = vsi->back;
4331 struct i40e_hw *hw = &pf->hw;
4332 bool is_sfp = false;
4333 i40e_status status;
4334 u32 value = 0;
4335 int i;
4336
4337 if (!ee || !ee->len || !data)
4338 return -EINVAL;
4339
4340 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4341 is_sfp = true;
4342
4343 for (i = 0; i < ee->len; i++) {
4344 u32 offset = i + ee->offset;
4345 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4346
4347 /* Check if we need to access the other memory page */
4348 if (is_sfp) {
4349 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4350 offset -= ETH_MODULE_SFF_8079_LEN;
4351 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4352 }
4353 } else {
4354 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4355 /* Compute memory page number and offset. */
4356 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4357 addr++;
4358 }
4359 }
4360
4361 status = i40e_aq_get_phy_register(hw,
4362 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4363 addr, offset, &value, NULL);
4364 if (status)
4365 return -EIO;
4366 data[i] = value;
4367 }
4368 return 0;
4369}
4370
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004371static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004372 .get_drvinfo = i40e_get_drvinfo,
4373 .get_regs_len = i40e_get_regs_len,
4374 .get_regs = i40e_get_regs,
4375 .nway_reset = i40e_nway_reset,
4376 .get_link = ethtool_op_get_link,
4377 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004378 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004379 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004380 .get_eeprom_len = i40e_get_eeprom_len,
4381 .get_eeprom = i40e_get_eeprom,
4382 .get_ringparam = i40e_get_ringparam,
4383 .set_ringparam = i40e_set_ringparam,
4384 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004385 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004386 .get_msglevel = i40e_get_msglevel,
4387 .set_msglevel = i40e_set_msglevel,
4388 .get_rxnfc = i40e_get_rxnfc,
4389 .set_rxnfc = i40e_set_rxnfc,
4390 .self_test = i40e_diag_test,
4391 .get_strings = i40e_get_strings,
4392 .set_phys_id = i40e_set_phys_id,
4393 .get_sset_count = i40e_get_sset_count,
4394 .get_ethtool_stats = i40e_get_ethtool_stats,
4395 .get_coalesce = i40e_get_coalesce,
4396 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004397 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4398 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4399 .get_rxfh = i40e_get_rxfh,
4400 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004401 .get_channels = i40e_get_channels,
4402 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004403 .get_module_info = i40e_get_module_info,
4404 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004405 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004406 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004407 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004408 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004409 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004410 .get_link_ksettings = i40e_get_link_ksettings,
4411 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004412};
4413
4414void i40e_set_ethtool_ops(struct net_device *netdev)
4415{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004416 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004417}