blob: 5fe8ac07f0ec078179b5dad6b549745c0fa52be9 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Catherine Sullivane8278452015-02-06 08:52:08 +00004 * Copyright(c) 2013 - 2015 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),
Shannon Nelson41a9e552014-04-23 04:50:20 +000091};
92
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +000093/* These PF_STATs might look like duplicates of some NETDEV_STATs,
94 * but they are separate. This device supports Virtualization, and
95 * as such might have several netdevs supporting VMDq and FCoE going
96 * through a single port. The NETDEV_STATs are for individual netdevs
97 * seen at the top of the stack, and the PF_STATs are for the physical
98 * function at the bottom of the stack hosting those netdevs.
99 *
100 * The PF_STATs are appended to the netdev stats only when ethtool -S
101 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
102 */
103static struct i40e_stats i40e_gstrings_stats[] = {
104 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
105 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
Shannon Nelson532d2832014-04-23 04:50:09 +0000106 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast),
107 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast),
108 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast),
109 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast),
110 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast),
111 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000112 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
113 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000114 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
Shannon Nelson9f7c9442015-07-10 19:35:57 -0400115 I40E_PF_STAT("rx_crc_errors", stats.crc_errors),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000116 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
117 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
118 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
Jesse Brandeburga47a15f2014-02-06 05:51:09 +0000119 I40E_PF_STAT("tx_timeout", tx_timeout_count),
Jesse Brandeburg8a3c91c2014-05-20 08:01:43 +0000120 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000121 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
122 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
123 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
124 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
125 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
126 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
127 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
128 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
129 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
130 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
131 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
132 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
133 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
134 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
135 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
136 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
137 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
138 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
139 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
140 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
141 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
142 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
143 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
144 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
Jacob Kellerbeb0dff2014-01-11 05:43:19 +0000145 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +0000146 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000147 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match),
Anjali Singhai Jain60ccd452015-04-16 20:06:01 -0400148 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400149 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000150 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match),
Anjali Singhai Jaind0389e52015-04-22 19:34:05 -0400151 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status),
Anjali Singhai Jain433c47d2014-05-22 06:32:17 +0000152
Anjali Singhai Jainbee5af72014-03-06 08:59:50 +0000153 /* LPI stats */
154 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
155 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
156 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
157 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000158};
159
Vasu Dev38e00432014-08-01 13:27:03 -0700160#ifdef I40E_FCOE
161static const struct i40e_stats i40e_gstrings_fcoe_stats[] = {
162 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc),
163 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped),
164 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets),
165 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords),
166 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count),
167 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error),
168 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets),
169 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords),
170};
171
172#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000173#define I40E_QUEUE_STATS_LEN(n) \
Shannon Nelson31cd8402014-04-04 04:43:12 +0000174 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
175 * 2 /* Tx and Rx together */ \
176 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000177#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
178#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
Shannon Nelson41a9e552014-04-23 04:50:20 +0000179#define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
Vasu Dev38e00432014-08-01 13:27:03 -0700180#ifdef I40E_FCOE
181#define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats)
182#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
183 I40E_FCOE_STATS_LEN + \
184 I40E_MISC_STATS_LEN + \
185 I40E_QUEUE_STATS_LEN((n)))
186#else
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000187#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
Shannon Nelson41a9e552014-04-23 04:50:20 +0000188 I40E_MISC_STATS_LEN + \
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000189 I40E_QUEUE_STATS_LEN((n)))
Vasu Dev38e00432014-08-01 13:27:03 -0700190#endif /* I40E_FCOE */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000191#define I40E_PFC_STATS_LEN ( \
192 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
193 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
194 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
195 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
196 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
197 / sizeof(u64))
Neerav Parikhfe860af2015-07-10 19:36:02 -0400198#define I40E_VEB_TC_STATS_LEN ( \
199 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \
200 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \
201 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \
202 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \
203 / sizeof(u64))
Shannon Nelson8eab9cf2014-04-23 04:49:55 +0000204#define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats)
Neerav Parikhfe860af2015-07-10 19:36:02 -0400205#define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000206#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
207 I40E_PFC_STATS_LEN + \
208 I40E_VSI_STATS_LEN((n)))
209
210enum i40e_ethtool_test_id {
211 I40E_ETH_TEST_REG = 0,
212 I40E_ETH_TEST_EEPROM,
213 I40E_ETH_TEST_INTR,
214 I40E_ETH_TEST_LOOPBACK,
215 I40E_ETH_TEST_LINK,
216};
217
218static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
219 "Register test (offline)",
220 "Eeprom test (offline)",
221 "Interrupt test (offline)",
222 "Loopback test (offline)",
223 "Link test (on/offline)"
224};
225
226#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
227
Greg Rose7e45ab42015-02-06 08:52:19 +0000228static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = {
229 "NPAR",
Shannon Nelson9ac77262015-08-27 11:42:40 -0400230 "LinkPolling",
Jesse Brandeburgef171782015-09-03 17:18:49 -0400231 "flow-director-atr",
Greg Rose7e45ab42015-02-06 08:52:19 +0000232};
233
Shannon Nelson9ac77262015-08-27 11:42:40 -0400234#define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings)
Greg Rose7e45ab42015-02-06 08:52:19 +0000235
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000236/**
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000237 * i40e_partition_setting_complaint - generic complaint for MFP restriction
238 * @pf: the PF struct
239 **/
240static void i40e_partition_setting_complaint(struct i40e_pf *pf)
241{
242 dev_info(&pf->pdev->dev,
243 "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");
244}
245
246/**
Catherine Sullivane8278452015-02-06 08:52:08 +0000247 * i40e_get_settings_link_up - Get the Link settings for when link is up
248 * @hw: hw structure
249 * @ecmd: ethtool command to fill in
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000250 * @netdev: network interface device structure
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000251 *
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000252 **/
Catherine Sullivane8278452015-02-06 08:52:08 +0000253static void i40e_get_settings_link_up(struct i40e_hw *hw,
254 struct ethtool_cmd *ecmd,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400255 struct net_device *netdev,
256 struct i40e_pf *pf)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000257{
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000258 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000259 u32 link_speed = hw_link_info->link_speed;
260
Catherine Sullivane8278452015-02-06 08:52:08 +0000261 /* Initialize supported and advertised settings based on phy settings */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000262 switch (hw_link_info->phy_type) {
263 case I40E_PHY_TYPE_40GBASE_CR4:
264 case I40E_PHY_TYPE_40GBASE_CR4_CU:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000265 ecmd->supported = SUPPORTED_Autoneg |
266 SUPPORTED_40000baseCR4_Full;
267 ecmd->advertising = ADVERTISED_Autoneg |
268 ADVERTISED_40000baseCR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000269 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000270 case I40E_PHY_TYPE_XLAUI:
271 case I40E_PHY_TYPE_XLPPI:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000272 case I40E_PHY_TYPE_40GBASE_AOC:
Catherine Sullivane8278452015-02-06 08:52:08 +0000273 ecmd->supported = SUPPORTED_40000baseCR4_Full;
274 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000275 case I40E_PHY_TYPE_40GBASE_SR4:
276 ecmd->supported = SUPPORTED_40000baseSR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000277 break;
278 case I40E_PHY_TYPE_40GBASE_LR4:
279 ecmd->supported = SUPPORTED_40000baseLR4_Full;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000281 case I40E_PHY_TYPE_10GBASE_SR:
282 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000283 case I40E_PHY_TYPE_1000BASE_SX:
284 case I40E_PHY_TYPE_1000BASE_LX:
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400285 ecmd->supported = SUPPORTED_10000baseT_Full;
286 if (hw_link_info->module_type[2] &
287 I40E_MODULE_TYPE_1000BASE_SX ||
288 hw_link_info->module_type[2] &
289 I40E_MODULE_TYPE_1000BASE_LX) {
290 ecmd->supported |= SUPPORTED_1000baseT_Full;
291 if (hw_link_info->requested_speeds &
292 I40E_LINK_SPEED_1GB)
293 ecmd->advertising |= ADVERTISED_1000baseT_Full;
294 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000295 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
296 ecmd->advertising |= ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000297 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000298 case I40E_PHY_TYPE_10GBASE_T:
Catherine Sullivane8278452015-02-06 08:52:08 +0000299 case I40E_PHY_TYPE_1000BASE_T:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000300 ecmd->supported = SUPPORTED_Autoneg |
Mitch Williams5960d332014-09-13 07:40:47 +0000301 SUPPORTED_10000baseT_Full |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400302 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000303 ecmd->advertising = ADVERTISED_Autoneg;
304 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB)
305 ecmd->advertising |= ADVERTISED_10000baseT_Full;
306 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
307 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400308 break;
309 case I40E_PHY_TYPE_100BASE_TX:
310 ecmd->supported = SUPPORTED_Autoneg |
311 SUPPORTED_100baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000312 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB)
313 ecmd->advertising |= ADVERTISED_100baseT_Full;
314 break;
315 case I40E_PHY_TYPE_10GBASE_CR1_CU:
316 case I40E_PHY_TYPE_10GBASE_CR1:
317 ecmd->supported = SUPPORTED_Autoneg |
318 SUPPORTED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000319 ecmd->advertising = ADVERTISED_Autoneg |
Catherine Sullivane8278452015-02-06 08:52:08 +0000320 ADVERTISED_10000baseT_Full;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000321 break;
322 case I40E_PHY_TYPE_XAUI:
323 case I40E_PHY_TYPE_XFI:
324 case I40E_PHY_TYPE_SFI:
325 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
Catherine Sullivan180204c2015-02-26 16:14:58 +0000326 case I40E_PHY_TYPE_10GBASE_AOC:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000327 ecmd->supported = SUPPORTED_10000baseT_Full;
328 break;
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000329 case I40E_PHY_TYPE_SGMII:
330 ecmd->supported = SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400331 SUPPORTED_1000baseT_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000332 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB)
333 ecmd->advertising |= ADVERTISED_1000baseT_Full;
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400334 if (pf->hw.mac.type == I40E_MAC_X722) {
335 ecmd->supported |= SUPPORTED_100baseT_Full;
336 if (hw_link_info->requested_speeds &
337 I40E_LINK_SPEED_100MB)
338 ecmd->advertising |= ADVERTISED_100baseT_Full;
339 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000340 break;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400341 /* Backplane is set based on supported phy types in get_settings
342 * so don't set anything here but don't warn either
343 */
344 case I40E_PHY_TYPE_40GBASE_KR4:
345 case I40E_PHY_TYPE_20GBASE_KR2:
346 case I40E_PHY_TYPE_10GBASE_KR:
347 case I40E_PHY_TYPE_10GBASE_KX4:
348 case I40E_PHY_TYPE_1000BASE_KX:
349 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000350 default:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000351 /* if we got here and link is up something bad is afoot */
Catherine Sullivan124ed152014-07-12 07:28:12 +0000352 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n",
353 hw_link_info->phy_type);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000354 }
355
Catherine Sullivane8278452015-02-06 08:52:08 +0000356 /* Set speed and duplex */
357 switch (link_speed) {
358 case I40E_LINK_SPEED_40GB:
Greg Roseedf5cff2015-04-07 19:45:41 -0400359 ethtool_cmd_speed_set(ecmd, SPEED_40000);
Catherine Sullivane8278452015-02-06 08:52:08 +0000360 break;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700361 case I40E_LINK_SPEED_20GB:
362 ethtool_cmd_speed_set(ecmd, SPEED_20000);
363 break;
Catherine Sullivane8278452015-02-06 08:52:08 +0000364 case I40E_LINK_SPEED_10GB:
365 ethtool_cmd_speed_set(ecmd, SPEED_10000);
366 break;
367 case I40E_LINK_SPEED_1GB:
368 ethtool_cmd_speed_set(ecmd, SPEED_1000);
369 break;
370 case I40E_LINK_SPEED_100MB:
371 ethtool_cmd_speed_set(ecmd, SPEED_100);
372 break;
373 default:
374 break;
375 }
376 ecmd->duplex = DUPLEX_FULL;
377}
378
379/**
380 * i40e_get_settings_link_down - Get the Link settings for when link is down
381 * @hw: hw structure
382 * @ecmd: ethtool command to fill in
383 *
384 * Reports link settings that can be determined when link is down
385 **/
386static void i40e_get_settings_link_down(struct i40e_hw *hw,
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400387 struct ethtool_cmd *ecmd,
388 struct i40e_pf *pf)
Catherine Sullivane8278452015-02-06 08:52:08 +0000389{
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400390 enum i40e_aq_capabilities_phy_type phy_types = hw->phy.phy_types;
Catherine Sullivane8278452015-02-06 08:52:08 +0000391
392 /* link is down and the driver needs to fall back on
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400393 * supported phy types to figure out what info to display
Catherine Sullivane8278452015-02-06 08:52:08 +0000394 */
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400395 ecmd->supported = 0x0;
396 ecmd->advertising = 0x0;
397 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) {
398 ecmd->supported |= SUPPORTED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400399 SUPPORTED_1000baseT_Full;
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400400 ecmd->advertising |= ADVERTISED_Autoneg |
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400401 ADVERTISED_1000baseT_Full;
402 if (pf->hw.mac.type == I40E_MAC_X722) {
403 ecmd->supported |= SUPPORTED_100baseT_Full;
404 ecmd->advertising |= ADVERTISED_100baseT_Full;
405 }
Catherine Sullivane8278452015-02-06 08:52:08 +0000406 }
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400407 if (phy_types & I40E_CAP_PHY_TYPE_XAUI ||
408 phy_types & I40E_CAP_PHY_TYPE_XFI ||
409 phy_types & I40E_CAP_PHY_TYPE_SFI ||
410 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU ||
411 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC)
412 ecmd->supported |= SUPPORTED_10000baseT_Full;
413 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU ||
414 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 ||
415 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T ||
416 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR ||
417 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) {
418 ecmd->supported |= SUPPORTED_Autoneg |
419 SUPPORTED_10000baseT_Full;
420 ecmd->advertising |= ADVERTISED_Autoneg |
421 ADVERTISED_10000baseT_Full;
422 }
423 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI ||
424 phy_types & I40E_CAP_PHY_TYPE_XLPPI ||
425 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC)
426 ecmd->supported |= SUPPORTED_40000baseCR4_Full;
427 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU ||
428 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) {
429 ecmd->supported |= SUPPORTED_Autoneg |
430 SUPPORTED_40000baseCR4_Full;
431 ecmd->advertising |= ADVERTISED_Autoneg |
432 ADVERTISED_40000baseCR4_Full;
433 }
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400434 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) &&
435 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) {
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400436 ecmd->supported |= SUPPORTED_Autoneg |
437 SUPPORTED_100baseT_Full;
438 ecmd->advertising |= ADVERTISED_Autoneg |
439 ADVERTISED_100baseT_Full;
440 }
441 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T ||
442 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX ||
443 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX ||
444 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) {
445 ecmd->supported |= SUPPORTED_Autoneg |
446 SUPPORTED_1000baseT_Full;
447 ecmd->advertising |= ADVERTISED_Autoneg |
448 ADVERTISED_1000baseT_Full;
449 }
450 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4)
451 ecmd->supported |= SUPPORTED_40000baseSR4_Full;
452 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4)
453 ecmd->supported |= SUPPORTED_40000baseLR4_Full;
Catherine Sullivane8278452015-02-06 08:52:08 +0000454
455 /* With no link speed and duplex are unknown */
456 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
457 ecmd->duplex = DUPLEX_UNKNOWN;
458}
459
460/**
461 * i40e_get_settings - Get Link Speed and Duplex settings
462 * @netdev: network interface device structure
463 * @ecmd: ethtool command
464 *
465 * Reports speed/duplex settings based on media_type
466 **/
467static int i40e_get_settings(struct net_device *netdev,
468 struct ethtool_cmd *ecmd)
469{
470 struct i40e_netdev_priv *np = netdev_priv(netdev);
471 struct i40e_pf *pf = np->vsi->back;
472 struct i40e_hw *hw = &pf->hw;
473 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
474 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
475
476 if (link_up)
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400477 i40e_get_settings_link_up(hw, ecmd, netdev, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000478 else
Catherine Sullivan3b6c2172015-09-03 17:18:52 -0400479 i40e_get_settings_link_down(hw, ecmd, pf);
Catherine Sullivane8278452015-02-06 08:52:08 +0000480
481 /* Now set the settings that don't rely on link being up/down */
482
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400483 /* For backplane, supported and advertised are only reliant on the
484 * phy types the NVM specifies are supported.
485 */
486 if (hw->device_id == I40E_DEV_ID_KX_B ||
487 hw->device_id == I40E_DEV_ID_KX_C ||
488 hw->device_id == I40E_DEV_ID_20G_KR2 ||
489 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
490 ecmd->supported = SUPPORTED_Autoneg;
491 ecmd->advertising = ADVERTISED_Autoneg;
492 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) {
493 ecmd->supported |= SUPPORTED_40000baseKR4_Full;
494 ecmd->advertising |= ADVERTISED_40000baseKR4_Full;
495 }
496 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) {
497 ecmd->supported |= SUPPORTED_20000baseKR2_Full;
498 ecmd->advertising |= ADVERTISED_20000baseKR2_Full;
499 }
500 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) {
501 ecmd->supported |= SUPPORTED_10000baseKR_Full;
502 ecmd->advertising |= ADVERTISED_10000baseKR_Full;
503 }
504 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) {
505 ecmd->supported |= SUPPORTED_10000baseKX4_Full;
506 ecmd->advertising |= ADVERTISED_10000baseKX4_Full;
507 }
508 if (hw->phy.phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) {
509 ecmd->supported |= SUPPORTED_1000baseKX_Full;
510 ecmd->advertising |= ADVERTISED_1000baseKX_Full;
511 }
512 }
513
Catherine Sullivane8278452015-02-06 08:52:08 +0000514 /* Set autoneg settings */
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000515 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
516 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000517
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000518 switch (hw->phy.media_type) {
519 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000520 ecmd->supported |= SUPPORTED_Autoneg |
521 SUPPORTED_Backplane;
522 ecmd->advertising |= ADVERTISED_Autoneg |
523 ADVERTISED_Backplane;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000524 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000525 break;
526 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000527 ecmd->supported |= SUPPORTED_TP;
528 ecmd->advertising |= ADVERTISED_TP;
529 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000530 break;
531 case I40E_MEDIA_TYPE_DA:
532 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000533 ecmd->supported |= SUPPORTED_FIBRE;
534 ecmd->advertising |= ADVERTISED_FIBRE;
535 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000536 break;
537 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000538 ecmd->supported |= SUPPORTED_FIBRE;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000539 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000540 break;
541 case I40E_MEDIA_TYPE_UNKNOWN:
542 default:
543 ecmd->port = PORT_OTHER;
544 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000545 }
546
Catherine Sullivane8278452015-02-06 08:52:08 +0000547 /* Set transceiver */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000548 ecmd->transceiver = XCVR_EXTERNAL;
549
Catherine Sullivane8278452015-02-06 08:52:08 +0000550 /* Set flow control settings */
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000551 ecmd->supported |= SUPPORTED_Pause;
552
Catherine Sullivane8278452015-02-06 08:52:08 +0000553 switch (hw->fc.requested_mode) {
Jesse Brandeburg4e91bcd2014-06-04 08:45:23 +0000554 case I40E_FC_FULL:
555 ecmd->advertising |= ADVERTISED_Pause;
556 break;
557 case I40E_FC_TX_PAUSE:
558 ecmd->advertising |= ADVERTISED_Asym_Pause;
559 break;
560 case I40E_FC_RX_PAUSE:
561 ecmd->advertising |= (ADVERTISED_Pause |
562 ADVERTISED_Asym_Pause);
563 break;
564 default:
565 ecmd->advertising &= ~(ADVERTISED_Pause |
566 ADVERTISED_Asym_Pause);
567 break;
568 }
569
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000570 return 0;
571}
572
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000573/**
574 * i40e_set_settings - Set Speed and Duplex
575 * @netdev: network interface device structure
576 * @ecmd: ethtool command
577 *
578 * Set speed/duplex per media_types advertised/forced
579 **/
580static int i40e_set_settings(struct net_device *netdev,
581 struct ethtool_cmd *ecmd)
582{
583 struct i40e_netdev_priv *np = netdev_priv(netdev);
584 struct i40e_aq_get_phy_abilities_resp abilities;
585 struct i40e_aq_set_phy_config config;
586 struct i40e_pf *pf = np->vsi->back;
587 struct i40e_vsi *vsi = np->vsi;
588 struct i40e_hw *hw = &pf->hw;
589 struct ethtool_cmd safe_ecmd;
590 i40e_status status = 0;
591 bool change = false;
592 int err = 0;
593 u8 autoneg;
594 u32 advertise;
595
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000596 /* Changing port settings is not supported if this isn't the
597 * port's controlling PF
598 */
599 if (hw->partition_id != 1) {
600 i40e_partition_setting_complaint(pf);
601 return -EOPNOTSUPP;
602 }
603
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000604 if (vsi != pf->vsi[pf->lan_vsi])
605 return -EOPNOTSUPP;
606
607 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
608 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
Catherine Sullivanc57e9f12014-07-12 07:28:13 +0000609 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE &&
610 hw->phy.link_info.link_info & I40E_AQ_LINK_UP)
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000611 return -EOPNOTSUPP;
612
Catherine Sullivanfc72dbc2015-09-01 11:36:30 -0400613 if (hw->device_id == I40E_DEV_ID_KX_B ||
614 hw->device_id == I40E_DEV_ID_KX_C ||
615 hw->device_id == I40E_DEV_ID_20G_KR2 ||
616 hw->device_id == I40E_DEV_ID_20G_KR2_A) {
617 netdev_info(netdev, "Changing settings is not supported on backplane.\n");
618 return -EOPNOTSUPP;
619 }
620
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000621 /* get our own copy of the bits to check against */
622 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd));
623 i40e_get_settings(netdev, &safe_ecmd);
624
625 /* save autoneg and speed out of ecmd */
626 autoneg = ecmd->autoneg;
627 advertise = ecmd->advertising;
628
629 /* set autoneg and speed back to what they currently are */
630 ecmd->autoneg = safe_ecmd.autoneg;
631 ecmd->advertising = safe_ecmd.advertising;
632
633 ecmd->cmd = safe_ecmd.cmd;
634 /* If ecmd and safe_ecmd are not the same now, then they are
635 * trying to set something that we do not support
636 */
637 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd)))
638 return -EOPNOTSUPP;
639
640 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state))
641 usleep_range(1000, 2000);
642
643 /* Get the current phy config */
644 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
645 NULL);
646 if (status)
647 return -EAGAIN;
648
Catherine Sullivan124ed152014-07-12 07:28:12 +0000649 /* Copy abilities to config in case autoneg is not
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000650 * set below
651 */
652 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000653 config.abilities = abilities.abilities;
654
655 /* Check autoneg */
656 if (autoneg == AUTONEG_ENABLE) {
657 /* If autoneg is not supported, return error */
658 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) {
659 netdev_info(netdev, "Autoneg not supported on this phy\n");
660 return -EINVAL;
661 }
662 /* If autoneg was not already enabled */
663 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) {
664 config.abilities = abilities.abilities |
665 I40E_AQ_PHY_ENABLE_AN;
666 change = true;
667 }
668 } else {
669 /* If autoneg is supported 10GBASE_T is the only phy that
670 * can disable it, so otherwise return error
671 */
672 if (safe_ecmd.supported & SUPPORTED_Autoneg &&
673 hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) {
674 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
675 return -EINVAL;
676 }
677 /* If autoneg is currently enabled */
678 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) {
Mitch Williams5960d332014-09-13 07:40:47 +0000679 config.abilities = abilities.abilities &
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000680 ~I40E_AQ_PHY_ENABLE_AN;
681 change = true;
682 }
683 }
684
685 if (advertise & ~safe_ecmd.supported)
686 return -EINVAL;
687
688 if (advertise & ADVERTISED_100baseT_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000689 config.link_speed |= I40E_LINK_SPEED_100MB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000690 if (advertise & ADVERTISED_1000baseT_Full ||
691 advertise & ADVERTISED_1000baseKX_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000692 config.link_speed |= I40E_LINK_SPEED_1GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000693 if (advertise & ADVERTISED_10000baseT_Full ||
694 advertise & ADVERTISED_10000baseKX4_Full ||
695 advertise & ADVERTISED_10000baseKR_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000696 config.link_speed |= I40E_LINK_SPEED_10GB;
Jesse Brandeburgae24b402015-03-27 00:12:09 -0700697 if (advertise & ADVERTISED_20000baseKR2_Full)
698 config.link_speed |= I40E_LINK_SPEED_20GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000699 if (advertise & ADVERTISED_40000baseKR4_Full ||
700 advertise & ADVERTISED_40000baseCR4_Full ||
701 advertise & ADVERTISED_40000baseSR4_Full ||
702 advertise & ADVERTISED_40000baseLR4_Full)
Catherine Sullivan124ed152014-07-12 07:28:12 +0000703 config.link_speed |= I40E_LINK_SPEED_40GB;
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000704
Catherine Sullivan0002e112015-08-26 15:14:16 -0400705 /* If speed didn't get set, set it to what it currently is.
706 * This is needed because if advertise is 0 (as it is when autoneg
707 * is disabled) then speed won't get set.
708 */
709 if (!config.link_speed)
710 config.link_speed = abilities.link_speed;
711
Catherine Sullivan124ed152014-07-12 07:28:12 +0000712 if (change || (abilities.link_speed != config.link_speed)) {
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000713 /* copy over the rest of the abilities */
714 config.phy_type = abilities.phy_type;
715 config.eee_capability = abilities.eee_capability;
716 config.eeer = abilities.eeer_val;
717 config.low_power_ctrl = abilities.d3_lpan;
718
Catherine Sullivane8278452015-02-06 08:52:08 +0000719 /* save the requested speeds */
720 hw->phy.link_info.requested_speeds = config.link_speed;
Catherine Sullivan94128512014-07-12 07:28:16 +0000721 /* set link and auto negotiation so changes take effect */
722 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
723 /* If link is up put link down */
724 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) {
725 /* Tell the OS link is going down, the link will go
726 * back up when fw says it is ready asynchronously
727 */
Matt Jaredc156f852015-08-27 11:42:39 -0400728 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000729 netif_carrier_off(netdev);
730 netif_tx_stop_all_queues(netdev);
731 }
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000732
733 /* make the aq call */
734 status = i40e_aq_set_phy_config(hw, &config, NULL);
735 if (status) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400736 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n",
737 i40e_stat_str(hw, status),
738 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000739 return -EAGAIN;
740 }
741
Catherine Sullivan0a862b42015-08-31 19:54:53 -0400742 status = i40e_update_link_info(hw);
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000743 if (status)
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400744 netdev_info(netdev, "Updating link info failed with err %s aq_err %s\n",
745 i40e_stat_str(hw, status),
746 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivanbf9c7142014-06-04 08:45:28 +0000747
748 } else {
749 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
750 }
751
752 return err;
753}
754
Jesse Brandeburga6599722014-06-04 08:45:25 +0000755static int i40e_nway_reset(struct net_device *netdev)
756{
757 /* restart autonegotiation */
758 struct i40e_netdev_priv *np = netdev_priv(netdev);
759 struct i40e_pf *pf = np->vsi->back;
760 struct i40e_hw *hw = &pf->hw;
761 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
762 i40e_status ret = 0;
763
764 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL);
765 if (ret) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400766 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
767 i40e_stat_str(hw, ret),
768 i40e_aq_str(hw, hw->aq.asq_last_status));
Jesse Brandeburga6599722014-06-04 08:45:25 +0000769 return -EIO;
770 }
771
772 return 0;
773}
774
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000775/**
776 * i40e_get_pauseparam - Get Flow Control status
777 * Return tx/rx-pause status
778 **/
779static void i40e_get_pauseparam(struct net_device *netdev,
780 struct ethtool_pauseparam *pause)
781{
782 struct i40e_netdev_priv *np = netdev_priv(netdev);
783 struct i40e_pf *pf = np->vsi->back;
784 struct i40e_hw *hw = &pf->hw;
785 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000786 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000787
788 pause->autoneg =
789 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
790 AUTONEG_ENABLE : AUTONEG_DISABLE);
791
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000792 /* PFC enabled so report LFC as off */
793 if (dcbx_cfg->pfc.pfcenable) {
794 pause->rx_pause = 0;
795 pause->tx_pause = 0;
796 return;
797 }
798
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000799 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000800 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000801 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000802 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000803 } else if (hw->fc.current_mode == I40E_FC_FULL) {
804 pause->rx_pause = 1;
805 pause->tx_pause = 1;
806 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000807}
808
Catherine Sullivan2becc352014-06-04 08:45:27 +0000809/**
810 * i40e_set_pauseparam - Set Flow Control parameter
811 * @netdev: network interface device structure
812 * @pause: return tx/rx flow control status
813 **/
814static int i40e_set_pauseparam(struct net_device *netdev,
815 struct ethtool_pauseparam *pause)
816{
817 struct i40e_netdev_priv *np = netdev_priv(netdev);
818 struct i40e_pf *pf = np->vsi->back;
819 struct i40e_vsi *vsi = np->vsi;
820 struct i40e_hw *hw = &pf->hw;
821 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000822 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000823 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
824 i40e_status status;
825 u8 aq_failures;
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000826 int err = 0;
Catherine Sullivan2becc352014-06-04 08:45:27 +0000827
Shannon Nelsonf0d8c732014-12-11 07:06:32 +0000828 /* Changing the port's flow control is not supported if this isn't the
829 * port's controlling PF
830 */
831 if (hw->partition_id != 1) {
832 i40e_partition_setting_complaint(pf);
833 return -EOPNOTSUPP;
834 }
835
Catherine Sullivan2becc352014-06-04 08:45:27 +0000836 if (vsi != pf->vsi[pf->lan_vsi])
837 return -EOPNOTSUPP;
838
839 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
840 AUTONEG_ENABLE : AUTONEG_DISABLE)) {
841 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
842 return -EOPNOTSUPP;
843 }
844
845 /* If we have link and don't have autoneg */
846 if (!test_bit(__I40E_DOWN, &pf->state) &&
847 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) {
848 /* Send message that it might not necessarily work*/
849 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
850 }
851
Neerav Parikh4b7698c2014-11-12 00:18:57 +0000852 if (dcbx_cfg->pfc.pfcenable) {
853 netdev_info(netdev,
854 "Priority flow control enabled. Cannot set link flow control.\n");
Catherine Sullivan2becc352014-06-04 08:45:27 +0000855 return -EOPNOTSUPP;
856 }
857
858 if (pause->rx_pause && pause->tx_pause)
859 hw->fc.requested_mode = I40E_FC_FULL;
860 else if (pause->rx_pause && !pause->tx_pause)
861 hw->fc.requested_mode = I40E_FC_RX_PAUSE;
862 else if (!pause->rx_pause && pause->tx_pause)
863 hw->fc.requested_mode = I40E_FC_TX_PAUSE;
864 else if (!pause->rx_pause && !pause->tx_pause)
865 hw->fc.requested_mode = I40E_FC_NONE;
866 else
867 return -EINVAL;
868
Catherine Sullivan94128512014-07-12 07:28:16 +0000869 /* Tell the OS link is going down, the link will go back up when fw
870 * says it is ready asynchronously
871 */
Matt Jaredc156f852015-08-27 11:42:39 -0400872 i40e_print_link_message(vsi, false);
Catherine Sullivan94128512014-07-12 07:28:16 +0000873 netif_carrier_off(netdev);
874 netif_tx_stop_all_queues(netdev);
875
Catherine Sullivan2becc352014-06-04 08:45:27 +0000876 /* Set the fc mode and only restart an if link is up*/
877 status = i40e_set_fc(hw, &aq_failures, link_up);
878
879 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400880 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
881 i40e_stat_str(hw, status),
882 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000883 err = -EAGAIN;
884 }
885 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400886 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
887 i40e_stat_str(hw, status),
888 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000889 err = -EAGAIN;
890 }
891 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) {
Shannon Nelsonf1c7e722015-06-04 16:24:01 -0400892 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
893 i40e_stat_str(hw, status),
894 i40e_aq_str(hw, hw->aq.asq_last_status));
Catherine Sullivan2becc352014-06-04 08:45:27 +0000895 err = -EAGAIN;
896 }
897
Catherine Sullivan7d62dac2014-07-09 07:46:18 +0000898 if (!test_bit(__I40E_DOWN, &pf->state)) {
899 /* Give it a little more time to try to come back */
900 msleep(75);
901 if (!test_bit(__I40E_DOWN, &pf->state))
902 return i40e_nway_reset(netdev);
903 }
Catherine Sullivan2becc352014-06-04 08:45:27 +0000904
905 return err;
906}
907
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000908static u32 i40e_get_msglevel(struct net_device *netdev)
909{
910 struct i40e_netdev_priv *np = netdev_priv(netdev);
911 struct i40e_pf *pf = np->vsi->back;
912
913 return pf->msg_enable;
914}
915
916static void i40e_set_msglevel(struct net_device *netdev, u32 data)
917{
918 struct i40e_netdev_priv *np = netdev_priv(netdev);
919 struct i40e_pf *pf = np->vsi->back;
920
921 if (I40E_DEBUG_USER & data)
922 pf->hw.debug_mask = data;
923 pf->msg_enable = data;
924}
925
926static int i40e_get_regs_len(struct net_device *netdev)
927{
928 int reg_count = 0;
929 int i;
930
931 for (i = 0; i40e_reg_list[i].offset != 0; i++)
932 reg_count += i40e_reg_list[i].elements;
933
934 return reg_count * sizeof(u32);
935}
936
937static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
938 void *p)
939{
940 struct i40e_netdev_priv *np = netdev_priv(netdev);
941 struct i40e_pf *pf = np->vsi->back;
942 struct i40e_hw *hw = &pf->hw;
943 u32 *reg_buf = p;
944 int i, j, ri;
945 u32 reg;
946
947 /* Tell ethtool which driver-version-specific regs output we have.
948 *
949 * At some point, if we have ethtool doing special formatting of
950 * this data, it will rely on this version number to know how to
951 * interpret things. Hence, this needs to be updated if/when the
952 * diags register table is changed.
953 */
954 regs->version = 1;
955
956 /* loop through the diags reg table for what to print */
957 ri = 0;
958 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
959 for (j = 0; j < i40e_reg_list[i].elements; j++) {
960 reg = i40e_reg_list[i].offset
961 + (j * i40e_reg_list[i].stride);
962 reg_buf[ri++] = rd32(hw, reg);
963 }
964 }
965
966}
967
968static int i40e_get_eeprom(struct net_device *netdev,
969 struct ethtool_eeprom *eeprom, u8 *bytes)
970{
971 struct i40e_netdev_priv *np = netdev_priv(netdev);
972 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000973 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +0000974 int ret_val = 0, len, offset;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000975 u8 *eeprom_buff;
976 u16 i, sectors;
977 bool last;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000978 u32 magic;
979
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +0000980#define I40E_NVM_SECTOR_SIZE 4096
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000981 if (eeprom->len == 0)
982 return -EINVAL;
983
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000984 /* check for NVMUpdate access method */
985 magic = hw->vendor_id | (hw->device_id << 16);
986 if (eeprom->magic && eeprom->magic != magic) {
Shannon Nelsonc150a502014-11-13 08:23:13 +0000987 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000988 int errno;
989
990 /* make sure it is the right magic for NVMUpdate */
991 if ((eeprom->magic >> 16) != hw->device_id)
992 return -EINVAL;
993
Shannon Nelsonc150a502014-11-13 08:23:13 +0000994 cmd = (struct i40e_nvm_access *)eeprom;
995 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -0400996 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +0000997 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +0000998 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
999 ret_val, hw->aq.asq_last_status, errno,
1000 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1001 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001002
1003 return errno;
1004 }
1005
1006 /* normal ethtool get_eeprom support */
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001007 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
1008
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001009 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001010 if (!eeprom_buff)
1011 return -ENOMEM;
1012
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001013 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
1014 if (ret_val) {
1015 dev_info(&pf->pdev->dev,
1016 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
1017 ret_val, hw->aq.asq_last_status);
1018 goto free_buff;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001019 }
1020
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001021 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
1022 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
1023 len = I40E_NVM_SECTOR_SIZE;
1024 last = false;
1025 for (i = 0; i < sectors; i++) {
1026 if (i == (sectors - 1)) {
1027 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
1028 last = true;
1029 }
Shannon Nelsonc150a502014-11-13 08:23:13 +00001030 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
1031 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001032 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001033 last, NULL);
Shannon Nelsonc150a502014-11-13 08:23:13 +00001034 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) {
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001035 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001036 "read NVM failed, invalid offset 0x%x\n",
1037 offset);
1038 break;
1039 } else if (ret_val &&
1040 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) {
1041 dev_info(&pf->pdev->dev,
1042 "read NVM failed, access, offset 0x%x\n",
1043 offset);
1044 break;
1045 } else if (ret_val) {
1046 dev_info(&pf->pdev->dev,
1047 "read NVM failed offset %d err=%d status=0x%x\n",
1048 offset, ret_val, hw->aq.asq_last_status);
1049 break;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001050 }
1051 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001052
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001053 i40e_release_nvm(hw);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001054 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001055free_buff:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001056 kfree(eeprom_buff);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001057 return ret_val;
1058}
1059
1060static int i40e_get_eeprom_len(struct net_device *netdev)
1061{
1062 struct i40e_netdev_priv *np = netdev_priv(netdev);
1063 struct i40e_hw *hw = &np->vsi->back->hw;
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001064 u32 val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001065
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001066 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
1067 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
1068 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
1069 /* register returns value in power of 2, 64Kbyte chunks. */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001070 val = (64 * 1024) * BIT(val);
Anjali Singhai Jaine5e0a5d2013-11-28 06:39:28 +00001071 return val;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001072}
1073
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001074static int i40e_set_eeprom(struct net_device *netdev,
1075 struct ethtool_eeprom *eeprom, u8 *bytes)
1076{
1077 struct i40e_netdev_priv *np = netdev_priv(netdev);
1078 struct i40e_hw *hw = &np->vsi->back->hw;
1079 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonc150a502014-11-13 08:23:13 +00001080 struct i40e_nvm_access *cmd;
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001081 int ret_val = 0;
1082 int errno;
1083 u32 magic;
1084
1085 /* normal ethtool set_eeprom is not supported */
1086 magic = hw->vendor_id | (hw->device_id << 16);
1087 if (eeprom->magic == magic)
1088 return -EOPNOTSUPP;
1089
1090 /* check for NVMUpdate access method */
1091 if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id)
1092 return -EINVAL;
1093
1094 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
1095 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
1096 return -EBUSY;
1097
Shannon Nelsonc150a502014-11-13 08:23:13 +00001098 cmd = (struct i40e_nvm_access *)eeprom;
1099 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno);
Shannon Nelson3c5c4202015-09-28 14:12:32 -04001100 if (ret_val && (hw->debug_mask & I40E_DEBUG_NVM))
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001101 dev_info(&pf->pdev->dev,
Shannon Nelsonc150a502014-11-13 08:23:13 +00001102 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n",
1103 ret_val, hw->aq.asq_last_status, errno,
1104 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK),
1105 cmd->offset, cmd->data_size);
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00001106
1107 return errno;
1108}
1109
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001110static void i40e_get_drvinfo(struct net_device *netdev,
1111 struct ethtool_drvinfo *drvinfo)
1112{
1113 struct i40e_netdev_priv *np = netdev_priv(netdev);
1114 struct i40e_vsi *vsi = np->vsi;
1115 struct i40e_pf *pf = vsi->back;
1116
1117 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
1118 strlcpy(drvinfo->version, i40e_driver_version_str,
1119 sizeof(drvinfo->version));
Shannon Nelson6dec1012015-09-28 14:12:30 -04001120 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw),
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001121 sizeof(drvinfo->fw_version));
1122 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
1123 sizeof(drvinfo->bus_info));
1124}
1125
1126static void i40e_get_ringparam(struct net_device *netdev,
1127 struct ethtool_ringparam *ring)
1128{
1129 struct i40e_netdev_priv *np = netdev_priv(netdev);
1130 struct i40e_pf *pf = np->vsi->back;
1131 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
1132
1133 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1134 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
1135 ring->rx_mini_max_pending = 0;
1136 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +00001137 ring->rx_pending = vsi->rx_rings[0]->count;
1138 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001139 ring->rx_mini_pending = 0;
1140 ring->rx_jumbo_pending = 0;
1141}
1142
1143static int i40e_set_ringparam(struct net_device *netdev,
1144 struct ethtool_ringparam *ring)
1145{
1146 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
1147 struct i40e_netdev_priv *np = netdev_priv(netdev);
1148 struct i40e_vsi *vsi = np->vsi;
1149 struct i40e_pf *pf = vsi->back;
1150 u32 new_rx_count, new_tx_count;
1151 int i, err = 0;
1152
1153 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
1154 return -EINVAL;
1155
Shannon Nelson1fa18372013-11-20 10:03:08 +00001156 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1157 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
1158 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
1159 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
1160 netdev_info(netdev,
1161 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
1162 ring->tx_pending, ring->rx_pending,
1163 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
1164 return -EINVAL;
1165 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001166
Shannon Nelson1fa18372013-11-20 10:03:08 +00001167 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
1168 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001169
1170 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001171 if ((new_tx_count == vsi->tx_rings[0]->count) &&
1172 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001173 return 0;
1174
1175 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
1176 usleep_range(1000, 2000);
1177
1178 if (!netif_running(vsi->netdev)) {
1179 /* simple case - set for the next time the netdev is started */
1180 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001181 vsi->tx_rings[i]->count = new_tx_count;
1182 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001183 }
1184 goto done;
1185 }
1186
1187 /* We can't just free everything and then setup again,
1188 * because the ISRs in MSI-X mode get passed pointers
1189 * to the Tx and Rx ring structs.
1190 */
1191
1192 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001193 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001194 netdev_info(netdev,
1195 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001196 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001197 tx_rings = kcalloc(vsi->alloc_queue_pairs,
1198 sizeof(struct i40e_ring), GFP_KERNEL);
1199 if (!tx_rings) {
1200 err = -ENOMEM;
1201 goto done;
1202 }
1203
1204 for (i = 0; i < vsi->num_queue_pairs; i++) {
1205 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001206 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001207 tx_rings[i].count = new_tx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001208 /* the desc and bi pointers will be reallocated in the
1209 * setup call
1210 */
1211 tx_rings[i].desc = NULL;
1212 tx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001213 err = i40e_setup_tx_descriptors(&tx_rings[i]);
1214 if (err) {
1215 while (i) {
1216 i--;
1217 i40e_free_tx_resources(&tx_rings[i]);
1218 }
1219 kfree(tx_rings);
1220 tx_rings = NULL;
1221
1222 goto done;
1223 }
1224 }
1225 }
1226
1227 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001228 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001229 netdev_info(netdev,
1230 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +00001231 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001232 rx_rings = kcalloc(vsi->alloc_queue_pairs,
1233 sizeof(struct i40e_ring), GFP_KERNEL);
1234 if (!rx_rings) {
1235 err = -ENOMEM;
1236 goto free_tx;
1237 }
1238
1239 for (i = 0; i < vsi->num_queue_pairs; i++) {
1240 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +00001241 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001242 rx_rings[i].count = new_rx_count;
Jesse Brandeburg1e8efb42015-08-27 11:42:33 -04001243 /* the desc and bi pointers will be reallocated in the
1244 * setup call
1245 */
1246 rx_rings[i].desc = NULL;
1247 rx_rings[i].rx_bi = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001248 err = i40e_setup_rx_descriptors(&rx_rings[i]);
1249 if (err) {
1250 while (i) {
1251 i--;
1252 i40e_free_rx_resources(&rx_rings[i]);
1253 }
1254 kfree(rx_rings);
1255 rx_rings = NULL;
1256
1257 goto free_tx;
1258 }
1259 }
1260 }
1261
1262 /* Bring interface down, copy in the new ring info,
1263 * then restore the interface
1264 */
1265 i40e_down(vsi);
1266
1267 if (tx_rings) {
1268 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001269 i40e_free_tx_resources(vsi->tx_rings[i]);
1270 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001271 }
1272 kfree(tx_rings);
1273 tx_rings = NULL;
1274 }
1275
1276 if (rx_rings) {
1277 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +00001278 i40e_free_rx_resources(vsi->rx_rings[i]);
1279 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001280 }
1281 kfree(rx_rings);
1282 rx_rings = NULL;
1283 }
1284
1285 i40e_up(vsi);
1286
1287free_tx:
1288 /* error cleanup if the Rx allocations failed after getting Tx */
1289 if (tx_rings) {
1290 for (i = 0; i < vsi->num_queue_pairs; i++)
1291 i40e_free_tx_resources(&tx_rings[i]);
1292 kfree(tx_rings);
1293 tx_rings = NULL;
1294 }
1295
1296done:
1297 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
1298
1299 return err;
1300}
1301
1302static int i40e_get_sset_count(struct net_device *netdev, int sset)
1303{
1304 struct i40e_netdev_priv *np = netdev_priv(netdev);
1305 struct i40e_vsi *vsi = np->vsi;
1306 struct i40e_pf *pf = vsi->back;
1307
1308 switch (sset) {
1309 case ETH_SS_TEST:
1310 return I40E_TEST_LEN;
1311 case ETH_SS_STATS:
Shannon Nelson58ce5172015-02-27 09:15:26 +00001312 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001313 int len = I40E_PF_STATS_LEN(netdev);
1314
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001315 if ((pf->lan_veb != I40E_NO_VEB) &&
1316 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED))
Neerav Parikhfe860af2015-07-10 19:36:02 -04001317 len += I40E_VEB_STATS_TOTAL;
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001318 return len;
1319 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001320 return I40E_VSI_STATS_LEN(netdev);
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001321 }
Greg Rose7e45ab42015-02-06 08:52:19 +00001322 case ETH_SS_PRIV_FLAGS:
1323 return I40E_PRIV_FLAGS_STR_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001324 default:
1325 return -EOPNOTSUPP;
1326 }
1327}
1328
1329static void i40e_get_ethtool_stats(struct net_device *netdev,
1330 struct ethtool_stats *stats, u64 *data)
1331{
1332 struct i40e_netdev_priv *np = netdev_priv(netdev);
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001333 struct i40e_ring *tx_ring, *rx_ring;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001334 struct i40e_vsi *vsi = np->vsi;
1335 struct i40e_pf *pf = vsi->back;
1336 int i = 0;
1337 char *p;
1338 int j;
1339 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001340 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001341
1342 i40e_update_stats(vsi);
1343
1344 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
1345 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
1346 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
1347 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1348 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001349 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
1350 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
1351 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
1352 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1353 }
Vasu Dev38e00432014-08-01 13:27:03 -07001354#ifdef I40E_FCOE
1355 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) {
1356 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset;
1357 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat ==
1358 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1359 }
1360#endif
Alexander Duyck980e9b12013-09-28 06:01:03 +00001361 rcu_read_lock();
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001362 for (j = 0; j < vsi->num_queue_pairs; j++) {
Akeem G Abodunrine7046ee2014-04-09 05:58:58 +00001363 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001364
1365 if (!tx_ring)
1366 continue;
1367
1368 /* process Tx ring statistics */
1369 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001370 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
Alexander Duyck980e9b12013-09-28 06:01:03 +00001371 data[i] = tx_ring->stats.packets;
1372 data[i + 1] = tx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001373 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001374 i += 2;
Alexander Duyck980e9b12013-09-28 06:01:03 +00001375
1376 /* Rx ring is the 2nd half of the queue pair */
1377 rx_ring = &tx_ring[1];
1378 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001379 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001380 data[i] = rx_ring->stats.packets;
1381 data[i + 1] = rx_ring->stats.bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001382 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
Catherine Sullivan99c472a2014-03-14 07:32:30 +00001383 i += 2;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001384 }
Alexander Duyck980e9b12013-09-28 06:01:03 +00001385 rcu_read_unlock();
Shannon Nelson58ce5172015-02-27 09:15:26 +00001386 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001387 return;
1388
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001389 if ((pf->lan_veb != I40E_NO_VEB) &&
1390 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001391 struct i40e_veb *veb = pf->veb[pf->lan_veb];
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001392
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001393 for (j = 0; j < I40E_VEB_STATS_LEN; j++) {
1394 p = (char *)veb;
1395 p += i40e_gstrings_veb_stats[j].stat_offset;
1396 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat ==
1397 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001398 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001399 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001400 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
1401 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
1402 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
1403 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1404 }
1405 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1406 data[i++] = pf->stats.priority_xon_tx[j];
1407 data[i++] = pf->stats.priority_xoff_tx[j];
1408 }
1409 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
1410 data[i++] = pf->stats.priority_xon_rx[j];
1411 data[i++] = pf->stats.priority_xoff_rx[j];
1412 }
1413 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
1414 data[i++] = pf->stats.priority_xon_2_xoff[j];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001415}
1416
1417static void i40e_get_strings(struct net_device *netdev, u32 stringset,
1418 u8 *data)
1419{
1420 struct i40e_netdev_priv *np = netdev_priv(netdev);
1421 struct i40e_vsi *vsi = np->vsi;
1422 struct i40e_pf *pf = vsi->back;
1423 char *p = (char *)data;
1424 int i;
1425
1426 switch (stringset) {
1427 case ETH_SS_TEST:
1428 for (i = 0; i < I40E_TEST_LEN; i++) {
1429 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
1430 data += ETH_GSTRING_LEN;
1431 }
1432 break;
1433 case ETH_SS_STATS:
1434 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
1435 snprintf(p, ETH_GSTRING_LEN, "%s",
1436 i40e_gstrings_net_stats[i].stat_string);
1437 p += ETH_GSTRING_LEN;
1438 }
Shannon Nelson41a9e552014-04-23 04:50:20 +00001439 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
1440 snprintf(p, ETH_GSTRING_LEN, "%s",
1441 i40e_gstrings_misc_stats[i].stat_string);
1442 p += ETH_GSTRING_LEN;
1443 }
Vasu Dev38e00432014-08-01 13:27:03 -07001444#ifdef I40E_FCOE
1445 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) {
1446 snprintf(p, ETH_GSTRING_LEN, "%s",
1447 i40e_gstrings_fcoe_stats[i].stat_string);
1448 p += ETH_GSTRING_LEN;
1449 }
1450#endif
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001451 for (i = 0; i < vsi->num_queue_pairs; i++) {
1452 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
1453 p += ETH_GSTRING_LEN;
1454 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
1455 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001456 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
1457 p += ETH_GSTRING_LEN;
1458 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
1459 p += ETH_GSTRING_LEN;
1460 }
Shannon Nelson58ce5172015-02-27 09:15:26 +00001461 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001462 return;
1463
Anjali Singhai Jaind1a8d272015-07-23 16:54:40 -04001464 if ((pf->lan_veb != I40E_NO_VEB) &&
1465 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) {
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001466 for (i = 0; i < I40E_VEB_STATS_LEN; i++) {
1467 snprintf(p, ETH_GSTRING_LEN, "veb.%s",
1468 i40e_gstrings_veb_stats[i].stat_string);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001469 p += ETH_GSTRING_LEN;
1470 }
Neerav Parikhfe860af2015-07-10 19:36:02 -04001471 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
1472 snprintf(p, ETH_GSTRING_LEN,
1473 "veb.tc_%u_tx_packets", i);
1474 p += ETH_GSTRING_LEN;
1475 snprintf(p, ETH_GSTRING_LEN,
1476 "veb.tc_%u_tx_bytes", i);
1477 p += ETH_GSTRING_LEN;
1478 snprintf(p, ETH_GSTRING_LEN,
1479 "veb.tc_%u_rx_packets", i);
1480 p += ETH_GSTRING_LEN;
1481 snprintf(p, ETH_GSTRING_LEN,
1482 "veb.tc_%u_rx_bytes", i);
1483 p += ETH_GSTRING_LEN;
1484 }
Shannon Nelson8eab9cf2014-04-23 04:49:55 +00001485 }
1486 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
1487 snprintf(p, ETH_GSTRING_LEN, "port.%s",
1488 i40e_gstrings_stats[i].stat_string);
1489 p += ETH_GSTRING_LEN;
1490 }
1491 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1492 snprintf(p, ETH_GSTRING_LEN,
1493 "port.tx_priority_%u_xon", i);
1494 p += ETH_GSTRING_LEN;
1495 snprintf(p, ETH_GSTRING_LEN,
1496 "port.tx_priority_%u_xoff", i);
1497 p += ETH_GSTRING_LEN;
1498 }
1499 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1500 snprintf(p, ETH_GSTRING_LEN,
1501 "port.rx_priority_%u_xon", i);
1502 p += ETH_GSTRING_LEN;
1503 snprintf(p, ETH_GSTRING_LEN,
1504 "port.rx_priority_%u_xoff", i);
1505 p += ETH_GSTRING_LEN;
1506 }
1507 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
1508 snprintf(p, ETH_GSTRING_LEN,
1509 "port.rx_priority_%u_xon_2_xoff", i);
1510 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001511 }
1512 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
1513 break;
Greg Rose7e45ab42015-02-06 08:52:19 +00001514 case ETH_SS_PRIV_FLAGS:
1515 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) {
1516 memcpy(data, i40e_priv_flags_strings[i],
1517 ETH_GSTRING_LEN);
1518 data += ETH_GSTRING_LEN;
1519 }
1520 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001521 default:
1522 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001523 }
1524}
1525
1526static int i40e_get_ts_info(struct net_device *dev,
1527 struct ethtool_ts_info *info)
1528{
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001529 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
1530
Jacob Kellerfe88bda2014-11-11 20:05:58 +00001531 /* only report HW timestamping if PTP is enabled */
1532 if (!(pf->flags & I40E_FLAG_PTP))
1533 return ethtool_op_get_ts_info(dev, info);
1534
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001535 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1536 SOF_TIMESTAMPING_RX_SOFTWARE |
1537 SOF_TIMESTAMPING_SOFTWARE |
1538 SOF_TIMESTAMPING_TX_HARDWARE |
1539 SOF_TIMESTAMPING_RX_HARDWARE |
1540 SOF_TIMESTAMPING_RAW_HARDWARE;
1541
1542 if (pf->ptp_clock)
1543 info->phc_index = ptp_clock_index(pf->ptp_clock);
1544 else
1545 info->phc_index = -1;
1546
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001547 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001548
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001549 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
1550 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1551 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
Jacob Kellerbeb0dff2014-01-11 05:43:19 +00001552
1553 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001554}
1555
Shannon Nelson7b086392013-11-20 10:02:59 +00001556static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001557{
Shannon Nelson7b086392013-11-20 10:02:59 +00001558 struct i40e_netdev_priv *np = netdev_priv(netdev);
1559 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001560 i40e_status status;
1561 bool link_up = false;
Shannon Nelson7b086392013-11-20 10:02:59 +00001562
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001563 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburga72a5abc2015-08-26 15:14:19 -04001564 status = i40e_get_link_status(&pf->hw, &link_up);
1565 if (status) {
1566 netif_err(pf, drv, netdev, "link query timed out, please retry test\n");
1567 *data = 1;
1568 return *data;
1569 }
1570
1571 if (link_up)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001572 *data = 0;
1573 else
1574 *data = 1;
1575
1576 return *data;
1577}
1578
Shannon Nelson7b086392013-11-20 10:02:59 +00001579static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001580{
Shannon Nelson7b086392013-11-20 10:02:59 +00001581 struct i40e_netdev_priv *np = netdev_priv(netdev);
1582 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001583
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001584 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001585 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001586
Shannon Nelson7b086392013-11-20 10:02:59 +00001587 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001588}
1589
Shannon Nelson7b086392013-11-20 10:02:59 +00001590static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001591{
Shannon Nelson7b086392013-11-20 10:02:59 +00001592 struct i40e_netdev_priv *np = netdev_priv(netdev);
1593 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001594
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001595 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +00001596 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001597
Shannon Nelson4443ec92014-11-13 08:23:12 +00001598 /* forcebly clear the NVM Update state machine */
1599 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT;
1600
Shannon Nelson7b086392013-11-20 10:02:59 +00001601 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001602}
1603
Shannon Nelson7b086392013-11-20 10:02:59 +00001604static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001605{
Shannon Nelson7b086392013-11-20 10:02:59 +00001606 struct i40e_netdev_priv *np = netdev_priv(netdev);
1607 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001608 u16 swc_old = pf->sw_int_count;
1609
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001610 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001611 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
1612 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
Shannon Nelson5d1ff1062014-11-11 20:04:35 +00001613 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK |
1614 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK |
1615 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK |
1616 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK));
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001617 usleep_range(1000, 2000);
1618 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001619
1620 return *data;
1621}
1622
Shannon Nelson7b086392013-11-20 10:02:59 +00001623static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001624{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001625 struct i40e_netdev_priv *np = netdev_priv(netdev);
1626 struct i40e_pf *pf = np->vsi->back;
1627
1628 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +00001629 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001630
1631 return *data;
1632}
1633
Greg Rosee17bc412015-04-16 20:05:59 -04001634static inline bool i40e_active_vfs(struct i40e_pf *pf)
1635{
1636 struct i40e_vf *vfs = pf->vf;
1637 int i;
1638
1639 for (i = 0; i < pf->num_alloc_vfs; i++)
Jesse Brandeburg6995b362015-08-28 17:55:54 -04001640 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states))
Greg Rosee17bc412015-04-16 20:05:59 -04001641 return true;
1642 return false;
1643}
1644
Greg Rose510efb22015-07-10 19:36:01 -04001645static inline bool i40e_active_vmdqs(struct i40e_pf *pf)
1646{
1647 struct i40e_vsi **vsi = pf->vsi;
1648 int i;
1649
1650 for (i = 0; i < pf->num_alloc_vsi; i++) {
1651 if (!vsi[i])
1652 continue;
1653 if (vsi[i]->type == I40E_VSI_VMDQ2)
1654 return true;
1655 }
1656
1657 return false;
1658}
1659
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001660static void i40e_diag_test(struct net_device *netdev,
1661 struct ethtool_test *eth_test, u64 *data)
1662{
1663 struct i40e_netdev_priv *np = netdev_priv(netdev);
Greg Rose5b86c5c2015-02-26 16:14:35 +00001664 bool if_running = netif_running(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001665 struct i40e_pf *pf = np->vsi->back;
1666
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001667 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1668 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001669 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001670
Shannon Nelsonf551b432013-11-26 10:49:12 +00001671 set_bit(__I40E_TESTING, &pf->state);
Greg Rosee17bc412015-04-16 20:05:59 -04001672
Greg Rose510efb22015-07-10 19:36:01 -04001673 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) {
Greg Rosee17bc412015-04-16 20:05:59 -04001674 dev_warn(&pf->pdev->dev,
Greg Rose510efb22015-07-10 19:36:01 -04001675 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
Greg Rosee17bc412015-04-16 20:05:59 -04001676 data[I40E_ETH_TEST_REG] = 1;
1677 data[I40E_ETH_TEST_EEPROM] = 1;
1678 data[I40E_ETH_TEST_INTR] = 1;
1679 data[I40E_ETH_TEST_LOOPBACK] = 1;
1680 data[I40E_ETH_TEST_LINK] = 1;
1681 eth_test->flags |= ETH_TEST_FL_FAILED;
1682 clear_bit(__I40E_TESTING, &pf->state);
1683 goto skip_ol_tests;
1684 }
1685
Greg Rose5b86c5c2015-02-26 16:14:35 +00001686 /* If the device is online then take it offline */
1687 if (if_running)
1688 /* indicate we're in test mode */
1689 dev_close(netdev);
1690 else
Greg Roseb4e53f02015-07-10 19:36:03 -04001691 /* This reset does not affect link - if it is
1692 * changed to a type of reset that does affect
1693 * link then the following link test would have
1694 * to be moved to before the reset
1695 */
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001696 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Shannon Nelsonf551b432013-11-26 10:49:12 +00001697
Shannon Nelson7b086392013-11-20 10:02:59 +00001698 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001699 eth_test->flags |= ETH_TEST_FL_FAILED;
1700
Shannon Nelson7b086392013-11-20 10:02:59 +00001701 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001702 eth_test->flags |= ETH_TEST_FL_FAILED;
1703
Shannon Nelson7b086392013-11-20 10:02:59 +00001704 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001705 eth_test->flags |= ETH_TEST_FL_FAILED;
1706
Shannon Nelson7b086392013-11-20 10:02:59 +00001707 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001708 eth_test->flags |= ETH_TEST_FL_FAILED;
1709
Shannon Nelsonf551b432013-11-26 10:49:12 +00001710 /* run reg test last, a reset is required after it */
1711 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
1712 eth_test->flags |= ETH_TEST_FL_FAILED;
1713
1714 clear_bit(__I40E_TESTING, &pf->state);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001715 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED));
Greg Rose5b86c5c2015-02-26 16:14:35 +00001716
1717 if (if_running)
1718 dev_open(netdev);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001719 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001720 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001721 netif_info(pf, drv, netdev, "online testing starting\n");
1722
Shannon Nelson7b086392013-11-20 10:02:59 +00001723 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001724 eth_test->flags |= ETH_TEST_FL_FAILED;
1725
1726 /* Offline only tests, not run in online; pass by default */
1727 data[I40E_ETH_TEST_REG] = 0;
1728 data[I40E_ETH_TEST_EEPROM] = 0;
1729 data[I40E_ETH_TEST_INTR] = 0;
1730 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001731 }
Shannon Nelsonc140c172013-11-20 10:02:58 +00001732
Greg Rosee17bc412015-04-16 20:05:59 -04001733skip_ol_tests:
1734
Shannon Nelsonb03aaa92013-11-20 10:03:06 +00001735 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001736}
1737
1738static void i40e_get_wol(struct net_device *netdev,
1739 struct ethtool_wolinfo *wol)
1740{
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001741 struct i40e_netdev_priv *np = netdev_priv(netdev);
1742 struct i40e_pf *pf = np->vsi->back;
1743 struct i40e_hw *hw = &pf->hw;
1744 u16 wol_nvm_bits;
1745
1746 /* NVM bit on means WoL disabled for the port */
1747 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001748 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) {
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001749 wol->supported = 0;
1750 wol->wolopts = 0;
1751 } else {
1752 wol->supported = WAKE_MAGIC;
1753 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
1754 }
1755}
1756
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001757/**
1758 * i40e_set_wol - set the WakeOnLAN configuration
1759 * @netdev: the netdev in question
1760 * @wol: the ethtool WoL setting data
1761 **/
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001762static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
1763{
1764 struct i40e_netdev_priv *np = netdev_priv(netdev);
1765 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001766 struct i40e_vsi *vsi = np->vsi;
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001767 struct i40e_hw *hw = &pf->hw;
1768 u16 wol_nvm_bits;
1769
Shannon Nelsonf0d8c732014-12-11 07:06:32 +00001770 /* WoL not supported if this isn't the controlling PF on the port */
1771 if (hw->partition_id != 1) {
1772 i40e_partition_setting_complaint(pf);
1773 return -EOPNOTSUPP;
1774 }
1775
1776 if (vsi != pf->vsi[pf->lan_vsi])
1777 return -EOPNOTSUPP;
1778
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001779 /* NVM bit on means WoL disabled for the port */
1780 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04001781 if (BIT(hw->port) & wol_nvm_bits)
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001782 return -EOPNOTSUPP;
1783
1784 /* only magic packet is supported */
1785 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
1786 return -EOPNOTSUPP;
1787
1788 /* is this a new value? */
1789 if (pf->wol_en != !!wol->wolopts) {
1790 pf->wol_en = !!wol->wolopts;
1791 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
1792 }
1793
1794 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001795}
1796
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001797static int i40e_set_phys_id(struct net_device *netdev,
1798 enum ethtool_phys_id_state state)
1799{
1800 struct i40e_netdev_priv *np = netdev_priv(netdev);
1801 struct i40e_pf *pf = np->vsi->back;
1802 struct i40e_hw *hw = &pf->hw;
1803 int blink_freq = 2;
1804
1805 switch (state) {
1806 case ETHTOOL_ID_ACTIVE:
1807 pf->led_status = i40e_led_get(hw);
1808 return blink_freq;
1809 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001810 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001811 break;
1812 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001813 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001814 break;
1815 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001816 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001817 break;
Akeem G Abodunrin579b23d2015-02-24 06:58:42 +00001818 default:
1819 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001820 }
1821
1822 return 0;
1823}
1824
1825/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1826 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1827 * 125us (8000 interrupts per second) == ITR(62)
1828 */
1829
1830static int i40e_get_coalesce(struct net_device *netdev,
1831 struct ethtool_coalesce *ec)
1832{
1833 struct i40e_netdev_priv *np = netdev_priv(netdev);
1834 struct i40e_vsi *vsi = np->vsi;
1835
1836 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1837 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1838
1839 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001840 ec->use_adaptive_rx_coalesce = 1;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001841
1842 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
Mitch Williams32f5f542014-04-04 04:43:10 +00001843 ec->use_adaptive_tx_coalesce = 1;
1844
1845 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1846 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001847
1848 return 0;
1849}
1850
1851static int i40e_set_coalesce(struct net_device *netdev,
1852 struct ethtool_coalesce *ec)
1853{
1854 struct i40e_netdev_priv *np = netdev_priv(netdev);
1855 struct i40e_q_vector *q_vector;
1856 struct i40e_vsi *vsi = np->vsi;
1857 struct i40e_pf *pf = vsi->back;
1858 struct i40e_hw *hw = &pf->hw;
1859 u16 vector;
1860 int i;
1861
1862 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1863 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1864
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001865 vector = vsi->base_vector;
Mitch Williams32f5f542014-04-04 04:43:10 +00001866 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001867 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001868 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001869 } else if (ec->rx_coalesce_usecs == 0) {
1870 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001871 if (ec->use_adaptive_rx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001872 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001873 } else {
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001874 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001875 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001876 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001877
Mitch Williams32f5f542014-04-04 04:43:10 +00001878 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001879 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001880 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001881 } else if (ec->tx_coalesce_usecs == 0) {
1882 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001883 if (ec->use_adaptive_tx_coalesce)
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001884 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001885 } else {
1886 netif_info(pf, drv, netdev,
Jesse Brandeburg79442d32014-10-25 03:24:32 +00001887 "Invalid value, tx-usecs range is 0-8160\n");
Mitch Williams32f5f542014-04-04 04:43:10 +00001888 return -EINVAL;
Carolyn Wyborny5c2cebd2014-06-04 01:23:18 +00001889 }
Mitch Williams32f5f542014-04-04 04:43:10 +00001890
1891 if (ec->use_adaptive_rx_coalesce)
1892 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1893 else
1894 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1895
1896 if (ec->use_adaptive_tx_coalesce)
1897 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1898 else
1899 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001900
Alexander Duyck493fb302013-09-28 07:01:44 +00001901 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1902 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001903 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1904 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1905 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1906 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1907 i40e_flush(hw);
1908 }
1909
1910 return 0;
1911}
1912
1913/**
1914 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1915 * @pf: pointer to the physical function struct
1916 * @cmd: ethtool rxnfc command
1917 *
1918 * Returns Success if the flow is supported, else Invalid Input.
1919 **/
1920static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1921{
1922 cmd->data = 0;
1923
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00001924 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) {
1925 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data;
1926 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type;
1927 return 0;
1928 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001929 /* Report default options for RSS on i40e */
1930 switch (cmd->flow_type) {
1931 case TCP_V4_FLOW:
1932 case UDP_V4_FLOW:
1933 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1934 /* fall through to add IP fields */
1935 case SCTP_V4_FLOW:
1936 case AH_ESP_V4_FLOW:
1937 case AH_V4_FLOW:
1938 case ESP_V4_FLOW:
1939 case IPV4_FLOW:
1940 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1941 break;
1942 case TCP_V6_FLOW:
1943 case UDP_V6_FLOW:
1944 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1945 /* fall through to add IP fields */
1946 case SCTP_V6_FLOW:
1947 case AH_ESP_V6_FLOW:
1948 case AH_V6_FLOW:
1949 case ESP_V6_FLOW:
1950 case IPV6_FLOW:
1951 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1952 break;
1953 default:
1954 return -EINVAL;
1955 }
1956
1957 return 0;
1958}
1959
1960/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001961 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1962 * @pf: Pointer to the physical function struct
1963 * @cmd: The command to get or set Rx flow classification rules
1964 * @rule_locs: Array of used rule locations
1965 *
1966 * This function populates both the total and actual rule count of
1967 * the ethtool flow classification command
1968 *
1969 * Returns 0 on success or -EMSGSIZE if entry not found
1970 **/
1971static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1972 struct ethtool_rxnfc *cmd,
1973 u32 *rule_locs)
1974{
1975 struct i40e_fdir_filter *rule;
1976 struct hlist_node *node2;
1977 int cnt = 0;
1978
1979 /* report total rule count */
Anjali Singhai Jain082def12014-04-09 05:59:00 +00001980 cmd->data = i40e_get_fd_cnt_all(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00001981
1982 hlist_for_each_entry_safe(rule, node2,
1983 &pf->fdir_filter_list, fdir_node) {
1984 if (cnt == cmd->rule_cnt)
1985 return -EMSGSIZE;
1986
1987 rule_locs[cnt] = rule->fd_id;
1988 cnt++;
1989 }
1990
1991 cmd->rule_cnt = cnt;
1992
1993 return 0;
1994}
1995
1996/**
1997 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1998 * @pf: Pointer to the physical function struct
1999 * @cmd: The command to get or set Rx flow classification rules
2000 *
2001 * This function looks up a filter based on the Rx flow classification
2002 * command and fills the flow spec info for it if found
2003 *
2004 * Returns 0 on success or -EINVAL if filter not found
2005 **/
2006static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
2007 struct ethtool_rxnfc *cmd)
2008{
2009 struct ethtool_rx_flow_spec *fsp =
2010 (struct ethtool_rx_flow_spec *)&cmd->fs;
2011 struct i40e_fdir_filter *rule = NULL;
2012 struct hlist_node *node2;
2013
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002014 hlist_for_each_entry_safe(rule, node2,
2015 &pf->fdir_filter_list, fdir_node) {
2016 if (fsp->location <= rule->fd_id)
2017 break;
2018 }
2019
2020 if (!rule || fsp->location != rule->fd_id)
2021 return -EINVAL;
2022
2023 fsp->flow_type = rule->flow_type;
Anjali Singhai Jain7d54eb22014-03-14 07:32:21 +00002024 if (fsp->flow_type == IP_USER_FLOW) {
2025 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
2026 fsp->h_u.usr_ip4_spec.proto = 0;
2027 fsp->m_u.usr_ip4_spec.proto = 0;
2028 }
2029
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002030 /* Reverse the src and dest notion, since the HW views them from
2031 * Tx perspective where as the user expects it from Rx filter view.
2032 */
2033 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port;
2034 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port;
2035 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0];
2036 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0];
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002037
2038 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET)
2039 fsp->ring_cookie = RX_CLS_FLOW_DISC;
2040 else
2041 fsp->ring_cookie = rule->q_index;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002042
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002043 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
2044 struct i40e_vsi *vsi;
2045
2046 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
2047 if (vsi && vsi->type == I40E_VSI_SRIOV) {
2048 fsp->h_ext.data[1] = htonl(vsi->vf_id);
2049 fsp->m_ext.data[1] = htonl(0x1);
2050 }
2051 }
2052
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002053 return 0;
2054}
2055
2056/**
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002057 * i40e_get_rxnfc - command to get RX flow classification rules
2058 * @netdev: network interface device structure
2059 * @cmd: ethtool rxnfc command
2060 *
2061 * Returns Success if the command is supported.
2062 **/
2063static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2064 u32 *rule_locs)
2065{
2066 struct i40e_netdev_priv *np = netdev_priv(netdev);
2067 struct i40e_vsi *vsi = np->vsi;
2068 struct i40e_pf *pf = vsi->back;
2069 int ret = -EOPNOTSUPP;
2070
2071 switch (cmd->cmd) {
2072 case ETHTOOL_GRXRINGS:
2073 cmd->data = vsi->alloc_queue_pairs;
2074 ret = 0;
2075 break;
2076 case ETHTOOL_GRXFH:
2077 ret = i40e_get_rss_hash_opts(pf, cmd);
2078 break;
2079 case ETHTOOL_GRXCLSRLCNT:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002080 cmd->rule_cnt = pf->fdir_pf_active_filters;
Anjali Singhai Jain082def12014-04-09 05:59:00 +00002081 /* report total rule count */
2082 cmd->data = i40e_get_fd_cnt_all(pf);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002083 ret = 0;
2084 break;
2085 case ETHTOOL_GRXCLSRULE:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002086 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002087 break;
2088 case ETHTOOL_GRXCLSRLALL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002089 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
2090 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002091 default:
2092 break;
2093 }
2094
2095 return ret;
2096}
2097
2098/**
2099 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2100 * @pf: pointer to the physical function struct
2101 * @cmd: ethtool rxnfc command
2102 *
2103 * Returns Success if the flow input set is supported.
2104 **/
2105static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
2106{
2107 struct i40e_hw *hw = &pf->hw;
2108 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
2109 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
2110
2111 /* RSS does not support anything other than hashing
2112 * to queues on src and dst IPs and ports
2113 */
2114 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
2115 RXH_L4_B_0_1 | RXH_L4_B_2_3))
2116 return -EINVAL;
2117
2118 /* We need at least the IP SRC and DEST fields for hashing */
2119 if (!(nfc->data & RXH_IP_SRC) ||
2120 !(nfc->data & RXH_IP_DST))
2121 return -EINVAL;
2122
2123 switch (nfc->flow_type) {
2124 case TCP_V4_FLOW:
2125 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2126 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002127 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002128 break;
2129 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002130 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002131 break;
2132 default:
2133 return -EINVAL;
2134 }
2135 break;
2136 case TCP_V6_FLOW:
2137 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2138 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002139 hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002140 break;
2141 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002142 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002143 break;
2144 default:
2145 return -EINVAL;
2146 }
2147 break;
2148 case UDP_V4_FLOW:
2149 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2150 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002151 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2152 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002153 break;
2154 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002155 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
2156 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002157 break;
2158 default:
2159 return -EINVAL;
2160 }
2161 break;
2162 case UDP_V6_FLOW:
2163 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
2164 case 0:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002165 hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2166 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002167 break;
2168 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002169 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
2170 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002171 break;
2172 default:
2173 return -EINVAL;
2174 }
2175 break;
2176 case AH_ESP_V4_FLOW:
2177 case AH_V4_FLOW:
2178 case ESP_V4_FLOW:
2179 case SCTP_V4_FLOW:
2180 if ((nfc->data & RXH_L4_B_0_1) ||
2181 (nfc->data & RXH_L4_B_2_3))
2182 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002183 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002184 break;
2185 case AH_ESP_V6_FLOW:
2186 case AH_V6_FLOW:
2187 case ESP_V6_FLOW:
2188 case SCTP_V6_FLOW:
2189 if ((nfc->data & RXH_L4_B_0_1) ||
2190 (nfc->data & RXH_L4_B_2_3))
2191 return -EINVAL;
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002192 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002193 break;
2194 case IPV4_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002195 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
2196 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002197 break;
2198 case IPV6_FLOW:
Jesse Brandeburg41a1d042015-06-04 16:24:02 -04002199 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
2200 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002201 break;
2202 default:
2203 return -EINVAL;
2204 }
2205
2206 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
2207 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
2208 i40e_flush(hw);
2209
Carolyn Wyborny88eee9b2015-02-06 08:52:09 +00002210 /* Save setting for future output/update */
2211 pf->vsi[pf->lan_vsi]->rxnfc = *nfc;
2212
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002213 return 0;
2214}
2215
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002216/**
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002217 * i40e_match_fdir_input_set - Match a new filter against an existing one
2218 * @rule: The filter already added
2219 * @input: The new filter to comapre against
2220 *
2221 * Returns true if the two input set match
2222 **/
2223static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
2224 struct i40e_fdir_filter *input)
2225{
2226 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
2227 (rule->src_ip[0] != input->src_ip[0]) ||
2228 (rule->dst_port != input->dst_port) ||
2229 (rule->src_port != input->src_port))
2230 return false;
2231 return true;
2232}
2233
2234/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002235 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
2236 * @vsi: Pointer to the targeted VSI
2237 * @input: The filter to update or NULL to indicate deletion
2238 * @sw_idx: Software index to the filter
2239 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002240 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002241 * This function updates (or deletes) a Flow Director entry from
2242 * the hlist of the corresponding PF
2243 *
2244 * Returns 0 on success
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002245 **/
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002246static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
2247 struct i40e_fdir_filter *input,
2248 u16 sw_idx,
2249 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002250{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002251 struct i40e_fdir_filter *rule, *parent;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002252 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002253 struct hlist_node *node2;
2254 int err = -EINVAL;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002255
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002256 parent = NULL;
2257 rule = NULL;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002258
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002259 hlist_for_each_entry_safe(rule, node2,
2260 &pf->fdir_filter_list, fdir_node) {
2261 /* hash found, or no matching entry */
2262 if (rule->fd_id >= sw_idx)
2263 break;
2264 parent = rule;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002265 }
2266
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002267 /* if there is an old rule occupying our place remove it */
2268 if (rule && (rule->fd_id == sw_idx)) {
Anjali Singhai Jain43fddb72014-02-11 08:24:09 +00002269 if (input && !i40e_match_fdir_input_set(rule, input))
2270 err = i40e_add_del_fdir(vsi, rule, false);
2271 else if (!input)
2272 err = i40e_add_del_fdir(vsi, rule, false);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002273 hlist_del(&rule->fdir_node);
2274 kfree(rule);
2275 pf->fdir_pf_active_filters--;
2276 }
2277
2278 /* If no input this was a delete, err should be 0 if a rule was
2279 * successfully found and removed from the list else -EINVAL
2280 */
2281 if (!input)
2282 return err;
2283
2284 /* initialize node and set software index */
2285 INIT_HLIST_NODE(&input->fdir_node);
2286
2287 /* add filter to the list */
2288 if (parent)
Ken Helias1d023282014-08-06 16:09:16 -07002289 hlist_add_behind(&input->fdir_node, &parent->fdir_node);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002290 else
2291 hlist_add_head(&input->fdir_node,
2292 &pf->fdir_filter_list);
2293
2294 /* update counts */
2295 pf->fdir_pf_active_filters++;
2296
2297 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002298}
2299
2300/**
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002301 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
2302 * @vsi: Pointer to the targeted VSI
2303 * @cmd: The command to get or set Rx flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002304 *
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002305 * The function removes a Flow Director filter entry from the
2306 * hlist of the corresponding PF
2307 *
2308 * Returns 0 on success
2309 */
2310static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
2311 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002312{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002313 struct ethtool_rx_flow_spec *fsp =
2314 (struct ethtool_rx_flow_spec *)&cmd->fs;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002315 struct i40e_pf *pf = vsi->back;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002316 int ret = 0;
Jesse Brandeburgc35a1d72013-12-18 13:46:02 +00002317
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002318 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2319 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2320 return -EBUSY;
2321
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002322 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2323 return -EBUSY;
2324
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002325 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002326
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002327 i40e_fdir_check_and_reenable(pf);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002328 return ret;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002329}
2330
2331/**
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002332 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002333 * @vsi: pointer to the targeted VSI
2334 * @cmd: command to get or set RX flow classification rules
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002335 *
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002336 * Add Flow Director filters for a specific flow spec based on their
2337 * protocol. Returns 0 if the filters were successfully added.
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002338 **/
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002339static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
2340 struct ethtool_rxnfc *cmd)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002341{
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002342 struct ethtool_rx_flow_spec *fsp;
2343 struct i40e_fdir_filter *input;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002344 struct i40e_pf *pf;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002345 int ret = -EINVAL;
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002346 u16 vf_id;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002347
2348 if (!vsi)
2349 return -EINVAL;
2350
2351 pf = vsi->back;
2352
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002353 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
2354 return -EOPNOTSUPP;
2355
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002356 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002357 return -ENOSPC;
2358
Anjali Singhai Jain60793f4a2014-07-09 07:46:23 +00002359 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) ||
2360 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state))
2361 return -EBUSY;
2362
Anjali Singhai Jain1e1be8f2014-07-10 08:03:26 +00002363 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
2364 return -EBUSY;
2365
Anjali Singhai Jain55a5e602014-02-12 06:33:25 +00002366 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
2367
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002368 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
2369 pf->hw.func_caps.fd_filters_guaranteed)) {
2370 return -EINVAL;
2371 }
2372
Anjali Singhai Jain387ce1a2014-05-22 06:32:23 +00002373 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
2374 (fsp->ring_cookie >= vsi->num_queue_pairs))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002375 return -EINVAL;
2376
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002377 input = kzalloc(sizeof(*input), GFP_KERNEL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002378
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002379 if (!input)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002380 return -ENOMEM;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002381
2382 input->fd_id = fsp->location;
2383
Anjali Singhai Jain35a91fd2014-03-06 09:00:00 +00002384 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
2385 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
2386 else
2387 input->dest_ctl =
2388 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
2389
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002390 input->q_index = fsp->ring_cookie;
2391 input->flex_off = 0;
2392 input->pctype = 0;
2393 input->dest_vsi = vsi->id;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002394 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
Anjali Singhai Jain0bf4b1b2015-04-16 20:06:02 -04002395 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002396 input->flow_type = fsp->flow_type;
2397 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
Anjali Singhai Jain04b73bd2014-05-22 06:31:41 +00002398
2399 /* Reverse the src and dest notion, since the HW expects them to be from
2400 * Tx perspective where as the input from user is from Rx filter view.
2401 */
2402 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc;
2403 input->src_port = fsp->h_u.tcp_ip4_spec.pdst;
2404 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
2405 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002406
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002407 if (ntohl(fsp->m_ext.data[1])) {
2408 if (ntohl(fsp->h_ext.data[1]) >= pf->num_alloc_vfs) {
2409 netif_info(pf, drv, vsi->netdev, "Invalid VF id\n");
2410 goto free_input;
2411 }
2412 vf_id = ntohl(fsp->h_ext.data[1]);
2413 /* Find vsi id from vf id and override dest vsi */
2414 input->dest_vsi = pf->vf[vf_id].lan_vsi_id;
2415 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) {
2416 netif_info(pf, drv, vsi->netdev, "Invalid queue id\n");
2417 goto free_input;
2418 }
2419 }
2420
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002421 ret = i40e_add_del_fdir(vsi, input, true);
Anjali Singhai Jaine7c8c602015-04-07 19:45:31 -04002422free_input:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002423 if (ret)
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002424 kfree(input);
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002425 else
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002426 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002427
2428 return ret;
2429}
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002430
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002431/**
2432 * i40e_set_rxnfc - command to set RX flow classification rules
2433 * @netdev: network interface device structure
2434 * @cmd: ethtool rxnfc command
2435 *
2436 * Returns Success if the command is supported.
2437 **/
2438static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2439{
2440 struct i40e_netdev_priv *np = netdev_priv(netdev);
2441 struct i40e_vsi *vsi = np->vsi;
2442 struct i40e_pf *pf = vsi->back;
2443 int ret = -EOPNOTSUPP;
2444
2445 switch (cmd->cmd) {
2446 case ETHTOOL_SRXFH:
2447 ret = i40e_set_rss_hash_opt(pf, cmd);
2448 break;
2449 case ETHTOOL_SRXCLSRLINS:
Anjali Singhai Jain1eaa3842014-03-06 08:59:59 +00002450 ret = i40e_add_fdir_ethtool(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002451 break;
2452 case ETHTOOL_SRXCLSRLDEL:
Joseph Gasparakis17a73f62014-02-12 01:45:30 +00002453 ret = i40e_del_fdir_entry(vsi, cmd);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002454 break;
2455 default:
2456 break;
2457 }
2458
2459 return ret;
2460}
2461
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002462/**
2463 * i40e_max_channels - get Max number of combined channels supported
2464 * @vsi: vsi pointer
2465 **/
2466static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
2467{
2468 /* TODO: This code assumes DCB and FD is disabled for now. */
2469 return vsi->alloc_queue_pairs;
2470}
2471
2472/**
2473 * i40e_get_channels - Get the current channels enabled and max supported etc.
2474 * @netdev: network interface device structure
2475 * @ch: ethtool channels structure
2476 *
2477 * We don't support separate tx and rx queues as channels. The other count
2478 * represents how many queues are being used for control. max_combined counts
2479 * how many queue pairs we can support. They may not be mapped 1 to 1 with
2480 * q_vectors since we support a lot more queue pairs than q_vectors.
2481 **/
2482static void i40e_get_channels(struct net_device *dev,
2483 struct ethtool_channels *ch)
2484{
2485 struct i40e_netdev_priv *np = netdev_priv(dev);
2486 struct i40e_vsi *vsi = np->vsi;
2487 struct i40e_pf *pf = vsi->back;
2488
2489 /* report maximum channels */
2490 ch->max_combined = i40e_max_channels(vsi);
2491
2492 /* report info for other vector */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002493 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002494 ch->max_other = ch->other_count;
2495
2496 /* Note: This code assumes DCB is disabled for now. */
2497 ch->combined_count = vsi->num_queue_pairs;
2498}
2499
2500/**
2501 * i40e_set_channels - Set the new channels count.
2502 * @netdev: network interface device structure
2503 * @ch: ethtool channels structure
2504 *
2505 * The new channels count may not be the same as requested by the user
2506 * since it gets rounded down to a power of 2 value.
2507 **/
2508static int i40e_set_channels(struct net_device *dev,
2509 struct ethtool_channels *ch)
2510{
2511 struct i40e_netdev_priv *np = netdev_priv(dev);
2512 unsigned int count = ch->combined_count;
2513 struct i40e_vsi *vsi = np->vsi;
2514 struct i40e_pf *pf = vsi->back;
2515 int new_count;
2516
2517 /* We do not support setting channels for any other VSI at present */
2518 if (vsi->type != I40E_VSI_MAIN)
2519 return -EINVAL;
2520
2521 /* verify they are not requesting separate vectors */
2522 if (!count || ch->rx_count || ch->tx_count)
2523 return -EINVAL;
2524
2525 /* verify other_count has not changed */
Jesse Brandeburg60ea5f82014-01-17 15:36:34 -08002526 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002527 return -EINVAL;
2528
2529 /* verify the number of channels does not exceed hardware limits */
2530 if (count > i40e_max_channels(vsi))
2531 return -EINVAL;
2532
2533 /* update feature limits from largest to smallest supported values */
2534 /* TODO: Flow director limit, DCB etc */
2535
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002536 /* use rss_reconfig to rebuild with new queue count and update traffic
2537 * class queue mapping
2538 */
2539 new_count = i40e_reconfig_rss_queues(pf, count);
Anjali Singhai Jain5f90f422013-12-21 05:44:43 +00002540 if (new_count > 0)
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002541 return 0;
2542 else
2543 return -EINVAL;
2544}
2545
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002546#define I40E_HLUT_ARRAY_SIZE ((I40E_PFQF_HLUT_MAX_INDEX + 1) * 4)
2547/**
2548 * i40e_get_rxfh_key_size - get the RSS hash key size
2549 * @netdev: network interface device structure
2550 *
2551 * Returns the table size.
2552 **/
2553static u32 i40e_get_rxfh_key_size(struct net_device *netdev)
2554{
2555 return I40E_HKEY_ARRAY_SIZE;
2556}
2557
2558/**
2559 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size
2560 * @netdev: network interface device structure
2561 *
2562 * Returns the table size.
2563 **/
2564static u32 i40e_get_rxfh_indir_size(struct net_device *netdev)
2565{
2566 return I40E_HLUT_ARRAY_SIZE;
2567}
2568
2569static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
2570 u8 *hfunc)
2571{
2572 struct i40e_netdev_priv *np = netdev_priv(netdev);
2573 struct i40e_vsi *vsi = np->vsi;
2574 struct i40e_pf *pf = vsi->back;
2575 struct i40e_hw *hw = &pf->hw;
2576 u32 reg_val;
2577 int i, j;
2578
2579 if (hfunc)
2580 *hfunc = ETH_RSS_HASH_TOP;
2581
2582 if (!indir)
2583 return 0;
2584
2585 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2586 reg_val = rd32(hw, I40E_PFQF_HLUT(i));
2587 indir[j++] = reg_val & 0xff;
2588 indir[j++] = (reg_val >> 8) & 0xff;
2589 indir[j++] = (reg_val >> 16) & 0xff;
2590 indir[j++] = (reg_val >> 24) & 0xff;
2591 }
2592
2593 if (key) {
2594 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2595 reg_val = rd32(hw, I40E_PFQF_HKEY(i));
2596 key[j++] = (u8)(reg_val & 0xff);
2597 key[j++] = (u8)((reg_val >> 8) & 0xff);
2598 key[j++] = (u8)((reg_val >> 16) & 0xff);
2599 key[j++] = (u8)((reg_val >> 24) & 0xff);
2600 }
2601 }
2602 return 0;
2603}
2604
2605/**
2606 * i40e_set_rxfh - set the rx flow hash indirection table
2607 * @netdev: network interface device structure
2608 * @indir: indirection table
2609 * @key: hash key
2610 *
Mitch Williamscd494fb2015-07-10 19:36:04 -04002611 * Returns -EINVAL if the table specifies an invalid queue id, otherwise
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002612 * returns 0 after programming the table.
2613 **/
2614static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir,
2615 const u8 *key, const u8 hfunc)
2616{
2617 struct i40e_netdev_priv *np = netdev_priv(netdev);
2618 struct i40e_vsi *vsi = np->vsi;
2619 struct i40e_pf *pf = vsi->back;
2620 struct i40e_hw *hw = &pf->hw;
2621 u32 reg_val;
2622 int i, j;
2623
2624 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
2625 return -EOPNOTSUPP;
2626
2627 if (!indir)
2628 return 0;
2629
2630 for (i = 0, j = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++) {
2631 reg_val = indir[j++];
2632 reg_val |= indir[j++] << 8;
2633 reg_val |= indir[j++] << 16;
2634 reg_val |= indir[j++] << 24;
2635 wr32(hw, I40E_PFQF_HLUT(i), reg_val);
2636 }
2637
2638 if (key) {
2639 for (i = 0, j = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++) {
2640 reg_val = key[j++];
2641 reg_val |= key[j++] << 8;
2642 reg_val |= key[j++] << 16;
2643 reg_val |= key[j++] << 24;
2644 wr32(hw, I40E_PFQF_HKEY(i), reg_val);
2645 }
2646 }
2647 return 0;
2648}
2649
Greg Rose7e45ab42015-02-06 08:52:19 +00002650/**
2651 * i40e_get_priv_flags - report device private flags
2652 * @dev: network interface device structure
2653 *
2654 * The get string set count and the string set should be matched for each
2655 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
2656 * array.
2657 *
2658 * Returns a u32 bitmap of flags.
2659 **/
Jesse Brandeburg5bbc3302015-02-26 16:15:20 +00002660static u32 i40e_get_priv_flags(struct net_device *dev)
Greg Rose7e45ab42015-02-06 08:52:19 +00002661{
2662 struct i40e_netdev_priv *np = netdev_priv(dev);
2663 struct i40e_vsi *vsi = np->vsi;
2664 struct i40e_pf *pf = vsi->back;
2665 u32 ret_flags = 0;
2666
2667 ret_flags |= pf->hw.func_caps.npar_enable ?
2668 I40E_PRIV_FLAGS_NPAR_FLAG : 0;
Shannon Nelson9ac77262015-08-27 11:42:40 -04002669 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ?
2670 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0;
Jesse Brandeburgef171782015-09-03 17:18:49 -04002671 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ?
2672 I40E_PRIV_FLAGS_FD_ATR : 0;
Greg Rose7e45ab42015-02-06 08:52:19 +00002673
2674 return ret_flags;
2675}
2676
Shannon Nelson9ac77262015-08-27 11:42:40 -04002677/**
2678 * i40e_set_priv_flags - set private flags
2679 * @dev: network interface device structure
2680 * @flags: bit flags to be set
2681 **/
2682static int i40e_set_priv_flags(struct net_device *dev, u32 flags)
2683{
2684 struct i40e_netdev_priv *np = netdev_priv(dev);
2685 struct i40e_vsi *vsi = np->vsi;
2686 struct i40e_pf *pf = vsi->back;
2687
2688 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG)
2689 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED;
2690 else
2691 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED;
2692
Jesse Brandeburgef171782015-09-03 17:18:49 -04002693 /* allow the user to control the state of the Flow
2694 * Director ATR (Application Targeted Routing) feature
2695 * of the driver
2696 */
2697 if (flags & I40E_PRIV_FLAGS_FD_ATR) {
2698 pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
2699 } else {
2700 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED;
2701 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
2702 }
2703
Shannon Nelson9ac77262015-08-27 11:42:40 -04002704 return 0;
2705}
2706
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002707static const struct ethtool_ops i40e_ethtool_ops = {
2708 .get_settings = i40e_get_settings,
Catherine Sullivanbf9c7142014-06-04 08:45:28 +00002709 .set_settings = i40e_set_settings,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002710 .get_drvinfo = i40e_get_drvinfo,
2711 .get_regs_len = i40e_get_regs_len,
2712 .get_regs = i40e_get_regs,
2713 .nway_reset = i40e_nway_reset,
2714 .get_link = ethtool_op_get_link,
2715 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00002716 .set_wol = i40e_set_wol,
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002717 .set_eeprom = i40e_set_eeprom,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002718 .get_eeprom_len = i40e_get_eeprom_len,
2719 .get_eeprom = i40e_get_eeprom,
2720 .get_ringparam = i40e_get_ringparam,
2721 .set_ringparam = i40e_set_ringparam,
2722 .get_pauseparam = i40e_get_pauseparam,
Catherine Sullivan2becc352014-06-04 08:45:27 +00002723 .set_pauseparam = i40e_set_pauseparam,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002724 .get_msglevel = i40e_get_msglevel,
2725 .set_msglevel = i40e_set_msglevel,
2726 .get_rxnfc = i40e_get_rxnfc,
2727 .set_rxnfc = i40e_set_rxnfc,
2728 .self_test = i40e_diag_test,
2729 .get_strings = i40e_get_strings,
2730 .set_phys_id = i40e_set_phys_id,
2731 .get_sset_count = i40e_get_sset_count,
2732 .get_ethtool_stats = i40e_get_ethtool_stats,
2733 .get_coalesce = i40e_get_coalesce,
2734 .set_coalesce = i40e_set_coalesce,
Mitch A Williamsb29e13b2015-03-05 04:14:40 +00002735 .get_rxfh_key_size = i40e_get_rxfh_key_size,
2736 .get_rxfh_indir_size = i40e_get_rxfh_indir_size,
2737 .get_rxfh = i40e_get_rxfh,
2738 .set_rxfh = i40e_set_rxfh,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00002739 .get_channels = i40e_get_channels,
2740 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002741 .get_ts_info = i40e_get_ts_info,
Greg Rose7e45ab42015-02-06 08:52:19 +00002742 .get_priv_flags = i40e_get_priv_flags,
Shannon Nelson9ac77262015-08-27 11:42:40 -04002743 .set_priv_flags = i40e_set_priv_flags,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002744};
2745
2746void i40e_set_ethtool_ops(struct net_device *netdev)
2747{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00002748 netdev->ethtool_ops = &i40e_ethtool_ops;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00002749}