blob: a4210ccdaa5f2469bab04b40043527e325109b19 [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
Alan Brady52e2d022017-10-05 14:53:35 -0700256 * @pf: PF struct with phy_types
Catherine Sullivan06566e52016-05-03 15:13:14 -0700257 * @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) {
Alan Brady6987bd252017-10-05 14:53:38 -0700271 *supported |= SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700272 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
273 *advertising |= ADVERTISED_1000baseT_Full;
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400274 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Catherine Sullivan06566e52016-05-03 15:13:14 -0700275 *supported |= SUPPORTED_100baseT_Full;
276 *advertising |= ADVERTISED_100baseT_Full;
277 }
278 }
279 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
280 phy_types & I40E_CAP_PHY_TYPE_XFI ||
281 phy_types & I40E_CAP_PHY_TYPE_SFI ||
282 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
283 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
284 *supported |= SUPPORTED_10000baseT_Full;
285 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
286 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
287 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
288 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
289 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
Alan Brady6987bd252017-10-05 14:53:38 -0700290 *supported |= SUPPORTED_10000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700291 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
292 *advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700293 }
294 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
295 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
296 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
297 *supported |= SUPPORTED_40000baseCR4_Full;
298 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
299 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
Alan Brady6987bd252017-10-05 14:53:38 -0700300 *supported |= SUPPORTED_40000baseCR4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700301 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB)
302 *advertising |= ADVERTISED_40000baseCR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700303 }
Avinash Dayanand01a7a9f2016-05-16 10:26:40 -0700304 if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Alan Brady6987bd252017-10-05 14:53:38 -0700305 *supported |= SUPPORTED_100baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700306 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
307 *advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700308 }
309 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
310 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
311 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
312 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
Alan Brady6987bd252017-10-05 14:53:38 -0700313 *supported |= SUPPORTED_1000baseT_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700314 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
315 *advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700316 }
317 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
318 *supported |= SUPPORTED_40000baseSR4_Full;
319 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
320 *supported |= SUPPORTED_40000baseLR4_Full;
321 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
Alan Brady6987bd252017-10-05 14:53:38 -0700322 *supported |= SUPPORTED_40000baseKR4_Full;
323 *advertising |= ADVERTISED_40000baseKR4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700324 }
325 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
Alan Brady6987bd252017-10-05 14:53:38 -0700326 *supported |= SUPPORTED_20000baseKR2_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700327 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB)
328 *advertising |= ADVERTISED_20000baseKR2_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700329 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700330 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
Alan Brady6987bd252017-10-05 14:53:38 -0700331 *supported |= SUPPORTED_10000baseKX4_Full;
Avinash Dayanand28537042016-06-20 09:10:33 -0700332 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
333 *advertising |= ADVERTISED_10000baseKX4_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700334 }
Alan Brady6987bd252017-10-05 14:53:38 -0700335 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR &&
336 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
337 *supported |= SUPPORTED_10000baseKR_Full;
338 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
339 *advertising |= ADVERTISED_10000baseKR_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700340 }
Alan Brady6987bd252017-10-05 14:53:38 -0700341 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX &&
342 !(pf->hw_features & I40E_HW_HAVE_CRT_RETIMER)) {
343 *supported |= SUPPORTED_1000baseKX_Full;
344 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
345 *advertising |= ADVERTISED_1000baseKX_Full;
346 }
347 /* Autoneg PHY types */
348 if (phy_types & I40E_CAP_PHY_TYPE_SGMII ||
349 phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4 ||
350 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
351 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4 ||
Carolyn Wyborny31232372016-11-21 13:03:48 -0800352 phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR ||
Alan Brady6987bd252017-10-05 14:53:38 -0700353 phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR ||
354 phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR ||
355 phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR ||
356 phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2 ||
357 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
358 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
359 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR ||
360 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4 ||
361 phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR ||
362 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
363 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
364 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL ||
365 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
366 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
367 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
368 phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX ||
369 phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) {
Carolyn Wyborny31232372016-11-21 13:03:48 -0800370 *supported |= SUPPORTED_Autoneg;
371 *advertising |= ADVERTISED_Autoneg;
372 }
Catherine Sullivan06566e52016-05-03 15:13:14 -0700373}
374
375/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000376 * i40e_get_settings_link_up - Get the Link settings for when link is up
377 * @hw: hw structure
Alan Brady1c142e12017-10-05 14:53:31 -0700378 * @ks: ethtool ksettings to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000379 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700380 * @pf: pointer to physical function struct
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000381 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000382static void i40e_get_settings_link_up(struct i40e_hw *hw,
Alan Brady1c142e12017-10-05 14:53:31 -0700383 struct ethtool_link_ksettings *ks,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400384 struct net_device *netdev,
385 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000386{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000387 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000388 u32 link_speed = hw_link_info->link_speed;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700389 u32 e_advertising = 0x0;
390 u32 e_supported = 0x0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100391 u32 supported, advertising;
392
393 ethtool_convert_link_mode_to_legacy_u32(&supported,
Alan Brady1c142e12017-10-05 14:53:31 -0700394 ks->link_modes.supported);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100395 ethtool_convert_link_mode_to_legacy_u32(&advertising,
Alan Brady1c142e12017-10-05 14:53:31 -0700396 ks->link_modes.advertising);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000397
Catherine Sullivane8278452015-02-06 08:52:08 +0000398 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000399 switch (hw_link_info->phy_type) {
400 case I40E_PHY_TYPE_40GBASE_CR4:
401 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100402 supported = SUPPORTED_Autoneg |
403 SUPPORTED_40000baseCR4_Full;
404 advertising = ADVERTISED_Autoneg |
405 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000406 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000407 case I40E_PHY_TYPE_XLAUI:
408 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000409 case I40E_PHY_TYPE_40GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100410 supported = SUPPORTED_40000baseCR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000411 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000412 case I40E_PHY_TYPE_40GBASE_SR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100413 supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000414 break;
415 case I40E_PHY_TYPE_40GBASE_LR4:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100416 supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000417 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000418 case I40E_PHY_TYPE_10GBASE_SR:
419 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000420 case I40E_PHY_TYPE_1000BASE_SX:
421 case I40E_PHY_TYPE_1000BASE_LX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100422 supported = SUPPORTED_10000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400423 if (hw_link_info->module_type[2] &
424 I40E_MODULE_TYPE_1000BASE_SX ||
425 hw_link_info->module_type[2] &
426 I40E_MODULE_TYPE_1000BASE_LX) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100427 supported |= SUPPORTED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400428 if (hw_link_info->requested_speeds &
429 I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100430 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400431 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000432 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100433 advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000434 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000435 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000436 case I40E_PHY_TYPE_1000BASE_T:
Catherine Sullivan06566e52016-05-03 15:13:14 -0700437 case I40E_PHY_TYPE_100BASE_TX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100438 supported = SUPPORTED_Autoneg |
439 SUPPORTED_10000baseT_Full |
440 SUPPORTED_1000baseT_Full |
441 SUPPORTED_100baseT_Full;
442 advertising = ADVERTISED_Autoneg;
Catherine Sullivane8278452015-02-06 08:52:08 +0000443 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100444 advertising |= ADVERTISED_10000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000445 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100446 advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan06566e52016-05-03 15:13:14 -0700447 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100448 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400449 break;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400450 case I40E_PHY_TYPE_1000BASE_T_OPTICAL:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100451 supported = SUPPORTED_Autoneg |
452 SUPPORTED_1000baseT_Full;
453 advertising = ADVERTISED_Autoneg |
454 ADVERTISED_1000baseT_Full;
Catherine Sullivan48becae2015-09-28 14:12:41 -0400455 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000456 case I40E_PHY_TYPE_10GBASE_CR1_CU:
457 case I40E_PHY_TYPE_10GBASE_CR1:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100458 supported = SUPPORTED_Autoneg |
459 SUPPORTED_10000baseT_Full;
460 advertising = ADVERTISED_Autoneg |
461 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000462 break;
463 case I40E_PHY_TYPE_XAUI:
464 case I40E_PHY_TYPE_XFI:
465 case I40E_PHY_TYPE_SFI:
466 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000467 case I40E_PHY_TYPE_10GBASE_AOC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100468 supported = SUPPORTED_10000baseT_Full;
469 advertising = SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000470 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000471 case I40E_PHY_TYPE_SGMII:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100472 supported = SUPPORTED_Autoneg |
473 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000474 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100475 advertising |= ADVERTISED_1000baseT_Full;
Jacob Kellerd36e41d2017-06-23 04:24:46 -0400476 if (pf->hw_features & I40E_HW_100M_SGMII_CAPABLE) {
Philippe Reynesa7f90942017-02-04 22:05:06 +0100477 supported |= SUPPORTED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400478 if (hw_link_info->requested_speeds &
479 I40E_LINK_SPEED_100MB)
Philippe Reynesa7f90942017-02-04 22:05:06 +0100480 advertising |= ADVERTISED_100baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400481 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000482 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400483 case I40E_PHY_TYPE_40GBASE_KR4:
484 case I40E_PHY_TYPE_20GBASE_KR2:
485 case I40E_PHY_TYPE_10GBASE_KR:
486 case I40E_PHY_TYPE_10GBASE_KX4:
487 case I40E_PHY_TYPE_1000BASE_KX:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100488 supported |= SUPPORTED_40000baseKR4_Full |
489 SUPPORTED_20000baseKR2_Full |
490 SUPPORTED_10000baseKR_Full |
491 SUPPORTED_10000baseKX4_Full |
492 SUPPORTED_1000baseKX_Full |
493 SUPPORTED_Autoneg;
494 advertising |= ADVERTISED_40000baseKR4_Full |
495 ADVERTISED_20000baseKR2_Full |
496 ADVERTISED_10000baseKR_Full |
497 ADVERTISED_10000baseKX4_Full |
498 ADVERTISED_1000baseKX_Full |
499 ADVERTISED_Autoneg;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400500 break;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800501 case I40E_PHY_TYPE_25GBASE_KR:
502 case I40E_PHY_TYPE_25GBASE_CR:
503 case I40E_PHY_TYPE_25GBASE_SR:
504 case I40E_PHY_TYPE_25GBASE_LR:
Sudheer Mogilappagari211b4c12017-10-05 14:53:39 -0700505 case I40E_PHY_TYPE_25GBASE_AOC:
506 case I40E_PHY_TYPE_25GBASE_ACC:
Philippe Reynesa7f90942017-02-04 22:05:06 +0100507 supported = SUPPORTED_Autoneg;
508 advertising = ADVERTISED_Autoneg;
Carolyn Wyborny31232372016-11-21 13:03:48 -0800509 /* TODO: add speeds when ethtool is ready to support*/
510 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000511 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000512 /* if we got here and link is up something bad is afoot */
Alan Bradya03af692017-10-05 14:53:37 -0700513 netdev_info(netdev,
514 "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
Catherine Sullivan124ed152014-07-12 07:28:12 +0000515 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
Alan Brady91a5c442017-10-05 14:53:36 -0700519 * current PHY type, get what is supported by the NVM and intersect
520 * them to get what is truly supported
Catherine Sullivan06566e52016-05-03 15:13:14 -0700521 */
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;
Alan Brady5f434992017-10-05 14:53:34 -0700603
604 ethtool_link_ksettings_zero_link_mode(ks, supported);
605 ethtool_link_ksettings_zero_link_mode(ks, advertising);
Catherine Sullivane8278452015-02-06 08:52:08 +0000606
607 if (link_up)
Alan Brady1c142e12017-10-05 14:53:31 -0700608 i40e_get_settings_link_up(hw, ks, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000609 else
Alan Brady1c142e12017-10-05 14:53:31 -0700610 i40e_get_settings_link_down(hw, ks, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000611
612 /* Now set the settings that don't rely on link being up/down */
Catherine Sullivane8278452015-02-06 08:52:08 +0000613 /* Set autoneg settings */
Alan Brady1c142e12017-10-05 14:53:31 -0700614 ks->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
615 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000616
Alan Bradya03af692017-10-05 14:53:37 -0700617 /* Set media type settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000618 switch (hw->phy.media_type) {
619 case I40E_MEDIA_TYPE_BACKPLANE:
Alan Bradya03af692017-10-05 14:53:37 -0700620 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
621 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
622 ethtool_link_ksettings_add_link_mode(ks, advertising, 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 Bradya03af692017-10-05 14:53:37 -0700653 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000654 break;
655 case I40E_FC_TX_PAUSE:
Alan Brady1c142e12017-10-05 14:53:31 -0700656 ethtool_link_ksettings_add_link_mode(ks, advertising,
Philippe Reynesa7f90942017-02-04 22:05:06 +0100657 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000658 break;
659 case I40E_FC_RX_PAUSE:
Alan Bradya03af692017-10-05 14:53:37 -0700660 ethtool_link_ksettings_add_link_mode(ks, advertising, 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 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000663 break;
664 default:
Alan Brady5f434992017-10-05 14:53:34 -0700665 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
666 ethtool_link_ksettings_del_link_mode(ks, advertising,
667 Asym_Pause);
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000668 break;
669 }
670
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000671 return 0;
672}
673
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000674/**
Alan Brady1c142e12017-10-05 14:53:31 -0700675 * i40e_set_link_ksettings - Set Speed and Duplex
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000676 * @netdev: network interface device structure
Alan Brady1c142e12017-10-05 14:53:31 -0700677 * @ks: ethtool ksettings
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000678 *
679 * Set speed/duplex per media_types advertised/forced
680 **/
Philippe Reynesa7f90942017-02-04 22:05:06 +0100681static int i40e_set_link_ksettings(struct net_device *netdev,
Alan Brady1c142e12017-10-05 14:53:31 -0700682 const struct ethtool_link_ksettings *ks)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000683{
684 struct i40e_netdev_priv *np = netdev_priv(netdev);
685 struct i40e_aq_get_phy_abilities_resp abilities;
686 struct i40e_aq_set_phy_config config;
687 struct i40e_pf *pf = np->vsi->back;
688 struct i40e_vsi *vsi = np->vsi;
689 struct i40e_hw *hw = &pf->hw;
Alan Brady1c142e12017-10-05 14:53:31 -0700690 struct ethtool_link_ksettings safe_ks;
691 struct ethtool_link_ksettings copy_ks;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000692 i40e_status status = 0;
693 bool change = false;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400694 int timeout = 50;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000695 int err = 0;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100696 u32 autoneg;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000697 u32 advertise;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100698 u32 tmp;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000699
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000700 /* Changing port settings is not supported if this isn't the
701 * port's controlling PF
702 */
703 if (hw->partition_id != 1) {
704 i40e_partition_setting_complaint(pf);
705 return -EOPNOTSUPP;
706 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000707 if (vsi != pf->vsi[pf->lan_vsi])
708 return -EOPNOTSUPP;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000709 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
710 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000711 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
Serey Kong65362272016-05-16 10:26:39 -0700712 hw->phy.media_type != I40E_MEDIA_TYPE_DA &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000713 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000714 return -EOPNOTSUPP;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400715 if (hw->device_id == I40E_DEV_ID_KX_B ||
716 hw->device_id == I40E_DEV_ID_KX_C ||
717 hw->device_id == I40E_DEV_ID_20G_KR2 ||
718 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
719 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
720 return -EOPNOTSUPP;
721 }
722
Alan Brady1c142e12017-10-05 14:53:31 -0700723 /* copy the ksettings to copy_ks to avoid modifying the origin */
724 memcpy(&copy_ks, ks, sizeof(struct ethtool_link_ksettings));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000725
Philippe Reynesa7f90942017-02-04 22:05:06 +0100726 /* get our own copy of the bits to check against */
Alan Brady1c142e12017-10-05 14:53:31 -0700727 memset(&safe_ks, 0, sizeof(struct ethtool_link_ksettings));
728 i40e_get_link_ksettings(netdev, &safe_ks);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100729
Alan Brady1c142e12017-10-05 14:53:31 -0700730 /* save autoneg and speed out of ksettings */
731 autoneg = ks->base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100732 ethtool_convert_link_mode_to_legacy_u32(&advertise,
Alan Brady1c142e12017-10-05 14:53:31 -0700733 ks->link_modes.advertising);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000734
735 /* set autoneg and speed back to what they currently are */
Alan Brady1c142e12017-10-05 14:53:31 -0700736 copy_ks.base.autoneg = safe_ks.base.autoneg;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100737 ethtool_convert_link_mode_to_legacy_u32(
Alan Brady1c142e12017-10-05 14:53:31 -0700738 &tmp, safe_ks.link_modes.advertising);
Philippe Reynesa7f90942017-02-04 22:05:06 +0100739 ethtool_convert_legacy_u32_to_link_mode(
Alan Brady1c142e12017-10-05 14:53:31 -0700740 copy_ks.link_modes.advertising, tmp);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000741
Alan Brady1c142e12017-10-05 14:53:31 -0700742 copy_ks.base.cmd = safe_ks.base.cmd;
Philippe Reynesa7f90942017-02-04 22:05:06 +0100743
Alan Brady1c142e12017-10-05 14:53:31 -0700744 /* If copy_ks and safe_ks are not the same now, then they are
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000745 * trying to set something that we do not support
746 */
Alan Brady1c142e12017-10-05 14:53:31 -0700747 if (memcmp(&copy_ks, &safe_ks, sizeof(struct ethtool_link_ksettings)))
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000748 return -EOPNOTSUPP;
749
Jacob Keller0da36b92017-04-19 09:25:55 -0400750 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400751 timeout--;
752 if (!timeout)
753 return -EBUSY;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000754 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400755 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000756
757 /* Get the current phy config */
758 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
759 NULL);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400760 if (status) {
761 err = -EAGAIN;
762 goto done;
763 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000764
Catherine Sullivan124ed152014-07-12 07:28:12 +0000765 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000766 * set below
767 */
768 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000769 config.abilities = abilities.abilities;
770
771 /* Check autoneg */
772 if (autoneg == AUTONEG_ENABLE) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000773 /* If autoneg was not already enabled */
774 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400775 /* If autoneg is not supported, return error */
Alan Brady1c142e12017-10-05 14:53:31 -0700776 if (!ethtool_link_ksettings_test_link_mode(&safe_ks,
777 supported,
778 Autoneg)) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400779 netdev_info(netdev, "Autoneg not supported on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400780 err = -EINVAL;
781 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400782 }
783 /* Autoneg is allowed to change */
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000784 config.abilities = abilities.abilities |
785 I40E_AQ_PHY_ENABLE_AN;
786 change = true;
787 }
788 } else {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000789 /* If autoneg is currently enabled */
790 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400791 /* If autoneg is supported 10GBASE_T is the only PHY
792 * that can disable it, so otherwise return error
793 */
Alan Brady1c142e12017-10-05 14:53:31 -0700794 if (ethtool_link_ksettings_test_link_mode(&safe_ks,
795 supported,
796 Autoneg) &&
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400797 hw->phy.link_info.phy_type !=
798 I40E_PHY_TYPE_10GBASE_T) {
799 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400800 err = -EINVAL;
801 goto done;
Catherine Sullivan3ce12ee2015-09-28 14:16:58 -0400802 }
803 /* Autoneg is allowed to change */
Mitch Williams5960d332014-09-13 07:40:47 +0000804 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000805 ~I40E_AQ_PHY_ENABLE_AN;
806 change = true;
807 }
808 }
809
Philippe Reynesa7f90942017-02-04 22:05:06 +0100810 ethtool_convert_link_mode_to_legacy_u32(&tmp,
Alan Brady1c142e12017-10-05 14:53:31 -0700811 safe_ks.link_modes.supported);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400812 if (advertise & ~tmp) {
813 err = -EINVAL;
814 goto done;
815 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000816
817 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000818 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000819 if (advertise & ADVERTISED_1000baseT_Full ||
820 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000821 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000822 if (advertise & ADVERTISED_10000baseT_Full ||
823 advertise & ADVERTISED_10000baseKX4_Full ||
824 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000825 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700826 if (advertise & ADVERTISED_20000baseKR2_Full)
827 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000828 if (advertise & ADVERTISED_40000baseKR4_Full ||
829 advertise & ADVERTISED_40000baseCR4_Full ||
830 advertise & ADVERTISED_40000baseSR4_Full ||
831 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000832 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000833
Catherine Sullivan0002e112015-08-26 15:14:16 -0400834 /* If speed didn't get set, set it to what it currently is.
835 * This is needed because if advertise is 0 (as it is when autoneg
836 * is disabled) then speed won't get set.
837 */
838 if (!config.link_speed)
839 config.link_speed = abilities.link_speed;
Catherine Sullivan124ed152014-07-12 07:28:12 +0000840 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000841 /* copy over the rest of the abilities */
842 config.phy_type = abilities.phy_type;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800843 config.phy_type_ext = abilities.phy_type_ext;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000844 config.eee_capability = abilities.eee_capability;
845 config.eeer = abilities.eeer_val;
846 config.low_power_ctrl = abilities.d3_lpan;
Henry Tiemanb7eaf8f2016-12-02 12:33:01 -0800847 config.fec_config = abilities.fec_cfg_curr_mod_ext_info &
848 I40E_AQ_PHY_FEC_CONFIG_MASK;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000849
Catherine Sullivane8278452015-02-06 08:52:08 +0000850 /* save the requested speeds */
851 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000852 /* set link and auto negotiation so changes take effect */
853 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
854 /* If link is up put link down */
855 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
856 /* Tell the OS link is going down, the link will go
857 * back up when fw says it is ready asynchronously
858 */
Matt Jaredc156f852015-08-27 11:42:39 -0400859 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000860 netif_carrier_off(netdev);
861 netif_tx_stop_all_queues(netdev);
862 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000863
864 /* make the aq call */
865 status = i40e_aq_set_phy_config(hw, &config, NULL);
866 if (status) {
Alan Bradya03af692017-10-05 14:53:37 -0700867 netdev_info(netdev,
868 "Set phy config failed, err %s aq_err %s\n",
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400869 i40e_stat_str(hw, status),
870 i40e_aq_str(hw, hw->aq.asq_last_status));
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400871 err = -EAGAIN;
872 goto done;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000873 }
874
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400875 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000876 if (status)
Alan Bradya03af692017-10-05 14:53:37 -0700877 netdev_dbg(netdev,
878 "Updating link info failed with err %s aq_err %s\n",
Catherine Sullivan52e96892015-09-28 14:16:59 -0400879 i40e_stat_str(hw, status),
880 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000881
882 } else {
883 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
884 }
885
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400886done:
Jacob Keller0da36b92017-04-19 09:25:55 -0400887 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -0400888
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000889 return err;
890}
891
Jesse Brandeburga6599722014-06-04 08:45:25 +0000892static int i40e_nway_reset(struct net_device *netdev)
893{
894 /* restart autonegotiation */
895 struct i40e_netdev_priv *np = netdev_priv(netdev);
896 struct i40e_pf *pf = np->vsi->back;
897 struct i40e_hw *hw = &pf->hw;
898 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
899 i40e_status ret = 0;
900
901 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
902 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400903 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
904 i40e_stat_str(hw, ret),
905 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000906 return -EIO;
907 }
908
909 return 0;
910}
911
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000912/**
913 * i40e_get_pauseparam - Get Flow Control status
914 * Return tx/rx-pause status
915 **/
916static void i40e_get_pauseparam(struct net_device *netdev,
917 struct ethtool_pauseparam *pause)
918{
919 struct i40e_netdev_priv *np = netdev_priv(netdev);
920 struct i40e_pf *pf = np->vsi->back;
921 struct i40e_hw *hw = &pf->hw;
922 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000923 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000924
925 pause->autoneg =
926 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
927 AUTONEG_ENABLE : AUTONEG_DISABLE);
928
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000929 /* PFC enabled so report LFC as off */
930 if (dcbx_cfg->pfc.pfcenable) {
931 pause->rx_pause = 0;
932 pause->tx_pause = 0;
933 return;
934 }
935
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000936 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000937 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000938 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000939 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000940 } else if (hw->fc.current_mode == I40E_FC_FULL) {
941 pause->rx_pause = 1;
942 pause->tx_pause = 1;
943 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000944}
945
Catherine Sullivan2becc352014-06-04 08:45:27 +0000946/**
947 * i40e_set_pauseparam - Set Flow Control parameter
948 * @netdev: network interface device structure
949 * @pause: return tx/rx flow control status
950 **/
951static int i40e_set_pauseparam(struct net_device *netdev,
952 struct ethtool_pauseparam *pause)
953{
954 struct i40e_netdev_priv *np = netdev_priv(netdev);
955 struct i40e_pf *pf = np->vsi->back;
956 struct i40e_vsi *vsi = np->vsi;
957 struct i40e_hw *hw = &pf->hw;
958 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000959 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000960 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
961 i40e_status status;
962 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000963 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000964
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000965 /* Changing the port's flow control is not supported if this isn't the
966 * port's controlling PF
967 */
968 if (hw->partition_id != 1) {
969 i40e_partition_setting_complaint(pf);
970 return -EOPNOTSUPP;
971 }
972
Catherine Sullivan2becc352014-06-04 08:45:27 +0000973 if (vsi != pf->vsi[pf->lan_vsi])
974 return -EOPNOTSUPP;
975
976 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
977 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
978 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
979 return -EOPNOTSUPP;
980 }
981
982 /* If we have link and don't have autoneg */
Jacob Keller0da36b92017-04-19 09:25:55 -0400983 if (!test_bit(__I40E_DOWN, pf->state) &&
Catherine Sullivan2becc352014-06-04 08:45:27 +0000984 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
985 /* Send message that it might not necessarily work*/
986 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
987 }
988
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000989 if (dcbx_cfg->pfc.pfcenable) {
990 netdev_info(netdev,
991 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000992 return -EOPNOTSUPP;
993 }
994
995 if (pause->rx_pause && pause->tx_pause)
996 hw->fc.requested_mode = I40E_FC_FULL;
997 else if (pause->rx_pause && !pause->tx_pause)
998 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
999 else if (!pause->rx_pause && pause->tx_pause)
1000 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
1001 else if (!pause->rx_pause && !pause->tx_pause)
1002 hw->fc.requested_mode = I40E_FC_NONE;
1003 else
1004 return -EINVAL;
1005
Catherine Sullivan94128512014-07-12 07:28:16 +00001006 /* Tell the OS link is going down, the link will go back up when fw
1007 * says it is ready asynchronously
1008 */
Matt Jaredc156f852015-08-27 11:42:39 -04001009 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +00001010 netif_carrier_off(netdev);
1011 netif_tx_stop_all_queues(netdev);
1012
Catherine Sullivan2becc352014-06-04 08:45:27 +00001013 /* Set the fc mode and only restart an if link is up*/
1014 status = i40e_set_fc(hw, &aq_failures, link_up);
1015
1016 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001017 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
1018 i40e_stat_str(hw, status),
1019 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001020 err = -EAGAIN;
1021 }
1022 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001023 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
1024 i40e_stat_str(hw, status),
1025 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001026 err = -EAGAIN;
1027 }
1028 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -04001029 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
1030 i40e_stat_str(hw, status),
1031 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +00001032 err = -EAGAIN;
1033 }
1034
Jacob Keller0da36b92017-04-19 09:25:55 -04001035 if (!test_bit(__I40E_DOWN, pf->state)) {
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001036 /* Give it a little more time to try to come back */
1037 msleep(75);
Jacob Keller0da36b92017-04-19 09:25:55 -04001038 if (!test_bit(__I40E_DOWN, pf->state))
Catherine Sullivan7d62dac2014-07-09 07:46:18 +00001039 return i40e_nway_reset(netdev);
1040 }
Catherine Sullivan2becc352014-06-04 08:45:27 +00001041
1042 return err;
1043}
1044
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001045static u32 i40e_get_msglevel(struct net_device *netdev)
1046{
1047 struct i40e_netdev_priv *np = netdev_priv(netdev);
1048 struct i40e_pf *pf = np->vsi->back;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001049 u32 debug_mask = pf->hw.debug_mask;
1050
1051 if (debug_mask)
1052 netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001053
1054 return pf->msg_enable;
1055}
1056
1057static void i40e_set_msglevel(struct net_device *netdev, u32 data)
1058{
1059 struct i40e_netdev_priv *np = netdev_priv(netdev);
1060 struct i40e_pf *pf = np->vsi->back;
1061
1062 if (I40E_DEBUG_USER & data)
1063 pf->hw.debug_mask = data;
Alexander Duyck5d4ca232016-09-30 08:21:46 -04001064 else
1065 pf->msg_enable = data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001066}
1067
1068static int i40e_get_regs_len(struct net_device *netdev)
1069{
1070 int reg_count = 0;
1071 int i;
1072
1073 for (i = 0; i40e_reg_list[i].offset != 0; i++)
1074 reg_count += i40e_reg_list[i].elements;
1075
1076 return reg_count * sizeof(u32);
1077}
1078
1079static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
1080 void *p)
1081{
1082 struct i40e_netdev_priv *np = netdev_priv(netdev);
1083 struct i40e_pf *pf = np->vsi->back;
1084 struct i40e_hw *hw = &pf->hw;
1085 u32 *reg_buf = p;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001086 unsigned int i, j, ri;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001087 u32 reg;
1088
1089 /* Tell ethtool which driver-version-specific regs output we have.
1090 *
1091 * At some point, if we have ethtool doing special formatting of
1092 * this data, it will rely on this version number to know how to
1093 * interpret things. Hence, this needs to be updated if/when the
1094 * diags register table is changed.
1095 */
1096 regs->version = 1;
1097
1098 /* loop through the diags reg table for what to print */
1099 ri = 0;
1100 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
1101 for (j = 0; j < i40e_reg_list[i].elements; j++) {
1102 reg = i40e_reg_list[i].offset
1103 + (j * i40e_reg_list[i].stride);
1104 reg_buf[ri++] = rd32(hw, reg);
1105 }
1106 }
1107
1108}
1109
1110static int i40e_get_eeprom(struct net_device *netdev,
1111 struct ethtool_eeprom *eeprom, u8 *bytes)
1112{
1113 struct i40e_netdev_priv *np = netdev_priv(netdev);
1114 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001115 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001116 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001117 u8 *eeprom_buff;
1118 u16 i, sectors;
1119 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001120 u32 magic;
1121
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001122#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001123 if (eeprom->len == 0)
1124 return -EINVAL;
1125
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001126 /* check for NVMUpdate access method */
1127 magic = hw->vendor_id | (hw->device_id << 16);
1128 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001129 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
1130 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001131
1132 /* make sure it is the right magic for NVMUpdate */
1133 if ((eeprom->magic >> 16) != hw->device_id)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001134 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001135 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1136 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001137 errno = -EBUSY;
1138 else
1139 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001140
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001141 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001142 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001143 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1144 ret_val, hw->aq.asq_last_status, errno,
1145 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1146 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001147
1148 return errno;
1149 }
1150
1151 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001152 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1153
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001154 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001155 if (!eeprom_buff)
1156 return -ENOMEM;
1157
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001158 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1159 if (ret_val) {
1160 dev_info(&pf->pdev->dev,
1161 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1162 ret_val, hw->aq.asq_last_status);
1163 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001164 }
1165
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001166 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1167 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1168 len = I40E_NVM_SECTOR_SIZE;
1169 last = false;
1170 for (i = 0; i < sectors; i++) {
1171 if (i == (sectors - 1)) {
1172 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1173 last = true;
1174 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001175 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1176 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001177 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001178 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001179 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001180 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001181 "read NVM failed, invalid offset 0x%x\n",
1182 offset);
1183 break;
1184 } else if (ret_val &&
1185 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1186 dev_info(&pf->pdev->dev,
1187 "read NVM failed, access, offset 0x%x\n",
1188 offset);
1189 break;
1190 } else if (ret_val) {
1191 dev_info(&pf->pdev->dev,
1192 "read NVM failed offset %d err=%d status=0x%x\n",
1193 offset, ret_val, hw->aq.asq_last_status);
1194 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001195 }
1196 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001197
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001198 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001199 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001200free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001201 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001202 return ret_val;
1203}
1204
1205static int i40e_get_eeprom_len(struct net_device *netdev)
1206{
1207 struct i40e_netdev_priv *np = netdev_priv(netdev);
1208 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001209 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001210
Lihong Yangc271dd62017-01-30 12:29:32 -08001211#define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF
1212 if (hw->mac.type == I40E_MAC_X722) {
1213 val = X722_EEPROM_SCOPE_LIMIT + 1;
1214 return val;
1215 }
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001216 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1217 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1218 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1219 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001220 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001221 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001222}
1223
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001224static int i40e_set_eeprom(struct net_device *netdev,
1225 struct ethtool_eeprom *eeprom, u8 *bytes)
1226{
1227 struct i40e_netdev_priv *np = netdev_priv(netdev);
1228 struct i40e_hw *hw = &np->vsi->back->hw;
1229 struct i40e_pf *pf = np->vsi->back;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001230 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001231 int ret_val = 0;
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001232 int errno = 0;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001233 u32 magic;
1234
1235 /* normal ethtool set_eeprom is not supported */
1236 magic = hw->vendor_id | (hw->device_id << 16);
1237 if (eeprom->magic == magic)
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001238 errno = -EOPNOTSUPP;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001239 /* check for NVMUpdate access method */
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001240 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1241 errno = -EINVAL;
Jacob Keller0da36b92017-04-19 09:25:55 -04001242 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
1243 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001244 errno = -EBUSY;
1245 else
1246 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001247
Shannon Nelson6e93d0c2016-01-15 14:33:18 -08001248 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001249 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001250 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1251 ret_val, hw->aq.asq_last_status, errno,
1252 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1253 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001254
1255 return errno;
1256}
1257
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001258static void i40e_get_drvinfo(struct net_device *netdev,
1259 struct ethtool_drvinfo *drvinfo)
1260{
1261 struct i40e_netdev_priv *np = netdev_priv(netdev);
1262 struct i40e_vsi *vsi = np->vsi;
1263 struct i40e_pf *pf = vsi->back;
1264
1265 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1266 strlcpy(drvinfo->version, i40e_driver_version_str,
1267 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001268 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001269 sizeof(drvinfo->fw_version));
1270 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1271 sizeof(drvinfo->bus_info));
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001272 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN;
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07001273 if (pf->hw.pf_id == 0)
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001274 drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001275}
1276
1277static void i40e_get_ringparam(struct net_device *netdev,
1278 struct ethtool_ringparam *ring)
1279{
1280 struct i40e_netdev_priv *np = netdev_priv(netdev);
1281 struct i40e_pf *pf = np->vsi->back;
1282 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1283
1284 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1285 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1286 ring->rx_mini_max_pending = 0;
1287 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001288 ring->rx_pending = vsi->rx_rings[0]->count;
1289 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001290 ring->rx_mini_pending = 0;
1291 ring->rx_jumbo_pending = 0;
1292}
1293
Björn Töpel74608d12017-05-24 07:55:35 +02001294static bool i40e_active_tx_ring_index(struct i40e_vsi *vsi, u16 index)
1295{
1296 if (i40e_enabled_xdp_vsi(vsi)) {
1297 return index < vsi->num_queue_pairs ||
1298 (index >= vsi->alloc_queue_pairs &&
1299 index < vsi->alloc_queue_pairs + vsi->num_queue_pairs);
1300 }
1301
1302 return index < vsi->num_queue_pairs;
1303}
1304
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001305static int i40e_set_ringparam(struct net_device *netdev,
1306 struct ethtool_ringparam *ring)
1307{
1308 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1309 struct i40e_netdev_priv *np = netdev_priv(netdev);
Tushar Dave2f7679e2016-10-26 10:49:27 -07001310 struct i40e_hw *hw = &np->vsi->back->hw;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001311 struct i40e_vsi *vsi = np->vsi;
1312 struct i40e_pf *pf = vsi->back;
1313 u32 new_rx_count, new_tx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001314 u16 tx_alloc_queue_pairs;
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001315 int timeout = 50;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001316 int i, err = 0;
1317
1318 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1319 return -EINVAL;
1320
Shannon Nelson1fa18372013-11-20 10:03:08 +00001321 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1322 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1323 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1324 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1325 netdev_info(netdev,
1326 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1327 ring->tx_pending, ring->rx_pending,
1328 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1329 return -EINVAL;
1330 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001331
Shannon Nelson1fa18372013-11-20 10:03:08 +00001332 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1333 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001334
1335 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001336 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1337 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001338 return 0;
1339
Jacob Keller0da36b92017-04-19 09:25:55 -04001340 while (test_and_set_bit(__I40E_CONFIG_BUSY, pf->state)) {
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001341 timeout--;
1342 if (!timeout)
1343 return -EBUSY;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001344 usleep_range(1000, 2000);
Jacob Kellere8d2f4c2017-04-13 04:45:48 -04001345 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001346
1347 if (!netif_running(vsi->netdev)) {
1348 /* simple case - set for the next time the netdev is started */
1349 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001350 vsi->tx_rings[i]->count = new_tx_count;
1351 vsi->rx_rings[i]->count = new_rx_count;
Björn Töpel74608d12017-05-24 07:55:35 +02001352 if (i40e_enabled_xdp_vsi(vsi))
1353 vsi->xdp_rings[i]->count = new_tx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001354 }
1355 goto done;
1356 }
1357
1358 /* We can't just free everything and then setup again,
1359 * because the ISRs in MSI-X mode get passed pointers
1360 * to the Tx and Rx ring structs.
1361 */
1362
Björn Töpel74608d12017-05-24 07:55:35 +02001363 /* alloc updated Tx and XDP Tx resources */
1364 tx_alloc_queue_pairs = vsi->alloc_queue_pairs *
1365 (i40e_enabled_xdp_vsi(vsi) ? 2 : 1);
Alexander Duyck9f65e152013-09-28 06:00:58 +00001366 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001367 netdev_info(netdev,
1368 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001369 vsi->tx_rings[0]->count, new_tx_count);
Björn Töpel74608d12017-05-24 07:55:35 +02001370 tx_rings = kcalloc(tx_alloc_queue_pairs,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001371 sizeof(struct i40e_ring), GFP_KERNEL);
1372 if (!tx_rings) {
1373 err = -ENOMEM;
1374 goto done;
1375 }
1376
Björn Töpel74608d12017-05-24 07:55:35 +02001377 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1378 if (!i40e_active_tx_ring_index(vsi, i))
1379 continue;
1380
Alexander Duyck9f65e152013-09-28 06:00:58 +00001381 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001382 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001383 /* the desc and bi pointers will be reallocated in the
1384 * setup call
1385 */
1386 tx_rings[i].desc = NULL;
1387 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001388 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1389 if (err) {
1390 while (i) {
1391 i--;
Björn Töpel74608d12017-05-24 07:55:35 +02001392 if (!i40e_active_tx_ring_index(vsi, i))
1393 continue;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001394 i40e_free_tx_resources(&tx_rings[i]);
1395 }
1396 kfree(tx_rings);
1397 tx_rings = NULL;
1398
1399 goto done;
1400 }
1401 }
1402 }
1403
1404 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001405 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001406 netdev_info(netdev,
1407 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001408 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001409 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1410 sizeof(struct i40e_ring), GFP_KERNEL);
1411 if (!rx_rings) {
1412 err = -ENOMEM;
1413 goto free_tx;
1414 }
1415
1416 for (i = 0; i < vsi->num_queue_pairs; i++) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001417 struct i40e_ring *ring;
1418 u16 unused;
1419
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001420 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001421 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001422 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001423 /* the desc and bi pointers will be reallocated in the
1424 * setup call
1425 */
1426 rx_rings[i].desc = NULL;
1427 rx_rings[i].rx_bi = NULL;
Tushar Dave2f7679e2016-10-26 10:49:27 -07001428 /* this is to allow wr32 to have something to write to
1429 * during early allocation of Rx buffers
1430 */
1431 rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001432 err = i40e_setup_rx_descriptors(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001433 if (err)
1434 goto rx_unwind;
1435
1436 /* now allocate the Rx buffers to make sure the OS
1437 * has enough memory, any failure here means abort
1438 */
1439 ring = &rx_rings[i];
1440 unused = I40E_DESC_UNUSED(ring);
1441 err = i40e_alloc_rx_buffers(ring, unused);
1442rx_unwind:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001443 if (err) {
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001444 do {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001445 i40e_free_rx_resources(&rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001446 } while (i--);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001447 kfree(rx_rings);
1448 rx_rings = NULL;
1449
1450 goto free_tx;
1451 }
1452 }
1453 }
1454
1455 /* Bring interface down, copy in the new ring info,
1456 * then restore the interface
1457 */
1458 i40e_down(vsi);
1459
1460 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001461 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1462 if (i40e_active_tx_ring_index(vsi, i)) {
1463 i40e_free_tx_resources(vsi->tx_rings[i]);
1464 *vsi->tx_rings[i] = tx_rings[i];
1465 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001466 }
1467 kfree(tx_rings);
1468 tx_rings = NULL;
1469 }
1470
1471 if (rx_rings) {
1472 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001473 i40e_free_rx_resources(vsi->rx_rings[i]);
Jesse Brandeburg147e81e2016-04-18 11:33:49 -07001474 /* get the real tail offset */
1475 rx_rings[i].tail = vsi->rx_rings[i]->tail;
1476 /* this is to fake out the allocation routine
1477 * into thinking it has to realloc everything
1478 * but the recycling logic will let us re-use
1479 * the buffers allocated above
1480 */
1481 rx_rings[i].next_to_use = 0;
1482 rx_rings[i].next_to_clean = 0;
1483 rx_rings[i].next_to_alloc = 0;
1484 /* do a struct copy */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001485 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001486 }
1487 kfree(rx_rings);
1488 rx_rings = NULL;
1489 }
1490
1491 i40e_up(vsi);
1492
1493free_tx:
1494 /* error cleanup if the Rx allocations failed after getting Tx */
1495 if (tx_rings) {
Björn Töpel74608d12017-05-24 07:55:35 +02001496 for (i = 0; i < tx_alloc_queue_pairs; i++) {
1497 if (i40e_active_tx_ring_index(vsi, i))
1498 i40e_free_tx_resources(vsi->tx_rings[i]);
1499 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001500 kfree(tx_rings);
1501 tx_rings = NULL;
1502 }
1503
1504done:
Jacob Keller0da36b92017-04-19 09:25:55 -04001505 clear_bit(__I40E_CONFIG_BUSY, pf->state);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001506
1507 return err;
1508}
1509
1510static int i40e_get_sset_count(struct net_device *netdev, int sset)
1511{
1512 struct i40e_netdev_priv *np = netdev_priv(netdev);
1513 struct i40e_vsi *vsi = np->vsi;
1514 struct i40e_pf *pf = vsi->back;
1515
1516 switch (sset) {
1517 case ETH_SS_TEST:
1518 return I40E_TEST_LEN;
1519 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001520 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001521 int len = I40E_PF_STATS_LEN(netdev);
1522
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001523 if ((pf->lan_veb != I40E_NO_VEB) &&
1524 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001525 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001526 return len;
1527 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001528 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001529 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001530 case ETH_SS_PRIV_FLAGS:
Jacob Kellerd182a5c2016-10-25 16:08:50 -07001531 return I40E_PRIV_FLAGS_STR_LEN +
1532 (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001533 default:
1534 return -EOPNOTSUPP;
1535 }
1536}
1537
1538static void i40e_get_ethtool_stats(struct net_device *netdev,
1539 struct ethtool_stats *stats, u64 *data)
1540{
1541 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001542 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001543 struct i40e_vsi *vsi = np->vsi;
1544 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001545 unsigned int j;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001546 int i = 0;
1547 char *p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001548 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001549 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001550
1551 i40e_update_stats(vsi);
1552
1553 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1554 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1555 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1556 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1557 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001558 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1559 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1560 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1561 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1562 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001563 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001564 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001565 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001566
1567 if (!tx_ring)
1568 continue;
1569
1570 /* process Tx ring statistics */
1571 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001572 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001573 data[i] = tx_ring->stats.packets;
1574 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001575 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001576 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001577
1578 /* Rx ring is the 2nd half of the queue pair */
1579 rx_ring = &tx_ring[1];
1580 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001581 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001582 data[i] = rx_ring->stats.packets;
1583 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001584 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001585 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001586 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001587 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001588 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001589 return;
1590
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001591 if ((pf->lan_veb != I40E_NO_VEB) &&
1592 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001593 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001594
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001595 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1596 p = (char *)veb;
1597 p += i40e_gstrings_veb_stats[j].stat_offset;
1598 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1599 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600 }
Jesse Brandeburg74a6c662015-10-02 19:09:34 -07001601 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) {
1602 data[i++] = veb->tc_stats.tc_tx_packets[j];
1603 data[i++] = veb->tc_stats.tc_tx_bytes[j];
1604 data[i++] = veb->tc_stats.tc_rx_packets[j];
1605 data[i++] = veb->tc_stats.tc_rx_bytes[j];
1606 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001607 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001608 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1609 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1610 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1611 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1612 }
1613 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1614 data[i++] = pf->stats.priority_xon_tx[j];
1615 data[i++] = pf->stats.priority_xoff_tx[j];
1616 }
1617 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1618 data[i++] = pf->stats.priority_xon_rx[j];
1619 data[i++] = pf->stats.priority_xoff_rx[j];
1620 }
1621 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1622 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001623}
1624
1625static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1626 u8 *data)
1627{
1628 struct i40e_netdev_priv *np = netdev_priv(netdev);
1629 struct i40e_vsi *vsi = np->vsi;
1630 struct i40e_pf *pf = vsi->back;
1631 char *p = (char *)data;
Jesse Brandeburgb85c94b2017-06-20 15:16:59 -07001632 unsigned int i;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001633
1634 switch (stringset) {
1635 case ETH_SS_TEST:
Jacob Kellere5d32202016-11-08 13:05:11 -08001636 memcpy(data, i40e_gstrings_test,
1637 I40E_TEST_LEN * ETH_GSTRING_LEN);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001638 break;
1639 case ETH_SS_STATS:
1640 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1641 snprintf(p, ETH_GSTRING_LEN, "%s",
1642 i40e_gstrings_net_stats[i].stat_string);
1643 p += ETH_GSTRING_LEN;
1644 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001645 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1646 snprintf(p, ETH_GSTRING_LEN, "%s",
1647 i40e_gstrings_misc_stats[i].stat_string);
1648 p += ETH_GSTRING_LEN;
1649 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001650 for (i = 0; i < vsi->num_queue_pairs; i++) {
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001651 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001652 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001653 snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001654 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001655 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001656 p += ETH_GSTRING_LEN;
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001657 snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001658 p += ETH_GSTRING_LEN;
1659 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001660 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001661 return;
1662
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001663 if ((pf->lan_veb != I40E_NO_VEB) &&
1664 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001665 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1666 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1667 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001668 p += ETH_GSTRING_LEN;
1669 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001670 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1671 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001672 "veb.tc_%d_tx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001673 p += ETH_GSTRING_LEN;
1674 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001675 "veb.tc_%d_tx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001676 p += ETH_GSTRING_LEN;
1677 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001678 "veb.tc_%d_rx_packets", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001679 p += ETH_GSTRING_LEN;
1680 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001681 "veb.tc_%d_rx_bytes", i);
Neerav Parikhfe860af2015-07-10 19:36:02 -04001682 p += ETH_GSTRING_LEN;
1683 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001684 }
1685 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1686 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1687 i40e_gstrings_stats[i].stat_string);
1688 p += ETH_GSTRING_LEN;
1689 }
1690 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1691 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001692 "port.tx_priority_%d_xon", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001693 p += ETH_GSTRING_LEN;
1694 snprintf(p, ETH_GSTRING_LEN,
Heinrich Schuchardtfbcfac32016-08-11 01:07:22 +02001695 "port.tx_priority_%d_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001696 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.rx_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.rx_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_2_xoff", i);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001709 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001710 }
1711 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1712 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001713 case ETH_SS_PRIV_FLAGS:
Alexander Duyckaca955d2017-03-10 12:22:01 -08001714 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1715 snprintf(p, ETH_GSTRING_LEN, "%s",
1716 i40e_gstrings_priv_flags[i].flag_string);
1717 p += ETH_GSTRING_LEN;
1718 }
1719 if (pf->hw.pf_id != 0)
1720 break;
1721 for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++) {
1722 snprintf(p, ETH_GSTRING_LEN, "%s",
1723 i40e_gl_gstrings_priv_flags[i].flag_string);
1724 p += ETH_GSTRING_LEN;
1725 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001726 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001727 default:
1728 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001729 }
1730}
1731
1732static int i40e_get_ts_info(struct net_device *dev,
1733 struct ethtool_ts_info *info)
1734{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001735 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1736
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001737 /* only report HW timestamping if PTP is enabled */
1738 if (!(pf->flags & I40E_FLAG_PTP))
1739 return ethtool_op_get_ts_info(dev, info);
1740
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001741 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1742 SOF_TIMESTAMPING_RX_SOFTWARE |
1743 SOF_TIMESTAMPING_SOFTWARE |
1744 SOF_TIMESTAMPING_TX_HARDWARE |
1745 SOF_TIMESTAMPING_RX_HARDWARE |
1746 SOF_TIMESTAMPING_RAW_HARDWARE;
1747
1748 if (pf->ptp_clock)
1749 info->phc_index = ptp_clock_index(pf->ptp_clock);
1750 else
1751 info->phc_index = -1;
1752
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001753 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001754
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001755 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
Jacob Keller1e28e862016-11-11 12:39:25 -08001756 BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
1757 BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
1758 BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
1759
Jacob Kellerd36e41d2017-06-23 04:24:46 -04001760 if (pf->hw_features & I40E_HW_PTP_L4_CAPABLE)
Jacob Keller1e28e862016-11-11 12:39:25 -08001761 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1762 BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1763 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
1764 BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1765 BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
1766 BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1767 BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1768 BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001769
1770 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001771}
1772
Shannon Nelson7b086392013-11-20 10:02:59 +00001773static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001774{
Shannon Nelson7b086392013-11-20 10:02:59 +00001775 struct i40e_netdev_priv *np = netdev_priv(netdev);
1776 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001777 i40e_status status;
1778 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001779
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001780 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001781 status = i40e_get_link_status(&pf->hw, &link_up);
1782 if (status) {
1783 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1784 *data = 1;
1785 return *data;
1786 }
1787
1788 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001789 *data = 0;
1790 else
1791 *data = 1;
1792
1793 return *data;
1794}
1795
Shannon Nelson7b086392013-11-20 10:02:59 +00001796static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797{
Shannon Nelson7b086392013-11-20 10:02:59 +00001798 struct i40e_netdev_priv *np = netdev_priv(netdev);
1799 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001800
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001801 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001802 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001803
Shannon Nelson7b086392013-11-20 10:02:59 +00001804 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001805}
1806
Shannon Nelson7b086392013-11-20 10:02:59 +00001807static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001808{
Shannon Nelson7b086392013-11-20 10:02:59 +00001809 struct i40e_netdev_priv *np = netdev_priv(netdev);
1810 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001812 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001813 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001814
Shannon Nelson4443ec92014-11-13 08:23:12 +00001815 /* forcebly clear the NVM Update state machine */
1816 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1817
Shannon Nelson7b086392013-11-20 10:02:59 +00001818 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001819}
1820
Shannon Nelson7b086392013-11-20 10:02:59 +00001821static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001822{
Shannon Nelson7b086392013-11-20 10:02:59 +00001823 struct i40e_netdev_priv *np = netdev_priv(netdev);
1824 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001825 u16 swc_old = pf->sw_int_count;
1826
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001827 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001828 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1829 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001830 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1831 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1832 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1833 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001834 usleep_range(1000, 2000);
1835 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001836
1837 return *data;
1838}
1839
Greg Rosee17bc412015-04-16 20:05:59 -04001840static inline bool i40e_active_vfs(struct i40e_pf *pf)
1841{
1842 struct i40e_vf *vfs = pf->vf;
1843 int i;
1844
1845 for (i = 0; i < pf->num_alloc_vfs; i++)
Jacob Keller6322e632017-04-13 04:45:54 -04001846 if (test_bit(I40E_VF_STATE_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001847 return true;
1848 return false;
1849}
1850
Greg Rose510efb22015-07-10 19:36:01 -04001851static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1852{
Alexander Duyck4b816442016-10-11 15:26:53 -07001853 return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2);
Greg Rose510efb22015-07-10 19:36:01 -04001854}
1855
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001856static void i40e_diag_test(struct net_device *netdev,
1857 struct ethtool_test *eth_test, u64 *data)
1858{
1859 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001860 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001861 struct i40e_pf *pf = np->vsi->back;
1862
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001863 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1864 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001865 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001866
Jacob Keller0da36b92017-04-19 09:25:55 -04001867 set_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001868
Greg Rose510efb22015-07-10 19:36:01 -04001869 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001870 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001871 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001872 data[I40E_ETH_TEST_REG] = 1;
1873 data[I40E_ETH_TEST_EEPROM] = 1;
1874 data[I40E_ETH_TEST_INTR] = 1;
Greg Rosee17bc412015-04-16 20:05:59 -04001875 data[I40E_ETH_TEST_LINK] = 1;
1876 eth_test->flags |= ETH_TEST_FL_FAILED;
Jacob Keller0da36b92017-04-19 09:25:55 -04001877 clear_bit(__I40E_TESTING, pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001878 goto skip_ol_tests;
1879 }
1880
Greg Rose5b86c5c2015-02-26 16:14:35 +00001881 /* If the device is online then take it offline */
1882 if (if_running)
1883 /* indicate we're in test mode */
Stefan Assmann08ca3872016-02-03 09:20:47 +01001884 i40e_close(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001885 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001886 /* This reset does not affect link - if it is
1887 * changed to a type of reset that does affect
1888 * link then the following link test would have
1889 * to be moved to before the reset
1890 */
Maciej Sosin373149f2017-04-05 07:50:55 -04001891 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Shannon Nelsonf551b432013-11-26 10:49:12 +00001892
Shannon Nelson7b086392013-11-20 10:02:59 +00001893 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001894 eth_test->flags |= ETH_TEST_FL_FAILED;
1895
Shannon Nelson7b086392013-11-20 10:02:59 +00001896 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001897 eth_test->flags |= ETH_TEST_FL_FAILED;
1898
Shannon Nelson7b086392013-11-20 10:02:59 +00001899 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001900 eth_test->flags |= ETH_TEST_FL_FAILED;
1901
Shannon Nelsonf551b432013-11-26 10:49:12 +00001902 /* run reg test last, a reset is required after it */
1903 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1904 eth_test->flags |= ETH_TEST_FL_FAILED;
1905
Jacob Keller0da36b92017-04-19 09:25:55 -04001906 clear_bit(__I40E_TESTING, pf->state);
Maciej Sosin373149f2017-04-05 07:50:55 -04001907 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001908
1909 if (if_running)
Stefan Assmann08ca3872016-02-03 09:20:47 +01001910 i40e_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001911 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001912 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001913 netif_info(pf, drv, netdev, "online testing starting\n");
1914
Shannon Nelson7b086392013-11-20 10:02:59 +00001915 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001916 eth_test->flags |= ETH_TEST_FL_FAILED;
1917
1918 /* Offline only tests, not run in online; pass by default */
1919 data[I40E_ETH_TEST_REG] = 0;
1920 data[I40E_ETH_TEST_EEPROM] = 0;
1921 data[I40E_ETH_TEST_INTR] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001922 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001923
Greg Rosee17bc412015-04-16 20:05:59 -04001924skip_ol_tests:
1925
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001926 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001927}
1928
1929static void i40e_get_wol(struct net_device *netdev,
1930 struct ethtool_wolinfo *wol)
1931{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001932 struct i40e_netdev_priv *np = netdev_priv(netdev);
1933 struct i40e_pf *pf = np->vsi->back;
1934 struct i40e_hw *hw = &pf->hw;
1935 u16 wol_nvm_bits;
1936
1937 /* NVM bit on means WoL disabled for the port */
1938 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001939 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001940 wol->supported = 0;
1941 wol->wolopts = 0;
1942 } else {
1943 wol->supported = WAKE_MAGIC;
1944 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1945 }
1946}
1947
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001948/**
1949 * i40e_set_wol - set the WakeOnLAN configuration
1950 * @netdev: the netdev in question
1951 * @wol: the ethtool WoL setting data
1952 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001953static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1954{
1955 struct i40e_netdev_priv *np = netdev_priv(netdev);
1956 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001957 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001958 struct i40e_hw *hw = &pf->hw;
1959 u16 wol_nvm_bits;
1960
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001961 /* WoL not supported if this isn't the controlling PF on the port */
1962 if (hw->partition_id != 1) {
1963 i40e_partition_setting_complaint(pf);
1964 return -EOPNOTSUPP;
1965 }
1966
1967 if (vsi != pf->vsi[pf->lan_vsi])
1968 return -EOPNOTSUPP;
1969
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001970 /* NVM bit on means WoL disabled for the port */
1971 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001972 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001973 return -EOPNOTSUPP;
1974
1975 /* only magic packet is supported */
1976 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1977 return -EOPNOTSUPP;
1978
1979 /* is this a new value? */
1980 if (pf->wol_en != !!wol->wolopts) {
1981 pf->wol_en = !!wol->wolopts;
1982 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1983 }
1984
1985 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001986}
1987
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001988static int i40e_set_phys_id(struct net_device *netdev,
1989 enum ethtool_phys_id_state state)
1990{
1991 struct i40e_netdev_priv *np = netdev_priv(netdev);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001992 i40e_status ret = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001993 struct i40e_pf *pf = np->vsi->back;
1994 struct i40e_hw *hw = &pf->hw;
1995 int blink_freq = 2;
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08001996 u16 temp_status;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001997
1998 switch (state) {
1999 case ETHTOOL_ID_ACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002000 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002001 pf->led_status = i40e_led_get(hw);
2002 } else {
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002003 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2004 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL,
2005 NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002006 ret = i40e_led_get_phy(hw, &temp_status,
2007 &pf->phy_led_val);
2008 pf->led_status = temp_status;
2009 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002010 return blink_freq;
2011 case ETHTOOL_ID_ON:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002012 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002013 i40e_led_set(hw, 0xf, false);
2014 else
2015 ret = i40e_led_set_phy(hw, true, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002016 break;
2017 case ETHTOOL_ID_OFF:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002018 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS))
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002019 i40e_led_set(hw, 0x0, false);
2020 else
2021 ret = i40e_led_set_phy(hw, false, pf->led_status, 0);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002022 break;
2023 case ETHTOOL_ID_INACTIVE:
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002024 if (!(pf->hw_features & I40E_HW_PHY_CONTROLS_LEDS)) {
Henry Tieman4f9b4302016-11-08 13:05:18 -08002025 i40e_led_set(hw, pf->led_status, false);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002026 } else {
2027 ret = i40e_led_set_phy(hw, false, pf->led_status,
2028 (pf->phy_led_val |
2029 I40E_PHY_LED_MODE_ORIG));
Mariusz Stachura052b93d2017-08-29 05:32:40 -04002030 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE))
2031 i40e_aq_set_phy_debug(hw, 0, NULL);
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002032 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002033 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00002034 default:
2035 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002036 }
Carolyn Wyborny31b606d2016-02-17 16:12:12 -08002037 if (ret)
2038 return -ENOENT;
2039 else
2040 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002041}
2042
2043/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
2044 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
2045 * 125us (8000 interrupts per second) == ITR(62)
2046 */
2047
Jacob Keller65e87c02016-09-12 14:18:44 -07002048/**
2049 * __i40e_get_coalesce - get per-queue coalesce settings
2050 * @netdev: the netdev to check
2051 * @ec: ethtool coalesce data structure
2052 * @queue: which queue to pick
2053 *
2054 * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
2055 * are per queue. If queue is <0 then we default to queue 0 as the
2056 * representative value.
2057 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002058static int __i40e_get_coalesce(struct net_device *netdev,
2059 struct ethtool_coalesce *ec,
2060 int queue)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002061{
2062 struct i40e_netdev_priv *np = netdev_priv(netdev);
Jacob Keller65e87c02016-09-12 14:18:44 -07002063 struct i40e_ring *rx_ring, *tx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002064 struct i40e_vsi *vsi = np->vsi;
2065
2066 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
2067 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
2068
Alan Bradya03af692017-10-05 14:53:37 -07002069 /* rx and tx usecs has per queue value. If user doesn't specify the
2070 * queue, return queue 0's value to represent.
Kan Lianga75e8002016-02-19 09:24:04 -05002071 */
Alan Bradya03af692017-10-05 14:53:37 -07002072 if (queue < 0)
Kan Lianga75e8002016-02-19 09:24:04 -05002073 queue = 0;
Alan Bradya03af692017-10-05 14:53:37 -07002074 else if (queue >= vsi->num_queue_pairs)
Kan Lianga75e8002016-02-19 09:24:04 -05002075 return -EINVAL;
Kan Lianga75e8002016-02-19 09:24:04 -05002076
Jacob Keller65e87c02016-09-12 14:18:44 -07002077 rx_ring = vsi->rx_rings[queue];
2078 tx_ring = vsi->tx_rings[queue];
2079
2080 if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002081 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002082
Jacob Keller65e87c02016-09-12 14:18:44 -07002083 if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00002084 ec->use_adaptive_tx_coalesce = 1;
2085
Jacob Keller65e87c02016-09-12 14:18:44 -07002086 ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
2087 ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
2088
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002089 /* we use the _usecs_high to store/set the interrupt rate limit
2090 * that the hardware supports, that almost but not quite
2091 * fits the original intent of the ethtool variable,
2092 * the rx_coalesce_usecs_high limits total interrupts
2093 * per second from both tx/rx sources.
2094 */
2095 ec->rx_coalesce_usecs_high = vsi->int_rate_limit;
2096 ec->tx_coalesce_usecs_high = vsi->int_rate_limit;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002097
2098 return 0;
2099}
2100
Jacob Keller65e87c02016-09-12 14:18:44 -07002101/**
2102 * i40e_get_coalesce - get a netdev's coalesce settings
2103 * @netdev: the netdev to check
2104 * @ec: ethtool coalesce data structure
2105 *
2106 * Gets the coalesce settings for a particular netdev. Note that if user has
2107 * modified per-queue settings, this only guarantees to represent queue 0. See
2108 * __i40e_get_coalesce for more details.
2109 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002110static int i40e_get_coalesce(struct net_device *netdev,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002111 struct ethtool_coalesce *ec)
2112{
Kan Lianga75e8002016-02-19 09:24:04 -05002113 return __i40e_get_coalesce(netdev, ec, -1);
2114}
2115
Jacob Keller65e87c02016-09-12 14:18:44 -07002116/**
2117 * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue
2118 * @netdev: netdev structure
2119 * @ec: ethtool's coalesce settings
2120 * @queue: the particular queue to read
2121 *
2122 * Will read a specific queue's coalesce settings
2123 **/
Kan Liangbe280ba2016-02-19 09:24:05 -05002124static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue,
2125 struct ethtool_coalesce *ec)
2126{
2127 return __i40e_get_coalesce(netdev, ec, queue);
2128}
2129
Jacob Keller65e87c02016-09-12 14:18:44 -07002130/**
2131 * i40e_set_itr_per_queue - set ITR values for specific queue
2132 * @vsi: the VSI to set values for
2133 * @ec: coalesce settings from ethtool
2134 * @queue: the queue to modify
2135 *
2136 * Change the ITR settings for a specific queue.
2137 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002138static void i40e_set_itr_per_queue(struct i40e_vsi *vsi,
2139 struct ethtool_coalesce *ec,
2140 int queue)
2141{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002142 struct i40e_pf *pf = vsi->back;
2143 struct i40e_hw *hw = &pf->hw;
Kan Lianga75e8002016-02-19 09:24:04 -05002144 struct i40e_q_vector *q_vector;
2145 u16 vector, intrl;
2146
Alan Brady1c0e6a32016-11-28 16:06:02 -08002147 intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit);
Kan Lianga75e8002016-02-19 09:24:04 -05002148
2149 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs;
2150 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs;
2151
2152 if (ec->use_adaptive_rx_coalesce)
2153 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC;
2154 else
2155 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
2156
2157 if (ec->use_adaptive_tx_coalesce)
2158 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC;
2159 else
2160 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
2161
2162 q_vector = vsi->rx_rings[queue]->q_vector;
2163 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting);
2164 vector = vsi->base_vector + q_vector->v_idx;
2165 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
2166
2167 q_vector = vsi->tx_rings[queue]->q_vector;
2168 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting);
2169 vector = vsi->base_vector + q_vector->v_idx;
2170 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
2171
2172 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl);
2173 i40e_flush(hw);
2174}
2175
Jacob Keller65e87c02016-09-12 14:18:44 -07002176/**
2177 * __i40e_set_coalesce - set coalesce settings for particular queue
2178 * @netdev: the netdev to change
2179 * @ec: ethtool coalesce settings
2180 * @queue: the queue to change
2181 *
2182 * Sets the coalesce settings for a particular queue.
2183 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002184static int __i40e_set_coalesce(struct net_device *netdev,
2185 struct ethtool_coalesce *ec,
2186 int queue)
2187{
2188 struct i40e_netdev_priv *np = netdev_priv(netdev);
Alan Brady06b2dec2017-07-12 05:46:06 -04002189 u16 intrl_reg, cur_rx_itr, cur_tx_itr;
Kan Lianga75e8002016-02-19 09:24:04 -05002190 struct i40e_vsi *vsi = np->vsi;
2191 struct i40e_pf *pf = vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002192 int i;
2193
2194 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
2195 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
2196
Alan Brady06b2dec2017-07-12 05:46:06 -04002197 if (queue < 0) {
2198 cur_rx_itr = vsi->rx_rings[0]->rx_itr_setting;
2199 cur_tx_itr = vsi->tx_rings[0]->tx_itr_setting;
2200 } else if (queue < vsi->num_queue_pairs) {
2201 cur_rx_itr = vsi->rx_rings[queue]->rx_itr_setting;
2202 cur_tx_itr = vsi->tx_rings[queue]->tx_itr_setting;
2203 } else {
2204 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
2205 vsi->num_queue_pairs - 1);
2206 return -EINVAL;
2207 }
2208
2209 cur_tx_itr &= ~I40E_ITR_DYNAMIC;
2210 cur_rx_itr &= ~I40E_ITR_DYNAMIC;
2211
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002212 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */
2213 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) {
2214 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n");
2215 return -EINVAL;
2216 }
2217
Alan Brady33084062016-11-28 16:06:03 -08002218 if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) {
2219 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n",
2220 INTRL_REG_TO_USEC(I40E_MAX_INTRL));
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002221 return -EINVAL;
2222 }
2223
Alan Brady06b2dec2017-07-12 05:46:06 -04002224 if (ec->rx_coalesce_usecs != cur_rx_itr &&
2225 ec->use_adaptive_rx_coalesce) {
2226 netif_info(pf, drv, netdev, "RX interrupt moderation cannot be changed if adaptive-rx is enabled.\n");
2227 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002228 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002229
Alan Brady06b2dec2017-07-12 05:46:06 -04002230 if (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2231 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
2232 return -EINVAL;
2233 }
2234
2235 if (ec->tx_coalesce_usecs != cur_tx_itr &&
2236 ec->use_adaptive_tx_coalesce) {
2237 netif_info(pf, drv, netdev, "TX interrupt moderation cannot be changed if adaptive-tx is enabled.\n");
2238 return -EINVAL;
2239 }
2240
2241 if (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)) {
2242 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
2243 return -EINVAL;
2244 }
2245
2246 if (ec->use_adaptive_rx_coalesce && !cur_rx_itr)
2247 ec->rx_coalesce_usecs = I40E_MIN_ITR << 1;
2248
2249 if (ec->use_adaptive_tx_coalesce && !cur_tx_itr)
2250 ec->tx_coalesce_usecs = I40E_MIN_ITR << 1;
2251
Alan Brady33084062016-11-28 16:06:03 -08002252 intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high);
2253 vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg);
2254 if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) {
2255 netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n",
2256 vsi->int_rate_limit);
2257 }
Jesse Brandeburgac26fc12015-09-28 14:12:37 -04002258
Alan Bradya03af692017-10-05 14:53:37 -07002259 /* rx and tx usecs has per queue value. If user doesn't specify the
2260 * queue, apply to all queues.
Kan Lianga75e8002016-02-19 09:24:04 -05002261 */
2262 if (queue < 0) {
2263 for (i = 0; i < vsi->num_queue_pairs; i++)
2264 i40e_set_itr_per_queue(vsi, ec, i);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002265 } else {
Alan Brady06b2dec2017-07-12 05:46:06 -04002266 i40e_set_itr_per_queue(vsi, ec, queue);
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00002267 }
Mitch Williams32f5f542014-04-04 04:43:10 +00002268
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002269 return 0;
2270}
2271
Jacob Keller65e87c02016-09-12 14:18:44 -07002272/**
2273 * i40e_set_coalesce - set coalesce settings for every queue on the netdev
2274 * @netdev: the netdev to change
2275 * @ec: ethtool coalesce settings
2276 *
2277 * This will set each queue to the same coalesce settings.
2278 **/
Kan Lianga75e8002016-02-19 09:24:04 -05002279static int i40e_set_coalesce(struct net_device *netdev,
2280 struct ethtool_coalesce *ec)
2281{
2282 return __i40e_set_coalesce(netdev, ec, -1);
2283}
2284
Jacob Keller65e87c02016-09-12 14:18:44 -07002285/**
2286 * i40e_set_per_queue_coalesce - set specific queue's coalesce settings
2287 * @netdev: the netdev to change
2288 * @ec: ethtool's coalesce settings
2289 * @queue: the queue to change
2290 *
2291 * Sets the specified queue's coalesce settings.
2292 **/
Kan Liangf3757a42016-02-19 09:24:06 -05002293static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue,
2294 struct ethtool_coalesce *ec)
2295{
2296 return __i40e_set_coalesce(netdev, ec, queue);
2297}
2298
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002299/**
2300 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
2301 * @pf: pointer to the physical function struct
2302 * @cmd: ethtool rxnfc command
2303 *
2304 * Returns Success if the flow is supported, else Invalid Input.
2305 **/
2306static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
2307{
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002308 struct i40e_hw *hw = &pf->hw;
2309 u8 flow_pctype = 0;
2310 u64 i_set = 0;
2311
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002312 cmd->data = 0;
2313
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002314 switch (cmd->flow_type) {
2315 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002316 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2317 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002318 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002319 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2320 break;
2321 case TCP_V6_FLOW:
2322 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
2323 break;
2324 case UDP_V6_FLOW:
2325 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
2326 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002327 case SCTP_V4_FLOW:
2328 case AH_ESP_V4_FLOW:
2329 case AH_V4_FLOW:
2330 case ESP_V4_FLOW:
2331 case IPV4_FLOW:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002332 case SCTP_V6_FLOW:
2333 case AH_ESP_V6_FLOW:
2334 case AH_V6_FLOW:
2335 case ESP_V6_FLOW:
2336 case IPV6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002337 /* Default is src/dest for IP, no matter the L4 hashing */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002338 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
2339 break;
2340 default:
2341 return -EINVAL;
2342 }
2343
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002344 /* Read flow based hash input set register */
2345 if (flow_pctype) {
2346 i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2347 flow_pctype)) |
2348 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2349 flow_pctype)) << 32);
2350 }
2351
2352 /* Process bits of hash input set */
2353 if (i_set) {
2354 if (i_set & I40E_L4_SRC_MASK)
2355 cmd->data |= RXH_L4_B_0_1;
2356 if (i_set & I40E_L4_DST_MASK)
2357 cmd->data |= RXH_L4_B_2_3;
2358
2359 if (cmd->flow_type == TCP_V4_FLOW ||
2360 cmd->flow_type == UDP_V4_FLOW) {
2361 if (i_set & I40E_L3_SRC_MASK)
2362 cmd->data |= RXH_IP_SRC;
2363 if (i_set & I40E_L3_DST_MASK)
2364 cmd->data |= RXH_IP_DST;
2365 } else if (cmd->flow_type == TCP_V6_FLOW ||
2366 cmd->flow_type == UDP_V6_FLOW) {
2367 if (i_set & I40E_L3_V6_SRC_MASK)
2368 cmd->data |= RXH_IP_SRC;
2369 if (i_set & I40E_L3_V6_DST_MASK)
2370 cmd->data |= RXH_IP_DST;
2371 }
2372 }
2373
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002374 return 0;
2375}
2376
2377/**
Jacob Kellere7930952017-02-06 14:38:49 -08002378 * i40e_check_mask - Check whether a mask field is set
2379 * @mask: the full mask value
2380 * @field; mask of the field to check
2381 *
2382 * If the given mask is fully set, return positive value. If the mask for the
2383 * field is fully unset, return zero. Otherwise return a negative error code.
2384 **/
2385static int i40e_check_mask(u64 mask, u64 field)
2386{
2387 u64 value = mask & field;
2388
2389 if (value == field)
2390 return 1;
2391 else if (!value)
2392 return 0;
2393 else
2394 return -1;
2395}
2396
2397/**
2398 * i40e_parse_rx_flow_user_data - Deconstruct user-defined data
2399 * @fsp: pointer to rx flow specification
2400 * @data: pointer to userdef data structure for storage
2401 *
2402 * Read the user-defined data and deconstruct the value into a structure. No
2403 * other code should read the user-defined data, so as to ensure that every
2404 * place consistently reads the value correctly.
2405 *
2406 * The user-defined field is a 64bit Big Endian format value, which we
2407 * deconstruct by reading bits or bit fields from it. Single bit flags shall
2408 * be defined starting from the highest bits, while small bit field values
2409 * shall be defined starting from the lowest bits.
2410 *
2411 * Returns 0 if the data is valid, and non-zero if the userdef data is invalid
2412 * and the filter should be rejected. The data structure will always be
2413 * modified even if FLOW_EXT is not set.
2414 *
2415 **/
2416static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2417 struct i40e_rx_flow_userdef *data)
2418{
2419 u64 value, mask;
2420 int valid;
2421
2422 /* Zero memory first so it's always consistent. */
2423 memset(data, 0, sizeof(*data));
2424
2425 if (!(fsp->flow_type & FLOW_EXT))
2426 return 0;
2427
2428 value = be64_to_cpu(*((__be64 *)fsp->h_ext.data));
2429 mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data));
2430
2431#define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0)
2432#define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16)
2433#define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0)
2434
2435 valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER);
2436 if (valid < 0) {
2437 return -EINVAL;
2438 } else if (valid) {
2439 data->flex_word = value & I40E_USERDEF_FLEX_WORD;
2440 data->flex_offset =
2441 (value & I40E_USERDEF_FLEX_OFFSET) >> 16;
2442 data->flex_filter = true;
2443 }
2444
2445 return 0;
2446}
2447
2448/**
2449 * i40e_fill_rx_flow_user_data - Fill in user-defined data field
2450 * @fsp: pointer to rx_flow specification
2451 *
2452 * Reads the userdef data structure and properly fills in the user defined
2453 * fields of the rx_flow_spec.
2454 **/
2455static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp,
2456 struct i40e_rx_flow_userdef *data)
2457{
2458 u64 value = 0, mask = 0;
2459
2460 if (data->flex_filter) {
2461 value |= data->flex_word;
2462 value |= (u64)data->flex_offset << 16;
2463 mask |= I40E_USERDEF_FLEX_FILTER;
2464 }
2465
2466 if (value || mask)
2467 fsp->flow_type |= FLOW_EXT;
2468
2469 *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value);
2470 *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask);
2471}
2472
2473/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002474 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
2475 * @pf: Pointer to the physical function struct
2476 * @cmd: The command to get or set Rx flow classification rules
2477 * @rule_locs: Array of used rule locations
2478 *
2479 * This function populates both the total and actual rule count of
2480 * the ethtool flow classification command
2481 *
2482 * Returns 0 on success or -EMSGSIZE if entry not found
2483 **/
2484static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
2485 struct ethtool_rxnfc *cmd,
2486 u32 *rule_locs)
2487{
2488 struct i40e_fdir_filter *rule;
2489 struct hlist_node *node2;
2490 int cnt = 0;
2491
2492 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002493 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002494
2495 hlist_for_each_entry_safe(rule, node2,
2496 &pf->fdir_filter_list, fdir_node) {
2497 if (cnt == cmd->rule_cnt)
2498 return -EMSGSIZE;
2499
2500 rule_locs[cnt] = rule->fd_id;
2501 cnt++;
2502 }
2503
2504 cmd->rule_cnt = cnt;
2505
2506 return 0;
2507}
2508
2509/**
2510 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
2511 * @pf: Pointer to the physical function struct
2512 * @cmd: The command to get or set Rx flow classification rules
2513 *
2514 * This function looks up a filter based on the Rx flow classification
2515 * command and fills the flow spec info for it if found
2516 *
2517 * Returns 0 on success or -EINVAL if filter not found
2518 **/
2519static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2520 struct ethtool_rxnfc *cmd)
2521{
2522 struct ethtool_rx_flow_spec *fsp =
2523 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jacob Kellere7930952017-02-06 14:38:49 -08002524 struct i40e_rx_flow_userdef userdef = {0};
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002525 struct i40e_fdir_filter *rule = NULL;
2526 struct hlist_node *node2;
Jacob Keller36777d92017-03-07 15:05:23 -08002527 u64 input_set;
2528 u16 index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002529
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002530 hlist_for_each_entry_safe(rule, node2,
2531 &pf->fdir_filter_list, fdir_node) {
2532 if (fsp->location <= rule->fd_id)
2533 break;
2534 }
2535
2536 if (!rule || fsp->location != rule->fd_id)
2537 return -EINVAL;
2538
2539 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002540 if (fsp->flow_type == IP_USER_FLOW) {
2541 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2542 fsp->h_u.usr_ip4_spec.proto = 0;
2543 fsp->m_u.usr_ip4_spec.proto = 0;
2544 }
2545
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002546 /* Reverse the src and dest notion, since the HW views them from
2547 * Tx perspective where as the user expects it from Rx filter view.
2548 */
2549 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2550 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08002551 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip;
2552 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip;
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002553
Jacob Keller36777d92017-03-07 15:05:23 -08002554 switch (rule->flow_type) {
Jacob Kellerf223c872017-02-06 14:38:51 -08002555 case SCTP_V4_FLOW:
2556 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
2557 break;
Jacob Keller36777d92017-03-07 15:05:23 -08002558 case TCP_V4_FLOW:
2559 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
2560 break;
2561 case UDP_V4_FLOW:
2562 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
2563 break;
2564 case IP_USER_FLOW:
2565 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
2566 break;
2567 default:
2568 /* If we have stored a filter with a flow type not listed here
2569 * it is almost certainly a driver bug. WARN(), and then
2570 * assign the input_set as if all fields are enabled to avoid
2571 * reading unassigned memory.
2572 */
2573 WARN(1, "Missing input set index for flow_type %d\n",
2574 rule->flow_type);
2575 input_set = 0xFFFFFFFFFFFFFFFFULL;
2576 goto no_input_set;
2577 }
2578
2579 input_set = i40e_read_fd_input_set(pf, index);
2580
2581no_input_set:
2582 if (input_set & I40E_L3_SRC_MASK)
2583 fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF);
2584
2585 if (input_set & I40E_L3_DST_MASK)
2586 fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF);
2587
2588 if (input_set & I40E_L4_SRC_MASK)
2589 fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF);
2590
2591 if (input_set & I40E_L4_DST_MASK)
2592 fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08002593
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002594 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2595 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2596 else
2597 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002598
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002599 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2600 struct i40e_vsi *vsi;
2601
2602 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2603 if (vsi && vsi->type == I40E_VSI_SRIOV) {
Jacob Keller43b15692017-02-06 14:38:48 -08002604 /* VFs are zero-indexed by the driver, but ethtool
2605 * expects them to be one-indexed, so add one here
2606 */
2607 u64 ring_vf = vsi->vf_id + 1;
2608
2609 ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
2610 fsp->ring_cookie |= ring_vf;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002611 }
2612 }
2613
Jacob Keller0e588de2017-02-06 14:38:50 -08002614 if (rule->flex_filter) {
2615 userdef.flex_filter = true;
2616 userdef.flex_word = be16_to_cpu(rule->flex_word);
2617 userdef.flex_offset = rule->flex_offset;
2618 }
2619
Jacob Kellere7930952017-02-06 14:38:49 -08002620 i40e_fill_rx_flow_user_data(fsp, &userdef);
2621
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002622 return 0;
2623}
2624
2625/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002626 * i40e_get_rxnfc - command to get RX flow classification rules
2627 * @netdev: network interface device structure
2628 * @cmd: ethtool rxnfc command
2629 *
2630 * Returns Success if the command is supported.
2631 **/
2632static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2633 u32 *rule_locs)
2634{
2635 struct i40e_netdev_priv *np = netdev_priv(netdev);
2636 struct i40e_vsi *vsi = np->vsi;
2637 struct i40e_pf *pf = vsi->back;
2638 int ret = -EOPNOTSUPP;
2639
2640 switch (cmd->cmd) {
2641 case ETHTOOL_GRXRINGS:
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07002642 cmd->data = vsi->rss_size;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002643 ret = 0;
2644 break;
2645 case ETHTOOL_GRXFH:
2646 ret = i40e_get_rss_hash_opts(pf, cmd);
2647 break;
2648 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002649 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002650 /* report total rule count */
2651 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002652 ret = 0;
2653 break;
2654 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002655 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002656 break;
2657 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002658 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2659 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002660 default:
2661 break;
2662 }
2663
2664 return ret;
2665}
2666
2667/**
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002668 * i40e_get_rss_hash_bits - Read RSS Hash bits from register
2669 * @nfc: pointer to user request
2670 * @i_setc bits currently set
2671 *
2672 * Returns value of bits to be set per user request
2673 **/
2674static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc)
2675{
2676 u64 i_set = i_setc;
2677 u64 src_l3 = 0, dst_l3 = 0;
2678
2679 if (nfc->data & RXH_L4_B_0_1)
2680 i_set |= I40E_L4_SRC_MASK;
2681 else
2682 i_set &= ~I40E_L4_SRC_MASK;
2683 if (nfc->data & RXH_L4_B_2_3)
2684 i_set |= I40E_L4_DST_MASK;
2685 else
2686 i_set &= ~I40E_L4_DST_MASK;
2687
2688 if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) {
2689 src_l3 = I40E_L3_V6_SRC_MASK;
2690 dst_l3 = I40E_L3_V6_DST_MASK;
2691 } else if (nfc->flow_type == TCP_V4_FLOW ||
2692 nfc->flow_type == UDP_V4_FLOW) {
2693 src_l3 = I40E_L3_SRC_MASK;
2694 dst_l3 = I40E_L3_DST_MASK;
2695 } else {
2696 /* Any other flow type are not supported here */
2697 return i_set;
2698 }
2699
2700 if (nfc->data & RXH_IP_SRC)
2701 i_set |= src_l3;
2702 else
2703 i_set &= ~src_l3;
2704 if (nfc->data & RXH_IP_DST)
2705 i_set |= dst_l3;
2706 else
2707 i_set &= ~dst_l3;
2708
2709 return i_set;
2710}
2711
2712/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002713 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2714 * @pf: pointer to the physical function struct
2715 * @cmd: ethtool rxnfc command
2716 *
2717 * Returns Success if the flow input set is supported.
2718 **/
2719static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2720{
2721 struct i40e_hw *hw = &pf->hw;
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002722 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
2723 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002724 u8 flow_pctype = 0;
2725 u64 i_set, i_setc;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002726
Carolyn Wyborny83d14c52017-06-07 05:43:07 -04002727 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
2728 dev_err(&pf->pdev->dev,
2729 "Change of RSS hash input set is not supported when MFP mode is enabled\n");
2730 return -EOPNOTSUPP;
2731 }
2732
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002733 /* RSS does not support anything other than hashing
2734 * to queues on src and dst IPs and ports
2735 */
2736 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2737 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2738 return -EINVAL;
2739
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002740 switch (nfc->flow_type) {
2741 case TCP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002742 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002743 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002744 hena |=
2745 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002746 break;
2747 case TCP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002748 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002749 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002750 hena |=
2751 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002752 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002753 hena |=
2754 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002755 break;
2756 case UDP_V4_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002757 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002758 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002759 hena |=
2760 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
2761 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002762
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002763 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002764 break;
2765 case UDP_V6_FLOW:
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002766 flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP;
Jacob Kellerd36e41d2017-06-23 04:24:46 -04002767 if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE)
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002768 hena |=
2769 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
2770 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
Anjali Singhai Jain3d0da5b2015-12-22 14:25:05 -08002771
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002772 hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002773 break;
2774 case AH_ESP_V4_FLOW:
2775 case AH_V4_FLOW:
2776 case ESP_V4_FLOW:
2777 case SCTP_V4_FLOW:
2778 if ((nfc->data & RXH_L4_B_0_1) ||
2779 (nfc->data & RXH_L4_B_2_3))
2780 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002781 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002782 break;
2783 case AH_ESP_V6_FLOW:
2784 case AH_V6_FLOW:
2785 case ESP_V6_FLOW:
2786 case SCTP_V6_FLOW:
2787 if ((nfc->data & RXH_L4_B_0_1) ||
2788 (nfc->data & RXH_L4_B_2_3))
2789 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002790 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002791 break;
2792 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002793 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2794 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002795 break;
2796 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002797 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2798 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002799 break;
2800 default:
2801 return -EINVAL;
2802 }
2803
Carolyn Wybornyeb0dd6e2016-07-27 12:02:40 -07002804 if (flow_pctype) {
2805 i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0,
2806 flow_pctype)) |
2807 ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1,
2808 flow_pctype)) << 32);
2809 i_set = i40e_get_rss_hash_bits(nfc, i_setc);
2810 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype),
2811 (u32)i_set);
2812 i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype),
2813 (u32)(i_set >> 32));
2814 hena |= BIT_ULL(flow_pctype);
2815 }
2816
Shannon Nelson272cdaf22016-02-17 16:12:21 -08002817 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
2818 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002819 i40e_flush(hw);
2820
2821 return 0;
2822}
2823
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002824/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002825 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2826 * @vsi: Pointer to the targeted VSI
2827 * @input: The filter to update or NULL to indicate deletion
2828 * @sw_idx: Software index to the filter
2829 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002830 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002831 * This function updates (or deletes) a Flow Director entry from
2832 * the hlist of the corresponding PF
2833 *
2834 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002835 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002836static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2837 struct i40e_fdir_filter *input,
2838 u16 sw_idx,
2839 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002840{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002841 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002842 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002843 struct hlist_node *node2;
2844 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002845
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002846 parent = NULL;
2847 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002848
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002849 hlist_for_each_entry_safe(rule, node2,
2850 &pf->fdir_filter_list, fdir_node) {
2851 /* hash found, or no matching entry */
2852 if (rule->fd_id >= sw_idx)
2853 break;
2854 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002855 }
2856
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002857 /* if there is an old rule occupying our place remove it */
2858 if (rule && (rule->fd_id == sw_idx)) {
Jacob Kellerc6da5252017-02-06 14:39:13 -08002859 /* Remove this rule, since we're either deleting it, or
2860 * replacing it.
2861 */
2862 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002863 hlist_del(&rule->fdir_node);
2864 kfree(rule);
2865 pf->fdir_pf_active_filters--;
2866 }
2867
Jacob Kellerc6da5252017-02-06 14:39:13 -08002868 /* If we weren't given an input, this is a delete, so just return the
2869 * error code indicating if there was an entry at the requested slot
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002870 */
2871 if (!input)
2872 return err;
2873
Jacob Kellerc6da5252017-02-06 14:39:13 -08002874 /* Otherwise, install the new rule as requested */
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002875 INIT_HLIST_NODE(&input->fdir_node);
2876
2877 /* add filter to the list */
2878 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002879 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002880 else
2881 hlist_add_head(&input->fdir_node,
2882 &pf->fdir_filter_list);
2883
2884 /* update counts */
2885 pf->fdir_pf_active_filters++;
2886
2887 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002888}
2889
2890/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002891 * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table
2892 * @pf: pointer to PF structure
2893 *
2894 * This function searches the list of filters and determines which FLX_PIT
2895 * entries are still required. It will prune any entries which are no longer
2896 * in use after the deletion.
2897 **/
2898static void i40e_prune_flex_pit_list(struct i40e_pf *pf)
2899{
2900 struct i40e_flex_pit *entry, *tmp;
2901 struct i40e_fdir_filter *rule;
2902
2903 /* First, we'll check the l3 table */
2904 list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) {
2905 bool found = false;
2906
2907 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2908 if (rule->flow_type != IP_USER_FLOW)
2909 continue;
2910 if (rule->flex_filter &&
2911 rule->flex_offset == entry->src_offset) {
2912 found = true;
2913 break;
2914 }
2915 }
2916
2917 /* If we didn't find the filter, then we can prune this entry
2918 * from the list.
2919 */
2920 if (!found) {
2921 list_del(&entry->list);
2922 kfree(entry);
2923 }
2924 }
2925
2926 /* Followed by the L4 table */
2927 list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) {
2928 bool found = false;
2929
2930 hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) {
2931 /* Skip this filter if it's L3, since we already
2932 * checked those in the above loop
2933 */
2934 if (rule->flow_type == IP_USER_FLOW)
2935 continue;
2936 if (rule->flex_filter &&
2937 rule->flex_offset == entry->src_offset) {
2938 found = true;
2939 break;
2940 }
2941 }
2942
2943 /* If we didn't find the filter, then we can prune this entry
2944 * from the list.
2945 */
2946 if (!found) {
2947 list_del(&entry->list);
2948 kfree(entry);
2949 }
2950 }
2951}
2952
2953/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002954 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2955 * @vsi: Pointer to the targeted VSI
2956 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002957 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002958 * The function removes a Flow Director filter entry from the
2959 * hlist of the corresponding PF
2960 *
2961 * Returns 0 on success
2962 */
2963static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2964 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002965{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002966 struct ethtool_rx_flow_spec *fsp =
2967 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002968 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002969 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002970
Jacob Keller0da36b92017-04-19 09:25:55 -04002971 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
2972 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002973 return -EBUSY;
2974
Jacob Keller0da36b92017-04-19 09:25:55 -04002975 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002976 return -EBUSY;
2977
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002978 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002979
Jacob Keller0e588de2017-02-06 14:38:50 -08002980 i40e_prune_flex_pit_list(pf);
2981
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002982 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002983 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002984}
2985
2986/**
Jacob Keller0e588de2017-02-06 14:38:50 -08002987 * i40e_unused_pit_index - Find an unused PIT index for given list
2988 * @pf: the PF data structure
2989 *
2990 * Find the first unused flexible PIT index entry. We search both the L3 and
2991 * L4 flexible PIT lists so that the returned index is unique and unused by
2992 * either currently programmed L3 or L4 filters. We use a bit field as storage
2993 * to track which indexes are already used.
2994 **/
2995static u8 i40e_unused_pit_index(struct i40e_pf *pf)
2996{
2997 unsigned long available_index = 0xFF;
2998 struct i40e_flex_pit *entry;
2999
3000 /* We need to make sure that the new index isn't in use by either L3
3001 * or L4 filters so that IP_USER_FLOW filters can program both L3 and
3002 * L4 to use the same index.
3003 */
3004
3005 list_for_each_entry(entry, &pf->l4_flex_pit_list, list)
3006 clear_bit(entry->pit_index, &available_index);
3007
3008 list_for_each_entry(entry, &pf->l3_flex_pit_list, list)
3009 clear_bit(entry->pit_index, &available_index);
3010
3011 return find_first_bit(&available_index, 8);
3012}
3013
3014/**
3015 * i40e_find_flex_offset - Find an existing flex src_offset
3016 * @flex_pit_list: L3 or L4 flex PIT list
3017 * @src_offset: new src_offset to find
3018 *
3019 * Searches the flex_pit_list for an existing offset. If no offset is
3020 * currently programmed, then this will return an ERR_PTR if there is no space
3021 * to add a new offset, otherwise it returns NULL.
3022 **/
3023static
3024struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list,
3025 u16 src_offset)
3026{
3027 struct i40e_flex_pit *entry;
3028 int size = 0;
3029
3030 /* Search for the src_offset first. If we find a matching entry
3031 * already programmed, we can simply re-use it.
3032 */
3033 list_for_each_entry(entry, flex_pit_list, list) {
3034 size++;
3035 if (entry->src_offset == src_offset)
3036 return entry;
3037 }
3038
3039 /* If we haven't found an entry yet, then the provided src offset has
3040 * not yet been programmed. We will program the src offset later on,
3041 * but we need to indicate whether there is enough space to do so
3042 * here. We'll make use of ERR_PTR for this purpose.
3043 */
3044 if (size >= I40E_FLEX_PIT_TABLE_SIZE)
3045 return ERR_PTR(-ENOSPC);
3046
3047 return NULL;
3048}
3049
3050/**
3051 * i40e_add_flex_offset - Add src_offset to flex PIT table list
3052 * @flex_pit_list: L3 or L4 flex PIT list
3053 * @src_offset: new src_offset to add
3054 * @pit_index: the PIT index to program
3055 *
3056 * This function programs the new src_offset to the list. It is expected that
3057 * i40e_find_flex_offset has already been tried and returned NULL, indicating
3058 * that this offset is not programmed, and that the list has enough space to
3059 * store another offset.
3060 *
3061 * Returns 0 on success, and negative value on error.
3062 **/
3063static int i40e_add_flex_offset(struct list_head *flex_pit_list,
3064 u16 src_offset,
3065 u8 pit_index)
3066{
3067 struct i40e_flex_pit *new_pit, *entry;
3068
3069 new_pit = kzalloc(sizeof(*entry), GFP_KERNEL);
3070 if (!new_pit)
3071 return -ENOMEM;
3072
3073 new_pit->src_offset = src_offset;
3074 new_pit->pit_index = pit_index;
3075
3076 /* We need to insert this item such that the list is sorted by
3077 * src_offset in ascending order.
3078 */
3079 list_for_each_entry(entry, flex_pit_list, list) {
3080 if (new_pit->src_offset < entry->src_offset) {
3081 list_add_tail(&new_pit->list, &entry->list);
3082 return 0;
3083 }
3084
3085 /* If we found an entry with our offset already programmed we
3086 * can simply return here, after freeing the memory. However,
3087 * if the pit_index does not match we need to report an error.
3088 */
3089 if (new_pit->src_offset == entry->src_offset) {
3090 int err = 0;
3091
3092 /* If the PIT index is not the same we can't re-use
3093 * the entry, so we must report an error.
3094 */
3095 if (new_pit->pit_index != entry->pit_index)
3096 err = -EINVAL;
3097
3098 kfree(new_pit);
3099 return err;
3100 }
3101 }
3102
3103 /* If we reached here, then we haven't yet added the item. This means
3104 * that we should add the item at the end of the list.
3105 */
3106 list_add_tail(&new_pit->list, flex_pit_list);
3107 return 0;
3108}
3109
3110/**
3111 * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table
3112 * @pf: Pointer to the PF structure
3113 * @flex_pit_list: list of flexible src offsets in use
3114 * #flex_pit_start: index to first entry for this section of the table
3115 *
3116 * In order to handle flexible data, the hardware uses a table of values
3117 * called the FLX_PIT table. This table is used to indicate which sections of
3118 * the input correspond to what PIT index values. Unfortunately, hardware is
3119 * very restrictive about programming this table. Entries must be ordered by
3120 * src_offset in ascending order, without duplicates. Additionally, unused
3121 * entries must be set to the unused index value, and must have valid size and
3122 * length according to the src_offset ordering.
3123 *
3124 * This function will reprogram the FLX_PIT register from a book-keeping
3125 * structure that we guarantee is already ordered correctly, and has no more
3126 * than 3 entries.
3127 *
3128 * To make things easier, we only support flexible values of one word length,
3129 * rather than allowing variable length flexible values.
3130 **/
3131static void __i40e_reprogram_flex_pit(struct i40e_pf *pf,
3132 struct list_head *flex_pit_list,
3133 int flex_pit_start)
3134{
3135 struct i40e_flex_pit *entry = NULL;
3136 u16 last_offset = 0;
3137 int i = 0, j = 0;
3138
3139 /* First, loop over the list of flex PIT entries, and reprogram the
3140 * registers.
3141 */
3142 list_for_each_entry(entry, flex_pit_list, list) {
3143 /* We have to be careful when programming values for the
3144 * largest SRC_OFFSET value. It is possible that adding
3145 * additional empty values at the end would overflow the space
3146 * for the SRC_OFFSET in the FLX_PIT register. To avoid this,
3147 * we check here and add the empty values prior to adding the
3148 * largest value.
3149 *
3150 * To determine this, we will use a loop from i+1 to 3, which
3151 * will determine whether the unused entries would have valid
3152 * SRC_OFFSET. Note that there cannot be extra entries past
3153 * this value, because the only valid values would have been
3154 * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not
3155 * have been added to the list in the first place.
3156 */
3157 for (j = i + 1; j < 3; j++) {
3158 u16 offset = entry->src_offset + j;
3159 int index = flex_pit_start + i;
3160 u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3161 1,
3162 offset - 3);
3163
3164 if (offset > I40E_MAX_FLEX_SRC_OFFSET) {
3165 i40e_write_rx_ctl(&pf->hw,
3166 I40E_PRTQF_FLX_PIT(index),
3167 value);
3168 i++;
3169 }
3170 }
3171
3172 /* Now, we can program the actual value into the table */
3173 i40e_write_rx_ctl(&pf->hw,
3174 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3175 I40E_FLEX_PREP_VAL(entry->pit_index + 50,
3176 1,
3177 entry->src_offset));
3178 i++;
3179 }
3180
3181 /* In order to program the last entries in the table, we need to
3182 * determine the valid offset. If the list is empty, we'll just start
3183 * with 0. Otherwise, we'll start with the last item offset and add 1.
3184 * This ensures that all entries have valid sizes. If we don't do this
3185 * correctly, the hardware will disable flexible field parsing.
3186 */
3187 if (!list_empty(flex_pit_list))
3188 last_offset = list_prev_entry(entry, list)->src_offset + 1;
3189
3190 for (; i < 3; i++, last_offset++) {
3191 i40e_write_rx_ctl(&pf->hw,
3192 I40E_PRTQF_FLX_PIT(flex_pit_start + i),
3193 I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED,
3194 1,
3195 last_offset));
3196 }
3197}
3198
3199/**
3200 * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change
3201 * @pf: pointer to the PF structure
3202 *
3203 * This function reprograms both the L3 and L4 FLX_PIT tables. See the
3204 * internal helper function for implementation details.
3205 **/
3206static void i40e_reprogram_flex_pit(struct i40e_pf *pf)
3207{
3208 __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list,
3209 I40E_FLEX_PIT_IDX_START_L3);
3210
3211 __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list,
3212 I40E_FLEX_PIT_IDX_START_L4);
3213
3214 /* We also need to program the L3 and L4 GLQF ORT register */
3215 i40e_write_rx_ctl(&pf->hw,
3216 I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX),
3217 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3,
3218 3, 1));
3219
3220 i40e_write_rx_ctl(&pf->hw,
3221 I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX),
3222 I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4,
3223 3, 1));
3224}
3225
3226/**
Jacob Keller9229e992017-02-06 14:38:47 -08003227 * i40e_flow_str - Converts a flow_type into a human readable string
3228 * @flow_type: the flow type from a flow specification
3229 *
3230 * Currently only flow types we support are included here, and the string
3231 * value attempts to match what ethtool would use to configure this flow type.
3232 **/
3233static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp)
3234{
3235 switch (fsp->flow_type & ~FLOW_EXT) {
3236 case TCP_V4_FLOW:
3237 return "tcp4";
3238 case UDP_V4_FLOW:
3239 return "udp4";
3240 case SCTP_V4_FLOW:
3241 return "sctp4";
3242 case IP_USER_FLOW:
3243 return "ip4";
3244 default:
3245 return "unknown";
3246 }
3247}
3248
3249/**
Jacob Keller0e588de2017-02-06 14:38:50 -08003250 * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index
3251 * @pit_index: PIT index to convert
3252 *
3253 * Returns the mask for a given PIT index. Will return 0 if the pit_index is
3254 * of range.
3255 **/
3256static u64 i40e_pit_index_to_mask(int pit_index)
3257{
3258 switch (pit_index) {
3259 case 0:
3260 return I40E_FLEX_50_MASK;
3261 case 1:
3262 return I40E_FLEX_51_MASK;
3263 case 2:
3264 return I40E_FLEX_52_MASK;
3265 case 3:
3266 return I40E_FLEX_53_MASK;
3267 case 4:
3268 return I40E_FLEX_54_MASK;
3269 case 5:
3270 return I40E_FLEX_55_MASK;
3271 case 6:
3272 return I40E_FLEX_56_MASK;
3273 case 7:
3274 return I40E_FLEX_57_MASK;
3275 default:
3276 return 0;
3277 }
3278}
3279
3280/**
Jacob Keller9229e992017-02-06 14:38:47 -08003281 * i40e_print_input_set - Show changes between two input sets
3282 * @vsi: the vsi being configured
3283 * @old: the old input set
3284 * @new: the new input set
3285 *
3286 * Print the difference between old and new input sets by showing which series
3287 * of words are toggled on or off. Only displays the bits we actually support
3288 * changing.
3289 **/
3290static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new)
3291{
3292 struct i40e_pf *pf = vsi->back;
3293 bool old_value, new_value;
Jacob Keller0e588de2017-02-06 14:38:50 -08003294 int i;
Jacob Keller9229e992017-02-06 14:38:47 -08003295
3296 old_value = !!(old & I40E_L3_SRC_MASK);
3297 new_value = !!(new & I40E_L3_SRC_MASK);
3298 if (old_value != new_value)
3299 netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n",
3300 old_value ? "ON" : "OFF",
3301 new_value ? "ON" : "OFF");
3302
3303 old_value = !!(old & I40E_L3_DST_MASK);
3304 new_value = !!(new & I40E_L3_DST_MASK);
3305 if (old_value != new_value)
3306 netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n",
3307 old_value ? "ON" : "OFF",
3308 new_value ? "ON" : "OFF");
3309
3310 old_value = !!(old & I40E_L4_SRC_MASK);
3311 new_value = !!(new & I40E_L4_SRC_MASK);
3312 if (old_value != new_value)
3313 netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n",
3314 old_value ? "ON" : "OFF",
3315 new_value ? "ON" : "OFF");
3316
3317 old_value = !!(old & I40E_L4_DST_MASK);
3318 new_value = !!(new & I40E_L4_DST_MASK);
3319 if (old_value != new_value)
3320 netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n",
3321 old_value ? "ON" : "OFF",
3322 new_value ? "ON" : "OFF");
3323
3324 old_value = !!(old & I40E_VERIFY_TAG_MASK);
3325 new_value = !!(new & I40E_VERIFY_TAG_MASK);
3326 if (old_value != new_value)
3327 netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n",
3328 old_value ? "ON" : "OFF",
3329 new_value ? "ON" : "OFF");
3330
Jacob Keller0e588de2017-02-06 14:38:50 -08003331 /* Show change of flexible filter entries */
3332 for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) {
3333 u64 flex_mask = i40e_pit_index_to_mask(i);
3334
3335 old_value = !!(old & flex_mask);
3336 new_value = !!(new & flex_mask);
3337 if (old_value != new_value)
3338 netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n",
3339 i,
3340 old_value ? "ON" : "OFF",
3341 new_value ? "ON" : "OFF");
3342 }
3343
Jacob Keller9229e992017-02-06 14:38:47 -08003344 netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n",
3345 old);
3346 netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n",
3347 new);
3348}
3349
3350/**
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003351 * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid
Jacob Keller36777d92017-03-07 15:05:23 -08003352 * @vsi: pointer to the targeted VSI
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003353 * @fsp: pointer to Rx flow specification
Jacob Keller0e588de2017-02-06 14:38:50 -08003354 * @userdef: userdefined data from flow specification
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003355 *
Jacob Keller9229e992017-02-06 14:38:47 -08003356 * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support
3357 * for partial matches exists with a few limitations. First, hardware only
3358 * supports masking by word boundary (2 bytes) and not per individual bit.
3359 * Second, hardware is limited to using one mask for a flow type and cannot
3360 * use a separate mask for each filter.
3361 *
3362 * To support these limitations, if we already have a configured filter for
3363 * the specified type, this function enforces that new filters of the type
3364 * match the configured input set. Otherwise, if we do not have a filter of
3365 * the specified type, we allow the input set to be updated to match the
3366 * desired filter.
3367 *
3368 * To help ensure that administrators understand why filters weren't displayed
3369 * as supported, we print a diagnostic message displaying how the input set
3370 * would change and warning to delete the preexisting filters if required.
3371 *
3372 * Returns 0 on successful input set match, and a negative return code on
3373 * failure.
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003374 **/
Jacob Keller36777d92017-03-07 15:05:23 -08003375static int i40e_check_fdir_input_set(struct i40e_vsi *vsi,
Jacob Keller0e588de2017-02-06 14:38:50 -08003376 struct ethtool_rx_flow_spec *fsp,
3377 struct i40e_rx_flow_userdef *userdef)
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003378{
Jacob Keller36777d92017-03-07 15:05:23 -08003379 struct i40e_pf *pf = vsi->back;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003380 struct ethtool_tcpip4_spec *tcp_ip4_spec;
3381 struct ethtool_usrip4_spec *usr_ip4_spec;
Jacob Keller36777d92017-03-07 15:05:23 -08003382 u64 current_mask, new_mask;
Jacob Keller0e588de2017-02-06 14:38:50 -08003383 bool new_flex_offset = false;
3384 bool flex_l3 = false;
Jacob Keller9229e992017-02-06 14:38:47 -08003385 u16 *fdir_filter_count;
Jacob Keller0e588de2017-02-06 14:38:50 -08003386 u16 index, src_offset = 0;
3387 u8 pit_index = 0;
3388 int err;
Jacob Keller36777d92017-03-07 15:05:23 -08003389
3390 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003391 case SCTP_V4_FLOW:
3392 index = I40E_FILTER_PCTYPE_NONF_IPV4_SCTP;
3393 fdir_filter_count = &pf->fd_sctp4_filter_cnt;
3394 break;
Jacob Keller36777d92017-03-07 15:05:23 -08003395 case TCP_V4_FLOW:
3396 index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
Jacob Keller9229e992017-02-06 14:38:47 -08003397 fdir_filter_count = &pf->fd_tcp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003398 break;
3399 case UDP_V4_FLOW:
3400 index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP;
Jacob Keller9229e992017-02-06 14:38:47 -08003401 fdir_filter_count = &pf->fd_udp4_filter_cnt;
Jacob Keller36777d92017-03-07 15:05:23 -08003402 break;
3403 case IP_USER_FLOW:
3404 index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
Jacob Keller9229e992017-02-06 14:38:47 -08003405 fdir_filter_count = &pf->fd_ip4_filter_cnt;
Jacob Keller0e588de2017-02-06 14:38:50 -08003406 flex_l3 = true;
Jacob Keller36777d92017-03-07 15:05:23 -08003407 break;
3408 default:
3409 return -EOPNOTSUPP;
3410 }
3411
3412 /* Read the current input set from register memory. */
3413 current_mask = i40e_read_fd_input_set(pf, index);
3414 new_mask = current_mask;
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003415
Jacob Keller9229e992017-02-06 14:38:47 -08003416 /* Determine, if any, the required changes to the input set in order
3417 * to support the provided mask.
3418 *
3419 * Hardware only supports masking at word (2 byte) granularity and does
3420 * not support full bitwise masking. This implementation simplifies
3421 * even further and only supports fully enabled or fully disabled
3422 * masks for each field, even though we could split the ip4src and
3423 * ip4dst fields.
3424 */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003425 switch (fsp->flow_type & ~FLOW_EXT) {
Jacob Kellerf223c872017-02-06 14:38:51 -08003426 case SCTP_V4_FLOW:
3427 new_mask &= ~I40E_VERIFY_TAG_MASK;
3428 /* Fall through */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003429 case TCP_V4_FLOW:
3430 case UDP_V4_FLOW:
3431 tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec;
3432
3433 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003434 if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3435 new_mask |= I40E_L3_SRC_MASK;
3436 else if (!tcp_ip4_spec->ip4src)
3437 new_mask &= ~I40E_L3_SRC_MASK;
3438 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003439 return -EOPNOTSUPP;
3440
3441 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003442 if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3443 new_mask |= I40E_L3_DST_MASK;
3444 else if (!tcp_ip4_spec->ip4dst)
3445 new_mask &= ~I40E_L3_DST_MASK;
3446 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003447 return -EOPNOTSUPP;
3448
3449 /* L4 source port */
Jacob Keller36777d92017-03-07 15:05:23 -08003450 if (tcp_ip4_spec->psrc == htons(0xFFFF))
3451 new_mask |= I40E_L4_SRC_MASK;
3452 else if (!tcp_ip4_spec->psrc)
3453 new_mask &= ~I40E_L4_SRC_MASK;
3454 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003455 return -EOPNOTSUPP;
3456
3457 /* L4 destination port */
Jacob Keller36777d92017-03-07 15:05:23 -08003458 if (tcp_ip4_spec->pdst == htons(0xFFFF))
3459 new_mask |= I40E_L4_DST_MASK;
3460 else if (!tcp_ip4_spec->pdst)
3461 new_mask &= ~I40E_L4_DST_MASK;
3462 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003463 return -EOPNOTSUPP;
3464
3465 /* Filtering on Type of Service is not supported. */
3466 if (tcp_ip4_spec->tos)
3467 return -EOPNOTSUPP;
3468
3469 break;
3470 case IP_USER_FLOW:
3471 usr_ip4_spec = &fsp->m_u.usr_ip4_spec;
3472
3473 /* IPv4 source address */
Jacob Keller36777d92017-03-07 15:05:23 -08003474 if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF))
3475 new_mask |= I40E_L3_SRC_MASK;
3476 else if (!usr_ip4_spec->ip4src)
3477 new_mask &= ~I40E_L3_SRC_MASK;
3478 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003479 return -EOPNOTSUPP;
3480
3481 /* IPv4 destination address */
Jacob Keller36777d92017-03-07 15:05:23 -08003482 if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF))
3483 new_mask |= I40E_L3_DST_MASK;
3484 else if (!usr_ip4_spec->ip4dst)
3485 new_mask &= ~I40E_L3_DST_MASK;
3486 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003487 return -EOPNOTSUPP;
3488
3489 /* First 4 bytes of L4 header */
Jacob Keller36777d92017-03-07 15:05:23 -08003490 if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF))
3491 new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK;
3492 else if (!usr_ip4_spec->l4_4_bytes)
3493 new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK);
3494 else
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003495 return -EOPNOTSUPP;
3496
3497 /* Filtering on Type of Service is not supported. */
3498 if (usr_ip4_spec->tos)
3499 return -EOPNOTSUPP;
3500
Jacob Keller0e588de2017-02-06 14:38:50 -08003501 /* Filtering on IP version is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003502 if (usr_ip4_spec->ip_ver)
3503 return -EINVAL;
3504
Jacob Keller0e588de2017-02-06 14:38:50 -08003505 /* Filtering on L4 protocol is not supported */
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003506 if (usr_ip4_spec->proto)
3507 return -EINVAL;
Jacob Keller36777d92017-03-07 15:05:23 -08003508
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003509 break;
3510 default:
3511 return -EOPNOTSUPP;
3512 }
3513
Jacob Keller0e588de2017-02-06 14:38:50 -08003514 /* First, clear all flexible filter entries */
3515 new_mask &= ~I40E_FLEX_INPUT_MASK;
3516
3517 /* If we have a flexible filter, try to add this offset to the correct
3518 * flexible filter PIT list. Once finished, we can update the mask.
3519 * If the src_offset changed, we will get a new mask value which will
3520 * trigger an input set change.
Jacob Keller9229e992017-02-06 14:38:47 -08003521 */
Jacob Keller0e588de2017-02-06 14:38:50 -08003522 if (userdef->flex_filter) {
3523 struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL;
3524
3525 /* Flexible offset must be even, since the flexible payload
3526 * must be aligned on 2-byte boundary.
3527 */
3528 if (userdef->flex_offset & 0x1) {
3529 dev_warn(&pf->pdev->dev,
3530 "Flexible data offset must be 2-byte aligned\n");
3531 return -EINVAL;
3532 }
3533
3534 src_offset = userdef->flex_offset >> 1;
3535
3536 /* FLX_PIT source offset value is only so large */
3537 if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) {
3538 dev_warn(&pf->pdev->dev,
3539 "Flexible data must reside within first 64 bytes of the packet payload\n");
3540 return -EINVAL;
3541 }
3542
3543 /* See if this offset has already been programmed. If we get
3544 * an ERR_PTR, then the filter is not safe to add. Otherwise,
3545 * if we get a NULL pointer, this means we will need to add
3546 * the offset.
3547 */
3548 flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list,
3549 src_offset);
3550 if (IS_ERR(flex_pit))
3551 return PTR_ERR(flex_pit);
3552
3553 /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown)
3554 * packet types, and thus we need to program both L3 and L4
3555 * flexible values. These must have identical flexible index,
3556 * as otherwise we can't correctly program the input set. So
3557 * we'll find both an L3 and L4 index and make sure they are
3558 * the same.
3559 */
3560 if (flex_l3) {
3561 l3_flex_pit =
3562 i40e_find_flex_offset(&pf->l3_flex_pit_list,
3563 src_offset);
3564 if (IS_ERR(l3_flex_pit))
3565 return PTR_ERR(l3_flex_pit);
3566
3567 if (flex_pit) {
3568 /* If we already had a matching L4 entry, we
3569 * need to make sure that the L3 entry we
3570 * obtained uses the same index.
3571 */
3572 if (l3_flex_pit) {
3573 if (l3_flex_pit->pit_index !=
3574 flex_pit->pit_index) {
3575 return -EINVAL;
3576 }
3577 } else {
3578 new_flex_offset = true;
3579 }
3580 } else {
3581 flex_pit = l3_flex_pit;
3582 }
3583 }
3584
3585 /* If we didn't find an existing flex offset, we need to
3586 * program a new one. However, we don't immediately program it
3587 * here because we will wait to program until after we check
3588 * that it is safe to change the input set.
3589 */
3590 if (!flex_pit) {
3591 new_flex_offset = true;
3592 pit_index = i40e_unused_pit_index(pf);
3593 } else {
3594 pit_index = flex_pit->pit_index;
3595 }
3596
3597 /* Update the mask with the new offset */
3598 new_mask |= i40e_pit_index_to_mask(pit_index);
3599 }
3600
3601 /* If the mask and flexible filter offsets for this filter match the
3602 * currently programmed values we don't need any input set change, so
3603 * this filter is safe to install.
3604 */
3605 if (new_mask == current_mask && !new_flex_offset)
Jacob Keller9229e992017-02-06 14:38:47 -08003606 return 0;
3607
3608 netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n",
3609 i40e_flow_str(fsp));
3610 i40e_print_input_set(vsi, current_mask, new_mask);
Jacob Keller0e588de2017-02-06 14:38:50 -08003611 if (new_flex_offset) {
3612 netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d",
3613 pit_index, src_offset);
3614 }
Jacob Keller9229e992017-02-06 14:38:47 -08003615
3616 /* Hardware input sets are global across multiple ports, so even the
3617 * main port cannot change them when in MFP mode as this would impact
3618 * any filters on the other ports.
3619 */
3620 if (pf->flags & I40E_FLAG_MFP_ENABLED) {
3621 netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n");
Jacob Keller36777d92017-03-07 15:05:23 -08003622 return -EOPNOTSUPP;
Jacob Keller9229e992017-02-06 14:38:47 -08003623 }
3624
3625 /* This filter requires us to update the input set. However, hardware
3626 * only supports one input set per flow type, and does not support
3627 * separate masks for each filter. This means that we can only support
3628 * a single mask for all filters of a specific type.
3629 *
3630 * If we have preexisting filters, they obviously depend on the
3631 * current programmed input set. Display a diagnostic message in this
3632 * case explaining why the filter could not be accepted.
3633 */
3634 if (*fdir_filter_count) {
3635 netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n",
3636 i40e_flow_str(fsp),
3637 *fdir_filter_count);
3638 return -EOPNOTSUPP;
3639 }
3640
3641 i40e_write_fd_input_set(pf, index, new_mask);
Jacob Keller36777d92017-03-07 15:05:23 -08003642
Jacob Keller0e588de2017-02-06 14:38:50 -08003643 /* Add the new offset and update table, if necessary */
3644 if (new_flex_offset) {
3645 err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset,
3646 pit_index);
3647 if (err)
3648 return err;
3649
3650 if (flex_l3) {
3651 err = i40e_add_flex_offset(&pf->l3_flex_pit_list,
3652 src_offset,
3653 pit_index);
3654 if (err)
3655 return err;
3656 }
3657
3658 i40e_reprogram_flex_pit(pf);
3659 }
3660
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003661 return 0;
3662}
3663
3664/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003665 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003666 * @vsi: pointer to the targeted VSI
3667 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003668 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003669 * Add Flow Director filters for a specific flow spec based on their
3670 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003671 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003672static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
3673 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003674{
Jacob Kellere7930952017-02-06 14:38:49 -08003675 struct i40e_rx_flow_userdef userdef;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003676 struct ethtool_rx_flow_spec *fsp;
3677 struct i40e_fdir_filter *input;
Jacob Keller43b15692017-02-06 14:38:48 -08003678 u16 dest_vsi = 0, q_index = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003679 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003680 int ret = -EINVAL;
Jacob Keller43b15692017-02-06 14:38:48 -08003681 u8 dest_ctl;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003682
3683 if (!vsi)
3684 return -EINVAL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003685 pf = vsi->back;
3686
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003687 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
3688 return -EOPNOTSUPP;
3689
Jacob Keller47994c12017-04-19 09:25:57 -04003690 if (pf->flags & I40E_FLAG_FD_SB_AUTO_DISABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003691 return -ENOSPC;
3692
Jacob Keller0da36b92017-04-19 09:25:55 -04003693 if (test_bit(__I40E_RESET_RECOVERY_PENDING, pf->state) ||
3694 test_bit(__I40E_RESET_INTR_RECEIVED, pf->state))
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00003695 return -EBUSY;
3696
Jacob Keller0da36b92017-04-19 09:25:55 -04003697 if (test_bit(__I40E_FD_FLUSH_REQUESTED, pf->state))
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00003698 return -EBUSY;
3699
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00003700 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
3701
Jacob Kellere7930952017-02-06 14:38:49 -08003702 /* Parse the user-defined field */
3703 if (i40e_parse_rx_flow_user_data(fsp, &userdef))
3704 return -EINVAL;
3705
Jacob Keller1ec8dea2017-02-06 14:39:12 -08003706 /* Extended MAC field is not supported */
3707 if (fsp->flow_type & FLOW_MAC_EXT)
3708 return -EINVAL;
3709
Jacob Keller0e588de2017-02-06 14:38:50 -08003710 ret = i40e_check_fdir_input_set(vsi, fsp, &userdef);
Jacob Kellerfaa16e02017-03-07 15:05:22 -08003711 if (ret)
3712 return ret;
3713
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003714 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
3715 pf->hw.func_caps.fd_filters_guaranteed)) {
3716 return -EINVAL;
3717 }
3718
Jacob Keller43b15692017-02-06 14:38:48 -08003719 /* ring_cookie is either the drop index, or is a mask of the queue
3720 * index and VF id we wish to target.
3721 */
3722 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) {
3723 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
3724 } else {
3725 u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
3726 u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie);
3727
3728 if (!vf) {
3729 if (ring >= vsi->num_queue_pairs)
3730 return -EINVAL;
3731 dest_vsi = vsi->id;
3732 } else {
3733 /* VFs are zero-indexed, so we subtract one here */
3734 vf--;
3735
3736 if (vf >= pf->num_alloc_vfs)
3737 return -EINVAL;
3738 if (ring >= pf->vf[vf].num_queue_pairs)
3739 return -EINVAL;
3740 dest_vsi = pf->vf[vf].lan_vsi_id;
3741 }
3742 dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
3743 q_index = ring;
3744 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003745
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003746 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003747
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003748 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003749 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003750
3751 input->fd_id = fsp->location;
Jacob Keller43b15692017-02-06 14:38:48 -08003752 input->q_index = q_index;
3753 input->dest_vsi = dest_vsi;
3754 input->dest_ctl = dest_ctl;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003755 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04003756 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Jacob Keller43b15692017-02-06 14:38:48 -08003757 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3758 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Jacob Kellere7930952017-02-06 14:38:49 -08003759 input->flow_type = fsp->flow_type & ~FLOW_EXT;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003760 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00003761
3762 /* Reverse the src and dest notion, since the HW expects them to be from
3763 * Tx perspective where as the input from user is from Rx filter view.
3764 */
3765 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
3766 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
Jacob Keller8ce43dc2017-02-06 14:38:39 -08003767 input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src;
3768 input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003769
Jacob Keller0e588de2017-02-06 14:38:50 -08003770 if (userdef.flex_filter) {
3771 input->flex_filter = true;
3772 input->flex_word = cpu_to_be16(userdef.flex_word);
3773 input->flex_offset = userdef.flex_offset;
3774 }
3775
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003776 ret = i40e_add_del_fdir(vsi, input, true);
3777 if (ret)
Jacob Keller01016da2017-02-06 14:38:40 -08003778 goto free_input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003779
Jacob Keller01016da2017-02-06 14:38:40 -08003780 /* Add the input filter to the fdir_input_list, possibly replacing
3781 * a previous filter. Do not free the input structure after adding it
3782 * to the list as this would cause a use-after-free bug.
3783 */
3784 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
3785
3786 return 0;
3787
3788free_input:
3789 kfree(input);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003790 return ret;
3791}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08003792
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003793/**
3794 * i40e_set_rxnfc - command to set RX flow classification rules
3795 * @netdev: network interface device structure
3796 * @cmd: ethtool rxnfc command
3797 *
3798 * Returns Success if the command is supported.
3799 **/
3800static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3801{
3802 struct i40e_netdev_priv *np = netdev_priv(netdev);
3803 struct i40e_vsi *vsi = np->vsi;
3804 struct i40e_pf *pf = vsi->back;
3805 int ret = -EOPNOTSUPP;
3806
3807 switch (cmd->cmd) {
3808 case ETHTOOL_SRXFH:
3809 ret = i40e_set_rss_hash_opt(pf, cmd);
3810 break;
3811 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00003812 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003813 break;
3814 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00003815 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00003816 break;
3817 default:
3818 break;
3819 }
3820
3821 return ret;
3822}
3823
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003824/**
3825 * i40e_max_channels - get Max number of combined channels supported
3826 * @vsi: vsi pointer
3827 **/
3828static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
3829{
3830 /* TODO: This code assumes DCB and FD is disabled for now. */
3831 return vsi->alloc_queue_pairs;
3832}
3833
3834/**
3835 * i40e_get_channels - Get the current channels enabled and max supported etc.
3836 * @netdev: network interface device structure
3837 * @ch: ethtool channels structure
3838 *
3839 * We don't support separate tx and rx queues as channels. The other count
3840 * represents how many queues are being used for control. max_combined counts
3841 * how many queue pairs we can support. They may not be mapped 1 to 1 with
3842 * q_vectors since we support a lot more queue pairs than q_vectors.
3843 **/
3844static void i40e_get_channels(struct net_device *dev,
3845 struct ethtool_channels *ch)
3846{
3847 struct i40e_netdev_priv *np = netdev_priv(dev);
3848 struct i40e_vsi *vsi = np->vsi;
3849 struct i40e_pf *pf = vsi->back;
3850
3851 /* report maximum channels */
3852 ch->max_combined = i40e_max_channels(vsi);
3853
3854 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003855 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003856 ch->max_other = ch->other_count;
3857
3858 /* Note: This code assumes DCB is disabled for now. */
3859 ch->combined_count = vsi->num_queue_pairs;
3860}
3861
3862/**
3863 * i40e_set_channels - Set the new channels count.
3864 * @netdev: network interface device structure
3865 * @ch: ethtool channels structure
3866 *
3867 * The new channels count may not be the same as requested by the user
3868 * since it gets rounded down to a power of 2 value.
3869 **/
3870static int i40e_set_channels(struct net_device *dev,
3871 struct ethtool_channels *ch)
3872{
Jacob Keller59826d92016-07-27 12:02:35 -07003873 const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003874 struct i40e_netdev_priv *np = netdev_priv(dev);
3875 unsigned int count = ch->combined_count;
3876 struct i40e_vsi *vsi = np->vsi;
3877 struct i40e_pf *pf = vsi->back;
Jacob Keller59826d92016-07-27 12:02:35 -07003878 struct i40e_fdir_filter *rule;
3879 struct hlist_node *node2;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003880 int new_count;
Jacob Keller59826d92016-07-27 12:02:35 -07003881 int err = 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003882
3883 /* We do not support setting channels for any other VSI at present */
3884 if (vsi->type != I40E_VSI_MAIN)
3885 return -EINVAL;
3886
Amritha Nambiara9ce82f2017-09-07 04:00:22 -07003887 /* We do not support setting channels via ethtool when TCs are
3888 * configured through mqprio
3889 */
3890 if (pf->flags & I40E_FLAG_TC_MQPRIO)
3891 return -EINVAL;
3892
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003893 /* verify they are not requesting separate vectors */
3894 if (!count || ch->rx_count || ch->tx_count)
3895 return -EINVAL;
3896
3897 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08003898 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003899 return -EINVAL;
3900
3901 /* verify the number of channels does not exceed hardware limits */
3902 if (count > i40e_max_channels(vsi))
3903 return -EINVAL;
3904
Jacob Keller59826d92016-07-27 12:02:35 -07003905 /* verify that the number of channels does not invalidate any current
3906 * flow director rules
3907 */
3908 hlist_for_each_entry_safe(rule, node2,
3909 &pf->fdir_filter_list, fdir_node) {
3910 if (rule->dest_ctl != drop && count <= rule->q_index) {
3911 dev_warn(&pf->pdev->dev,
3912 "Existing user defined filter %d assigns flow to queue %d\n",
3913 rule->fd_id, rule->q_index);
3914 err = -EINVAL;
3915 }
3916 }
3917
3918 if (err) {
3919 dev_err(&pf->pdev->dev,
3920 "Existing filter rules must be deleted to reduce combined channel count to %d\n",
3921 count);
3922 return err;
3923 }
3924
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003925 /* update feature limits from largest to smallest supported values */
3926 /* TODO: Flow director limit, DCB etc */
3927
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003928 /* use rss_reconfig to rebuild with new queue count and update traffic
3929 * class queue mapping
3930 */
3931 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00003932 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00003933 return 0;
3934 else
3935 return -EINVAL;
3936}
3937
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003938/**
3939 * i40e_get_rxfh_key_size - get the RSS hash key size
3940 * @netdev: network interface device structure
3941 *
3942 * Returns the table size.
3943 **/
3944static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
3945{
3946 return I40E_HKEY_ARRAY_SIZE;
3947}
3948
3949/**
3950 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
3951 * @netdev: network interface device structure
3952 *
3953 * Returns the table size.
3954 **/
3955static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
3956{
3957 return I40E_HLUT_ARRAY_SIZE;
3958}
3959
Alan Brady21675bd2017-10-05 14:53:33 -07003960/**
3961 * i40e_get_rxfh - get the rx flow hash indirection table
3962 * @netdev: network interface device structure
3963 * @indir: indirection table
3964 * @key: hash key
3965 * @hfunc: hash function
3966 *
3967 * Reads the indirection table directly from the hardware. Returns 0 on
3968 * success.
3969 **/
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003970static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
3971 u8 *hfunc)
3972{
3973 struct i40e_netdev_priv *np = netdev_priv(netdev);
3974 struct i40e_vsi *vsi = np->vsi;
Helin Zhang043dd652015-10-21 19:56:23 -04003975 u8 *lut, *seed = NULL;
3976 int ret;
3977 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003978
3979 if (hfunc)
3980 *hfunc = ETH_RSS_HASH_TOP;
3981
3982 if (!indir)
3983 return 0;
3984
Helin Zhang043dd652015-10-21 19:56:23 -04003985 seed = key;
3986 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
3987 if (!lut)
3988 return -ENOMEM;
3989 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE);
3990 if (ret)
3991 goto out;
3992 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
3993 indir[i] = (u32)(lut[i]);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003994
Helin Zhang043dd652015-10-21 19:56:23 -04003995out:
3996 kfree(lut);
3997
3998 return ret;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00003999}
4000
4001/**
4002 * i40e_set_rxfh - set the rx flow hash indirection table
4003 * @netdev: network interface device structure
4004 * @indir: indirection table
4005 * @key: hash key
4006 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04004007 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004008 * returns 0 after programming the table.
4009 **/
4010static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
4011 const u8 *key, const u8 hfunc)
4012{
4013 struct i40e_netdev_priv *np = netdev_priv(netdev);
4014 struct i40e_vsi *vsi = np->vsi;
Alan Bradyf1582352016-08-24 11:33:46 -07004015 struct i40e_pf *pf = vsi->back;
Helin Zhang28c58692015-10-26 19:44:27 -04004016 u8 *seed = NULL;
Helin Zhang043dd652015-10-21 19:56:23 -04004017 u16 i;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004018
4019 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
4020 return -EOPNOTSUPP;
4021
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004022 if (key) {
Helin Zhang28c58692015-10-26 19:44:27 -04004023 if (!vsi->rss_hkey_user) {
4024 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE,
4025 GFP_KERNEL);
4026 if (!vsi->rss_hkey_user)
4027 return -ENOMEM;
4028 }
4029 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE);
4030 seed = vsi->rss_hkey_user;
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004031 }
Helin Zhang28c58692015-10-26 19:44:27 -04004032 if (!vsi->rss_lut_user) {
4033 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL);
4034 if (!vsi->rss_lut_user)
4035 return -ENOMEM;
4036 }
Helin Zhang043dd652015-10-21 19:56:23 -04004037
Helin Zhang28c58692015-10-26 19:44:27 -04004038 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
Alan Bradyf1582352016-08-24 11:33:46 -07004039 if (indir)
4040 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++)
4041 vsi->rss_lut_user[i] = (u8)(indir[i]);
4042 else
4043 i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE,
4044 vsi->rss_size);
Helin Zhang28c58692015-10-26 19:44:27 -04004045
4046 return i40e_config_rss(vsi, seed, vsi->rss_lut_user,
4047 I40E_HLUT_ARRAY_SIZE);
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004048}
4049
Greg Rose7e45ab42015-02-06 08:52:19 +00004050/**
4051 * i40e_get_priv_flags - report device private flags
4052 * @dev: network interface device structure
4053 *
4054 * The get string set count and the string set should be matched for each
Alexander Duyckaca955d2017-03-10 12:22:01 -08004055 * flag returned. Add new strings for each flag to the i40e_gstrings_priv_flags
Greg Rose7e45ab42015-02-06 08:52:19 +00004056 * array.
4057 *
4058 * Returns a u32 bitmap of flags.
4059 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00004060static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00004061{
4062 struct i40e_netdev_priv *np = netdev_priv(dev);
4063 struct i40e_vsi *vsi = np->vsi;
4064 struct i40e_pf *pf = vsi->back;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004065 u32 i, j, ret_flags = 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00004066
Alexander Duyckaca955d2017-03-10 12:22:01 -08004067 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4068 const struct i40e_priv_flags *priv_flags;
4069
4070 priv_flags = &i40e_gstrings_priv_flags[i];
4071
4072 if (priv_flags->flag & pf->flags)
4073 ret_flags |= BIT(i);
4074 }
4075
4076 if (pf->hw.pf_id != 0)
4077 return ret_flags;
4078
4079 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4080 const struct i40e_priv_flags *priv_flags;
4081
4082 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4083
4084 if (priv_flags->flag & pf->flags)
4085 ret_flags |= BIT(i + j);
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004086 }
Greg Rose7e45ab42015-02-06 08:52:19 +00004087
4088 return ret_flags;
4089}
4090
Shannon Nelson9ac77262015-08-27 11:42:40 -04004091/**
4092 * i40e_set_priv_flags - set private flags
4093 * @dev: network interface device structure
4094 * @flags: bit flags to be set
4095 **/
4096static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
4097{
4098 struct i40e_netdev_priv *np = netdev_priv(dev);
4099 struct i40e_vsi *vsi = np->vsi;
4100 struct i40e_pf *pf = vsi->back;
Jacob Kellerb74f5712017-09-01 13:54:07 -07004101 u32 orig_flags, new_flags, changed_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004102 u32 i, j;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004103
Jacob Keller841c9502017-06-23 04:24:50 -04004104 orig_flags = READ_ONCE(pf->flags);
4105 new_flags = orig_flags;
Jesse Brandeburg827de392015-11-06 15:26:07 -08004106
Alexander Duyckaca955d2017-03-10 12:22:01 -08004107 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
4108 const struct i40e_priv_flags *priv_flags;
Shannon Nelson9ac77262015-08-27 11:42:40 -04004109
Alexander Duyckaca955d2017-03-10 12:22:01 -08004110 priv_flags = &i40e_gstrings_priv_flags[i];
4111
Alexander Duyckaca955d2017-03-10 12:22:01 -08004112 if (flags & BIT(i))
Jacob Keller841c9502017-06-23 04:24:50 -04004113 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004114 else
Jacob Keller841c9502017-06-23 04:24:50 -04004115 new_flags &= ~(priv_flags->flag);
4116
4117 /* If this is a read-only flag, it can't be changed */
4118 if (priv_flags->read_only &&
4119 ((orig_flags ^ new_flags) & ~BIT(i)))
4120 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004121 }
4122
4123 if (pf->hw.pf_id != 0)
4124 goto flags_complete;
4125
4126 for (j = 0; j < I40E_GL_PRIV_FLAGS_STR_LEN; j++) {
4127 const struct i40e_priv_flags *priv_flags;
4128
4129 priv_flags = &i40e_gl_gstrings_priv_flags[j];
4130
Alexander Duyckaca955d2017-03-10 12:22:01 -08004131 if (flags & BIT(i + j))
Jacob Keller841c9502017-06-23 04:24:50 -04004132 new_flags |= priv_flags->flag;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004133 else
Jacob Keller841c9502017-06-23 04:24:50 -04004134 new_flags &= ~(priv_flags->flag);
4135
4136 /* If this is a read-only flag, it can't be changed */
4137 if (priv_flags->read_only &&
4138 ((orig_flags ^ new_flags) & ~BIT(i)))
4139 return -EOPNOTSUPP;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004140 }
4141
4142flags_complete:
Jacob Keller841c9502017-06-23 04:24:50 -04004143 /* Before we finalize any flag changes, we need to perform some
4144 * checks to ensure that the changes are supported and safe.
4145 */
4146
4147 /* ATR eviction is not supported on all devices */
4148 if ((new_flags & I40E_FLAG_HW_ATR_EVICT_ENABLED) &&
4149 !(pf->hw_features & I40E_HW_ATR_EVICT_CAPABLE))
4150 return -EOPNOTSUPP;
4151
4152 /* Compare and exchange the new flags into place. If we failed, that
Jacob Kellerb74f5712017-09-01 13:54:07 -07004153 * is if cmpxchg returns anything but the old value, this means that
Jacob Keller841c9502017-06-23 04:24:50 -04004154 * something else has modified the flags variable since we copied it
4155 * originally. We'll just punt with an error and log something in the
4156 * message buffer.
4157 */
Jacob Kellerb74f5712017-09-01 13:54:07 -07004158 if (cmpxchg(&pf->flags, orig_flags, new_flags) != orig_flags) {
Jacob Keller841c9502017-06-23 04:24:50 -04004159 dev_warn(&pf->pdev->dev,
4160 "Unable to update pf->flags as it was modified by another thread...\n");
4161 return -EAGAIN;
4162 }
4163
4164 changed_flags = orig_flags ^ new_flags;
Alexander Duyckaca955d2017-03-10 12:22:01 -08004165
4166 /* Process any additional changes needed as a result of flag changes.
4167 * The changed_flags value reflects the list of bits that were
4168 * changed in the code above.
Jesse Brandeburgef171782015-09-03 17:18:49 -04004169 */
Jacob Keller234dc4e2016-09-06 18:05:09 -07004170
Alexander Duyckaca955d2017-03-10 12:22:01 -08004171 /* Flush current ATR settings if ATR was disabled */
4172 if ((changed_flags & I40E_FLAG_FD_ATR_ENABLED) &&
4173 !(pf->flags & I40E_FLAG_FD_ATR_ENABLED)) {
Jacob Keller47994c12017-04-19 09:25:57 -04004174 pf->flags |= I40E_FLAG_FD_ATR_AUTO_DISABLED;
Jacob Keller0da36b92017-04-19 09:25:55 -04004175 set_bit(__I40E_FD_FLUSH_REQUESTED, pf->state);
Jesse Brandeburgef171782015-09-03 17:18:49 -04004176 }
4177
Alexander Duyckaca955d2017-03-10 12:22:01 -08004178 if (changed_flags & I40E_FLAG_TRUE_PROMISC_SUPPORT) {
4179 u16 sw_flags = 0, valid_flags = 0;
4180 int ret;
4181
Anjali Singhai Jainb5569892016-05-03 15:13:12 -07004182 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
4183 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4184 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
4185 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags,
4186 NULL);
4187 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
4188 dev_info(&pf->pdev->dev,
4189 "couldn't set switch config bits, err %s aq_err %s\n",
4190 i40e_stat_str(&pf->hw, ret),
4191 i40e_aq_str(&pf->hw,
4192 pf->hw.aq.asq_last_status));
4193 /* not a fatal problem, just keep going */
4194 }
4195 }
4196
Alexander Duyckaca955d2017-03-10 12:22:01 -08004197 /* Issue reset to cause things to take effect, as additional bits
4198 * are added we will need to create a mask of bits requiring reset
4199 */
Mitch Williams64615b52017-08-29 05:32:30 -04004200 if (changed_flags & (I40E_FLAG_VEB_STATS_ENABLED |
4201 I40E_FLAG_LEGACY_RX |
4202 I40E_FLAG_SOURCE_PRUNING_DISABLED))
Maciej Sosin373149f2017-04-05 07:50:55 -04004203 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED), true);
Jesse Brandeburg827de392015-11-06 15:26:07 -08004204
Shannon Nelson9ac77262015-08-27 11:42:40 -04004205 return 0;
4206}
4207
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004208/**
4209 * i40e_get_module_info - get (Q)SFP+ module type info
4210 * @netdev: network interface device structure
4211 * @modinfo: module EEPROM size and layout information structure
4212 **/
4213static int i40e_get_module_info(struct net_device *netdev,
4214 struct ethtool_modinfo *modinfo)
4215{
4216 struct i40e_netdev_priv *np = netdev_priv(netdev);
4217 struct i40e_vsi *vsi = np->vsi;
4218 struct i40e_pf *pf = vsi->back;
4219 struct i40e_hw *hw = &pf->hw;
4220 u32 sff8472_comp = 0;
4221 u32 sff8472_swap = 0;
4222 u32 sff8636_rev = 0;
4223 i40e_status status;
4224 u32 type = 0;
4225
4226 /* Check if firmware supports reading module EEPROM. */
4227 if (!(hw->flags & I40E_HW_FLAG_AQ_PHY_ACCESS_CAPABLE)) {
4228 netdev_err(vsi->netdev, "Module EEPROM memory read not supported. Please update the NVM image.\n");
4229 return -EINVAL;
4230 }
4231
4232 status = i40e_update_link_info(hw);
4233 if (status)
4234 return -EIO;
4235
4236 if (hw->phy.link_info.phy_type == I40E_PHY_TYPE_EMPTY) {
4237 netdev_err(vsi->netdev, "Cannot read module EEPROM memory. No module connected.\n");
4238 return -EINVAL;
4239 }
4240
4241 type = hw->phy.link_info.module_type[0];
4242
4243 switch (type) {
4244 case I40E_MODULE_TYPE_SFP:
4245 status = i40e_aq_get_phy_register(hw,
4246 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4247 I40E_I2C_EEPROM_DEV_ADDR,
4248 I40E_MODULE_SFF_8472_COMP,
4249 &sff8472_comp, NULL);
4250 if (status)
4251 return -EIO;
4252
4253 status = i40e_aq_get_phy_register(hw,
4254 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4255 I40E_I2C_EEPROM_DEV_ADDR,
4256 I40E_MODULE_SFF_8472_SWAP,
4257 &sff8472_swap, NULL);
4258 if (status)
4259 return -EIO;
4260
4261 /* Check if the module requires address swap to access
4262 * the other EEPROM memory page.
4263 */
4264 if (sff8472_swap & I40E_MODULE_SFF_ADDR_MODE) {
4265 netdev_warn(vsi->netdev, "Module address swap to access page 0xA2 is not supported.\n");
4266 modinfo->type = ETH_MODULE_SFF_8079;
4267 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4268 } else if (sff8472_comp == 0x00) {
4269 /* Module is not SFF-8472 compliant */
4270 modinfo->type = ETH_MODULE_SFF_8079;
4271 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4272 } else {
4273 modinfo->type = ETH_MODULE_SFF_8472;
4274 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4275 }
4276 break;
4277 case I40E_MODULE_TYPE_QSFP_PLUS:
4278 /* Read from memory page 0. */
4279 status = i40e_aq_get_phy_register(hw,
4280 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4281 0,
4282 I40E_MODULE_REVISION_ADDR,
4283 &sff8636_rev, NULL);
4284 if (status)
4285 return -EIO;
4286 /* Determine revision compliance byte */
4287 if (sff8636_rev > 0x02) {
4288 /* Module is SFF-8636 compliant */
4289 modinfo->type = ETH_MODULE_SFF_8636;
4290 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4291 } else {
4292 modinfo->type = ETH_MODULE_SFF_8436;
4293 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4294 }
4295 break;
4296 case I40E_MODULE_TYPE_QSFP28:
4297 modinfo->type = ETH_MODULE_SFF_8636;
4298 modinfo->eeprom_len = I40E_MODULE_QSFP_MAX_LEN;
4299 break;
4300 default:
4301 netdev_err(vsi->netdev, "Module type unrecognized\n");
4302 return -EINVAL;
4303 }
4304 return 0;
4305}
4306
4307/**
4308 * i40e_get_module_eeprom - fills buffer with (Q)SFP+ module memory contents
4309 * @netdev: network interface device structure
4310 * @ee: EEPROM dump request structure
4311 * @data: buffer to be filled with EEPROM contents
4312 **/
4313static int i40e_get_module_eeprom(struct net_device *netdev,
4314 struct ethtool_eeprom *ee,
4315 u8 *data)
4316{
4317 struct i40e_netdev_priv *np = netdev_priv(netdev);
4318 struct i40e_vsi *vsi = np->vsi;
4319 struct i40e_pf *pf = vsi->back;
4320 struct i40e_hw *hw = &pf->hw;
4321 bool is_sfp = false;
4322 i40e_status status;
4323 u32 value = 0;
4324 int i;
4325
4326 if (!ee || !ee->len || !data)
4327 return -EINVAL;
4328
4329 if (hw->phy.link_info.module_type[0] == I40E_MODULE_TYPE_SFP)
4330 is_sfp = true;
4331
4332 for (i = 0; i < ee->len; i++) {
4333 u32 offset = i + ee->offset;
4334 u32 addr = is_sfp ? I40E_I2C_EEPROM_DEV_ADDR : 0;
4335
4336 /* Check if we need to access the other memory page */
4337 if (is_sfp) {
4338 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4339 offset -= ETH_MODULE_SFF_8079_LEN;
4340 addr = I40E_I2C_EEPROM_DEV_ADDR2;
4341 }
4342 } else {
4343 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4344 /* Compute memory page number and offset. */
4345 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4346 addr++;
4347 }
4348 }
4349
4350 status = i40e_aq_get_phy_register(hw,
4351 I40E_AQ_PHY_REG_ACCESS_EXTERNAL_MODULE,
4352 addr, offset, &value, NULL);
4353 if (status)
4354 return -EIO;
4355 data[i] = value;
4356 }
4357 return 0;
4358}
4359
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004360static const struct ethtool_ops i40e_ethtool_ops = {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004361 .get_drvinfo = i40e_get_drvinfo,
4362 .get_regs_len = i40e_get_regs_len,
4363 .get_regs = i40e_get_regs,
4364 .nway_reset = i40e_nway_reset,
4365 .get_link = ethtool_op_get_link,
4366 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00004367 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00004368 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004369 .get_eeprom_len = i40e_get_eeprom_len,
4370 .get_eeprom = i40e_get_eeprom,
4371 .get_ringparam = i40e_get_ringparam,
4372 .set_ringparam = i40e_set_ringparam,
4373 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00004374 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004375 .get_msglevel = i40e_get_msglevel,
4376 .set_msglevel = i40e_set_msglevel,
4377 .get_rxnfc = i40e_get_rxnfc,
4378 .set_rxnfc = i40e_set_rxnfc,
4379 .self_test = i40e_diag_test,
4380 .get_strings = i40e_get_strings,
4381 .set_phys_id = i40e_set_phys_id,
4382 .get_sset_count = i40e_get_sset_count,
4383 .get_ethtool_stats = i40e_get_ethtool_stats,
4384 .get_coalesce = i40e_get_coalesce,
4385 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00004386 .get_rxfh_key_size = i40e_get_rxfh_key_size,
4387 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
4388 .get_rxfh = i40e_get_rxfh,
4389 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00004390 .get_channels = i40e_get_channels,
4391 .set_channels = i40e_set_channels,
Filip Sadowski9c0e5ca2017-08-22 06:57:44 -04004392 .get_module_info = i40e_get_module_info,
4393 .get_module_eeprom = i40e_get_module_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004394 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00004395 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04004396 .set_priv_flags = i40e_set_priv_flags,
Kan Liangbe280ba2016-02-19 09:24:05 -05004397 .get_per_queue_coalesce = i40e_get_per_queue_coalesce,
Kan Liangf3757a42016-02-19 09:24:06 -05004398 .set_per_queue_coalesce = i40e_set_per_queue_coalesce,
Philippe Reynesa7f90942017-02-04 22:05:06 +01004399 .get_link_ksettings = i40e_get_link_ksettings,
4400 .set_link_ksettings = i40e_set_link_ksettings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004401};
4402
4403void i40e_set_ethtool_ops(struct net_device *netdev)
4404{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00004405 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00004406}